-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLAST_virus.sh
210 lines (159 loc) · 9.37 KB
/
BLAST_virus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
echo -e "###########################################################################################" "\n"
echo -e ===== Identificación taxonómica de virus con BLASTn en ensambles obtenidos con SPAdes ===== "\n"
echo -e "\t" ===== Inicio: $(date) ===== "\n"
echo -e "###########################################################################################" "\n"
#Crear la base de datos de BLASTn: makeblastdb -in archivo.fa -dbtype nucl -out ./virus_db
#La base de datos de virus se puede descargar en: https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&VirusLineage_ss=Influenza%20A%20virus,%20taxid:11320&HostLineage_ss=NOT%20Homo%20sapiens%20(human),%20taxid:HostId_i:*%20NOT%20HostId_i:9606
cd /home/admcenasa/Analisis_corridas/SPAdes/virus
for ensamble in *.fa; do
ID="$(basename ${ensamble} | cut -d '-' -f '1')"
# -------------------------------------------------------------------------
# Ejecutar BLASTn sobre los ensambles para identificar los contigs de virus
# -------------------------------------------------------------------------
blastn -query ${ensamble} -db $Bn_DB_PATH/virus_db -outfmt "6 qseqid salltitles sstrand pident qcovs" -max_target_seqs 1 -perc_identity 94 -evalue 1e-10 -out /home/admcenasa/Analisis_corridas/SPAdes/virus/BLASTn_results/${ID}_results.tsv
#-evalue 1e-10
#-perc_identity 90
#Para conocer el % de identidad: -outfmt "6 pident"
#ID de secuencia de consulta: -outfmt "6 qseqid"
#Sentido de la secuencia: "sstrand"
# --------------------------------
# Modificar los archivos de salida
# --------------------------------
cat ./BLASTn_results/${ID}_results.tsv | tr " " "_" > ./BLASTn_results/${ID}_results_2.tsv
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $1}' > ./BLASTn_results/${ID}_nodos.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $2}' > ./BLASTn_results/${ID}_gen.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $3}' > ./BLASTn_results/${ID}_sentido.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $4}' > ./BLASTn_results/${ID}_ident.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $5}' > ./BLASTn_results/${ID}_cov.txt
cat ./BLASTn_results/${ID}_gen.txt | cut -d ',' -f '1' > ./BLASTn_results/${ID}_gen1.txt
cat ./BLASTn_results/${ID}_gen1.txt | tr "_" " " > ./BLASTn_results/${ID}_gen2.txt
cat ./BLASTn_results/${ID}_gen2.txt | tr "( )" " | " > ./BLASTn_results/${ID}_gen3.txt
paste ./BLASTn_results/${ID}_nodos.txt ./BLASTn_results/${ID}_sentido.txt ./BLASTn_results/${ID}_ident.txt ./BLASTn_results/${ID}_cov.txt ./BLASTn_results/${ID}_gen3.txt > ./BLASTn_results/${ID}_BLASTn_results_tmp.tsv
cat ./BLASTn_results/${ID}_BLASTn_results_tmp.tsv | uniq > ./BLASTn_results/${ID}_BLASTn_results.tsv
# -------------------------
# Remover archivos sin uso
# -------------------------
rm ./BLASTn_results/${ID}_results.tsv
rm ./BLASTn_results/${ID}_results_2.tsv
rm ./BLASTn_results/*.txt*
rm ./BLASTn_results/*tmp*
done
# -----------------------------------------------------
# Invertir secuencias en minus a su complemento inverso
# -----------------------------------------------------
for BLAST in /home/admcenasa/Analisis_corridas/SPAdes/virus/BLASTn_results/*tsv; do
ID=$(basename ${BLAST} | cut -d '_' -f '1')
for assembly in /home/admcenasa/Analisis_corridas/SPAdes/virus/*fa; do
IDa=$(basename ${assembly} | cut -d '-' -f '1')
awk '$2 == "minus" {print $1}' ${BLAST} > ./BLAST_assembly/${IDa}_minus_contigs.txt
awk '$2 == "plus" {print $1}' ${BLAST} > ./BLAST_assembly/${IDa}_plus_contigs.txt
if [[ ${ID} == ${IDa} ]]; then
echo -e "If control: ${ID} ${IDa}"
seqtk subseq ${assembly} ./BLAST_assembly/${IDa}_minus_contigs.txt | seqtk seq -r > ${IDa}_metaSPAdes_plus.fa
seqtk subseq ${assembly} ./BLAST_assembly/${IDa}_plus_contigs.txt > ${IDa}_SPAdes_plus_contigs.fa
cat ${IDa}_SPAdes_plus_contigs.fa ${IDa}_metaSPAdes_plus.fa > ./BLAST_assembly/${ID}-metaSPAdes-assembly-plus.fasta
chmod -R 775 ./BLAST_assembly/${ID}-metaSPAdes-assembly-plus.fasta
else
continue
fi
done
done
rm *_metaSPAdes_plus.fa
rm *_SPAdes_plus_contigs.fa
rm ./BLAST_assembly/*_plus_contigs* ./BLAST_assembly/*_minus_contigs.txt
#find /home/admcenasa/Analisis_corridas/SPAdes/virus/BLAST_assembly -type f -size 0 -exec rm -f {} \;
# ----------------------------------------------
# Correr BLASTn para confirmar las orientaciones
# ----------------------------------------------
for ens in /home/admcenasa/Analisis_corridas/SPAdes/virus/BLAST_assembly/*fasta; do
ID=$(basename ${ens} | cut -d '-' -f '1')
blastn -query ${ens} -db $Bn_DB_PATH/virus_db -outfmt "6 qseqid salltitles sstrand pident qcovs" -max_target_seqs 1 -perc_identity 94 -evalue 1e-10 -out /home/admcenasa/Analisis_corridas/SPAdes/virus/BLAST_assembly/${ID}_results.tsv
# --------------------------------
# Modificar los archivos de salida
# --------------------------------
cat ./BLAST_assembly/${ID}_results.tsv | tr " " "_" > ./BLAST_assembly/${ID}_results_2.tsv
cat ./BLAST_assembly/${ID}_results_2.tsv | awk '{print $1}' > ./BLAST_assembly/${ID}_nodos.txt
cat ./BLAST_assembly/${ID}_results_2.tsv | awk '{print $2}' > ./BLAST_assembly/${ID}_gen.txt
cat ./BLAST_assembly/${ID}_results_2.tsv | awk '{print $3}' > ./BLAST_assembly/${ID}_sentido.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $4}' > ./BLAST_assembly/${ID}_ident.txt
cat ./BLASTn_results/${ID}_results_2.tsv | awk '{print $5}' > ./BLAST_assembly/${ID}_cov.txt
cat ./BLAST_assembly/${ID}_gen.txt | cut -d ',' -f '1' > ./BLAST_assembly/${ID}_gen1.txt
cat ./BLAST_assembly/${ID}_gen1.txt | tr "_" " " > ./BLAST_assembly/${ID}_gen2.txt
cat ./BLAST_assembly/${ID}_gen2.txt | tr "( )" " | " > ./BLAST_assembly/${ID}_gen3.txt
paste ./BLAST_assembly/${ID}_nodos.txt ./BLAST_assembly/${ID}_sentido.txt ./BLAST_assembly/${ID}_ident.txt ./BLAST_assembly/${ID}_cov.txt ./BLAST_assembly/${ID}_gen3.txt > ./BLAST_assembly/${ID}_BLASTn_results_tmp.tsv
cat ./BLAST_assembly/${ID}_BLASTn_results_tmp.tsv | uniq > ./BLAST_assembly/${ID}_BLASTn_results.tsv
# -------------------------
# Remover archivos sin uso
# -------------------------
rm ./BLAST_assembly/${ID}_results.tsv
rm ./BLAST_assembly/${ID}_results_2.tsv
rm ./BLAST_assembly/*.txt*
rm ./BLAST_assembly/*tmp*
done
#------------------------------------------------------
# Concatenar los resultados de BLAST revisado en un solo archivo
#------------------------------------------------------
for file in ./BLAST_assembly/*BLASTn_results*; do
ename=$(basename ${file} | cut -d '_' -f '1')
echo -e "\n########## ${ename} ########## \n$(cat ${file})"
done >> ./BLAST_assembly/BLASTn_all_rev.tsv
rm ./BLAST_assembly/*_BLASTn_results.tsv
#---------------------------------------------------------------------------
# Concatenar los resultados del primer analisis de BLAST en un solo archivo
#---------------------------------------------------------------------------
for file in ./BLASTn_results/*BLASTn_results*; do
ename=$(basename ${file} | cut -d '_' -f '1')
echo -e "\n########## ${ename} ########## \n$(cat ${file})"
done >> ./BLASTn_results/BLASTn_all_results.tsv
rm ./BLASTn_results/*_BLASTn_results.tsv
# -----------------------------------------------------------------------------
# Eliminar contigs pequeños para todos los generos virales menos para influenza
# -----------------------------------------------------------------------------
cd /home/admcenasa/Analisis_corridas/SPAdes/virus/BLAST_assembly
for file in /home/admcenasa/Analisis_corridas/kmerfinder/virus/*spa; do
genero=$(cat ${file} | sed -n '2p' | cut -d ' ' -f '2,3,4' | cut -d ',' -f '1'| tr ' ' '_')
ID=$(basename ${file} | cut -d '_' -f '1')
echo -e "${genero}"
for assembly in *.fasta; do
assembly_ID=$(basename ${assembly} | cut -d '-' -f '1')
if [[ ${ID} == ${assembly_ID} ]]; then
echo -e "If control: ${ID} ${assembly_ID}"
if [[ ${genero} != "Influenza_A_virus" ]]; then
echo -e "If control: ${genero}"
echo -e "seqtk seq -L 950 ${assembly} > ${ID}-metaSPAdes-assembly-plus.fa"
seqtk seq -L 950 ${assembly} > ${ID}-metaSPAdes-assembly-plus.fa
else
echo -e "else control: ${genero}"
mv ${assembly} ${ID}-metaSPAdes-assembly-plus.fa
echo -e "mv ${assembly} a ${ID}-metaSPAdes-assembly-plus.fa"
continue
echo -e "Else control: ${genero}"
fi
fi
done
done
rm *.fasta
chmod -R 775 *-metaSPAdes-assembly-plus.fa
# ------------------------------------------------------------------------------------
# Mover los ensambles a una carpeta nombrada con el genero del organismo identificado
# ------------------------------------------------------------------------------------
cd /home/admcenasa/Analisis_corridas/kmerfinder/virus
for file in *spa; do
genero=$(cat ${file} | sed -n '2p' | cut -d ' ' -f '2,3,4' | cut -d ',' -f '1'| tr ' ' '_')
ID=$(basename ${file} | cut -d '_' -f '1')
for assembly in /home/admcenasa/Analisis_corridas/SPAdes/virus/BLAST_assembly/*.fa; do
assembly_ID=$(basename ${assembly} | cut -d '-' -f '1')
if [[ ${ID} != ${assembly_ID} ]]; then
continue
else
mkdir -p /home/admcenasa/Analisis_corridas/Resultados_all_virus/Ensambles/${genero}
echo -e "Moviendo ${assembly} a ${genero}"
mv ${assembly} /home/admcenasa/Analisis_corridas/Resultados_all_virus/Ensambles/${genero}
fi
done
done
rm /home/admcenasa/Analisis_corridas/kmerfinder/virus/*spa
echo -e "############################################" "\n"
echo -e "\t" ===== Fin: $(date) ===== "\n"
echo -e "############################################" "\n"