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

Commit

Permalink
#26 Fix for Graph copying operation. Still hitting "too many SQL vari…
Browse files Browse the repository at this point in the history
…ables".
  • Loading branch information
josiahseaman committed Sep 3, 2019
1 parent 96df52a commit 5159eae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Graph/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create(self, graph, zoom) -> 'ZoomLevel':
# Makes a full copy of every traversal in the Path so new copies can be edited
copies = [NodeTraversal(path=p, node=traverse.node, strand=traverse.strand, order=traverse.order)
for traverse in path.nodetraversal_set.all()]
NodeTraversal.objects.bulk_create(copies, 500)
NodeTraversal.objects.bulk_create(copies, 100)
return me


Expand Down
5 changes: 3 additions & 2 deletions HaploBlocker/haplonetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ def simple_merge(current_level: ZoomLevel) -> ZoomLevel:
x.save()

# edit existing traversals
path_ids = next_level.paths.values_list('id', flat=True)
NodeTraversal.objects.\
filter(node=next_node, path__in=next_level.paths).\
filter(node=next_node, path_id__in=path_ids).\
update(node_id=merged_node.id)
# next_node.nodetraversal_set.filter(zoom=zoom).bulk_update(node_id=merged_node.id)

# delete my_node and all associates
query = NodeTraversal.objects.filter(node=my_node, path__in=next_level.paths)
query = NodeTraversal.objects.filter(node=my_node, path_id__in=path_ids)
query._raw_delete(query.db) # https://www.nickang.com/fastest-delete-django/
# TODO: merged_node.start = my_node.start
return next_level
Expand Down
27 changes: 13 additions & 14 deletions HaploBlocker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def test_creation(self):


class HaploTest(TestCase):
# @classmethod
# def setUpClass(self) -> None:
# """Reads the input data file once. Tests that need a fresh graph must
# call create_graph()"""
# print("Setting up HaploTest:", os.getcwd())
# self.alleles, self.individuals = read_data(os.path.join(BASE_DIR, "test_data/KE_chromo10.txt"))
# print("Finished reading SNP file")
# super(HaploTest, self).setUpClass()
@classmethod
def setUpClass(self) -> None:
"""Reads the input data file once. Tests that need a fresh graph must
call create_graph()"""
print("Setting up HaploTest:", os.getcwd())
self.alleles, self.individuals = read_data(os.path.join(BASE_DIR, "test_data/KE_chromo10.txt"))
print("Finished reading SNP file")
super(HaploTest, self).setUpClass()

def create_graph(self, graph_name):
"""Tests that need a fresh graph must call create_graph() FIRST!
Expand Down Expand Up @@ -98,20 +98,19 @@ def test_no_duplicate_nodes(self):
unique_nodes.add(node)
assert duplicates_found == 0, f"Found {duplicates_found} duplicated nodes in the graph"


def _test_simple_merge(self, layer : ZoomLevel) -> ZoomLevel:
def _test_simple_merge(self, layer: ZoomLevel):
# these tests could be made independent of test_workflow, but it would be slower
graph = layer.graph
zoom_level = layer.zoom
assert graph.highest_zoom_level() == zoom_level
self.assertEqual(len(layer), 7180)
next_level = simple_merge(layer)
#Test every Path has a representative in this ZoomLevel
# Test every Path has a representative in this ZoomLevel
self.assertEqual(Path.objects.filter(graph=graph, zoom=zoom_level + 1).count(),
Path.objects.filter(graph=graph, zoom=zoom_level + 0).count())
self.assertEqual(NodeTraversal.objects.filter(graph=graph, zoom=zoom_level+1).count(), 3690) #*501?

@skip

def test_simple_merge(self):
graph = self.create_graph('test')
self._test_simple_merge(graph.nucleotide_level())
Expand Down Expand Up @@ -165,8 +164,8 @@ def test_split_groups(self):
# zoom_level, zoom = prep_next_summary_layer(g.nucleotide_level())
split_groups(g.nucleotide_level())
self.assertEqual(len(g.nucleotide_level()), 5)
simple_merge(g.nucleotide_level())
self.assertEqual(len(g.nucleotide_level()), 3)
# simple_merge(g.nucleotide_level())
# self.assertEqual(len(g.nucleotide_level()), 3)

def test_workflow(self):
graph = self.create_graph('test')
Expand Down

0 comments on commit 5159eae

Please sign in to comment.