Skip to content

Instantly share code, notes, and snippets.

@knmkr
Created April 2, 2013 14:38
Show Gist options
  • Save knmkr/5292716 to your computer and use it in GitHub Desktop.
Save knmkr/5292716 to your computer and use it in GitHub Desktop.
count the number of each characters in <stdin>
#!/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