PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/datatypes/converters/maf_to_interval_converter.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 32 lines | 24 code | 5 blank | 3 comment | 7 complexity | b821d7a9d47e7cc1994fe83309e101ee MD5 | raw file
 1#!/usr/bin/env python
 2#Dan Blankenberg
 3
 4import sys
 5from galaxy import eggs
 6import pkg_resources; pkg_resources.require( "bx-python" )
 7import bx.align.maf
 8from galaxy.tools.util import maf_utilities
 9
10assert sys.version_info[:2] >= ( 2, 4 )
11
12def __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
32if __name__ == "__main__": __main__()