Mercurial > repos > xuebing > sharplabtool
comparison tools/maf/maf_reverse_complement.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 | |
| 3 """ | |
| 4 Reads a MAF file. Produces a MAF file containing | |
| 5 the reverse complement for each block in the source file. | |
| 6 | |
| 7 usage: %prog input_maf_file output_maf_file | |
| 8 """ | |
| 9 #Dan Blankenberg | |
| 10 from galaxy import eggs | |
| 11 import pkg_resources; pkg_resources.require( "bx-python" ) | |
| 12 import bx.align.maf | |
| 13 from galaxy.tools.util import maf_utilities | |
| 14 import sys | |
| 15 | |
| 16 assert sys.version_info[:2] >= ( 2, 4 ) | |
| 17 | |
| 18 def __main__(): | |
| 19 #Parse Command Line | |
| 20 input_file = sys.argv.pop( 1 ) | |
| 21 output_file = sys.argv.pop( 1 ) | |
| 22 species = maf_utilities.parse_species_option( sys.argv.pop( 1 ) ) | |
| 23 | |
| 24 try: | |
| 25 maf_writer = bx.align.maf.Writer( open( output_file, 'w' ) ) | |
| 26 except: | |
| 27 print sys.stderr, "Unable to open output file" | |
| 28 sys.exit() | |
| 29 try: | |
| 30 count = 0 | |
| 31 for count, maf in enumerate( bx.align.maf.Reader( open( input_file ) ) ): | |
| 32 maf = maf.reverse_complement() | |
| 33 if species: | |
| 34 maf = maf.limit_to_species( species ) | |
| 35 maf_writer.write( maf ) | |
| 36 except: | |
| 37 print >>sys.stderr, "Your MAF file appears to be malformed." | |
| 38 sys.exit() | |
| 39 print "%i regions were reverse complemented." % count | |
| 40 maf_writer.close() | |
| 41 | |
| 42 if __name__ == "__main__": __main__() |
