PageRenderTime 36ms CodeModel.GetById 11ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/fastq/fastq_filter.xml

https://bitbucket.org/cistrome/cistrome-harvard/
XML | 318 lines | 254 code | 10 blank | 54 comment | 0 complexity | 4e9b551d1aeaad5b657014e484389199 MD5 | raw file
  1<tool id="fastq_filter" name="Filter FASTQ" version="1.0.0">
  2  <description>reads by quality score and length</description>
  3  <command interpreter="python">fastq_filter.py $input_file $fastq_filter_file $output_file $output_file.files_path '${input_file.extension[len( 'fastq' ):]}'</command>
  4  <inputs>
  5    <page>
  6      <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."/>
  7       <param name="min_size" label="Minimum Size" value="0" type="integer">
  8        <validator type="in_range" message="Minimum size must be positive" min="0"/>
  9      </param>
 10      <param name="max_size" label="Maximum Size" value="0" type="integer" help="A maximum size less than 1 indicates no limit."/>
 11      <param name="min_quality" label="Minimum Quality" value="0" type="float"/>
 12      <param name="max_quality" label="Maximum Quality" value="0" type="float" help="A maximum quality less than 1 indicates no limit."/>
 13      <param name="max_num_deviants" label="Maximum number of bases allowed outside of quality range" value="0" type="integer">
 14        <validator type="in_range" message="Maximum number of deviate bases must be positive" min="0"/>
 15      </param>
 16     <param name="paired_end" label="This is paired end data" type="boolean" truevalue="paired_end" falsevalue="single_end" checked="False"/>
 17      <repeat name="fastq_filters" title="Quality Filter on a Range of Bases" help="The above settings do not apply to these filters.">
 18        <conditional name="offset_type">
 19          <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)">
 20            <option value="offsets_absolute" selected="true">Absolute Values</option>
 21            <option value="offsets_percent">Percentage of Read Length</option>
 22          </param>
 23          <when value="offsets_absolute">
 24            <param name="left_column_offset" label="Offset from 5' end" value="0" type="integer" help="Values start at 0, increasing from the left">
 25              <validator type="in_range" message="Base Offsets must be positive" min="0" max="inf"/>
 26              <validator type="expression" message="An integer is required.">int( float( value ) ) == float( value )</validator>
 27            </param>
 28            <param name="right_column_offset" label="Offset from 3' end" value="0" type="integer" help="Values start at 0, increasing from the right">
 29              <validator type="in_range" message="Base Offsets must be positive" min="0" max="inf"/>
 30              <validator type="expression" message="An integer is required.">int( float( value ) ) == float( value )</validator>
 31            </param>
 32          </when>
 33          <when value="offsets_percent">
 34            <param name="left_column_offset" label="Offset from 5' end" value="0" type="float">
 35              <validator type="in_range" message="Base Offsets must be between 0 and 100" min="0" max="100"/>
 36            </param>
 37            <param name="right_column_offset" label="Offset from 3' end" value="0" type="float">
 38              <validator type="in_range" message="Base Offsets must be between 0 and 100" min="0" max="100"/>
 39            </param>
 40          </when>
 41        </conditional>
 42        <param name="score_operation" type="select" label="Aggregate read score for specified range">
 43          <option value="min" selected="True">min score</option>
 44          <option value="max">max score</option>
 45          <option value="sum">sum of scores</option>
 46          <option value="mean">mean of scores</option>
 47        </param>
 48        <param name="score_comparison" type="select" label="Keep read when aggregate score is">
 49          <option value="&gt;">&gt;</option>
 50          <option value="&gt;=" selected="true">&gt;=</option>
 51          <option value="==">==</option>
 52          <option value="&lt;">&lt;</option>
 53          <option value="&lt;=">&lt;=</option>
 54          <sanitizer sanitize="False"/>
 55        </param>
 56        <param name="score" label="Quality Score" value="0" type="float" />
 57      </repeat>
 58    </page>
 59  </inputs>
 60  <configfiles>
 61    <configfile name="fastq_filter_file">
 62def fastq_read_pass_filter( fastq_read ):
 63    def mean( score_list ):
 64        return float( sum( score_list ) ) / float( len( score_list ) )
 65    if len( fastq_read ) &lt; $min_size:
 66        return False
 67    if $max_size &gt; 0 and len( fastq_read ) &gt; $max_size:
 68        return False
 69    num_deviates = $max_num_deviants
 70    qual_scores = fastq_read.get_decimal_quality_scores()
 71    for qual_score in qual_scores:
 72        if qual_score &lt; $min_quality or ( $max_quality &gt; 0 and qual_score &gt; $max_quality ):
 73            if num_deviates == 0:
 74                return False
 75            else:
 76                num_deviates -= 1
 77#if not $paired_end:
 78    qual_scores_split = [ qual_scores ]
 79#else:
 80    qual_scores_split = [ qual_scores[ 0:int( len( qual_scores ) / 2 ) ], qual_scores[ int( len( qual_scores ) / 2 ): ] ]
 81#end if
 82#for $fastq_filter in $fastq_filters:
 83    for split_scores in qual_scores_split:
 84        left_column_offset = $fastq_filter[ 'offset_type' ][ 'left_column_offset' ]
 85        right_column_offset = $fastq_filter[ 'offset_type' ][ 'right_column_offset' ]
 86#if $fastq_filter[ 'offset_type' ]['base_offset_type'] == 'offsets_percent':
 87        left_column_offset = int( round( float( left_column_offset ) / 100.0 * float( len( split_scores ) ) ) )
 88        right_column_offset = int( round( float( right_column_offset ) / 100.0 * float( len( split_scores ) ) ) )
 89#end if
 90        if right_column_offset > 0:
 91            split_scores = split_scores[ left_column_offset:-right_column_offset]
 92        else:
 93            split_scores = split_scores[ left_column_offset:]
 94        if split_scores: ##if a read doesn't have enough columns, it passes by default 
 95            if not ( ${fastq_filter[ 'score_operation' ]}( split_scores ) $fastq_filter[ 'score_comparison' ] $fastq_filter[ 'score' ]  ):
 96                return False
 97#end for
 98    return True
 99ret_val = fastq_read_pass_filter( fastq_read )
