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

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

import galaxy-central

行番号 
1#!/usr/bin/env python
2#Dan Blankenberg
3"""
4Removes blocks that fall outside of specified size range.
5"""
6
7import sys
8from galaxy import eggs
9import pkg_resources; pkg_resources.require( "bx-python" )
10import bx.align.maf
11
12assert sys.version_info[:2] >= ( 2, 4 )
13
14def __main__():
15
16    input_maf_filename = sys.argv[1].strip()
17    output_filename1 = sys.argv[2].strip()
18    min_size = int( sys.argv[3].strip() )
19    max_size = int( sys.argv[4].strip() )
20    if max_size < 1: max_size = sys.maxint
21    maf_writer = bx.align.maf.Writer( open( output_filename1, 'w' ) )
22    try:
23        maf_reader = bx.align.maf.Reader( open( input_maf_filename, 'r' ) )
24    except:
25        print >>sys.stderr, "Your MAF file appears to be malformed."
26        sys.exit()
27   
28    blocks_kept = 0
29    i = 0
30    for i, m in enumerate( maf_reader ):
31        if min_size <= m.text_size <= max_size:
32            maf_writer.write( m )
33            blocks_kept += 1
34    print 'Kept %s of %s blocks (%.2f%%).' % ( blocks_kept, i + 1, float( blocks_kept ) / float( i + 1 ) * 100.0 )
35
36if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。