Files
galaxy/tools/maf/maf_split_by_species.py
T
Daniel Blankenberg 87eebd3206 First pass at allowing MAF tools to deal with multiple occurrences of a species within a block. Tool versions have been incremented as necessary.
These changes should only affect output when an input block has a species appearing more than once, with the exception being the MAF to multiple FASTA blocks converters: the FASTA headers have been revised to included the sequence index for a species in a block as well as the block index.

A new tool "Split MAF Blocks by Species" has been added that will split MAF blocks into the complete combination of multiple blocks when a species appears more than once.
2009-09-04 10:40:16 -04:00

45 lines
1.4 KiB
Python

#!/usr/bin/env python
"""
Read a maf and split blocks by unique species combinations
"""
import sys
from galaxy import eggs
import pkg_resources; pkg_resources.require( "bx-python" )
from bx.align import maf
from galaxy.tools.util import maf_utilities
from galaxy.util import string_as_bool
assert sys.version_info[:2] >= ( 2, 4 )
def __main__():
try:
maf_reader = maf.Reader( open( sys.argv[1] ) )
except Exception, e:
maf_utilities.tool_fail( "Error opening MAF: %s" % e )
try:
out = maf.Writer( open( sys.argv[2], "w") )
except Exception, e:
maf_utilities.tool_fail( "Error opening file for output: %s" % e )
try:
collapse_columns = string_as_bool( sys.argv[3] )
except Exception, e:
maf_utilities.tool_fail( "Error determining collapse columns value: %s" % e )
start_count = 0
end_count = 0
for start_count, start_block in enumerate( maf_reader ):
for block in maf_utilities.iter_blocks_split_by_species( start_block ):
if collapse_columns:
block.remove_all_gap_columns()
out.write( block )
end_count += 1
out.close()
if end_count:
print "%i alignment blocks created from %i original blocks." % ( end_count, start_count + 1 )
else:
print "No alignment blocks were created."
if __name__ == "__main__": __main__()