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

Commit

Permalink
Cleaned up sort imports for code review
Browse files Browse the repository at this point in the history
  • Loading branch information
josiahseaman committed Jul 19, 2019
1 parent aee4823 commit 0dc0528
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ def compute_slices(self):
return SlicedGraph.from_graph(self)


from sort import DAGify


class SlicedGraph(Graph):
def __init__(self, paths):
super(SlicedGraph, self).__init__(paths)
Expand Down Expand Up @@ -295,6 +292,8 @@ def compute_slices(self):

def compute_slices_by_dagify(self):
"""This method uses DAGify algorithm to compute slices."""
from src.sort import DAGify # help avoid circular import

if not self.paths:
return self
dagify = DAGify(self.paths)
Expand Down
19 changes: 12 additions & 7 deletions src/sort.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from src.graph import *

import sys
import dataclasses
from typing import List

from src.graph import NodeTraversal, Path, Slice, Node, SlicedGraph


@dataclasses.dataclass
class Profile:
Expand All @@ -13,11 +16,12 @@ def __repr__(self):
return "["+str(self.node.node) + str(self.paths)+":"+str(self.candidate_paths) +"]"

class DAGify:
def __init__(self, paths: List[Path], nodes={}):
def __init__(self, paths: List[Path], nodes=None):
"""
:type paths: List[Path]
"""
if nodes is None:
nodes = {}
self.paths = paths
self.nodes = nodes

Expand Down Expand Up @@ -102,7 +106,7 @@ def lcs(self, s1: List[Profile], s2: Path) -> List[Profile]:

return index

def to_slices(self, profile: List[Profile]) -> List[Path]:
def to_slices(self, profile: List[Profile]) -> List[Slice]:
factory_input = []
current_slice = Slice([])
current_paths = []
Expand Down Expand Up @@ -138,11 +142,12 @@ def to_slices(self, profile: List[Profile]) -> List[Path]:
if len(current_slice.nodes) > 0:
all_path_set = set([x for x in current_paths])
if profile[-1].candidate_paths - all_path_set != set():
print(prof)
current_slice.add_node(Node("", prof.candidate_paths - all_path_set))
factory_input.append(current_slice)
return factory_input

def to_graph(self, profile: List[Profile]):
factory_input = self.to_slices(profile)
def to_graph(self, profiles: List[Profile]):
factory_input = self.to_slices(profiles)
base_graph = SlicedGraph.load_from_slices(factory_input, self.paths)
return base_graph
2 changes: 0 additions & 2 deletions src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ def test_load_gfa_to_graph(self):
self.assertEqual(len(graph.nodes), 15)

def test_gfa_to_sliced_graph(self):
#TODO: this is currently close but not quite there.
# Slices must be fully defined in SlicedGraph.compute_slices()
graph, gfa = self.make_graph_from_gfa()
slices = SlicedGraph.from_graph(graph)
x = 'x'
Expand Down

0 comments on commit 0dc0528

Please sign in to comment.