forked from ruizhang84/Bioinformatics-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimb_length.py
More file actions
39 lines (32 loc) · 1.18 KB
/
Copy pathlimb_length.py
File metadata and controls
39 lines (32 loc) · 1.18 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
class TXT_Extract:
def __init__(self,dna_file):
f=open(dna_file,'r')
self.lists=[]
for line in open(dna_file):
line=f.readline()
line=line.strip()
line=line.split(" ")
for n,x in enumerate(line):
line[n]=int(x)
self.lists.append(line)
self.num_node=int(self.lists.pop(0)[0])
self.cal_node=int(self.lists.pop(0)[0])
f.close()
def cal_length(self):
import heapq
dis=[]
limb_legnth=0
for i in range(self.num_node):
for j in range(self.num_node):
if i != self.cal_node and j !=self.cal_node and i !=j:
distance_ni=self.lists[self.cal_node][i]
distance_nj=self.lists[self.cal_node][j]
distance_ij=self.lists[i][j]
limb=(distance_ni+distance_nj-distance_ij)/2
heapq.heappush(dis,limb)
limb_legnth=heapq.heappop(dis)
print limb_legnth
return limb_legnth
if __name__=="__main__":
test=TXT_Extract('dataset_10329_11.txt')
test.cal_length()