-
Notifications
You must be signed in to change notification settings - Fork 4
/
RedDog.py
executable file
·2730 lines (2475 loc) · 130 KB
/
RedDog.py
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/env python
'''
RedDog V1beta.11 ("StopBreakingIt") 260719
======
Copyright (c) 2016 David Edwards, Bernie Pope, Kat Holt
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Description:
This program implements a worklow pipeline for short read length
sequencing analysis, including the read mapping task, through to variant
detection, followed by analyses (SNPs only).
It uses Rubra (https://github.com/bjpop/rubra) based on the
Ruffus package (v2.2).
It supports parallel evaluation of independent pipeline stages,
and can run stages on a cluster environment.
Note: for Illumina paired-end or single reads, or Ion Torrent single reads.
IMPORTANT: See config file/instructions for input options/requirements
Version History: See ReadMe.txt
'''
from ruffus import *
import os
import shutil
import sys
import glob
from rubra.utils import pipeline_options
from rubra.utils import (runStageCheck, splitPath)
from pipe_utils import (isGenbank, isFasta, chromInfoFasta, chromInfoGenbank, getValue,
getCover, make_sequence_list, getSuccessCount, make_run_report,
get_run_report_data, getFastaDetails, checkBases)
version = "V1beta.11"
modules = pipeline_options.stageDefaults['modules']
# determine the reference file,
# list of sequence files, and list of chromosmes.
try:
reference = pipeline_options.reference
except:
print "\nNo Reference supplied"
print "Pipeline Stopped: please supply a reference in the config file\n"
sys.exit()
#check that a reference has been given in the options file
if reference == "":
print "\nNo Reference supplied"
print "Pipeline Stopped: please supply a reference in the config file\n"
sys.exit()
#check whether reference file exists
if not os.path.exists(reference):
print "\nReference supplied does not exist"
print "Pipeline Stopped: please check supplied reference\n"
sys.exit()
#check whether reference is in FASTA or GenBank format
if isFasta(reference):
refGenbank = False
checkBases(reference, 'fasta')
replicons = chromInfoFasta(reference)
elif isGenbank(reference):
refGenbank = True
checkBases(reference, 'genbank')
replicons = chromInfoGenbank(reference)
else:
print "\nReference not in GenBank or FASTA format"
print "Pipeline Stopped: please check your reference\n"
sys.exit()
# check that reference name does not in contain "+"
if reference.find("+") != -1:
print "\nReference has an illegal character in the name ('+') "
print "Pipeline Stopped: please change the name of the reference\n"
sys.exit()
# check that replicons in reference have non-unique names
if len(replicons)>1:
for i in range(len(replicons)-1):
for j in range (i+1, len(replicons)):
if replicons[i][0] != replicons[j][0]:
pass
else:
print "\nReference has replicons with non-unique names: " + replicons[i][0]
print "Pipeline Stopped: please check your reference\n"
sys.exit()
# check that replicon names in reference do not in contain '|', ':', '+', or '.'
# these all cause problems in third-party scripts
for i in range(len(replicons)):
if replicons[i][0].find(":") != -1 or replicons[i][0].find("+") != -1 or replicons[i][0].find("|") != -1 or replicons[i][0].find(".") != -1:
print "\nReference has replicon with an illegal character ('|', ':', '+', or '.'): " + replicons[i][0]
print "Pipeline Stopped: please change the name of the replicon in the reference\n"
sys.exit()
(refPrefix, refName, refExt) = splitPath(reference)
try:
sequencePatterns = pipeline_options.sequences
except:
print "\nNo Sequences option supplied"
print "Pipeline Stopped: please include 'sequences' in the config file\n"
sys.exit()
try:
runType = pipeline_options.runType
except:
runType = ""
try:
core_replicon = pipeline_options.core_replicon
except:
core_replicon = ""
#check that a 'known' runType has been supplied
if runType != "":
if runType == "pangenome" or runType == "phylogeny":
pass
else:
print "\nUnrecognised run type"
print "Pipeline Stopped: please check 'runType' in the config file\n"
sys.exit()
# if no runType entered, work out default runType on number of replicons in reference
if runType == "":
if len(replicons) > 100:
runType = "pangenome"
elif len(replicons) > 0:
runType = "phylogeny"
if len(replicons) < 1:
print "\nNo chromosomes found in reference"
print "Pipeline Stopped: please check 'reference' in the config file\n"
sys.exit()
repliconNames = []
longest_replicon_length = 0
for repliconName, repliconLength in replicons:
repliconNames.append(repliconName)
if int(repliconLength) > longest_replicon_length:
longest_replicon_length = int(repliconLength)
core_replicons = []
if runType == "pangenome":
if core_replicon == "":
for repliconName, repliconLength in replicons:
if int(repliconLength) == longest_replicon_length:
core_replicon = repliconName
core_replicons = core_replicon.split(', ')
sequences = []
if type(sequencePatterns) == list:
for pattern in sequencePatterns:
sequences += glob.glob(pattern)
else:
sequences = glob.glob(sequencePatterns)
if sequences == []:
if sequencePatterns == "":
print "\nNo mapping - analysis only"
print "Pipeline Stopped: Not Yet Available\n"
sys.exit()
else:
print "\nNo matching sequences found"
print "Pipeline Stopped: please check 'sequences' in the config file\n"
sys.exit()
for sequence in sequences:
if sequence.find(":") != -1 or sequence.find("+") != -1:
print "\nA read set has an illegal character (':' or '+'): " + sequence
print "Pipeline Stopped: please change the name of the read set\n"
sys.exit()
try:
readType = pipeline_options.readType
except:
readType = 'PE'
if readType == 'IT' or readType == 'PE' or readType == 'SE':
pass
elif readType == '':
readType = 'PE'
else:
print "\nUnrecognised read type"
print "Pipeline Stopped: please check 'readType' in the config file\n"
sys.exit()
if readType == 'SE':
readPattern = '.fastq.gz'
elif readType == 'IT':
readPattern = '_in.iontor.fastq.gz'
mapping_out = ""
try:
mapping = pipeline_options.mapping
except:
mapping = 'bowtie'
if mapping == "":
mapping = 'bowtie'
if mapping == 'bwa' and readType == 'SE':
mapping_out = 'BWA V0.6.2 samse'
elif mapping == 'bwa' and readType == 'PE':
mapping_out = 'BWA V0.6.2 sampe'
elif mapping == 'bowtie':
mapping_out = 'Bowtie2 V2.2.9'
else:
print "\nUnrecognised mapping option"
print "Pipeline Stopped: please check 'mapping' in the config file\n"
sys.exit()
try:
SNPcaller = pipeline_options.SNPcaller
if not(SNPcaller != 'c' or SNPcaller != 'm'):
print "\nUnrecognised SNPcaller option"
print "Pipeline Stopped: please check 'SNPcaller' in the config file\n"
else:
SNPcaller = '-' + SNPcaller
except:
SNPcaller = '-c'
sequence_list = []
for sequence in sequences:
(prefix, name, ext) = splitPath(sequence)
if readType == "IT":
sequence_list.append(name[:-16])
elif readType == "PE":
if name.find('_1.fastq') != -1 and name[:-8] not in sequence_list:
sequence_list.append(name[:-8])
if name.find('_2.fastq') != -1 and name[:-8] not in sequence_list:
sequence_list.append(name[:-8])
else:
sequence_list.append(name[:-6])
if readType == 'PE':
missing_pairs = []
for seqName in sequence_list:
test_1 = False
test_2 = False
for sequence in sequences:
if sequence.find(seqName+'_1.f') != -1:
test_1 = True
if sequence.find(seqName+'_2.f') != -1:
test_2 = True
if test_1 == False or test_2 == False:
missing_pairs.append(seqName)
if missing_pairs != []:
print "\nNot all sequence sets have pairs:"
for seq in missing_pairs:
print seq
print "Pipeline Stopped: please fix sequence pairs\n"
sys.exit()
if mapping == 'bowtie':
try:
bowtie_map_type = pipeline_options.bowtie_map_type
except:
bowtie_map_type = '--sensitive-local'
if bowtie_map_type == "":
bowtie_map_type = '--sensitive-local'
if (bowtie_map_type == "--very-fast" or
bowtie_map_type == "--fast" or
bowtie_map_type == "--sensitive" or
bowtie_map_type == "--very-sensitive" or
bowtie_map_type == "--very-fast-local" or
bowtie_map_type == "--fast-local" or
bowtie_map_type == "--sensitive-local" or
bowtie_map_type == "--very-sensitive-local"):
pass
else:
print "\nUnrecognised Bowtie2 mapping option"
print "Pipeline Stopped: please check 'bowtie_map_type' in the config file\n"
sys.exit()
else:
bowtie_map_type = "-"
try:
bowtie_X_value = pipeline_options.bowtie_X_value
except:
bowtie_X_value = 2000
try:
minDepth = pipeline_options.minimum_depth
except:
minDepth = 5
try:
HetsVCF = pipeline_options.HetsVCF
if HetsVCF != True and HetsVCF != False:
print "\nUnrecognised HetsVCF option"
print "Pipeline Stopped: please check 'HetsVCF' in the config file\n"
sys.exit()
except:
HetsVCF = True
try:
coverFail = pipeline_options.cover_fail
except:
coverFail = 50
try:
depthFail = pipeline_options.depth_fail
except:
depthFail = 10
try:
mappedFail = pipeline_options.mapped_fail
except:
mappedFail = 50
try:
sdOutgroupMultiplier = pipeline_options.sd_out
except:
sdOutgroupMultiplier = 2
try:
strand_bias_cutoff = pipeline_options.strand_bias_cutoff
except:
strand_bias_cutoff = 0.8
try:
check_reads_mapped = pipeline_options.check_reads_mapped
except:
check_reads_mapped = ""
if check_reads_mapped == "":
for repliconName, repliconLength in replicons:
if int(repliconLength) == longest_replicon_length:
check_reads_mapped = repliconName
elif check_reads_mapped != 'off':
if check_reads_mapped.find(',') == -1:
if check_reads_mapped not in repliconNames:
print "\nUnrecognised replicon used in 'check_reads_mapped': " + check_reads_mapped
print "Pipeline Stopped: please check 'check_reads_mapped' in the config file\n"
sys.exit()
else:
found_x = False
final_ratio = 1.0
list_of_replicons = []
check_reps = check_reads_mapped.split(',')
for item in check_reps:
if item != 'x':
if found_x != True:
list_of_replicons.append(item)
else:
final_ratio -= float(item)
else:
found_x = True
if final_ratio <= 0:
print "\nFinal ratio in 'check_reads_mapped' less than or equal to zero"
print "Pipeline Stopped: please check ratio(s) in 'check_reads_mapped' in the config file\n"
sys.exit()
list_of_replicons_done = []
for replicon in list_of_replicons:
if replicon not in repliconNames:
print "\nUnrecognised replicon in 'check_reads_mapped': " + replicon
print "Pipeline Stopped: please check 'check_reads_mapped' in the config file\n"
sys.exit()
elif replicon not in list_of_replicons_done:
list_of_replicons_done.append(replicon)
else:
print "\nReplicon repeated in 'check_reads_mapped': " + replicon
print "Pipeline Stopped: please check 'check_reads_mapped' in the config file\n"
sys.exit()
try:
outPrefix = pipeline_options.output
except:
outPrefix = ""
if outPrefix == "":
print "\nNo Output folder given"
print "Pipeline Stopped: please check 'output' in the config file\n"
sys.exit()
if outPrefix[-1] != '/':
outPrefix += '/'
outTempPrefix = outPrefix + 'temp/'
outSuccessPrefix = outTempPrefix + 'success/'
outBamPrefix = outPrefix + 'bam/'
outVcfPrefix = outPrefix + 'vcf/'
if os.path.isdir(outPrefix) and not(os.path.exists(outSuccessPrefix + "dir.makeDir.Success")):
print "\nOutput folder already exists"
print "Pipeline Stopped: please change 'output' to a new folder\n"
sys.exit()
try:
outMerge = pipeline_options.out_merge_target
except:
print "\n'out_merge_target' not set"
print "Pipeline Stopped: please set 'out_merge_target' in the config file\n"
sys.exit()
if outPrefix == outMerge:
print "\nOutput folder and out_merge_target for run are the same"
print "Pipeline Stopped: please check 'output' and 'out_merge_target' in the config file\n"
sys.exit()
continuity_test = False
if outMerge != '':
if outMerge[-1] != '/':
outMerge += '/'
outMergeBam = outMerge + 'bam/'
outMergeVcf = outMerge + 'vcf/'
if not(os.path.isdir(outMerge)):
print "\nMerge target folder not found"
print "Pipeline Stopped: please change 'out_merge_target' to previous output folder\n"
sys.exit()
else:
if not(os.path.isdir(outMergeBam)):
print "\nBAM folder not found"
print "Pipeline Stopped: check 'out_merge_target' has BAM folder\n"
sys.exit()
if not(os.path.isdir(outMergeVcf)):
print "\nVCF folder not found"
print "Pipeline Stopped: check 'out_merge_target' has VCF folder\n"
sys.exit()
if os.path.exists(outMerge + 'finish.deleteDir.Success'):
print "\n'out_merge_target' still has 'finish.deleteDir.Success' file"
print "Pipeline Stopped: please delete this file before restarting\n"
sys.exit()
if os.path.exists(outMerge + refName +'_AllStats.txt') != True:
print "\n'out_merge_target' has no '"+ refName+"_AllStats.txt' file"
print "Pipeline Stopped: please check you have the correct 'reference' and/or "
print "\t\t 'out_merge_target' before restarting\n"
sys.exit()
merge_run = True
if os.path.exists(outMerge + refName + '_run_report.txt'):
(read_history,
run_history,
old_ref_name,
old_ref_format,
old_replicon_count,
old_core_replicon_list,
old_run_type,
old_bowtie_preset,
old_bowtie_X,
old_user_failed_list,
old_min_depth,
old_cover_fail,
old_depth_fail,
old_mapped_fail,
old_replicon_test_list,
old_replicon_percent_list,
old_conservation,
old_sd_out,
old_replicon_list) = get_run_report_data(outMerge + refName + '_run_report.txt')
continuity_test = True
run_count = run_history.count('merge')
if run_count == -1:
run_count = 0
else:
print "\nMerge Run: No prior run report found"
print "No continuity tests will be done...\n"
run_history = '-'
read_history = '_'
else:
merge_run = False
run_history = '-'
read_history = '-'
try:
if pipeline_options.replaceReads != "":
replaceReads = pipeline_options.replaceReads
else:
replaceReads = "-"
except:
replaceReads = "-"
try:
conservation = float(pipeline_options.conservation)
except:
conservation = 0.95
if conservation > 1.0 or conservation < 0.0:
print "\n'conservation' set to value outside parameters"
print "Pipeline Stopped: please change 'conservation' to a value between 0 and 1\n"
sys.exit()
try:
DifferenceMatrix = pipeline_options.DifferenceMatrix
if DifferenceMatrix != True and DifferenceMatrix != False:
print "\nUnrecognised DifferenceMatrix option"
print "Pipeline Stopped: please check 'DifferenceMatrix' in the config file\n"
sys.exit()
except:
DifferenceMatrix = False
try:
force_tree = pipeline_options.force_tree
if force_tree != True and force_tree != False:
print "\nUnrecognised force_tree option"
print "Pipeline Stopped: please check 'force_tree' in the config file\n"
sys.exit()
except:
force_tree = False
try:
force_no_tree = pipeline_options.force_no_tree
if force_no_tree != True and force_no_tree != False:
print "\nUnrecognised force_no_tree option"
print "Pipeline Stopped: please check 'force_no_tree' in the config file\n"
sys.exit()
except:
force_no_tree = False
full_sequence_list = []
if outMerge == '':
for item in sequence_list:
full_sequence_list.append(item)
else:
for item in sequence_list:
full_sequence_list.append(item)
try:
sequence_list_file = open((outMerge + 'sequence_list.txt') , "r")
except:
print "\nNo sequence list found"
print "Pipeline Stopped: please generate new 'sequence_list.txt' file\n"
sys.exit()
for line in sequence_list_file:
full_sequence_list.append(line[:-1])
sequence_list_file.close()
duplicate_isolate_name = []
for i in range(len(full_sequence_list)-1):
for j in range(i+1, len(full_sequence_list)):
if full_sequence_list[i] == full_sequence_list[j]:
duplicate_isolate_name.append(i)
if duplicate_isolate_name != []:
print "\nDuplicate reads (isolate) names found"
print "Pipeline Stopped: please remove/rename duplicates"
for i in duplicate_isolate_name:
print full_sequence_list[i]
print "\n"
sys.exit()
full_sequence_list_string = ""
for sequence in full_sequence_list:
full_sequence_list_string += sequence + ","
full_sequence_list_string.rstrip()
sequence_list_string = ""
for sequence in sequence_list:
sequence_list_string += sequence + ","
sequence_list_string.rstrip()
success_count = len(glob.glob(outSuccessPrefix+"*.Success"))
# test for continuity with prior run for merge runs
if continuity_test:
if refName != old_ref_name:
print "\nReference name is different from prior run(s)"
print "Pipeline Stopped: please use correct reference\n"
sys.exit()
if refGenbank and old_ref_format != 'Genbank':
print "\nExpected FASTA reference, not Genbank"
print "Pipeline Stopped: please use correct reference\n"
sys.exit()
if not refGenbank and old_ref_format == 'Genbank':
print "\nExpected Genbank reference, not FASTA"
print "Pipeline Stopped: please use correct reference\n"
sys.exit()
if len(replicons) != int(old_replicon_count):
print "\nDifferent number of replicons found in reference"
print "Pipeline Stopped: please use correct reference\n"
sys.exit()
if runType != old_run_type:
print "\nExpected " + old_run_type + " run; " + runType + " run specified"
print "Pipeline Stopped: please specify same run type as previously used ("+old_run_type+")\n"
sys.exit()
replicon_fail = False
if runType == 'pangenome':
for replicon in old_core_replicon_list:
if replicon not in core_replicons:
replicon_fail = True
for replicon in core_replicons:
if replicon not in old_core_replicon_list:
replicon_fail = True
if replicion_fail:
print "\nCore replicons have changed since last run"
print "Pipeline Stopped: please specify reference with same replicons as previously used\n"
sys.exit()
else:
replicon_names = []
for replicon in replicons:
replicon_names.append(replicon[0])
if replicon[0] not in old_replicon_list:
replicon_fail = True
for replicon in old_replicon_list:
if replicon not in replicon_names:
replicon_fail = True
if replicon_fail:
print "\nReplicons have changed since last run"
print "Pipeline Stopped: please specify reference with same replicons as previously\n"
sys.exit()
if old_mapped_fail != 'off':
old_check_reads_mapped = ""
for replicon in old_replicon_test_list:
if len(old_replicon_test_list) > 1:
old_check_reads_mapped += (replicon + ",")
else:
old_check_reads_mapped = replicon
if len(old_replicon_test_list) > 1:
old_check_reads_mapped += 'x,'
for number in range(len(old_replicon_percent_list)-1):
if number < len(old_replicon_percent_list)-2:
old_check_reads_mapped += str(float(old_replicon_percent_list[number])/100) + ','
else:
old_check_reads_mapped += str(float(old_replicon_percent_list[number])/100)
if check_reads_mapped != 'off':
check_test = True
if len(old_replicon_test_list) == 1:
if check_reads_mapped.find(',x,') != -1:
check_test = False
else:
if old_replicon_test_list[0] != check_reads_mapped:
check_test = False
if len(old_replicon_test_list) > 1:
if check_reads_mapped.find(',x,') == -1:
check_test = False
else:
all_values = check_reads_mapped.split(',x,')
names = all_values[0].split(',')
values = all_values[1].split(',')
if len(names) != len(old_replicon_test_list):
check_test = False
else:
for name in names:
if name not in old_replicon_test_list:
check_test = False
for name in old_replicon_test_list:
if name not in names:
check_test = False
replicon_value_test = []
for number in range(len(old_replicon_percent_list)-1):
replicon_value_test.append(float(old_replicon_percent_list[number])/100)
if len(values) != len(replicon_value_test):
check_test = False
else:
for number in range(len(values)):
if float(values[number]) != replicon_value_test[number]:
check_test = False
if not check_test:
print "\n'check_reads_mapped' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input("\nWhich 'check_reads_mapped' do you want to use: \n[1] the new value, or\n[2] the old value?\n")
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
print "\n'check_reads_mapped' restored to previously used setting:"
print old_check_reads_mapped + "\n\n"
check_reads_mapped = old_check_reads_mapped
elif keyboard_entry == '1':
print "\n'check_reads_mapped' using new setting:"
print check_reads_mapped + "\n"
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for 'yes', or '2' for 'no'"
else:
print "\n'check_reads_mapped' has changed to 'off' since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nAre you sure you want to turn off checking percentage of reads mapped: \n[1] yes, or\n[2] no?\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
print "\n'check_reads_mapped' restored to previously used setting:"
print old_check_reads_mapped + "\n"
check_reads_mapped = old_check_reads_mapped
elif keyboard_entry == '1':
print "\n'check_reads_mapped' set to 'off' confirmed\n"
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for 'yes', or '2' for 'no'"
else:
if check_reads_mapped != "off":
print "\n'check_reads_mapped' has changed from 'off' since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nAre you sure you want to turn on checking percentage of reads mapped: \n[1] yes, or\n[2] no?\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
print "\n'check_reads_mapped' set to 'off' confirmed\n"
check_reads_mapped = 'off'
elif keyboard_entry == '1':
print "\n'check_reads_mapped' changed from 'off' and set to:"
print check_reads_mapped + "\n"
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for 'yes', or '2' for 'no'"
if old_bowtie_preset != '' and old_bowtie_preset != bowtie_map_type:
print "\n'bowtie_map_type' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+bowtie_map_type +'), or\n[2] the old value? ('+old_bowtie_preset+')\nNote: this only affects new read sets\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
bowtie_map_type = old_bowtie_preset
print "\n'bowtie_map_type' set to " + bowtie_map_type
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for new value, or '2' for old value"
if old_bowtie_X != '' and int(old_bowtie_X) != bowtie_X_value:
print "\n'bowtie_X_value' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(bowtie_X_value) +'), or\n[2] the old value? ('+old_bowtie_X+')\nNote: this only affects new read sets\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
bowtie_X_value = int(old_bowtie_X)
print "\n'bowtie_X_value' set to " + str(bowtie_X_value)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for new value, or '2' for old value"
if int(old_min_depth) != minDepth:
print "\n'minimum_depth' for SNP calling has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(minDepth)+'), or\n[2] the old value? ('+old_min_depth+')\nNote: this only affects new read sets\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
minDepth = int(old_min_depth)
print "\n'minimum_depth' set to " + str(minDepth)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for new value, or '2' for old value"
if int(old_cover_fail) != coverFail:
print "\n'cover_fail' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(coverFail)+'), or\n[2] the old value? ('+old_cover_fail+')\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
coverFail = int(old_cover_fail)
print "\n'cover_fail' set to " + str(coverFail)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for new value, or '2' for old value"
if int(old_depth_fail) != depthFail:
print "\n'depth_fail' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(depthFail)+'), or\n[2] the old value? ('+old_depth_fail+')\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
depthFail = int(old_depth_fail)
print "\n'depth_fail' set to " + str(depthFail)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter '1' for new value, or '2' for old value"
if old_mapped_fail != 'off' and check_reads_mapped != 'off':
if int(old_mapped_fail) != mappedFail:
print "\n'mapped_fail' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(mappedFail)+'), or\n[2] the old value? ('+old_mapped_fail+')\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
mappedFail = int(old_mapped_fail)
print "\n'mapped_fail' set to " + str(mappedFail)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter either '1' for new value, or '2' for old value"
if int(old_sd_out) != sdOutgroupMultiplier:
print "\n'sd_out' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(sdOutgroupMultiplier)+'), or\n[2] the old value? ('+old_sd_out+')\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
sdOutgroupMultiplier = old_sd_out
print "\n'sd_out' set to " + str(sdOutgroupMultiplier)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter '1' for new value, or '2' for old value"
if float(old_conservation) != conservation:
print "\n'conservation' has changed since last run"
value_change = False
attempts_count = 0
while value_change == False:
keyboard_entry = raw_input('\nDo you wish to use: \n[1] the new value ('+str(conservation)+'), or\n[2] the old value? ('+old_conservation+')\n')
if keyboard_entry == '1' or keyboard_entry == '2':
value_change = True
if keyboard_entry == '2':
conservation = int(old_conservation)
print "\n'conservation' set to " + str(conservation)
else:
attempts_count +=1
if attempts_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter '1' for new value, or '2' for old value"
#Phew! Now that's all set up, we can begin...
#but first, output run conditions to user and get confirmation to run
print "\nRedDog " + version + " - " + runType + " run\n"
print "Copyright (c) 2016 David Edwards, Bernie Pope, Kat Holt"
print "All rights reserved. (see README.txt for more details)\n"
print "Mapping: " + mapping_out
if mapping == 'bowtie':
print "Preset Option: " + bowtie_map_type
if refGenbank == False:
ref_string = 'FASTA'
else:
ref_string = 'GenBank'
print str(len(replicons)) + " replicon(s) in " + ref_string + " reference " + refName
if runType != '':
if runType == 'phylogeny':
number_string = str(len(replicons))
else:
number_string = str(len(core_replicons))
print number_string + " replicon(s) to be reported"
number_string = str(len(sequence_list))
if readType == 'PE':
print number_string + " sequence pair(s) to be mapped"
else:
print number_string + " sequence(s) to be mapped"
print "\nOutput folder:"
print outPrefix
if outMerge != '':
print "Remember: this output folder will be deleted at the end of the run\n"
print "Merge new sets with the following folder ('out_merge_target'):"
print outMerge
if pipeline_options.no_check:
start_run = True
else:
start_run = False
start_count = 0
while start_run == False:
keyboard_entry = raw_input('\nStart Pipeline? (y/n) ')
if keyboard_entry == 'y' or keyboard_entry == 'Y' or keyboard_entry == 'yes' or keyboard_entry == 'Yes' or keyboard_entry == 'YES':
start_run = True
elif keyboard_entry == 'n' or keyboard_entry == 'N' or keyboard_entry == 'no' or keyboard_entry == 'No' or keyboard_entry == 'NO':
print "\nPipeline Stopped: user request\n"
sys.exit()
else:
start_count +=1
if start_count >= 3:
print "\nPipeline Stopped: too many tries\n"
sys.exit()
else:
print "Please enter 'y' (yes) or 'n' (no)"
print "\nStarting pipeline..."
stage_count = 0
# Create temp and other output subfolders
@files(input==None, outSuccessPrefix + "dir.makeDir.Success")
def makeDir(input, flagFile):
runStageCheck('makeDir', flagFile, outPrefix, full_sequence_list_string)
stage_count += 1
if refGenbank == False:
# Copy reference to outTemp
newReference = outTempPrefix + refName + refExt
@follows(makeDir)
@files(reference, [newReference, outSuccessPrefix + refName + '.copyRef.Success'])
def copyRef(reference, outputs):
_output, flagFile = outputs
runStageCheck('copyRef', flagFile, reference, outTempPrefix)
reference = newReference
stage_count += 1
# Index copy of reference for SNP calling by samtools
@follows(copyRef)
@files(reference, [reference + '.fai', outSuccessPrefix + refName + '.indexRef.Success'])
def indexRef(reference, outputs):
_output, flagFile = outputs
runStageCheck('indexRef', flagFile, reference)
stage_count += 1
if mapping == 'bowtie':
# Index the reference file for bowtie2
@follows(copyRef)
@files(reference, [outTempPrefix + refName + '.1.bt2', outSuccessPrefix + refName + '.buildBowtieIndex.Success'])
def buildBowtieIndex(reference, outputs):
output, flagFile = outputs
base = output[:-6]
runStageCheck('buildBowtieIndex', flagFile, reference, base)
stage_count += 1
else:
# Index the reference file for bwa
@follows(copyRef)
@files(reference, [reference + '.bwt', outSuccessPrefix + refName + '.buildBWAIndex.Success'])
def buildBWAIndex(reference, outputs):
_output, flagFile = outputs
runStageCheck('buildBWAIndex', flagFile, reference)
stage_count += 1
else: