root/galaxy-central/tools/maf/maf_limit_to_species.py @ 3

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

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Read a maf file and write out a new maf with only blocks having the
5required species, after dropping any other species and removing
6columns containing only gaps.
7
8usage: %prog species,species2,... input_maf output_maf allow_partial min_species_per_block
9"""
10#Dan Blankenberg
11from galaxy import eggs
12import pkg_resources; pkg_resources.require( "bx-python" )
13import bx.align.maf
14from galaxy.tools.util import maf_utilities
15import sys
16
17assert sys.version_info[:2] >= ( 2, 4 )
18
19def main():
20
21    species = maf_utilities.parse_species_option( sys.argv[1] )
22    if species:
23        spec_len = len( species )
24    else:
25        spec_len = 0
26    try:
27        maf_reader = bx.align.maf.Reader( open( sys.argv[2],'r' ) )
28        maf_writer = bx.align.maf.Writer( open( sys.argv[3],'w' ) )
29    except:
30        print >>sys.stderr, "Your MAF file appears to be malformed."
31        sys.exit()
32    allow_partial = False
33    if int( sys.argv[4] ): allow_partial = True
34    min_species_per_block = int( sys.argv[5] )
35   
36    maf_blocks_kept = 0
37    for m in maf_reader:
38        if species:
39            m = m.limit_to_species( species )
40        m.remove_all_gap_columns()
41        spec_in_block_len = len( maf_utilities.get_species_in_block( m ) )
42        if ( not species or allow_partial or spec_in_block_len == spec_len ) and spec_in_block_len > min_species_per_block:
43            maf_writer.write( m )
44            maf_blocks_kept += 1
45   
46    maf_reader.close()
47    maf_writer.close()
48   
49    print "Restricted to species: %s." % ", ".join( species )
50    print "%i MAF blocks have been kept." % maf_blocks_kept
51
52if __name__ == "__main__":
53    main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。