annotate tools/maf/maf_reverse_complement.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 Reads a MAF file. Produces a MAF file containing
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 the reverse complement for each block in the source file.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 usage: %prog input_maf_file output_maf_file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 #Dan Blankenberg
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 from galaxy import eggs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 import pkg_resources; pkg_resources.require( "bx-python" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 import bx.align.maf
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 from galaxy.tools.util import maf_utilities
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 import sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 assert sys.version_info[:2] >= ( 2, 4 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 def __main__():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 #Parse Command Line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 input_file = sys.argv.pop( 1 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 output_file = sys.argv.pop( 1 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 species = maf_utilities.parse_species_option( sys.argv.pop( 1 ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 maf_writer = bx.align.maf.Writer( open( output_file, 'w' ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 print sys.stderr, "Unable to open output file"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 count = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 for count, maf in enumerate( bx.align.maf.Reader( open( input_file ) ) ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 maf = maf.reverse_complement()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 if species:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 maf = maf.limit_to_species( species )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 maf_writer.write( maf )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 print >>sys.stderr, "Your MAF file appears to be malformed."
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 print "%i regions were reverse complemented." % count
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 maf_writer.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 if __name__ == "__main__": __main__()