-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate_reads_and_assembly.sh
271 lines (204 loc) · 9.66 KB
/
simulate_reads_and_assembly.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
#The following script uses ReadSimulator.py to simulate Illumina short reads (PE 150bp) with the specified error sources and ratios, then generates the corresponding genone assemblies all.
#Finally quast is run to collect the genome assembly quality metrics.
#bbmap and MutationSimulator should be placed in the current directory.
ids="ls *fna | cut -f 1 -d_" #assumes all reference genome sequences to be located in the current directory. extension should be .fna.
covs="25 50 75 100 125 150"
err="0 0.01 0.025 0.05"
odups="0.01 0.05 0.15 0.30"
pdups="0.01 0.05 0.15 0.30"
rep="1 2 3 4 5"
sed -i 's/^>/>GENOMESEQ_/' *fna
for r in $rep
do
for n in $ids;
do
for i in $covs
do
for l in $err
do
echo "readSimulator.py --input ${n}*fna --simulator wgsim --outdir ${n}_cov${i}_err${l}_rep${r} --iterations 10 --readlen 150 --depth $i --opts '-e $l -r 0 -R 0 -X 0 -h -S 5'"
done
done
done
done > readsim.sh
sh readsim.sh
for l in $ids
do
for i in $( ls ${l}* | grep -v "gz\|html\|zip\|fna" )
do
ii=ids_${i}; echo "mv $i $ii"
done
done | sed 's/://g' | parallel -j48
mkdir shs_reps #to run created scripts in parallel
for r in $rep
do
for n in $ids;
do
for i in $covs
do
for l in $err
do
echo "mkdir ${n}_cov${i}_err${l}_rep${r}
zcat ids_${n}_cov${i}_err${l}_rep${r}/*1.fastq.gz | awk 'sub(\"GENOMESEQ\",cnt+1, \$0){cnt++}1' | gzip > ${n}_cov${i}_err${l}_rep${r}/${n}_1.fastq.gz
zcat ids_${n}_cov${i}_err${l}_rep${r}/*2.fastq.gz | awk 'sub(\"GENOMESEQ\",cnt+1, \$0){cnt++}1' | gzip > ${n}_cov${i}_err${l}_rep${r}/${n}_2.fastq.gz" > shs_reps/${n}_cov"${i}"_err"${l}"_rep"${r}"_make_ids.sh
done
done
done
done
parallel -j48 bash :::: <(ls shs_reps/*make_ids.sh)
for r in $rep
do
for n in $ids
do
for i in $covs
do
for l in $err
do
for o in $odups
do
echo "zgrep "^@" ${n}_cov${i}_err${l}_rep${r}/${n}_*1.fastq.gz | sed 's/\/1$//' > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids" > shs_reps/extract_ids_${n}_cov"${i}"_err"${l}"_odup"${o}"_pdup0_rep"${r}".sh
done
done
done
done
done
parallel -j48 bash :::: <(ls shs_reps/extract_ids_*.sh)
for r in $rep
do
for n in $ids
do
for i in $covs
do
for l in $err
do
for o in $odups
do
echo "no_reads=\`cat ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids | wc -l\`
echo \$no_reads
no_sub=\`awk -v x="\$no_reads" -v y=$o 'BEGIN {print x*y}' | awk '{ printf(\"%d\", \$1 + 0.5) }'\`
echo \$no_sub
cat ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids | shuf | head -n \$no_sub > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.randids
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.randids ${n}_cov${i}_err${l}_rep${r}/*1.fastq.gz --no-group-separator | sed 's/^@/@odup/' | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads1.gz
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.randids ${n}_cov${i}_err${l}_rep${r}/*2.fastq.gz --no-group-separator | sed 's/^@/@odup/' | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads2.gz
mkdir ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}
zcat ${n}_cov${i}_err${l}_rep${r}/${n}*1.fastq.gz ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads1.gz | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/${n}_1.fastq.gz
zcat ${n}_cov${i}_err${l}_rep${r}/${n}*2.fastq.gz ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads2.gz | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/${n}_2.fastq.gz" > ./shs_reps/merge_${n}_cov"${i}"_err"${l}"_odup"${o}"_pdup0_rep"${r}".sh
done
done
done
done
done
parallel -j48 bash :::: <(ls shs_reps/merge_*.sh)
pdups="0.01 0.05 0.15 0.30"
for r in $rep
do
for n in $ids
do
for i in $covs
do
for l in $err
do
for o in $odups
do
for p in $pdups
do
echo "no_reads=\`cat ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids | wc -l\`
echo \$no_reads
no_sub=\`awk -v x="\$no_reads" -v y=$p 'BEGIN {print x*y}' | awk '{ printf(\"%d\", \$1 + 0.5) }'\`
echo \$no_sub
cat ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids | shuf | head -n \$no_sub > ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}.prandids
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}.prandids ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/*1.fastq.gz --no-group-separator | sed 's/^@/@pdup/' | seqtk seq -a > temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1.fa
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}.prandids ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/*2.fastq.gz --no-group-separator | sed 's/^@/@pdup/' | seqtk seq -a > temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2.fa
./Mutation-Simulator/mutation-simulator.py temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1.fa args -sn 0.01
./Mutation-Simulator/mutation-simulator.py temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2.fa args -sn 0.01
./bbmap/reformat.sh in=temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1_ms.fa out=${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1_ms.fq qfake=40
./bbmap/reformat.sh in=temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2_ms.fa out=${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2_ms.fq qfake=40
gzip ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1_ms.fq
gzip ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2_ms.fq
mkdir ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}
zcat ${n}_cov${i}_err${l}_rep${r}/*1.fastq.gz ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads1.gz ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads1_ms.fq.gz | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}/${n}_1.fastq.gz
zcat ${n}_cov${i}_err${l}_rep${r}/*2.fastq.gz ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}_dupreads2.gz ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}_pdupreads2_ms.fq.gz | gzip > ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}/${n}_2.fastq.gz
rm temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}*" > shs_reps/mutate_${n}_cov"${i}"_err"${l}"_odup"${o}"_pdup"${p}"_rep"${r}".sh
done
done
done
done
done
done
parallel -j48 bash :::: <(ls shs_reps/mutate_cbot*.sh)
#odup=0 and pdup=$pdup
for r in $rep
do
for n in $ids
do
for i in $covs
do
for l in $err
do
for p in $pdups
do
echo "no_reads=\`cat ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}.ids | wc -l\`
echo \$no_reads
no_sub=\`awk -v x="\$no_reads" -v y=$p 'BEGIN {print x*y}' | awk '{ printf(\"%d\", \$1 + 0.5) }'\`
echo \$no_sub
cat ${n}_cov${i}_err${l}_odup0.01_pdup0_rep${r}.ids | shuf | head -n \$no_sub > ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}.prandids
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}.prandids ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/*1.fastq.gz --no-group-separator | sed 's/^@/@pdup/' | seqtk seq -a > temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1.fa
zgrep -A 3 -F -f ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}.prandids ${n}_cov${i}_err${l}_odup${o}_pdup0_rep${r}/*2.fastq.gz --no-group-separator | sed 's/^@/@pdup/' | seqtk seq -a > temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2.fa
./Mutation-Simulator/mutation-simulator.py temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1.fa args -sn 0.01
./Mutation-Simulator/mutation-simulator.py temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2.fa args -sn 0.01
./bbmap/reformat.sh in=temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1_ms.fa out=${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1_ms.fq qfake=40
./bbmap/reformat.sh in=temp_${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2_ms.fa out=${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2_ms.fq qfake=40
gzip ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1_ms.fq
gzip ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2_ms.fq
mkdir ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}
zcat ${n}_cov${i}_err${l}_rep${r}/*1.fastq.gz ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads1_ms.fq.gz | gzip > ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}/${n}_1.fastq.gz
zcat ${n}_cov${i}_err${l}_rep${r}/*2.fastq.gz ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}_pdupreads2_ms.fq.gz | gzip > ${n}_cov${i}_err${l}_odup0_pdup${p}_rep${r}/${n}_2.fastq.gz
rm temp_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}*" > shs_reps/mutate_${n}_cov"${i}"_err"${l}"_odup0_pdup"${p}"_rep"${r}".sh
done
done
done
done
parallel -j48 bash :::: <(ls shs_reps/mutate_llac*odup0_*.sh)
renames=$(find ./ -name "*err*" -type d | grep -v "odup\|ids") #move assemblies with zero error
for i in $renames
do
ii=$(echo "$i" | sed 's/_rep/_odup0_pdup0_rep/')
echo "mv ${i} ${ii}"
done
err="0 0.01 0.025 0.05" #reassign to assemble zero error reads
odups="0 0.01 0.05 0.15 0.30"
pdups="0 0.01 0.05 0.15 0.30"
rep="1 2 3 4 5"
for r in $rep
do
for n in $ids
do
for i in $covs
do
for l in $err
do
for o in $odups
do
for p in $pdups
do
echo "{ time spades.py -1 ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}/${n}_1.fastq.gz -2 ${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}/${n}_2.fastq.gz -o spades_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r} -t 16 --only-assembler ; } 2> time_spades_${n}_cov${i}_err${l}_odup${o}_pdup${p}_rep${r}.txt" > shs_reps/run_spades_${n}_cov"${i}"_err"${l}"_odup"${o}"_pdup"${p}"_"${r}".sh
done
done
done
done
done
done
parallel -j3 bash :::: <(ls shs_reps/run_spades_*.sh)
for n in $ids
do
for i in $rep
do
find ./ -name "contigs.fasta" | grep "$n" | grep rep"${i}" | xargs quast.py -o "${n}"_rep"${i}"_quast --glimmer -t 16 --min-contig 200 -r "${n}"*.fna
done
done
for n i $ids
do
find ./${n}_rep*_quast -name "transposed_report.tsv" | xargs cat | grep -v Assembly > temp
cat <(grep Assembly ${n}_rep1_quast/transposed_report.tsv) temp > ${n}_reps_quast_transposed_report.tsv
done