How to use the pybel.BELGraph function in pybel

To help you get started, we’ve selected a few pybel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pybel / pybel / tests / test_manager_graph.py View on Github external
def help_reconstitute(self, node_data, namespace_dict, number_nodes, number_edges):
        """Helps test the round-trip conversion from PyBEL data dictionary to node model, then back to PyBEL node
        data dictionary and PyBEL node tuple.

        :param dict node_data: PyBEL node data dictionary
        """
        graph = BELGraph(name='test', version='0.0.0')
        make_dummy_namespaces(self.manager, graph, namespace_dict)

        node_tuple = graph.add_node_from_data(node_data)

        self.manager.insert_graph(graph, store_parts=True)
        self.assertEqual(number_nodes, self.manager.count_nodes())
        self.assertEqual(number_edges, self.manager.count_edges())

        node = self.manager.get_or_create_node(graph, node_tuple)
        self.manager.session.commit()

        self.assertEqual(node_data, node.to_json())
        self.assertEqual(node_tuple, node.to_tuple())

        self.assertEqual(node, self.manager.get_node_by_tuple(node_tuple))
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_lenient_semantic_no_failure(self):
        graph = BELGraph()
        parser = BELParser(graph, allow_naked_names=True)

        update_provenance(parser.control_parser)

        parser.bel_term.addParseAction(parser.handle_term)
        parser.bel_term.parseString('bp(ABASD)')

        node = bioprocess(namespace=DIRTY, name='ABASD')
        self.assertIn(node, graph)
github pybel / pybel / tests / test_struct / test_transformations / test_induction.py View on Github external
def test_build_pmid_set_inclusion_filter(self):
        """Test getting a sub-graph by a set of PubMed identifiers."""
        a, b, c, d, e, f = [protein(namespace='test', name=n()) for _ in range(6)]
        p1, p2, p3, p4, p5, p6 = n(), n(), n(), n(), n(), n()

        graph = BELGraph()
        keyword, url = n(), n()
        graph.namespace_url[keyword] = url
        graph.add_increases(a, b, evidence=n(), citation=p1)
        graph.add_increases(a, b, evidence=n(), citation=p2)
        graph.add_increases(b, c, evidence=n(), citation=p1)
        graph.add_increases(b, c, evidence=n(), citation=p3)
        graph.add_increases(c, d, evidence=n(), citation=p3)
        graph.add_increases(e, f, evidence=n(), citation=p4)

        subgraph = get_subgraph_by_pubmed(graph, [p1, p4])

        self.assertIsInstance(subgraph, BELGraph)
        self.assert_all_nodes_are_base_entities(subgraph)

        self.assertIn(keyword, subgraph.namespace_url)
        self.assertEqual(url, subgraph.namespace_url[keyword])
github pybel / pybel / tests / test_struct / test_transformations / test_deletions.py View on Github external
def test_no_infer_protein_fusion(self):
        """Test that no gene is inferred from a RNA fusion node."""
        partner5p = Protein(n(), n())
        partner3p = Protein(n(), n())

        p = protein_fusion(partner_3p=partner3p, partner_5p=partner5p)

        graph = BELGraph()
        graph.add_node_from_data(p)

        self.assertEqual(1, graph.number_of_nodes())
        self.assertEqual(0, graph.number_of_edges())

        enrich_protein_and_rna_origins(graph)

        self.assertEqual(1, graph.number_of_nodes())
        self.assertEqual(0, graph.number_of_edges())
github pybel / pybel / tests / test_manager_graph.py View on Github external
def test_no_protein_modification(self, mock):
        """Test that a protein node whose pmod variant is in the uncached namespaces set can't be added"""
        graph = BELGraph(name='Test No Add Nodes', version='1.0.0')

        dummy_namespace_name = n8()
        dummy_url = n()

        graph.namespace_url[dummy_namespace_name] = dummy_url
        graph.uncached_namespaces.add(dummy_url)

        node_data = protein(namespace='HGNC', name='YFG', variants=[
            pmod(name='dummy', namespace=dummy_namespace_name)
        ])

        graph.add_node_from_data(node_data)

        make_dummy_namespaces(self.manager, graph, {'HGNC': ['YFG']})
        network = self.manager.insert_graph(graph)
