Mercurial > repos > devteam > get_flanks
changeset 3:2fdec558c935 draft
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
author | devteam |
---|---|
date | Tue, 13 Oct 2015 12:50:28 -0400 |
parents | 0eae46dcc35c |
children | 0f9775889036 |
files | get_flanks.py get_flanks.xml tool_dependencies.xml |
diffstat | 3 files changed, 47 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/get_flanks.py Mon Apr 14 09:17:59 2014 -0400 +++ b/get_flanks.py Tue Oct 13 12:50:28 2015 -0400 @@ -9,15 +9,17 @@ -o, --off=N: Offset """ -import sys, re, os +import sys from bx.cookbook import doc_optparse -from galaxy.tools.util.galaxyops import * +from galaxy.tools.util.galaxyops import parse_cols_arg + def stop_err( msg ): sys.stderr.write( msg ) sys.exit() -def main(): + +def main(): try: if int( sys.argv[3] ) < 0: raise Exception @@ -30,26 +32,26 @@ chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols ) inp_file, out_file, size, direction, region = args if strand_col_1 <= 0: - strand = "+" #if strand is not defined, default it to + + strand = "+" # if strand is not defined, default it to + except: stop_err( "Metadata issue, correct the metadata attributes by clicking on the pencil icon in the history item." ) try: offset = int(options.off) size = int(size) - except: + except: stop_err( "Invalid offset or length entered. Try again by entering valid integer values." ) - fo = open(out_file,'w') - + fo = open(out_file, 'w') + skipped_lines = 0 first_invalid_line = 0 invalid_line = None elems = [] - j=0 + j = 0 for i, line in enumerate( file( inp_file ) ): line = line.strip() if line and (not line.startswith( '#' )) and line != '': - j+=1 + j += 1 try: elems = line.split('\t') #if the start and/or end columns are not numbers, skip that line. @@ -76,15 +78,15 @@ elems[end_col_1] = str(int(elems[start_col_1]) + size) assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - + elif direction == 'Downstream': if strand == '-': if region == 'start': - elems[end_col_1] = str(int(elems[end_col_1]) - offset) - elems[start_col_1] = str( int(elems[end_col_1]) - size ) + elems[end_col_1] = str(int(elems[end_col_1]) - offset) + elems[start_col_1] = str( int(elems[end_col_1]) - size ) else: - elems[end_col_1] = str(int(elems[start_col_1]) - offset) - elems[start_col_1] = str( int(elems[end_col_1]) - size ) + elems[end_col_1] = str(int(elems[start_col_1]) - offset) + elems[start_col_1] = str( int(elems[end_col_1]) - size ) elif strand == '+': if region == 'start': elems[start_col_1] = str(int(elems[start_col_1]) + offset) @@ -94,31 +96,31 @@ elems[end_col_1] = str(int(elems[start_col_1]) + size) assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - + elif direction == 'Both': if strand == '-': if region == 'start': start = str(int(elems[end_col_1]) - offset) end1 = str(int(start) + size) end2 = str(int(start) - size) - elems[start_col_1]=start - elems[end_col_1]=end1 + elems[start_col_1] = start + elems[end_col_1] = end1 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=end2 - elems[end_col_1]=start + elems[start_col_1] = end2 + elems[end_col_1] = start assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) elif region == 'end': start = str(int(elems[start_col_1]) - offset) end1 = str(int(start) + size) end2 = str(int(start) - size) - elems[start_col_1]=start - elems[end_col_1]=end1 + elems[start_col_1] = start + elems[end_col_1] = end1 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=end2 - elems[end_col_1]=start + elems[start_col_1] = end2 + elems[end_col_1] = start assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) else: @@ -126,12 +128,12 @@ end1 = str(int(start1) + size) start2 = str(int(elems[start_col_1]) - offset) end2 = str(int(start2) - size) - elems[start_col_1]=start1 - elems[end_col_1]=end1 + elems[start_col_1] = start1 + elems[end_col_1] = end1 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=end2 - elems[end_col_1]=start2 + elems[start_col_1] = end2 + elems[end_col_1] = start2 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) elif strand == '+': @@ -139,24 +141,24 @@ start = str(int(elems[start_col_1]) + offset) end1 = str(int(start) - size) end2 = str(int(start) + size) - elems[start_col_1]=end1 - elems[end_col_1]=start + elems[start_col_1] = end1 + elems[end_col_1] = start assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=start - elems[end_col_1]=end2 + elems[start_col_1] = start + elems[end_col_1] = end2 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) elif region == 'end': start = str(int(elems[end_col_1]) + offset) end1 = str(int(start) - size) end2 = str(int(start) + size) - elems[start_col_1]=end1 - elems[end_col_1]=start + elems[start_col_1] = end1 + elems[end_col_1] = start assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=start - elems[end_col_1]=end2 + elems[start_col_1] = start + elems[end_col_1] = end2 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) else: @@ -164,12 +166,12 @@ end1 = str(int(start1) - size) start2 = str(int(elems[end_col_1]) + offset) end2 = str(int(start2) + size) - elems[start_col_1]=end1 - elems[end_col_1]=start1 + elems[start_col_1] = end1 + elems[end_col_1] = start1 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) - elems[start_col_1]=start2 - elems[end_col_1]=end2 + elems[start_col_1] = start2 + elems[end_col_1] = end2 assert int(elems[start_col_1]) > 0 and int(elems[end_col_1]) > 0 fo.write( "%s\n" % '\t'.join( elems ) ) except: @@ -183,7 +185,7 @@ stop_err( "Data issue: click the pencil icon in the history item to correct the metadata attributes." ) if skipped_lines > 0: print 'Skipped %d invalid lines starting with #%dL "%s"' % ( skipped_lines, first_invalid_line, invalid_line ) - print 'Location: %s, Region: %s, Flank-length: %d, Offset: %d ' %( direction, region, size, offset ) - + print 'Location: %s, Region: %s, Flank-length: %d, Offset: %d ' % ( direction, region, size, offset ) + if __name__ == "__main__": main()
--- a/get_flanks.xml Mon Apr 14 09:17:59 2014 -0400 +++ b/get_flanks.xml Tue Oct 13 12:50:28 2015 -0400 @@ -17,8 +17,8 @@ <option value="Downstream">Downstream</option> <option value="Both">Both</option> </param> - <param name="offset" size="10" type="integer" value="0" label="Offset" help="Use positive values to offset co-ordinates in the direction of transcription and negative values to offset in the opposite direction."/> - <param name="size" size="10" type="integer" value="50" label="Length of the flanking region(s)" help="Use non-negative value for length"/> + <param name="offset" type="integer" value="0" label="Offset" help="Use positive values to offset co-ordinates in the direction of transcription and negative values to offset in the opposite direction."/> + <param name="size" type="integer" value="50" label="Length of the flanking region(s)" help="Use non-negative value for length"/> </inputs>
--- a/tool_dependencies.xml Mon Apr 14 09:17:59 2014 -0400 +++ b/tool_dependencies.xml Tue Oct 13 12:50:28 2015 -0400 @@ -1,9 +1,9 @@ <?xml version="1.0"?> <tool_dependency> <package name="bx-python" version="0.7.1"> - <repository changeset_revision="cdb5991f9790" name="package_bx_python_0_7" owner="devteam" prior_installation_required="False" toolshed="http://testtoolshed.g2.bx.psu.edu" /> + <repository changeset_revision="35e2457234ef" name="package_bx_python_0_7" owner="devteam" toolshed="https://testtoolshed.g2.bx.psu.edu" /> </package> <package name="galaxy-ops" version="1.0.0"> - <repository changeset_revision="3287c55c02b8" name="package_galaxy_ops_1_0_0" owner="devteam" prior_installation_required="False" toolshed="http://testtoolshed.g2.bx.psu.edu" /> + <repository changeset_revision="3287c55c02b8" name="package_galaxy_ops_1_0_0" owner="devteam" toolshed="https://testtoolshed.g2.bx.psu.edu" /> </package> </tool_dependency>