-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCCseqBasic4.sh
More file actions
1376 lines (1002 loc) · 42.5 KB
/
CCseqBasic4.sh
File metadata and controls
1376 lines (1002 loc) · 42.5 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
##########################################################################
# Copyright 2017, Jelena Telenius (jelena.telenius@imm.ox.ac.uk) #
# #
# This file is part of CCseqBasic4 . #
# #
# CCseqBasic4 is free software: you can redistribute it and/or modify #
# it under the terms of the MIT license.
#
#
# #
# CCseqBasic4 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 CCseqBasic4.
##########################################################################
#------------------------------------------
# The codes of the pipeline
#------------------------------------------
#
# CCseqBasic4/
#
# |
# |-- CCseqBasic4.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
echo
echo "Analysis complete !"
date
fi
}
trap finish EXIT
#------------------------------------------
QSUBOUTFILE="qsub.out"
QSUBERRFILE="qsub.err"
OligoFile=""
TRIM=1
GENOME=""
WINDOW=200
INCREMENT=20
CAPITAL_M=0
LOWERCASE_M=0
LOWERCASE_V=-1
BOWTIEMEMORY="256"
Sample="sample"
Read1=""
Read2=""
CUSTOMAD=-1
ADA31="no"
ADA32="no"
# trimgalore default
QMIN=20
# flash defaults
flashOverlap=10
flashErrorTolerance=0.25
saveDpnGenome=0
ucscBuild=""
otherBowtieParameters=""
bowtieMismatchBehavior=""
otherParameters=""
PublicPath="UNDETERMINED"
ploidyFilter=""
extend=20000
# 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)
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="."
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
#------------------------------------------
CCversion="CB4"
captureScript="analyseMappedReads"
CCseqBasicVersion="CCseqBasic4"
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 .."
CaptureTopPath="$( echo $0 | sed 's/\/'${CCseqBasicVersion}'.sh$//' )"
CapturePipePath="${CaptureTopPath}/bin/subroutines"
# 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
# SETTING THE GENOME BUILD PARAMETERS
. ${CapturePipePath}/genomeSetters.sh
# SETTING THE BLACKLIST GENOME LIST PARAMETERS
. ${CapturePipePath}/blacklistSetters.sh
# PRINTING HELP AND VERSION MESSAGES
. ${CapturePipePath}/usageAndVersion.sh
#------------------------------------------
# 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 CONFIGURA`TION 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=()
BOWTIE1=()
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:,s:,w:,i:,v: --long help,dump,snp,dpn,nla,BLATforREUSEfolderPath:,globin:,outfile:,errfile:,limit:,pf:,genome:,R1:,R2:,saveGenomeDigest,dontSaveGenomeDigest,trim,noTrim,chunkmb:,window:,increment:,ada3read1:,ada3read2:,extend:,onlyCCanalyser,onlyHub,noPloidyFilter:,qmin:,flashBases:,flashMismatch:,stringent,trim3:,trim5:,seedmms:,seedlen:,maqerr:,stepSize:,tileSize:,minScore:,maxIntron:,oneOff: -- "$@"`
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) OligoFile=$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;;
--dpn) REenzyme="dpnII" ; shift;;
--nla) REenzyme="nlaIII" ; shift;;
--onlyCCanalyser) ONLY_CC_ANALYSER=1 ; shift;;
--onlyHub) ONLY_HUB=1 ; shift;;
--R1) Read1=$2 ; shift 2;;
--R2) Read2=$2 ; shift 2;;
--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;;
--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;;
--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;;
--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) bowtieMismatchBehavior="${bowtieMismatchBehavior} --seedmms $2 " ; shift 2;;
--seedlen) bowtieMismatchBehavior="${bowtieMismatchBehavior} --seedlen $2 " ; shift 2;;
--maqerr) bowtieMismatchBehavior="${bowtieMismatchBehavior} --maqerr $2 " ; shift 2;;
--stepSize) stepSize=$2 ; shift 2;;
--tileSize) tileSize==$2 ; shift 2;;
--minScore) minScore=$2 ; shift 2;;
--maxIntron) maxIntron=$2 ; shift 2;;
--oneOff) oneOff=$2 ; shift 2;;
--outfile) QSUBOUTFILE=$2 ; shift 2;;
--errfile) QSUBERRFILE=$2 ; shift 2;;
--) shift; break;;
esac
done
# ----------------------------------------------
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
#------------------------------------------
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
#---------------------------------------------------------
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 "Read1 ${Read1}" >> parameters_capc.log
echo "Read2 ${Read2}" >> parameters_capc.log
echo "GENOME ${GENOME}" >> parameters_capc.log
echo "GenomeIndex ${GenomeIndex}" >> parameters_capc.log
echo "OligoFile ${OligoFile}" >> parameters_capc.log
echo "REenzyme ${REenzyme}" >> parameters_capc.log
echo "ONLY_CC_ANALYSER ${ONLY_CC_ANALYSER}" >> 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 "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 "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="${OligoFile}"
doInputFileTesting
# Making output folder.. (and crashing run if found it existing from a previous crashed run)
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
# Here crashing if public folder exists (and this is not --onlyCCanalyser run ..
if [ -d ${PublicPath} ] && [ ${ONLY_CC_ANALYSER} -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} "
printThis="Delete the data before restarting the script (refusing to overwrite) "
printToLogFile
exit 1
fi
fi
if [[ ${ONLY_HUB} -eq "0" ]]; then
if [[ ${ONLY_CC_ANALYSER} -eq "0" ]]; then
# Copy files over..
testedFile="${Read1}"
doInputFileTesting
testedFile="${Read2}"
doInputFileTesting
if [ "${Read1}" != "READ1.fastq" ] ; then
printThis="Copying input file R1.."
printToLogFile
cp "${Read1}" F1_beforeCCanalyser_${Sample}_${CCversion}/READ1.fastq
else
printThis="Making safety copy of the original READ1.fastq : READ1.fastq_original.."
printToLogFile
cp "${Read1}" F1_beforeCCanalyser_${Sample}_${CCversion}/READ1.fastq_original
fi
doQuotaTesting
if [ "${Read2}" != "READ2.fastq" ] ; then
printThis="Copying input file R2.."
printToLogFile
cp "${Read2}" F1_beforeCCanalyser_${Sample}_${CCversion}/READ2.fastq
else
printThis="Making safety copy of the original READ2.fastq : READ2.fastq_original.."
printToLogFile
cp "${Read2}" F1_beforeCCanalyser_${Sample}_${CCversion}/READ2.fastq_original
fi
doQuotaTesting
testedFile="F1_beforeCCanalyser_${Sample}_${CCversion}/READ1.fastq"
doTempFileTesting
testedFile="F1_beforeCCanalyser_${Sample}_${CCversion}/READ2.fastq"
doTempFileTesting
# Save oligo file full path (to not to lose the file when we cd into the folder, if we used relative paths ! )
TEMPdoWeStartWithSlash=$(($( echo ${OligoFile} | awk '{print substr($1,1,1)}' | grep -c '/' )))
if [ "${TEMPdoWeStartWithSlash}" -eq 0 ]
then
OligoFile=$(pwd)"/"${OligoFile}
fi
testedFile="${OligoFile}"
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
################################################################
#Check BOWTIE quality scores..
printThis="Checking the quality score scheme of the fastq files.."
printToLogFile
bowtieQuals=""
LineCount=$(($( grep -c "" READ1.fastq )/4))
if [ "${LineCount}" -gt 100000 ] ; then
bowtieQuals=$( perl ${RunScriptsPath}/fastq_scores_bowtie1.pl -i READ1.fastq -r 90000 )
else
rounds=$((${LineCount}-10))
bowtieQuals=$( perl ${RunScriptsPath}/fastq_scores_bowtie1.pl -i READ1.fastq -r ${rounds} )
fi
echo "Flash, Trim_galore and Bowtie will be ran in quality score scheme : ${bowtieQuals}"
# The location of "zero" for the filtering/trimming programs cutadapt, trim_galore, flash
intQuals=""
if [ "${bowtieQuals}" == "--phred33-quals" ] ; then
intQuals="33"
else
# Both solexa and illumina phred64 have their "zero point" in 64
intQuals="64"
fi
################################################################
# Fastq for original files..
printThis="Running fastQC for input files.."
printToLogFile
printThis="${RunScriptsPath}/QC_and_Trimming.sh --fastqc"
printToLogFile
${RunScriptsPath}/QC_and_Trimming.sh --fastqc
# Changing names of fastqc folders to be "ORIGINAL"
rm -rf READ1_fastqc_ORIGINAL
rm -rf READ2_fastqc_ORIGINAL
mkdir READ1_fastqc_ORIGINAL
mkdir READ2_fastqc_ORIGINAL
mv -f READ1_fastqc.html READ1_fastqc_ORIGINAL/fastqc_report.html
mv -f READ2_fastqc.html READ2_fastqc_ORIGINAL/fastqc_report.html
mv -f READ1_fastqc.zip READ1_fastqc_ORIGINAL.zip
mv -f READ2_fastqc.zip READ2_fastqc_ORIGINAL.zip
ls -lht
################################################################
# Trimgalore for the reads..
if [[ ${TRIM} -eq "1" ]]; then
printThis="Running trim_galore for the reads.."
printToLogFile
printThis="${RunScriptsPath}/QC_and_Trimming.sh -q ${intQuals} --filter 3 --qmin ${QMIN}"
printToLogFile
${RunScriptsPath}/QC_and_Trimming.sh -q "${intQuals}" --filter 3 --qmin ${QMIN}
doQuotaTesting
ls -lht
testedFile="READ1.fastq"
doTempFileTesting
testedFile="READ2.fastq"
doTempFileTesting
################################################################
# Fastq for trimmed files..
printThis="Running fastQC for trimmed files.."
printToLogFile
printThis="${RunScriptsPath}/QC_and_Trimming.sh --fastqc"
printToLogFile
${RunScriptsPath}/QC_and_Trimming.sh --fastqc
# Changing names of fastqc folders to be "TRIMMED"
rm -rf READ1_fastqc_TRIMMED
rm -rf READ2_fastqc_TRIMMED
mkdir READ1_fastqc_TRIMMED
mkdir READ2_fastqc_TRIMMED
mv -f READ1_fastqc.html READ1_fastqc_TRIMMED/fastqc_report.html
mv -f READ2_fastqc.html READ2_fastqc_TRIMMED/fastqc_report.html
mv -f READ1_fastqc.zip READ1_fastqc_TRIMMED.zip
mv -f READ2_fastqc.zip READ2_fastqc_TRIMMED.zip
fi
################################################################
# FLASH for trimmed files..
printThis="Running FLASH for trimmed files.."
printToLogFile
runFlash
ls -lht
doQuotaTesting
rm -f READ1.fastq READ2.fastq
################################################################
# Fastq for flashed files..
printThis="Running fastQC for FLASHed and nonflashed files.."
printToLogFile
rm -rf FLASHED_fastqc
rm -rf NONFLASHED_fastqc
mkdir FLASHED_fastqc
mkdir NONFLASHED_fastqc
printThis="fastqc --quiet -f fastq FLASHED.fastq"
printToLogFile
fastqc --quiet -f fastq FLASHED.fastq
mv -f FLASHED_fastqc.html FLASHED_fastqc/fastqc_report.html
printThis="fastqc --quiet -f fastq NONFLASHED.fastq"
printToLogFile
fastqc --quiet -f fastq NONFLASHED.fastq
mv -f NONFLASHED_fastqc.html NONFLASHED_fastqc/fastqc_report.html
################################################################
# Running dpnII digestion for flashed file..
printThis="Running ${REenzyme} digestion for flashed file.."
printToLogFile
printThis="perl ${RunScriptsPath}/${REenzyme}cutReads4.pl FLASHED.fastq FLASHED"
printToLogFile
perl ${RunScriptsPath}/${REenzyme}cutReads4.pl FLASHED.fastq FLASHED > FLASHED_${REenzyme}digestion.log
cat FLASHED_${REenzyme}digestion.log
ls -lht
doQuotaTesting
testedFile="FLASHED_REdig.fastq"
doTempFileTesting
rm -f FLASHED.fastq
# Running dpnII digestion for non-flashed file..
printThis="Running ${REenzyme} digestion for non-flashed file.."
printToLogFile
printThis="perl ${RunScriptsPath}/${REenzyme}cutReads4.pl NONFLASHED.fastq NONFLASHED"
printToLogFile
perl ${RunScriptsPath}/${REenzyme}cutReads4.pl NONFLASHED.fastq NONFLASHED > NONFLASHED_${REenzyme}digestion.log
cat NONFLASHED_${REenzyme}digestion.log
ls -lht
doQuotaTesting
testedFile="NONFLASHED_REdig.fastq"
doTempFileTesting
rm -f NONFLASHED.fastq
################################################################
# Fastq for flashed files..
printThis="Running fastQC for RE-digested files.."
printToLogFile
rm -rf FLASHED_REdig_fastqc
rm -rf NONFLASHED_REdig_fastqc
mkdir FLASHED_REdig_fastqc
mkdir NONFLASHED_REdig_fastqc
printThis="fastqc --quiet -f fastq FLASHED_REdig.fastq"
printToLogFile
fastqc --quiet -f fastq FLASHED_REdig.fastq
mv -f FLASHED_REdig_fastqc.html FLASHED_REdig_fastqc/fastqc_report.html
printThis="fastqc --quiet -f fastq NONFLASHED_REdig.fastq"
printToLogFile
fastqc --quiet -f fastq NONFLASHED_REdig.fastq
mv -f NONFLASHED_REdig_fastqc.html NONFLASHED_REdig_fastqc/fastqc_report.html
################################################################
# Running Bowtie for the digested file..
printThis="Running Bowtie for the digested files.."
printToLogFile
printThis="Flashed reads Bowtie .."
printToLogFile
echo "Beginning bowtie run (outputting run command after completion) .."
setMparameter
bowtie -p 1 --chunkmb "${BOWTIEMEMORY}" ${otherBowtieParameters} ${bowtieQuals} ${mParameter} --best --strata --sam "${BowtieGenome}" FLASHED_REdig.fastq > FLASHED_REdig.sam
#bowtie -p 1 -m 2 --best --strata --sam --chunkmb 256 ${bowtieQuals} "${BowtieGenome}" Combined_reads_REdig.fastq Combined_reads_REdig.sam
testedFile="FLASHED_REdig.sam"
doTempFileTesting
doQuotaTesting
samtools view -SH FLASHED_REdig.sam | grep bowtie
printThis="Non-flashed reads Bowtie .."
printToLogFile
echo "Beginning bowtie run (outputting run command after completion) .."
setMparameter
bowtie -p 1 --chunkmb "${BOWTIEMEMORY}" ${otherBowtieParameters} ${bowtieQuals} ${mParameter} --best --strata --sam "${BowtieGenome}" NONFLASHED_REdig.fastq > NONFLASHED_REdig.sam
#bowtie -p 1 -m 2 --best --strata --sam --chunkmb 256 ${bowtieQuals} "${BowtieGenome}" Combined_reads_REdig.fastq Combined_reads_REdig.sam
testedFile="NONFLASHED_REdig.sam"
doTempFileTesting
doQuotaTesting
samtools view -SH NONFLASHED_REdig.sam | grep bowtie
# Cleaning up after ourselves ..
printThis="Cleaning up the run folder.."
printToLogFile
#ls -lht Combined_reads_REdig.bam
ls -lht FLASHED_REdig.sam
ls -lht NONFLASHED_REdig.sam
#rm -f Combined_reads_REdig.fastq
rm -f FLASHED_REdig.fastq NONFLASHED_REdig.fastq
else
# This is the "ONLY_CC_ANALYSER" end fi - if testrun, skipped everything before this point :
# assuming existing output on the above mentioned files - all correctly formed except captureC output !
echo
echo "RE-RUN ! - running only capC analyser script, and filtering (assuming previous pipeline output in the run folder)"
echo
# Here deleting the existing - and failed - capturec analysis directory. not touching public files.
rm -rf "../F2_redGraphs_${Sample}_${CCversion}"
rm -rf "../F3_orangeGraphs_${Sample}_${CCversion}"
rm -rf "../F4_blatPloidyFilteringLog_${Sample}_${CCversion}"
rm -rf "../F5_greenGraphs_separate_${Sample}_${CCversion}"
rm -rf "../F6_greenGraphs_combined_${Sample}_${CCversion}"
rm -rf "../F7_summaryFigure_${Sample}_${CCversion}"
rm -rf ../filteringLogFor_PREfiltered_${Sample}_${CCversion} ../RAW_${Sample}_${CCversion} ../PREfiltered_${Sample}_${CCversion} ../FILTERED_${Sample}_${CCversion} ../COMBINED_${Sample}_${CCversion}
# Remove the malformed public folder for a new try..
rm -rf ${PublicPath}
# Restoring the input sam files..
# Run crash : we will have SAM instead of bam - if we don't check existence here, we will overwrite (due to funny glitch in samtools 1.1 )
if [ ! -s FLASHED_REdig.sam ]
then
samtools view -h FLASHED_REdig.bam > TEMP.sam
mv -f TEMP.sam FLASHED_REdig.sam
if [ -s FLASHED_REdig.sam ]; then
rm -f FLASHED_REdig.bam
else
echo "EXITING ! : Couldn't make FLASHED_REdig.sam from FLASHED_REdig.bam" >> "/dev/stderr"
exit 1
fi
fi
# Run crash : we will have SAM instead of bam - if we don't check existence here, we will overwrite (due to funny glitch in samtools 1.1 )
if [ ! -s NONFLASHED_REdig.sam ]
then
samtools view -h NONFLASHED_REdig.bam > TEMP.sam
mv -f TEMP.sam NONFLASHED_REdig.sam
if [ -s NONFLASHED_REdig.sam ]; then
rm -f NONFLASHED_REdig.bam
else
echo "EXITING ! : Couldn't make NONFLASHED_REdig.sam from NONFLASHED_REdig.bam" >> "/dev/stderr"
exit 1
fi
fi
fi
################################################################
# Running whole genome fasta dpnII digestion..
rm -f genome_${REenzyme}_coordinates.txt
if [ -s ${CaptureDigestPath}/${GENOME}.txt ]
then
ln -s ${CaptureDigestPath}/${GENOME}.txt genome_${REenzyme}_coordinates.txt
else
# Running the digestion ..
# dpnIIcutGenome.pl
# nlaIIIcutGenome.pl
printThis="Running whole genome fasta ${REenzyme} digestion.."
printToLogFile
printThis="perl ${RunScriptsPath}/${REenzyme}cutGenome4.pl ${GenomeFasta}"
printToLogFile
perl ${RunScriptsPath}/${REenzyme}cutGenome4.pl "${GenomeFasta}"
testedFile="genome_${REenzyme}_coordinates.txt"
doTempFileTesting
doQuotaTesting
fi
ls -lht
################################################################
# Store the pre-CCanalyser log files for metadata html
printThis="Store the pre-CCanalyser log files for metadata html.."
printToLogFile
copyPreCCanalyserLogFilesToPublic
dpnGenomeName=$( echo "${GenomeFasta}" | sed 's/.*\///' | sed 's/\..*//' )
# output file :
# ${GenomeFasta}_dpnII_coordinates.txt
fullPathDpnGenome=$(pwd)"/genome_dpnII_coordinates.txt"
cd ..
################################################################
# Running CAPTURE-C analyser for the aligned file..
printThis="##################################"
printToLogFile
printThis="Running CCanalyser without filtering - generating the RED graphs.."
printToLogFile
printThis="##################################"
printToLogFile
runDir=$( pwd )
dirForQuotaAsking=${runDir}
samDirForCCanalyser=${runDir}
publicPathForCCanalyser="${PublicPath}/RAW"
JamesUrlForCCanalyser="${JamesUrl}/RAW"
CCscriptname="${captureScript}.pl"
################################
printThis="Flashed reads.."
printToLogFile
sampleForCCanalyser="RAW_${Sample}"
samForCCanalyser="F1_beforeCCanalyser_${Sample}_${CCversion}/FLASHED_REdig.sam"
testedFile="${samForCCanalyser}"
doTempFileTesting
rm -f parameters_for_filtering.log
# For testing purposes..
# otherParameters="${otherParameters} --dump"
FLASHED=1
DUPLFILTER=0
runCCanalyser
doQuotaTesting
printThis="##################################"
printToLogFile
printThis="Non-flashed reads.."
printToLogFile
sampleForCCanalyser="RAW_${Sample}"
samForCCanalyser="F1_beforeCCanalyser_${Sample}_${CCversion}/NONFLASHED_REdig.sam"