view utils/freqs.py @ 599:56d62d405021
pair_cores_all.py: close openned files to avoid error
error "Too many openned files" occured in child processes
multiprocessing seems to use old process when new python process
is created to avoid increasing of process number. Therefore
files openned in childred are not closed automatically
author |
boris (kodomo) <bnagaev@gmail.com> |
date |
Sun, 03 Apr 2011 17:05:32 +0400 |
parents |
7184863832b9 |
children |
aa3cf3b44f86 |
line source
1 """Read alignment on stdin. Print CSV table of letter frequences on stdout.
3 from allpy import protein
4 from allpy.data import codes
7 sys.stderr.write(__doc__)
10 amount = freqs.get(monomer)
12 return 100.0 * amount / width
15 aln = protein.Alignment().append_file(sys.stdin)
16 monomers = [code1 for code1, modified, _, _ in codes.protein if not modified]
18 width = len(aln.sequences)
19 print ", ".join(map(str, monomers))
20 for column in aln.columns_as_lists():
22 for monomer in column:
24 monomer = monomer.code1
27 freqs[monomer] = freqs.get(monomer, 0) + 1
28 print ", ".join(map(str, map(freq, monomers)))