comparison tools/maf/maf_split_by_species.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9071e359b9a3
1 #!/usr/bin/env python
2
3 """
4 Read a maf and split blocks by unique species combinations
5 """
6 import sys
7 from galaxy import eggs
8 import pkg_resources; pkg_resources.require( "bx-python" )
9 from bx.align import maf
10 from galaxy.tools.util import maf_utilities
11 from galaxy.util import string_as_bool
12
13 assert sys.version_info[:2] >= ( 2, 4 )
14
15 def __main__():
16 try:
17 maf_reader = maf.Reader( open( sys.argv[1] ) )
18 except Exception, e:
19 maf_utilities.tool_fail( "Error opening MAF: %s" % e )
20 try:
21 out = maf.Writer( open( sys.argv[2], "w") )
22 except Exception, e:
23 maf_utilities.tool_fail( "Error opening file for output: %s" % e )
24 try:
25 collapse_columns = string_as_bool( sys.argv[3] )
26 except Exception, e:
27 maf_utilities.tool_fail( "Error determining collapse columns value: %s" % e )
28
29 start_count = 0
30 end_count = 0
31 for start_count, start_block in enumerate( maf_reader ):
32 for block in maf_utilities.iter_blocks_split_by_species( start_block ):
33 if collapse_columns:
34 block.remove_all_gap_columns()
35 out.write( block )
36 end_count += 1
37 out.close()
38
39 if end_count:
40 print "%i alignment blocks created from %i original blocks." % ( end_count, start_count + 1 )
41 else:
42 print "No alignment blocks were created."
43
44 if __name__ == "__main__": __main__()