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

リビジョン 3, 1.0 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 counts and frequencies of all n-mers
5(words composed on n consecutive alignment columns)
6
7TODO: reconcile this and maf_mapping_word_frequency.py
8
9usage: %prog n < maf_file
10"""
11
12from __future__ import division
13
14import psyco; psyco.profile()
15
16from bx.cookbook import doc_optparse
17import string
18import sys
19
20from align import maf
21
22
23def __main__():
24
25    motif_len = int( sys.argv[1] )
26
27    big_map = {}
28    total = 0
29   
30    maf_reader = maf.Reader( sys.stdin )
31
32    for m in maf_reader:
33        texts = [ c.text.upper() for c in m.components ]
34        for i in range( m.text_size - motif_len ):
35            motif = string.join( [ text[ i : i + motif_len ] for text in texts ] )
36            if big_map.has_key( motif ): big_map[ motif ] += 1
37            else: big_map[ motif ] = 1
38            total += 1
39
40    items = zip( big_map.values(), big_map.keys() )
41    items.sort()
42    items.reverse()
43
44    for count, motif in items:
45        print "%d\t%0.10f\t%s" % ( count, count / total, motif )
46
47if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。