100</configfile>
101  </configfiles>
102  <outputs>
103    <data format="input" name="output_file" />
104  </outputs>
105  <tests>
106    <!-- Do nothing filter -->
107    <test>
108      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
109      <param name="min_size" value="0"/>
110      <param name="max_size" value="0"/>
111      <param name="min_quality" value="0"/>
112      <param name="max_quality" value="0"/>
113      <param name="max_num_deviants" value="0"/>
114      <param name="paired_end" value="False"/>
115      <param name="base_offset_type" value="offsets_absolute"/>
116      <param name="left_column_offset" value="0"/>
117      <param name="right_column_offset" value="0"/>
118      <param name="score_operation" value="min"/>
119      <param name="score_comparison" value="&gt;="/>
120      <param name="score" value="0"/>
121      <output name="out_file1" file="sanger_full_range_original_sanger.fastqsanger"/>
122    </test>
123    <!-- crippled input types prevent this test <test>
124      <param name="input_file" value="solexa_full_range_original_solexa.fastqsolexa" ftype="fastqsolexa"/>
125      <param name="min_size" value="0"/>
126      <param name="max_size" value="0"/>
127      <param name="min_quality" value="-5"/>
128      <param name="max_quality" value="0"/>
129      <param name="max_num_deviants" value="0"/>
130      <param name="paired_end" value="False"/>
131      <param name="base_offset_type" value="offsets_absolute"/>
132      <param name="left_column_offset" value="0"/>
133      <param name="right_column_offset" value="0"/>
134      <param name="score_operation" value="min"/>
135      <param name="score_comparison" value="&gt;="/>
136      <param name="score" value="-5"/>
137      <output name="out_file1" file="solexa_full_range_original_solexa.fastqsolexa"/>
138    </test> -->
139    <!-- No trim, so does not remove Adapter from cssanger -->
140    <test>
141      <param name="input_file" value="sanger_full_range_as_cssanger.fastqcssanger" ftype="fastqcssanger"/>
142      <param name="min_size" value="0"/>
143      <param name="max_size" value="0"/>
144      <param name="min_quality" value="0"/>
145      <param name="max_quality" value="0"/>
146      <param name="max_num_deviants" value="0"/>
147      <param name="paired_end" value="False"/>
148      <param name="base_offset_type" value="offsets_absolute"/>
149      <param name="left_column_offset" value="0"/>
150      <param name="right_column_offset" value="0"/>
151      <param name="score_operation" value="min"/>
152      <param name="score_comparison" value="&gt;="/>
153      <param name="score" value="0"/>
154      <output name="out_file1" file="sanger_full_range_as_cssanger.fastqcssanger"/>
155    </test>
156    <!-- Remove all Filter -->
157    <test>
158      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
159      <param name="min_size" value="0"/>
160      <param name="max_size" value="0"/>
161      <param name="min_quality" value="1"/>
162      <param name="max_quality" value="0"/>
163      <param name="max_num_deviants" value="0"/>
164      <param name="paired_end" value="False"/>
165      <param name="base_offset_type" value="offsets_absolute"/>
166      <param name="left_column_offset" value="0"/>
167      <param name="right_column_offset" value="0"/>
168      <param name="score_operation" value="min"/>
169      <param name="score_comparison" value="&gt;="/>
170      <param name="score" value="0"/>
171      <output name="out_file1" file="empty_file.dat"/>
172    </test>
173    <!-- crippled input types prevent this test <test>
174      <param name="input_file" value="solexa_full_range_original_solexa.fastqsolexa" ftype="fastqsolexa"/>
175      <param name="min_size" value="0"/>
176      <param name="max_size" value="0"/>
177      <param name="min_quality" value="-4"/>
178      <param name="max_quality" value="0"/>
179      <param name="max_num_deviants" value="0"/>
180      <param name="paired_end" value="False"/>
181      <param name="base_offset_type" value="offsets_absolute"/>
182      <param name="left_column_offset" value="0"/>
183      <param name="right_column_offset" value="0"/>
184      <param name="score_operation" value="min"/>
185      <param name="score_comparison" value="&gt;="/>
186      <param name="score" value="-5"/>
187      <output name="out_file1" file="empty_file.dat"/>
188    </test> -->
189    <!-- Keep all by allowing 1 deviant -->
190    <test>
191      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
192      <param name="min_size" value="0"/>
193      <param name="max_size" value="0"/>
194      <param name="min_quality" value="1"/>
195      <param name="max_quality" value="0"/>
196      <param name="max_num_deviants" value="1"/>
197      <param name="paired_end" value="False"/>
198      <param name="base_offset_type" value="offsets_absolute"/>
199      <param name="left_column_offset" value="0"/>
200      <param name="right_column_offset" value="0"/>
201      <param name="score_operation" value="min"/>
202      <param name="score_comparison" value="&gt;="/>
203      <param name="score" value="0"/>
204      <output name="out_file1" file="sanger_full_range_original_sanger.fastqsanger"/>
205    </test>
206    <!-- crippled input types prevent this test<test>
207      <param name="input_file" value="solexa_full_range_original_solexa.fastqsolexa" ftype="fastqsolexa"/>
208      <param name="min_size" value="0"/>
209      <param name="max_size" value="0"/>
210      <param name="min_quality" value="-5"/>
211      <param name="max_quality" value="61"/>
212      <param name="max_num_deviants" value="1"/>
213      <param name="paired_end" value="False"/>
214      <param name="base_offset_type" value="offsets_absolute"/>
215      <param name="left_column_offset" value="0"/>
216      <param name="right_column_offset" value="0"/>
217      <param name="score_operation" value="min"/>
218      <param name="score_comparison" value="&gt;="/>
219      <param name="score" value="-5"/>
220      <output name="out_file1" file="solexa_full_range_original_solexa.fastqsolexa"/>
221    </test> -->
222    <!-- Filter inner range -->
223    <test>
224      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
225      <param name="min_size" value="0"/>
226      <param name="max_size" value="0"/>
227      <param name="min_quality" value="0"/>
228      <param name="max_quality" value="0"/>
229      <param name="max_num_deviants" value="0"/>
230      <param name="paired_end" value="False"/>
231      <param name="base_offset_type" value="offsets_absolute"/>
232      <param name="left_column_offset" value="1"/>
233      <param name="right_column_offset" value="1"/>
234      <param name="score_operation" value="min"/>
235      <param name="score_comparison" value="&gt;="/>
236      <param name="score" value="1"/>
237      <output name="out_file1" file="sanger_full_range_original_sanger.fastqsanger"/>
238    </test>
239    <test>
240      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
241      <param name="min_size" value="0"/>
242      <param name="max_size" value="0"/>
243      <param name="min_quality" value="0"/>
244      <param name="max_quality" value="0"/>
245      <param name="max_num_deviants" value="0"/>
246      <param name="paired_end" value="False"/>
247      <param name="base_offset_type" value="offsets_absolute"/>
248      <param name="left_column_offset" value="1"/>
249      <param name="right_column_offset" value="1"/>
250      <param name="score_operation" value="max"/>
251      <param name="score_comparison" value="&lt;="/>
252      <param name="score" value="92"/>
253      <output name="out_file1" file="sanger_full_range_original_sanger.fastqsanger"/>
254    </test>
255    <!-- percent based offsets -->
256    <test>
257      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
258      <param name="min_size" value="0"/>
259      <param name="max_size" value="0"/>
260      <param name="min_quality" value="0"/>
261      <param name="max_quality" value="0"/>
262      <param name="max_num_deviants" value="0"/>
263      <param name="paired_end" value="False"/>
264      <param name="base_offset_type" value="offsets_percent"/>
265      <param name="left_column_offset" value="1.075"/>
266      <param name="right_column_offset" value="1.075"/>
267      <param name="score_operation" value="min"/>
268      <param name="score_comparison" value="&gt;="/>
269      <param name="score" value="1"/>
270      <output name="out_file1" file="sanger_full_range_original_sanger.fastqsanger"/>
271    </test>
272    <test>
273      <param name="input_file" value="sanger_full_range_original_sanger.fastqsanger" ftype="fastqsanger"/>
274      <param name="min_size" value="0"/>
275      <param name="max_size" value="0"/>
276      <param name="min_quality" value="0"/>
277      <param name="max_quality" value="0"/>
278      <param name="max_num_deviants" value="0"/>
279      <param name="paired_end" value="True"/>
280      <param name="base_offset_type" value="offsets_percent"/>
281      <param name="left_column_offset" value="1"/>
282      <param name="right_column_offset" value="1"/>
283      <param name="score_operation" value="min"/>
284      <param name="score_comparison" value="&gt;="/>
285      <param name="score" value="1"/>
286      <output name="out_file1" file="empty_file.dat"/>
287    </test>
288  </tests>
289<help>
290This tool allows you to build complex filters to be applied to each read in a FASTQ file.
291
292**Basic Options:**
293    * You can specify a minimum and maximum read lengths.
294    * You can specify minimum and maximum per base quality scores, with optionally specifying the number of bases that are allowed to deviate from this range (default of 0 deviant bases).
295    * If your data is paired-end, select the proper checkbox; this will cause each read to be internally split down the middle and filters applied to each half using the offsets specified.
296
297**Advance Options:**
298    * You can specify any number of advanced filters. 
299    * 5' and 3' offsets are defined, starting at zero, increasing from the respective end of the reads. For example, a quality string of "ABCDEFG", with 5' and 3' offsets of 1 and 1, respectively, specified will yield "BCDEF".
300    * You can specify either absolute offset values, or percentage offset values. *Absolute Values* based offsets are useful for fixed length reads (e.g. Illumina or SOLiD data). *Percentage of Read Length* based offsets are useful for variable length reads (e.g. 454 data). When using the percent-based method, offsets are rounded to the nearest integer.
301    * The user specifies the aggregating action (min, max, sum, mean) to perform on the quality score values found between the specified offsets to be used with the user defined comparison operation and comparison value.
302    * If a set of offsets is specified that causes the remaining quality score list to be of length zero, then the read will **pass** the quality filter unless the size range filter is used to remove these reads.
303
304-----
305
306.. class:: warningmark
307
308Adapter bases in color space reads are excluded from filtering.
309
310------
311
312**Citation**
313
314If 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;`_
315
316
317</help>
318</tool>