# -*- coding: utf-8 -*-
# author : kian-meng, ang
#
# input  : a dna string at most 100 nt (NucleoTides)
# output : 20 12 17 21
#
# $ python counting_nucleotides.py

# input  : a dna string at most 100 nt (NucleoTides)
# output : 20 12 17 21

f = open("rosalind_dna.txt", "r")
dna_string = f.read()

# method 1: using count()
print "%d %d %d %d" % (
    dna_string.count('A'), dna_string.count('C'),
    dna_string.count('G'), dna_string.count('T')
)

# method 2: using list
for char in ['A', 'C', 'G', 'T']:
    print dna_string.count(char),
print ""

# method 3: generate the unique characters
# we need to strip the newline \n and sort the result.
# @see http://stackoverflow.com/a/13902829
nucleotides = ''.join(sorted(set(dna_string.strip())))
for char in nucleotides:
    print dna_string.count(char),
print ""

# method 4: using collections
# @see http://codereview.stackexchange.com/a/27784
# @see https://docs.python.org/2/library/collections.html#counter-objects
# @see http://stackoverflow.com/a/17930886
from collections import Counter
nucleotides_count = sorted(Counter(dna_string.strip()).items())
for _, count in nucleotides_count:
    print count,
print ""

# method 5: using collections but different approach
counter = Counter()
for char in ''.join(dna_string.strip()):
    counter[char] += 1

for _, count in sorted(counter.items()):
    print count,