Skip to content
This repository has been archived by the owner on Mar 20, 2020. It is now read-only.

Commit

Permalink
#19 split_groups returning a new graph copy instead of appending to t…
Browse files Browse the repository at this point in the history
…he old.
  • Loading branch information
josiahseaman committed Aug 14, 2019
1 parent fa99d2c commit 4d42721
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions HaploBlocker/haplonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ def split_groups(all_nodes: List[Node]):
are present where 2 would suffice. Split groups splits the anchor node and gives pieces
to each haplotype; reducing 5 Nodes to 2.
:Returns new graph with less nodes, all_nodes is still modified, but length doesn't change
Note: This is called crossmerge in the R code.
TODO: Ideally, the database would retain some record of how many nucleotides are shared between
the two new haplotype nodes."""
length = len(all_nodes) # size of global_nodes changes, necessitating this weird loop
for n in range(length):
node = all_nodes[n]
new_graph = list(all_nodes)
for node in all_nodes:
# check if all transition upstream match with one of my downstream nodes
if len(node.specimens) > 0:
# Matchup upstream and downstream with specimen identities
Expand All @@ -337,7 +337,7 @@ def split_groups(all_nodes: List[Node]):

if set1 == set2 and len(set1) > 0:
new_node = split_one_group(up, node, down)
all_nodes.append(new_node)
new_graph.append(new_node)

filtered = neglect_nodes(all_nodes, 0) # Delete nodes with zero specimens from the Graph?
filtered = neglect_nodes(new_graph, 0) # Delete nodes with zero specimens from the Graph?
return filtered
2 changes: 2 additions & 0 deletions HaploBlocker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def test_workflow(self):
summary1 = self._test_simple_merge(all_nodes)
summary2 = self._test_neglect_nodes(summary1)
summary3 = self._test_split_groups(summary2)
assert len(summary1) > len(summary2) > len(summary3), "Each summarization should result in less nodes"
summary4 = simple_merge(summary3)
bad = summary3[2]
print(bad.details())

Expand Down

0 comments on commit 4d42721

Please sign in to comment.