Mercurial > repos > xuebing > sharplabtool
comparison tools/maf/maf_limit_size.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 #Dan Blankenberg | |
3 """ | |
4 Removes blocks that fall outside of specified size range. | |
5 """ | |
6 | |
7 import sys | |
8 from galaxy import eggs | |
9 import pkg_resources; pkg_resources.require( "bx-python" ) | |
10 import bx.align.maf | |
11 | |
12 assert sys.version_info[:2] >= ( 2, 4 ) | |
13 | |
14 def __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 | |
36 if __name__ == "__main__": __main__() |