-
Notifications
You must be signed in to change notification settings - Fork 1
/
CCseqBasic5.sh
1969 lines (1441 loc) · 62.7 KB
/
CCseqBasic5.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
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
##########################################################################
# Copyright 2017, Jelena Telenius (jelena.telenius@imm.ox.ac.uk) #
# #
# This file is part of CCseqBasic5 . #
# #
# CCseqBasic5 is free software: you can redistribute it and/or modify #
# it under the terms of the MIT license.
#
#
# #
# CCseqBasic5 is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# MIT license for more details.
# #
# You should have received a copy of the MIT license
# along with CCseqBasic5.
##########################################################################
#------------------------------------------
# The codes of the pipeline
#------------------------------------------
#
# CCseqBasic5/
#
# |
# |-- CCseqBasic5.sh
# |
# `-- bin
# |
# |-- runscripts
# | |
# | |-- analyseMappedReads.pl
# | |-- dpnIIcutGenome.pl
# | |-- nlaIIIcutGenome.pl
# | |-- dpnIIcutReads.pl
# | |-- nlaIIIcutReads.pl
# | |
# | |-- filterArtifactMappers
# | | |
# | | |-- 1_blat.sh
# | | |-- 2_psl_parser.pl
# | | `-- filter.sh
# | |
# | `-- drawFigure
# | |
# | |-- countsFromCCanalyserOutput.sh
# | |-- drawFigure.py
# | `-- generatePercentages.py
# |
# `-- subroutines
# |-- cleaners.sh
# |-- hubbers.sh
# |-- parametersetters.sh
# |-- runtools.sh
# |-- testers_and_loggers.sh
# `-- usageAndVersion.sh
#------------------------------------------
function finish {
if [ $? != "0" ]; then
echo
echo "RUN CRASHED ! - check qsub.err to see why !"
echo
echo "If your run passed folder1 (F1) succesfully - i.e. you have F2 or later folders formed correctly - you can restart in same folder, same run.sh :"
echo "Just add --onlyCCanalyser to the end of run command in run.sh, and start the run normally, in the same folder you crashed now (this will overrwrite your run from bowtie output onwards)."
echo
echo "If you are going to rerun a crashed run without using --onlyCCanalyser , copy your run script to a NEW EMPTY FOLDER,"
echo "and remember to delete your malformed /public/ hub-folders (especially the tracks.txt files) to avoid wrongly generated data hubs (if you are going to use same SAMPLE NAME as in the crashed run)"
echo
else
if [ "${thisWashelpRequest}" != 1 ];then
echo
echo "Analysis complete !"
date
fi
fi
}
trap finish EXIT
#------------------------------------------
# script top path setup , usage script load.
CCversion="CS5"
captureScript="analyseMappedReads"
CCseqBasicVersion="CCseqBasic5"
CaptureTopPath="$( which $0 | sed 's/\/'${CCseqBasicVersion}'.sh$//' )"
CapturePipePath="${CaptureTopPath}/bin/subroutines"
. ${CapturePipePath}/usageAndVersion.sh
#------------------------------------------
# help user cases .
thisWashelpRequest=0
if [ "$1" == '-h' ] || [ "$1" == '--help' ]
then
thisWashelpRequest=1
usage ;
fi
#------------------------------------------
QSUBOUTFILE="qsub.out"
QSUBERRFILE="qsub.err"
CapturesiteFile=""
TRIM=1
GENOME=""
WINDOW=200
INCREMENT=20
CAPITAL_M=0
LOWERCASE_M=0
LOWERCASE_V=-1
BOWTIEMEMORY="256"
Sample="sample"
Read1=""
Read2=""
LANES=1
GZIP=0
SINGLE_END=0
CUSTOMAD=-1
ADA31="no"
ADA32="no"
# trimgalore default
QMIN=20
# bowtie default
BOWTIE=1
# flash defaults
flashOverlap=10
flashErrorTolerance=0.25
saveDpnGenome=0
ucscBuild=""
ucscBuildName=""
REDGREEN=0
otherBowtie1Parameters=""
otherBowtie2Parameters=""
bowtie1MismatchBehavior=""
bowtie2MismatchBehavior=""
otherParameters=""
PublicPath="UNDETERMINED"
ploidyFilter=""
extend=20000
ampliconSize=300
# If we have many capture-site (REfragment)s, the stuff can be eased up by analysing only in cis.
onlyCis=0
# Blat flags
stepSize=5 # Jon default - James used blat default, which is "tileSize", in this case thus 11 (this was the setting in CC2 and CC3 - i.e filter versions VS101 and VS102)
tileSize=11 # Jon, James default
minScore=10 # Jon new default. Jon default before2016 and CC4 default until 080916 minScore=30 - James used minScore=30 (this was the setting in CC2 and CC3 - i.e filter versions VS101 and VS102)
minIdentity=70 # Jon, James default.
minMatch=2 # blat default
maxIntron=4000 # blat default 750000- James used maxIntron=4000 (this was the setting in CC2 and CC3 - i.e filter versions VS101 and VS102)
oneOff=0 # oneOff=1 would allow 1 mismatch in tile (blat default = 0 - that is also CC3 and CC2 default)
# Whether we reuse blat results from earlier run ..
# Having this as "." will search from the run dir when blat is ran - so file will not be found, and thus BLAT will be ran normally.
reuseBLATpath="."
ONLY_BLAT=0
REenzyme="dpnII"
# Skip other stages - assume input from this run has been ran earlier - to construct to THIS SAME FOLDER everything else
# but as the captureC analyser naturally crashed - this will jump right to the beginning of that part..
ONLY_CC_ANALYSER=0
# Rerun public folder generation and filling. Will not delete existing folder, but will overwrite all files (and start tracks.txt from scratch).
ONLY_HUB=0
# Only run 3-way interaction map generation (on existing CS5 run)
ONLY_TRIC=0
# Run tri-c also in binned mode (run the alternative script which runs both binned and normal in one go)
# This is FOR FUTURE PURPOSES ONLY : - the underlying perl script got never finished.
# also : the below 1 flag (BINNED_TRIC) never worked, as the portability fixes to the underlying perl script were never debugged fully.
# The binned tric user case needs also TRIC_BIN parameter, which is currently used ONLY in the python matrix plotting script.
BINNED_TRIC=0
# Bin size
TRIC_BIN=1000
# Max signal
TRIC_MAX=20
# Other params (currently only the color scale, if not the default one)
TRIC_OTHER_VISUAL_PARAMS=""
# If we have TRI-C run (no exclusion zones - auto-edit capture coordinate file)
TRIC=0
# If we have TRI-C run (no editing capture coordinate file - using exclusion zones as they are given)
TRICEXC=0
otherTricParameters=""
strandSpecificDuplicates=0
srrFastq=0
# Before setting the default ..
fragsPerRead=-1
#------------------------------------------
echo "${CCseqBasicVersion}.sh - by Jelena Telenius, 05/01/2016"
echo
timepoint=$( date )
echo "run started : ${timepoint}"
echo
echo "Script located at"
echo "$0"
echo
echo "RUNNING IN MACHINE : "
hostname --long
echo "run called with parameters :"
echo "${CCseqBasicVersion}.sh" $@
echo
#------------------------------------------
# Loading subroutines in ..
echo "Loading subroutines in .."
# HUBBING subroutines
. ${CapturePipePath}/hubbers.sh
# SETTING parameter values - subroutines
. ${CapturePipePath}/parametersetters.sh
# CLEANING folders and organising structures
. ${CapturePipePath}/cleaners.sh
# TESTING file existence, log file output general messages
. ${CapturePipePath}/testers_and_loggers.sh
# RUNNING the main tools (flash, ccanalyser, etc..)
. ${CapturePipePath}/runtools.sh
# INPUT the fastq files
. ${CapturePipePath}/inputFastqs.sh
# SETTING THE GENOME BUILD PARAMETERS
. ${CapturePipePath}/genomeSetters.sh
# SETTING THE BLACKLIST GENOME LIST PARAMETERS
. ${CapturePipePath}/blacklistSetters.sh
# SORTING HELPER SUBROUTINES
. ${CapturePipePath}/sort_helpers.sh
# PRINTING HELP AND VERSION MESSAGES
# . ${CapturePipePath}/usageAndVersion.sh
# (loaded already above - where the help user case is done)
#------------------------------------------
# From where to call the main scripts operating from the runscripts folder..
RunScriptsPath="${CaptureTopPath}/bin/runscripts"
#------------------------------------------
# From where to call the filtering scripts..
# (blacklisting regions with BLACKLIST pre-made region list, as well as on-the-fly BLAT-hit based "false positive" hits)
CaptureFilterPath="${RunScriptsPath}/filterArtifactMappers"
#------------------------------------------
# From where to call the python plots..
# (blacklisting regions with BLACKLIST pre-made region list, as well as on-the-fly BLAT-hit based "false positive" hits)
CapturePlotPath="${RunScriptsPath}/drawFigure"
#------------------------------------------
# From where to call the CONFIGURATION script..
confFolder="${CaptureTopPath}/conf"
#------------------------------------------
echo
echo "CaptureTopPath ${CaptureTopPath}"
echo "CapturePipePath ${CapturePipePath}"
echo "confFolder ${confFolder}"
echo "RunScriptsPath ${RunScriptsPath}"
echo "CaptureFilterPath ${CaptureFilterPath}"
echo
#------------------------------------------
# Calling in the CONFIGURATION script and its default setup :
# Defaulting this to "not in use" - if it is not set in the config file.
CaptureDigestPath="NOT_IN_USE"
#------------------------------------------
# Calling in the CONFIGURATION script and its default setup :
echo "Calling in the conf/config.sh script and its default setup .."
CaptureDigestPath="NOT_IN_USE"
supportedGenomes=()
ucscGenomeNames=()
BOWTIE1=()
BOWTIE2=()
UCSC=()
BLACKLIST=()
genomesWhichHaveBlacklist=()
# . ${confFolder}/config.sh
. ${confFolder}/genomeBuildSetup.sh
. ${confFolder}/loadNeededTools.sh
. ${confFolder}/serverAddressAndPublicDiskSetup.sh
# setConfigLocations
setPathsForPipe
setGenomeLocations
echo
echo "Supported genomes : "
for g in $( seq 0 $((${#supportedGenomes[@]}-1)) ); do echo -n "${supportedGenomes[$g]} "; done
echo
echo
echo
echo "Blacklist filtering available for these genomes : "
for g in $( seq 0 $((${#genomesWhichHaveBlacklist[@]}-1)) ); do echo -n "${genomesWhichHaveBlacklist[$g]} "; done
echo
echo
echo "Calling in the conf/serverAddressAndPublicDiskSetup.sh script and its default setup .."
SERVERTYPE="UNDEFINED"
SERVERADDRESS="UNDEFINED"
REMOVEfromPUBLICFILEPATH="NOTHING"
ADDtoPUBLICFILEPATH="NOTHING"
tobeREPLACEDinPUBLICFILEPATH="NOTHING"
REPLACEwithThisInPUBLICFILEPATH="NOTHING"
. ${confFolder}/serverAddressAndPublicDiskSetup.sh
setPublicLocations
echo
echo "SERVERTYPE ${SERVERTYPE}"
echo "SERVERADDRESS ${SERVERADDRESS}"
echo "ADDtoPUBLICFILEPATH ${ADDtoPUBLICFILEPATH}"
echo "REMOVEfromPUBLICFILEPATH ${REMOVEfromPUBLICFILEPATH}"
echo "tobeREPLACEDinPUBLICFILEPATH ${tobeREPLACEDinPUBLICFILEPATH}"
echo "REPLACEwithThisInPUBLICFILEPATH ${REPLACEwithThisInPUBLICFILEPATH}"
echo
#------------------------------------------
OPTS=`getopt -o h,m:,M:,o:,c:,s:,w:,i:,v: --long help,dump,snp,dpn,nla,hind,gz,strandSpecificDuplicates,redGreen,triCyellowBlack,onlyCis,onlyBlat,onlyTriC,triC,triCwithExcl,binnedTriC,UMI,useSymbolicLinks,SRR,CCversion:,BLATforREUSEfolderPath:,globin:,outfile:,errfile:,lanes:,limit:,pf:,genome:,R1:,R2:,saveGenomeDigest,dontSaveGenomeDigest,trim,noTrim,chunkmb:,bowtie1,bowtie2,window:,increment:,ada3read1:,ada3read2:,extend:,onlyCCanalyser,onlyHub,noPloidyFilter:,qmin:,flashBases:,flashMismatch:,stringent,trim3:,trim5:,seedmms:,seedlen:,maqerr:,stepSize:,tileSize:,minScore:,minIdentity:,minMatch:,maxIntron:,oneOff:,wobblyEndBinWidth:,ampliconSize:,sonicationSize:,triCbin:,triCmax:,fourFragmentsPerRead,fiveFragmentsPerRead,sixFragmentsPerRead,sevenFragmentsPerRead -- "$@"`
if [ $? != 0 ]
then
exit 1
fi
eval set -- "$OPTS"
while true ; do
case "$1" in
-h) usage ; shift;;
-m) LOWERCASE_M=$2 ; shift 2;;
-M) CAPITAL_M=$2 ; shift 2;;
-o) CapturesiteFile=$2 ; shift 2;;
-c) CapturesiteFile=$2 ; shift 2;;
-w) WINDOW=$2 ; shift 2;;
-i) INCREMENT=$2 ; shift 2;;
-s) Sample=$2 ; shift 2;;
-v) LOWERCASE_V=$2; shift 2;;
--help) usage ; shift;;
--UMI) printThis="UMI flag temporarily broken 01Nov2018\nEXITING";printToLogFile;exit 1;otherParameters="$otherParameters --umi" ; shift;;
--useSymbolicLinks) otherParameters="${otherParameters} --symlinks" ; otherTricParameters="${otherTricParameters} --symlinks"; shift;;
--CCversion) CCversion="$2"; shift 2;;
--dpn) REenzyme="dpnII" ; shift;;
--nla) REenzyme="nlaIII" ; shift;;
--hind) REenzyme="hindIII" ; shift;;
--triC) TRIC=1 ; shift;;
--triCwithExcl) TRIC_EXCL=1 ; shift;;
--binnedTriC) TRIC_BINNED=1 ; shift;;
--onlyCCanalyser) ONLY_CC_ANALYSER=1 ; shift;;
--onlyHub) ONLY_HUB=1 ; shift;;
--onlyTriC) ONLY_TRIC=1 ; shift;;
--onlyCis) onlyCis=1;otherParameters="$otherParameters --onlycis"; shift;;
--onlyBlat) ONLY_BLAT=1 ; shift;;
--onlyBlat) ONLY_BLAT=1 ; shift;;
--fourFragmentsPerRead) fragsPerRead=4 ; shift;;
--fiveFragmentsPerRead) fragsPerRead=5 ; shift;;
--sixFragmentsPerRead) fragsPerRead=6 ; shift;;
--sevenFragmentsPerRead) fragsPerRead=7 ; shift;;
--R1) Read1=$2 ; shift 2;;
--R2) Read2=$2 ; shift 2;;
--lanes) LANES=$2 ; shift 2;;
--gz) GZIP=1 ; shift;;
--SRR) srrFastq=1 ; shift;;
--bowtie1) BOWTIE=1 ; shift;;
--bowtie2) BOWTIE=2 ; shift;;
--chunkmb) BOWTIEMEMORY=$2 ; shift 2;;
--saveGenomeDigest) saveDpnGenome=1 ; shift;;
--dontSaveGenomeDigest) saveDpnGenome=0 ; shift;;
--trim) TRIM=1 ; shift;;
--noTrim) TRIM=0 ; shift;;
--window) WINDOW=$2 ; shift 2;;
--triCbin) TRIC_BIN=$2 ; shift 2;;
--triCmax) TRIC_MAX=$2 ; shift 2;;
--triCyellowBlack) TRIC_OTHER_VISUAL_PARAMS="${TRIC_OTHER_VISUAL_PARAMS} --afmhot" ; shift ;;
--increment) INCREMENT=$2 ; shift 2;;
--genome) GENOME=$2 ; shift 2;;
--ada3read1) ADA31=$2 ; shift 2;;
--ada3read2) ADA32=$2 ; shift 2;;
--extend) extend=$2 ; shift 2;;
--noPloidyFilter) ploidyFilter="--noploidyfilter " ; shift;;
--ampliconSize) ampliconSize=$2 ; shift 2;;
--sonicationSize) ampliconSize=$2 ; shift 2;;
--strandSpecificDuplicates) otherParameters="$otherParameters --stranded"; strandSpecificDuplicates=1 ; shift;;
--dump) otherParameters="$otherParameters --dump" ; shift;;
--snp) otherParameters="$otherParameters --snp" ; shift;;
--globin) otherParameters="$otherParameters --globin $2" ; shift 2;;
--limit) otherParameters="$otherParameters --limit $2" ; shift 2;;
--stringent) otherParameters="$otherParameters --stringent" ; shift 1;;
--pf) PublicPath="$2" ; shift 2;;
--redGreen) REDGREEN=1 ; shift;;
--qmin) QMIN="$2" ; shift 2;;
--BLATforREUSEfolderPath) reuseBLATpath="$2" ; shift 2;;
--flashBases) flashOverlap="$2" ; shift 2;;
--flashMismatch) flashErrorTolerance="$2" ; shift 2;;
--trim3) otherBowtieParameters="${otherBowtieParameters} --trim3 $2 " ; shift 2;;
--trim5) otherBowtieParameters="${otherBowtieParameters} --trim5 $2 " ; shift 2;;
--seedmms) bowtie1MismatchBehavior="${bowtie1MismatchBehavior} --seedmms $2 " ; ${bowtie2MismatchBehavior}="${bowtie2MismatchBehavior} -N $2 " ; shift 2;;
--seedlen) bowtie1MismatchBehavior="${bowtie1MismatchBehavior} --seedlen $2 " ; ${bowtie2MismatchBehavior}="${bowtie2MismatchBehavior} -L $2 " ; shift 2;;
--maqerr) bowtie1MismatchBehavior="${bowtie1MismatchBehavior} --maqerr $2 " ; shift 2;;
--stepSize) stepSize=$2 ; shift 2;;
--tileSize) tileSize=$2 ; shift 2;;
--minScore) minScore=$2 ; shift 2;;
--minMatch) minMatch=$2 ; shift 2;;
--minIdentity) minIdentity=$2 ; shift 2;;
--maxIntron) maxIntron=$2 ; shift 2;;
--oneOff) oneOff=$2 ; shift 2;;
--outfile) QSUBOUTFILE=$2 ; shift 2;;
--errfile) QSUBERRFILE=$2 ; shift 2;;
--wobblyEndBinWidth) otherParameters="$otherParameters --wobble $2" ; shift 2;;
--) shift; break;;
esac
done
# ----------------------------------------------
# Setting the duplicate filter style !
if [ ${CCversion} == "CS5" ] ; then
echo
echo "Duplicate filtering style CS5 selected ! "
echo
elif [ ${CCversion} == "CS3" ] ; then
echo
echo "Duplicate filtering style CS3 selected ! "
echo
elif [ ${CCversion} == "CS4" ] ; then
echo
echo "Duplicate filtering style CS4 selected ! "
echo
else
# Crashing here !
printThis="Duplicate filtering style given wrong ! Give either --CCversion CS3 or --CCversion CS4 ( or default --CCversion CS5 )"
printToLogFile
printThis="You gave --CCversion ${CCversion}"
printToLogFile
printThis="EXITING ! "
printToLogFile
exit 1
fi
# ----------------------------------------------
echo "Parsing the data area and server locations .."
PublicPath="${PublicPath}/${Sample}/${CCversion}_${REenzyme}"
# Here, parsing the data area location, to reach the public are address..
diskFolder=${PublicPath}
serverFolder=""
echo
parsePublicLocations
echo
tempJamesUrl="${SERVERADDRESS}/${serverFolder}"
JamesUrl=$( echo ${tempJamesUrl} | sed 's/\/\//\//g' )
ServerAndPath="${SERVERTYPE}://${JamesUrl}"
# ----------------------------------------------
# Setting artificial chromosome on, if we have it .
if [ ${GENOME} == "mm9PARP" ] ; then
# Whether we have artificial chromosome chrPARP or not, to feed to analyseMappedReads.pl (to be filtered out before visualisation)
# Will be turned on based on genome name, to become :
otherParameters="$otherParameters --parp"
fi
# ----------------------------------------------
# Modifying and adjusting parameter values, based on run flags
setBOWTIEgenomeSizes
setGenomeFasta
echo "GenomeFasta ${GenomeFasta}" >> parameters_capc.log
echo "BowtieGenome ${BowtieGenome}" >> parameters_capc.log
setUCSCgenomeSizes
echo "ucscBuild ${ucscBuild}" >> parameters_capc.log
setUCSCgenomeName
# For custom genomes this is different than the above
# (will be hubbed in a "standard UCSC build")
echo "ucscBuildName ${ucscBuildName}" >> parameters_capc.log
#------------------------------------------
CaptureDigestPath="${CaptureDigestPath}/${REenzyme}"
setParameters
# ----------------------------------------------
# Loading the environment - either with module system or setting them into path.
# This subroutine comes from conf/config.sh file
printThis="LOADING RUNNING ENVIRONMENT"
printToLogFile
setPathsForPipe
#---------------------------------------------------------
# Check that the requested RE actually exists ..
if [ ! -s ${RunScriptsPath}/${REenzyme}cutReads4.pl ] || [ ! -s ${RunScriptsPath}/${REenzyme}cutGenome4.pl ] ; then
printThis="EXITING ! - Restriction enzyme ${REenzyme} is not supported (check your spelling)"
exit 1
fi
#---------------------------------------------------------
# Here parsing the parameter files - if they are not purely tab-limited, but partially space-limited, or multiple-tab limited, this fixes it.
echo
echo "PARAMETER FILES GIVEN IN RUN FOLDER (if any) :"
echo
if [ $(ls PIPE*.txt 2>/dev/null| grep -c "") -gt 0 ]; then
for file in ./PIPE*.txt
do
echo ${file}
sed -i 's/\s\s*/\t/g' ${file}
done
fi
#---------------------------------------------------------
echo "Run with parameters :"
echo
echo "Output log file ${QSUBOUTFILE}" > parameters_capc.log
echo "Output error log file ${QSUBERRFILE}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "CaptureTopPath ${CaptureTopPath}" >> parameters_capc.log
echo "CapturePipePath ${CapturePipePath}" >> parameters_capc.log
echo "confFolder ${confFolder}" >> parameters_capc.log
echo "RunScriptsPath ${RunScriptsPath}" >> parameters_capc.log
echo "CaptureFilterPath ${CaptureFilterPath}" >> parameters_capc.log
echo "CaptureDigestPath ${CaptureDigestPath}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "Sample ${Sample}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "GZIP ${GZIP} (TRUE=1, FALSE=0) - if fastq input files are gzipped "
echo "Read1 ${Read1}" >> parameters_capc.log
echo "Read2 ${Read2}" >> parameters_capc.log
echo "srrFastq ${srrFastq} (TRUE=1, FALSE=0) - if fastq files are SRR format (instead of Illumina) " >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "GENOME ${GENOME}" >> parameters_capc.log
echo "GenomeIndex ${GenomeIndex}" >> parameters_capc.log
echo "CapturesiteFile ${CapturesiteFile}" >> parameters_capc.log
echo "REenzyme ${REenzyme}" >> parameters_capc.log
echo "ONLY_CC_ANALYSER ${ONLY_CC_ANALYSER}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "ONLY_TRIC ${ONLY_TRIC}" >> parameters_capc.log
echo "TRIC ${TRIC}" >> parameters_capc.log
echo "TRIC_EXCL ${TRIC_EXCL}" >> parameters_capc.log
# echo "BINNED_TRIC ${BINNED_TRIC}" >> parameters_capc.log
echo "TRIC_BIN ${TRIC_BIN}" >> parameters_capc.log
echo "TRIC_MAX ${TRIC_MAX}" >> parameters_capc.log
echo "TRIC_OTHER_VISUAL_PARAMS ${TRIC_OTHER_VISUAL_PARAMS}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "TRIM ${TRIM} (TRUE=1, FALSE=0)" >> parameters_capc.log
echo "QMIN ${QMIN} (default 20)" >> parameters_capc.log
echo "CUSTOMAD ${CUSTOMAD} (TRUE=1, FALSE= -1)" >> parameters_capc.log
if [ "${CUSTOMAD}" -ne -1 ]; then
echo "ADA31 ${ADA31}" >> parameters_capc.log
echo "ADA32 ${ADA32}" >> parameters_capc.log
fi
echo "------------------------------" >> parameters_capc.log
echo "flashOverlap ${flashOverlap} (default 10)" >> parameters_capc.log
echo "flashErrorTolerance ${flashErrorTolerance} (default 0.25)" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "saveDpnGenome ${saveDpnGenome} (TRUE=1, FALSE=0)" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "BOWTIEMEMORY ${BOWTIEMEMORY}" >> parameters_capc.log
echo "CAPITAL_M ${CAPITAL_M}" >> parameters_capc.log
echo "LOWERCASE_M ${LOWERCASE_M}" >> parameters_capc.log
echo "otherBowtieParameters ${otherBowtieParameters}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "reuseBLATpath ${reuseBLATpath}" >> parameters_capc.log
echo "stepSize ${stepSize}" >> parameters_capc.log
echo "tileSize ${tileSize}" >> parameters_capc.log
echo "minScore ${minScore}" >> parameters_capc.log
echo "maxIntron ${maxIntron}" >> parameters_capc.log
echo "oneOff ${oneOff}" >> parameters_capc.log
echo "extend ${extend}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "ampliconSize ${ampliconSize}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "ploidyFilter ${ploidyFilter}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "WINDOW ${WINDOW}" >> parameters_capc.log
echo "INCREMENT ${INCREMENT}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "PublicPath ${PublicPath}" >> parameters_capc.log
echo "ServerUrl ${SERVERADDRESS}" >> parameters_capc.log
echo "JamesUrl ${JamesUrl}" >> parameters_capc.log
echo "ServerAndPath ${ServerAndPath}" >> parameters_capc.log
echo "fragsPerRead ${fragsPerRead}"
echo "otherParameters ${otherParameters}" >> parameters_capc.log
echo "------------------------------" >> parameters_capc.log
echo "GenomeFasta ${GenomeFasta}" >> parameters_capc.log
echo "BowtieGenome ${BowtieGenome}" >> parameters_capc.log
echo "ucscBuild ${ucscBuild}" >> parameters_capc.log
cat parameters_capc.log
echo
echo "Whole genome fasta file path : ${GenomeFasta}"
echo "Bowtie genome index path : ${BowtieGenome}"
echo "Chromosome sizes for UCSC bigBed generation will be red from : ${ucscBuild}"
testedFile="${CapturesiteFile}"
doInputFileTesting
#---------------------------------------------------------
# Tri-c long run default user case (if we are not asking TRIC_EXCL) needs mods for the capture coordinate file ..
if [ "${TRIC}" -eq "1" ]; then
printThis="Running as tri-C run : omitting exclusion zones (generating file capturesitesNoExclusions.txt )"
printToLogFile
# Supporting 7-column format, so :
cat ${CapturesiteFile} | sed 's/\s\s*/\t/g' > TEMP_captureSites.txt
cut -f 1 TEMP_captureSites.txt > TEMP_1
cut -f 2-4 TEMP_captureSites.txt > TEMP_2to4
cut -f 1-7 --complement > TEMP_rest
paste TEMP_1 TEMP_2to4 TEMP_2to4 TEMP_rest > capturesitesNoExclusions.txt
rm -f TEMP_captureSites.txt TEMP_1 TEMP_2to4 TEMP_2to4 TEMP_rest
CapturesiteFile=$(pwd)"/capturesitesNoExclusions.txt"
testedFile="${CapturesiteFile}"
doTempFileTesting
ls -lht ${CapturesiteFile}
fi
#---------------------------------------------------------
# Doing the ONLY_BLAT user case first - they doesn't need existing input files (except the capture-site (REfragment) file) - so we shouldn't enter any testing of parameters here.
if [ "${ONLY_BLAT}" -eq "1" ]; then
{
paramGenerationRunFineOK=0
printThis="Running ONLY BLATS (user given --onlyBlat flag, or parallel run first step)"
printToLogFile
# --------------------------
# RE enzyme digestion (if needed .. )
dpnGenomeName=""
fullPathDpnGenome=""
generateReDigest
CCscriptname="${captureScript}.pl"
runCCanalyserOnlyBlat
# Return information to log file if we are parallel ..
if [ "${paramGenerationRunFineOK}" -ne 0 ];then {
printThis="CCanalyser to prepare BLAT runs failed."
printToLogFile
printThis="EXITING !"
printToLogFile
exit 1
}
fi
# --------------------------
${CaptureFilterPath}/filter.sh --onlyBlat ${ONLY_BLAT} --reuseBLAT ${reuseBLATpath} -p parameters_for_filtering.log --pipelinecall --extend ${extend} --onlyCis ${onlyCis} --stepSize ${stepSize} --minScore ${minScore} --minIdentity=${minIdentity} --minMatch=${minMatch} --maxIntron=${maxIntron} --tileSize=${tileSize} --oneOff=${oneOff} --bowtieMemory ${BOWTIEMEMORY} > filtering.log
# cat filtering.log
if [ "$?" -ne 0 ]; then {
printThis="Running filter.sh crashed - BLAT filtering failed !"
printToLogFile
printThis="EXITING !"
printToLogFile
exit 1
}
fi
# --------------------------
rm -rf blat_run_params
mkdir blat_run_params
mv blatParams.txt blat_run_params/.
mv -f parameters_*.log blat_run_params/.
echo > How_to_use_these_BLAT_files.txt
echo "Use the generated BLAT filtering .psl files by adding this to your run command : " >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
echo '--BLATforREUSEfolderPath '$( pwd )/BlatPloidyFilterRun/REUSE_blat/ >> How_to_use_these_BLAT_files.txt
echo > How_to_use_these_BLAT_files.txt
echo "Your psl-files for BLAT-filtering can be found in folder :\n $( pwd )/BlatPloidyFilterRun/REUSE_blat/" >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
echo "Use the generated BLAT filtering .psl files by adding this to your run command : " >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
echo '--BLATforREUSEfolderPath '$( pwd )/BlatPloidyFilterRun/REUSE_blat/ >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
echo "Here full list of generated files : " >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
echo "ls -lht $( pwd )/BlatPloidyFilterRun/REUSE_blat/" >> How_to_use_these_BLAT_files.txt
ls -lht $( pwd )/BlatPloidyFilterRun/REUSE_blat/ >> How_to_use_these_BLAT_files.txt
echo >> How_to_use_these_BLAT_files.txt
printThis="Your psl-files for BLAT-filtering can be found in folder :\n $( pwd )/BlatPloidyFilterRun/REUSE_blat/"
printToLogFile
echo "Use the generated BLAT filtering .psl files in CCseqBasic by adding this to your run command : "
echo '--BLATforREUSEfolderPath '$( pwd )/BlatPloidyFilterRun/REUSE_blat/
printThis="Details of this in the ouput file 'How_to_use_these_BLAT_files.txt' "
printToLogFile
echo
echo "All done !"
echo >> "/dev/stderr"
echo "All done !" >> "/dev/stderr"
exit 0
}
fi
# ---------------------------------------
# Making output folder.. (and crashing run if found it existing from a previous crashed run)
if [ "${ONLY_TRIC}" -eq "0" ]; then
if [ "${ONLY_HUB}" -eq "0" ]; then
if [ "${ONLY_CC_ANALYSER}" -eq "0" ]; then
if [ -d F1_beforeCCanalyser_${Sample}_${CCversion} ] ; then
# Crashing here !
printThis="EXITING ! Previous run data found in run folder ! - delete data of previous run (or define rerun with --onlyCCanalyser )"
printToLogFile
exit 1
fi
mkdir F1_beforeCCanalyser_${Sample}_${CCversion}
fi
fi
fi
# Here crashing if public folder exists (and this is not --onlyCCanalyser run ..
if [ -d ${PublicPath} ] && [ "${ONLY_CC_ANALYSER}" -eq "0" ] && [ ${ONLY_TRIC} -eq "0" ]; then
# Allows to remove if it is empty..
rmdir ${PublicPath}
if [ -d ${PublicPath} ] ; then
# Crashing here !
printThis="EXITING ! Existing public data found in folder ${PublicPath} "
printToLogFile
printThis="Delete the data before restarting the script (refusing to overwrite) "
printToLogFile
exit 1
fi
fi
# The whole CCanalyser part is skipped, if we are tric-only
if [ "${ONLY_TRIC}" -eq "0" ]; then
if [ "${ONLY_HUB}" -eq "0" ]; then
if [ "${ONLY_CC_ANALYSER}" -eq "0" ]; then
#--------Test if fastq paths given correctly ------------------------------------------------------
if [ -r "./PIPE_fastqPaths.txt" ] && [ "${Read1}" != "" ]; then
printThis="PIPE_fastqPaths.txt and --R1 parameter given at the same time. Only one at a time is allowed !"
printToLogFile
printThis="EXITING ! "
printToLogFile
exit 1
fi
if [ -r "./PIPE_fastqPaths.txt" ] && [ "${Read2}" != "" ]; then
printThis="PIPE_fastqPaths.txt and --R2 parameter given at the same time. Only one at a time is allowed !"
printToLogFile
printThis="EXITING ! "
printToLogFile
exit 1
fi
#--------THE-LOOP-over-all-FASTQ-file-based-data-sets------------------------------------------------------
if [ -r "./PIPE_fastqPaths.txt" ] ; then
# Check how many columns we have.
test=0
test=$( cut -f 3 ./PIPE_fastqPaths.txt | grep -vc "^\s*$" )
# If we have 2 columns paired end :
if [ "${test}" -eq "0" ]; then
# Fake list - only first element gets filled (as this is multi-lane support, no multi-sample support)
fileList1=($( cat ./PIPE_fastqPaths.txt | grep -v '^\s*$' | cut -f 1 | tr '\n' ',' | sed 's/,$//' ))
fileList2=($( cat ./PIPE_fastqPaths.txt | grep -v '^\s*$' | cut -f 2 | grep -v '^\s*$' | tr '\n' ',' | sed 's/,$//' ))
# If we have 3 columns paired end :
else
cat ./PIPE_fastqPaths.txt | grep -v '^\s*$' | cut -f 1,3 | awk '{ print $2"/"$1 }'| sed 's/\/\//\//' > forRead1.txt
cat ./PIPE_fastqPaths.txt | grep -v '^\s*$' | cut -f 2,3 | awk '{ print $2"/"$1 }'| sed 's/\/\//\//' > forRead2.txt
# Fake list - only first element gets filled (as this is multi-lane support, no multi-sample support)
fileList1=($( cat ./forRead1.txt | tr '\n' ',' | sed 's/,$//' ))
fileList2=($( cat ./forRead2.txt | tr '\n' ',' | sed 's/,$//' ))
rm -f forRead1.txt forRead2.txt
fi
LANES=$(($( cat ./PIPE_fastqPaths.txt | grep -v '^\s*$' | grep -c "" )))
else
#---------------------------------------
# If we didn't have PIPE_fastqPaths.txt , we have Read1 and Read2 as input parameters instead.
# Copy files over..
# Fake list - only first element gets filled (as this is multi-lane support, no multi-sample support)
fileList1=(${Read1})
fileList2=(${Read2})
LANES=1
#---------------------------------------
fi
# Fetch the files ..
printRunStartArraysFastq
echo "LANES ${LANES}" >> parameters_capc.log
echo "LANES ${LANES}"
# This is a fake list - only having one element (see above)
for (( i=0; i<=$(( ${#fileList1[@]} -1 )); i++ ))
do
# If we have single lane sequencing.
if [ "$LANES" -eq 1 ] ; then
#Fetch FASTQ :
fetchFastq
else
# If we have MULTIPLE lanes from sequencing.
fetchFastqMultilane
fi
done
#---------------------------------------
# Check that we have the files ..
testedFile="READ1.fastq"
doInputFileTesting
testedFile="READ2.fastq"
doInputFileTesting
mv -f READ1.fastq F1_beforeCCanalyser_${Sample}_${CCversion}/READ1.fastq
mv -f READ2.fastq F1_beforeCCanalyser_${Sample}_${CCversion}/READ2.fastq
echo "Generated fastqs :"
ls -lh F1_beforeCCanalyser_${Sample}_${CCversion} | cut -d " " -f 1,2,3,4 --complement
echo "In folder :"
pwd
testedFile="F1_beforeCCanalyser_${Sample}_${CCversion}/READ1.fastq"
doTempFileTesting
testedFile="F1_beforeCCanalyser_${Sample}_${CCversion}/READ2.fastq"
doTempFileTesting
#---------------------------------------
# Save capture-site (REfragment) file full path (to not to lose the file when we cd into the folder, if we used relative paths ! )
TEMPdoWeStartWithSlash=$(($( echo ${CapturesiteFile} | awk '{print substr($1,1,1)}' | grep -c '/' )))
if [ "${TEMPdoWeStartWithSlash}" -eq 0 ]
then
CapturesiteFile=$(pwd)"/"${CapturesiteFile}
fi
testedFile="${CapturesiteFile}"
doInputFileTesting
fi
fi
# Go into output folder..
cd F1_beforeCCanalyser_${Sample}_${CCversion}
if [ "${ONLY_HUB}" -eq "0" ]; then
if [ "${ONLY_CC_ANALYSER}" -eq "0" ]; then