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

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

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Reads a MAF file. Produces a MAF file containing
5the reverse complement for each block in the source file.
6
7usage: %prog input_maf_file output_maf_file
8"""
9#Dan Blankenberg
10from galaxy import eggs
11import pkg_resources; pkg_resources.require( "bx-python" )
12import bx.align.maf
13from galaxy.tools.util import maf_utilities
14import sys
15
16assert sys.version_info[:2] >= ( 2, 4 )
17
18def __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
42if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。