view utils/freqs.py @ 878:c6fc4ea7df8b
fix blocks3d/www: add changes forgotten while migrating to Makefile
 * json-adaptor with self-written function json
 * download utf8_encode.js, needed by original crc32
 | author | 
 Boris Nagaev <bnagaev@gmail.com> | 
 | date | 
 Thu, 15 Sep 2011 17:44:53 +0400 | 
 | parents | 
 8c7e5c16b2f4  | 
 | children | 
  | 
 line source
     2 """Read alignment on stdin. Print CSV table of letter frequences on stdout. 
     4 from allpy import protein 
     5 from allpy.data import codes 
     8 sys.stderr.write(__doc__) 
    11 	amount = freqs.get(monomer) 
    13 		return 100.0 * amount / width 
    16 aln = protein.Alignment().append_file(sys.stdin) 
    17 monomers = [code1 for code1, modified, _, _ in codes.protein if not modified] 
    19 width = len(aln.sequences) 
    20 print ", ".join(map(str, monomers)) 
    21 for column in aln.columns_as_lists(): 
    23 	for monomer in column: 
    25 			monomer = monomer.code1 
    28 		freqs[monomer] = freqs.get(monomer, 0) + 1 
    29 	print ", ".join(map(str, map(freq, monomers)))