root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/maf_split_by_src.py

リビジョン 3, 1.6 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1#!/usr/bin/python2.6
2
3"""
4Read a MAF from stdin and break into several mafs based on the source of
5each block. If the `component` option is provided then only that component
6will be used to determine the new file for each block, otherwise the src
7for *all* components will be used.
8
9TODO: Should be able to specify component by species/prefix?
10
11usage: %prog [options] < maf
12    -o, --outprefix: prepend this to the name of each generate maf
13    -c, --component: use only this component (by index!) to split
14"""
15
16import sys, string
17import bx.align.maf
18from optparse import OptionParser
19
20import psyco_full
21
22INF="inf"
23
24def __main__():
25
26    # Parse command line arguments
27
28    parser = OptionParser()
29    parser.add_option( "-o", "--outprefix", action="store", default="" )
30    parser.add_option( "-c", "--component", action="store", default=None )
31    ( options, args ) = parser.parse_args()
32
33    out_prefix = options.outprefix
34    comp = options.component
35    if comp is not None:
36       comp = int( comp )
37
38    maf_reader = bx.align.maf.Reader( sys.stdin )
39
40    writers = {}
41
42    for m in maf_reader:
43       
44        if comp is None:
45            writer_key = string.join( [ c.src for c in m.components ], '_' )
46        else:
47            writer_key = m.components[ comp ].src
48
49        if not writers.has_key( writer_key ):
50            writer = bx.align.maf.Writer( file( "%s%s.maf" % ( out_prefix, writer_key ), "w" ) )
51            writers[ writer_key ] = writer
52        else:
53            writer = writers[ writer_key ]
54
55        writer.write( m )
56
57    for key in writers:
58        writers[ key ].close()
59
60if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。