comparison bowtie_wrapper.py @ 5:306077e393d4 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/bowtie_wrappers commit b2e1043bf4db38be490fec298a1829f8e4a1c48e
author devteam
date Thu, 18 Aug 2016 10:20:09 -0400
parents df86f29bedee
children 2c811e06006a
comparison
equal deleted inserted replaced
4:df86f29bedee 5:306077e393d4
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """ 3 """
4 Runs Bowtie on single-end or paired-end data. 4 Runs Bowtie on single-end or paired-end data.
5 For use with Bowtie v. 0.12.7
6 5
7 usage: bowtie_wrapper.py [options] 6 usage: bowtie_wrapper.py [options]
8 -t, --threads=t: The number of threads to run 7 -t, --threads=t: The number of threads to run
9 -o, --output=o: The output file 8 -o, --output=o: The output file
10 --output_unmapped_reads=: File name for unmapped reads (single-end) 9 --output_unmapped_reads=: File name for unmapped reads (single-end)
11 --output_unmapped_reads_l=: File name for unmapped reads (left, paired-end) 10 --output_unmapped_reads_l=: File name for unmapped reads (left, paired-end)
12 --output_unmapped_reads_r=: File name for unmapped reads (right, paired-end) 11 --output_unmapped_reads_r=: File name for unmapped reads (right, paired-end)
13 --output_suppressed_reads=: File name for suppressed reads because of max setting (single-end) 12 --output_suppressed_reads=: File name for suppressed reads because of max setting (single-end)
14 --output_suppressed_reads_l=: File name for suppressed reads because of max setting (left, paired-end) 13 --output_suppressed_reads_l=: File name for suppressed reads because of max setting (left, paired-end)
15 --output_suppressed_reads_r=: File name for suppressed reads because of max setting (right, paired-end) 14 --output_suppressed_reads_r=: File name for suppressed reads because of max setting (right, paired-end)
15 --output_mapping_stats=: File name for mapping statistics (output on stderr by bowtie)
16 -i, --input1=i: The (forward or single-end) reads file in Sanger FASTQ format 16 -i, --input1=i: The (forward or single-end) reads file in Sanger FASTQ format
17 -I, --input2=I: The reverse reads file in Sanger FASTQ format 17 -I, --input2=I: The reverse reads file in Sanger FASTQ format
18 -4, --dataType=4: The type of data (SOLiD or Solexa) 18 -4, --dataType=4: The type of data (SOLiD or Solexa)
19 -2, --paired=2: Whether the data is single- or paired-end 19 -2, --paired=2: Whether the data is single- or paired-end
20 -g, --genomeSource=g: The type of reference provided 20 -g, --genomeSource=g: The type of reference provided
84 parser.add_option( '', '--output_unmapped_reads_l', dest='output_unmapped_reads_l', help='File name for unmapped reads (left, paired-end)' ) 84 parser.add_option( '', '--output_unmapped_reads_l', dest='output_unmapped_reads_l', help='File name for unmapped reads (left, paired-end)' )
85 parser.add_option( '', '--output_unmapped_reads_r', dest='output_unmapped_reads_r', help='File name for unmapped reads (right, paired-end)' ) 85 parser.add_option( '', '--output_unmapped_reads_r', dest='output_unmapped_reads_r', help='File name for unmapped reads (right, paired-end)' )
86 parser.add_option( '', '--output_suppressed_reads', dest='output_suppressed_reads', help='File name for suppressed reads because of max setting (single-end)' ) 86 parser.add_option( '', '--output_suppressed_reads', dest='output_suppressed_reads', help='File name for suppressed reads because of max setting (single-end)' )
87 parser.add_option( '', '--output_suppressed_reads_l', dest='output_suppressed_reads_l', help='File name for suppressed reads because of max setting (left, paired-end)' ) 87 parser.add_option( '', '--output_suppressed_reads_l', dest='output_suppressed_reads_l', help='File name for suppressed reads because of max setting (left, paired-end)' )
88 parser.add_option( '', '--output_suppressed_reads_r', dest='output_suppressed_reads_r', help='File name for suppressed reads because of max setting (right, paired-end)' ) 88 parser.add_option( '', '--output_suppressed_reads_r', dest='output_suppressed_reads_r', help='File name for suppressed reads because of max setting (right, paired-end)' )
89 parser.add_option( '', '--output_mapping_stats', dest='output_mapping_stats', help='File for mapping statistics (i.e. stderr from bowtie)' )
89 parser.add_option( '-4', '--dataType', dest='dataType', help='The type of data (SOLiD or Solexa)' ) 90 parser.add_option( '-4', '--dataType', dest='dataType', help='The type of data (SOLiD or Solexa)' )
90 parser.add_option( '-i', '--input1', dest='input1', help='The (forward or single-end) reads file in Sanger FASTQ format' ) 91 parser.add_option( '-i', '--input1', dest='input1', help='The (forward or single-end) reads file in Sanger FASTQ format' )
91 parser.add_option( '-I', '--input2', dest='input2', help='The reverse reads file in Sanger FASTQ format' ) 92 parser.add_option( '-I', '--input2', dest='input2', help='The reverse reads file in Sanger FASTQ format' )
92 parser.add_option( '-2', '--paired', dest='paired', help='Whether the data is single- or paired-end' ) 93 parser.add_option( '-2', '--paired', dest='paired', help='Whether the data is single- or paired-end' )
93 parser.add_option( '-g', '--genomeSource', dest='genomeSource', help='The type of reference provided' ) 94 parser.add_option( '-g', '--genomeSource', dest='genomeSource', help='The type of reference provided' )
413 else: 414 else:
414 cmd2 = 'bowtie %s %s %s > %s' % ( aligning_cmds, ref_file_name, options.input1, options.output ) 415 cmd2 = 'bowtie %s %s %s > %s' % ( aligning_cmds, ref_file_name, options.input1, options.output )
415 # align 416 # align
416 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name 417 tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
417 tmp_stderr = open( tmp, 'wb' ) 418 tmp_stderr = open( tmp, 'wb' )
418 proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() ) 419 proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_index_dir, stdout=sys.stdout, stderr=tmp_stderr.fileno() )
419 returncode = proc.wait() 420 returncode = proc.wait()
420 tmp_stderr.close() 421 tmp_stderr.close()
421 # get stderr, allowing for case where it's very large 422 # get stderr, allowing for case where it's very large
422 tmp_stderr = open( tmp, 'rb' ) 423 tmp_stderr = open( tmp, 'rb' )
423 stderr = '' 424 stderr = ''
430 except OverflowError: 431 except OverflowError:
431 pass 432 pass
432 tmp_stderr.close() 433 tmp_stderr.close()
433 if returncode != 0: 434 if returncode != 0:
434 raise Exception, stderr 435 raise Exception, stderr
436 elif options.output_mapping_stats is not None:
437 # Write stderr (containing the mapping statistics) to a named file
438 with open(options.output_mapping_stats, 'w') as mapping_stats:
439 mapping_stats.write( stderr )
435 # get suppressed and unmapped reads output files in place if appropriate 440 # get suppressed and unmapped reads output files in place if appropriate
436 if options.paired == 'paired' and tmp_suppressed_file_name and \ 441 if options.paired == 'paired' and tmp_suppressed_file_name and \
437 options.output_suppressed_reads_l and options.output_suppressed_reads_r: 442 options.output_suppressed_reads_l and options.output_suppressed_reads_r:
438 try: 443 try:
439 left = tmp_suppressed_file_name.replace( '.fastq', '_1.fastq' ) 444 left = tmp_suppressed_file_name.replace( '.fastq', '_1.fastq' )