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

リビジョン 3, 1.5 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 standard input and print counts of alignments, bases, or
5columns.
6
7usage: %prog [options]
8   -c, --cols: count alignment columns rather than number of alignments
9   -b, --bases: count bases in first species rather than number of alignments
10   -s, --skip=N: when counting bases, skip this base
11   -e, --each: print a count for each alignment rather than whole file
12   -r, --ref=N: reference sequence (first by default, 0..n)
13"""
14
15from bx.cookbook import doc_optparse
16import sys
17
18import bx.align.maf
19
20def __main__():
21
22    options, args = doc_optparse.parse( __doc__ )
23
24    try:
25        if options.cols: action = "cols"
26        elif options.bases: action = "bases"
27        else: action = "aligns"
28        print_each = bool( options.each )
29        if options.ref: ref = int( options.ref )
30        else: ref = 0
31        if options.skip: skip = options.skip
32        else: skip = None
33    except:
34        doc_optparse.exit()
35
36    maf_reader = bx.align.maf.Reader( sys.stdin )
37
38    count = 0
39
40    for m in maf_reader:
41       
42        if action == "aligns":
43            count += 1
44        elif action == "cols":
45            count += m.text_size
46        elif action == "bases":
47            if skip:
48                count += ( m.components[ref].size - m.components[ref].text.count( skip ) )
49            else:
50                count += m.components[ref].size
51
52        if print_each:
53            print count
54            count = 0
55
56    if not print_each: print count
57
58if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。