Skip to content

Commit

Permalink
:)
Browse files Browse the repository at this point in the history
  • Loading branch information
anicksaha committed Nov 7, 2019
1 parent 159ab15 commit 8b5d18e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 57 deletions.
54 changes: 27 additions & 27 deletions bootstrap.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
0.0
0.0
0.24
0.17
0.0
0.03
0.07
0.12
0.05
0.2
0.0
0.36
0.01
0.21
0.0
0.37
0.0
0.0
0.0
0.0
0.0
0.1
0.93
0.0
0.03
0.08
0.94
0.01
0.02
0.44
0.0
0.06
0.62
0.07
0.61
0.0
0.0
0.0
0.34
0.25
0.0
0.0
0.0
0.45
0.01
0.19
0.32
0.56
0.37
0.0
0.14
0.31
0.51
0.0
0.0
0.38
0.01
0.0
0.31
0.0
1.0
0.0
0.0
0.0
0.32
0.38
0.0
0.09
0.07
1.0
0.78
0.08
0.55
0.8
0.1
0.6
1.0
1.0
0.0
0.0
0.0
0.17
0.6
0.01
0.16
0.56
6 changes: 3 additions & 3 deletions edges.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
63 64 0.00376827912568
64 69 0.0114938796716
69 70 0.00240415262502
70 19 0.0913179402432
70 42 0.095761467563
70 19 0.0913179402432
69 6 0.068928283445
64 74 0.0138257703957
74 43 0.0701951689325
Expand Down Expand Up @@ -85,8 +85,8 @@
83 91 0.013850279425
91 102 0.00423269087876
102 104 0.00461971797755
104 51 0.0825808319509
104 13 0.0802724654919
104 51 0.0825808319509
102 105 0.00656803437777
105 110 0.0177473177689
110 50 0.0824905753015
Expand All @@ -102,10 +102,10 @@
109 27 0.0686467796658
107 5 0.0891093137398
83 119 0.188580743455
119 3 0.132248688913
119 120 0.0215198171439
120 1 0.115587289276
120 2 0.124654971827
119 3 0.132248688913
65 76 0.0120786458936
76 77 0.00238916628989
77 41 0.0648454483874
Expand Down
49 changes: 23 additions & 26 deletions neighbour_joining.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def nei_saitou(original_ids, original_dist_matrix, sequence_counter):
#Using a global root holder
global root
root = None
# Maintaining a map for the relationships between child and parent
# Maintaining a map for the relationships b/w child and parent
relationship_map = {}

