Created
April 2, 2013 14:38
-
-
Save knmkr/5292716 to your computer and use it in GitHub Desktop.
count the number of each characters in <stdin>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from collections import Counter | |
import fileinput | |
def _main(): | |
""" | |
Usage example: | |
% echo AAAAATATGAAACGT | python count-atgc.py | |
[('A', 9), ('T', 3), ('G', 2), ('C', 1)] | |
""" | |
c = Counter() | |
for line in fileinput.input(): | |
for base in line.rstrip(): | |
c[base] += 1 | |
print c.most_common() | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment