Changeset 1323:c6ce30677868

Show
Ignore:
Timestamp:
05/23/08 16:43:20 (8 months ago)
Author:
Greg Von Kuster <greg@bx.psu.edu>
branch:
default
convert_revision:
svn:9bcadc22-80f8-0310-8a53-c8f022958886/galaxy/trunk@2684
Message:

Corrected the way we handle exceptions in the gops tools when building / using bitsets dictionaries. Added several new functional tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eggs.ini

    r1254 r1323  
    5454python_lzo = _static 
    5555flup = .dev_r2311 
    56 bx_python = _dev_r418 
     56bx_python = _dev_r427 
    5757nose = .dev_r101 
    5858DRMAA_python = _6.1u4 
     
    6060; source location, necessary for scrambling 
    6161[source] 
    62 bx_python = http://dist.g2.bx.psu.edu/bx-python_dist-r414.tar.bz2 
     62bx_python = http://dist.g2.bx.psu.edu/bx-python_dist-r427.tar.bz2 
    6363Cheetah = http://umn.dl.sourceforge.net/sourceforge/cheetahtemplate/Cheetah-1.0.tar.gz 
    6464DRMAA_python = http://gridengine.sunsource.net/files/documents/7/36/DRMAA-python-0.2.tar.gz 
  • lib/galaxy/tools/util/galaxyops/__init__.py

    r1281 r1323  
    1 """ 
    2 Utility functions for galaxyops 
    3 """ 
     1"""Utility functions for galaxyops""" 
    42import sys 
    5  
    63from bx.bitset import * 
    74from bx.intervals.io import * 
    8  
    9 class BitsetSafeNiceReaderWrapper: 
    10     """Handles exceptions thrown in bx.""" 
    11     def __init__( self, iterat ): 
    12         self.iterat = iterat 
    13         self.MAXINT = 2147483647 # max signed int value for 32-bit 
    14     def __iter__( self ): 
    15         while True: 
    16             region = self.iterat.next() 
    17             # NiceReaderWrapper can return a header, comment or GenomicInterval 
    18             if type( region ) == GenomicInterval: 
    19                 if ( region.start > self.MAXINT ) or ( region.end > self.MAXINT ) or ( region.start > region.end ): 
    20                     self.iterat.skipped += 1 
    21                     if self.iterat.skipped < 10: 
    22                         self.iterat.skipped_lines.append( ( self.iterat.linenum, self.iterat.current_line ) ) 
    23                 else: 
    24                     yield region 
    25     def __getattr__( self, name ): 
    26         return getattr( self.iterat, name ) 
    27     def binned_bitsets( self , upstream_pad=0, downstream_pad=0, lens={} ): 
    28         # This is duplicated in bx.intervals.io, but we need it here so that self refers to  
    29         # our BitsetSafeNiceReaderWrapper rather than bx.intervals.io's GenomicIntervalReader 
    30         last_chrom = None 
    31         last_bitset = None 
    32         bitsets = dict() 
    33         for interval in self: 
    34             if type( interval ) == GenomicInterval: 
    35                 chrom = interval[self.chrom_col] 
    36                 if chrom != last_chrom: 
    37                     if chrom not in bitsets: 
    38                         if chrom in lens: 
    39                             size = lens[chrom] 
    40                         else: 
    41                             size = MAX 
    42                         bitsets[chrom] = BinnedBitSet( size ) 
    43                     last_chrom = chrom 
    44                     last_bitset = bitsets[chrom] 
    45                 start = max(int( interval[self.start_col]), 0 ) 
    46                 end = min(int( interval[self.end_col]), size) 
    47                 last_bitset.set_range( start, end-start ) 
    48         return bitsets 
    495 
    506def warn( msg ): 
     
    7329 
    7430def skipped( reader, filedesc="" ): 
    75     first_line, line_contents = reader.skipped_lines[0] 
    76     return 'Skipped %d invalid lines%s starting at line #%d: "%s"' \ 
    77            % ( reader.skipped, filedesc, first_line, line_contents ) 
     31    first_line, line_contents, problem = reader.skipped_lines[0] 
     32    return 'Skipped %d invalid lines%s, 1st line #%d: "%s", problem: %s' % ( reader.skipped, filedesc, first_line, line_contents, problem ) 
  • tools/new_operations/basecoverage.xml

    r1129 r1323  
    1414    <test> 
    1515      <param name="input1" value="1.bed" /> 
    16       <output name="output" file="gops-basecoverage.dat" />      
     16      <output name="output" file="gops_basecoverage_out.txt" />      
     17    </test> 
     18    <test> 
     19      <param name="input1" value="gops_bigint.interval" /> 
     20      <output name="output" file="gops_basecoverage_out2.txt" />      
    1721    </test> 
    1822  </tests> 
  • tools/new_operations/cluster.xml

    r1129 r1323  
    3333      <param name="returntype" value="1" /> 
    3434      <output name="output" file="gops-cluster-1.bed" />      
    35     </test>     
     35    </test> 
     36    <test> 
     37      <param name="input1" value="gops_cluster_bigint.bed" /> 
     38      <param name="distance" value="1" /> 
     39      <param name="minregions" value="2" /> 
     40      <param name="returntype" value="1" /> 
     41      <output name="output" file="gops-cluster-1.bed" />      
     42    </test> 
    3643    <test> 
    3744      <param name="input1" value="5.bed" /> 
  • tools/new_operations/complement.xml

    r1129 r1323  
    1717      <param name="input1" value="1.bed" /> 
    1818      <param name="allchroms" value="true" /> 
    19       <output name="output" file="gops-complement.dat" /> 
     19      <output name="output" file="gops_complement_out.bed" /> 
     20    </test> 
     21    <test> 
     22      <param name="input1" value="gops_bigint.interval" /> 
     23      <param name="allchroms" value="true" /> 
     24      <output name="output" file="gops_complement_out2.bed" /> 
    2025    </test> 
    2126  </tests> 
  • tools/new_operations/coverage.xml

    r1129 r1323  
    1818      <param name="input1" value="1.bed" /> 
    1919      <param name="input2" value="2.bed" /> 
    20       <output name="output" file="gops-coverage.dat" /> 
     20      <output name="output" file="gops_coverage_out.interval" /> 
     21    </test> 
     22    <test> 
     23      <param name="input1" value="gops_bigint.interval" /> 
     24      <param name="input2" value="gops_bigint2.interval" /> 
     25      <output name="output" file="gops_coverage_out2.interval" /> 
    2126    </test> 
    2227  </tests> 
  • tools/new_operations/flanking_features.py

    r1281 r1323  
    1111import pkg_resources 
    1212pkg_resources.require( "bx-python" ) 
    13  
    14 import sys 
    15 import traceback 
    16 import fileinput 
     13import sys, traceback, fileinput 
    1714from warnings import warn 
    18  
    1915from bx.cookbook import doc_optparse 
    2016from galaxy.tools.util.galaxyops import * 
    21  
    2217from bx.intervals.io import * 
    2318from bx.intervals.operations import quicksect 
     19 
     20assert sys.version_info[:2] >= ( 2, 4 ) 
    2421 
    2522def get_closest_feature (node, direction, threshold_up, threshold_down, report_func_up, report_func_down): 
     
    122119                 
    123120def main(): 
    124      
    125121    options, args = doc_optparse.parse( __doc__ ) 
    126122    try: 
     
    131127        doc_optparse.exception() 
    132128 
    133     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    134                                                          chrom_col=chr_col_1, 
    135                                                          start_col=start_col_1, 
    136                                                          end_col=end_col_1, 
    137                                                          strand_col=strand_col_1, 
    138                                                          fix_strand=True ) 
    139                                      ) 
    140     g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
    141                                                          chrom_col=chr_col_2, 
    142                                                          start_col=start_col_2, 
    143                                                          end_col=end_col_2, 
    144                                                          strand_col=strand_col_2, 
    145                                                          fix_strand=True ) 
    146                                      ) 
     129    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     130                            chrom_col=chr_col_1, 
     131                            start_col=start_col_1, 
     132                            end_col=end_col_1, 
     133                            strand_col=strand_col_1, 
     134                            fix_strand=True ) 
     135    g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
     136                            chrom_col=chr_col_2, 
     137                            start_col=start_col_2, 
     138                            end_col=end_col_2, 
     139                            strand_col=strand_col_2, 
     140                            fix_strand=True ) 
    147141    out_file = open( out_fname, "w" ) 
    148  
    149142    try: 
    150143        for line in proximal_region_finder([g1,g2], direction): 
     
    154147                out_file.write( "%s\n" % line ) 
    155148    except ParseError, exc: 
    156         fail( "Invalid file format: ", str( exc ) ) 
     149        fail( "Invalid file format: %s" % str( exc ) ) 
    157150 
    158151    print "Direction: %s" %(direction) 
    159      
    160152    if g1.skipped > 0: 
    161153        print skipped( g1, filedesc=" of 1st dataset" ) 
    162  
    163154    if g2.skipped > 0: 
    164155        print skipped( g2, filedesc=" of 2nd dataset" ) 
    165156 
    166  
    167157if __name__ == "__main__": 
    168158    main() 
  • tools/new_operations/gops_basecoverage.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Count total base coverage. 
     
    76    -1, --cols1=N,N,N,N: Columns for start, end, strand in first file 
    87""" 
    9  
    108from galaxy import eggs 
    119import pkg_resources 
    1210pkg_resources.require( "bx-python" ) 
    1311 
    14 import sys 
    15 import traceback 
    16 import fileinput 
     12import sys, traceback, fileinput 
    1713from warnings import warn 
    18  
    1914from bx.intervals import * 
    2015from bx.intervals.io import * 
    2116from bx.intervals.operations.base_coverage import * 
    2217from bx.cookbook import doc_optparse 
    23  
    2418from galaxy.tools.util.galaxyops import * 
    2519 
     
    2721 
    2822def main(): 
    29  
    3023    upstream_pad = 0 
    3124    downstream_pad = 0 
     
    3831        doc_optparse.exception() 
    3932 
    40     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    41                                                          chrom_col=chr_col_1, 
    42                                                          start_col=start_col_1, 
    43                                                          end_col=end_col_1, 
    44                                                          fix_strand=True ) 
    45                                      ) 
     33    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     34                            chrom_col=chr_col_1, 
     35                            start_col=start_col_1, 
     36                            end_col=end_col_1, 
     37                            fix_strand=True ) 
    4638 
    4739    if strand_col_1 >= 0: 
    4840        g1.strand_col=strand_col_1 
    49  
    5041    try: 
    5142        bases = base_coverage(g1) 
    5243    except ParseError, exc: 
    53         fail( "Invalid file format: ", str( exc ) ) 
    54  
     44        fail( "Invalid file format: %s" % str( exc ) ) 
    5545    out_file = open( out_fname, "w" ) 
    5646    out_file.write( "%s\n" % str( bases ) ) 
    57  
     47    out_file.close() 
    5848    if g1.skipped > 0: 
    5949        print skipped( g1, filedesc="" ) 
  • tools/new_operations/gops_cluster.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Cluster regions of intervals. 
     
    1110    -o, --output=N: 1)merged 2)filtered 3)clustered 4) minimum 5) maximum 
    1211""" 
    13  
    1412from galaxy import eggs 
    1513import pkg_resources 
    1614pkg_resources.require( "bx-python" ) 
    17  
    18 import sys 
    19 import traceback 
    20 import fileinput 
     15import sys, traceback, fileinput 
    2116from warnings import warn 
    22  
    2317from bx.intervals import * 
    2418from bx.intervals.io import * 
    2519from bx.intervals.operations.find_clusters import * 
    2620from bx.cookbook import doc_optparse 
     21from galaxy.tools.util.galaxyops import * 
    2722 
    28 from galaxy.tools.util.galaxyops import * 
     23assert sys.version_info[:2] >= ( 2, 4 ) 
    2924 
    3025def main(): 
     
    4641        doc_optparse.exception() 
    4742 
    48     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    49                                                          chrom_col=chr_col_1, 
    50                                                          start_col=start_col_1, 
    51                                                          end_col=end_col_1, 
    52                                                          strand_col=strand_col_1, 
    53                                                          fix_strand=True ) 
    54                                      ) 
    55     out_file = open( out_fname, "w" ) 
     43    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     44                            chrom_col=chr_col_1, 
     45                            start_col=start_col_1, 
     46                            end_col=end_col_1, 
     47                            strand_col=strand_col_1, 
     48                            fix_strand=True ) 
    5649 
    5750    # Get the cluster tree 
     
    5952        clusters, extra = find_clusters( g1, mincols=distance, minregions=minregions) 
    6053    except ParseError, exc: 
    61         fail( "Invalid file format: ", str( exc ) ) 
     54        fail( "Invalid file format: %s" % str( exc ) ) 
    6255 
    6356    f1 = open( in_fname, "r" ) 
     57    out_file = open( out_fname, "w" ) 
    6458     
    6559    # If "merge" 
     
    130124 
    131125    f1.close() 
     126    out_file.close() 
    132127     
    133128    if g1.skipped > 0: 
  • tools/new_operations/gops_complement.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Complement regions. 
     
    98    -a, --all: Complement all chromosomes (Genome-wide complement) 
    109""" 
    11  
    1210from galaxy import eggs 
    1311import pkg_resources 
    1412pkg_resources.require( "bx-python" ) 
    15  
    16 import sys 
    17 import traceback 
    18 import fileinput 
     13import sys, traceback, fileinput 
    1914from warnings import warn 
    20  
    2115from bx.intervals import * 
    2216from bx.intervals.io import * 
     
    2418from bx.intervals.operations.subtract import subtract 
    2519from bx.cookbook import doc_optparse 
     20from galaxy.tools.util.galaxyops import * 
    2621 
    27 from galaxy.tools.util.galaxyops import * 
     22assert sys.version_info[:2] >= ( 2, 4 ) 
    2823 
    2924def main(): 
     
    4136        doc_optparse.exception() 
    4237 
    43     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    44                                                          chrom_col=chr_col_1, 
    45                                                          start_col=start_col_1, 
    46                                                          end_col=end_col_1, 
    47                                                          strand_col=strand_col_1, 
    48                                                          fix_strand=True ) 
    49                                      ) 
    50          
    51     out_file = open( out_fname, "w" ) 
     38    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     39                            chrom_col=chr_col_1, 
     40                            start_col=start_col_1, 
     41                            end_col=end_col_1, 
     42                            strand_col=strand_col_1, 
     43                            fix_strand=True ) 
     44 
    5245    lens = dict() 
    5346    chroms = list() 
     47    # dbfile is used to determine the length of each chromosome.  The lengths 
     48    # are added to the lens dict and passed copmlement operation code in bx. 
    5449    dbfile = fileinput.FileInput( "static/ucsc/chrom/"+db+".len" ) 
    5550     
     
    8378        generator = complement(g1, lens) 
    8479 
     80    out_file = open( out_fname, "w" ) 
     81 
    8582    try: 
    8683        for interval in generator: 
     
    9087                out_file.write( "%s\n" % interval ) 
    9188    except ParseError, exc: 
    92         fail( "Invalid file format: ", str( exc ) ) 
     89        out_file.close() 
     90        fail( "Invalid file format: %s" % str( exc ) ) 
     91 
     92    out_file.close() 
    9393 
    9494    if g1.skipped > 0: 
  • tools/new_operations/gops_concat.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Concatenate two bed files.  The concatenated files are returned in the 
     
    1413    -s, --sameformat: All files are precisely the same format. 
    1514""" 
    16  
    1715from galaxy import eggs 
    1816import pkg_resources 
    1917pkg_resources.require( "bx-python" ) 
    20  
    21 import sys 
    22 import traceback 
    23 import fileinput 
     18import sys, traceback, fileinput 
    2419from warnings import warn 
    25  
    2620from bx.intervals import * 
    2721from bx.intervals.io import * 
    2822from bx.intervals.operations.concat import * 
    2923from bx.cookbook import doc_optparse 
    30  
    3124from galaxy.tools.util.galaxyops import * 
    3225 
     26assert sys.version_info[:2] >= ( 2, 4 ) 
     27 
    3328def main(): 
    34  
    3529    sameformat=False 
    3630    upstream_pad = 0 
     
    4640        doc_optparse.exception() 
    4741 
    48     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_file_1 ), 
    49                                                          chrom_col=chr_col_1, 
    50                                                          start_col=start_col_1, 
    51                                                          end_col=end_col_1, 
    52                                                          fix_strand=True ) 
    53                                      ) 
     42    g1 = NiceReaderWrapper( fileinput.FileInput( in_file_1 ), 
     43                            chrom_col=chr_col_1, 
     44                            start_col=start_col_1, 
     45                            end_col=end_col_1, 
     46                            fix_strand=True ) 
     47 
     48    g2 = NiceReaderWrapper( fileinput.FileInput( in_file_2 ), 
     49                            chrom_col=chr_col_2, 
     50                            start_col=start_col_2, 
     51                            end_col=end_col_2, 
     52                            strand_col=strand_col_2, 
     53                            fix_strand=True ) 
     54 
    5455    if strand_col_1 >= 0: 
    55         g1.strand_col=strand_col_1 
    56          
    57     g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_file_2 ), 
    58                                                          chrom_col=chr_col_2, 
    59                                                          start_col=start_col_2, 
    60                                                          end_col=end_col_2, 
    61                                                          strand_col=strand_col_2, 
    62                                                          fix_strand=True ) 
    63                                      ) 
    64      
     56        g1.strand_col = strand_col_1 
     57 
    6558    out_file = open( out_fname, "w" ) 
    6659 
     
    7265                out_file.write( "%s\n" % line ) 
    7366    except ParseError, exc: 
    74         fail( "Invalid file format: ", str( exc ) ) 
    75          
     67        out_file.close() 
     68        fail( "Invalid file format: %s" % str( exc ) ) 
     69 
     70    out_file.close() 
     71 
    7672    if g1.skipped > 0: 
    7773        print skipped( g1, filedesc=" of 1st dataset" ) 
  • tools/new_operations/gops_coverage.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Calculate coverage of one query on another, and append the coverage to 
     
    98    -2, --cols2=N,N,N,N: Columns for start, end, strand in second file 
    109""" 
    11  
    1210from galaxy import eggs 
    1311import pkg_resources 
    1412pkg_resources.require( "bx-python" ) 
    15  
    16 import sys 
    17 import traceback 
    18 import fileinput 
     13import sys, traceback, fileinput 
    1914from warnings import warn 
    20  
    2115from bx.intervals import * 
    2216from bx.intervals.io import * 
    2317from bx.intervals.operations.coverage import * 
    2418from bx.cookbook import doc_optparse 
    25  
    2619from galaxy.tools.util.galaxyops import * 
    2720 
     21assert sys.version_info[:2] >= ( 2, 4 ) 
     22 
    2823def main(): 
    29  
    3024    upstream_pad = 0 
    3125    downstream_pad = 0 
     
    3933        doc_optparse.exception() 
    4034 
    41     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    42                                                          chrom_col=chr_col_1, 
    43                                                          start_col=start_col_1, 
    44                                                          end_col=end_col_1, 
    45                                                          strand_col=strand_col_1, 
    46                                                          fix_strand=True ) 
    47                                      ) 
    48     g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
    49                                                          chrom_col=chr_col_2, 
    50                                                          start_col=start_col_2, 
    51                                                          end_col=end_col_2, 
    52                                                          strand_col=strand_col_2, 
    53                                                          fix_strand=True ) 
    54                                      ) 
     35    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     36                            chrom_col=chr_col_1, 
     37                            start_col=start_col_1, 
     38                            end_col=end_col_1, 
     39                            strand_col=strand_col_1, 
     40                            fix_strand=True ) 
     41    g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
     42                            chrom_col=chr_col_2, 
     43                            start_col=start_col_2, 
     44                            end_col=end_col_2, 
     45                            strand_col=strand_col_2, 
     46                            fix_strand=True ) 
     47 
    5548    out_file = open( out_fname, "w" ) 
    5649 
     
    6255                out_file.write( "%s\n" % line ) 
    6356    except ParseError, exc: 
    64         fail( "Invalid file format: ", str( exc ) ) 
     57        out_file.close() 
     58        fail( "Invalid file format: %s" % str( exc ) ) 
     59 
     60    out_file.close() 
    6561 
    6662    if g1.skipped > 0: 
  • tools/new_operations/gops_intersect.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Find regions of first bed file that overlap regions in a second bed file 
     
    109    -p, --pieces: just print pieces of second set (after padding) 
    1110""" 
    12  
    1311from galaxy import eggs 
    1412import pkg_resources 
    1513pkg_resources.require( "bx-python" ) 
    16  
    17 import sys 
    18 import traceback 
    19 import fileinput 
     14import sys, traceback, fileinput 
    2015from warnings import warn 
    21  
    2216from bx.intervals import * 
    2317from bx.intervals.io import * 
    2418from bx.intervals.operations.intersect import * 
    2519from bx.cookbook import doc_optparse 
    26  
    2720from galaxy.tools.util.galaxyops import * 
    2821 
     22assert sys.version_info[:2] >= ( 2, 4 ) 
     23 
    2924def main(): 
    30  
    3125    mincols = 1 
    3226    upstream_pad = 0 
     
    4337        doc_optparse.exception() 
    4438     
    45     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    46                                                          chrom_col=chr_col_1, 
    47                                                          start_col=start_col_1, 
    48                                                          end_col=end_col_1, 
    49                                                          strand_col=strand_col_1, 
    50                                                          fix_strand=True ) 
    51                                      ) 
    52     g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
    53                                                          chrom_col=chr_col_2, 
    54                                                          start_col=start_col_2, 
    55                                                          end_col=end_col_2, 
    56                                                          strand_col=strand_col_2, 
    57                                                          fix_strand=True ) 
    58                                      ) 
     39    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     40                            chrom_col=chr_col_1, 
     41                            start_col=start_col_1, 
     42                            end_col=end_col_1, 
     43                            strand_col=strand_col_1, 
     44                            fix_strand=True ) 
     45    g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
     46                            chrom_col=chr_col_2, 
     47                            start_col=start_col_2, 
     48                            end_col=end_col_2, 
     49                            strand_col=strand_col_2, 
     50                            fix_strand=True ) 
    5951 
    6052    out_file = open( out_fname, "w" ) 
     
    6759                out_file.write( "%s\n" % line ) 
    6860    except ParseError, e: 
     61        out_file.close() 
    6962        fail( "Invalid file format: %s" % str( e ) ) 
    7063 
     64    out_file.close() 
     65 
    7166    if g1.skipped > 0: 
    72         print skipped( g1, filedesc=" of 1st dataset." ) 
     67        print skipped( g1, filedesc=" of 1st dataset" ) 
    7368    if g2.skipped > 0: 
    74         print skipped( g2, filedesc=" of 2nd dataset." ) 
     69        print skipped( g2, filedesc=" of 2nd dataset" ) 
    7570 
    7671if __name__ == "__main__": 
  • tools/new_operations/gops_join.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Join two sets of intervals using their overlap as the key. 
     
    109    -f, --fill=N: none, right, left, both 
    1110""" 
    12  
    1311from galaxy import eggs 
    1412import pkg_resources 
    1513pkg_resources.require( "bx-python" ) 
    16  
    17 import traceback 
    18 import fileinput 
     14import sys, traceback, fileinput 
    1915from warnings import warn 
    20  
    2116from bx.intervals import * 
    2217from bx.intervals.io import * 
    2318from bx.intervals.operations.join import * 
    2419from bx.cookbook import doc_optparse 
    25  
    2620from galaxy.tools.util.galaxyops import * 
    2721 
     22assert sys.version_info[:2] >= ( 2, 4 ) 
     23 
    2824def main(): 
    29  
    3025    mincols = 1 
    3126    upstream_pad = 0 
     
    4944        doc_optparse.exception() 
    5045 
    51     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    52                                                          chrom_col=chr_col_1, 
    53                                                          start_col=start_col_1, 
    54                                                          end_col=end_col_1, 
    55                                                          strand_col=strand_col_1, 
    56                                                          fix_strand=True ) 
    57                                      ) 
    58     g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
    59                                                          chrom_col=chr_col_2, 
    60                                                          start_col=start_col_2, 
    61                                                          end_col=end_col_2, 
    62                                                          strand_col=strand_col_2, 
    63                                                          fix_strand=True ) 
    64                                      ) 
     46    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     47                            chrom_col=chr_col_1, 
     48                            start_col=start_col_1, 
     49                            end_col=end_col_1, 
     50                            strand_col=strand_col_1, 
     51                            fix_strand=True ) 
     52    g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ), 
     53                            chrom_col=chr_col_2, 
     54                            start_col=start_col_2, 
     55                            end_col=end_col_2, 
     56                            strand_col=strand_col_2, 
     57                            fix_strand=True ) 
    6558 
    6659    out_file = open( out_fname, "w" ) 
     
    7366                out_file.write( "%s\n" % outfields ) 
    7467    except ParseError, exc: 
    75         fail( "Invalid file format: ", str( exc ) ) 
     68        out_file.close() 
     69        fail( "Invalid file format: %s" % str( exc ) ) 
    7670    except MemoryError: 
     71        out_file.close() 
    7772        fail( "Input datasets were too large to complete the join operation." ) 
     73 
     74    out_file.close() 
    7875 
    7976    if g1.skipped > 0: 
  • tools/new_operations/gops_merge.py

    r1281 r1323  
    11#!/usr/bin/env python 
    2  
    32""" 
    43Merge overlaping regions. 
     
    98    -3, --threecol: Output 3 column bed 
    109""" 
    11  
    1210from galaxy import eggs 
    1311import pkg_resources 
    1412pkg_resources.require( "bx-python" ) 
    15  
    16 import sys 
    17 import traceback 
    18 import fileinput 
     13import sys, traceback, fileinput 
    1914from warnings import warn 
    20  
    2115from bx.intervals import * 
    2216from bx.intervals.io import * 
    2317from bx.intervals.operations.merge import * 
    2418from bx.cookbook import doc_optparse 
    25  
    2619from galaxy.tools.util.galaxyops import * 
    2720 
     21assert sys.version_info[:2] >= ( 2, 4 ) 
     22 
    2823def main(): 
    29  
    3024    mincols = 1 
    3125    upstream_pad = 0 
     
    4034        doc_optparse.exception() 
    4135 
    42     g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ), 
    43                                                          chrom_col=chr_col_1, 
    44                                                          start_col=start_col_1, 
    45                                                          end_col=end_col_1, 
    46                                                          strand_col = strand_col_1, 
    47                                                          fix_strand=True ) 
    48                                      ) 
     36    g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), 
     37                            chrom_col=chr_col_1, 
     38                            start_col=start_col_1, 
     39                            end_col=end_col_1, 
     40                            strand_col = strand_col_1, 
     41                            fix_strand=True ) 
    4942 
    5043    out_file = open( out_fname, "w" ) 
     
    6760                    out_file.write( "%s\n" % line ) 
    6861    except ParseError, exc: 
    69         fail( "Invalid file format: ", str( exc ) ) 
     62        out_file.close() 
     63        fail( "Invalid file format: %s" % str( exc ) ) 
     64 
     65    out_file.close() <