# Using a mapping for seqId and new ids.
Expand All @@ -18,42 +18,40 @@ def calculate_next_neighbours(ids, dist_matrix, sequence_counter, seqId_orderId_
global root
N = len(dist_matrix)

# Base case for recursion
if N <= 2:
# Assigning the ids to these nodes according to the requirements
if N <= 2: # Base case
if ids[0] in seqId_orderId_map:
tip_1 = seqId_orderId_map[ids[0]]
node_1 = seqId_orderId_map[ids[0]]
else:
tip_1 = ids[0]
node_1 = ids[0]
if ids[1] in seqId_orderId_map:
tip_2 = seqId_orderId_map[ids[1]]
node_2 = seqId_orderId_map[ids[1]]
else:
tip_2 = ids[1]
node_2 = ids[1]
# Adding their relationship to the tree
relationship_map[tip_1] = (tip_2, dist_matrix[0][1])
relationship_map[node_1] = (node_2, dist_matrix[0][1])
# Since these are the last two nodes, any of these can be chosen to be the root
root = tip_2
root = node_2
return

#First step is to get the closest two tips from the distance matrix
mini, minj, minVal = utils.get_qmatrix(dist_matrix)

edge_i, edge_j = utils.calculate_edge_lengths(dist_matrix, mini, minj, N)
#print(edge_i, edge_j)
tip_1 = tip_2 = None
node_1 = node_2 = None

# Setting the new ids to the tips/ internal node
if ids[mini] in seqId_orderId_map:
tip_1 = seqId_orderId_map[ids[mini]]
node_1 = seqId_orderId_map[ids[mini]]
else:
tip_1 = ids[mini]
node_1 = ids[mini]
if ids[minj] in seqId_orderId_map:
tip_2 = seqId_orderId_map[ids[minj]]
node_2 = seqId_orderId_map[ids[minj]]
else:
tip_2 = ids[minj]
node_2 = ids[minj]

# Add them to the tree relationships
relationship_map[tip_1] = (str(sequence_counter), edge_i)
relationship_map[tip_2] = (str(sequence_counter), edge_j)
relationship_map[node_1] = (str(sequence_counter), edge_i)
relationship_map[node_2] = (str(sequence_counter), edge_j)

# Remove the used ids and add the new sequence_counter
ids = [id for id in ids if id not in (ids[mini], ids[minj])] + [str(sequence_counter)]
Expand All @@ -67,19 +65,18 @@ def calculate_next_neighbours(ids, dist_matrix, sequence_counter, seqId_orderId_
calculate_next_neighbours(original_ids, original_dist_matrix, sequence_counter, seqId_orderId_map)

# construct tree from the relationship_map relations
rootNode = Node(root)
queue = [rootNode]
root_node = Node(root)
queue = [root_node]
# bfs for tree construction
while len(queue) > 0:
nodeList = []
node_list = []
for node in queue:
for child, (parent, distance) in relationship_map.items():
if parent == node.id:
childNode = Node(child)
node.add_child(childNode, distance)
nodeList.append(childNode)
for node in nodeList:
node_list.append(childNode)
for node in node_list:
del relationship_map[node.id]
queue = nodeList
return rootNode

queue = node_list
return root_node
Binary file modified tree.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion tree.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(((4439229:0.0994636314408,(164216:0.0805450227767,146154:0.0648116394037):0.0142644977651):0.00735813002246,((720729:0.097762461851,(((((100149:0.0486748871823,(4468812:0.0261929524043,166838:0.0343723235042):0.0135727575014):0.0312959330949,348167:0.0893299080895):0.0107871348319,(286686:0.0867460556338,((779409:0.04678825286,593544:0.060210401245):0.00697756765851,4387271:0.0431570218435):0.0165513871656):0.00338682209946):0.0117075956228,(11136:0.104185713798,(5364:0.0459632162084,(3148512:0.0387720577239,106543:0.0419816434874):0.0112373221496):0.024851971263):0.00389111736513):0.00387210426656,(((1920715:0.120428860031,(260976:0.0822133814411,646961:0.0759292834311):0.0141606419883):0.0116483249952,((((4378332:0.0506567246683,523025:0.0846057248606):0.0147056847708,(511006:0.0515193738372,(((273179:0.0226913456411,188674:0.020377295005):0.000565372968216,319214:0.0219783686199):0.0109189939435,197222:0.0380379374159):0.0254489976298):0.0132847257272):0.00561348628869,(806723:0.0722060713208,(1009440:0.0708603722105,((954340:0.0772832314566,947627:0.0727840632945):0.00484880367808,(4164932:0.0605401041029,(565897:0.0476464546292,144260:0.0337801940922):0.0454491287369):0.00415186926943):0.00135530746646):0.00572966219195):0.0100726310145):0.00375090334222,4397763:0.0781236103481):0.0106890635478):0.00388775124005,((((822879:0.0825808319509,664158:0.0802724654919):0.00461971797755,((3906666:0.0824905753015,(816087:0.0812659224188,4448694:0.0762037949433):0.0255175000687):0.0177473177689,(4431405:0.0543373959424,809189:0.0614095757938):0.0302843107641):0.00656803437777):0.00423269087876,((2034243:0.094206517777,208595:0.0686467796658):0.00510333767336,996519:0.0891093137398):0.025745017735):0.013850279425,((152801:0.115587289276,3855581:0.124654971827):0.0215198171439,4345542:0.132248688913):0.188580743455):0.0120725313848):0.0120473718793):0.00536520381635):0.00336721222622,((2263183:0.0648454483874,((586332:0.0726342497929,1136782:0.103677997852):0.00763606407822,2963287:0.0704258470927):0.0074964089477):0.00238916628989,(555079:0.0352536797343,553272:0.0313681237651):0.0385765133871):0.0120786458936):0.00753624506626):0.000959080610108);
(((4439229:0.0994636314408,(164216:0.0805450227767,146154:0.0648116394037):0.0142644977651):0.00735813002246,((720729:0.097762461851,(((((100149:0.0486748871823,(4468812:0.0261929524043,166838:0.0343723235042):0.0135727575014):0.0312959330949,348167:0.0893299080895):0.0107871348319,(286686:0.0867460556338,((779409:0.04678825286,593544:0.060210401245):0.00697756765851,4387271:0.0431570218435):0.0165513871656):0.00338682209946):0.0117075956228,(11136:0.104185713798,(5364:0.0459632162084,(3148512:0.0387720577239,106543:0.0419816434874):0.0112373221496):0.024851971263):0.00389111736513):0.00387210426656,(((1920715:0.120428860031,(260976:0.0822133814411,646961:0.0759292834311):0.0141606419883):0.0116483249952,((((4378332:0.0506567246683,523025:0.0846057248606):0.0147056847708,(511006:0.0515193738372,(((273179:0.0226913456411,188674:0.020377295005):0.000565372968216,319214:0.0219783686199):0.0109189939435,197222:0.0380379374159):0.0254489976298):0.0132847257272):0.00561348628869,(806723:0.0722060713208,(1009440:0.0708603722105,((954340:0.0772832314566,947627:0.0727840632945):0.00484880367808,(4164932:0.0605401041029,(565897:0.0476464546292,144260:0.0337801940922):0.0454491287369):0.00415186926943):0.00135530746646):0.00572966219195):0.0100726310145):0.00375090334222,4397763:0.0781236103481):0.0106890635478):0.00388775124005,((((664158:0.0802724654919,822879:0.0825808319509):0.00461971797755,((3906666:0.0824905753015,(816087:0.0812659224188,4448694:0.0762037949433):0.0255175000687):0.0177473177689,(4431405:0.0543373959424,809189:0.0614095757938):0.0302843107641):0.00656803437777):0.00423269087876,((2034243:0.094206517777,208595:0.0686467796658):0.00510333767336,996519:0.0891093137398):0.025745017735):0.013850279425,(4345542:0.132248688913,(152801:0.115587289276,3855581:0.124654971827):0.0215198171439):0.188580743455):0.0120725313848):0.0120473718793):0.00536520381635):0.00336721222622,((2263183:0.0648454483874,((586332:0.0726342497929,1136782:0.103677997852):0.00763606407822,2963287:0.0704258470927):0.0074964089477):0.00238916628989,(555079:0.0352536797343,553272:0.0313681237651):0.0385765133871):0.0120786458936):0.00753624506626):0.000959080610108);

0 comments on commit 8b5d18e

Please sign in to comment.