-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgbs.py
More file actions
executable file
·2414 lines (2175 loc) · 104 KB
/
gbs.py
File metadata and controls
executable file
·2414 lines (2175 loc) · 104 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Aim: perform the computational aspects of genotyping-by-sequencing
# Copyright (C) 2015-2018 Institut National de la Recherche Agronomique
# License: AGPL-3+
# Persons: Timothée Flutre [cre,aut]
# Versioning: https://github.com/timflutre/quantgen
# TODO:
# - refactor variantFiltering()
# - use env var for Java jar (e.g. for Picard)
# - see where to introduce BQSR
# - catch exception if step dir already exists, and skip step for the given lane(s)
# - add step to launch PLINK --mendel after using GATK VariantsToBinaryPed
# - check version of all external programs
# - check that dates in samples file agree with SAM specification
# - add option to ignore R2 files
# - add option to give VCF of known indels (for local realign)
# - try drmaa-python? https://github.com/pygridtools/drmaa-python
# - try sgeparse? https://pypi.python.org/pypi/sgeparse
# - try logging? https://docs.python.org/2/library/logging.html
# to allow code to work with Python 2 and 3
from __future__ import print_function # print is a function in python3
from __future__ import unicode_literals # avoid adding "u" to each string
from __future__ import division # avoid writing float(x) when dividing by x
import sys
import os
import getopt
import time
import datetime
import subprocess
import math
import gzip
import shlex
import warnings
import shutil
import glob
import string
import stat
import pip
import pkg_resources
# import xml.dom.minidom
# import sqlite3
if sys.version_info[0] == 2:
if sys.version_info[1] < 7:
msg = "ERROR: Python should be in version 2.7 or higher"
sys.stderr.write("%s\n" % msg)
sys.exit(1)
## check dependencies
installed_packages = pip.get_installed_distributions()
versions = {package.key: package.version for package in installed_packages}
deps = {"biopython": "1.64",
"pyutilstimflutre": "0.7"}
for depN,depV in deps.items():
msg = "ERROR: %s depends on %s in version %s or higher" % \
(os.path.basename(sys.argv[0]), depN, depV)
if depN not in versions:
sys.stderr.write("%s\n" % msg)
sys.exit(1)
if pkg_resources.parse_version(versions[depN]) \
< pkg_resources.parse_version(depV):
sys.stderr.write("%s\n" % msg)
sys.exit(1)
## http://biopython.org/
from Bio import SeqIO
from Bio.Seq import Seq, reverse_complement
from Bio.SeqRecord import SeqRecord
from Bio.Alphabet import IUPAC, generic_dna
from Bio.Data.IUPACData import ambiguous_dna_values
## https://github.com/timflutre/pyutilstimflutre
from pyutilstimflutre import Utils, ProgVersion, Job, JobGroup, JobManager, \
Fastqc, SamtoolsFlagstat
progVersion = "0.11.5" # http://semver.org/
class GbsSample(object):
"""
A GbsSample corresponds to a unique quadruplet (genotype,flowcell,lane,barcode),
given that the 'genotype' is the focus of the analysis.
Caution, in some rare cases, the same genotype can be present with multiple barcodes in the same lane: see the method below to get the sample identifier, with (before demultiplexing) or without barcode (after demultiplexing).
"""
def __init__(self, geno, flowcell, laneNum, barcode, demult="before"):
self.genotype = geno
self.flowcell = flowcell
self.lane = laneNum
self.barcode = barcode
self.id = "%s_%s_%s" % (self.genotype, self.flowcell, self.lane)
if demult == "before":
self.id += "_%s" % self.barcode
self.refGenome = ""
self.library = ""
self.seqCenter = ""
self.seqPlatform = ""
self.seqPlatformModel = ""
self.date = ""
self.initFastqFile1 = None
self.initFastqFile2 = None
self.dDemultiplexedFastqFiles = {}
self.dCleanedFastqFiles = {}
self.initialBamFile = ""
def __str__(self):
txt = "id=%s" % self.id
txt += ";genotype=%s" % self.genotype
txt += ";flowcell=%s" % self.flowcell
txt += ";lane=%s" % self.lane
txt += ";refGenome=%s" % self.refGenome
txt += ";library=%s" % self.library
txt += ";barcode=%s" % self.barcode
txt += ";seqCenter=%s" % self.seqCenter
txt += ";seqPlatform=%s" % self.seqPlatform
txt += ";seqPlatformModel=%s" % self.seqPlatformModel
txt += ";date=%s" % self.date
txt += ";initFastqFile1=%s" %self.initFastqFile1
txt += ";initFastqFile2=%s" %self.initFastqFile2
return txt
def setDemultiplexedFastqFiles(self, pathToDir):
# set R1 file:
lFilesR1 = glob.glob("%s/*_%s_R1.fastq.gz" % (pathToDir,
self.genotype))
if len(lFilesR1) == 0:
msg = "no demultiplexed R1 file found for sample '%s' in '%s'" % \
(self.id, pathToDir)
raise ValueError(msg)
if len(lFilesR1) > 1:
msg = "%i demultiplexed R1 files found for sample '%s' in '%s'" % \
(len(lFilesR1), self.id, pathToDir)
raise ValueError(msg)
self.dDemultiplexedFastqFiles["R1"] = lFilesR1[0]
# set R2 file, if necessary:
lFilesR2 = glob.glob("%s/*_%s_R2.fastq.gz" % (pathToDir,
self.genotype))
if len(lFilesR2) > 1:
msg = "%i demultiplexed R2 files found for sample '%s' in '%s'" % \
(len(lFilesR2), self.id, pathToDir)
raise ValueError(msg)
if len(lFilesR2) == 1:
self.dDemultiplexedFastqFiles["R2"] = lFilesR2[0]
def clean(self, adpR1, adpR2, errTol, minOvl, minReadLen, minQual,
maxNPerc, outDir, iJobGroup):
"""
https://cutadapt.readthedocs.org/en/stable/
"""
cmd = "# generated by gbs.py %s" % progVersion
cmd += "\ntime cutadapt"
cmd += " -a %s" % reverse_complement(str(adpR2)) # to be removed from R1 reads
if "R2" in self.dDemultiplexedFastqFiles:
cmd += " -A %s" % reverse_complement(str(adpR1) + str(self.barcode)) # idem from R2
cmd += " -o %s/%s_clean_R1.fastq.gz" % (outDir, self.id)
if "R2" in self.dDemultiplexedFastqFiles:
cmd += " -p %s/%s_clean_R2.fastq.gz" % (outDir, self.id)
cmd += " -e %f" % errTol # error tolerance
cmd += " -O %i" % minOvl # min overlap len btw reads and seq passed to -a/-A
cmd += " -m %i" % minReadLen # min read length
# cmd += " -U 3" # fixed nb of bases removed from starts of R2 reads
cmd += " -q %i,%i" % (minQual, minQual) # quality trimming
cmd += " --max-n %f" % maxNPerc
# cmd += " --maximum-length 150"
cmd += " %s" % self.dDemultiplexedFastqFiles["R1"]
if "R2" in self.dDemultiplexedFastqFiles:
cmd += " %s" % self.dDemultiplexedFastqFiles["R2"]
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def setCleanedFastqFiles(self, pathToDir):
# set R1 file
lFilesR1 = glob.glob("%s/%s_clean_R1.fastq.gz" % (pathToDir, self.id))
if len(lFilesR1) == 0:
msg = "no cleaned R1 file found for sample '%s' in '%s'" % \
(self.id, pathToDir)
raise ValueError(msg)
if len(lFilesR1) > 1:
msg = "%i cleaned R1 files found for sample '%s' in '%s'" % \
(len(lFilesR1), self.id, pathToDir)
raise ValueError(msg)
self.dCleanedFastqFiles["R1"] = lFilesR1[0]
# set R2 file, if necessary:
lFilesR2 = glob.glob("%s/%s_clean_R2.fastq.gz" % (pathToDir, self.id))
if len(lFilesR2) > 1:
msg = "%i cleaned R2 files found for sample '%s' in '%s'" % \
(len(lFilesR2), self.id, pathToDir)
raise ValueError(msg)
if len(lFilesR2) == 1:
self.dCleanedFastqFiles["R2"] = lFilesR2[0]
def cleanQc(self, outDir, iJobGroup):
"""
http://www.bioinformatics.babraham.ac.uk/projects/fastqc/
"""
for Ri in ["R1", "R2"]:
if Ri in self.dCleanedFastqFiles:
cmd = "# generated by gbs.py %s" % progVersion
cmd += "\ntime fastqc -o %s %s" % (outDir,
self.dCleanedFastqFiles[Ri])
jobName = "stdout_%s_%s_%s" % (iJobGroup.id, self.id, Ri)
bashFile = "%s/job_%s_%s_%s.bash" % (outDir, iJobGroup.id,
self.id, Ri)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def saveNbReadsFromFastqc(self, inDir, outHandle):
inFile = "%s/%s_clean_R1_fastqc.zip" % (inDir, self.id)
iFqc = Fastqc(inFile)
txt = "%s" % self.genotype
txt += "\t%s" % self.flowcell
txt += "\t%s" % self.lane
txt += "\tR1"
txt += "\t%s" % iFqc.lStats[1]["content"][3]["value"]
outHandle.write("%s\n" % txt)
if"R2" in self.dCleanedFastqFiles:
inFile = "%s/%s_clean_R2_fastqc.zip" % (inDir, self.id)
iFqc = Fastqc(inFile)
txt = "%s" % self.genotype
txt += "\t%s" % self.flowcell
txt += "\t%s" % self.lane
txt += "\tR2"
txt += "\t%s" % iFqc.lStats[1]["content"][3]["value"]
outHandle.write("%s\n" % txt)
def align(self, pathToPrefixRefGenome, tmpDir, dictFile, outDir,
iJobGroup):
"""
http://www.htslib.org/workflow/#mapping_to_variant
https://www.broadinstitute.org/gatk/guide/best-practices
Need to give bashFile to Job to keep <tab> in -R given to BWA
"""
cmd = "# generated by gbs.py %s" % progVersion
cmd += "\noutDir=\"%s\"" % outDir
cmd += "\n\necho \"align, fixmate and sort...\""
cmd += "\nbwa mem"
cmd += " -R \'@RG"
cmd += "\\tID:%s" % self.id
cmd += "\\tCN:%s" % self.seqCenter
cmd += "\\tDT:%s" % self.date
cmd += "\\tLB:%s" % self.library
cmd += "\\tPL:%s" % self.seqPlatform
cmd += "\\tPM:%s" % self.seqPlatformModel
cmd += "\\tPU:%s-%s.%s" % (self.flowcell, self.barcode, self.lane)
cmd += "\\tSM:%s" % self.genotype # see GATK's FAQ for what a sample is
cmd += "\'"
cmd += " -M %s" % pathToPrefixRefGenome
cmd += " %s" % self.dCleanedFastqFiles["R1"]
if "R2" in self.dCleanedFastqFiles:
cmd += " %s" % self.dCleanedFastqFiles["R2"]
tmpBamFile = "tmp_%s.bam" % self.id
cmd += " | samtools fixmate"
cmd += " -O bam"
cmd += " -" # stdin
cmd += " -" # stdout
cmd += " | samtools sort"
cmd += " -o ${outDir}/%s" % tmpBamFile
cmd += " -O bam"
cmd += " -T %s/tmp%s_%s" % (tmpDir, Utils.uniq_alphanum(5), self.id)
cmd += " -" # stdin
# update the header with @SQ from dictFile
tmpHeaderFile = "tmp_%s_header.sam" % self.id
cmd += "\n\necho \"update header...\""
cmd += "\ncat"
cmd += " <(samtools view -H ${outDir}/tmp_%s.bam" % self.id
cmd += " | grep -v '@SQ')"
cmd += " <(grep '@SQ' %s)" % dictFile
cmd += " > ${outDir}/%s" % tmpHeaderFile
cmd += "\ntime samtools reheader"
cmd += " ${outDir}/%s" % tmpHeaderFile
cmd += " ${outDir}/%s" % tmpBamFile
cmd += " > ${outDir}/%s.bam" % self.id
cmd += "\nrm ${outDir}/%s ${outDir}/%s" % (tmpBamFile, tmpHeaderFile)
# index
cmd += "\n\necho \"index\""
cmd += "\nsamtools index"
cmd += " ${outDir}/%s.bam" % self.id
# basic stats
cmd += "\n\necho \"flagstat\""
cmd += "\ntime samtools flagstat"
cmd += " ${outDir}/%s.bam" % self.id
cmd += " >& ${outDir}/flagstat_%s.txt" % self.id
if "R2" in self.dCleanedFastqFiles:
cmd += "\necho \"paired-end reads in proper pairs and primary alignments\""
else:
cmd += "\necho \"single reads in primary alignments\""
cmd += "\necho -e \"%s" % self.genotype
cmd += "\t%s" % self.flowcell
cmd += "\t%s" % self.lane
if "R2" in self.dCleanedFastqFiles:
cmd += "\t\"$(samtools view -f 0x0002 -F 0x0100 -q 5"
cmd += " ${outDir}/%s.bam" % self.id
cmd += " | cut -f1 | sort | uniq | wc -l)"
else:
cmd += "\t\"$(samtools view -F 0x0004 -F 0x0100 -F 0x0800 -q 5"
cmd += " ${outDir}/%s.bam" % self.id
cmd += " | cut -f1 | sort | uniq | wc -l)"
cmd += " > ${outDir}/reads_count-ok_%s.txt" % self.id
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def setInitialBamFile(self, dirName):
self.initialBamFile = "%s/%s/%s.bam" % (self.dir, dirName, self.id)
def saveSamtoolsFlagstat(self, outHandle):
inDir = os.path.dirname(self.initialBamFile)
inFile = "%s/flagstat_%s.txt" % (inDir, self.id)
iSf = SamtoolsFlagstat(inFile)
txt = "%s" % self.genotype
txt += "\t%s" % self.flowcell
txt += "\t%s" % self.lane
txt += "\t%s" % iSf.getTxtToWrite()
outHandle.write("%s\n" % txt)
def localRealign(self, jvmXms, jvmXmx, pathToPrefixRefGenome, knownIndelsFile,
outDir, iJobGroup):
cmd = "# generated by gbs.py %s" % progVersion
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T RealignerTargetCreator"
cmd += " -R %s.fa" % pathToPrefixRefGenome
cmd += " -I %s" % self.initialBamFile
if knownIndelsFile:
cmd += " --known %s" % knownIndelsFile
cmd += " -o %s/%s.intervals" % (outDir, self.id)
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T IndelRealigner"
cmd += " -R %s.fa" % pathToPrefixRefGenome
cmd += " -I %s" % self.initialBamFile
if knownIndelsFile:
cmd += " --known %s" % knownIndelsFile
cmd += " -targetIntervals %s/%s.intervals" % (outDir, self.id)
cmd += " -o %s/%s_realn.bam" % (outDir, self.id)
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def baseQualityRecalibrate(self, jvmXms, jvmXmx, pathToPrefixRefGenome,
knownFile, outDir, iJobGroup):
cmd = "# generated by gbs.py %s" % progVersion
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T BaseRecalibrator"
cmd += " -R %s.fa" % pathToPrefixRefGenome
cmd += " -I %s/%s_realn.bam" % (outDir, self.id)
if knownFile != "":
cmd += " --known %s" % knownFile
else:
cmd += " --run_without_dbsnp_potentially_ruining_quality"
cmd += " -o %s/%s_recal.table" % (outDir, self.id)
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T PrintReads"
cmd += " -R %s.fa" % pathToPrefixRefGenome
cmd += " -I %s/%s_realn.bam" % (outDir, self.id)
cmd += " --BQSR %s/%s_recal.table" % (outDir, self.id)
cmd += " -o %s/%s_recal.bam" % (outDir, self.id)
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
class GbsLane(object):
def __init__(self, laneId, flowcell, number):
self.id = laneId # flowcell identifier + "_" + lane number
self.flowcell = flowcell
self.number = number
self.dir = None
self.dSamples = {} # keys: sample id ; values: GbsSample object
self.dInitFastqFiles = {} # key(s): R1 (and R2, optional)
# values: [init, symlink]
def insert(self, iSample):
if iSample.id not in self.dSamples:
self.dSamples[iSample.id] = iSample
def nbGenos(self):
genos = set()
for sampleId,iSample in self.dSamples.items():
genos.add(iSample.genotype)
return len(genos)
def setInitFastqFiles(self):
for sampleId,iSample in self.dSamples.items():
if "R1" not in self.dInitFastqFiles:
self.dInitFastqFiles["R1"] = [iSample.initFastqFile1]
if iSample.initFastqFile2 and "R2" not in self.dInitFastqFiles:
self.dInitFastqFiles["R2"] = [iSample.initFastqFile2]
def makeInitFastqFileSymlinks(self):
if len(self.dInitFastqFiles["R1"]) == 1:
if not os.path.exists(self.dInitFastqFiles["R1"][0]):
msg = "file '%s' doesn't exist" \
% self.dInitFastqFiles["R1"][0]
raise OSError(msg)
if not self.dInitFastqFiles["R1"][0].endswith(".gz"):
msg = "fastq file '%s' should be gzipped" \
% self.dInitFastqFiles["R1"][0]
raise ValueError(msg)
self.dInitFastqFiles["R1"].append("%s/%s_R1.fastq.gz" %
(self.dir, self.id))
if not os.path.exists(self.dInitFastqFiles["R1"][1]):
os.symlink(self.dInitFastqFiles["R1"][0],
self.dInitFastqFiles["R1"][1])
if "R2" in self.dInitFastqFiles:
if len(self.dInitFastqFiles["R2"]) == 1:
if not os.path.exists(self.dInitFastqFiles["R2"][0]):
msg = "file '%s' doesn't exist" \
% self.dInitFastqFiles["R2"][0]
raise OSError(msg)
if not self.dInitFastqFiles["R2"][0].endswith(".gz"):
msg = "fastq file '%s' should be gzipped" \
% self.dInitFastqFiles["R2"][0]
raise ValueError(msg)
self.dInitFastqFiles["R2"].append("%s/%s_R2.fastq.gz" %
(self.dir, self.id))
if not os.path.exists(self.dInitFastqFiles["R2"][1]):
os.symlink(self.dInitFastqFiles["R2"][0],
self.dInitFastqFiles["R2"][1])
def initQc(self, outDir, iJobGroup):
"""
http://www.bioinformatics.babraham.ac.uk/projects/fastqc/
"""
for Ri,lFiles in self.dInitFastqFiles.items():
cmd = "echo \"commands generated by gbs.py %s\"" % progVersion
cmd += "\ntime fastqc -o %s %s" % (outDir, lFiles[1])
jobName = "stdout_%s_%s_%s" % (iJobGroup.id, self.id, Ri)
bashFile = "%s/job_%s_%s_%s.bash" % (outDir, iJobGroup.id,
self.id, Ri)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def saveBarcodeFile(self, outDir, format="table"):
fileName = "%s/barcodes_%s" % (outDir, self.id)
if format == "fasta":
fileName += ".fa"
elif format == "table":
fileName += ".tsv"
else:
msg = "format for demultiplex.py should be 'table' or 'fasta'"
raise ValueError(msg)
fileHandle = open(fileName, "w")
if format == "table":
fileHandle.write("id\ttag\n")
lSamples = self.dSamples.keys()
lSamples.sort()
for sample in lSamples:
iSample = self.dSamples[sample]
if format == "fasta":
fileHandle.write(">%s\n%s\n" % (iSample.genotype,
iSample.barcode))
else:
fileHandle.write("%s\t%s\n" % (iSample.genotype,
iSample.barcode))
fileHandle.close()
return fileName
def demultiplex(self, outDir, enzyme, method, nbSubstitutionsAllowed,
enforceSubst, iJobGroup):
cmd = "echo \"commands generated by gbs.py %s\"" % progVersion
cmd += "\ndemultiplex.py"
cmd += " --idir %s" % os.path.dirname(self.dInitFastqFiles["R1"][1])
cmd += " --ifq1 %s" % os.path.basename(self.dInitFastqFiles["R1"][1])
if "R2" in self.dInitFastqFiles:
cmd += " --ifq2 %s" % os.path.basename(self.dInitFastqFiles["R2"][1])
cmd += " --it %s" % self.saveBarcodeFile(outDir, format="table")
cmd += " --ofqp %s/%s" % (outDir, self.id)
cmd += " --met %s" % method
cmd += " --subst %i" % nbSubstitutionsAllowed
cmd += " --ensubst %s" % enforceSubst
cmd += " --dist %i" % 0
cmd += " --re %s" % enzyme
cmd += " --chim 1"
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def setDemultiplexedFastqFiles(self, pathToDir):
for sampleId,iSample in self.dSamples.items():
iSample.setDemultiplexedFastqFiles(pathToDir)
def clean(self, adpR1, adpR2, errTol, minOvl, minReadLen, minQual,
maxNPerc, outDir, iJobGroup):
for sampleId,iSample in self.dSamples.items():
iSample.clean(adpR1, adpR2, errTol, minOvl, minReadLen, minQual,
maxNPerc, outDir, iJobGroup)
def setCleanedFastqFiles(self, pathToDir):
for sampleId,iSample in self.dSamples.items():
iSample.setCleanedFastqFiles(pathToDir)
def cleanQc(self, outDir, iJobGroup):
for sampleId,iSample in self.dSamples.items():
iSample.cleanQc(outDir, iJobGroup)
def saveNbReadsFromFastqc(self, inDir, outHandle):
lSamples = self.dSamples.keys()
lSamples.sort()
for sampleId in lSamples:
iSample = self.dSamples[sampleId]
iSample.saveNbReadsFromFastqc(inDir, outHandle)
def align(self, pathToPrefixRefGenome, tmpDir, dictFile, outDirName,
iJobGroup):
for sampleId,iSample in self.dSamples.items():
outDir = "%s/%s" % (iSample.dir, outDirName)
if os.path.isdir(outDir):
shutil.rmtree(outDir)
os.mkdir(outDir)
iSample.align(pathToPrefixRefGenome, tmpDir, dictFile, outDir,
iJobGroup)
def setInitialBamFiles(self, dirName):
for sampleId,iSample in self.dSamples.items():
iSample.setInitialBamFile(dirName)
def gather(self, jvmXms, jvmXmx, tmpDir, outDir, iJobGroup):
lSamples = self.dSamples.keys()
cmd = "echo \"commands generated by gbs.py %s\"" % progVersion
cmd += "\necho \"merge, sort and index BAMs from %s (%i samples)...\"" \
% (self.id, len(lSamples))
cmd += "\ntime samtools merge -f"
cmd += " %s/%s_unsorted.bam" % (outDir, self.id)
lSamples.sort()
for sampleId in lSamples:
cmd += " %s" % self.dSamples[sampleId].initialBamFile
# https://www.biostars.org/p/251721/
cmd += "\nsamtools sort"
cmd += " -o %s/%s.bam" % (outDir, self.id)
cmd += " -T %s/tmp%s_%s" % (tmpDir, Utils.uniq_alphanum(5), self.id)
cmd += " %s/%s_unsorted.bam" % (outDir, self.id)
cmd += "\nrm -f %s/%s_unsorted.bam*" % (outDir, self.id)
cmd += "\nsamtools index"
cmd += " %s/%s.bam" % (outDir, self.id)
cmd += "\n\necho \"collect insert sizes...\""
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which picard.jar`"
cmd += " CollectInsertSizeMetrics"
cmd += " HISTOGRAM_FILE=%s/hist_insert-sizes_picard_%s.pdf" \
% (outDir, self.id)
cmd += " INPUT=%s/%s.bam" % (outDir, self.id)
cmd += " OUTPUT=%s/insert-sizes_picard_%s.txt" % (outDir, self.id)
cmd += " VALIDATION_STRINGENCY=%s" % "STRICT" #LENIENT"
cmd += "\n\necho \"clean...\""
cmd += "\nrm -f %s/%s.bam*" % (outDir, self.id) # to save space
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def saveSamtoolsFlagstat(self, outHandle):
lSamples = self.dSamples.keys()
lSamples.sort()
for sampleId in lSamples:
iSample = self.dSamples[sampleId]
iSample.saveSamtoolsFlagstat(outHandle)
def localRealignSamples(self, jvmXms, jvmXmx, pathToPrefixRefGenome,
knownIndelsFile, outDirName,
iJobGroup):
for sampleId,iSample in self.dSamples.items():
outDir = "%s/%s" % (iSample.dir, outDirName)
if os.path.isdir(outDir):
shutil.rmtree(outDir)
os.mkdir(outDir)
iSample.localRealign(jvmXms, jvmXmx, pathToPrefixRefGenome,
knownIndelsFile, outDir, iJobGroup)
def baseQualityRecalibrate(self, jvmXms, jvmXmx, pathToPrefixRefGenome,
knownFile, outDir, iJobGroup):
for sampleId,iSample in self.dSamples.items():
iSample.baseQualityRecalibrate(jvmXms, jvmXmx,
pathToPrefixRefGenome, knownFile,
outDir, iJobGroup)
class GbsGeno(object):
def __init__(self, geno):
self.id = geno
self.dir = None
self.dSamples = {}
self.lRealignedSampleBamFiles = []
self.realignedGenoBamFile = ""
def insert(self, iSample):
if iSample.id not in self.dSamples:
self.dSamples[iSample.id] = iSample
def setRealignedSampleBamFiles(self, stepDir):
lSamples = self.dSamples.keys()
lSamples.sort()
for sampleId in lSamples:
iSample = self.dSamples[sampleId]
self.lRealignedSampleBamFiles.append("%s/%s/%s_realn.bam" \
% (iSample.dir,
stepDir,
iSample.id))
def localRealign(self, jvmXms, jvmXmx, pathToPrefixRefGenome,
knownIndelsFile, outDir, iJobGroup):
cmd = "echo \"commands generated by gbs.py %s\"" % progVersion
if len(self.lRealignedSampleBamFiles) == 1:
pathWoExt = os.path.splitext(self.lRealignedSampleBamFiles[0])[0]
cmd += "\nln -s %s.bam" % pathWoExt
cmd += " %s/%s_realn.bam" % (outDir, self.id)
cmd += "\nln -s %s.bai" % pathWoExt
cmd += " %s/%s_realn.bai" % (outDir, self.id)
else:
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T RealignerTargetCreator"
cmd += " -R %s.fa" % pathToPrefixRefGenome
for i in range(len(self.lRealignedSampleBamFiles)):
cmd += " -I %s" % self.lRealignedSampleBamFiles[i]
if knownIndelsFile:
cmd += " --known %s" % knownIndelsFile
cmd += " -o %s/%s.intervals" % (outDir, self.id)
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T IndelRealigner"
cmd += " -R %s.fa" % pathToPrefixRefGenome
for i in range(len(self.lRealignedSampleBamFiles)):
cmd += " -I %s" % self.lRealignedSampleBamFiles[i]
if knownIndelsFile:
cmd += " --known %s" % knownIndelsFile
cmd += " -targetIntervals %s/%s.intervals" % (outDir, self.id)
cmd += " -o %s/%s_realn.bam" % (outDir, self.id)
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
def setRealignedGenotypeBamFile(self, pathToDir):
self.realignedGenoBamFile = "%s/%s_realn.bam" % (pathToDir, self.id)
def variantCalling(self, jvmXms, jvmXmx, tmpDir, pathToPrefixRefGenome,
knownFile, outDir, iJobGroup, saveActiveRegions=False,
saveActivityProfiles=False):
"""
https://www.broadinstitute.org/gatk/guide/tooldocs/org_broadinstitute_gatk_tools_walkers_haplotypecaller_HaplotypeCaller.php
http://gatkforums.broadinstitute.org/discussion/comment/14337/#Comment_14337
"""
cmd = "echo \"commands generated by gbs.py %s\"" % progVersion
cmd += "\njava"
cmd += " -Xms%s" % jvmXms
cmd += " -Xmx%s" % jvmXmx
if tmpDir:
cmd += " -Djava.io.tmpdir=%s" % tmpDir
cmd += " -jar `which GenomeAnalysisTK.jar`"
cmd += " -T HaplotypeCaller"
cmd += " -R %s.fa" % pathToPrefixRefGenome
cmd += " -I %s" % self.realignedGenoBamFile
# listBamsFile = "%s/bams_%s.list" % (outDir, self.id)
# listBamsHandle = open(listBamsFile, "w")
# for f in self.lPreprocessedBamFiles:
# listBamsHandle.write("%s\n" % f)
# listBamsHandle.close()
# cmd += " -I %s" % listBamsFile
cmd += " --emitRefConfidence GVCF"
cmd += " --variant_index_type LINEAR"
cmd += " --variant_index_parameter 128000"
if knownFile:
cmd += " --known %s" % knownFile
if saveActiveRegions:
cmd += " --activeRegionOut %s/%s_active-regions.tab" % (outDir, self.id)
if saveActivityProfiles:
cmd += " --activityProfileOut %s/%s_activity-profiles.tab" % (outDir, self.id)
cmd += " -o %s/%s.g.vcf.gz" % (outDir, self.id)
cmd += " --genotyping_mode DISCOVERY"
cmd += " --heterozygosity 0.001" # 1 het site in 100 bp (across all samples, for humans)
# cmd += " --output_mode " ?
cmd += " --sample_name %s" % self.id
cmd += " --annotateNDA"
cmd += " --activeRegionMaxSize 300" # to be increased?
# cmd += " --input_prior " # to be used for bi-parental crosses?
cmd += " --maxNumHaplotypesInPopulation 128" # change? no, see link above
jobName = "stdout_%s_%s" % (iJobGroup.id, self.id)
bashFile = "%s/job_%s_%s.bash" % (outDir, iJobGroup.id, self.id)
iJob = Job(groupId=iJobGroup.id, name=jobName, cmd=cmd,
bashFile=bashFile, dir=outDir)
iJobGroup.insert(iJob)
class Gbs(object):
def __init__(self):
self.verbose = 1
self.project1Id = None
self.project2Id = None
self.scheduler = "SGE"
self.queue = "normal.q"
self.lResources = None
self.rmvBash = False
self.lSteps = []
self.forceRerunSteps = False
self.samplesFile = None
self.fclnToKeep = None
self.pathToInReadsDir = ""
self.enzyme = "ApeKI"
self.dmxMethod = "4c"
self.nbSubstsAllowedDemult = 2
self.enforceSubst = "lenient"
self.jobManager = None # instantiated in run()
self.samplesCol2idx = {"genotype": None,
"flowcell": None,
"lane": None,
"ref_genome": None,
"library": None,
"barcode": None,
"seq_center": None,
"seq_platform": None,
"seq_platform_model": None,
"date": None,
"fastq_file_R1": None,
"fastq_file_R2": None}
self.dSamples = {}
self.dLanes = {}
self.dFlowcells = {}
self.dGenos = {}
self.allLanesDir = None # depends on cwd and project1Id
self.allSamplesDir = None # depends on cwd and project2Id
self.allGenosDir = None # depends on cwd and project2Id
self.lDirSteps = ["init-quality",
"demultiplex",
"clean-reads",
"align-reads",
"realign-reads-sample",
"realign-reads-geno",
"call-variants-geno",
"joint-genotyping", # to be completed by jointGenoId
"variant-geno-filter"]
self.adpFile = None
self.adapters = {}
self.errTol = 0.2
self.minOvl = 3
self.minReadLen = 35
self.minQual = 20
self.maxNPerc = 0.2
self.pathToPrefixRefGenome = None
self.dictFile = None
self.jointGenoId = None
self.restrictAllelesTo = "ALL"
self.minDp = None
self.minGq = None
self.maxNbFilterGenos = None
self.maxFracFilterGenos = None
self.maxNbNocallGenos = None
self.maxFracNocallGenos = None
self.famFile = None
self.mendelianViolationQualThreshold = 0
self.excludeSampleFile = None
self.tmpDir = "."
self.jvmXms = "512m"
self.jvmXmx = "4g"
self.queue2 = "bigmem.q"
self.knownIndelsFile = None
self.knownFile = None
def help(self):
"""
Display the help on stdout.
The format complies with help2man (http://www.gnu.org/s/help2man)
"""
msg = "`%s' performs the computational aspects of genotyping-by-sequencing.\n" % os.path.basename(sys.argv[0])
msg += "\n"
msg += "Usage: %s [OPTIONS] ...\n" % os.path.basename(sys.argv[0])
msg += "\n"
msg += "Options:\n"
msg += " -h, --help\tdisplay the help and exit\n"
msg += " -V, --version\toutput version information and exit\n"
msg += " -v, --verbose\tverbosity level (0/default=1/2/3)\n"
msg += " --proj1\tname of the project used for steps 1 to 4\n"
msg += "\t\tmention a reference genome only if all samples belong to\n"
msg += "\t\t the same species, and will be mapped to the same ref genome\n"
msg += " --proj2\tname of the project used for steps 4 to 8\n"
msg += "\t\tcan be the same as --proj1, or can be different\n"
msg +="\t\t notably when samples come from different species\n"
msg += "\t\t or if one wants to align reads to different ref genomes\n"
msg += " --schdlr\tname of the cluster scheduler (default=SGE)\n"
msg += " --queue\tname of the cluster queue (default=normal.q)\n"
msg += " --resou\tcluster resources (e.g. 'test' for 'qsub -l test')\n"
msg += " --rmvb\tremove bash scripts for jobs launched in parallel\n"
msg += " --step\tstep to perform (1/2/3/.../9)\n"
msg += "\t\t1: raw read quality per lane (with FastQC v >= 0.11.2)\n"
msg += "\t\t2: demultiplexing per lane (with demultiplex.py v >= 1.14.0)\n"
msg += "\t\t3: cleaning per sample (with CutAdapt v >= 1.8)\n"
msg += "\t\t4: alignment per sample (with BWA MEM v >= 0.7.12, Samtools v >= 1.3, Picard and R v >= 3)\n"
msg += "\t\t5: local realignment per sample (with GATK v >= 3.5)\n"
msg += "\t\t6: local realignment per genotype (with GATK v >= 3.5)\n"
msg += "\t\t7: variant and genotype calling per genotype (with GATK HaplotypeCaller v >= 3.5)\n"
msg += "\t\t8: variant and genotype calling jointly across genotypes (with GATK GenotypeGVCFs v >= 3.5)\n"
msg += "\t\t9: variant and genotype filtering (with GATK v >= 3.5)\n"
msg += " --samples\tpath to the 'samples' file\n"
msg += "\t\tcompulsory for all steps, but can differ between steps\n"
msg += "\t\t e.g. if samples come from different species or are aligned\n"
msg += "\t\t on different ref genomes, different samples file should\n"
msg += "\t\t be used for steps 4-9, representing different subsets of\n"
msg += "\t\t the file used for steps 1-3\n"
msg += "\t\tthe file should be encoded in ASCII\n"
msg += "\t\tthe first row should be a header with column names\n"
msg += "\t\teach 'sample' (see details below) should have one and only one row\n"
msg += "\t\tany two columns should be separated with one tabulation\n"
msg += "\t\tcolumns can be in any order\n"
msg += "\t\trows starting by '#' are skipped\n"
msg += "\t\t12 columns are compulsory (but there can be more):\n"
msg += "\t\t genotype (see details below, e.g. 'Col-0', but use neither underscore '_' nor space ' ' nor dot '.', use dash '-' instead)\n"
msg += "\t\t ref_genome (identifier of the reference genome used for alignment, e.g. 'Atha_v2', but use neither space ' ' nor dot '.'; the full species name, e.g. 'Arabidopsis thaliana', will be present in the file given to --dict)\n"
msg += "\t\t library (e.g. can be the same as 'genotype')\n"
msg += "\t\t barcode (e.g. 'ATGG')\n"
msg += "\t\t seq_center (e.g. 'Broad Institute', 'GenoToul', etc)\n"
msg += "\t\t seq_platform (e.g. 'ILLUMINA', see SAM format specification)\n"
msg += "\t\t seq_platform_model (e.g. 'HiSeq 2000')\n"
msg += "\t\t flowcell (e.g. 'C5YMDACXX')\n"
msg += "\t\t lane (e.g. '3', can be '31' if a first demultiplexing was done per index)\n"
msg += "\t\t date (e.g. '2015-01-15', see SAM format specification)\n"
msg += "\t\t fastq_file_R1 (filename, one per lane, gzip-compressed)\n"
msg += "\t\t fastq_file_R2 (filename, one per lane, gzip-compressed)\n"
msg += " --fcln\tidentifier of a flowcell and lane number\n"
msg += "\t\tformat as <flowcell>_<lane-number>, e.g. 'C5YMDACXX_1'\n"
msg += "\t\tif set, only the samples from this lane will be analyzed\n"
msg += " --pird\tpath to the input reads directory\n"
msg += "\t\tcompulsory for steps 1 and 2\n"
msg += "\t\twill be added to the columns 'fastq_file_R*' from the sample file\n"
msg += "\t\tif not set, input read files should be in current directory\n"
msg += " --enz\tname of the restriction enzyme\n"
msg += "\t\tcompulsory for step 2\n"
msg += "\t\tdefault=ApeKI\n"
msg += " --dmxmet\tmethod used to demultiplex\n"
msg += "\t\tcompulsory for step 2\n"
msg += "\t\tdefault=4c (see the help of demultiplex.py to know more)\n"
msg += " --subst\tnumber of substitutions allowed during demultiplexing\n"
msg += "\t\tcompulsory for step 2\n"
msg += "\t\tdefault=2\n"
msg += " --ensubst\tenforce the nb of substitutions allowed\n"
msg += "\t\tcompulsory for step 2\n"
msg += "\t\tdefault=lenient/strict\n"
msg += " --adp\tpath to the file containing the adapters\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tsame format as FastQC: name<tab>sequence\n"
msg += "\t\tname: at least 'adpR1' (also 'adpR2' if paired-end)\n"
msg += "\t\tsequence: from 5' (left) to 3' (right)\n"
msg += " --errtol\terror tolerance to find adapters\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tdefault=0.2\n"
msg += " --minovl\tminimum overlap length between reads and adapters\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tdefault=3 (in bases)\n"
msg += " --minrl\tminimum length to keep a read\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tdefault=35 (in bases)\n"
msg += " --minq\tminimum quality to trim a read\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tdefault=20 (used for both reads if paired-end)\n"
msg += " --maxNp\tmaximum percentage of N to keep a read\n"
msg += "\t\tcompulsory for step 3\n"
msg += "\t\tdefault=0.2\n"
msg += " --ref\tpath to the prefix of files for the reference genome\n"
msg += "\t\tcompulsory for steps 4, 5, 6, 7, 8, 9\n"
msg += "\t\tshould correspond to the 'ref_genome' column in --samples\n"
msg += "\t\te.g. '/data/Atha_v2' for '/data/Atha_v2.fa', '/data/Atha_v2.bwt', etc\n"
msg += "\t\tthese files are produced via 'bwa index ...'\n"
msg += " --dict\tpath to the 'dict' file (SAM header with @SQ tags)\n"
msg += "\t\tcompulsory for step 4\n"
msg += "\t\tsee 'CreateSequenceDictionary' in the Picard software\n"
msg += " --jgid\tcohort identifier to use for joint genotyping\n"
msg += "\t\tcompulsory for steps 8, 9\n"
msg += "\t\tuseful to launch several, different cohorts in parallel\n"
msg += " --rat\trestrict alleles to be of a particular allelicity\n"
msg += "\t\tused in step 9\n"
msg += "\t\tdefault=ALL/BIALLELIC/MULTIALLELIC\n"
msg += "\t\tsee '--restrictAllelesTo' in GATK's SelectVariant\n"
msg += " --mdp\tminimum value for DP (read depth; e.g. 10)\n"
msg += "\t\tused in step 9\n"
msg += "\t\tsee GATK's VariantFiltration\n"
msg += " --mgq\tminimum value for GQ (genotype quality; e.g. 20)\n"
msg += "\t\tused in step 9\n"
msg += "\t\tsee GATK's VariantFiltration\n"
msg += " --mnfg\tmaximum number of filtered genotypes to keep a variant\n"
msg += "\t\tused in step 9\n"
msg += "\t\tsee '--maxFilteredGenotypes' in GATK's SelectVariants\n"
msg += " --mffg\tmaximum fraction of filtered genotypes to keep a variant\n"
msg += "\t\tused in step 9\n"
msg += "\t\tsee '--maxFractionFilteredGenotypes' in GATK's SelectVariants\n"
msg += " --mnnc\tmaximum number of not-called genotypes to keep a variant\n"
msg += "\t\tused in step 9\n"
msg += " --mfnc\tmaximum fraction of not-called genotypes to keep a variant\n"
msg += "\t\tused in step 9\n"
msg += "\t\tsee '--maxNOCALLfraction' in GATK's SelectVariants\n"
msg += " --fam\tpath to the file containing pedigree information\n"
msg += "\t\tused in step 9\n"
msg += "\t\tdiscard variants with Mendelian violations (see Semler et al, 2012)\n"
msg += "\t\tshould be in the 'fam' format specified by PLINK\n"
msg += "\t\tvalidation strictness (GATK '-pedValidationType') is set at 'SILENT'\n"
msg += "\t\t allowing some samples to be absent from the pedigree\n"
msg += " --mvq\tminimum GQ for each trio member to accept a variant as a Mendelian violation\n"
msg += "\t\tused in step 9 if '--fam' is specified\n"
msg += "\t\tdefault=0\n"
msg += " --xlssf\tpath to the file with genotypes to exclude\n"
msg += "\t\tused in step 9 (can be especially useful if '--fam' is specified)\n"
msg += " --tmpd\tpath to a temporary directory on child nodes (default=.)\n"
msg += "\t\te.g. it can be /tmp or /scratch\n"
msg += "\t\tused in step 4 for 'samtools sort'\n"
msg += "\t\tused in step 7 for 'GATK HaplotypeCaller'\n"
msg += " --jvmXms\tinitial memory allocated to the Java Virtual Machine\n"
msg += "\t\tdefault=512m (can also be specified as 1024k, 1g, etc)\n"
msg += "\t\tused in steps 4, 5, 6, 7 and 8 for Picard and GATK\n"
msg += " --jvmXmx\tmaximum memory allocated to the Java Virtual Machine\n"
msg += "\t\tdefault=4g\n"
msg += "\t\tused in steps 4, 5, 6, 7 and 8 for Picard and GATK\n"
msg += " --queue2\tname of the second cluster queue (default=bigmem.q)\n"
msg += "\t\tused in step 4 for Picard to collect insert sizes\n"
msg += " --knowni\tpath to a VCF file with known indels (for local realignment)\n"
msg += " --known\tpath to a VCF file with known variants (e.g. from dbSNP)\n"
msg += " --force\tforce to re-run step(s)\n"
msg += "\t\tthis removes without warning the step directory if it exists\n"
msg += "\n"
msg += "Examples:\n"
msg += " %s --step 1 --samples samples.txt\n" % os.path.basename(sys.argv[0])
msg += "\n"
msg += "Details:\n"
msg += "This program aims at genotyping a set of 'genotypes' using data from\n"
msg += "a restriction-assisted DNA sequencing (RAD-seq) experiment, also known\n"
msg += "as a genotyping-by-sequencing (GBS) experiment.\n"
msg += "Here, by 'genotype', we mean the entity which is the focus of the\n"
msg += "study. For instance, it can be a plant variety (or a human being), or\n"
msg += "the specific clone of a given plant variety (or a specific tumor of a\n"
msg += "given human being), etc.\n"
msg += "Importantly, note that the content of the 'genotype' column will\n"
msg += "be used to set the 'SM' (sample) tag of the 'RG' (read group) header\n"
msg += "record type of the SAM format (see http://www.htslib.org/). However,\n"
msg += "internal to this program, the term 'sample' corresponds to the unique\n"
msg += "quadruplet (genotype,flowcell,lane,barcode) for steps 1 and 2, and to\n"
msg += "the unique triplet (genotype,flowcell,lane) for the others.\n"
msg += "Jobs are executed in parallel (--schdlr). Their return status is\n"
msg += "recorded in a SQLite database which is removed at the end. If a job\n"
msg += "fails, the whole script stops with an error.\n"
msg += "\n"
msg += "Dependencies:\n"
msg += "Python >= 2.7; Biopython; pyutilstimflutre >= 0.5\n"
msg += "\n"
msg += "Report bugs to <timothee.flutre@inra.fr>."
print(msg); sys.stdout.flush()
def version(self):
"""
Display version and license information on stdout.
The person roles comply with R's guidelines (The R Journal Vol. 4/1, June 2012).