comparison fastq_manipulation.xml @ 0:de14b969d713 draft

Imported from capsule None
author devteam
date Thu, 23 Jan 2014 12:31:03 -0500
parents
children b50aeae8bcaa
comparison
equal deleted inserted replaced
-1:000000000000 0:de14b969d713
1 <tool id="fastq_manipulation" name="Manipulate FASTQ" version="1.0.1">
2 <options sanitize="False" /> <!-- This tool uses a file to rely all parameter information (actually a dynamically generated python module), we can safely not sanitize any parameters -->
3 <requirements>
4 <requirement type="package" version="1.0.0">galaxy_sequence_utils</requirement>
5 </requirements>
6 <description>reads on various attributes</description>
7 <command interpreter="python">fastq_manipulation.py $input_file $fastq_manipulation_file $output_file $output_file.files_path '${input_file.extension[len( 'fastq' ):]}'</command>
8 <inputs>
9 <!-- This tool is purposely over-engineered (e.g. Single option conditionals) to allow easy enhancement with workflow/rerun compatibility -->
10 <page>
11 <param name="input_file" type="data" format="fastqsanger,fastqcssanger" label="FASTQ File" help="Requires groomed data: if your data does not appear here try using the FASTQ groomer."/>
12 <!-- Match Reads -->
13 <repeat name="match_blocks" title="Match Reads">
14 <conditional name="match_type">
15 <param name="match_type_selector" type="select" label="Match Reads by">
16 <option value="identifier">Name/Identifier</option>
17 <option value="sequence">Sequence Content</option>
18 <option value="quality">Quality Score Content</option>
19 </param>
20 <when value="identifier">
21 <conditional name="match">
22 <param name="match_selector" type="select" label="Identifier Match Type">
23 <option value="regex">Regular Expression</option>
24 </param>
25 <when value="regex">
26 <param type="text" name="match_by" label="Match by" value=".*" />
27 </when>
28 </conditional>
29 </when>
30 <when value="sequence">
31 <conditional name="match">
32 <param name="match_selector" type="select" label="Sequence Match Type">
33 <option value="regex">Regular Expression</option>
34 </param>
35 <when value="regex">
36 <param type="text" name="match_by" label="Match by" value=".*" />
37 </when>
38 </conditional>
39 </when>
40 <when value="quality">
41 <conditional name="match">
42 <param name="match_selector" type="select" label="Quality Match Type">
43 <option value="regex">Regular Expression</option>
44 </param>
45 <when value="regex">
46 <param type="text" name="match_by" label="Match by" value=".*" />
47 </when>
48 </conditional>
49 </when>
50 </conditional>
51 </repeat>
52 <!-- Manipulate Matched Reads -->
53 <repeat name="manipulate_blocks" title="Manipulate Reads">
54 <conditional name="manipulation_type">
55 <param name="manipulation_type_selector" type="select" label="Manipulate Reads on">
56 <option value="identifier">Name/Identifier</option>
57 <option value="sequence">Sequence Content</option>
58 <option value="quality">Quality Score Content</option>
59 <option value="miscellaneous">Miscellaneous Actions</option>
60 </param>
61 <when value="identifier">
62 <conditional name="manipulation">
63 <param name="manipulation_selector" type="select" label="Identifier Manipulation Type">
64 <option value="translate">String Translate</option>
65 </param>
66 <when value="translate">
67 <param name="from" type="text" label="From" value="" />
68 <param name="to" type="text" label="To" value="" />
69 </when>
70 </conditional>
71 </when>
72 <when value="sequence">
73 <conditional name="manipulation">
74 <param name="manipulation_selector" type="select" label="Sequence Manipulation Type">
75 <option value="rev_comp">Reverse Complement</option>
76 <option value="rev_no_comp">Reverse, No Complement</option>
77 <option value="no_rev_comp">Complement, No Reverse</option>
78 <option value="trim">Trim</option>
79 <option value="dna_to_rna">DNA to RNA</option>
80 <option value="rna_to_dna">RNA to DNA</option>
81 <option value="translate">String Translate</option>
82 <option value="change_adapter">Change Adapter Base</option>
83 </param>
84 <when value="rev_comp">
85 <!-- no extra settings -->
86 </when>
87 <when value="rev_no_comp">
88 <!-- no extra settings -->
89 </when>
90 <when value="no_rev_comp">
91 <!-- no extra settings -->
92 </when>
93 <when value="trim">
94 <conditional name="offset_type">
95 <param name="base_offset_type" type="select" label="Define Base Offsets as" help="Use Absolute for fixed length reads (Illumina, SOLiD)&lt;br&gt;Use Percentage for variable length reads (Roche/454)">
96 <option value="offsets_absolute" selected="true">Absolute Values</option>
97 <option value="offsets_percent">Percentage of Read Length</option>
98 </param>
99 <when value="offsets_absolute">
100 <param name="left_column_offset" label="Offset from 5' end" value="0" type="integer" help="Values start at 0, increasing from the left">
101 <validator type="in_range" message="Base Offsets must be positive" min="0" max="inf"/>
102 <validator type="expression" message="An integer is required.">int( float( value ) ) == float( value )</validator>
103 </param>
104 <param name="right_column_offset" label="Offset from 3' end" value="0" type="integer" help="Values start at 0, increasing from the right">
105 <validator type="in_range" message="Base Offsets must be positive" min="0" max="inf"/>
106 <validator type="expression" message="An integer is required.">int( float( value ) ) == float( value )</validator>
107 </param>
108 </when>
109 <when value="offsets_percent">
110 <param name="left_column_offset" label="Offset from 5' end" value="0" type="float">
111 <validator type="in_range" message="Base Offsets must be between 0 and 100" min="0" max="100"/>
112 </param>
113 <param name="right_column_offset" label="Offset from 3' end" value="0" type="float">
114 <validator type="in_range" message="Base Offsets must be between 0 and 100" min="0" max="100"/>
115 </param>
116 </when>
117 </conditional>
118 <param name="keep_zero_length" label="Keep reads with zero length" type="boolean" truevalue="keep_zero_length" falsevalue="exclude_zero_length" selected="False"/>
119 </when>
120 <when value="dna_to_rna">
121 <!-- no extra settings -->
122 </when>
123 <when value="rna_to_dna">
124 <!-- no extra settings -->
125 </when>
126 <when value="translate">
127 <param name="from" type="text" label="From" value="" />
128 <param name="to" type="text" label="To" value="" />
129 </when>
130 <when value="change_adapter">
131 <param name="new_adapter" label="New Adapter" type="text" value="G" help="An empty string will remove the adapter base" />
132 </when>
133 </conditional>
134 </when>
135 <when value="quality">
136 <conditional name="manipulation">
137 <param name="manipulation_selector" type="select" label="Quality Manipulation Type">
138 <option value="translate">String Translate</option>
139 <!-- <option value="modify_each_score">Apply Transformation to each Score</option> Not enabled yet-->
140 </param>
141 <when value="translate">
142 <param name="from" type="text" label="From" value="" />
143 <param name="to" type="text" label="To" value="" />
144 </when>
145 <when value="modify_each_score">
146 <param name="map_score" type="text" label="Modify Score by" value="$score + 1" />
147 </when>
148 </conditional>
149 </when>
150 <when value="miscellaneous">
151 <conditional name="manipulation">
152 <param name="manipulation_selector" type="select" label="Miscellaneous Manipulation Type">
153 <option value="remove">Remove Read</option>
154 </param>
155 <when value="remove">
156 <!-- no extra settings -->
157 </when>
158 </conditional>
159 </when>
160 </conditional>
161 </repeat>
162 </page>
163 </inputs>
164 <configfiles>
165 <configfile name="fastq_manipulation_file">##create an importable module
166 #import binascii
167 import re
168 import binascii
169 from string import maketrans
170 ##does read match
171 def match_read( fastq_read ):
172 #for $match_block in $match_blocks:
173 #if $match_block['match_type']['match_type_selector'] == 'identifier':
174 search_target = fastq_read.identifier[1:] ##don't include @
175 #elif $match_block['match_type']['match_type_selector'] == 'sequence':
176 search_target = fastq_read.sequence
177 #elif $match_block['match_type']['match_type_selector'] == 'quality':
178 search_target = fastq_read.quality
179 #else:
180 #continue
181 #end if
182 if not re.search( binascii.unhexlify( "${ binascii.hexlify( str( match_block['match_type']['match']['match_by'] ) ) }" ), search_target ):
183 return False
184 #end for
185 return True
186 ##modify matched reads
187 def manipulate_read( fastq_read ):
188 new_read = fastq_read.clone()
189 #for $manipulate_block in $manipulate_blocks:
190 #if $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'identifier':
191 #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
192 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'] ) ) }" ) ) )
193 #end if
194 #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'sequence':
195 #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
196 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'] ) ) }" ) ) )
197 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rev_comp':
198 new_read = new_read.reverse_complement()
199 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rev_no_comp':
200 new_read = new_read.reverse()
201 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'no_rev_comp':
202 new_read = new_read.complement()
203 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'trim':
204 #if $manipulate_block['manipulation_type']['manipulation']['offset_type']['base_offset_type'] == 'offsets_percent':
205 left_column_offset = int( round( float( ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['left_column_offset'] } ) / 100.0 * float( len( new_read ) ) ) )
206 right_column_offset = int( round( float( ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['right_column_offset'] } ) / 100.0 * float( len( new_read ) ) ) )
207 #else
208 left_column_offset = ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['left_column_offset'] }
209 right_column_offset = ${ manipulate_block['manipulation_type']['manipulation']['offset_type']['right_column_offset'] }
210 #end if
211 if right_column_offset > 0:
212 right_column_offset = -right_column_offset
213 else:
214 right_column_offset = None
215 new_read = new_read.slice( left_column_offset, right_column_offset )
216 if not ( ${str( manipulate_block['manipulation_type']['manipulation']['keep_zero_length'] ) == 'keep_zero_length'} or len( new_read ) ):
217 return None
218 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'dna_to_rna':
219 new_read = new_read.sequence_as_DNA()
220 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'rna_to_dna':
221 new_read = new_read.sequence_as_RNA()
222 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'change_adapter':
223 if new_read.sequence_space == 'color':
224 new_read = new_read.change_adapter( binascii.unhexlify( "${ binascii.hexlify( str( manipulate_block['manipulation_type']['manipulation']['new_adapter'] ) ) }" ) )
225 #end if
226 #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'quality':
227 #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'translate':
228 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'] ) ) }" ) ) )
229 #elif $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'map_score':
230 def score_method( score ):
231 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
232 new_read.quality_map( score_method )
233 #end if
234 #elif $manipulate_block['manipulation_type']['manipulation_type_selector'] == 'miscellaneous':
235 #if $manipulate_block['manipulation_type']['manipulation']['manipulation_selector'] == 'remove':
236 return None
237 #end if
238 #else:
239 #continue
240 #end if
241 #end for
242 if new_read.description != "+":
243 new_read.description = "+%s" % new_read.identifier[1:] ##ensure description is still valid
244 return new_read
245 def match_and_manipulate_read( fastq_read ):
246 new_read = fastq_read
247 if match_read( fastq_read ):
248 new_read = manipulate_read( fastq_read )
249 return new_read
250 </configfile>
251 </configfiles>
252 <outputs>
253 <data format="input" name="output_file" />
254 </outputs>
255 <tests>
256 <!-- match all and do nothing -->
257 <test>
258 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
259 <param name="match_type_selector" value="identifier" />
260 <param name="match_selector" value="regex" />
261 <param name="match_by" value=".*" />
262 <param name="manipulation_type_selector" value="identifier" />
263 <param name="manipulation_selector" value="translate" />
264 <param name="from" value="" />
265 <param name="to" value="" />
266 <output name="output_file" file="sanger_full_range_original_sanger.fastqsanger" />
267 </test>
268 <!-- match None and do nothing -->
269 <test>
270 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
271 <param name="match_type_selector" value="identifier" />
272 <param name="match_selector" value="regex" />
273 <param name="match_by" value="STRINGDOESNOTEXIST" />
274 <param name="manipulation_type_selector" value="identifier" />
275 <param name="manipulation_selector" value="translate" />
276 <param name="from" value="" />
277 <param name="to" value="" />
278 <output name="output_file" file="sanger_full_range_original_sanger.fastqsanger" />
279 </test>
280 <!-- match all and remove -->
281 <test>
282 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
283 <param name="match_type_selector" value="identifier" />
284 <param name="match_selector" value="regex" />
285 <param name="match_by" value=".*" />
286 <param name="manipulation_type_selector" value="miscellaneous" />
287 <param name="manipulation_selector" value="remove" />
288 <output name="output_file" file="empty_file.dat" />
289 </test>
290 <!-- match None and remove -->
291 <test>
292 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
293 <param name="match_type_selector" value="identifier" />
294 <param name="match_selector" value="regex" />
295 <param name="match_by" value="STRINGDOESNOTEXIST" />
296 <param name="manipulation_type_selector" value="miscellaneous" />
297 <param name="manipulation_selector" value="remove" />
298 <output name="output_file" file="sanger_full_range_original_sanger.fastqsanger" />
299 </test>
300 <!-- match all and trim to 4 inner-most bases -->
301 <test>
302 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
303 <param name="match_type_selector" value="identifier" />
304 <param name="match_selector" value="regex" />
305 <param name="match_by" value=".*" />
306 <param name="manipulation_type_selector" value="sequence" />
307 <param name="manipulation_selector" value="trim" />
308 <param name="base_offset_type" value="offsets_absolute"/>
309 <param name="left_column_offset" value="45"/>
310 <param name="right_column_offset" value="45"/>
311 <param name="keep_zero_length" value="true" />
312 <output name="output_file" file="fastq_trimmer_out1.fastqsanger" />
313 </test>
314 <test>
315 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
316 <param name="match_type_selector" value="identifier" />
317 <param name="match_selector" value="regex" />
318 <param name="match_by" value=".*" />
319 <param name="manipulation_type_selector" value="sequence" />
320 <param name="manipulation_selector" value="trim" />
321 <param name="base_offset_type" value="offsets_percent"/>
322 <param name="left_column_offset" value="47.87"/>
323 <param name="right_column_offset" value="47.87"/>
324 <param name="keep_zero_length" value="true" />
325 <output name="output_file" file="fastq_trimmer_out1.fastqsanger" />
326 </test>
327 <!-- match all and rev comp -->
328 <test>
329 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
330 <param name="match_type_selector" value="identifier" />
331 <param name="match_selector" value="regex" />
332 <param name="match_by" value=".*" />
333 <param name="manipulation_type_selector" value="sequence" />
334 <param name="manipulation_selector" value="rev_comp" />
335 <output name="output_file" file="sanger_full_range_rev_comp.fastqsanger" />
336 </test>
337 <!-- match all and rev comp, with ambiguous DNA -->
338 <test>
339 <param name="input_file" value="misc_dna_original_sanger.fastqsanger" ftype="fastqsanger" />
340 <param name="match_type_selector" value="identifier" />
341 <param name="match_selector" value="regex" />
342 <param name="match_by" value=".*" />
343 <param name="manipulation_type_selector" value="sequence" />
344 <param name="manipulation_selector" value="rev_comp" />
345 <output name="output_file" file="misc_dna_as_sanger_rev_comp_1.fastqsanger" />
346 </test>
347 <!-- match all and rev comp, with ambiguous RNA -->
348 <test>
349 <param name="input_file" value="misc_rna_original_sanger.fastqsanger" ftype="fastqsanger" />
350 <param name="match_type_selector" value="identifier" />
351 <param name="match_selector" value="regex" />
352 <param name="match_by" value=".*" />
353 <param name="manipulation_type_selector" value="sequence" />
354 <param name="manipulation_selector" value="rev_comp" />
355 <output name="output_file" file="misc_rna_as_sanger_rev_comp_1.fastqsanger" />
356 </test>
357 <!-- match first seq and rev comp -->
358 <test>
359 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
360 <param name="match_type_selector" value="identifier" />
361 <param name="match_selector" value="regex" />
362 <param name="match_by" value="FAKE0001" />
363 <param name="manipulation_type_selector" value="sequence" />
364 <param name="manipulation_selector" value="rev_comp" />
365 <output name="output_file" file="sanger_full_range_rev_comp_1_seq.fastqsanger" />
366 </test>
367 <!-- match first seq and rev comp: i.e. undo above -->
368 <test>
369 <param name="input_file" value="sanger_full_range_rev_comp_1_seq.fastqsanger" ftype="fastqsanger" />
370 <param name="match_type_selector" value="identifier" />
371 <param name="match_selector" value="regex" />
372 <param name="match_by" value="FAKE0001" />
373 <param name="manipulation_type_selector" value="sequence" />
374 <param name="manipulation_selector" value="rev_comp" />
375 <output name="output_file" file="sanger_full_range_original_sanger.fastqsanger" />
376 </test>
377 <!-- match all and DNA to RNA -->
378 <test>
379 <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger" />
380 <param name="match_type_selector" value="identifier" />
381 <param name="match_selector" value="regex" />
382 <param name="match_by" value=".*" />
383 <param name="manipulation_type_selector" value="sequence" />
384 <param name="manipulation_selector" value="dna_to_rna" />
385 <output name="output_file" file="sanger_full_range_as_rna.fastqsanger" />
386 </test>
387 <!-- match all and RNA to DNA -->
388 <test>
389 <param name="input_file" value="sanger_full_range_as_rna.fastqsanger" ftype="fastqsanger" />
390 <param name="match_type_selector" value="identifier" />
391 <param name="match_selector" value="regex" />
392 <param name="match_by" value=".*" />
393 <param name="manipulation_type_selector" value="sequence" />
394 <param name="manipulation_selector" value="rna_to_dna" />
395 <output name="output_file" file="sanger_full_range_original_sanger.fastqsanger" />
396 </test>
397 </tests>
398 <help>
399 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.
400
401 Regular Expression Matches are made using re.search, see http://docs.python.org/library/re.html for more information.
402 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.
403
404 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.
405
406 .. class:: warningmark
407
408 Only color space reads can have adapter bases substituted.
409
410
411 -----
412
413 **Example**
414
415 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.
416
417 Steps:
418
419 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).
420 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).
421 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".
422 4. Click Execute. The new history item will contained double-encoded psuedo-nucleotide space reads.
423
424 ------
425
426 **Citation**
427
428 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. &lt;http://www.ncbi.nlm.nih.gov/pubmed/20562416&gt;`_
429
430
431 </help>
432 </tool>