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

リビジョン 3, 1.7 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 and print the text as a fasta file, concatenating blocks. A
5specific subset of species can be chosen.
6
7usage %prog [options] species1,species2,... < maf_file > fasta_file
8    --fill="expression": Insert this between blocks
9    --wrap=columns: Wrap FASTA to this many columns
10"""
11
12from optparse import OptionParser
13
14import textwrap
15import sys
16from bx.align import maf
17
18def __main__():
19    # Parse command line arguments
20
21    parser = OptionParser()
22    parser.add_option( "--fill", action="store", default=None, type="string", help="" )
23    parser.add_option( "--wrap", action="store", default=None, type="int", help="" )
24    parser.add_option( "--nowrap", action="store_true", default=False, dest="nowrap", help="" )
25
26    ( options, args ) = parser.parse_args()
27
28    species = []
29    for arg in args: species.extend(arg.split(','))
30
31    fill = ""
32    if options.fill: fill = eval( options.fill )
33
34    wrap = 50
35    if   (options.wrap != None): wrap = options.wrap
36    elif (options.nowrap):       wrap = 0
37
38    # create the concatenated sequences
39
40    texts = {}
41    for s in species: texts[s] = []
42    maf_reader = maf.Reader( sys.stdin )
43    for m in maf_reader:
44        for s in species:
45            c = m.get_component_by_src_start( s )
46            if c: texts[s].append( c.text )
47            else: texts[s].append( "-" * m.text_size )
48    for s in species:
49        print ">" + s
50        print_n( fill.join( texts[s] ), wrap )
51
52def print_n( s, n, f = sys.stdout ):
53    if (n <= 0):
54        print >> f, s
55    else:
56        p = 0
57        while p < len( s ):
58            print >> f, s[p:min(p+n,len(s))]
59            p += n
60
61if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。