Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/f3358da68bcd/utils/freqs.py
Дата изменения: Unknown
Дата индексирования: Mon Feb 4 00:50:19 2013
Кодировка:
allpy: f3358da68bcd utils/freqs.py

allpy

view utils/freqs.py @ 933:f3358da68bcd

Fixed two bugs in one place: base Alignment/Block - realign used to cut sequence tails if the new alignment was wider than the existing one - any block modification that added new columns used to forget to add the columns to the alignment AFAIR, currently the only such modifications are IO, append_*, and realign() To fix it I've: - changed realign to use _pad_to_width() same as IO used, - and changed _pad_to_width() to behave in a blocks-safe manner: it now calls self._append_columns(), which in case of blocks calls itself recursively to add columns to parent too.
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 22 Nov 2011 00:13:40 +0300
parents 8c7e5c16b2f4
children
line source
1 #!/usr/bin/python
2 """Read alignment on stdin. Print CSV table of letter frequences on stdout.
3 """
4 from allpy import protein
5 from allpy.data import codes
6 import sys
8 sys.stderr.write(__doc__)
10 def freq(monomer):
11 amount = freqs.get(monomer)
12 if amount:
13 return 100.0 * amount / width
14 return ""
16 aln = protein.Alignment().append_file(sys.stdin)
17 monomers = [code1 for code1, modified, _, _ in codes.protein if not modified]
18 monomers += ["-"]
19 width = len(aln.sequences)
20 print ", ".join(map(str, monomers))
21 for column in aln.columns_as_lists():
22 freqs = {}
23 for monomer in column:
24 if monomer:
25 monomer = monomer.code1
26 else:
27 monomer = "-"
28 freqs[monomer] = freqs.get(monomer, 0) + 1
29 print ", ".join(map(str, map(freq, monomers)))