-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMS15101 - Q2.py
More file actions
50 lines (40 loc) · 1.06 KB
/
MS15101 - Q2.py
File metadata and controls
50 lines (40 loc) · 1.06 KB
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
50
#MS15101 - Q2
import math
import re
def shannon():
aa = 'ACDEFGHIKLMNPQRSTVWYZ'
#p =
entropy = -p*(log(p))
fd = open('E:/Study/Biocomputing/Mid-Sem/MS15101/q2_msa.fasta')
head = fd.readline()
var = fd.readlines()
fd.close()
ids= []
seqs = []
sortid = []
for line in var:
line = line.strip('\n')
id = re.findall(r'^(\w+)',line)
seq = re.findall(r'\w+\s+([\w-].+)',line)
#Can also be done without using regex by:
#for line in var:
#line = line.strip('\n')
#id = line[0:10]
#seq = line[16:]
ids.append(id)
seqs.append(seq)
zipcomb = zip(ids, seqs)
for i in range(len(ids)):
if ids[i] not in sortid:
sortid.append(ids[i])
for m in range(len(sortid)):
for j in range(len(zipcomb)):
for k in range(len(zipcomb[j])):
if zipcomb[j][0] == sortid[m]:
sortid[m].append(zipcomb[j][1])
else:
pass
for n in range(len(sortid)):
for l in range (len(sortid[n])):
sortid[n][l] == str(sortid[n][l])
print sortid