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

Commit

Permalink
Merge pull request #7 from graph-genome/path
Browse files Browse the repository at this point in the history
Version2; Summary Layer
  • Loading branch information
6br authored Jul 8, 2019
2 parents 3ea4a9d + e5c6172 commit 9466186
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/gfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def from_graph(cls, graph: Graph):
path_list[path].append(segment_id)
for path_key in path_list:
path_values = [str(x) for x in path_list[path_key]]
gfa.add_line('\t'.join(['P', path_key, "+,".join(path_values)+"+", ",".join(['*' for x in path_values])]))
gfa.add_line('\t'.join(['P', path_key, "+,".join(path_values)+"+", ",".join(['*' for _ in path_values])]))
return cls(gfa)

@property
Expand All @@ -128,7 +128,6 @@ def to_graph(self):

# Extract all paths into graph
for path in self.gfa.paths:
### TODO: Replace it as a path class object.
for node in path.segment_names:
path_dict[node.name + node.orient].append(path.name)
for node_pair in pairwise(path.segment_names):
Expand Down
45 changes: 24 additions & 21 deletions src/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,33 @@ def smallest(self):
version = 1.0


class NodeIndex(NamedTuple):
node: Node
strand: str

class Path:
"""TODO: Paths have not been implemented yet."""
def __init__(self, name: str, nodes: List[NodeIndex]):
self.name = name
self.nodes = nodes
self.position_checkpoints = {}

def __getitem__(self, i):
return self.nodes[i]

def __repr__(self):
"""Warning: the representation strings are very sensitive to whitespace"""
return self.nodes.__repr__()

def to_gfa(self):
return '\t'.join(['P', self.name, "+,".join([x.node.name + x.strand for x in self.nodes])+"+", ",".join(['*' for x in self.nodes])])


class Graph:
def __init__(self, cmd: List):
def __init__(self, cmd: List, paths: List[Path] = []):
"""Factory for generating graphs from a representation"""
self.slices = []
self.paths = paths
if isinstance(cmd, str):
cmd = eval(cmd)
for sl in cmd:
Expand Down Expand Up @@ -159,26 +182,6 @@ def save_as_pickle(self, file):
def save_as_xg(self):
raise NotImplementedError()

class NodeIndex(NamedTuple):
node: Node
strand: str

class Path:
"""TODO: Paths have not been implemented yet."""
def __init__(self, name: str, nodes: List[NodeIndex]):
self.name = name
self.nodes = nodes
self.position_checkpoints = {}

def __getitem__(self, i):
return self.nodes[i]

def __repr__(self):
"""Warning: the representation strings are very sensitive to whitespace"""
return self.nodes.__repr__()

def to_gfa(self):
return '\t'.join(['P', self.name, "+,".join([x.node.name + x.strand for x in self.nodes])+"+", ",".join(['*' for x in self.nodes])])

if __name__ == "__main__":
location_of_xg = sys.argv[0]
Expand Down
2 changes: 1 addition & 1 deletion src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def is_different(gfa1, gfa2):
if l.line.from_segment.name != l2.line.from_segment.name:
print(l, l2)
different = True
if l.line.to_segment.name != l.line.to_segment.name:
if l.line.to_segment.name != l2.line.to_segment.name:
print(l, l2)
different = True
for s in gfa1.edges:
Expand Down
2 changes: 1 addition & 1 deletion test/test2.gfa
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
H VN:Z:1.0
P x 1+,3+,5+,6+,8+,9+,11+,12+,14+,15+ *,*,*,*,*,*,*,*,*
P y 1+,2+,5+,6+,8+,9+,11+,12+,14+,15+ *,*,*,*,*,*,*,*,*
P z 1+,2+,5+,6+,7+,9+,11+,12+,14+,15+ *,*,*,*,*,*,*,*,*
P z 1+,2+,4+,6+,7+,9+,10+,12+,14+,15+ *,*,*,*,*,*,*,*,*
P a 12+,13+,15+ *,*
S 1 CAAATAAG
L 1 + 2 + 0M
Expand Down

0 comments on commit 9466186

Please sign in to comment.