From 0a19fd9638a81b132eb8753bdcf34b92f0f6d079 Mon Sep 17 00:00:00 2001 From: Toshiyuki Yokoyama Date: Thu, 20 Jun 2019 22:00:36 +0900 Subject: [PATCH] #4 Fix directory --- .gitignore | 4 +++- gfa.py => src/gfa.py | 0 src/graph.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ src/test.py | 20 ++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) rename gfa.py => src/gfa.py (100%) create mode 100644 src/graph.py create mode 100644 src/test.py diff --git a/.gitignore b/.gitignore index 84a7599..46d43f8 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,6 @@ # Tests test/*.xg test/*.pickle -test/xg \ No newline at end of file +test/xg + +__pycache__ diff --git a/gfa.py b/src/gfa.py similarity index 100% rename from gfa.py rename to src/gfa.py diff --git a/src/graph.py b/src/graph.py new file mode 100644 index 0000000..84bb517 --- /dev/null +++ b/src/graph.py @@ -0,0 +1,50 @@ +from typing import List, NamedTuple +import pickle + +class PathIndex(NamedTuple): + node: Node + index: int + +class Graph: + version = 1.0 + def __init__(self, nodes: list(Nodes), paths: list(Paths)): + self.nodes = nodes + self.paths = paths + + def load_from_pickle(self, file: str): + self = pickle.load(file) + + def load_form_xg(self, file: str, xg_bin: str): + raise NotImplementedError() + + def dump(): + raise NotImplementedError() + + def save_as_pickle(): + pickle.dump(self, file) + + def save_as_xg(): + raise NotImplementedError() + +class Node: + def __init__(self, id: int, sequence: str, paths: list(PathIndex)): + self.id = id + self.sequence = sequence + self.paths = paths + #self.strand = strand + + def alternative_nodes(self): + #WIP + +class Path: + def __init__(self, name: str, nodes: list(Node)): + self.name = name + self.nodes = paths + +if __name__ == "__main__": + location_of_xg = sys.argv[0] + + ### Usage + graph = Graph.load_form_xg + graph.save_as_pickle() + diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..0386258 --- /dev/null +++ b/src/test.py @@ -0,0 +1,20 @@ +import unittest +from gfa import GFA + +class GFATest(unittest.TestCase): + """ test class of gfa.py + """ + + def test_gfa(self): + ### Usage + self.maxDiff = None + location_of_xg = "test/xg" + graph = GFA.load_from_gfa("test/test.gfa") + graph.save_as_xg("test/test.xg", location_of_xg) + graph2 = GFA.load_form_xg("test/test.xg", location_of_xg) + self.assertEqual(len(graph.gfa.to_gfa1_s().split("\n")), len(graph2.gfa.to_gfa1_s().split("\n"))) + +if __name__ == "__main__": + unittest.main() + +