forked from stjacqrm/Daytona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_daytona.sh
320 lines (264 loc) · 12.3 KB
/
run_daytona.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/bin/bash
#----------
# Defaults
#----------
quantitative='FALSE'
from_tar=''
from_dir=''
output_dir='daytona_output'
daytona_variation='clearlabs'
pangolin_docker='docker://staphb/pangolin:4.3.1-pdata-1.25.1'
pangolin_version='v4.3.1'
pdata='v1.25.1'
sotc='S:L452R,S:E484K'
vadr_docker='docker://staphb/vadr:1.3'
samtools_docker='docker://staphb/samtools:1.12'
nextclade_docker='docker://nextstrain/nextclade:0.14.1'
#-------
# Usage
#-------
display_usage() {
echo -e "\nUsage: run_daytona.sh -t from_tar -r from_dir -o output_dir -v 'daytona_variation' -d 'pangolin_docker' -V 'pangolin_version' -D 'pdata' -s 'sotc' -a 'vadr_docker' -S 'samtools_docker' -n 'nextclade_docker' \n"
echo -e " -t if running from tar file."
echo -e " Default: none "
echo -e " -r if running from previously analyzed run."
echo -e " Default: none "
echo -e " -o name of Daytona output directory."
echo -e " Default: 'daytona_output'"
echo -e " -v name of Daytona Pipeline Variant."
echo -e " Default: 'clearlabs'"
echo -e " -d Pangolin docker container."
echo -e " Default: 'docker://staphb/pangolin:4.3.1-pdata-1.25.1'"
echo -e " -V Pangolin Version."
echo -e " Default: 'v4.3.1'"
echo -e " -D Pangolearn Version."
echo -e " Default: 'v1.25.1'"
echo -e " -s SOTCs to evaluate for."
echo -e " Default: 'S:L452R,S:E484K'"
echo -e " -a VADR docker container."
echo -e " Default: 'docker://staphb/vadr:1.3'"
echo -e " -S Samtools docker container."
echo -e " Default: 'docker://staphb/samtools:1.12'"
echo -e " -n Nextclade docker container."
echo -e " Default: 'docker://nextstrain/nextclade:0.14.1'"
echo -e " -h Displays this help message\n"
echo -e "run_daytona.sh"
echo -e "This wrapper is used to tidy and analyse Clear Labs data "
echo -e "using a custom cleaner and the Daytona pipeline.\n"
exit
}
#---------
# Options
#---------
while getopts "t:r:o:v:d:V:D:s:a:S:n:h" opt; do
case $opt in
t) from_tar=${OPTARG%/};;
r) from_dir=${OPTARG%/};;
o) output_dir=${OPTARG%/};;
v) daytona_variation=${OPTARG%/};;
d) pangolin_docker=${OPTARG%/};;
V) pangolin_version=${OPTARG%/};;
s) sotc=${OPTARG%/};;
D) pdata=${OPTARG%/};;
a) vadr_docker=${OPTARG%/};;
S) samtools_docker=${OPTARG%/};;
n) nextclade_docker=${OPTARG%/};;
h) display_usage;;
\?) #unrecognized option - show help
echo -e \\n"Option -$OPTARG not allowed."
display_usage;;
esac
done
if [ "$from_tar" = "tar" ]; then
#-------------------
# Running File Tidy
#-------------------
# making directory name from tarfile name
filename=$(ls *.tar)
dir_name=${filename%.all*}
echo "$dir_name"
echo 'Extracting Files'
tar xf *.tar
echo 'Fixing Filenames'
for fname in *; do
name="${fname%\.*}"
extension="${fname#$name}"
newname="${name//./_}"
newfname="$newname""$extension"
if [ "$fname" != "$newfname" ]; then
#echo mv "$fname" "$newfname"
mv "$fname" "$newfname"
fi
done
for fname in *\ *; do
mv "$fname" "${fname// /_}";
done
echo 'Sorting files into appropriate directories'
mkdir fasta && mv *.fasta fasta
mkdir fastq && mv *.fastq fastq
mkdir bam && mv *.bam bam
mkdir index_bam && mv *.bai index_bam
mkdir vcf && mv *.vcf vcf
mkdir metrics && mv *.csv metrics
echo 'Moving directories into data'
mkdir data
mv bam data
mv fasta data
mv fastq data
mv index_bam data
mv vcf data
echo 'Removing tar file'
rm *.tar
mkdir $dir_name
mv * $dir_name
cd $dir_name/metrics && awk 'FNR==1 && NR!=1{next;}{print}' *.csv > multi_metrics.csv
awk 'BEGIN {FS=","; OFS="\t"} {$1=$1; print}' multi_metrics.csv > multi_metrics1.tsv
sed -e 's/ /_/g' multi_metrics1.tsv > multi_metrics.tsv
rm multi_metrics.csv && rm multi_metrics1.tsv
mv multi_metrics.tsv .. && cd .. && mv multi_metrics.tsv metrics && cd ..
multi_mets=$dir_name/metrics/multi_metrics.tsv
echo 'Done Tidying'
#---------------------------------------
# Generating params_clearlabs.yaml file
#---------------------------------------
echo 'Generating params_clearlabs.yaml file'
get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
fastq="/data/fastq"
alignment="/data/bam"
fasta="/data/fasta"
base=$(get_abs_filename $dir_name)
outbase=$(get_abs_filename $output_dir)
input="\"${base}${fastq}\""
bams="\"${base}${alignment}\""
assemblies="\"${base}${fasta}\""
output="\"${outbase}\""
echo "$output"
sotc="\"$sotc\""
pangolin_docker="\"$pangolin_docker\""
pangolin_version="\"$pangolin_version\""
pangolin_data_version="\"$pdata\""
vadr_docker="\"$vadr_docker\""
samtools_docker="\"$samtools_docker\""
nc_d=$nextclade_docker
nextclade_docker="\"$nextclade_docker\""
touch params_clearlabs.yaml
echo "# The parameters "input", "bams", "assemblies" and "output" are the absolute paths of the folders. Do not include the "/" at the end of the paths." >> params_clearlabs.yaml
echo "input : "$input | tee -a params_clearlabs.yaml
echo "bams : "$bams | tee -a params_clearlabs.yaml
echo "assemblies : "$assemblies | tee -a params_clearlabs.yaml
echo "output : "$output | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "# comma separated list of SOTCs to screen, default as "S:L452R,S:E484K""| tee -a params_clearlabs.yaml
echo "sotc : "$sotc | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "#Do not change the parameter settings below:" | tee -a params_clearlabs.yaml
echo "pangolin_docker : "$pangolin_docker | tee -a params_clearlabs.yaml
echo "pangolin_version : "$pangolin_version | tee -a params_clearlabs.yaml
echo "pangolin_data_version : "$pangolin_data_version | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "vadr_docker : "$vadr_docker | tee -a params_clearlabs.yaml
echo "samtools_docker : "$samtools_docker | tee -a params_clearlabs.yaml
echo "nextclade_docker : "$nextclade_docker | tee -a params_clearlabs.yaml
#---------------------------
# Running Daytona Pipeline
#---------------------------
if [ "$daytona_variation" = "clearlabs" ]; then
##### run clearlabs pipeline
echo "run clearlabs pipeline"
nextflow run ~/Applications/daytona/flaq_sc2_clearlabs2.nf -params-file params_clearlabs.yaml
sort $output_dir/*/report.txt | uniq > $output_dir/sum_report.txt
sed -i '/sampleID\treference/d' $output_dir/sum_report.txt
sed -i '1i sampleID\treference\tstart\tend\tnum_clean_reads\tnum_mapped_reads\tpercent_mapped_clean_reads\tcov_bases_mapped\tpercent_genome_cov_map\tmean_depth\tmean_base_qual\tmean_map_qual\tassembly_length\tnumN\tpercent_ref_genome_cov\tVADR_flag\tQC_flag\tpangolin_version\tlineage\tSOTC' $output_dir/sum_report.txt
awk 'BEGIN {FS=OFS="\t"} {print $1,$8,$10,$14,$15,$17,$18,$19}' $output_dir/sum_report.txt > $output_dir/mid_file
paste -d'\t' $multi_mets $output_dir/mid_file | awk 'BEGIN {FS=OFS="\t"} {print $3,$4,$5,$6,$7,$8,$9,$10,$2}' > $output_dir/daytona_report.tsv
rm $output_dir/mid_file
cat $output_dir/assemblies_pass/*.fa > $output_dir/assemblies_pass.fasta
singularity exec $nc_d nextclade --input-fasta $output_dir/assemblies_pass.fasta --output-csv $output_dir/nextclade_report_clearlabs.csv
mv params_clearlabs.yaml $output_dir
else
###### run normal pipeline
echo "run normal pipeline"
nextflow run ~/Applications/daytona/flaq_sc2_humanclean2.nf -params-file params.yaml
sort ./output/*/report.txt | uniq > ./output/sum_report.txt
sed -i '/sampleID\treference/d' ./output/sum_report.txt
sed -i '1i sampleID\treference\tstart\tend\tnum_raw_reads\tnum_clean_reads\tnum_mapped_reads\tpercent_mapped_clean_reads\tcov_bases_mapped\tpercent_genome_cov_map\tmean_depth\tmean_base_qual\tmean_map_qual\tassembly_length\tnumN\tpercent_ref_genome_cov\tVADR_flag\tQC_flag\tpangolin_version\tlineage\tSOTC' ./output/sum_report.txt
cat ./output/assemblies/*.fa > ./output/assemblies.fasta
singularity exec $nc_d nextclade --input-fasta ./output/assemblies.fasta --output-csv ./output/nextclade_report.csv
mv params_clearlabs.yaml $output
fi
else
#---------------------------------------
# Generating params_clearlabs.yaml file
#---------------------------------------
mkdir $output_dir
get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
fastq="/data/fastq"
alignment="/data/bam"
fasta="/data/fasta"
base=$(get_abs_filename $from_dir)
outbase=$(get_abs_filename $output_dir)
input="\"${base}${fastq}\""
bams="\"${base}${alignment}\""
assemblies="\"${base}${fasta}\""
output="\"${outbase}\""
echo "$output"
sotc="\"$sotc\""
pangolin_docker="\"$pangolin_docker\""
pangolin_version="\"$pangolin_version\""
pangolin_data_version="\"$pdata\""
vadr_docker="\"$vadr_docker\""
samtools_docker="\"$samtools_docker\""
nc_d=$nextclade_docker
nextclade_docker="\"$nextclade_docker\""
touch params_clearlabs.yaml
echo "# The parameters "input", "bams", "assemblies" and "output" are the absolute paths of the folders. Do not include the "/" at the end of the paths." >> params_clearlabs.yaml
echo "input : "$input | tee -a params_clearlabs.yaml
echo "bams : "$bams | tee -a params_clearlabs.yaml
echo "assemblies : "$assemblies | tee -a params_clearlabs.yaml
echo "output : "$output | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "# comma separated list of SOTCs to screen, default as "S:L452R,S:E484K""| tee -a params_clearlabs.yaml
echo "sotc : "$sotc | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "#Do not change the parameter settings below:" | tee -a params_clearlabs.yaml
echo "pangolin_docker : "$pangolin_docker | tee -a params_clearlabs.yaml
echo "pangolin_version : "$pangolin_version | tee -a params_clearlabs.yaml
echo "pangolin_data_version : "$pangolin_data_version | tee -a params_clearlabs.yaml
echo ""| tee -a params_clearlabs.yaml
echo "vadr_docker : "$vadr_docker | tee -a params_clearlabs.yaml
echo "samtools_docker : "$samtools_docker | tee -a params_clearlabs.yaml
echo "nextclade_docker : "$nextclade_docker | tee -a params_clearlabs.yaml
#---------------------------
# Running Daytona Pipeline
#---------------------------
if [ "$daytona_variation" = "clearlabs" ]; then
##### run clearlabs pipeline
echo "run clearlabs pipeline"
nextflow run ~/Applications/daytona/flaq_sc2_clearlabs2.nf -params-file params_clearlabs.yaml
sort $output_dir/*/report.txt | uniq > $output_dir/sum_report.txt
sed -i '/sampleID\treference/d' $output_dir/sum_report.txt
sed -i '1i sampleID\treference\tstart\tend\tnum_clean_reads\tnum_mapped_reads\tpercent_mapped_clean_reads\tcov_bases_mapped\tpercent_genome_cov_map\tmean_depth\tmean_base_qual\tmean_map_qual\tassembly_length\tnumN\tpercent_ref_genome_cov\tVADR_flag\tQC_flag\tpangolin_version\tlineage\tSOTC' $output_dir/sum_report.txt
awk 'BEGIN {FS=OFS="\t"} {print $1,$8,$10,$14,$15,$17,$18,$19}' $output_dir/sum_report.txt > $output_dir/mid_file
paste -d'\t' $multi_mets $output_dir/mid_file | awk 'BEGIN {FS=OFS="\t"} {print $3,$4,$5,$6,$7,$8,$9,$10,$2}' > $output_dir/daytona_report.tsv
rm $output_dir/mid_file
cat $output_dir/assemblies_pass/*.fa > $output_dir/assemblies_pass.fasta
singularity exec $nc_d nextclade --input-fasta $output_dir/assemblies_pass.fasta --output-csv $output_dir/nextclade_report_clearlabs.csv
mv params_clearlabs.yaml $output_dir
else
###### run normal pipeline
echo "run normal pipeline"
nextflow run ~/Applications/daytona/flaq_sc2_humanclean2.nf -params-file params.yaml
sort ./output/*/report.txt | uniq > ./output/sum_report.txt
sed -i '/sampleID\treference/d' ./output/sum_report.txt
sed -i '1i sampleID\treference\tstart\tend\tnum_raw_reads\tnum_clean_reads\tnum_mapped_reads\tpercent_mapped_clean_reads\tcov_bases_mapped\tpercent_genome_cov_map\tmean_depth\tmean_base_qual\tmean_map_qual\tassembly_length\tnumN\tpercent_ref_genome_cov\tVADR_flag\tQC_flag\tpangolin_version\tlineage\tSOTC' ./output/sum_report.txt
cat ./output/assemblies/*.fa > ./output/assemblies.fasta
singularity exec $nc_d nextclade --input-fasta ./output/assemblies.fasta --output-csv ./output/nextclade_report.csv
mv params_clearlabs.yaml $output
fi
fi