[2] | 1 | #!/usr/bin/env python
|
---|
| 2 | #Dan Blankenberg
|
---|
| 3 |
|
---|
| 4 | import sys
|
---|
| 5 | from galaxy import eggs
|
---|
| 6 | import pkg_resources; pkg_resources.require( "bx-python" )
|
---|
| 7 | import bx.align.maf |
---|
| 8 | from galaxy.tools.util import maf_utilities
|
---|
| 9 |
|
---|
| 10 | assert sys.version_info[:2] >= ( 2, 4 )
|
---|
| 11 |
|
---|
| 12 | def __main__():
|
---|
| 13 | output_name = sys.argv.pop(1)
|
---|
| 14 | input_name = sys.argv.pop(1)
|
---|
| 15 | species = sys.argv.pop(1)
|
---|
| 16 | out = open(output_name,'w')
|
---|
| 17 | count = 0
|
---|
| 18 | #write interval header line
|
---|
| 19 | out.write( "#chrom\tstart\tend\tstrand\n" )
|
---|
| 20 | try:
|
---|
| 21 | for block in bx.align.maf.Reader( open( input_name, 'r' ) ):
|
---|
| 22 | for c in maf_utilities.iter_components_by_src_start( block, species ):
|
---|
| 23 | if c is not None:
|
---|
| 24 | out.write( "%s\t%i\t%i\t%s\n" % ( maf_utilities.src_split( c.src )[-1], c.get_forward_strand_start(), c.get_forward_strand_end(), c.strand ) )
|
---|
| 25 | count += 1
|
---|
| 26 | except Exception, e:
|
---|
| 27 | print >> sys.stderr, "There was a problem processing your input: %s" % e
|
---|
| 28 | out.close()
|
---|
| 29 | print "%i MAF blocks converted to Genomic Intervals for species %s." % ( count, species )
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | if __name__ == "__main__": __main__()
|
---|