commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/0df1612c1cb1/ changeset: 0df1612c1cb1 user: asbardellati date: 2013-01-18 17:11:04 summary: Add option for writing not aligned reads to file Reviewed-by: Nicola Soranzo <soranzo@crs4.it> affected #: 2 files diff -r b9d44cf4b68e2c4a76bc2b7f7eb54950e2c077be -r 0df1612c1cb14b48f5bee405a04886de5380df39 tools/sr_mapping/bowtie2_wrapper.py --- a/tools/sr_mapping/bowtie2_wrapper.py +++ b/tools/sr_mapping/bowtie2_wrapper.py @@ -31,10 +31,29 @@ parser.add_option( '', '--rgpl', dest='rgpl', help='Platform/technology used to produce the reads' ) parser.add_option( '', '--rgsm', dest='rgsm', help='Sample' ) + parser.add_option( '', '--output_unaligned_reads', dest='output_unaligned_reads', help='File name for unaligned reads (single-end)' ) + parser.add_option( '', '--output_unaligned_reads_l', dest='output_unaligned_reads_l', help='File name for unaligned reads (left, paired-end)' ) + parser.add_option( '', '--output_unaligned_reads_r', dest='output_unaligned_reads_r', help='File name for unaligned reads (right, paired-end)' ) + (options, args) = parser.parse_args() + tmp_unaligned_file_name = None # Creat bowtie index if necessary. tmp_index_dir = tempfile.mkdtemp() + + if options.single_paired == 'paired': + if options.output_unaligned_reads_l and options.output_unaligned_reads_r: + tmp_unaligned_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir, suffix='.fastq' ) + tmp_unaligned_file_name = tmp_unaligned_file.name + tmp_unaligned_file.close() + output_unaligned_reads = '--un-conc %s' % tmp_unaligned_file_name + else: + output_unaligned_reads = '' + elif options.output_unaligned_reads: + output_unaligned_reads = '--un %s' % options.output_unaligned_reads + else: + output_unaligned_reads = '' + if options.own_file: index_path = os.path.join( tmp_index_dir, '.'.join( os.path.split( options.own_file )[1].split( '.' )[:-1] ) ) try: @@ -71,7 +90,7 @@ index_path = options.index_path # Build bowtie command; use view and sort to create sorted bam. - cmd = 'bowtie2 %s -x %s %s | samtools view -Su - | samtools sort -o - - > %s' + cmd = 'bowtie2 %s -x %s %s %s | samtools view -Su - | samtools sort -o - - > %s' # Set up reads. if options.single_paired == 'paired': @@ -104,7 +123,7 @@ opts += ' --rg %s:%s' % ( 'SM', options.rgsm ) # Final command: - cmd = cmd % ( opts, index_path, reads, options.output ) + cmd = cmd % ( opts, index_path, reads, output_unaligned_reads, options.output ) print cmd # Run @@ -136,6 +155,16 @@ except Exception, e: stop_err( 'Error in bowtie2:\n' + str( e ) ) + # get unaligned reads output files in place if appropriate + if options.single_paired == 'paired' and tmp_unaligned_file_name and options.output_unaligned_reads_l and options.output_unaligned_reads_r: + try: + left = tmp_unaligned_file_name.replace( '.fastq', '.1.fastq' ) + right = tmp_unaligned_file_name.replace( '.fastq', '.2.fastq' ) + shutil.move( left, options.output_unaligned_reads_l ) + shutil.move( right, options.output_unaligned_reads_r ) + except Exception, e: + sys.stdout.write( 'Error producing the unaligned output files.\n' ) + # Clean up temp dirs if os.path.exists( tmp_index_dir ): shutil.rmtree( tmp_index_dir ) diff -r b9d44cf4b68e2c4a76bc2b7f7eb54950e2c077be -r 0df1612c1cb14b48f5bee405a04886de5380df39 tools/sr_mapping/bowtie2_wrapper.xml --- a/tools/sr_mapping/bowtie2_wrapper.xml +++ b/tools/sr_mapping/bowtie2_wrapper.xml @@ -1,6 +1,6 @@ <tool id="bowtie2" name="Bowtie2" version="0.1"><!-- Wrapper compatible with Bowtie version 2.0.0 --> - <description>is a short-read mapper</description> + <description>is a short-read aligner</description><version_command>bowtie2 --version</version_command><requirements><requirement type="package">bowtie2</requirement> @@ -15,6 +15,17 @@ ## Outputs. --output=$output + #if str( $singlePaired.sPaired ) == "single" + #if $output_unaligned_reads_l + --output_unaligned_reads=$output_unaligned_reads_l + #end if + #else + #if $output_unaligned_reads_l and $output_unaligned_reads_r + --output_unaligned_reads_l=$output_unaligned_reads_l + --output_unaligned_reads_r=$output_unaligned_reads_r + #end if + #end if + ## Handle reference file. #if $refGenomeSource.genomeSource == "history": --own-file=$refGenomeSource.ownFile @@ -71,6 +82,7 @@ <param name="maxInsert" type="integer" value="250" label="Maximum insert size for valid paired-end alignments" /></when></conditional> + <param name="unalignedFile" type="boolean" truevalue="true" falsevalue="false" checked="False" label="Write all reads that could not be aligned to a file (uses --un for single-end and --un-conc for paired-ends)" /><conditional name="refGenomeSource"><param name="genomeSource" type="select" label="Will you select a reference genome from your history or use a built-in index?" help="Built-ins were indexed using default options"><option value="indexed">Use a built-in index</option> @@ -133,7 +145,7 @@ </inputs><outputs> - <data format="bam" name="output" label="${tool.name} on ${on_string}: mapped reads"> + <data format="bam" name="output" label="${tool.name} on ${on_string}: aligned reads"><actions><conditional name="refGenomeSource.genomeSource"><when value="indexed"> @@ -152,6 +164,22 @@ </conditional></actions></data> + <data format="fastqsanger" name="output_unaligned_reads_l" label="${tool.name} on ${on_string}: unaligned reads (L)" > + <filter>unalignedFile is True</filter> + <actions> + <action type="format"> + <option type="from_param" name="singlePaired.input1" param_attribute="ext" /> + </action> + </actions> + </data> + <data format="fastqsanger" name="output_unaligned_reads_r" label="${tool.name} on ${on_string}: unaligned reads (R)"> + <filter>singlePaired['sPaired'] == "paired" and unalignedFile is True</filter> + <actions> + <action type="format"> + <option type="from_param" name="singlePaired.input1" param_attribute="ext" /> + </action> + </actions> + </data></outputs><tests> https://bitbucket.org/galaxy/galaxy-central/commits/7d37ffe813f2/ changeset: 7d37ffe813f2 user: jgoecks date: 2013-01-19 22:35:28 summary: Merged in nsoranzo/galaxy-central (pull request #110) Add option to bowtie2 tool for writing not aligned reads to file affected #: 2 files diff -r 50c65739cd1af36f48672a980db378783dffcdd5 -r 7d37ffe813f2a037b560af26770ffe5924ae643f tools/sr_mapping/bowtie2_wrapper.py --- a/tools/sr_mapping/bowtie2_wrapper.py +++ b/tools/sr_mapping/bowtie2_wrapper.py @@ -31,10 +31,29 @@ parser.add_option( '', '--rgpl', dest='rgpl', help='Platform/technology used to produce the reads' ) parser.add_option( '', '--rgsm', dest='rgsm', help='Sample' ) + parser.add_option( '', '--output_unaligned_reads', dest='output_unaligned_reads', help='File name for unaligned reads (single-end)' ) + parser.add_option( '', '--output_unaligned_reads_l', dest='output_unaligned_reads_l', help='File name for unaligned reads (left, paired-end)' ) + parser.add_option( '', '--output_unaligned_reads_r', dest='output_unaligned_reads_r', help='File name for unaligned reads (right, paired-end)' ) + (options, args) = parser.parse_args() + tmp_unaligned_file_name = None # Creat bowtie index if necessary. tmp_index_dir = tempfile.mkdtemp() + + if options.single_paired == 'paired': + if options.output_unaligned_reads_l and options.output_unaligned_reads_r: + tmp_unaligned_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir, suffix='.fastq' ) + tmp_unaligned_file_name = tmp_unaligned_file.name + tmp_unaligned_file.close() + output_unaligned_reads = '--un-conc %s' % tmp_unaligned_file_name + else: + output_unaligned_reads = '' + elif options.output_unaligned_reads: + output_unaligned_reads = '--un %s' % options.output_unaligned_reads + else: + output_unaligned_reads = '' + if options.own_file: index_path = os.path.join( tmp_index_dir, '.'.join( os.path.split( options.own_file )[1].split( '.' )[:-1] ) ) try: @@ -71,7 +90,7 @@ index_path = options.index_path # Build bowtie command; use view and sort to create sorted bam. - cmd = 'bowtie2 %s -x %s %s | samtools view -Su - | samtools sort -o - - > %s' + cmd = 'bowtie2 %s -x %s %s %s | samtools view -Su - | samtools sort -o - - > %s' # Set up reads. if options.single_paired == 'paired': @@ -104,7 +123,7 @@ opts += ' --rg %s:%s' % ( 'SM', options.rgsm ) # Final command: - cmd = cmd % ( opts, index_path, reads, options.output ) + cmd = cmd % ( opts, index_path, reads, output_unaligned_reads, options.output ) print cmd # Run @@ -136,6 +155,16 @@ except Exception, e: stop_err( 'Error in bowtie2:\n' + str( e ) ) + # get unaligned reads output files in place if appropriate + if options.single_paired == 'paired' and tmp_unaligned_file_name and options.output_unaligned_reads_l and options.output_unaligned_reads_r: + try: + left = tmp_unaligned_file_name.replace( '.fastq', '.1.fastq' ) + right = tmp_unaligned_file_name.replace( '.fastq', '.2.fastq' ) + shutil.move( left, options.output_unaligned_reads_l ) + shutil.move( right, options.output_unaligned_reads_r ) + except Exception, e: + sys.stdout.write( 'Error producing the unaligned output files.\n' ) + # Clean up temp dirs if os.path.exists( tmp_index_dir ): shutil.rmtree( tmp_index_dir ) diff -r 50c65739cd1af36f48672a980db378783dffcdd5 -r 7d37ffe813f2a037b560af26770ffe5924ae643f tools/sr_mapping/bowtie2_wrapper.xml --- a/tools/sr_mapping/bowtie2_wrapper.xml +++ b/tools/sr_mapping/bowtie2_wrapper.xml @@ -1,6 +1,6 @@ <tool id="bowtie2" name="Bowtie2" version="0.1"><!-- Wrapper compatible with Bowtie version 2.0.0 --> - <description>is a short-read mapper</description> + <description>is a short-read aligner</description><version_command>bowtie2 --version</version_command><requirements><requirement type="package">bowtie2</requirement> @@ -15,6 +15,17 @@ ## Outputs. --output=$output + #if str( $singlePaired.sPaired ) == "single" + #if $output_unaligned_reads_l + --output_unaligned_reads=$output_unaligned_reads_l + #end if + #else + #if $output_unaligned_reads_l and $output_unaligned_reads_r + --output_unaligned_reads_l=$output_unaligned_reads_l + --output_unaligned_reads_r=$output_unaligned_reads_r + #end if + #end if + ## Handle reference file. #if $refGenomeSource.genomeSource == "history": --own-file=$refGenomeSource.ownFile @@ -71,6 +82,7 @@ <param name="maxInsert" type="integer" value="250" label="Maximum insert size for valid paired-end alignments" /></when></conditional> + <param name="unalignedFile" type="boolean" truevalue="true" falsevalue="false" checked="False" label="Write all reads that could not be aligned to a file (uses --un for single-end and --un-conc for paired-ends)" /><conditional name="refGenomeSource"><param name="genomeSource" type="select" label="Will you select a reference genome from your history or use a built-in index?" help="Built-ins were indexed using default options"><option value="indexed">Use a built-in index</option> @@ -133,7 +145,7 @@ </inputs><outputs> - <data format="bam" name="output" label="${tool.name} on ${on_string}: mapped reads"> + <data format="bam" name="output" label="${tool.name} on ${on_string}: aligned reads"><actions><conditional name="refGenomeSource.genomeSource"><when value="indexed"> @@ -152,6 +164,22 @@ </conditional></actions></data> + <data format="fastqsanger" name="output_unaligned_reads_l" label="${tool.name} on ${on_string}: unaligned reads (L)" > + <filter>unalignedFile is True</filter> + <actions> + <action type="format"> + <option type="from_param" name="singlePaired.input1" param_attribute="ext" /> + </action> + </actions> + </data> + <data format="fastqsanger" name="output_unaligned_reads_r" label="${tool.name} on ${on_string}: unaligned reads (R)"> + <filter>singlePaired['sPaired'] == "paired" and unalignedFile is True</filter> + <actions> + <action type="format"> + <option type="from_param" name="singlePaired.input1" param_attribute="ext" /> + </action> + </actions> + </data></outputs><tests> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket