Ejemplo n.º 1
0
    def setUp(self):
        self.engine = create_engine(test_db_utils.create_engine_string())

        session_maker_obj = sessionmaker(bind=self.engine)
        self.session = session_maker_obj()

        self.metadata = MetaData(bind=self.engine)
        self.metadata.reflect()

        self.mapper = automap_base(metadata=self.metadata)
        self.mapper.prepare()

        self.graph = querying.build_graph(self.metadata)

        self.phage = self.metadata.tables["phage"]
        self.gene = self.metadata.tables["gene"]
        self.trna = self.metadata.tables["trna"]

        self.PhageID = self.phage.c.PhageID
        self.Cluster = self.phage.c.Cluster
        self.Subcluster = self.phage.c.Subcluster
        self.GeneID = self.gene.c.GeneID
        self.PhamID = self.gene.c.PhamID
        self.TrnaID = self.trna.c.GeneID
        self.AminoAcid = self.trna.c.AminoAcid
Ejemplo n.º 2
0
    def build_graph(self):
        """Create and store SQLAlchemy MetaData related NetworkX Graph object.
        """
        if self._metadata is None:
            self.build_metadata()

        self._graph = querying.build_graph(self._metadata)
Ejemplo n.º 3
0
    def test_build_onclause_2(self):
        """Verify build_onclause() detects table redundencies
        """
        graph = querying.build_graph(self.metadata)

        table = querying.build_onclause(graph, "phage", "phage")

        self.assertEqual(table, self.phage)
Ejemplo n.º 4
0
    def test_build_onclause_1(self, TranslateTable):
        TranslateTable.return_value = "phage"
        graph = querying.build_graph(self.metadata)

        table = querying.build_onclause(graph, "phage", "phage")

        TranslateTable.assert_called_with(self.metadata, "phage")
        self.assertEqual(table, self.phage)
Ejemplo n.º 5
0
    def test_build_onclause_1(self, translate_table_mock):
        """Verify translate_table() is called with the correct parameters.
        """
        translate_table_mock.return_value = "phage"
        graph = querying.build_graph(self.metadata)

        table = querying.build_onclause(graph, "phage", "phage")

        translate_table_mock.assert_called_with(self.metadata, "phage")
Ejemplo n.º 6
0
    def test_build_graph_2(self):
        graph = querying.build_graph(self.metadata)

        self.assertTrue("phage" in graph.nodes)
        self.assertTrue("gene" in graph.nodes)
        self.assertTrue("trna" in graph.nodes)

        self.assertEqual(graph.nodes["phage"]["table"], self.phage)
        self.assertEqual(graph.nodes["gene"]["table"], self.gene)
        self.assertEqual(graph.nodes["trna"]["table"], self.trna)
Ejemplo n.º 7
0
    def test_build_graph_2(self):
        """Verify build_graph() stores Table objects with correct structure.
        """
        graph = querying.build_graph(self.metadata)

        self.assertTrue("phage" in graph.nodes)
        self.assertTrue("gene" in graph.nodes)
        self.assertTrue("trna" in graph.nodes)

        self.assertEqual(graph.nodes["phage"]["table"], self.phage)
        self.assertEqual(graph.nodes["gene"]["table"], self.gene)
        self.assertEqual(graph.nodes["trna"]["table"], self.trna)
Ejemplo n.º 8
0
    def test_build_graph_3(self):
        graph = querying.build_graph(self.metadata)

        phage = graph.nodes["phage"]["table"]
        gene = graph.nodes["gene"]["table"]
        trna = graph.nodes["trna"]["table"]

        phage_gene_edge = graph["gene"]["phage"]
        phage_trna_edge = graph["trna"]["phage"]

        self.assertEqual(phage_gene_edge["key"], self.PhageGeneKey)
        self.assertEqual(phage_trna_edge["key"], self.PhageTrnaKey)
Ejemplo n.º 9
0
    def test_build_graph_3(self):
        """Verify build_graph() stores foreign keys with correct structure.
        """
        graph = querying.build_graph(self.metadata)

        phage = graph.nodes["phage"]["table"]
        gene = graph.nodes["gene"]["table"]
        trna = graph.nodes["trna"]["table"]

        phage_gene_edge = graph["gene"]["phage"]
        phage_trna_edge = graph["trna"]["phage"]

        self.assertEqual(phage_gene_edge["key"], self.PhageGeneKey)
        self.assertEqual(phage_trna_edge["key"], self.PhageTrnaKey)
Ejemplo n.º 10
0
    def test_build_graph_1(self):
        """Verify build_graph() creates a NetworkX Graph object.
        """
        graph = querying.build_graph(self.metadata)

        self.assertTrue(isinstance(graph, Graph))
Ejemplo n.º 11
0
    def test_build_onclause_2(self):
        graph = querying.build_graph(self.metadata)

        querying.build_onclause(graph, "phage", "gene")
Ejemplo n.º 12
0
    def test_build_graph_1(self):
        graph = querying.build_graph(self.metadata)

        self.assertTrue(isinstance(graph, Graph))