github pybel / pybel / tests / test_struct / test_transformations / test_induction.py View on Github external
def test_get_upstream_causal_subgraph(self):
        """Test get_upstream_causal_subgraph."""
        a, b, c, d, e, f = [protein(namespace='test', name=n()) for _ in range(6)]

        universe = BELGraph()
        universe.namespace_pattern['test'] = 'test-url'
        universe.add_increases(a, b, citation=n(), evidence=n())
        universe.add_increases(b, c, citation=n(), evidence=n())
        universe.add_association(d, a, citation=n(), evidence=n())
        universe.add_increases(e, a, citation=n(), evidence=n())
        universe.add_decreases(f, b, citation=n(), evidence=n())

        subgraph = get_upstream_causal_subgraph(universe, [a, b])

        self.assertIsInstance(subgraph, BELGraph)
        self.assert_all_nodes_are_base_entities(subgraph)

        self.assertIn('test', subgraph.namespace_pattern)
        self.assertEqual('test-url', subgraph.namespace_pattern['test'])

        self.assertIn(a, subgraph)
github pybel / pybel / tests / test_struct / test_filters / test_struct_filters.py View on Github external
def test_all_filter_no_annotations(self):
        graph = BELGraph()
        graph.add_increases(Protein(n(), n()), Protein(n(), n()), citation=n(), evidence=n())
        self.assertEqual(0, count_passed_edge_filter(graph, build_annotation_dict_all_filter({'A': {'1'}})))
github pybel / pybel / tests / test_struct / test_transformations / test_deletions.py View on Github external
def test_remove_isolated_out_of_place(self):
        """Test removing isolated nodes (out-of-place)."""
        g = BELGraph()

        g.add_edge(1, 2)
        g.add_edge(2, 3)
        g.add_node(4)

        g = remove_isolated_nodes_op(g)

        self.assertEqual(3, g.number_of_nodes())
        self.assertEqual(2, g.number_of_edges())
github pybel / pybel / tests / test_manager / test_manager_drop.py View on Github external
def test_simple(self, mock):
        """This test checks that the network can be added and dropped"""
        graph = BELGraph(name='test', version='0.0.0')
        graph.add_increases(
            yfg1,
            yfg2,
            evidence=test_evidence_text,
            citation=test_citation_dict,
            annotations={
                'Disease': {'Disease1': True},
                'Cell': {'Cell1': True}
            }
        )

        make_dummy_namespaces(self.manager, graph)
        make_dummy_annotations(self.manager, graph)

        network = self.manager.insert_graph(graph)
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def __init__(self, stmts=None, name=None, description=None, version=None,
                 authors=None, contact=None, license=None, copyright=None,
                 disclaimer=None):
        if stmts is None:
            self.statements = []
        else:
            self.statements = stmts
        if name is None:
            name = 'indra'
        if version is None:
            version = str(uuid.uuid4())
        # Create the model and assign metadata
        self.model = pybel.BELGraph(
            name=name,
            description=description,
            version=version,
            authors=authors,
            contact=contact,
            license=license,
            copyright=copyright,
            disclaimer=disclaimer,
        )
        ns_dict = {
            'HGNC': 'https://arty.scai.fraunhofer.de/artifactory/bel/'
                    'namespace/hgnc-human-genes/hgnc-human-genes-20170725.belns',
            'UP': 'https://arty.scai.fraunhofer.de/artifactory/bel/'
                  'namespace/swissprot/swissprot-20170725.belns',
            'IP': 'https://arty.scai.fraunhofer.de/artifactory/bel/'
                  'namespace/interpro/interpro-20170731.belns',