Ejemplo n.º 1
0
    def test_infer_on_sialic_acid_example(self):
        sgc = sialic_acid_graph.copy()

        self.assertFalse(sgc.has_node_with_data(trem2_gene))
        self.assertFalse(sgc.has_node_with_data(trem2_rna))

        infer_central_dogma(sgc)

        self.assertTrue(sgc.has_node_with_data(trem2_gene))
        self.assertTrue(sgc.has_node_with_data(trem2_rna))

        prune_central_dogma(sgc)

        self.assertFalse(sgc.has_node_with_data(trem2_gene))
        self.assertFalse(sgc.has_node_with_data(trem2_rna))
Ejemplo n.º 2
0
    def test_add_and_remove_annotation(self):
        """Test adding and removing annotations.

        See: :func:`pybel.struct.mutation.add_annotation_value` and
        :func:`pybel.struct.mutation.remove_annotation_value` functions.
        """
        graph = sialic_acid_graph.copy()
        annotation = 'test-annotation'
        value = 'test-value'
        url = n()

        graph.annotation_url[annotation] = url

        add_annotation_value(graph, annotation, value)

        for u, v, d in graph.edges(data=True):
            annotations = d.get(ANNOTATIONS)

            if annotations is None:
                continue

            self.assertIn(annotation, annotations)
            self.assertIn(value, annotations[annotation])

        remove_annotation_value(graph, annotation, value)

        for u, v, d in graph.edges(data=True):
            annotations = d.get(ANNOTATIONS)

            if annotations is None:
                continue

            annotation_values = annotations.get(annotation)

            if annotation_values is None:
                continue

            self.assertNotIn(value, annotation_values)
Ejemplo n.º 3
0
    def test_reload(self, mock_get):
        """Test that a graph with the same name and version can't be added twice."""
        graph = sialic_acid_graph.copy()
        self.assertEqual('1.0.0', graph.version)

        to_database(graph, manager=self.manager)
        time.sleep(1)

        self.assertEqual(1, self.manager.count_networks())

        networks = self.manager.list_networks()
        self.assertEqual(1, len(networks))

        network = networks[0]
        self.assertEqual(graph.name, network.name)
        self.assertEqual(graph.version, network.version)
        self.assertEqual(graph.description, network.description)

        reconstituted = self.manager.get_graph_by_name_version(
            graph.name, graph.version)

        self.assertIsInstance(reconstituted, BELGraph)
        self.assertEqual(graph.nodes(data=True),
                         reconstituted.nodes(data=True))
        # self.bel_thorough_reconstituted(reconstituted)

        self.assertEqual(1, self.manager.count_networks())

        graph_copy = graph.copy()
        graph_copy.version = '1.0.1'
        network_copy = self.manager.insert_graph(graph_copy)

        time.sleep(
            1)  # Sleep so the first graph always definitely goes in first

        self.assertNotEqual(network.id, network_copy.id)

        self.assertTrue(
            self.manager.has_name_version(graph_copy.name, graph_copy.version))
        self.assertFalse(self.manager.has_name_version('wrong name', '0.1.2'))
        self.assertFalse(
            self.manager.has_name_version(graph_copy.name, '0.1.2'))
        self.assertFalse(
            self.manager.has_name_version('wrong name', graph_copy.version))

        self.assertEqual(2, self.manager.count_networks())

        self.assertEqual(
            '1.0.1',
            self.manager.get_most_recent_network_by_name(graph.name).version)

        query_ids = {-1, network.id, network_copy.id}
        query_networks_result = self.manager.get_networks_by_ids(query_ids)
        self.assertEqual(2, len(query_networks_result))
        self.assertEqual({network.id, network_copy.id},
                         {network.id
                          for network in query_networks_result})

        expected_versions = {'1.0.1', '1.0.0'}
        self.assertEqual(expected_versions,
                         set(self.manager.get_network_versions(graph.name)))

        exact_name_version = from_database(graph.name,
                                           graph.version,
                                           manager=self.manager)
        self.assertEqual(graph.name, exact_name_version.name)
        self.assertEqual(graph.version, exact_name_version.version)

        exact_name_version = from_database(graph.name,
                                           '1.0.1',
                                           manager=self.manager)
        self.assertEqual(graph.name, exact_name_version.name)
        self.assertEqual('1.0.1', exact_name_version.version)

        most_recent_version = from_database(graph.name, manager=self.manager)
        self.assertEqual(graph.name, most_recent_version.name)
        self.assertEqual('1.0.1', exact_name_version.version)

        recent_networks = list(self.manager.list_recent_networks()
                               )  # just try it to see if it fails
        self.assertIsNotNone(recent_networks)
        self.assertEqual([(network.name, '1.0.1')],
                         [(n.name, n.version) for n in recent_networks])
        self.assertEqual('1.0.1', recent_networks[0].version)