Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/annotate/c4acc245244c/test/freqs.py
Дата изменения: Unknown
Дата индексирования: Sun Mar 2 07:44:56 2014
Кодировка:
allpy: test/freqs.py annotate

allpy

annotate test/freqs.py @ 432:c4acc245244c

blocks3d/wt improvement make symbolic link files/resources to wt resoure files (instead of copy them to files/resources)
author boris <bnagaev@gmail.com>
date Tue, 15 Feb 2011 00:07:57 +0300
parents
children
rev   line source
dendik@391 1 """Read alignment on stdin. Print CSV table of letter frequences on stdout.
dendik@391 2 """
dendik@391 3 from allpy import protein
dendik@391 4 from allpy.data import codes
dendik@391 5 import sys
dendik@391 6
dendik@391 7 sys.stderr.write(__doc__)
dendik@391 8
dendik@391 9 def freq(monomer):
dendik@391 10 amount = freqs.get(monomer)
dendik@391 11 if amount:
dendik@391 12 return 100.0 * amount / width
dendik@391 13 return ""
dendik@391 14
dendik@391 15 aln = protein.Alignment().append_file(sys.stdin)
dendik@391 16 monomers = [code1 for code1, modified, _, _ in codes.protein if not modified]
dendik@391 17 monomers += ["-"]
dendik@391 18 width = len(aln.sequences)
dendik@391 19 print ", ".join(map(str, monomers))
dendik@391 20 for column in aln.columns_as_lists():
dendik@391 21 freqs = {}
dendik@391 22 for monomer in column:
dendik@391 23 if monomer:
dendik@391 24 monomer = monomer.code1
dendik@391 25 else:
dendik@391 26 monomer = "-"
dendik@391 27 freqs[monomer] = freqs.get(monomer, 0) + 1
dendik@391 28 print ", ".join(map(str, map(freq, monomers)))