Mercurial > repos > crs4 > bwa_mem
annotate bwa_mem.py @ 1:ebb02ba5987c draft default tip
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
author | crs4 |
---|---|
date | Fri, 21 Mar 2014 12:56:15 -0400 |
parents | 6820983ba5d5 |
children |
rev | line source |
---|---|
0 | 1 # -*- coding: utf-8 -*- |
2 #!/usr/bin/env python | |
3 ## yufei.luo@gustave.roussy 22/07/2013 | |
4 ## Copyright © 2014 CRS4 Srl. http://www.crs4.it/ | |
5 ## Modified by: | |
6 ## Nicola Soranzo <nicola.soranzo@crs4.it> | |
7 | |
8 """ | |
9 Runs BWA on single-end or paired-end data. | |
10 Produces a SAM file containing the mappings. | |
11 Works with BWA version >= 0.7.5. | |
12 NOTICE: In this wrapper, we only use 'mem' for mapping step. | |
13 | |
14 usage: bwa_mem.py [options] | |
15 | |
16 See below for options | |
17 """ | |
18 | |
19 import optparse, os, shutil, subprocess, sys, tempfile | |
20 | |
21 def __main__(): | |
22 descr = "bwa_mem.py: Map (long length) reads against a reference genome with BWA-MEM." | |
23 parser = optparse.OptionParser(description=descr) | |
24 parser.add_option( '-t', '--threads', default=1, help='The number of threads to use [1]' ) | |
25 parser.add_option( '--ref', help='The reference genome to use or index' ) | |
26 parser.add_option( '-f', '--fastq', help='The (forward) fastq file to use for the mapping' ) | |
27 parser.add_option( '-F', '--rfastq', help='The reverse fastq file to use for mapping if paired-end data' ) | |
28 parser.add_option( '-u', '--output', help='The file to save the output (SAM format)' ) | |
29 parser.add_option( '-g', '--genAlignType', help='The type of pairing (single or paired)' ) | |
30 parser.add_option( '--params', help='Parameter setting to use (pre_set or full)' ) | |
31 parser.add_option( '-s', '--fileSource', help='Whether to use a previously indexed reference sequence or one form history (indexed or history)' ) | |
32 parser.add_option( '-D', '--dbkey', help='Dbkey for reference genome' ) | |
33 | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
34 parser.add_option( '-k', '--minSeedLength', type=int, help='Minimum seed length [19]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
35 parser.add_option( '-w', '--bandWidth', type=int, help='Band width for banded alignment [100]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
36 parser.add_option( '-d', '--offDiagonal', type=int, help='Off-diagonal X-dropoff [100]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
37 parser.add_option( '-r', '--internalSeeds', type=float, help='Look for internal seeds inside a seed longer than {-k} * FLOAT [1.5]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
38 parser.add_option( '-c', '--seedsOccurrence', type=int, help='Skip seeds with more than INT occurrences [10000]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
39 parser.add_option( '-S', '--mateRescue', action='store_true', help='Skip mate rescue' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
40 parser.add_option( '-P', '--skipPairing', action='store_true', help='Skip pairing' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
41 parser.add_option( '-A', '--seqMatch', type=int, help='Score for a sequence match [1]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
42 parser.add_option( '-B', '--mismatch', type=int, help='Penalty for a mismatch [4]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
43 parser.add_option( '-O', '--gapOpen', type=int, help='Gap open penalty [6]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
44 parser.add_option( '-E', '--gapExtension', type=int, help='Gap extension penalty; a gap of length k costs {-O} + {-E}*k [1]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
45 parser.add_option( '-L', '--clipping', help='Penalty for clipping [5]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
46 parser.add_option( '-U', '--unpairedReadpair', type=int, help='Penalty for an unpaired read pair [17]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
47 parser.add_option( '-p', '--interPairEnd', action='store_true', help='FASTQ file consists of interleaved paired-end sequences' ) |
0 | 48 parser.add_option( '--rgid', help='Read group identifier' ) |
49 parser.add_option( '--rgsm', help='Sample' ) | |
50 parser.add_option( '--rgpl', choices=[ 'CAPILLARY', 'LS454', 'ILLUMINA', 'SOLID', 'HELICOS', 'IONTORRENT', 'PACBIO' ], help='Platform/technology used to produce the reads' ) | |
51 parser.add_option( '--rglb', help='Library name' ) | |
52 parser.add_option( '--rgpu', help='Platform unit (e.g. flowcell-barcode.lane for Illumina or slide for SOLiD)' ) | |
53 parser.add_option( '--rgcn', help='Sequencing center that produced the read' ) | |
54 parser.add_option( '--rgds', help='Description' ) | |
55 parser.add_option( '--rgdt', help='Date that run was produced (ISO8601 format date or date/time, like YYYY-MM-DD)' ) | |
56 parser.add_option( '--rgfo', help='Flow order' ) | |
57 parser.add_option( '--rgks', help='The array of nucleotide bases that correspond to the key sequence of each read' ) | |
58 parser.add_option( '--rgpg', help='Programs used for processing the read group' ) | |
59 parser.add_option( '--rgpi', help='Predicted median insert size' ) | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
60 parser.add_option( '-T', '--minScore', type=int, help='Minimum score to output [30]' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
61 parser.add_option( '-a', '--outputAll', action='store_true', help='Output all found alignments for single-end or unpaired paired-end reads' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
62 parser.add_option( '-M', '--mark', action='store_true', help='Mark shorter split hits as secondary (for Picard/GATK compatibility)' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
63 parser.add_option( '-H', '--suppressHeader', dest='suppressHeader', action='store_true', help='Suppress header' ) |
0 | 64 (options, args) = parser.parse_args() |
65 if len(args) > 0: | |
66 parser.error('Wrong number of arguments') | |
67 | |
68 # output version # of tool | |
69 try: | |
70 tmp = tempfile.NamedTemporaryFile().name | |
71 tmp_stdout = open( tmp, 'wb' ) | |
72 proc = subprocess.Popen( args='bwa 2>&1', shell=True, stdout=tmp_stdout ) | |
73 tmp_stdout.close() | |
74 returncode = proc.wait() | |
75 stdout = None | |
76 for line in open( tmp_stdout.name, 'rb' ): | |
77 if line.lower().find( 'version' ) >= 0: | |
78 stdout = line.strip() | |
79 break | |
80 if stdout: | |
81 sys.stdout.write( 'BWA %s\n' % stdout ) | |
82 else: | |
83 raise Exception | |
84 except: | |
85 sys.stdout.write( 'Could not determine BWA version\n' ) | |
86 | |
87 fastq = options.fastq | |
88 if options.rfastq: | |
89 rfastq = options.rfastq | |
90 | |
91 # make temp directory for placement of indices | |
92 tmp_index_dir = tempfile.mkdtemp() | |
93 tmp_dir = tempfile.mkdtemp() | |
94 # index if necessary | |
95 if options.fileSource == 'history': | |
96 ref_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir ) | |
97 ref_file_name = ref_file.name | |
98 ref_file.close() | |
99 os.symlink( options.ref, ref_file_name ) | |
100 # determine which indexing algorithm to use, based on size | |
101 try: | |
102 size = os.stat( options.ref ).st_size | |
103 if size <= 2**30: | |
104 indexingAlg = 'is' | |
105 else: | |
106 indexingAlg = 'bwtsw' | |
107 except: | |
108 indexingAlg = 'is' | |
109 indexing_cmds = '-a %s' % indexingAlg | |
110 cmd1 = 'bwa index %s %s' % ( indexing_cmds, ref_file_name ) | |
111 try: | |
112 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name | |
113 tmp_stderr = open( tmp, 'wb' ) | |
114 proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() ) | |
115 returncode = proc.wait() | |
116 tmp_stderr.close() | |
117 # get stderr, allowing for case where it's very large | |
118 tmp_stderr = open( tmp, 'rb' ) | |
119 stderr = '' | |
120 buffsize = 1048576 | |
121 try: | |
122 while True: | |
123 stderr += tmp_stderr.read( buffsize ) | |
124 if not stderr or len( stderr ) % buffsize != 0: | |
125 break | |
126 except OverflowError: | |
127 pass | |
128 tmp_stderr.close() | |
129 if returncode != 0: | |
130 raise Exception, stderr | |
131 except Exception, e: | |
132 # clean up temp dirs | |
133 if os.path.exists( tmp_index_dir ): | |
134 shutil.rmtree( tmp_index_dir ) | |
135 if os.path.exists( tmp_dir ): | |
136 shutil.rmtree( tmp_dir ) | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
137 raise Exception, 'Error indexing reference sequence. ' + str( e ) |
0 | 138 else: |
139 ref_file_name = options.ref | |
140 # if options.illumina13qual: | |
141 # illumina_quals = "-I" | |
142 # else: | |
143 # illumina_quals = "" | |
144 | |
145 # set up aligning and generate aligning command args | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
146 start_cmds = "bwa mem -t %s" % options.threads |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
147 if options.interPairEnd: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
148 start_cmds += ' -p' |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
149 if options.params != 'pre_set': |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
150 if options.minSeedLength is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
151 start_cmds += " -k %d" % options.minSeedLength |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
152 if options.bandWidth is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
153 start_cmds += " -w %d" % options.bandWidth |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
154 if options.offDiagonal is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
155 start_cmds += " -d %d" % options.offDiagonal |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
156 if options.internalSeeds is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
157 start_cmds += " -r %s" % options.internalSeeds |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
158 if options.seedsOccurrence is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
159 start_cmds += " -c %d" % options.seedsOccurrence |
0 | 160 if options.mateRescue: |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
161 start_cmds += ' -S' |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
162 if options.skipPairing: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
163 start_cmds += ' -P' |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
164 if options.seqMatch is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
165 start_cmds += " -A %d" % options.seqMatch |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
166 if options.mismatch is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
167 start_cmds += " -B %d" % options.mismatch |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
168 if options.gapOpen is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
169 start_cmds += " -O %d" % options.gapOpen |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
170 if options.gapExtension is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
171 start_cmds += " -E %d" % options.gapExtension |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
172 if options.clipping: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
173 start_cmds += " -L %s" % options.clipping |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
174 if options.unpairedReadpair is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
175 start_cmds += " -U %d" % options.unpairedReadpair |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
176 if options.minScore is not None: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
177 start_cmds += " -T %d" % options.minScore |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
178 if options.outputAll: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
179 start_cmds += ' -a' |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
180 if options.mark: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
181 start_cmds += ' -M' |
0 | 182 if options.rgid: |
183 if not options.rglb or not options.rgpl or not options.rgsm or not options.rglb: | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
184 sys.exit( 'If you want to specify read groups, you must include the ID, LB, PL, and SM tags.' ) |
0 | 185 readGroup = '@RG\tID:%s\tLB:%s\tPL:%s\tSM:%s' % ( options.rgid, options.rglb, options.rgpl, options.rgsm ) |
186 if options.rgpu: | |
187 readGroup += '\tPU:%s' % options.rgpu | |
188 if options.rgcn: | |
189 readGroup += '\tCN:%s' % options.rgcn | |
190 if options.rgds: | |
191 readGroup += '\tDS:%s' % options.rgds | |
192 if options.rgdt: | |
193 readGroup += '\tDT:%s' % options.rgdt | |
194 if options.rgfo: | |
195 readGroup += '\tFO:%s' % options.rgfo | |
196 if options.rgks: | |
197 readGroup += '\tKS:%s' % options.rgks | |
198 if options.rgpg: | |
199 readGroup += '\tPG:%s' % options.rgpg | |
200 if options.rgpi: | |
201 readGroup += '\tPI:%s' % options.rgpi | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
202 start_cmds += " -R '%s'" % readGroup |
0 | 203 |
204 if options.genAlignType == 'paired': | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
205 cmd = "%s %s %s %s > %s" % ( start_cmds, ref_file_name, fastq, rfastq, options.output ) |
0 | 206 else: |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
207 cmd = "%s %s %s > %s" % ( start_cmds, ref_file_name, fastq, options.output ) |
0 | 208 |
209 # perform alignments | |
210 buffsize = 1048576 | |
211 try: | |
212 # need to nest try-except in try-finally to handle 2.4 | |
213 try: | |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
214 tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
215 tmp_stderr = open( tmp, 'wb' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
216 print "The cmd is %s" % cmd |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
217 proc = subprocess.Popen( args=cmd, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
218 returncode = proc.wait() |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
219 tmp_stderr.close() |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
220 # get stderr, allowing for case where it's very large |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
221 tmp_stderr = open( tmp, 'rb' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
222 stderr = '' |
0 | 223 try: |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
224 while True: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
225 stderr += tmp_stderr.read( buffsize ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
226 if not stderr or len( stderr ) % buffsize != 0: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
227 break |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
228 except OverflowError: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
229 pass |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
230 tmp_stderr.close() |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
231 if returncode != 0: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
232 raise Exception, stderr |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
233 except Exception, e: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
234 raise Exception, 'Error generating alignments. ' + str( e ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
235 # remove header if necessary |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
236 if options.suppressHeader: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
237 tmp_out = tempfile.NamedTemporaryFile( dir=tmp_dir) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
238 tmp_out_name = tmp_out.name |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
239 tmp_out.close() |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
240 try: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
241 shutil.move( options.output, tmp_out_name ) |
0 | 242 except Exception, e: |
1
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
243 raise Exception, 'Error moving output file before removing headers. ' + str( e ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
244 fout = file( options.output, 'w' ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
245 for line in file( tmp_out.name, 'r' ): |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
246 if not ( line.startswith( '@HD' ) or line.startswith( '@SQ' ) or line.startswith( '@RG' ) or line.startswith( '@PG' ) or line.startswith( '@CO' ) ): |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
247 fout.write( line ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
248 fout.close() |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
249 # check that there are results in the output file |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
250 if os.path.getsize( options.output ) > 0: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
251 sys.stdout.write( 'BWA run on %s-end data' % options.genAlignType ) |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
252 else: |
ebb02ba5987c
Rewrite of param handling. interPairEnd param moved to "paired" section. Add param for '-a' option. Remove basic parallelism tag, which does not work with multiple inputs (thanks Bjoern Gruening for the notice). Simplify Python code.
crs4
parents:
0
diff
changeset
|
253 raise Exception, 'The output file is empty. You may simply have no matches, or there may be an error with your input file or settings.' |
0 | 254 finally: |
255 # clean up temp dir | |
256 if os.path.exists( tmp_index_dir ): | |
257 shutil.rmtree( tmp_index_dir ) | |
258 if os.path.exists( tmp_dir ): | |
259 shutil.rmtree( tmp_dir ) | |
260 | |
261 if __name__ == "__main__": | |
262 __main__() |