forked from jaleezyy/covid-19-signal
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun_signal.sh
executable file
·551 lines (469 loc) · 19.5 KB
/
run_signal.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
#!/bin/bash
################
### SETTINGS ###
################
# DEFAULTS #
############
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" # Get script location which will be the signal base dir
mkdir -p $SCRIPTPATH/.snakemake
# Function to check if element is in an array
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
# Base Parameters #
FASTQ_PAIRS=0
PRIMER_SCHEME=0
CORES="3"
RUNNAME="nml"
METADATA_TSV=0
PDF=false
# SUBSTITUTE PARAMS #
BED=0
AMPLICON=0
CUSTOM=false
# Conda Parameters #
BASE_ENV_PATH="$SCRIPTPATH/.snakemake/conda"
SIGNAL_ENV="signal-1.6.2"
USER_SIGNAL=false
NCOV_ENV="ncov-qc-pangolin4.3" # New 4.3 env to try to fix all the env issues
USER_NCOV=false
# Values to Check #
schemeArray=('articV3' 'articV4' 'articV4.1' 'freed' 'freed_V2_nml' 'resende' 'V2resende')
HELP="
USAGE:
bash $SCRIPTPATH/run_signal.sh -d PATH_TO_PAIRED_FASTQ_DIR -p PRIMER_SCHEME <OPTIONAL FLAGS>
bash $SCRIPTPATH/run_signal.sh --update
Flags:
NEEDED:
-d --directory : Path to paired fastq file directory
-p --primer-scheme : Specify input data primer scheme
Available Primer Schemes: articV3, articV4, articV4.1, freed, freed_V2_nml, resende, V2resende, custom by passing '--bed' and '--amplicon'
SUBSTITUTE (Can be used instead of a primer scheme but must be used together):
--bed : Path to custom primer bed file to be used instead of default schemes
--amplicon : Path to custom amplicon bed file to be used instead of default schemes
OPTIONAL:
-c --cores : Number of Cores to use in Signal. Default is 3
-n --run-name : Run name for final ncov-tools outputs. Default is 'nml'
-m --metadata : Add metadata to the run. Must be in TSV format with atleast a column called 'sample'
--pdf : If you have pdflatex installed runs ncov-tools pdf output
--signal-env : Name of signal conda env. Default is '$BASE_ENV_PATH/signal'
--ncov-tools-env : Name of ncov-tools env. Default is '$BASE_ENV_PATH/ncov-qc-pangolin4'
**NOTE** It is highly recommended to let the script generate the environments as it will
only occur once and you won't have to pass the path each time
OTHER:
--update : Passing --update will update ncov-tools pip dependencies, pangolin and pangoDATA along with this repo and then exit
"
### END DEFAULTS ###
# INPUTS #
##########
# Check for Args #
if [ $# -eq 0 ]; then
echo "$HELP"
exit 0
fi
# Set Arguments #
while [ $# -gt 0 ];
do
if [ "$1" = "--directory" -o "$1" = "-d" ]; then
shift
FASTQ_PAIRS=$1
shift
elif [ "$1" = "--primer-scheme" -o "$1" = "-p" ]; then
shift
PRIMER_SCHEME=$1
shift
elif [ "$1" = "--cores" -o "$1" = "-c" ]; then
shift
CORES=$1
shift
elif [ "$1" = "--bed" ]; then
shift
BED=$1
shift
elif [ "$1" = "--amplicon" ]; then
shift
AMPLICON=$1
shift
elif [ "$1" = "--run-name" -o "$1" = "-n" ]; then
shift
RUNNAME=$1
shift
elif [ "$1" = "--metadata" -o "$1" = "-m" ]; then
shift
METADATA_TSV=$1
shift
elif [ "$1" = "--pdf" ]; then
PDF=true
shift
elif [ "$1" = "--signal-env" ]; then
shift
SIGNAL_ENV=$1
USER_SIGNAL=true
shift
elif [ "$1" = "--ncov-tools-env" ]; then
shift
NCOV_ENV=$1
USER_NCOV=true
shift
elif [ "$1" = "--update" ]; then
shift
# Scripts
cd $SCRIPTPATH
printf "\n Updating Repo at $SCRIPTPATH \n"
git pull
# ncov-tools Environment (not managed by snakemake unfortunately)
eval "$(conda shell.bash hook)"
printf "\n Updating ncov-tools environment at $BASE_ENV_PATH/$NCOV_ENV \n\n"
conda activate $BASE_ENV_PATH/$NCOV_ENV
pip install git+https://github.com/cov-lineages/pango-designation.git --upgrade
pangolin --update
pip install ncov-parser --upgrade
pip install git+https://github.com/jts/ncov-watch.git --upgrade
exit 0
else
echo "ERROR: $1 is not a known argument"
exit 1
fi
done
# CHECK INPUTS #
################
# Directory of fastqs
if [ -d "$FASTQ_PAIRS" ]; then
echo "Directory '$FASTQ_PAIRS' exists"
else
if [ $FASTQ_PAIRS = 0 ]; then
echo "ERROR: Please input a paired fastq directory with '-d'"
echo "$HELP"
exit 1
else
echo "ERROR: Directory '$FASTQ_PAIRS' does not exist"
echo "Please input a valid paired fastq directory"
exit 1
fi
fi
# Primer schemes
if containsElement "$PRIMER_SCHEME" "${schemeArray[@]}"; then
echo "Using primer scheme $PRIMER_SCHEME"
elif [[ $BED != 0 ]] && [[ $AMPLICON != 0 ]]; then
echo "Using custom amplicons"
PATHBED=$(realpath $BED)
PATHAMPLICON=$(realpath $AMPLICON)
CUSTOM=true
else
# Check for custom scheme
if [[ $BED != 0 ]] && [[ $AMPLICON = 0 ]]; then
echo "ERROR: Passed '--bed' without also passing '--amplicon'."
echo " Re-run the command with the missing argument to continue"
exit 1
elif [[ $BED = 0 ]] && [[ $AMPLICON != 0 ]]; then
echo "ERROR: Passed '--amplicon' without also passing '--bed'"
echo " Re-run the command with the missing argument to continue"
exit 1
fi
# Check if no scheme given or if scheme name was wrong
if [ $PRIMER_SCHEME = 0 ]; then
echo "ERROR: Please specify a primer scheme"
echo "Primer schemes available are ${schemeArray[@]}"
exit 1
else
echo "ERROR: $PRIMER_SCHEME unavailable"
echo "Primer schemes available are ${schemeArray[@]}"
exit 1
fi
fi
# Cores input is an int
if [[ $CORES == +([0-9]) ]]; then
echo "Using $CORES cores for analysis"
else
echo "ERROR: Cores input (-c) not an integer"
exit 1
fi
# Metadata handling
if [ $METADATA_TSV = 0 ]; then
:
elif [ -f $METADATA_TSV ]; then
echo "$METADATA_TSV file found, using it"
FULL_PATH_METADATA=$(realpath $METADATA_TSV)
else
echo "ERROR: Metadata input $METADATA_TSV was not found"
exit 1
fi
# Envs needed
envArray=($SIGNAL_ENV $NCOV_ENV 'snpdist_signal' 'qc_summary_signalv2' 'type_variants_signal')
### END INPUTS ###
################################
### OVERALL AUTOMATION SETUP ###
################################
# PATHES #
##########
# Set name for output and full path to reads #
pushd $FASTQ_PAIRS
run_name=${PWD##*/}
fastq_dir_path=$PWD
popd
# If we cannot find the data directory, we will fail out and let user know it isn't there
if [ ! -d "$SCRIPTPATH/data/" ]; then
echo "data/ directory not found in $SCRIPTPATH"
echo "Please run bash $SCRIPTPATH/scripts/get_data_dependencies.sh -d data -a MN908947.3 to make this folder or move an already made data folder here"
exit 1
fi
### END PATHES ###
# CONDA #
#########
eval "$(conda shell.bash hook)"
# Make mamba env or activate it
if [[ $(conda env list | awk '{print $1}' | grep "^mamba-signal"'$') ]]; then
conda activate mamba-signal
else
echo "Generating 'mamba-signal' environment to install needed dependencies"
conda create --yes -n mamba-signal -c conda-forge -c defaults mamba
conda activate mamba-signal
fi
# Conda Env Check #
for ENV in ${envArray[@]}; do
# If user given, don't add BASE_ENV_PATH to it
if [[ "$USER_SIGNAL" = true && "$ENV" = "$SIGNAL_ENV" ]] || [[ "$USER_NCOV" = true && "$ENV" = "$NCOV_ENV" ]]; then
FULL_ENV="$ENV"
else
FULL_ENV="$BASE_ENV_PATH/$ENV"
fi
# Check if env exists in user envs. NOTE if it is a env not listed in `conda env list` it will error out
if [[ $(conda env list | awk '{print $1}' | grep "^$FULL_ENV"'$') ]]; then
echo "$FULL_ENV found"
else
echo "Conda env '$FULL_ENV' wasn't found in the env list. Attempting to make the environment in $SCRIPTPATH/.snakemake"
mamba env create -f=$SCRIPTPATH/conda_envs/$ENV.yaml -p $FULL_ENV
fi
done
# Deactivate mamba, not needed anymore once envs made
conda deactivate
### END CONDA ###
# FINAL OUTPUT LOCATION #
#########################
timestamp=`date +%b%d_%H%M`
root="signal_${run_name}_${timestamp}"
mkdir -p $root
cd $root
# Get output root full path for later parts to the root directory #
root_path=$PWD
### END OUTPUT LOCATION ###
# ALL SNAKEMAKE CONFIGURATIONS #
################################
SIGNAL_PROFILE="$SCRIPTPATH/resources/profile"
cp "$SCRIPTPATH/resources/profile/parameters.yaml" .
SIGNAL_CONFIG="parameters.yaml"
# Get always current ncov-tools with clone and copy resources as we write to the config
echo "Setting up files in $root_path"
git clone --depth 1 https://github.com/jts/ncov-tools
# Copy the ncov-tools config as we will write data to it later
cp -r $SCRIPTPATH/resources/ncov-tools_files/* ./ncov-tools/
# Metadata #
if [ $METADATA_TSV = 0 ]; then
sed -i -e 's/^metadata/#metadata/' ./ncov-tools/config.yaml
cleanup_metadata=""
else
# Check if metadata has correct ncov-tools columns, if not we only append it to final output csv
if $(head -n 1 $FULL_PATH_METADATA | grep -q ct) && $(head -n 1 $FULL_PATH_METADATA | grep -q date); then
echo "Metadata contains correct ncov-tools headers"
else
echo "Metadata is missing ncov-tools headers, appending it only to final QC output"
sed -i -e 's/^metadata/#metadata/' ./ncov-tools/config.yaml
fi
cp $FULL_PATH_METADATA ./ncov-tools/metadata.tsv
cleanup_metadata="--sample_sheet $FULL_PATH_METADATA"
fi
# Echo in correct data locations to parameters config
# Done as for the primer pairs to work we need the full path
if [ "$CUSTOM" = true ]; then
# SIGNAL Parameters
echo "scheme_bed: '$PATHBED'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: '$PATHAMPLICON'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: ''" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $PATHAMPLICON" >> ./ncov-tools/config.yaml
echo "primer_bed: $PATHBED" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$PATHBED"
elif [ "$PRIMER_SCHEME" == "articV3" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/artic_v3/nCoV-2019.primer.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/artic_v3/ncov-qc_V3.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/articV3_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/artic_v3/ncov-qc_V3.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/artic_v3/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/artic_v3/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "articV4" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/artic_v4/nCoV-2019.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/artic_v4/ncov-qc_V4.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/articV4_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/artic_v4/ncov-qc_V4.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/artic_v4/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/artic_v4/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "articV4.1" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/artic_v4.1/nCoV-2019.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/artic_v4.1/ncov-qc_V4.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/articV4_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/artic_v4.1/ncov-qc_V4.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/artic_v4.1/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/artic_v4.1/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "freed" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/freed/nCoV-2019.primer.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/freed/ncov-qc_freed.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/freed_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/freed/ncov-qc_freed.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/freed/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/freed/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "freed_V2_nml" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/freed_V2_nml/nCoV-2019.primer.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/freed_V2_nml/ncov-qc_freed.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/freed_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/freed_V2_nml/ncov-qc_freed.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/freed_V2_nml/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/freed_V2_nml/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "resende" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/2kb_resende/nCoV-2019.primer.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/2kb_resende/ncov-qc_resende.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/resende_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/2kb_resende/ncov-qc_resende.scheme.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/2kb_resende/nCoV-2019.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="$SCRIPTPATH/resources/primer_schemes/2kb_resende/nCoV-2019.bed"
elif [ "$PRIMER_SCHEME" == "V2resende" ]; then
# SIGNAL Parameters
echo "scheme_bed: 'resources/primer_schemes/2kb_resende_v2/nCoV-2019.primer.bed'" >> $SIGNAL_CONFIG
echo "amplicon_loc_bed: 'resources/primer_schemes/2kb_resende_v2/ncov-qc_resende.scheme.bed'" >> $SIGNAL_CONFIG
echo "primer_pairs_tsv: '-f $SCRIPTPATH/resources/primer_pairs/resende_primer_pairs.tsv'" >> $SIGNAL_CONFIG
# NCOV-TOOLS Parameters
echo "amplicon_bed: $SCRIPTPATH/resources/primer_schemes/2kb_resende_v2/nCoV-2019.bed" >> ./ncov-tools/config.yaml
echo "primer_bed: $SCRIPTPATH/resources/primer_schemes/2kb_resende_v2/ncov-qc_resende.scheme.bed" >> ./ncov-tools/config.yaml
# Clean Up
CLEANUP_BED="primer_bed: $SCRIPTPATH/resources/primer_schemes/2kb_resende_v2/ncov-qc_resende.scheme.bed"
fi
echo "run_name: $RUNNAME" >> ./ncov-tools/config.yaml
### END SNAKEMAKE CONFIGS ###
# GET WANTED SIGNAL #
ln -s $SCRIPTPATH/* .
##################
### RUN SIGNAL ###
##################
# Activate env
if [ "$USER_SIGNAL" = true ]; then
conda activate $SIGNAL_ENV
else
conda activate $BASE_ENV_PATH/$SIGNAL_ENV
fi
# Echo out relevant info to double check it looks ok
echo "Running ${run_name} with scheme ${PRIMER_SCHEME}"
echo "config: $SIGNAL_CONFIG"
echo "profile: $SIGNAL_PROFILE"
# Run signal and postprocessing
bash generate_sample_table.sh -d $fastq_dir_path
snakemake -s Snakefile --configfile $SIGNAL_CONFIG --profile $SIGNAL_PROFILE --cores=$CORES --conda-prefix=$SCRIPTPATH/.snakemake/conda all
snakemake -s Snakefile --configfile $SIGNAL_CONFIG --profile $SIGNAL_PROFILE --cores=$CORES --conda-prefix=$SCRIPTPATH/.snakemake/conda postprocess
##################
### NCOV-TOOLS ###
##################
# Run NCOV-Tools on separate script at the moment as it won't work on same one. IDK why the same code won't work here
if [ "$USER_NCOV" = true ]; then
FULL_NCOV_ENV="$NCOV_ENV"
else
FULL_NCOV_ENV="$BASE_ENV_PATH/$NCOV_ENV"
fi
bash nml_automation/run_ncov-tools.sh $CORES $SCRIPTPATH $FULL_NCOV_ENV $PDF
##################
### FINAL DATA ###
##################
# Set Up #
##########
cd $root_path
mkdir -p ./summary_csvs
# Setting up relative paths from the root dir to needed data
ncov_qc="./ncov-tools/qc_reports/${RUNNAME}_summary_qc.tsv"
ncov_neg="./ncov-tools/qc_reports/${RUNNAME}_negative_control_report.tsv"
ref="./data/MN908947.3.fasta"
pangolin="./ncov-tools/lineages/${RUNNAME}_lineage_report.csv"
# Check to see if we have a negative control. If so do nothing. If not make a "fake" one to not error out
if [ -f "$ncov_neg" ];
then
echo "Negative contol data found"
else
touch ./ncov-tools/qc_reports/${RUNNAME}_negative_control_report.tsv
fi
### END Set Up ###
# QC Summary #
##############
conda activate $BASE_ENV_PATH/qc_summary_signalv2
for RESULT in $(ls -d signal_results/*/)
do
# Getting and keeping track of the name
found_name="$(basename $RESULT)"
relative_sample_path="$RESULT/core/"
snpeff="./ncov-tools/qc_annotation/${found_name}_aa_table.tsv"
echo "Processing $found_name"
# gzip variants vcf from freebayes to allow it to go into summary pipeline
gzip $RESULT/freebayes/${found_name}.variants.norm.vcf
# Run the python summary
python ./nml_automation/qc.py --illumina \
--outfile ./summary_csvs/${found_name}.qc.csv \
--sample ${found_name} \
--ref ${ref} \
--bam ${relative_sample_path}${found_name}_viral_reference.mapping.primertrimmed.sorted.bam \
--fasta ${relative_sample_path}${found_name}.consensus.fa \
--vcf $RESULT/freebayes/${found_name}.variants.norm.vcf.gz \
--pangolin ${pangolin} \
--ncov_summary ${ncov_qc} \
--ncov_negative ${ncov_neg} \
--revision v1.6.2 \
--pcr_bed ./resources/pcr_primers.bed \
--scheme $PRIMER_SCHEME \
--scheme_bed $CLEANUP_BED \
--script_name covid-19-signal \
--sequencing_technology illumina \
--snpeff_tsv $snpeff \
$cleanup_metadata
done
# Concatenate all summaries
csvtk concat ./summary_csvs/*.qc.csv > ./summary_csvs/combined.csv
# Check negative controls
python ./nml_automation/negative_control_fixes.py --qc_csv ./summary_csvs/combined.csv --output_prefix $RUNNAME
# SNP DISTS #
#############
conda deactivate
conda activate $BASE_ENV_PATH/snpdist_signal
if [ -f "./ncov-tools/qc_analysis/${RUNNAME}_aligned.fasta" ];
then
snp-dists ./ncov-tools/qc_analysis/${RUNNAME}_aligned.fasta > matrix.tsv
else
echo "No ./ncov-tools/qc_analysis/${RUNNAME}_aligned.fasta, skipping the snp-dist check"
fi
# TYPE VARIANTS #
#################
conda deactivate
conda activate $BASE_ENV_PATH/type_variants_signal
cat ./ncov-tools/files/*.fasta > all_seq.fasta
mafft --auto --keeplength --addfragments all_seq.fasta ./ncov-tools/nCoV-2019.reference.fasta > aligned_mafft.fasta
for CSV in $SCRIPTPATH/resources/variant_profile_csvs/*.csv
do
CSV_NAME="$(basename $CSV)"
type_variants.py --fasta-in aligned_mafft.fasta --variants-config $CSV --reference ./ncov-tools/nCoV-2019.reference.fasta --variants-out $CSV_NAME --append-genotypes
done
### END RUNNING ###