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

This commit is contained in:
Greg Von Kuster
2008-05-23 20:43:20 +00:00
parent 6859f36c8c
commit fab2f2dcca
19 changed files with 239 additions and 306 deletions
+2 -2
View File
@@ -53,13 +53,13 @@ pbs_python = _2.1.8
MySQL_python = _5.0.51a_static
python_lzo = _static
flup = .dev_r2311
bx_python = _dev_r418
bx_python = _dev_r427
nose = .dev_r101
DRMAA_python = _6.1u4
; source location, necessary for scrambling
[source]
bx_python = http://dist.g2.bx.psu.edu/bx-python_dist-r414.tar.bz2
bx_python = http://dist.g2.bx.psu.edu/bx-python_dist-r427.tar.bz2
Cheetah = http://umn.dl.sourceforge.net/sourceforge/cheetahtemplate/Cheetah-1.0.tar.gz
DRMAA_python = http://gridengine.sunsource.net/files/documents/7/36/DRMAA-python-0.2.tar.gz
MySQL_python = http://superb-west.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz http://mysql.mirrors.pair.com/Downloads/MySQL-5.0/mysql-5.0.51a.tar.gz
+3 -48
View File
@@ -1,52 +1,8 @@
"""
Utility functions for galaxyops
"""
"""Utility functions for galaxyops"""
import sys
from bx.bitset import *
from bx.intervals.io import *
class BitsetSafeNiceReaderWrapper:
"""Handles exceptions thrown in bx."""
def __init__( self, iterat ):
self.iterat = iterat
self.MAXINT = 2147483647 # max signed int value for 32-bit
def __iter__( self ):
while True:
region = self.iterat.next()
# NiceReaderWrapper can return a header, comment or GenomicInterval
if type( region ) == GenomicInterval:
if ( region.start > self.MAXINT ) or ( region.end > self.MAXINT ) or ( region.start > region.end ):
self.iterat.skipped += 1
if self.iterat.skipped < 10:
self.iterat.skipped_lines.append( ( self.iterat.linenum, self.iterat.current_line ) )
else:
yield region
def __getattr__( self, name ):
return getattr( self.iterat, name )
def binned_bitsets( self , upstream_pad=0, downstream_pad=0, lens={} ):
# This is duplicated in bx.intervals.io, but we need it here so that self refers to
# our BitsetSafeNiceReaderWrapper rather than bx.intervals.io's GenomicIntervalReader
last_chrom = None
last_bitset = None
bitsets = dict()
for interval in self:
if type( interval ) == GenomicInterval:
chrom = interval[self.chrom_col]
if chrom != last_chrom:
if chrom not in bitsets:
if chrom in lens:
size = lens[chrom]
else:
size = MAX
bitsets[chrom] = BinnedBitSet( size )
last_chrom = chrom
last_bitset = bitsets[chrom]
start = max(int( interval[self.start_col]), 0 )
end = min(int( interval[self.end_col]), size)
last_bitset.set_range( start, end-start )
return bitsets
def warn( msg ):
# TODO: since everything printed to stderr results in job.state = error, we
# don't need both a warn and a fail...
@@ -72,6 +28,5 @@ def default_printer( stream, exc, obj ):
print >> stream, "\tError: %s" % ( str(exc) )
def skipped( reader, filedesc="" ):
first_line, line_contents = reader.skipped_lines[0]
return 'Skipped %d invalid lines%s starting at line #%d: "%s"' \
% ( reader.skipped, filedesc, first_line, line_contents )
first_line, line_contents, problem = reader.skipped_lines[0]
return 'Skipped %d invalid lines%s, 1st line #%d: "%s", problem: %s' % ( reader.skipped, filedesc, first_line, line_contents, problem )
+5 -1
View File
@@ -13,7 +13,11 @@
<tests>
<test>
<param name="input1" value="1.bed" />
<output name="output" file="gops-basecoverage.dat" />
<output name="output" file="gops_basecoverage_out.txt" />
</test>
<test>
<param name="input1" value="gops_bigint.interval" />
<output name="output" file="gops_basecoverage_out2.txt" />
</test>
</tests>
<help>
+8 -1
View File
@@ -32,7 +32,14 @@
<param name="minregions" value="2" />
<param name="returntype" value="1" />
<output name="output" file="gops-cluster-1.bed" />
</test>
</test>
<test>
<param name="input1" value="gops_cluster_bigint.bed" />
<param name="distance" value="1" />
<param name="minregions" value="2" />
<param name="returntype" value="1" />
<output name="output" file="gops-cluster-1.bed" />
</test>
<test>
<param name="input1" value="5.bed" />
<param name="distance" value="1" />
+6 -1
View File
@@ -16,7 +16,12 @@
<test>
<param name="input1" value="1.bed" />
<param name="allchroms" value="true" />
<output name="output" file="gops-complement.dat" />
<output name="output" file="gops_complement_out.bed" />
</test>
<test>
<param name="input1" value="gops_bigint.interval" />
<param name="allchroms" value="true" />
<output name="output" file="gops_complement_out2.bed" />
</test>
</tests>
<help>
+6 -1
View File
@@ -17,7 +17,12 @@
<test>
<param name="input1" value="1.bed" />
<param name="input2" value="2.bed" />
<output name="output" file="gops-coverage.dat" />
<output name="output" file="gops_coverage_out.interval" />
</test>
<test>
<param name="input1" value="gops_bigint.interval" />
<param name="input2" value="gops_bigint2.interval" />
<output name="output" file="gops_coverage_out2.interval" />
</test>
</tests>
<help>
+16 -26
View File
@@ -10,18 +10,15 @@ usage: %prog primary_file features_file out_file direction
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
from bx.intervals.io import *
from bx.intervals.operations import quicksect
assert sys.version_info[:2] >= ( 2, 4 )
def get_closest_feature (node, direction, threshold_up, threshold_down, report_func_up, report_func_down):
#direction=1 for +ve strand upstream and -ve strand downstream cases; and it is 0 for +ve strand downstream and -ve strand upstream cases
#threhold_Up is equal to the interval start for +ve strand, and interval end for -ve strand
@@ -121,7 +118,6 @@ def proximal_region_finder(readers, region, comments=True):
yield outfields
def main():
options, args = doc_optparse.parse( __doc__ )
try:
chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
@@ -130,22 +126,19 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
try:
for line in proximal_region_finder([g1,g2], direction):
if type( line ) is list:
@@ -153,16 +146,13 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
fail( "Invalid file format: %s" % str( exc ) )
print "Direction: %s" %(direction)
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
if g2.skipped > 0:
print skipped( g2, filedesc=" of 2nd dataset" )
if __name__ == "__main__":
main()
+8 -18
View File
@@ -1,32 +1,25 @@
#!/usr/bin/env python
"""
Count total base coverage.
usage: %prog in_file out_file
-1, --cols1=N,N,N,N: Columns for start, end, strand in first file
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.base_coverage import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
assert sys.version_info[:2] >= ( 2, 4 )
def main():
upstream_pad = 0
downstream_pad = 0
@@ -37,24 +30,21 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
fix_strand=True )
if strand_col_1 >= 0:
g1.strand_col=strand_col_1
try:
bases = base_coverage(g1)
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
fail( "Invalid file format: %s" % str( exc ) )
out_file = open( out_fname, "w" )
out_file.write( "%s\n" % str( bases ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc="" )
+12 -17
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Cluster regions of intervals.
@@ -10,23 +9,19 @@ usage: %prog in_file out_file
-m, --minregions=N: Minimum regions per cluster
-o, --output=N: 1)merged 2)filtered 3)clustered 4) minimum 5) maximum
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.find_clusters import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
assert sys.version_info[:2] >= ( 2, 4 )
def main():
distance = 0
minregions = 2
@@ -45,22 +40,21 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
out_file = open( out_fname, "w" )
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
# Get the cluster tree
try:
clusters, extra = find_clusters( g1, mincols=distance, minregions=minregions)
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
fail( "Invalid file format: %s" % str( exc ) )
f1 = open( in_fname, "r" )
out_file = open( out_fname, "w" )
# If "merge"
if output == 1:
@@ -129,6 +123,7 @@ def main():
out_file.write( "%s\n" % outinterval )
f1.close()
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc="" )
+18 -18
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Complement regions.
@@ -8,24 +7,20 @@ usage: %prog in_file out_file
-d, --db=N: Database name (for determining chromosome lengths)
-a, --all: Complement all chromosomes (Genome-wide complement)
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.complement import complement
from bx.intervals.operations.subtract import subtract
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
assert sys.version_info[:2] >= ( 2, 4 )
def main():
allchroms = False
upstream_pad = 0
@@ -40,17 +35,17 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
out_file = open( out_fname, "w" )
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
lens = dict()
chroms = list()
# dbfile is used to determine the length of each chromosome. The lengths
# are added to the lens dict and passed copmlement operation code in bx.
dbfile = fileinput.FileInput( "static/ucsc/chrom/"+db+".len" )
if dbfile:
@@ -82,6 +77,8 @@ def main():
else:
generator = complement(g1, lens)
out_file = open( out_fname, "w" )
try:
for interval in generator:
if type( interval ) is GenomicInterval:
@@ -89,7 +86,10 @@ def main():
else:
out_file.write( "%s\n" % interval )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc="" )
+23 -27
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Concatenate two bed files. The concatenated files are returned in the
same format as the first. If --sameformat is specified, then all
@@ -13,25 +12,20 @@ usage: %prog in_file_1 in_file_2 out_file
-2, --cols2=N,N,N,N: Columns for chrom, start, end, strand in second file
-s, --sameformat: All files are precisely the same format.
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.concat import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
sameformat=False
upstream_pad = 0
downstream_pad = 0
@@ -45,23 +39,22 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_file_1 ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_file_1 ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in_file_2 ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
if strand_col_1 >= 0:
g1.strand_col=strand_col_1
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_file_2 ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1.strand_col = strand_col_1
out_file = open( out_fname, "w" )
try:
@@ -71,8 +64,11 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
if g2.skipped > 0:
+20 -24
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Calculate coverage of one query on another, and append the coverage to
the last two columns as bases covered and percent coverage.
@@ -8,25 +7,20 @@ usage: %prog bed_file_1 bed_file_2 out_file
-1, --cols1=N,N,N,N: Columns for start, end, strand in first file
-2, --cols2=N,N,N,N: Columns for start, end, strand in second file
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.coverage import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
upstream_pad = 0
downstream_pad = 0
@@ -38,20 +32,19 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
try:
@@ -61,7 +54,10 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
+20 -25
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Find regions of first bed file that overlap regions in a second bed file
@@ -9,25 +8,20 @@ usage: %prog bed_file_1 bed_file_2 out_file
-m, --mincols=N: Require this much overlap (default 1bp)
-p, --pieces: just print pieces of second set (after padding)
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.intersect import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
mincols = 1
upstream_pad = 0
downstream_pad = 0
@@ -42,20 +36,18 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
@@ -66,12 +58,15 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, e:
out_file.close()
fail( "Invalid file format: %s" % str( e ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset." )
print skipped( g1, filedesc=" of 1st dataset" )
if g2.skipped > 0:
print skipped( g2, filedesc=" of 2nd dataset." )
print skipped( g2, filedesc=" of 2nd dataset" )
if __name__ == "__main__":
main()
+20 -23
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Join two sets of intervals using their overlap as the key.
@@ -9,24 +8,20 @@ usage: %prog bed_file_1 bed_file_2 out_file
-m, --mincols=N: Require this much overlap (default 1bp)
-f, --fill=N: none, right, left, both
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.join import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
mincols = 1
upstream_pad = 0
downstream_pad = 0
@@ -48,20 +43,18 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
@@ -72,10 +65,14 @@ def main():
else:
out_file.write( "%s\n" % outfields )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
except MemoryError:
out_file.close()
fail( "Input datasets were too large to complete the join operation." )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
if g2.skipped > 0:
+13 -17
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Merge overlaping regions.
@@ -8,25 +7,20 @@ usage: %prog in_file out_file
-m, --mincols=N: Require this much overlap (default 1bp)
-3, --threecol: Output 3 column bed
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.merge import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
mincols = 1
upstream_pad = 0
downstream_pad = 0
@@ -39,13 +33,12 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col = strand_col_1,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col = strand_col_1,
fix_strand=True )
out_file = open( out_fname, "w" )
@@ -66,7 +59,10 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
+20 -24
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env python
"""
Find regions of first bed file that do not overlap regions in a second
bed file
@@ -10,25 +9,20 @@ usage: %prog bed_file_1 bed_file_2 out_file
-m, --mincols=N: Require this much overlap (default 1bp)
-p, --pieces: just print pieces of second set (after padding)
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals import *
from bx.intervals.io import *
from bx.intervals.operations.subtract import *
from bx.cookbook import doc_optparse
from galaxy.tools.util.galaxyops import *
def main():
assert sys.version_info[:2] >= ( 2, 4 )
def main():
mincols = 1
upstream_pad = 0
downstream_pad = 0
@@ -43,20 +37,19 @@ def main():
except:
doc_optparse.exception()
g1 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
)
g2 = BitsetSafeNiceReaderWrapper( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
)
g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
try:
@@ -66,7 +59,10 @@ def main():
else:
out_file.write( "%s\n" % line )
except ParseError, exc:
fail( "Invalid file format: ", str( exc ) )
out_file.close()
fail( "Invalid file format: %s" % str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 2nd dataset" )
+5
View File
@@ -21,6 +21,11 @@
<output name="output" file="gops-merge.dat" />
<param name="returntype" value="true" />
</test>
<test>
<param name="input1" value="gops_bigint.interval" />
<output name="output" file="gops_merge_out2.bed" />
<param name="returntype" value="true" />
</test>
</tests>
<help>
+7
View File
@@ -32,6 +32,13 @@
<param name="returntype" value="" />
<output name="output" file="gops-subtract.dat" />
</test>
<test>
<param name="input1" value="gops_subtract_bigint.bed" />
<param name="input2" value="2.bed" />
<param name="min" value="1" />
<param name="returntype" value="" />
<output name="output" file="gops-subtract.dat" />
</test>
<test>
<param name="input1" value="1.bed" />
<param name="input2" value="2.bed" />
+27 -33
View File
@@ -8,22 +8,18 @@ usage: %prog bed_file_1 bed_file_2 out_file
-1, --cols1=N,N,N,N: Columns for chr, start, end, strand in first file
-2, --cols2=N,N,N,N: Columns for chr, start, end, strand in second file
"""
from galaxy import eggs
import pkg_resources
pkg_resources.require( "bx-python" )
import sys
import traceback
import fileinput
import sys, traceback, fileinput
from warnings import warn
from bx.intervals.io import *
from bx.cookbook import doc_optparse
from bx.intervals.operations import quicksect
from galaxy.tools.util.galaxyops import *
assert sys.version_info[:2] >= ( 2, 4 )
def stop_err(msg):
sys.stderr.write(msg)
sys.exit()
@@ -99,7 +95,6 @@ def count_coverage(readers):
yield interval
def main():
options, args = doc_optparse.parse( __doc__ )
try:
@@ -108,32 +103,29 @@ def main():
in1_fname, in2_fname, out_fname = args
except:
stop_err( "Data issue: click the pencil icon in the history item to correct the metadata attributes." )
try:
out_file = open( out_fname, "w" )
except:
stop_err( "Unable to open output file." )
g1 = NiceReaderWrapper( fileinput.FileInput( in1_fname ),
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True)
chrom_col=chr_col_1,
start_col=start_col_1,
end_col=end_col_1,
strand_col=strand_col_1,
fix_strand=True )
g2 = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True)
g2_copy = BitsetSafeNiceReaderWrapper ( NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True) )
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
g2_copy = NiceReaderWrapper( fileinput.FileInput( in2_fname ),
chrom_col=chr_col_2,
start_col=start_col_2,
end_col=end_col_2,
strand_col=strand_col_2,
fix_strand=True )
out_file = open( out_fname, "w" )
try:
for line in count_coverage([g1,g2,g2_copy]):
if type( line ) is GenomicInterval:
@@ -141,11 +133,13 @@ def main():
else:
print >> out_file, line
except ParseError, exc:
print >> sys.stderr, "Invalid file format: ", str( exc )
out_file.close()
fail( str( exc ) )
out_file.close()
if g1.skipped > 0:
print skipped( g1, filedesc=" of 1st dataset" )
if g2.skipped > 0:
print skipped( g2, filedesc=" of 2nd dataset" )
elif g2_copy.skipped > 0: