forked from jwschroeder3/504GitExercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
27 lines (25 loc) · 732 Bytes
/
code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def count_nts(seq):
'''
Returns a dictionary of counts of nucleotides.
Params:
seq: a sequence of nucleotides, or any string really.
'''
counts = dict()
for nt in seq:
if nt not in counts:
counts[nt] = 1
else:
counts[nt] += 1
return counts
def calc_freq(counts):
'''
Calculates and displays to std out the frequencies of the characters/
nucleotides in the given sequence.
Params:
counts: dictionary of counts of characters.
'''
print('freqs')
total = float(sum([counts[nt] for nt in counts.keys()]))
for nt in counts.keys():
print(nt + ':' + str(counts[nt]/total))
calc_freq(count_nts('ATCTGACGCGCGCCGC'))