-
Notifications
You must be signed in to change notification settings - Fork 5
/
dDocentHPC.bash
executable file
·2307 lines (1990 loc) · 104 KB
/
dDocentHPC.bash
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
#!/usr/bin/env bash
VERSION=4.6
#This script serves as an interactive bash wrapper to QC, assemble, map, and call SNPs from double digest RAD (SE or PE), ezRAD (SE or PE) data, or SE RAD data.
#It requires that your raw data are split up by tagged individual and follow the naming convention of:
#Pop_Sample1.F.fq and Pop_Sample1.R.fq
#Prints out title and contact info
echo; echo -e "\n* dDocentHPC v$VERSION Forked by [email protected] * \n"
#Determine which functions to run
#demultiplexFQ trimFQ mkREF mkBAM fltrBAM mkVCF fltrVCF
if [ -n "$3" ]; then
#getting functions from command line
FUNKTION=$1
OVERWRITE=FALSE
echo; echo "Running dDocentHPC $FUNKTION in PRESERVATION mode. \n Sample names, file indexing, etc will be preserved to increase speed..."
elif [ -n "$1" ]; then
#getting functions from command line
FUNKTION=$1
OVERWRITE=TRUE
echo; echo "Running dDocentHPC $FUNKTION in OVERWRITE mode. \n Sample names, file indexing, etc will be overwritten to clear errors..."
else
echo ""; echo `date` "ERROR: dDocentHPC must be run with at least 2 arguments, "
echo " dDocentHPC.bash [function] [config file]"
echo " functions: trimFQ, mkREF, mkBAM, fltrBAM, mkVCF, fltrVCF"
exit
fi
#load variables from config file
if [ -n "$2" ]; then
echo " "
echo `date` "Files output to: " $(pwd)
echo ""; echo `date` "Reading config file... "
echo " "
#echo "BEGIN*CONFIG*FILE*****************************************************************************************"
# cat $1
cat $2
#echo "*********END*CONFIG*FILE*******************************************************************************************"
echo ""; echo `date` "Reading in variables from config file..."
CONFIG=$2
# NUMProc=$(grep 'Number of Processors (Auto, 1, 2, 3,' $CONFIG | awk '{print $1;}')
NUMProc=$(nproc)
# MAXMemory=$(grep 'Maximum Memory (1G,2G,' $CONFIG | awk '{print $1;}')
freeMEM=$(free | tr -s " " "\t" | cut -f4 | tail -n+2 | head -n1)
#TRIM=$(grep -A1 Trim $CONFIG | tail -1)
TRIM="RemoveThisVar"
TRIM_LENGTH_ASSEMBLY=$(grep 'trimmomatic MINLEN (integer, mkREF only)' $CONFIG | awk '{print $1;}')
ADAPTERS_FILE=$(grep 'trimmomatic ILLUMINACLIP:<fasta>' $CONFIG | awk '{print $1;}')
SEED_ASSEMBLY=$(grep 'trimmomatic ILLUMINACLIP:<seed mismatches> (integer)' $CONFIG | awk '{print $1;}')
PALIMDROME_ASSEMBLY=$(grep 'trimmomatic ILLUMINACLIP:<palindrome clip thresh> (integer)' $CONFIG | awk '{print $1;}')
SIMPLE_ASSEMBLY=$(grep 'trimmomatic ILLUMINACLIP:<simple clip thresh> (integer)' $CONFIG | awk '{print $1;}')
windowSize_ASSEMBLY=$(grep 'trimmomatic SLIDINGWINDOW:<windowSize> (integer)' $CONFIG | awk '{print $1;}')
windowQuality_ASSEMBLY=$(grep 'trimmomatic SLIDINGWINDOW:<windowQuality> (integer)' $CONFIG | awk '{print $1;}')
TRAILING_ASSEMBLY=$(grep 'trimmomatic TRAILING:<quality> (integer, mkREF only)' $CONFIG | awk '{print $1;}')
TRIM_LENGTH_MAPPING=$(grep 'trimmomatic MINLEN (integer, mkBAM only)' $CONFIG | awk '{print $1;}')
LEADING_MAPPING=$(grep 'trimmomatic LEADING:<quality> (integer, mkBAM only)' $CONFIG | awk '{print $1;}')
TRAILING_MAPPING=$(grep 'trimmomatic TRAILING:<quality> (integer, mkBAM only)' $CONFIG | awk '{print $1;}')
CROP=$(grep 'trimmomatic CROP:' $CONFIG | awk '{print $1;}')
HEADCROP=$(grep 'trimmomatic HEADCROP:<length> (integer, only Read1 for ezRAD)' $CONFIG | awk '{print $1;}')
FixStacks=$(grep 'FixStacks ' $CONFIG | awk '{print $1;}')
ASSEMBLY="RemoveThisVar"
ATYPE=$(grep 'Type of reads for assembly (PE, SE, OL, RPE)' $CONFIG | awk '{print $1;}')
simC=$(grep 'cdhit Clustering_Similarity_Pct' $CONFIG | awk '{print $1;}')
HPC="RemoveThisVar" #$(grep 'Get graphs for cutoffs, then stop? (yes or no)' $CONFIG | awk '{print $1;}')
MANCUTOFF="RemoveThisVar" #$(grep 'Manually set cutoffs? (yes or no)' $CONFIG | awk '{print $1;}')
CUTOFF=$(grep 'Cutoff1 (integer)' $CONFIG | awk '{print $1;}')
CUTOFF2=$(grep 'Cutoff2 (integer)' $CONFIG | awk '{print $1;}')
rPERCENTILE=$(grep 'rainbow merge -r' $CONFIG | awk '{print $1;}')
RPERCENTILE=$(grep 'rainbow merge -R' $CONFIG | awk '{print $1;}')
MAP="RemoveThisVar"
optA=$(grep 'bwa mem -A Mapping_Match_Value' $CONFIG | awk '{print $1;}')
optB=$(grep 'bwa mem -B Mapping_MisMatch_Value' $CONFIG | awk '{print $1;}')
optO=$(grep 'bwa mem -O Mapping_GapOpen_Penalty' $CONFIG | awk '{print $1;}')
MAPPING_MIN_ALIGNMENT_SCORE=$(grep 'bwa mem -T Mapping_Minimum_Alignment_Score' $CONFIG | awk '{print $1;}')
MAPPING_CLIPPING_PENALTY=$(grep 'bwa mem -L Mapping_Clipping_Penalty' $CONFIG | awk '{print $1;}')
FILTERMAP="RemoveThisVar"
MAPPING_MIN_QUALITY=$(grep 'Mapping_Min_Quality' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F4=$(grep 'Remove_unmapped_reads?' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F8=$(grep 'Remove_read_pair_if_one_is_unmapped' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F256=$(grep 'Remove_secondary_alignments' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F512=$(grep 'Remove_reads_not_passing_platform_vendor_filters' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F1024=$(grep 'Remove_PCR_or_optical_duplicates' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_F2048=$(grep 'Remove_supplementary_alignments' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_f2=$(grep 'Keep_only_properly_aligned_read_pairs' $CONFIG | awk '{print $1;}')
# GNU parallel for running on single node
PARALLEL="parallel --no-notice -j $NUMProc"
# mpi_parallal over generic MPI
#PARALLEL="mpirun ./mpi_parallel"
# mpi_parallel for wahab & turing
#MPI_PARALLEL_INJECT_LD_PRELOAD=/opt/conda/lib/libjemalloc.so
#PARALLEL="srun crun ./mpi_parallel"
if [ "$SAMTOOLS_VIEW_F4" == "yes" ]; then
F4=4
else
F4=0
fi
if [ "$SAMTOOLS_VIEW_F8" == "yes" ]; then
F8=8
else
F8=0
fi
if [ "$SAMTOOLS_VIEW_F256" == "yes" ]; then
F256=256
else
F256=0
fi
if [ "$SAMTOOLS_VIEW_F512" == "yes" ]; then
F512=512
else
F512=0
fi
if [ "$SAMTOOLS_VIEW_F1024" == "yes" ]; then
F1024=1024
else
F1024=0
fi
if [ "$SAMTOOLS_VIEW_F2048" == "yes" ]; then
F2048=2048
else
F2048=0
fi
SAMTOOLS_VIEW_F=$(($F4+$F8+$F256+$F512+$F1024+$F2048))
if [ "$SAMTOOLS_VIEW_f2" == "yes" ]; then
SAMTOOLS_VIEW_f=2
else
SAMTOOLS_VIEW_f=0
fi
SAMTOOLS_VIEW_Fcustom=$(grep 'Custom_samtools_view_F_bit_value' $CONFIG | awk '{print $1;}')
SAMTOOLS_VIEW_fcustom=$(grep 'Custom_samtools_view_f_bit_value' $CONFIG | awk '{print $1;}')
SOFT_CLIP_CUT=$(grep 'Remove_reads_with_excessive_soft_clipping' $CONFIG | awk '{print $1;}')
FILTER_MIN_AS=$(grep 'Remove_reads_with_alignment_score_below_relative_threshold' $CONFIG | awk '{print $1;}')
FILTER_MIN_AS_LEN=$(grep 'Read_length_assumed_by_relative_alignment_score_threshold' $CONFIG | awk '{print $1;}')
FILTER_ORPHANS=$(grep 'Remove_reads_orphaned_by_filters' $CONFIG | awk '{print $1;}')
SNP="RemoveThisVar"
POOLS=$(grep 'freebayes -J --pooled-discrete' $CONFIG | awk '{print $1;}')
POOL_PLOIDY_FILE=$(grep 'freebayes -A --cnv-map' $CONFIG | awk '{print $1;}')
PLOIDY=$(grep 'freebayes -p --ploidy' $CONFIG | awk '{print $1;}')
FREEBAYES_r=$(grep 'freebayes -r --region' $CONFIG | awk '{print $1;}'); if [ $FREEBAYES_r == "no" ]; then FREEBAYES_r=""; elif [ -s $FREEBAYES_r ]; then FREEBAYES_r="-r $FREEBAYES_r "; else FREEBAYES_r="", echo error loading freebayes -r setting, default set to no;fi
R1MaxBP=$(grep 'only genotype read 1' $CONFIG | awk '{print $1;}')
MinGenoDepth=$(grep 'Minimum Mean Depth of Coverage Per Individual' $CONFIG | awk '{print $1;}')
BEST_N_ALLELES=$(grep 'freebayes -n --use-best-n-alleles' $CONFIG | awk '{print $1;}')
MIN_MAPPING_QUAL=$(grep 'freebayes -m --min-mapping-quality' $CONFIG | awk '{print $1;}')
MIN_BASE_QUAL=$(grep 'freebayes -q --min-base-quality' $CONFIG | awk '{print $1;}')
HAPLOTYPE_LENGTH=$(grep 'freebayes -E --haplotype-length' $CONFIG | awk '{print $1;}')
MIN_REPEAT_ENTROPY=$(grep 'freebayes --min-repeat-entropy' $CONFIG | awk '{print $1;}')
MIN_COVERAGE=$(grep 'freebayes --min-coverage' $CONFIG | awk '{print $1;}')
MIN_ALT_FRACTION=$(grep 'freebayes -F --min-alternate-fraction' $CONFIG | awk '{print $1;}')
FREEBAYES_z=$(grep 'freebayes -z --read-max-mismatch-fraction' $CONFIG | awk '{print $1;}')
FREEBAYES_C=$(grep 'freebayes -C --min-alternate-count' $CONFIG | awk '{print $1;}')
FREEBAYES_3=$(grep 'freebayes ~3 ~~min-alternate-qsum' $CONFIG | awk '{print $1;}'); FREEBAYES_3=$((FREEBAYES_3 * FREEBAYES_C))
FREEBAYES_G=$(grep 'freebayes -G --min-alternate-total' $CONFIG | awk '{print $1;}')
FREEBAYES_Q=$(grep 'freebayes -Q --mismatch-base-quality-threshold' $CONFIG | awk '{print $1;}')
FREEBAYES_U=$(grep 'freebayes -U --read-mismatch-limit' $CONFIG | awk '{print $1;}')
FREEBAYES_DOLLAR=$(grep 'freebayes -\$ --read-snp-limit' $CONFIG | awk '{print $1;}')
FREEBAYES_e=$(grep 'freebayes -e --read-indel-limit' $CONFIG | awk '{print $1;}')
FREEBAYES_w=$(grep 'freebayes -w --hwe-priors-off' $CONFIG | awk '{print $1;}'); if [ $FREEBAYES_w == "no" ]; then FREEBAYES_w=""; else FREEBAYES_w="-w "; fi
FREEBAYES_V=$(grep 'freebayes -V --binomial-obs-priors-off' $CONFIG | awk '{print $1;}'); if [ $FREEBAYES_V == "no" ]; then FREEBAYES_V=""; else FREEBAYES_V="-V "; fi
FREEBAYES_a=$(grep 'freebayes -a --allele-balance-priors-off' $CONFIG | awk '{print $1;}'); if [ $FREEBAYES_a == "no" ]; then FREEBAYES_a=""; else FREEBAYES_a="-a "; fi
FREEBAYES_no_partial_observations=$(grep -P 'freebayes *\t* --no-partial-observations' $CONFIG | awk '{print $1;}'); if [ "${FREEBAYES_no_partial_observations}" == "no" ]; then FREEBAYES_no_partial_observations=""; else FREEBAYES_no_partial_observations="--no-partial-observations "; fi
FREEBAYES_report_monomorphic=$(grep -P 'freebayes *\t* --report-monomorphic' $CONFIG | awk '{print $1;}'); if [ "$FREEBAYES_report_monomorphic" == "no" ]; then FREEBAYES_report_monomorphic=""; else FREEBAYES_report_monomorphic="--report-monomorphic "; fi
MAIL=$(grep -A1 Email $CONFIG | tail -1)
CUTOFFS=$CUTOFF.$CUTOFF2
else
echo ""; echo `date` "ERROR: dDocentHPC must be run with 2 arguments, "
echo " dDocentHPC.bash [function] [config file]"
echo " functions: trimFQ, mkREF, mkBAM, fltrBAM, mkVCF, fltrVCF"
echo " the default config file is called config.*"
exit
fi
####################################################################################################
###Function to check for the required software for dDocent
####################################################################################################
CheckVersion() {
lower="$1"
higher="$2"
real="$(echo -e "$lower\n$higher" | sort -V | head -1)"
[ ! "$lower" = "$real" ]
}
CheckDependencies(){
echo
echo " Running CheckDependencies Function..."
DEP=$1
missing_dep=""
for i in "${DEP[@]}"; do
echo
case "$i" in
trimmomatic)
found=0
TRIMMOMATIC=$(find ${PATH//:/ } -maxdepth 1 -name trimmomatic*jar 2> /dev/null | head -1)
if [ $ADAPTERS_FILE != 0 ]; then
ADAPTERS=$( find ${PATH//:/ } -maxdepth 2 -name $ADAPTERS_FILE 2> /dev/null | head -1)
[ -z "$ADAPTERS" ] && found=1
fi
[ -z "$TRIMMOMATIC" ] && found=1
;;
*)
hash $i 2> /dev/null
found=$?
;;
esac
if [ $found -ne 0 ]; then
echo " The dependency $i is not installed or is not in your '\$PATH'."
missing_dep+="$i "
continue
fi
echo " The dependency $i is installed!"
case "$i" in
freebayes)
real_version=$(freebayes | awk -F'[ v-]*' '/ersion/ {print $3}')
target_version="1.0.0"
;;
bwa)
real_version=$(bwa 2>&1 | awk -F'[ -]' '/Version/ {print $2}')
target_version="0.7.13"
;;
samtools)
real_version=$(samtools --help | awk '/Version/ {print $2}')
target_version="1.3"
;;
vcftools)
real_version=$(vcftools | awk -F'[()]' '/VCFtools/ {print $2}')
target_version="0.1.11"
;;
rainbow)
real_version=$(rainbow | awk '/^rainbow/ {print $2}')
target_version="2.0.2"
;;
bedtools)
real_version=$(bedtools --version | awk -F'[v ]' '{print $3}')
target_version="2.23.0"
;;
*)
continue
;;
esac
if CheckVersion "$target_version" "$real_version" ; then
echo " The version of $i installed in your \$PATH is not optimized for dDocent."
echo " Please install a version newer than $real_version"
missing_dep+="$i "
fi
if [ "$i" = "bedtools" ]; then
CheckVersion "2.24.0" "$real_version" && BEDTOOLSFLAG="OLD"
CheckVersion "$real_version" "2.26.0" && BEDTOOLSFLAG="NEW"
if [ -z "$BEDTOOLSFLAG" ]; then
echo " The version of bedtools installed in your \$PATH is not optimized for dDocent."
echo " Please install version 2.23.0 or version 2.26.0 and above"
missing_dep+="$i "
fi
fi
done
echo
if [ -z "$missing_dep" ]; then
echo " All dependencies are installed and up to date!"
return
fi
echo " ERROR: Some software is not installed or not up to date but dDocentHPC"
echo " will continue to run with limited functionality."
echo " Please install all required software for full functionality"
}
echo
echo `date` "Checking for all required dDocent software..."
DEP=(trimmomatic freebayes mawk bwa samtools vcftools rainbow gnuplot gawk seqtk cd-hit-est bamToBed bedtools coverageBed parallel vcfcombine bamtools pearRM)
CheckDependencies $DEP
if ! awk --version | fgrep -v GNU &>/dev/null; then
awk=gawk
else
awk=awk
fi
if ! sort --version | fgrep GNU &>/dev/null; then
sort=gsort
else
sort=sort
fi
#This code checks for individual fastq files follow the correct naming convention and are gziped
TEST=$(ls *.fq 2> /dev/null | wc -l )
if [ "$TEST" -gt 0 ]; then
echo -e "\ndDocent is now configured to work on compressed sequence files. "
echo -e "\nIf the following files are not your original data files, they can likely be deleted."
ls *fq
echo "Otherwise, please run gzip to compress your files. This is as simple as 'gzip *.fq'"
echo "Please rerun dDocent after compressing files."
echo $TEST
exit 1
fi
###############################################################################################
#Wrapper for main program functions. This allows the entire file to be read first before execution
main(){
echo "";echo ""; echo `date` " Begin main ddocent function"
##########User Input Section##########
#This code gets input from the user and assigns variables
######################################
#RMH added ALL variables
# echo "";echo " Loading variable values..."
# echo " FUNKTION= ${55}"
# echo " NUMProc= $1"
# echo " MAXMemory= $2"
# echo " TRIM= $3"
# echo " TRIM_LENGTH_ASSEMBLY= $4"
# echo " SEED_ASSEMBLY= $5"
# echo " PALIMDROME_ASSEMBLY= $6"
# echo " SIMPLE_ASSEMBLY= $7"
# echo " windowSize_ASSEMBLY= $8"
# echo " windowQuality_ASSEMBLY= $9"
# echo " TRAILING_ASSEMBLY= ${10}"
# echo " TRIM_LENGTH_MAPPING= ${11}"
# echo " LEADING_MAPPING= ${12}"
# echo " TRAILING_MAPPING= ${13}"
# echo " HEADCROP= ${56}"
# echo " FixStacks= ${14}"
# echo " ASSEMBLY= ${15}"
# echo " ATYPE= ${16}"
# echo " simC= ${17}"
# echo " HPC= ${18}"
# echo " MANCUTOFF= ${19}"
# echo " CUTOFF= ${20}"
# echo " CUTOFF2= ${21}"
# echo " MAP= ${22}"
# echo " optA= ${23}"
# echo " optB= ${24}"
# echo " optO= ${25}"
# echo " MAPPING_MIN_ALIGNMENT_SCORE= ${26}"
# echo " MAPPING_CLIPPING_PENALTY= ${27}"
# echo " FILTERMAP= ${45}"
# echo " MAPPING_MIN_QUALITY= ${28}"
# echo " SAMTOOLS_VIEW_f= ${46}"
# echo " SAMTOOLS_VIEW_F= ${29}"
# echo " SAMTOOLS_VIEW_Fcustom= ${47}"
# echo " SAMTOOLS_VIEW_fcustom= ${48}"
# echo " SOFT_CLIP_CUTOFF= ${49}"
# echo " FILTER_MIN_AS= ${52}"
# echo " FILTER_ORPHANS= ${50}"
# echo " SNP= ${30}"
# echo " POOLS= ${31}"
# echo " POOL_PLOIDY_FILE= ${32}"
# echo " PLOIDY= ${33}"
# echo " BEST_N_ALLELES= ${34}"
# echo " MIN_MAPPING_QUAL= ${35}"
# echo " MIN_BASE_QUAL= ${36}"
# echo " HAPLOTYPE_LENGTH= ${37}"
# echo " MIN_REPEAT_ENTROPY= ${38}"
# echo " MIN_COVERAGE= ${39}"
# echo " MIN_ALT_FRACTION= ${40}"
# echo " FREEBAYES_C= ${41}"
# echo " FREEBAYES_G= ${42}"
# echo " FREEBAYES_z= ${43}"
# echo " FREEBAYES_Q= ${53}"
# echo " FREEBAYES_U= ${54}"
# echo " freebayes -3 $FREEBAYES_3"
# echo " freebayes -\$ $FREEBAYES_DOLLAR"
# echo " freebayes -e $FREEBAYES_e"
# if [[ $FREEBAYES_w != "" ]]; then echo " freebayes ${FREEBAYES_w}"; fi
# if [[ $FREEBAYES_V != "" ]]; then echo " freebayes ${FREEBAYES_V}"; fi
# if [[ $FREEBAYES_a != "" ]]; then echo " freebayes ${FREEBAYES_a}"; fi
# if [[ $FREEBAYES_no_partial_observations != "" ]]; then echo " freebayes ${FREEBAYES_no_partial_observations}"; fi
# echo " MAIL= ${44}"
# echo " BEDTOOLSFLAG= ${51}"
#Load config arguments into variables
# RMH added ALL variables
# FUNKTION=${55}
# NUMProc=$1
# MAXMemory=$2
# TRIM=$3
# TRIM_LENGTH_ASSEMBLY=$4
# SEED_ASSEMBLY=$5
# PALIMDROME_ASSEMBLY=$6
# SIMPLE_ASSEMBLY=$7
# windowSize_ASSEMBLY=$8
# windowQuality_ASSEMBLY=$9
# TRAILING_ASSEMBLY=${10}
# TRIM_LENGTH_MAPPING=${11}
# LEADING_MAPPING=${12}
# TRAILING_MAPPING=${13}
# HEADCROP=${56}
# FixStacks=${14}
# ASSEMBLY=${15}
# ATYPE=${16}
# simC=${17}
# HPC=${18}
# MANCUTOFF=${19}
# CUTOFF=${20}
# CUTOFF2=${21}
# MAP=${22}
# optA=${23}
# optB=${24}
# optO=${25}
# MAPPING_MIN_ALIGNMENT_SCORE=${26}
# MAPPING_CLIPPING_PENALTY=${27}
# FILTERMAP=${45}
# MAPPING_MIN_QUALITY=${28}
# SAMTOOLS_VIEW_f=${46}
# SAMTOOLS_VIEW_F=${29}
# SAMTOOLS_VIEW_Fcustom=${47}
# SAMTOOLS_VIEW_fcustom=${48}
# SOFT_CLIP_CUTOFF=${49}
# FILTER_MIN_AS=${52}
# FILTER_ORPHANS=${50}
# SNP=${30}
# POOLS=${31}
# POOL_PLOIDY_FILE=${32}
# PLOIDY=${33}
# BEST_N_ALLELES=${34}
# MIN_MAPPING_QUAL=${35}
# MIN_BASE_QUAL=${36}
# HAPLOTYPE_LENGTH=${37}
# MIN_REPEAT_ENTROPY=${38}
# MIN_COVERAGE=${39}
# MIN_ALT_FRACTION=${40}
# FREEBAYES_C=${41}
# FREEBAYES_G=${42}
# FREEBAYES_z=${43}
# FREEBAYES_Q=${53}
# FREEBAYES_U=${54}
# MAIL=${44}
# BEDTOOLSFLAG=${51}
#$$$$$$$$$$$$$$$$$$$$$CEB$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#Count number of individuals in current directory
#this alerts user to fastq file naming conventions
echo "";echo " The HPC version of dDocent will only digest files with particular extensions for particular tasks"
echo " untouched files for trimming must be *.F.fq.gz and *.R.fq.gz"
echo " files trimmed for assembly (mkREF) must be *r1.fq.gz *r2.fq.gz"
echo " files trimmed for mapping (mkBAM) must be *R1.fq.gz *R2.fq.gz"
if [ "$FUNKTION" == "trimFQ" ]; then
F="F"
Fwild="*.F.fq.gz"
Fsed=".F.fq.gz"
R="R"
Rwild="*.R.fq.gz"
Rsed=".R.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "trimFQref" ]; then
F="F"
Fwild="*.F.fq.gz"
Fsed=".F.fq.gz"
R="R"
Rwild="*.R.fq.gz"
Rsed=".R.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "trimFQmap" ]; then
F="F"
Fwild="*.F.fq.gz"
Fsed=".F.fq.gz"
R="R"
Rwild="*.R.fq.gz"
Rsed=".R.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "mkREF" ]; then
F="r1"
Fwild="*.r1.fq.gz"
Fsed=".r1.fq.gz"
R="r2"
Rwild="*.r2.fq.gz"
Rsed=".r2.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "mkBAM" ]; then
F="R1"
Fwild="*.R1.fq.gz"
Fsed=".R1.fq.gz"
R="R2"
Rwild="*.R2.fq.gz"
Rsed=".R2.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "fltrBAM" ]; then
F="R1"
#Fwild="*-RAW.bam"
#Fsed=".${CUTOFFS}-RAW.bam"
Fwild="*.R1.fq.gz"
Fsed=".R1.fq.gz"
R="R2"
Rwild="*.R2.fq.gz"
Rsed=".R2.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
elif [ "$FUNKTION" == "mkVCF" ]; then
F="R1"
Fwild="*.R1.fq.gz"
Fsed=".R1.fq.gz"
# Fwild="*-RG.bam"
# Fsed=".${CUTOFFS}-RG.bam"
R="R2"
Rwild="*.R2.fq.gz"
Rsed=".R2.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
else
echo "";echo " Couldn't decide which file extensions were selected"
F="r1"
Fwild="*.r1.fq.gz"
Fsed=".r1.fq.gz"
R="r2"
Rwild="*.r2.fq.gz"
Rsed=".r2.fq.gz"
echo "";echo " extensions selected: $Fwild $Rwild"
fi
if [ "$FUNKTION" == "fltrBAM" ]; then
NumInd=$(ls *.${CUTOFFS}-RAW.bam | wc -l)
#Create list of sample names
if [ ! -s "namelist.$CUTOFF.$CUTOFF2" ] || [ "$OVERWRITE" == "TRUE" ];then
ls *.${CUTOFFS}-RAW.bam > namelist.$CUTOFFS
sed -i -e "s/\.${CUTOFFS}-RAW.bam//g" namelist.$CUTOFFS
elif [ "$(grep -c '^' namelist.$CUTOFFS)" != "$NumInd" ]; then
echo "";echo " The existing namelist file does not match the present sample set and is being recreated. "
ls *.${CUTOFFS}-RAW.bam > namelist.$CUTOFFS
sed -i -e "s/\.${CUTOFFS}-RAW.bam//g" namelist.$CUTOFFS
else
echo "";echo " The namelist file already exists and was not recreated. "
echo " If you experience errors, you should delete the namelist file."
fi
elif [ "$FUNKTION" == "mkVCF" ]; then
NumInd=$(ls *.${CUTOFFS}-RG.bam | wc -l)
#Create list of sample names
if [ ! -s "namelist.$CUTOFF.$CUTOFF2" ] || [ "$OVERWRITE" == "TRUE" ];then
ls *.${CUTOFFS}-RG.bam > namelist.$CUTOFFS
sed -i -e "s/\.${CUTOFFS}-RG.bam//g" namelist.$CUTOFFS
elif [ "$(grep -c '^' namelist.$CUTOFFS)" != "$NumInd" ]; then
echo "";echo " The existing namelist file does not match the present sample set and is being recreated. "
ls *.${CUTOFFS}-RG.bam > namelist.$CUTOFFS
sed -i'' -e "s/*.${CUTOFFS}-RG.bam//g" namelist.$CUTOFFS
else
echo "";echo " The namelist file already exists and was not recreated. "
echo " If you experience errors, you should delete the namelist file."
fi
else
NumInd=$(ls $Fwild | wc -l)
NumInd=$(($NumInd - 0))
#Create list of sample names
if [ ! -s "namelist.$CUTOFF.$CUTOFF2" ] || [ "$OVERWRITE" == "TRUE" ];then
ls $Fwild > namelist.$CUTOFFS
sed -i'' -e "s/$Fsed//g" namelist.$CUTOFFS
elif [ "$(grep -c '^' namelist.$CUTOFFS)" != "$NumInd" ]; then
echo "";echo " The existing namelist file does not match the present sample set and is being recreated. "
ls $Fwild > namelist.$CUTOFFS
sed -i'' -e "s/*.${CUTOFFS}-RAW.bam//g" namelist.$CUTOFFS
else
echo "";echo " The namelist file already exists and was not recreated. "
echo " If you experience errors, you should delete the namelist file."
fi
fi
#Create an array of sample names
#NUMNAMES=$(mawk '/_/' namelist.$CUTOFFS | wc -l)
NUMNAMES=$(grep -c '^' namelist.$CUTOFFS)
if [ "$NUMNAMES" == "$NumInd" ]; then
NAMES=( `cat "namelist.$CUTOFFS" `)
echo " ";echo " The samples being processed are:"
cat namelist.$CUTOFFS | parallel --no-notice "echo ' '{}"
echo ""
else
echo ""; echo " "`date` " ERROR: NUMNAMES=$NUMNAMES NUMIND=$NumInd"
echo " Individuals do not follow the dDocent naming convention."
echo " Please rename individuals to: Locality_Individual.F.fq.gz"
echo " For example: LocA_001.F.fq.gz"
exit 1
fi
#Sets a start time variable
STARTTIME=$(date)
##Section of logic statements that dictates the order and function of processing the pipeline
if [ "$FixStacks" == "yes" ]; then
FIXSTACKS
fi
if [ "$FUNKTION" == "trimFQ" ]; then
echo " ";echo " "`date` "Trimming reads "
TrimReadsRef #$NUMProc $R $CONFIG #& 2> ./mkREF/trimref.log
TrimReads #$NUMProc $R $CONFIG #& 2> ./mkBAM/trim.log
fi
if [ "$FUNKTION" == "trimFQref" ]; then
echo " ";echo " "`date` "Trimming reads "
TrimReadsRef #$NUMProc $R $CONFIG #& 2> ./mkREF/trimref.log
fi
if [ "$FUNKTION" == "trimFQmap" ]; then
echo " ";echo " "`date` "Trimming reads "
TrimReads #$NUMProc $R $CONFIG #& 2> ./mkBAM/trim.log
fi
if [ "$FUNKTION" == "mkREF" ]; then
Assemble #$NUMProc $CONFIG $Rsed $NumInd $Fwild $Rwild $awk NAMES
fi
if [ "$FUNKTION" == "mkBAM" ]; then
MAP2REF #$CUTOFF.$CUTOFF2 $NUMProc $CONFIG $ATYPE $Rsed NAMES
fi
if [ "$FUNKTION" == "fltrBAM" ]; then
FILTERBAM #$CUTOFFS $NUMProc $CONFIG $ATYPE
fi
if [ "$FUNKTION" == "mkVCF" ]; then
GENOTYPE #$CUTOFFS $NUMProc $CONFIG
fi
##Checking for possible errors
if [ "$FUNKTION" == "mkBAM" ]; then
ERROR1=$(mawk '/developer/' bwa* | wc -l 2>/dev/null)
fi
#CEB this was causing an error, there's no bam.log created
# ERROR2=$(mawk '/error/' *.bam.log | wc -l 2>/dev/null)
#ERRORS=$(($ERROR1 + $ERROR2))
#Move various log files to own directory
if [ ! -d "logfiles" ]; then
mkdir logfiles
fi
mv *.log log ./logfiles 2> /dev/null
#Sending a completion email
#CEB this was causing error: mawk: cannot open ./logfiles/Final.log (No such file or directory)
#if [ $ERRORS -gt 0 ]; then
# echo -e "dDocent has finished with errors in" `pwd` "\n\ndDocent started" $STARTTIME "\n\ndDocent finished" `date` "\n\nPlease check log files\n\n" `mawk '/After filtering, kept .* out of a possible/' ./logfiles/Final.log` "\n\ndDocent 2.24 \nThe 'd' is silent, hillbilly." | mailx -s "dDocent has finished with ERRORS!" $MAIL
#else
# echo -e "dDocent has finished with an analysis in" `pwd` "\n\ndDocent started" $STARTTIME "\n\ndDocent finished" `date` "\n\n" `mawk '/After filtering, kept .* out of a possible/' ./logfiles/Final.log` "\n\ndDocent 2.24 \nIt is pronounced Dee-Docent, professor." | mailx -s "dDocent has finished" $MAIL
#fi
#Creates (or appends to) a dDocent run file recording variables
#RMH added ALL variables
echo "Variables used in dDocent Run at" $STARTTIME >> dDocent.runs
echo "Number of Processors" >> dDocent.runs
echo $NUMProc >> dDocent.runs
echo "Maximum Memory" >> dDocent.runs
echo $MAXMemory >> dDocent.runs
echo "Free Memory" >> dDocent.runs
echo $freeMEM >> dDocent.runs
echo "Trimming" >> dDocent.runs
echo $TRIM >> dDocent.runs
echo "TRIM_LENGTH_ASSEMBLY" >> dDocent.runs
echo $TRIM_LENGTH_ASSEMBLY >> dDocent.runs
echo "SEED_ASSEMBLY" >> dDocent.runs
echo $SEED_ASSEMBLY >> dDocent.runs
echo "PALIMDROME_ASSEMBLY" >> dDocent.runs
echo $PALIMDROME_ASSEMBLY >> dDocent.runs
echo "SIMPLE_ASSEMBLY" >> dDocent.runs
echo $SIMPLE_ASSEMBLY >> dDocent.runs
echo "windowSize_ASSEMBLY" >> dDocent.runs
echo $windowSize_ASSEMBLY >> dDocent.runs
echo "windowQuality_ASSEMBLY" >> dDocent.runs
echo $windowQuality_ASSEMBLY >> dDocent.runs
echo "TRAILING_ASSEMBLY" >> dDocent.runs
echo $TRAILING_ASSEMBLY >> dDocent.runs
echo "TRIM_LENGTH_MAPPING" >> dDocent.runs
echo $TRIM_LENGTH_MAPPING >> dDocent.runs
echo "LEADING_MAPPING" >> dDocent.runs
echo $LEADING_MAPPING >> dDocent.runs
echo "TRAILING_MAPPING" >> dDocent.runs
echo $TRAILING_MAPPING >> dDocent.runs
echo "HEADCROP" >> dDocent.runs
echo $HEADCROP >> dDocent.runs
echo "FixStacks" >> dDocent.runs
echo $FixStacks >> dDocent.runs
# echo "Assembly?" >> dDocent.runs
# echo $ASSEMBLY >> dDocent.runs
echo "Type_of_Assembly" >> dDocent.runs
echo $ATYPE >> dDocent.runs
echo "Clustering_Similarity%" >> dDocent.runs
echo $simC >> dDocent.runs
echo "HPC" >> dDocent.runs
echo $HPC >> dDocent.runs
echo "MANCUTOFF" >> dDocent.runs
echo $MANCUTOFF >> dDocent.runs
echo "CUTOFF" >> dDocent.runs
echo $CUTOFF >> dDocent.runs
echo "CUTOFF2" >> dDocent.runs
echo $CUTOFF2 >> dDocent.runs
# echo "Mapping_Reads?" >> dDocent.runs
# echo $MAP >> dDocent.runs
echo "Mapping_Match_Value" >> dDocent.runs
echo $optA >> dDocent.runs
echo "Mapping_MisMatch_Value" >> dDocent.runs
echo $optB >> dDocent.runs
echo "Mapping_GapOpen_Penalty" >> dDocent.runs
echo $optO >> dDocent.runs
echo "MAPPING_MIN_ALIGNMENT_SCORE" >> dDocent.runs
echo $MAPPING_MIN_ALIGNMENT_SCORE >> dDocent.runs
echo "MAPPING_CLIPPING_PENALTY" >> dDocent.runs
echo $MAPPING_CLIPPING_PENALTY >> dDocent.runs
echo "MAPPING_MIN_QUALITY" >> dDocent.runs
echo $MAPPING_MIN_QUALITY >> dDocent.runs
echo "SAMTOOLS_VIEW_F" >> dDocent.runs
echo $SAMTOOLS_VIEW_F >> dDocent.runs
# echo "Calling_SNPs?" >> dDocent.runs
# echo $SNP >> dDocent.runs
echo "POOLS" >> dDocent.runs
echo $POOLS >> dDocent.runs
echo "POOL_PLOIDY_FILE" >> dDocent.runs
echo $POOL_PLOIDY_FILE >> dDocent.runs
echo "PLOIDY" >> dDocent.runs
echo $PLOIDY >> dDocent.runs
echo "BEST_N_ALLELES" >> dDocent.runs
echo $BEST_N_ALLELES >> dDocent.runs
echo "MIN_MAPPING_QUAL" >> dDocent.runs
echo $MIN_MAPPING_QUAL >> dDocent.runs
echo "MIN_BASE_QUAL" >> dDocent.runs
echo $MIN_BASE_QUAL >> dDocent.runs
echo "HAPLOTYPE_LENGTH" >> dDocent.runs
echo $HAPLOTYPE_LENGTH >> dDocent.runs
echo "MIN_REPEAT_ENTROPY" >> dDocent.runs
echo $MIN_REPEAT_ENTROPY >> dDocent.runs
echo "MIN_COVERAGE" >> dDocent.runs
echo $MIN_COVERAGE >> dDocent.runs
echo "MIN_ALT_FRACTION" >> dDocent.runs
echo $MIN_ALT_FRACTION >> dDocent.runs
echo "FREEBAYES_C" >> dDocent.runs
echo $FREEBAYES_C >> dDocent.runs
echo "FREEBAYES_G" >> dDocent.runs
echo $FREEBAYES_G >> dDocent.runs
echo "FREEBAYES_z" >> dDocent.runs
echo $FREEBAYES_z >> dDocent.runs
echo "Email" >> dDocent.runs
echo $MAIL >> dDocent.runs
}
###############################################################################################
##Function definitions
###############################################################################################
##############################################################################################
#Function for correcting stacks file errors (antiquated?)
###############################################################################################
FIXSTACKS () {
echo "";echo " "`date` " Fixing Stacks anomalies"
#STACKS adds a strange _1 or _2 character to the end of processed reads, this looks for checks for errant characters and replaces them.
#This functionality is now parallelized and will run if only SE sequences are used.
STACKS=$(cat namelist.$CUTOFFS| parallel -j $NUMProc --no-notice "zcat {}$Fsed | head -1" | mawk '!/\/1/' | wc -l)
FB1=$(( $NUMProc / 2 ))
if [ $STACKS -gt 0 ]; then
echo " Removing the _1 character and replacing with /1 in the name of every sequence"
cat namelist.$CUTOFFS | parallel -j $FB1 --no-notice "zcat {}.$F.fq.gz | sed -e 's:_1$:/1:g' > {}.$F.fq"
rm $Fwild
cat namelist.$CUTOFFS | parallel -j $FB1 --no-notice "gzip {}.$F.fq"
fi
if [ -f "${NAMES[@]:(-1)}"$Rsed ]; then
STACKS=$(cat namelist.$CUTOFFS| parallel -j $NUMProc --no-notice "zcat {}$Rsed | head -1" | mawk '!/\/2/' | wc -l)
if [ $STACKS -gt 0 ]; then
echo " Removing the _2 character and replacing with /2 in the name of every sequence"
cat namelist.$CUTOFFS | parallel -j $FB1 --no-notice "zcat {}.$R.fq.gz | sed -e 's:_2$:/2:g' > {}.$R.fq"
rm $Rwild
cat namelist.$CUTOFFS | parallel -j $FB1 --no-notice "gzip {}.$R.fq"
fi
fi
}
##############################################################################################
#Function for trimming reads using trimmomatic
###############################################################################################
TrimReadsRef () {
# NUMProc=$1
# R=$2
# CONFIG=$3
echo " "
echo `date` "Trimming reads for reference genome"
TRIMMOMATIC=$(find ${PATH//:/ } -maxdepth 1 -name trimmomatic*jar 2> /dev/null | head -1)
if [ $ADAPTERS_FILE != 0 ]; then
ADAPTERS=$(find ${PATH//:/ } -maxdepth 2 -name $ADAPTERS_FILE 2> /dev/null | head -1)
fi
echo " TRIMMOMATIC= $TRIMMOMATIC"
echo " ADAPTERS= $ADAPTERS"
# echo " NUMProc= $NUMProc"
echo " SEED_ASSEMBLY= $SEED_ASSEMBLY"
echo " PALIMDROME_ASSEMBLY= $PALIMDROME_ASSEMBLY"
echo " SIMPLE_ASSEMBLY= $SIMPLE_ASSEMBLY"
echo " HEADCROP= $HEADCROP"
echo " TRAILING_ASSEMBLY= $TRAILING_ASSEMBLY"
echo " windowSize_ASSEMBLY= $windowSize_ASSEMBLY"
echo " windowQuality_ASSEMBLY= $windowQuality_ASSEMBLY"
echo " TRIM_LENGTH_ASSEMBLY= $TRIM_LENGTH_ASSEMBLY"
# echo " F= $F"
# echo " R= $R"
if [ ! -d "mkREF" ]; then mkdir mkREF &>/dev/null; fi
if [ ! -d "./mkREF/unpaired" ]; then mkdir ./mkREF/unpaired &>/dev/null; fi
if [ ! -d "./mkREF/logs" ]; then mkdir ./mkREF/logs &>/dev/null; fi
if [ -f "${NAMES[1]}".$R.fq.gz ]; then
THREADS=1 #CEB I tried different numbers here and 1 seems to be best
Proc=$(($NUMProc/$THREADS))
if [ $ADAPTERS_FILE == 0 ]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $Proc "java -jar $TRIMMOMATIC PE -threads $THREADS -phred33 {}.F.fq.gz {}.R.fq.gz ./mkREF/{}.r1.fq.gz ./mkREF/unpaired/{}.unpairedF.fq.gz ./mkREF/{}.r2.fq.gz ./mkREF/unpaired/{}.unpairedR.fq.gz TRAILING:$TRAILING_ASSEMBLY SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_ASSEMBLY &> ./mkREF/logs/{}.trim.log"
else
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $Proc "java -jar $TRIMMOMATIC PE -threads $THREADS -phred33 {}.F.fq.gz {}.R.fq.gz ./mkREF/{}.r1.fq.gz ./mkREF/unpaired/{}.unpairedF.fq.gz ./mkREF/{}.r2.fq.gz ./mkREF/unpaired/{}.unpairedR.fq.gz ILLUMINACLIP:$ADAPTERS:$SEED_ASSEMBLY:$PALIMDROME_ASSEMBLY:$SIMPLE_ASSEMBLY TRAILING:$TRAILING_ASSEMBLY SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_ASSEMBLY &> ./mkREF/logs/{}.trim.log"
fi
else
if [ $ADAPTERS_FILE == 0 ]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 {}.F.fq.gz ./mkREF/{}.r1.fq.gz TRAILING:$TRAILING_ASSEMBLY SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_ASSEMBLY &> ./mkREF/logs/{}.trim.log"
else
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 {}.F.fq.gz ./mkREF/{}.r1.fq.gz ILLUMINACLIP:$ADAPTERS:$SEED_ASSEMBLY:$PALIMDROME_ASSEMBLY:$SIMPLE_ASSEMBLY TRAILING:$TRAILING_ASSEMBLY SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_ASSEMBLY &> ./mkREF/logs/{}.trim.log"
fi
fi
if [[ $HEADCROP != 0 ]]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 ./mkREF/{}.r1.fq.gz ./mkREF/{}.headcropped.r1.fq.gz HEADCROP:$HEADCROP &> ./mkREF/logs/{}.trim.log"
mkdir ./mkREF/unheadcropped
ls ./mkREF/*r1.fq.gz | grep -v 'headcropped' | parallel --no-notice "mv {} ./mkREF/unheadcropped"
rename .headcropped.r1.fq.gz .r1.fq.gz ./mkREF/*.headcropped.r1.fq.gz
fi
}
##############################################################################################
#Function for trimming reads using trimmomatic
###############################################################################################
TrimReads () {
# NUMProc=$1
# R=$2
echo " "
echo; echo `date` "Trimming reads for mapping"
TRIMMOMATIC=$(find ${PATH//:/ } -maxdepth 1 -name trimmomatic*jar 2> /dev/null | head -1)
if [ $ADAPTERS_FILE != 0 ]; then
ADAPTERS=$(find ${PATH//:/ } -maxdepth 2 -name $ADAPTERS_FILE 2> /dev/null | head -1)
fi
echo " TRIMMOMATIC= $TRIMMOMATIC"
echo " ADAPTERS= $ADAPTERS"
# echo " NUMProc= $NUMProc"
echo " SEED_ASSEMBLY= $SEED_ASSEMBLY"
echo " PALIMDROME_ASSEMBLY= $PALIMDROME_ASSEMBLY"
echo " SIMPLE_ASSEMBLY= $SIMPLE_ASSEMBLY"
echo " CROP= $CROP"
echo " HEADCROP= $HEADCROP"
echo " TRAILING_ASSEMBLY= $TRAILING_ASSEMBLY"
echo " windowSize_ASSEMBLY= $windowSize_ASSEMBLY"
echo " windowQuality_ASSEMBLY= $windowQuality_ASSEMBLY"
echo " TRIM_LENGTH_ASSEMBLY= $TRIM_LENGTH_ASSEMBLY"
# echo " F= $F"
# echo " R= $R"
if [ ! -d "mkBAM" ]; then mkdir mkBAM &>/dev/null; fi
if [ ! -d "./mkBAM/unpaired" ]; then mkdir ./mkBAM/unpaired &>/dev/null; fi
if [ ! -d "./mkBAM/logs" ]; then mkdir ./mkBAM/logs &>/dev/null; fi
if [ -f "${NAMES[1]}".$R.fq.gz ]; then
THREADS=1 #CEB I tried different numbers here and 1 seems to be best
Proc=$(($NUMProc/$THREADS))
if [ $ADAPTERS_FILE == 0 ]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | sort -r | parallel --no-notice -j $Proc "java -jar $TRIMMOMATIC PE -threads $THREADS -phred33 {}.F.fq.gz {}.R.fq.gz ./mkBAM/{}.R1.fq.gz ./mkBAM/unpaired/{}.unpairedF.fq.gz ./mkBAM/{}.R2.fq.gz ./mkBAM/unpaired/{}.unpairedR.fq.gz LEADING:$LEADING_MAPPING TRAILING:$TRAILING_MAPPING SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_MAPPING &> ./mkBAM/logs/{}.trim.log"
else
echo "${NAMES[@]}" | sed 's/ /\n/g' | sort -r | parallel --no-notice -j $Proc "java -jar $TRIMMOMATIC PE -threads $THREADS -phred33 {}.F.fq.gz {}.R.fq.gz ./mkBAM/{}.R1.fq.gz ./mkBAM/unpaired/{}.unpairedF.fq.gz ./mkBAM/{}.R2.fq.gz ./mkBAM/unpaired/{}.unpairedR.fq.gz ILLUMINACLIP:$ADAPTERS:$SEED_ASSEMBLY:$PALIMDROME_ASSEMBLY:$SIMPLE_ASSEMBLY LEADING:$LEADING_MAPPING TRAILING:$TRAILING_MAPPING SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_MAPPING &> ./mkBAM/logs/{}.trim.log"
fi
else
if [ $ADAPTERS_FILE == 0 ]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | sort -r | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 {}.F.fq.gz ./mkBAM/{}.R1.fq.gz LEADING:$LEADING_MAPPING TRAILING:$TRAILING_MAPPING SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_MAPPING &> ./mkBAM/logs/{}.trim.log"
else
echo "${NAMES[@]}" | sed 's/ /\n/g' | sort -r | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 {}.F.fq.gz ./mkBAM/{}.R1.fq.gz ILLUMINACLIP:$ADAPTERS:$SEED_ASSEMBLY:$PALIMDROME_ASSEMBLY:$SIMPLE_ASSEMBLY LEADING:$LEADING_MAPPING TRAILING:$TRAILING_MAPPING SLIDINGWINDOW:$windowSize_ASSEMBLY:$windowQuality_ASSEMBLY MINLEN:$TRIM_LENGTH_MAPPING &> ./mkBAM/logs/{}.trim.log"
fi
fi
if [[ $CROP != 0 ]]; then
if [ ! -d "./mkBAM/unpaired_crop" ]; then mkdir ./mkBAM/unpaired_crop &>/dev/null; fi
if [ ! -d "./mkBAM/uncropped" ]; then mkdir ./mkBAM/uncropped &>/dev/null; fi
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC PE -threads 1 -phred33 ./mkBAM/{}.R1.fq.gz ./mkBAM/{}.R2.fq.gz ./mkBAM/{}.R1.cropped.fq.gz ./mkBAM/unpaired_crop/{}.unpairedF.fq.gz ./mkBAM/{}.R2.cropped.fq.gz ./mkBAM/unpaired_crop/{}.unpairedR.fq.gz CROP:$CROP &> ./mkBAM/logs/{}.trim.log"
ls ./mkBAM/*R[12].fq.gz | grep -v 'cropped' | parallel --no-notice "mv {} ./mkBAM/uncropped"
rename .cropped.fq.gz .fq.gz ./mkBAM/*.cropped.fq.gz
fi
if [[ $HEADCROP != 0 ]]; then
echo "${NAMES[@]}" | sed 's/ /\n/g' | parallel --no-notice -j $NUMProc "java -jar $TRIMMOMATIC SE -threads 1 -phred33 ./mkBAM/{}.R1.fq.gz ./mkBAM/{}.headcropped.R1.fq.gz HEADCROP:$HEADCROP &> ./mkBAM/logs/{}.trim.log"
mkdir ./mkBAM/unheadcropped
ls ./mkBAM/*R1.fq.gz | grep -v 'headcropped' | parallel --no-notice "mv {} ./mkBAM/unheadcropped"
rename .headcropped.R1.fq.gz .R1.fq.gz ./mkBAM/*.headcropped.R1.fq.gz
fi
}
###############################################################################################
#Main function for assembly
###############################################################################################
Assemble(){
AWK1='BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++}'
AWK2='!/>/'
AWK3='!/NNN/'
AWK4='{for(i=0;i<$1;i++)print}'
PERLT='while (<>) {chomp; $z{$_}++;} while(($k,$v) = each(%z)) {print "$v\t$k\n";}'
SED1='s/^[ \t]*//'
SED2='s/\s/\t/g'
FRL=$(zcat ${NAMES[0]}.r1.fq.gz | mawk '{ print length() | "sort -rn" }' | head -1)
special_uniq(){
mawk -v x=$1 '$1 >= x' $2 |cut -f2 | sed -e 's/NNNNNNNNNN/\t/g' | cut -f1 | uniq
}
export -f special_uniq
if [ ! -s "namelistfr.$CUTOFFS" ];then
ls $Fwild > namelistfr.$CUTOFFS
ls $Rwild >> namelistfr.$CUTOFFS
sed -i'' -e "s/\.fq\.gz//g" namelistfr.$CUTOFFS
else
echo "";echo " The namelistfr file already exists and was not recreated."
echo " If you experience errors, you should delete the namelistfr file."
fi
#this block of code will either align or concatenate r1 & r2 seqs and create a file of unique sequences
echo " "; echo `date` " Reference Genome Assembly Step 1, Select Cutoffs"
if [ ${NAMES[@]:(-1)}.r1.fq.gz -nt ${NAMES[@]:(-1)}.uniq.seqs ];then
echo " ";echo `date` " the *.fq.gz files are newer than the *uniq.seqs files or the *.uniq.seq files do not exist"
if [ ! -s ${NAMES[@]:(-1)}.uniq.seqs ];then
echo "";echo `date` " make *.uniq.seqs files"
if [[ "$ATYPE" == "PE" || "$ATYPE" == "RPE" ]]; then
cat namelistfr.$CUTOFFS | parallel --no-notice -j $NUMProc "zcat {}.fq.gz | mawk '$AWK1' | mawk '$AWK2' > {}.XXX"
rename r1.XXX forward *r1.XXX
rename r2.XXX reverse *r2.XXX