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

Commit

Permalink
#23 test_export_as_gfa now working with example fast queries for fetc…
Browse files Browse the repository at this point in the history
…hing the whole graph.
  • Loading branch information
josiahseaman committed Aug 23, 2019
1 parent 52c5c0f commit 005d1d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Graph/gfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ def save_as_gfa(self, file: str):
self.gfa.to_file(file)

@classmethod
def from_graph(cls, graph: GraphGenome):
def from_graph(cls, graph: GraphGenome): # TODO: should be given ZoomLevel instead
"""Constructs the lines of a GFA file listing paths, then sequence nodes in arbitrary order."""
gfa = gfapy.Gfa()
for path in graph.paths:
visits = [traverse.node_name + traverse.strand for traverse in
path.nodes.values_list('node_name', 'strand', named=True)]
for path in graph.paths.all():
visits = []
# example of using lazy queries and values_list for fast lookup
node_infos = path.nodes.values_list('node_id', 'strand', named=True)
for traverse in node_infos:
name = Node.objects.values_list('name', flat=True).get(id=traverse.node_id) # fast lookup
visits.append(name + traverse.strand)
node_series = ",".join(visits)
connections = ",".join(['*'] * path.nodes.count()) # count -1?
gfa.add_line('\t'.join(['P', path.accession, node_series, connections]))
Expand Down
2 changes: 0 additions & 2 deletions Graph/migrations/0004_ZoomLevel_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

class Migration(migrations.Migration):

replaces = [('Graph', '0004_ZoomLevel_objects'), ('Graph', '0005_auto_20190823_1603')]

dependencies = [
('Graph', '0003_add_zoom_levels'),
]
Expand Down
7 changes: 4 additions & 3 deletions Graph/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ def test_summary_storage(self):
current = graph.node(node_name)
NodeTraversal(node=current, path=path, strand='+', order=i).save()
assert NodeTraversal.objects.get(order=0, path=path).downstream().downstream().node.name == '6'
child = graph.paths.get(accession='a')
child.update(summarized_by=path)
assert graph.zoomlevel_set.count() == 2
graph.paths.filter(accession='a').update(summarized_by=path)
assert bool(path.summary_child), "Path should be linked to its child."
path_pointers = graph.zoomlevel_set.filter(zoom=1).first().paths
print('path_pointers', type(path_pointers))
assert path_pointers.count() == 1

# @unittest.skip # DAGify has not been converted to databases yet.

#@unittest.skip # DAGify has not been converted to databases yet.
class DAGifyTest(TestCase):
""" test class of sort.py
"""
Expand Down

0 comments on commit 005d1d8

Please sign in to comment.