root/galaxy-central/tools/maf/maf_split_by_species.py

リビジョン 2, 1.4 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Read a maf and split blocks by unique species combinations
5"""
6import sys
7from galaxy import eggs
8import pkg_resources; pkg_resources.require( "bx-python" )
9from bx.align import maf
10from galaxy.tools.util import maf_utilities
11from galaxy.util import string_as_bool
12
13assert sys.version_info[:2] >= ( 2, 4 )
14
15def __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
44if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。