# HG changeset patch # User devteam # Date 1354637405 18000 # Node ID f862a6e4d0964d93923513222266d947c7c4ac98 Uploaded trimmer tarball. diff -r 000000000000 -r f862a6e4d096 test-data/trimmer_a_f_c0_s1_e13_i62.dat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/trimmer_a_f_c0_s1_e13_i62.dat Tue Dec 04 11:10:05 2012 -0500 @@ -0,0 +1,5 @@ +12345 abcdef +67890 ghjkl g +>assa lljlj ljlj +sasas hghg hg +@dgf gfgf gfg diff -r 000000000000 -r f862a6e4d096 test-data/trimmer_a_f_c2_s1_e2_i62.dat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/trimmer_a_f_c2_s1_e2_i62.dat Tue Dec 04 11:10:05 2012 -0500 @@ -0,0 +1,5 @@ +12345 ab xyz +67890 gh ghjt +>assa lljlj ljlj +sasas hg hghg +@dgf gf gfgf diff -r 000000000000 -r f862a6e4d096 test-data/trimmer_tab_delimited.dat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/trimmer_tab_delimited.dat Tue Dec 04 11:10:05 2012 -0500 @@ -0,0 +1,5 @@ +12345 abcdef xyz +67890 ghjkl ghjt +>assa lljlj ljlj +sasas hghg hghg +@dgf gfgf gfgf diff -r 000000000000 -r f862a6e4d096 trimmer.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trimmer.py Tue Dec 04 11:10:05 2012 -0500 @@ -0,0 +1,106 @@ +#!/usr/bin/env python + +import sys +import optparse + +def stop_err( msg ): + sys.stderr.write( msg ) + sys.exit() + +def main(): + usage = """%prog [options] + +options (listed below) default to 'None' if omitted + """ + parser = optparse.OptionParser(usage=usage) + + parser.add_option( + '-a','--ascii', + dest='ascii', + action='store_true', + default = False, + help='Use ascii codes to defined ignored beginnings instead of raw characters') + + parser.add_option( + '-q','--fastq', + dest='fastq', + action='store_true', + default = False, + help='The input data in fastq format. It selected the script skips every even line since they contain sequence ids') + + parser.add_option( + '-i','--ignore', + dest='ignore', + help='A comma separated list on ignored beginnings (e.g., ">,@"), or its ascii codes (e.g., "60,42") if option -a is enabled') + + parser.add_option( + '-s','--start', + dest='start', + default = '0', + help='Trim from beginning to here (1-based)') + + parser.add_option( + '-e','--end', + dest='end', + default = '0', + help='Trim from here to the ned (1-based)') + + parser.add_option( + '-f','--file', + dest='input_txt', + default = False, + help='Name of file to be chopped. STDIN is default') + + parser.add_option( + '-c','--column', + dest='col', + default = '0', + help='Column to chop. If 0 = chop the whole line') + + + options, args = parser.parse_args() + invalid_starts = [] + + if options.input_txt: + infile = open ( options.input_txt, 'r') + else: + infile = sys.stdin + + if options.ignore and options.ignore != "None": + invalid_starts = options.ignore.split(',') + + if options.ascii and options.ignore and options.ignore != "None": + for i, item in enumerate( invalid_starts ): + invalid_starts[i] = chr( int( item ) ) + + col = int( options.col ) + + for i, line in enumerate( infile ): + line = line.rstrip( '\r\n' ) + if line: + + if options.fastq and i % 2 == 0: + print line + continue + + + if line[0] not in invalid_starts: + if col == 0: + if int( options.end ) > 0: + line = line[ int( options.start )-1 : int( options.end ) ] + else: + line = line[ int( options.start )-1 : ] + else: + fields = line.split( '\t' ) + if col-1 > len( fields ): + stop_err('Column %d does not exist. Check input parameters\n' % col) + + if int( options.end ) > 0: + fields[col - 1] = fields[col - 1][ int( options.start )-1 : int( options.end ) ] + else: + fields[col - 1] = fields[col - 1][ int( options.start )-1 : ] + line = '\t'.join(fields) + print line + +if __name__ == "__main__": main() + diff -r 000000000000 -r f862a6e4d096 trimmer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trimmer.xml Tue Dec 04 11:10:05 2012 -0500 @@ -0,0 +1,120 @@ + + leading or trailing characters + + trimmer.py -a -f $input1 -c $col -s $start -e $end -i $ignore $fastq > $out_file1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +**What it does** + +Trims specified number of characters from a dataset or its field (if dataset is tab-delimited). + +----- + +**Example 1** + +Trimming this dataset:: + + 1234567890 + abcdefghijk + +by setting **Trim from the beginning to this position** to *2* and **Remove everything from this position to the end** to *6* will produce:: + + 23456 + bcdef + +----- + +**Example 2** + +Trimming column 2 of this dataset:: + + abcde 12345 fghij 67890 + fghij 67890 abcde 12345 + +by setting **Trim content of this column only** to *2*, **Trim from the beginning to this position** to *2*, and **Remove everything from this position to the end** to *4* will produce:: + + abcde 234 fghij 67890 + fghij 789 abcde 12345 + +----- + +**Trimming FASTQ datasets** + +This tool can be used to trim sequences and quality strings in fastq datasets. This is done by selected *Yes* from the **Is input dataset in fastq format?** dropdown. If set to *Yes*, the tool will skip all even numbered lines (see warning below). For example, trimming last 5 bases of this dataset:: + + @081017-and-081020:1:1:1715:1759 + GGACTCAGATAGTAATCCACGCTCCTTTAAAATATC + + + II#IIIIIII$5+.(9IIIIIII$%*$G$A31I&&B + +cab done by setting **Remove everything from this position to the end** to 31:: + + @081017-and-081020:1:1:1715:1759 + GGACTCAGATAGTAATCCACGCTCCTTTAAA + + + II#IIIIIII$5+.(9IIIIIII$%*$G$A3 + +**Note** that headers are skipped. + +.. class:: warningmark + +**WARNING:** This tool will only work on properly formatted fastq datasets where (1) each read and quality string occupy one line and (2) '@' (read header) and "+" (quality header) lines are evenly numbered like in the above example. + + + +