diff --git a/code.py b/code.py deleted file mode 100644 index 7bfc82b..0000000 --- a/code.py +++ /dev/null @@ -1,16 +0,0 @@ -def function1(a): - b = dict() - for c in a: - if c not in b: - b[c] = 1 - else: - b[c] += 1 - return b - -def function2(a): - print('freqs') - total = float(sum([a[b] for b in a.keys()])) - for b in a.keys(): - print(b + ':' + str(a[b]/total)) - -function2(function1('ATCTGACGCGCGCCGC')) diff --git a/print_proportions.py b/print_proportions.py new file mode 100644 index 0000000..8fed6ae --- /dev/null +++ b/print_proportions.py @@ -0,0 +1,15 @@ +import collections + +def print_proportions(seq): + """Print the proportions of each base in the string `seq`.""" + + counts = collections.Counter(seq) + total = counts.total() + + # It's printing proportions here, not frequencies, but we'll keep this label for + # backwards compatibility. + print('freqs') + for base, n in counts.items(): + print(f'{base}:{n/total}') + +print_proportions('ATCTGACGCGCGCCGC')