# HG changeset patch
# User devteam
# Date 1390498263 18000
# Node ID de14b969d7135810a00bfb1da856894b2b856d9c
Imported from capsule None
diff -r 000000000000 -r de14b969d713 fastq_manipulation.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fastq_manipulation.py Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,37 @@
+#Dan Blankenberg
+import sys, os, shutil
+import imp
+from galaxy_utils.sequence.fastq import fastqReader, fastqWriter
+
+def main():
+ #Read command line arguments
+ input_filename = sys.argv[1]
+ script_filename = sys.argv[2]
+ output_filename = sys.argv[3]
+ additional_files_path = sys.argv[4]
+ input_type = sys.argv[5] or 'sanger'
+
+ #Save script file for debuging/verification info later
+ os.mkdir( additional_files_path )
+ shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) )
+
+ fastq_manipulator = imp.load_module( 'fastq_manipulator', open( script_filename ), script_filename, ( '', 'r', imp.PY_SOURCE ) )
+
+ out = fastqWriter( open( output_filename, 'wb' ), format = input_type )
+
+ i = None
+ reads_manipulated = 0
+ for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ):
+ new_read = fastq_manipulator.match_and_manipulate_read( fastq_read )
+ if new_read:
+ out.write( new_read )
+ if new_read != fastq_read:
+ reads_manipulated += 1
+ out.close()
+ if i is None:
+ print "Your file contains no valid FASTQ reads."
+ else:
+ print 'Manipulated %s of %s reads (%.2f%%).' % ( reads_manipulated, i + 1, float( reads_manipulated ) / float( i + 1 ) * 100.0 )
+
+if __name__ == "__main__":
+ main()
diff -r 000000000000 -r de14b969d713 fastq_manipulation.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fastq_manipulation.xml Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,432 @@
+
+
+
+ galaxy_sequence_utils
+
+ reads on various attributes
+ fastq_manipulation.py $input_file $fastq_manipulation_file $output_file $output_file.files_path '${input_file.extension[len( 'fastq' ):]}'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int( float( value ) ) == float( value )
+
+
+
+ int( float( value ) ) == float( value )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ##create an importable module
+#import binascii
+import re
+import binascii
+from string import maketrans
+##does read match
+def match_read( fastq_read ):
+ #for $match_block in $match_blocks:
+ #if $match_block['match_type']['match_type_selector'] == 'identifier':
+ search_target = fastq_read.identifier[1:] ##don't include @
+ #elif $match_block['match_type']['match_type_selector'] == 'sequence':
+ search_target = fastq_read.sequence
+ #elif $match_block['match_type']['match_type_selector'] == 'quality':
+ search_target = fastq_read.quality
+ #else:
+ #continue
+ #end if
+ if not re.search( binascii.unhexlify( "${ binascii.hexlify( str( match_block['match_type']['match']['match_by'] ) ) }" ), search_target ):
+ return False
+ #end for
+ return True
+##modify matched reads
+def manipulate_read( fastq_read ):
+ new_read = fastq_read.clone()
+ #for $manipulate_block in $manipulate_blocks:
+ #if $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'identifier':
+ #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
+ new_read.identifier = "@%s" % new_read.identifier[1:].translate( maketrans( binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['from'] ) ) }" ), binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['to'] ) ) }" ) ) )
+ #end if
+ #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'sequence':
+ #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
+ new_read.sequence = new_read.sequence.translate( maketrans( binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['from'] ) ) }" ), binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['to'] ) ) }" ) ) )
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rev_comp':
+ new_read = new_read.reverse_complement()
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rev_no_comp':
+ new_read = new_read.reverse()
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'no_rev_comp':
+ new_read = new_read.complement()
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'trim':
+ #if $manipulate_block['manipulation_type']['manipulation']['offset_type']['base_offset_type'] == 'offsets_percent':
+ left_column_offset = int( round( float( ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['left_column_offset'] } ) / 100.0 * float( len( new_read ) ) ) )
+ right_column_offset = int( round( float( ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['right_column_offset'] } ) / 100.0 * float( len( new_read ) ) ) )
+ #else
+ left_column_offset = ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['left_column_offset'] }
+ right_column_offset = ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['right_column_offset'] }
+ #end if
+ if right_column_offset > 0:
+ right_column_offset = -right_column_offset
+ else:
+ right_column_offset = None
+ new_read = new_read.slice( left_column_offset, right_column_offset )
+ if not ( ${str( manipulate_block['manipulation_type']['manipulation']['keep_zero_length'] ) == 'keep_zero_length'} or len( new_read ) ):
+ return None
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'dna_to_rna':
+ new_read = new_read.sequence_as_DNA()
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rna_to_dna':
+ new_read = new_read.sequence_as_RNA()
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'change_adapter':
+ if new_read.sequence_space == 'color':
+ new_read = new_read.change_adapter( binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['new_adapter'] ) ) }" ) )
+ #end if
+ #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'quality':
+ #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
+ new_read.quality = new_read.quality.translate( maketrans( binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['from'] ) ) }" ), binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['to'] ) ) }" ) ) )
+ #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'map_score':
+ def score_method( score ):
+ raise Exception, "Unimplemented" ##This option is not yet available, need to abstract out e.g. column adding tool action: preventing users from using 'harmful' actions
+ new_read.quality_map( score_method )
+ #end if
+ #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'miscellaneous':
+ #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'remove':
+ return None
+ #end if
+ #else:
+ #continue
+ #end if
+ #end for
+ if new_read.description != "+":
+ new_read.description = "+%s" % new_read.identifier[1:] ##ensure description is still valid
+ return new_read
+def match_and_manipulate_read( fastq_read ):
+ new_read = fastq_read
+ if match_read( fastq_read ):
+ new_read = manipulate_read( fastq_read )
+ return new_read
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+This tool allows you to build complex manipulations to be applied to each matching read in a FASTQ file. A read must match all matching directives in order for it to be manipulated; if a read does not match, it is output in a non-modified manner. All reads matching will have each of the specified manipulations performed upon them, in the order specified.
+
+Regular Expression Matches are made using re.search, see http://docs.python.org/library/re.html for more information.
+ All matching is performed on a single line string, regardless if e.g. the sequence or quality score spans multiple lines in the original file.
+
+String translations are performed using string.translate, see http://docs.python.org/library/string.html#string.translate and http://docs.python.org/library/string.html#string.maketrans for more information.
+
+.. class:: warningmark
+
+Only color space reads can have adapter bases substituted.
+
+
+-----
+
+**Example**
+
+Suppose you have a color space sanger formatted sequence (fastqcssanger) and you want to double-encode the color space into psuedo-nucleotide space (this is different from converting) to allow these reads to be used in tools which do not natively support it (using specially designed indexes). This tool can handle this manipulation, however, this is generally not recommended as results tend to be poorer than those produced from tools which are specially designed to handle color space data.
+
+Steps:
+
+1. Click **Add new Match Reads** and leave the matching options set to the default (Matching by sequence name/identifier using the regular expression "\*."; thereby matching all reads).
+2. Click **Add new Manipulate Reads**, change **Manipulate Reads on** to "Sequence Content", set **Sequence Manipulation Type** to "Change Adapter Base" and set **New Adapter** to "" (an empty text field).
+3. Click **Add new Manipulate Reads**, change **Manipulate Reads on** to "Sequence Content", set **Sequence Manipulation Type** to "String Translate" and set **From** to "0123." and **To** to "ACGTN".
+4. Click Execute. The new history item will contained double-encoded psuedo-nucleotide space reads.
+
+------
+
+**Citation**
+
+If you use this tool, please cite `Blankenberg D, Gordon A, Von Kuster G, Coraor N, Taylor J, Nekrutenko A; Galaxy Team. Manipulation of FASTQ data with Galaxy. Bioinformatics. 2010 Jul 15;26(14):1783-5. <http://www.ncbi.nlm.nih.gov/pubmed/20562416>`_
+
+
+
+
diff -r 000000000000 -r de14b969d713 test-data/empty_file.dat
diff -r 000000000000 -r de14b969d713 test-data/fastq_trimmer_out1.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/fastq_trimmer_out1.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,8 @@
+@FAKE0001 Original version has PHRED scores from 0 to 93 inclusive (in that order)
+CGTA
++
+NOPQ
+@FAKE0002 Original version has PHRED scores from 93 to 0 inclusive (in that order)
+ATGC
++
+QPON
diff -r 000000000000 -r de14b969d713 test-data/misc_dna_as_sanger_rev_comp_1.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/misc_dna_as_sanger_rev_comp_1.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,16 @@
+@FAKE0007 Original version has lower case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+TACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0008 Original version has mixed case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+cgCTatgAcgCTatgAcgCTatgAcgCTatgAcgCTatgAc
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0009 Original version has lower case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+actgactgactgactgactgactgactgactgactgactga
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0010 Original version has mixed case ambiguous DNA and PHRED scores of 40, 30, 20, 10 (cycled)
+NHBVDMKSWRYGATCnhbvdmkswrygatc
++
+?I+5?I+5?I+5?I+5?I+5?I+5?I+5?I
diff -r 000000000000 -r de14b969d713 test-data/misc_dna_original_sanger.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/misc_dna_original_sanger.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,16 @@
+@FAKE0007 Original version has lower case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTA
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0008 Original version has mixed case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+gTcatAGcgTcatAGcgTcatAGcgTcatAGcgTcatAGcg
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0009 Original version has lower case unambiguous DNA with PHRED scores from 0 to 40 inclusive (in that order)
+tcagtcagtcagtcagtcagtcagtcagtcagtcagtcagt
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0010 Original version has mixed case ambiguous DNA and PHRED scores of 40, 30, 20, 10 (cycled)
+gatcrywsmkhbvdnGATCRYWSMKHBVDN
++
+I?5+I?5+I?5+I?5+I?5+I?5+I?5+I?
diff -r 000000000000 -r de14b969d713 test-data/misc_rna_as_sanger_rev_comp_1.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/misc_rna_as_sanger_rev_comp_1.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,16 @@
+@FAKE0011 Original version has lower case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+UACGUACGUACGUACGUACGUACGUACGUACGUACGUACGU
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0012 Original version has mixed case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+cgCUaugAcgCUaugAcgCUaugAcgCUaugAcgCUaugAc
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0013 Original version has lower case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+acugacugacugacugacugacugacugacugacugacuga
++
+IHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0014 Original version has mixed case ambiguous RNA with PHRED scores from 35 to 40 inclusive (cycled)
+NHBVDMKSWRYGAUCnhbvdmkswrygauc
++
+IHGFEDIHGFEDIHGFEDIHGFEDIHGFED
diff -r 000000000000 -r de14b969d713 test-data/misc_rna_original_sanger.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/misc_rna_original_sanger.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,16 @@
+@FAKE0011 Original version has lower case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+ACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUA
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0012 Original version has mixed case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+gUcauAGcgUcauAGcgUcauAGcgUcauAGcgUcauAGcg
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0013 Original version has lower case unambiguous RNA with PHRED scores from 0 to 40 inclusive (in that order)
+ucagucagucagucagucagucagucagucagucagucagu
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI
+@FAKE0014 Original version has mixed case ambiguous RNA with PHRED scores from 35 to 40 inclusive (cycled)
+gaucrywsmkhbvdnGAUCRYWSMKHBVDN
++
+DEFGHIDEFGHIDEFGHIDEFGHIDEFGHI
diff -r 000000000000 -r de14b969d713 test-data/sanger_full_range_as_rna.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sanger_full_range_as_rna.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,8 @@
+@FAKE0001 Original version has PHRED scores from 0 to 93 inclusive (in that order)
+ACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUACGUAC
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
+@FAKE0002 Original version has PHRED scores from 93 to 0 inclusive (in that order)
+CAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCAUGCA
++
+~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
diff -r 000000000000 -r de14b969d713 test-data/sanger_full_range_original_sanger.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sanger_full_range_original_sanger.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,8 @@
+@FAKE0001 Original version has PHRED scores from 0 to 93 inclusive (in that order)
+ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTAC
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
+@FAKE0002 Original version has PHRED scores from 93 to 0 inclusive (in that order)
+CATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCA
++
+~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
diff -r 000000000000 -r de14b969d713 test-data/sanger_full_range_rev_comp.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sanger_full_range_rev_comp.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,8 @@
+@FAKE0001 Original version has PHRED scores from 0 to 93 inclusive (in that order)
+GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT
++
+~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0002 Original version has PHRED scores from 93 to 0 inclusive (in that order)
+TGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATG
++
+!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
diff -r 000000000000 -r de14b969d713 test-data/sanger_full_range_rev_comp_1_seq.fastqsanger
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/sanger_full_range_rev_comp_1_seq.fastqsanger Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,8 @@
+@FAKE0001 Original version has PHRED scores from 0 to 93 inclusive (in that order)
+GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT
++
+~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
+@FAKE0002 Original version has PHRED scores from 93 to 0 inclusive (in that order)
+CATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCA
++
+~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
diff -r 000000000000 -r de14b969d713 tool_dependencies.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml Thu Jan 23 12:31:03 2014 -0500
@@ -0,0 +1,6 @@
+
+
+
+
+
+