-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrph.py
More file actions
32 lines (30 loc) · 1001 Bytes
/
Copy pathgrph.py
File metadata and controls
32 lines (30 loc) · 1001 Bytes
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
#!/usr/env
from rosa_util import *
#get O3 from FASTA, note that a "directed graph" is required
def edge(seqnamelist,seqlist,k):
edges = []
tmppair = []
for i in range(len(seqnamelist)):
for j in range(len(seqnamelist)):
# check if the suffix k-mer of the i-th sequence = the prefix of the j-th
if seqlist[i][-k:] == seqlist[j][:k]:
# ensure the two sequences are not the same
tmppair = [seqnamelist[i],seqnamelist[j]]
if len(seqlist[i]) != len(seqlist[j]):
# check not duplicated
if tmppair not in edges:
#print seqnamelist[i]+' '+seqnamelist[j]
writeResult(' '.join(tmppair)+'\n')
edges.append(tmppair)
else:
for p in range(len(seqlist[i])):
if seqlist[i][p] != seqlist[j][p]:
if tmppair not in edges:
#print seqnamelist[i]+' '+seqnamelist[j]
writeResult(' '.join(tmppair)+'\n')
edges.append(tmppair)
break
return edges
flushResult()
f = readFASTA('data/rosalind_grph.txt')
edge(f[0],f[1],3)