forked from pyramidsnail/bioinformatics-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cons.py
49 lines (41 loc) · 950 Bytes
/
cons.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys, re, os
from Bio import SeqIO
seqs = []
handle = open('test', 'rU')
for record in SeqIO.parse(handle, 'fasta'):
seqs.append(record.seq)
handle.close()
cols = len(seqs[0])
nc = {'A':[], 'T':[], 'C':[], 'G':[]}
for i in xrange(cols):
anum = 0
tnum = 0
cnum = 0
gnum = 0
for j in xrange(len(seqs)):
if seqs[j][i] == 'A':
anum += 1
elif seqs[j][i] == 'T':
tnum += 1
elif seqs[j][i] == 'C':
cnum += 1
else:
gnum += 1
nc['A'].append(anum)
nc['T'].append(tnum)
nc['C'].append(cnum)
nc['G'].append(gnum)
res = ''
for i in xrange(cols):
maxnum = 0
maxnc = 'A'
for key in nc:
if nc[key][i]>maxnum:
maxnc = key
maxnum = nc[key][i]
res += maxnc
print res
for i in sorted(nc):
print i+':',
nc[i] = [str(x) for x in nc[i]]
print ' '.join(nc[i])