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

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

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

行番号 
1#!/usr/bin/python2.6
2
3"""
4For every column that occurs in a multiple alignment print the column
5and the number of times it occurs (one column/count per line, tab
6separated), sorted by count descending.
7
8Note: all blocks must have exactly the same number of species.
9
10usage: %prog < maf > column_counts
11"""
12
13import bx.align.maf
14import sys
15
16from itertools import *
17
18counts = {}
19
20nspecies = None
21
22for block in bx.align.maf.Reader( sys.stdin ):
23    # Ensure all blocks have the same number of rows
24    if nspecies: assert len( block.components ) == nspecies
25    else: nspecies = len( block.components )
26    # Increment count for each column
27    for col in izip( * [ iter( comp.text.upper() ) for comp in block.components ] ):
28        try: counts[ col ] += 1
29        except: counts[ col ] = 1
30
31counts = [ ( value, key ) for key, value in counts.iteritems() ]
32counts.sort()
33counts.reverse()
34
35# print len( counts )
36
37for count, col in counts:
38    print "".join(col), count
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。