-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsh_WES.sh
More file actions
executable file
·1560 lines (1381 loc) · 58.8 KB
/
sh_WES.sh
File metadata and controls
executable file
·1560 lines (1381 loc) · 58.8 KB
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# shellcheck disable=SC2028,SC2030,SC2031
#
# Usage: sh_WES.sh </path/to/fastq(.gz)/folder> </path/to/destination/folder> [/path/to/config/file.ini]
#
##############################################################
## Description ##
##############################################################
#
# This script will process fastq(.gz) files and align them to
# a reference genome using bowtie2. It will then use Picard
# and GATK following the June 2016 best practices workflow.
# SNPs will then be annotated using ANNOVAR.
#
## Options:
#
# --help : Display help message.
# --version : Display version number.
#
##############################################################
## Configurable variables ##
##############################################################
#
#
## General options
#
# Maximum number of threads (or CPUs) to request and allocate to programs.
# In some case less than this value may automatically be allowed.
threads=$(nproc --all --ignore=1)
#
# Maximum amount of memory (in GB) to request and allocate to programs.
# In some case less than this value may automatically be allowed.
mem="128"
#
# Log folder, will be created in your destination folder.
logs="logs"
#
# Advanced: Path to temporary folder. Useful if your cluster system have a fast local I/O disk.
# Leave empty to use the destination folder. In all cases temporary files will be purged at the end of the script.
tmp="\${L_SCRATCH_JOB}"
#
# Debug mode.
# For troubleshooting only. Will keep all intermediate files,
# sbatch files and logs.
# 0 = No ; 1 = Yes
debug="0"
#
#
## SLURM options
#
# email to use to receive SLURM notifications.
# By default only send FAIL notifications for all jobs and FAIL,END for the last one.
SLURMemail=""
#
# SLURM account, partition and qos settings if required.
SLURMaccount=""
SLURMpartition=""
SLURMqos=""
#
# Custom commands to run before any other program.
# Use it to load modules for example:
# customcmd="module load R"
customcmd=""
#
#
## FastQ options
#
# If sample files are split into multiple FastQ files, merge them.
# 0 = No ; 1 = Yes
merge="0"
#
# Process undetermined/unmatched files (tag not properly recognized).
# 0 = No ; 1 = Yes
underdet="0"
#
# Process BLANK files (Sample name should be "BLANK").
# 0 = No ; 1 = Yes
blank="0"
#
# Perform fastqc on fastq files.
# If sequences are trimmed, fastqc will be performed on trimmed sequences.
# 0 = No ; 1 = Yes
fastqc="0"
#
# Trim sequences with Trimmomatic.
# 0 = No ; 1 = Yes
trim="0"
#
# Trimmomatic folder, should contain a trimmomatic.jar file
Trimmomatic="/Tools/Trimmomatic"
#
# Keep unpaired trimmed sequences.
# 0 = No ; 1 = Yes
unpaired="0"
#
#
## Alignment options
#
# Filter by MapQ quality score to remove poor aligned reads.
# samtools defaut is 0 (no filtering), 10<MapQ<20 is advised.
mapq="10"
#
# bowtie2 indexed reference genome location.
bt_refgenome="/Tools/RefGenomes/Homo_sapiens/UCSC/hg19/Sequence/Bowtie2Index/genome"
#
# Read group parameters.
# Library: if empty LB will be set to the destination folder name.
LB=""
#
# Platform used to produce the reads.
# Valid values: CAPILLARY, LS454, ILLUMINA, SOLID, HELICOS, IONTORRENT and PACBIO.
PL="ILLUMINA"
#
#
## GATK options
#
# Picard-tools picard.jar location.
picard="/Tools/Picard/picard.jar"
#
# GATK GenomeAnalysisTK.jar file location.
gatk="/Tools/GATK/GenomeAnalysisTK.jar"
#
# Reference genome (fasta) file.
# It must be the same one that was indexed by bowtie2 for alignment
fasta_refgenome="/Tools/RefGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa"
#
# List of the targeted intervals sequenced.
# This is necessary as only about 60-70% of all the reads will end up in exonic regions and the rest may align anywhere else in the genome.
# To restrict the output to exonic sequences, generate a file containing for example all the exons plus 50bp at each end for getting splice site information as well.
# This can be done using the UCSC Table Browser (http://genome.ucsc.edu/cgi-bin/hgTables?command=start).
# Choose the hg19 assembly of the human genome and set the track to RefSeq genes and the table to refGene.
# Use BED format as output format and assign the file an appropriate name.
# By clicking on get output, several more options can be made: Choose "create one bed record per Exon plus 50bp at each end" and save the file.
# A .bed file specific to the library preparation kit targets can be used instead if available (ex: https://earray.chem.agilent.com/suredesign/search.htm ).
regions="/Tools/AgilentBedFiles/SureSelect_Human_All_Exon_V6+UTR_r2/S07604624_Covered.bed"
#
# VQSR reference files (from GATK bundle).
# HapMap vcf file location (SNP).
hapmap="/Tools/GATK/hapmap_3.3.hg19.sites.vcf"
# 1000 genome omni vcf file location (SNP).
omni="/Tools/GATK/1000G_omni2.5.hg19.sites.vcf"
# 1000 genomes phase 1 indels vcf file location.
onekGph1="/Tools/GATK/1000G_phase1.snps.high_confidence.hg19.sites.vcf"
# dbSNP known SNPs .vcf file location.
dbSNP="/Tools/GATK/dbsnp_138.hg19.vcf"
# Mills and 1000 genomes gold standard vcf file location.
millsgold="/Tools/GATK/Mills_and_1000G_gold_standard.indels.hg19.sites.vcf"
#
# Indel realignment is generally no longer necessary for variant discovery,
# unless in specific uncommon use cases.
# 0 = No ; 1 = Yes
realign="0"
#
# Stop after .g.vcf creation (no filtering, no annotation).
# Yes = 1 ; No = 0
gvcf="0"
#
# PED file to specify family relations if available.
ped=$([ -f "${1}/$(basename "${1}").ped" ] && echo "${1}/$(basename "${1}").ped")
#
# Folder containing gVCFs to be used as a learning control for VQSR calibration.
# Leave empty if you have a ready to use .vcf file and use popgvcf below.
popfolder=""
#
# VCF file to be used as a learning control for VQSR calibration.
popgvcf=""
#
# Compute coverage (slow).
# Yes = 1 ; No = 0
coverage="1"
#
#
## Annovar options
#
# Annovar folder (containing humandb folder).
annovar="/Tools/annovar"
#
# Genome build version.
# Name of the genome assembly used. Can also be determined automatically from your directory structure (see examples).
# examples:
# buildver="hg19"
# buildver=$(echo ${fasta_refgenome} | sed 's/\/Sequence.*//g' | awk -F/ '{print $NF}')
buildver=$(echo ${fasta_refgenome} | sed 's/\/Sequence.*//g' | awk -F/ '{print $NF}')
#
# Protocols to be used for annotation.
protocol="refGene,phastConsElements46way,genomicSuperDups,gwasCatalog,esp6500siv2_all,1000g2015aug_all,exac03,gme,kaviar_20150923,avsnp150,dbnsfp35a,dbnsfp31a_interpro,dbscsnv11,clinvar_20200316,intervar_20180118,hrcr1,revel,mcap,gnomad211_exome"
#
# Matching operations to be used for annotation.
operation="g,r,r,r,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f"
#
#
## Notifications options
#
# Event name used in your webhooks or IFTTT recipes.
# The IFTTT maker channel will look for the combination private key + event name to then trigger your recipe.
# You can then create a recipe to send an email, a text message or a push notification.
# In the case of a Slack webhook this will be used in the message title
notifevent="SNPCalling"
#
# Trigger a Slack Webhook when script is done.
# You must create an "Incoming WebHooks" associated to your slack workspace on https://slack.com/apps
# Copy your full private webhook URL here. Leave blank to disable this function.
# slackwebhookURL="https://hooks.slack.com/services/T5HF5GTUK85/AHUIK456HJG/GSD27f5gGQ7SD5r2fg" # Not a real webhook URL, you have to use your own private one.
slackwebhookURL=""
#
# Trigger IFTTT when script is done.
# You must register the "Maker channel" on https://ifttt.com/maker and create an event (limit of 3 free event since September 2020...)
# Copy your private key here. Leave blank to disable this function.
# iftttkey="AbCd_15CdhUIvbsFJTHGMcfgjsdHRTgcyjt" # Not a real key, you have to use your own private one.
iftttkey=""
#
#
## Setup done. You should not need to edit below this point ##
# Help!
if [ "${1}" = "--help" ] || [ "${2}" = "--help" ] || [ "${3}" = "--help" ] || [ "${4}" = "--help" ]
then
echo "Usage: $(basename "${0}") </path/to/fastq(.gz)/folder> </path/to/destination/folder> [/path/to/config/file.ini]"
echo ""
echo "Description"
echo ""
echo "This script will process fastq(.gz) files and align them to"
echo "a reference genome using bowtie2. It will then use Picard"
echo "and GATK following the June 2016 best practices workflow."
echo "SNPs will then be annotated using ANNOVAR."
echo ""
echo "Options:"
echo "$(basename "${0}") --help : Display this help message."
echo "$(basename "${0}") --version : Display version number."
echo ""
exit
fi
# Version
if [ "${1}" = "--version" ] || [ "${2}" = "--version" ] || [ "${3}" = "--version" ] || [ "${4}" = "--version" ]
then
echo "$(basename "${0}") version 2.0.2"
echo "Only for GATK 3.X ( 3.8.1 tested, download from https://software.broadinstitute.org/gatk/download/archive )"
echo "Major code cleaning (2.0.1)"
echo ".g.vcf support (2.0)"
exit
fi
# Get fastq directory
dir="${1}"
# Get destination directory
dir2="${2}"
# Get config file location
config="${3}"
# Check paths and trailing / in directories
if [ -z "${dir}" ] || [ -z "${dir2}" ]
then
${0} --help
exit
fi
if [ "${dir: -1}" = "/" ]
then
dir=${dir%?}
fi
if [ "${dir2: -1}" = "/" ]
then
dir2=${dir2%?}
fi
if [ -n "${config}" ]
then
if [ "${config: -4}" = ".ini" ]
then
# shellcheck disable=SC1090
source "${config}"
else
echo "Invalid config file detected. Is it an .ini file?"
echo ""
${0} --help
exit
fi
fi
if [ -n "${popgvcf}" ]
then
if [ "${popgvcf: -4}" != ".vcf" ]
then
echo "Invalid population vcf file detected. Is ${popgvcf} a .vcf file?"
exit
fi
fi
if [ -n "${popgvcf}" ] && [ -n "${popfolder}" ]
then
echo "Error, either \"popgvcf\" or \"popfolder\" should be defined"
exit
fi
# GATK version check
if [ "$(basename ${gatk})" = "GenomeAnalysisTK.jar" ]
then
vgatk="3"
elif [ "$(basename ${gatk})" = "gatk" ]
then
vgatk="4"
echo "GATK 4.X detected, pipeline not yet compatible."
echo "Only for GATK 3.X ( 3.8.1 tested, download from https://software.broadinstitute.org/gatk/download/archive )"
exit
fi
# Test if sequence files are .fastq or .fastq.gz
fastqgz=$(find -L "${dir}" -maxdepth 1 -name '*.fastq.gz')
fastq=$(find -L "${dir}" -maxdepth 1 -name '*.fastq')
if [ -z "${fastqgz}" ] && [ -z "${fastq}" ]
then
echo ""
echo "No .fastq or .fastq.gz files are present in ${dir}/"
exit
fi
if [ -n "${fastqgz}" ] && [ -n "${fastq}" ]
then
echo ""
echo "Both .fastq and .fastq.gz files are present in ${dir}/"
echo "Existing .fastq.gz files will now be converted to .fastq files"
gunzip "${dir}/*.fastq.gz"
fileext=".fastq"
fi
if [ -n "${fastqgz}" ] && [ -z "${fastq}" ]
then
fileext=".fastq.gz"
fi
if [ -n "${fastq}" ] && [ -z "${fastqgz}" ]
then
fileext=".fastq"
fi
# Displaying variables to shell
echo ""
echo "-- Informations --"
echo ""
if [ -z "${config}" ]
then
echo "You can change the following parameters by using a custom config file"
else
echo "You are using a custom config file: ${config}"
fi
echo "Your ${fileext} files are located in ${dir}/"
echo "Final results will be located in ${dir2}/"
echo "Log files will be created in ${dir2}/${logs}"
echo ""
echo "-- Alignment options"
echo ""
echo "Using ${bt_refgenome} as reference genome"
if [ ${underdet} -eq "0" ]
then
echo "Undetermined files will not be processed"
fi
if [ ${blank} -eq "1" ]
then
echo "\"BLANK\" files will be processed"
fi
if [ ${merge} -eq "1" ]
then
echo "Individual files will also be merged into a big \"MERGED\" file"
fi
if [ ${trim} -eq "1" ]
then
echo "Sequence will be trimmed"
echo "Trimmomatic is installed in ${Trimmomatic}"
fi
if [ ${mapq} = "0" ] || [ -z ${mapq} ]
then
echo "MapQ score will not be used to filter reads"
else
echo "Reads with a MapQ score <${mapq} will be discarded"
fi
echo ""
echo "-- GATK options"
echo ""
echo "Picard-tools are installed in ${picard}"
echo "GATK version ${vgatk} is installed in ${gatk}"
echo "ANNOVAR is installed in ${annovar}"
echo "Using ${fasta_refgenome} as reference genome"
echo ""
if [ ${realign} -eq "1" ]
then
echo "Local realigment around known indels will be performed"
fi
echo "Joint Genotyping will be performed using:"
echo "Mills and 1000 genomes gold standard, located at ${millsgold}"
echo "1000 genomes phase 1 database, located at ${onekGph1}"
echo ""
echo "VQSR calibration will be performed using:"
if [ -n "${popgvcf}" ]
then
echo "A previously generated file, ${popgvcf}"
else
echo "A newly generated file using g.vcf files present in ${popfolder}"
fi
echo ""
echo "Regions of interest are defined in ${regions}"
echo ""
echo "-- Hardware"
echo ""
echo "Up to ${threads} CPUs will be used"
echo "Up to ${mem}GB of memory will be allocated to the programs"
echo ""
echo "---------------"
# Initialize
[ -f "${dir2}/files1" ] && rm "${dir2}/files1"
[ -f "${dir2}/files2" ] && rm "${dir2}/files2"
[ -f "${dir2}/Fastqs" ] && rm "${dir2}/Fastqs"
[ -d "${dir2}/logs" ] && rm -rf "${dir2}/logs"
mkdir -p "${dir2}/"
mkdir -p "${dir2}/${logs}"
if [ -z "${tmp}" ]
then
tmp="${dir2}/tmp"
fi
# Concatenate files if split
if [ "${merge}" = "1" ]
then
echo ""
echo "-- Merging files --"
echo ""
mkdir -p "${dir}/FastQbackup/"
filestomergeR1=$(ls "${dir}"/*_L[0-9][0-9][0-9]_R1)
filestomergeR2=$(ls "${dir}"/*_L[0-9][0-9][0-9]_R2)
echo "Processing R1 files"
echo ""
for i in ${filestomergeR1}
do
sampleoutput="${i//_L[0-9][0-9][0-9]_R1/_R1}"
echo "Processing ${i}"
cat "${i}" >> "${sampleoutput}"
mv "${i}" "${dir}/FastQbackup/"
done
echo ""
echo "Processing R2 files"
echo ""
for i in ${filestomergeR2}
do
sampleoutput="${i//_L[0-9][0-9][0-9]_R2/_R2}"
echo "Processing ${i}"
cat "${i}" >> "${sampleoutput}"
mv "${i}" "${dir}/FastQbackup/"
done
echo ""
echo "-- Files merged --"
fi
if [ "${underdet}" = "0" ]
then
if [ "${blank}" = "0" ]
then
# Remove all Undetermined_* and BLANK* files
find -L "${dir}" -maxdepth 1 -name '*_R1*' -not -name '*ndetermined*' -not -name '*nmatched*' -not -name 'BLANK*' | sed 's#.*/##' | sort -n > "${dir2}/files1"
find -L "${dir}" -maxdepth 1 -name '*_R2*' -not -name '*ndetermined*' -not -name '*nmatched*' -not -name 'BLANK*' | sed 's#.*/##' | sort -n > "${dir2}/files2"
paste "${dir2}/files1" "${dir2}/files2" > "${dir2}/Fastqs"
else
# Remove all Undetermined_* files
find -L "${dir}" -maxdepth 1 -name '*_R1*' -not -name '*ndetermined*' -not -name '*nmatched*' | sed 's#.*/##' | sort -n > "${dir2}/files1"
find -L "${dir}" -maxdepth 1 -name '*_R2*' -not -name '*ndetermined*' -not -name '*nmatched*' | sed 's#.*/##' | sort -n > "${dir2}/files2"
paste "${dir2}/files1" "${dir2}/files2" > "${dir2}/Fastqs"
fi
else
if [ "${blank}" = "0" ]
then
# Remove all BLANK* files
find -L "${dir}" -maxdepth 1 -name '*_R1*' -not -name 'BLANK*' | sort -n | sed 's#.*/##' > "${dir2}/files1"
find -L "${dir}" -maxdepth 1 -name '*_R2*' -not -name 'BLANK*' | sort -n | sed 's#.*/##' > "${dir2}/files2"
paste "${dir2}/files1" "${dir2}/files2" > "${dir2}/Fastqs"
else
# Process all the files!
find -L "${dir}" -maxdepth 1 -name '*_R1*' | sed 's#.*/##' | sort -n > "${dir2}/files1"
find -L "${dir}" -maxdepth 1 -name '*_R2*' | sed 's#.*/##' | sort -n > "${dir2}/files2"
paste "${dir2}/files1" "${dir2}/files2" > "${dir2}/Fastqs"
fi
fi
######################
## Processing samples
######################
echo ""
echo "-- Queuing sample jobs --"
while read -r line;
do
# General variables
read1=$(echo "${line}" | cut -f1)
read2=$(echo "${line}" | cut -f2)
samplename=$(echo "${read1}" | awk -F_R1 '{print $1}')
echo ""
echo -e "\t-- Processing" "${samplename}"
######################
## Prepare and queue trimming job
job="trim"
# Trimmomatic variables
trimout1="${dir2}/$(basename "${read1}" ${fileext}).trim.fastq"
trimout2="${dir2}/$(basename "${read2}" ${fileext}).trim.fastq"
if [ -n "${unpaired}" ] && [ "${unpaired}" = "1" ]
then
unpaired1="${dir2}/$(basename "${read1}" ${fileext}).unpaired.fastq" # Save unpaired reads
unpaired2="${dir2}/$(basename "${read2}" ${fileext}).unpaired.fastq" # Save unpaired reads
else
unpaired1="/dev/null" # Unpaired reads are discarded
unpaired2="/dev/null" # Unpaired reads are discarded
fi
if [ -n "${trim}" ] && [ ${trim} -eq "1" ]
then
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH $(if [ -n "${mem}" ] && [ ${mem} -gt "8" ]; then echo "--mem=8000"; else echo "--mem=${mem}000"; fi) $(if [ -n "${threads}" ] && [ "${threads}" -gt "2" ]; then echo "--cpus-per-task=2"; else echo "--cpus-per-task=${threads}"; fi)"
echo "#SBATCH --requeue"
echo "#SBATCH --time=3:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
# Trim fastq files with trimmomatic
echo "java -Xmx$(if [ -n "${mem}" ] && [ ${mem} -gt "8" ]; then echo "8"; else echo "${mem}"; fi)g -Djava.io.tmpdir=${tmp} -jar ${Trimmomatic}/trimmomatic.jar PE -threads $(if [ -n "${threads}" ] && [ "${threads}" -gt "2" ]; then echo "2"; else echo "${threads}"; fi) -phred33 ${dir}/${read1} ${dir}/${read2} ${trimout1} ${unpaired1} ${trimout2} ${unpaired2} ILLUMINACLIP:${Trimmomatic}/adapters/TruSeq3-PE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36 || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBtrim=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
echo -e "\t Trimming job queued"
else
# Need to rename some variables
trimout1="${dir}/${read1}"
trimout2="${dir}/${read2}"
fi
######################
## Prepare and queue alignment job
job="align"
# bowtie2 variables
samout=$(basename "${read1}" | sed "s/_R1${fileext}/.sam/g")
bamout=$(basename "${read1}" | sed "s/_R1${fileext}/.bam/g")
bamsortedout=$(basename "${read1}" | sed "s/_R1${fileext}/.sorted.bam/g")
if [ -z "$LB" ]
then
LB=$(basename "${dir2}")
fi
SM=$(echo "${read1}" | awk -F_ '{print $1}')
if [ "${fileext}" = ".fastq.gz" ]
then
CN=$(gzip -cd "${dir}"/"${read1}" | head -n 1 | awk -F: '{print $1}' | sed 's/@//')
PU=$(gzip -cd "${dir}"/"${read1}" | head -n 1 | awk -F: '{print $3}')
else
CN=$(head -n 1 "${dir}"/"${read1}" | awk -F: '{print $1}' | sed 's/@//')
PU=$(head -n 1 "${dir}"/"${read1}" | awk -F: '{print $3}')
fi
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH --mem=${mem}000 --cpus-per-task=${threads}"
echo "#SBATCH --requeue"
echo "#SBATCH --time=8:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMaccount}" ]
then
echo "#SBATCH --account=${SLURMaccount}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# Require previous job successful completion
if [ -n "${SBtrim}" ]
then
echo "#SBATCH --dependency=afterok:${SBtrim##* }"
fi
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
# Perform alignment with bowtie
echo "bowtie2 -p ${threads} --phred33 --rg-id ${LB}_${SM} --rg CN:${CN} --rg LB:${LB} --rg PL:${PL} --rg PU:${PU} --rg SM:${SM} -x ${bt_refgenome} -S ${dir2}/${samout} -1 ${trimout1} -2 ${trimout2} || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Convert .sam to .bam with optional filter on MapQ quality score
echo "samtools view -bS -q ${mapq} -o ${dir2}/${bamout} ${dir2}/${samout} || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Sort .bam file
echo "samtools sort -@ ${threads} -o ${dir2}/${bamsortedout} -O bam -T ${tmp} ${dir2}/${bamout} || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Index sorted .bam
echo "samtools index ${dir2}/${bamsortedout} || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove trim.fastq files from destination folder
if [ "${trim}" = "1" ] && [ "${fastqc}" = "0" ]
then
echo "rm ${trimout1} ${trimout2}"
fi
# Remove .sam file
echo "rm ${dir2}/${samout}"
# Remove unsorted .bam file
echo "rm ${dir2}/${bamout}"
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBalign=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
if [ -n "${SBalign##* }" ]
then
SBalignIDs=${SBalignIDs}:${SBalign##* }
fi
echo -e "\t Alignment job queued"
######################
## Run fastqc to generate quality control files
if [ -n "${fastqc}" ] && [ ${fastqc} -eq "1" ]
then
job="fqc"
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH $(if [ -n "${mem}" ] && [ ${mem} -gt "4" ]; then echo "--mem=4000"; else echo "--mem=${mem}000"; fi) $(if [ -n "${threads}" ] && [ "${threads}" -gt "1" ]; then echo "--cpus-per-task=1"; else echo "--cpus-per-task=${threads}"; fi)"
echo "#SBATCH --requeue"
echo "#SBATCH --time=1:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# Require previous job successful completion
if [ -n "${SBalign}" ]
then
echo "#SBATCH --dependency=afterok:${SBalign##* }"
fi
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
echo "fastqc -o ${dir2}/ --noextract ${trimout1} ${trimout2} || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove trim.fastq files from destination folder
if [ "${trim}" = "1" ]
then
echo "rm ${trimout1} ${trimout2}"
fi
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBfqc=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
if [ -n "${SBfqc##* }" ]
then
SBfqcIDs=${SBfqcIDs}:${SBfqc##* }
fi
echo -e "\t FastQC job queued"
fi
######################
## Prepare and queue duplicates marking job
job="dup"
# Picard variables
dupout="$(basename "${bamsortedout}" .bam).nodup.bam"
dupbai="$(basename "${bamsortedout}" .bam).nodup.bai"
dupmetrics="$(basename "${read1}" _R1${fileext}).dupmetrics"
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH $(if [ -n "${mem}" ] && [ ${mem} -gt "64" ]; then echo "--mem=64000"; else echo "--mem=${mem}000"; fi)"
echo "#SBATCH --requeue"
echo "#SBATCH --time=4:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMaccount}" ]
then
echo "#SBATCH --account=${SLURMaccount}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# Require previous job successful completion
echo "#SBATCH --dependency=afterok:${SBalign##* }"
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
# Use picard tools MarkDuplicates with removal of duplicates and index creation options.
echo "java -Xmx$(if [ -n "${mem}" ] && [ ${mem} -gt "64" ]; then echo "64"; else echo "${mem}"; fi)g -Djava.io.tmpdir=${tmp} -jar ${picard} MarkDuplicates I=${dir2}/${bamsortedout} O=${dir2}/${dupout} METRICS_FILE=${dir2}/${logs}/${dupmetrics} REMOVE_DUPLICATES=true VALIDATION_STRINGENCY=LENIENT CREATE_INDEX=true SORTING_COLLECTION_SIZE_RATIO=0.20 || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove sorted files
echo "rm ${dir2}/${bamsortedout}"
echo "rm ${dir2}/${bamsortedout}.bai"
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBdup=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
if [ -n "${SBdup##* }" ]
then
SBdupIDs=${SBdupIDs}:${SBdup##* }
fi
echo -e "\t Duplicates marking job queued"
## Start GATK best practice (June 2016) Somatic short variant discovery (SNVs + Indels)
######################
## Local realignment around indels
# Note that indel realignment is no longer necessary for variant discovery if you plan to use a variant
# caller that performs a haplotype assembly step, such as HaplotypeCaller or MuTect2. However it is still
# required when using legacy callers such as UnifiedGenotyper or the original MuTect.
if [ -n "${realign}" ] && [ ${realign} -eq "1" ]
then
job="realign"
# GATK variables
intervals="${samplename}.intervals"
realigned="$(basename "${dupout}" .bam).realigned.bam"
matefixed="$(basename "${realigned}" .bam).fixed.bam"
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH --mem=${mem}000 --cpus-per-task=${threads}"
echo "#SBATCH --requeue"
echo "#SBATCH --time=8:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMaccount}" ]
then
echo "#SBATCH --account=${SLURMaccount}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# Require previous job successful completion
echo "#SBATCH --dependency=afterok:${SBdup##* }"
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
if [ "${vgatk}" = 3 ]
then
# Determining (small) suspicious intervals which are likely in need of realignment (technically not required on GATK > 3.6)
echo "java -Xmx${mem}g -Djava.io.tmpdir=${tmp} -jar ${gatk} -T RealignerTargetCreator -R ${fasta_refgenome} -I ${dir2}/${dupout} -o ${dir2}/${intervals} -known ${millsgold} -known ${onekGph1} -L ${regions} -nt ${threads} $(if [ -n "${ped}" ]; then echo "-ped ${ped}"; fi) || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# Running the realigner over those intervals (technically not required on GATK > 3.6)
echo "java -Xmx${mem}g -Djava.io.tmpdir=${tmp} -jar ${gatk} -T IndelRealigner -R ${fasta_refgenome} -I ${dir2}/${dupout} -o ${dir2}/${realigned} -targetIntervals ${dir2}/${intervals} $(if [ -n "${ped}" ]; then echo "-ped ${ped}"; fi) || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
# When using paired end data, the mate information must be fixed, as alignments may change during the realignment process
echo "java -Xmx${mem}g -Djava.io.tmpdir=${tmp} -jar ${picard} FixMateInformation I=${dir2}/${realigned} O=${dir2}/${matefixed} SO=coordinate VALIDATION_STRINGENCY=LENIENT CREATE_INDEX=true || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
else
echo "GATK4 command; not implemented yet"
exit
"${gatk}" --java-options "-Xmx${mem}g -Djava.io.tmpdir=${tmp}"
fi
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove intermediate files
echo "rm ${dir2}/${intervals}"
echo "rm ${dir2}/${realigned}"
echo "rm ${dir2}/${realigned}bai"
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBrealign=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
if [ -n "${SBrealign##* }" ]
then
SBrealignIDs=${SBrealignIDs}:${SBrealign##* }
fi
echo -e "\t Realignment job queued"
# Update variable names for next step
dupout="${matefixed}"
SBdup="${SBrealign}"
fi
######################
## Quality score recalibration
job="recal"
# GATK variables
recal_data="${samplename}.recal.grp"
recal="$(basename "${dupout}" .bam).recal.bam"
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH --mem=${mem}000 --cpus-per-task=${threads}"
echo "#SBATCH --requeue"
echo "#SBATCH --time=8:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"
fi
if [ -n "${SLURMaccount}" ]
then
echo "#SBATCH --account=${SLURMaccount}"
fi
if [ -n "${SLURMpartition}" ]
then
echo "#SBATCH --partition=${SLURMpartition}"
fi
if [ -n "${SLURMqos}" ]
then
echo "#SBATCH --qos=${SLURMqos}"
fi
# Require previous job successful completion
echo "#SBATCH --dependency=afterok:${SBdup##* }"
# General commands
echo "mkdir -p ${tmp}"
if [ -n "${customcmd}" ]
then
echo "${customcmd}"
fi
# Job specific commands
if [ "${vgatk}" = 3 ]
then
echo "java -Xmx${mem}g -Djava.io.tmpdir=${tmp} -jar ${gatk} -T BaseRecalibrator -R ${fasta_refgenome} -I ${dir2}/${dupout} -knownSites ${dbSNP} -cov ReadGroupCovariate -cov QualityScoreCovariate -cov CycleCovariate -cov ContextCovariate -o ${dir2}/${recal_data} -L ${regions} -nct ${threads} $(if [ -n "${ped}" ]; then echo "-ped ${ped}"; fi) || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
#echo "java -Xmx${mem}g -Djava.io.tmpdir=${tmp} -jar ${gatk} -T PrintReads -R ${fasta_refgenome} -I ${dir2}/${dupout} -BQSR ${dir2}/${recal_data} -o ${dir2}/${recal} -nct ${threads} $(if [ -n "${ped}" ]; then echo "-ped ${ped}"; fi) || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
## Dirty fix for Java fatal error while using PrintReads, max memory set to 16g https://gatkforums.broadinstitute.org/gatk/discussion/10353/gatk-3-8-0-printreads-fatal-error
echo "java -Xmx$(if [ -n "${mem}" ] && [ ${mem} -gt "16" ]; then echo "16"; else echo "${mem}"; fi)g -Djava.io.tmpdir=${tmp} -jar ${gatk} -T PrintReads -R ${fasta_refgenome} -I ${dir2}/${dupout} -BQSR ${dir2}/${recal_data} -o ${dir2}/${recal} -nct ${threads} $(if [ -n "${ped}" ]; then echo "-ped ${ped}"; fi) || if [ -f ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err ]; then echo \${SLURM_JOB_NODELIST} >> ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && exit 1; else echo \${SLURM_JOB_NODELIST} > ${dir2}/\${SLURM_JOBID}-${samplename}_${job}.err && scontrol requeue \${SLURM_JOBID} && sleep 42m; fi"
else
echo "GATK4 command; not implemented yet"
"${gatk}" --java-options "-Xmx${mem}g -Djava.io.tmpdir=${tmp}"
exit
fi
# Cleaning commands
if [ "${debug}" != "1" ]
then
# Remove deduplicated files
echo "rm ${dir2}/${dupout}"
echo "rm ${dir2}/${dupbai}"
# Remove intermediate files
echo "rm ${dir2}/${recal_data}"
# Remove .sbatch
echo "rm ${dir2}/${samplename}_${job}.sbatch"
fi
} > "${dir2}/${samplename}_${job}.sbatch"
# Queue job
SBrecal=$(until sbatch "${dir2}/${samplename}_${job}.sbatch"; do echo "Job submission failed (exit code ${?}) - Trying again in 5s"; sleep 5; done)
if [ -n "${SBrecal##* }" ]
then
SBrecalIDs=${SBrecalIDs}:${SBrecal##* }
fi
echo -e "\t Quality score recalibration job queued"
######################
## Calling SNPs
job="gvcf"
# GATK variables
rawgvcf="${samplename}.raw.g.vcf"
{
# General SLURM parameters
echo '#!/bin/bash'
echo "#SBATCH --job-name=${samplename}_${job} --output=${dir2}/${logs}/${samplename}_${job}.out --error=${dir2}/${logs}/${samplename}_${job}.err --open-mode=append"
echo "#SBATCH --mem=${mem}000 --cpus-per-task=${threads}"
echo "#SBATCH --requeue"
echo "#SBATCH --time=8:00:00"
if [ -n "${SLURMemail}" ]
then
echo "#SBATCH --mail-type=FAIL --mail-user=${SLURMemail}"