def test_gap(): gap = Agent('RASA1', mods=[ModCondition('phosphorylation')], db_refs={'HGNC': '9871'}) ras = Agent('KRAS', db_refs={'HGNC': '6407'}) stmt = Gap(gap, ras) pba = pa.PybelAssembler([stmt]) belgraph = pba.make_model() assert len(belgraph) == 3 assert belgraph.number_of_edges() == 2 gap_reference_node = protein(namespace='HGNC', name='RASA1') gap_node = gap_reference_node.with_variants(pmod('Ph')) ras_node = protein(namespace='HGNC', name='KRAS') assert gap_reference_node in belgraph assert gap_node in belgraph assert ras_node in belgraph edge_data = get_edge_data(belgraph, gap_node, ras_node) edge = { pc.RELATION: pc.DIRECTLY_DECREASES, pc.SUBJECT: activity('gap'), pc.OBJECT: activity('gtp') } assert edge_data == edge
def test_no_activity_on_bioprocess(): yfg_agent = Agent('PPP1R13L', db_refs={'HGNC': id('PPP1R13L')}) apoptosis_agent = Agent('apoptotic process', db_refs={'GO': 'GO:0006915'}) stmt = Activation(yfg_agent, apoptosis_agent) pba = pa.PybelAssembler([stmt]) belgraph = pba.make_model() assert len(belgraph) == 2 assert belgraph.number_of_edges() == 1 yfg_pybel = protein('HGNC', 'PPP1R13L') apoptosis_pybel = bioprocess('GO', 'GO:0006915') assert yfg_pybel in belgraph assert apoptosis_pybel in belgraph _, _, e = list(belgraph.edges(data=True))[0] assert pc.OBJECT not in e
def test_rxn_with_controller(): hk1 = Agent('HK1', db_refs={'HGNC': id('HK1')}) glu = Agent('D-GLUCOSE', db_refs={'CHEBI': 'CHEBI:17634'}) g6p = Agent('GLUCOSE-6-PHOSPHATE', db_refs={'CHEBI': 'CHEBI:4170'}) stmt = Conversion(hk1, [glu], [g6p]) pba = pa.PybelAssembler([stmt]) belgraph = pba.make_model() # The graph should contain the node for the reaction as well as nodes # for all of the members assert len(belgraph) == 4 # check the catalyst makes it assert protein(namespace='HGNC', name='HK1') in belgraph # The reaction data should be the same as before assert chebi_17534 in belgraph assert chebi_4170 in belgraph assert chebi_17534_to_4170 in belgraph
def test_gef(): gef = Agent('SOS1', mods=[ModCondition('phosphorylation')], db_refs={'HGNC': '11187'}) ras = Agent('KRAS', db_refs={'HGNC': '6407'}) stmt = Gef(gef, ras) pba = pa.PybelAssembler([stmt]) belgraph = pba.make_model() assert len(belgraph) == 3 assert belgraph.number_of_edges() == 2 gef_reference_node = protein(namespace='HGNC', name='SOS1') gef_node = gef_reference_node.with_variants(pmod('Ph')) assert gef_reference_node in belgraph assert gef_node in belgraph assert kras_node in belgraph edge_data = get_edge_data(belgraph, gef_node, kras_node) edge = { pc.RELATION: pc.DIRECTLY_INCREASES, pc.SUBJECT: activity('gef'), pc.OBJECT: activity('gtp') } assert edge_data == edge
def prosite(name=None, identifier=None): return protein(namespace=PROSITE, name=name, identifier=identifier)
def test_protein_fragment(self): node = protein(name='APP', namespace='HGNC', variants=[fragment(start=672, stop=713)]) self.assertEqual('p(HGNC:APP, frag("672_713"))', str(node))
def test_decreases(self): """Test parsing a decreases relation with a reaction. 3.1.3 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#Xdecreases """ statement = 'pep(p(FPLX:CAPN, location(GO:intracellular))) -| reaction(reactants(p(HGNC:CDK5R1)),products(p(HGNC:CDK5)))' result = self.parser.relation.parseString(statement) expected_dict = { SUBJECT: { MODIFIER: ACTIVITY, TARGET: { FUNCTION: PROTEIN, CONCEPT: { NAMESPACE: 'FPLX', NAME: 'CAPN', }, LOCATION: {NAMESPACE: 'GO', NAME: 'intracellular'} }, EFFECT: { NAME: 'pep', NAMESPACE: BEL_DEFAULT_NAMESPACE }, }, RELATION: DECREASES, OBJECT: { FUNCTION: REACTION, REACTANTS: [ { FUNCTION: PROTEIN, CONCEPT: { NAMESPACE: 'HGNC', NAME: 'CDK5R1', }, } ], PRODUCTS: [ { FUNCTION: PROTEIN, CONCEPT: { NAMESPACE: 'HGNC', NAME: 'CDK5', }, }, ], }, } self.assertEqual(expected_dict, result.asDict()) sub = protein('FPLX', 'CAPN') self.assert_has_node(sub) obj_member_1 = protein('HGNC', 'CDK5R1') self.assert_has_node(obj_member_1) obj_member_2 = protein('HGNC', 'CDK5') self.assert_has_node(obj_member_2) obj = reaction(reactants=[obj_member_1], products=[obj_member_2]) self.assert_has_node(obj) self.assert_has_edge(obj, obj_member_1, relation=HAS_REACTANT) self.assert_has_edge(obj, obj_member_2, relation=HAS_PRODUCT) expected_edge_attributes = { RELATION: DECREASES, SUBJECT: { MODIFIER: ACTIVITY, EFFECT: { NAME: 'pep', NAMESPACE: BEL_DEFAULT_NAMESPACE, }, LOCATION: { NAMESPACE: 'GO', NAME: 'intracellular', } } } self.assertEqual(expected_edge_attributes[SUBJECT], activity(name='pep', location=Entity(name='intracellular', namespace='GO'))) self.assert_has_edge(sub, obj, **expected_edge_attributes)
for act in results: molecule = act['molecule_chembl_id'] relation = act['standard_relation'] value = act['standard_value'] document = act['document_chembl_id'] evidence = act['assay_description'] if relation == '=': if float(value) > 40000: continue graph.add_inhibits(abundance(namespace='CHEMBL', name=molecule), node, citation={ CITATION_TYPE: 'CHEMBL', CITATION_REFERENCE: document }, evidence=evidence) if __name__ == '__main__': from pybel import BELGraph from pybel.dsl import protein graph_ = BELGraph() node_ = graph_.add_node_from_data(protein(namespace='HGNC', name='PDE5A')) enrich_target(graph_, node_)
def setUp(self): self.g = BELGraph() self.u = protein(name='u', namespace='TEST') self.v = protein(name='v', namespace='TEST') self.g.add_node_from_data(self.u) self.g.add_node_from_data(self.v)
def test_with_variants_list(self): """Test the `with_variant` function in :class:`CentralDogmaAbundance`s.""" app = protein(name='APP', namespace='HGNC') ab42 = app.with_variants([fragment(start=672, stop=713)]) self.assertEqual('p(HGNC:APP)', app.as_bel()) self.assertEqual('p(HGNC:APP, frag(672_713))', ab42.as_bel())
"""Tests for graph operations.""" import unittest from pybel import BELGraph from pybel.dsl import protein from pybel.struct.operations import ( left_full_join, left_node_intersection_join, left_outer_join, node_intersection, union, ) from pybel.testing.utils import n p1, p2, p3, p4, p5, p6, p7, p8 = (protein(namespace='HGNC', name=n()) for _ in range(8)) class TestLeftFullJoin(unittest.TestCase): """Tests the variants of the left full join, including the exhaustive vs. hash algorithms and calling by function or magic functions""" def setUp(self): """Set up tests for the left full join with two example graphs.""" g = BELGraph() g.add_increases(p1, p2, citation='PMID1', evidence='Evidence 1') self.tag = 'EXTRANEOUS' self.tag_value = 'MOST DEFINITELY' h = BELGraph()
complex_abundance, hgvs, pmod, protein, reaction from indra.assemblers.pybel import assembler as pa from indra.databases import hgnc_client from indra.statements import * def id(gene_name): return hgnc_client.get_hgnc_id(gene_name) phos_dsl = pmod('Ph', 'Ser', 218) ub_dsl = pmod('Ub', 'Ser', 218) egfr_phos_dsl = pmod('Ph', 'Tyr', 1173) braf_dsl = protein(namespace='HGNC', name='BRAF', identifier='1097') map2k1_dsl = protein(namespace='HGNC', name='MAP2K1', identifier='6840') tp53_dsl = protein(namespace='HGNC', name='TP53', identifier='11998') mdm2_dsl = protein(namespace='HGNC', name='MDM2', identifier='6973') egfr_dsl = protein(namespace='HGNC', name='EGFR', identifier='3236') chebi_17534 = abundance(namespace='CHEBI', name='D-glucose', identifier='17634') chebi_4170 = abundance(namespace='CHEBI', name='D-glucopyranose 6-phosphate', identifier='4170') chebi_17534_to_4170 = reaction(chebi_17534, chebi_4170) grb2_dsl = protein(namespace='HGNC', name='GRB2', identifier='4566') sos1_dsl = protein(namespace='HGNC', name='SOS1', identifier='11187') sos1_phosphorylated_dsl = sos1_dsl.with_variants(pmod('Ph')) kras_node = protein(namespace='HGNC', name='KRAS', identifier='6407')
# -*- coding: utf-8 -*- from pybel import BELGraph from pybel.constants import INCREASES, PROTEIN from pybel.dsl import protein from pybel.manager.models import Edge, Namespace, NamespaceEntry, Network, Node from pybel.testing.cases import TemporaryCacheMixin from pybel.testing.mocks import mock_bel_resources from pybel.testing.utils import make_dummy_annotations, make_dummy_namespaces, n from tests.constants import test_citation_dict, test_evidence_text yfg1 = protein(name='YFG1', namespace='HGNC') yfg2 = protein(name='YFG1', namespace='HGNC') class TestReconstituteNodeTuples(TemporaryCacheMixin): @mock_bel_resources def test_simple(self, mock): """This test checks that the network can be added and dropped""" graph = BELGraph(name='test', version='0.0.0') namespaces = {'HGNC': ['YFG1', 'YFG2']} annotations = {'Disease': ['Disease1', 'Disease2'], 'Cell': ['Cell1']} make_dummy_namespaces(self.manager, graph, namespaces) make_dummy_annotations(self.manager, graph, annotations) graph.add_increases(yfg1, yfg2, evidence=test_evidence_text, citation=test_citation_dict,
def node_to_bel(node: Dict, graph, hgnc_manager: HgncManager, chebi_manager: ChebiManager) -> BaseEntity: """Convert node dictionary to BEL node object.""" node_types = node['entity_type'] identifier, name, namespace = get_valid_node_parameters( node, hgnc_manager, chebi_manager) members = set() if namespace == 'hgnc_multiple_entry': return composite_abundance(process_multiple_proteins(identifier)) elif 'Protein' in node_types: return protein(namespace=namespace.upper(), name=name, identifier=identifier) elif 'Dna' in node_types: return gene(namespace=namespace.upper(), name=name, identifier=identifier) elif 'Rna' in node_types: return rna(namespace=namespace.upper(), name=name, identifier=identifier) elif 'SmallMolecule' in node_types: return abundance(namespace=namespace.upper(), name=name, identifier=identifier) elif 'PhysicalEntity' in node_types: return abundance(namespace=namespace.upper(), name=name, identifier=identifier) elif 'Complex' in node_types: complex_components = node.get('complex_components') if complex_components: for component in complex_components: bel_node = node_to_bel(component, graph, hgnc_manager, chebi_manager) members.add(bel_node) if members: return complex_abundance( name=node.get('display_name'), members=members, identifier=identifier, namespace=namespace.upper(), ) else: return NamedComplexAbundance( name=node.get('display_name'), identifier=identifier, namespace=namespace.upper(), ) elif 'Pathway' in node_types: bioprocess_node = bioprocess(identifier=identifier, name=name, namespace=namespace.upper()) graph.add_node_from_data(bioprocess_node) return bioprocess_node else: logger.warning('Entity type not recognized', node_types)
# fill temporary database with test data cls.manager.populate(url=pathlib.Path(gene_sets_path).as_uri()) # PyBEL manager cls.pybel_manager = pybel.Manager(engine=cls.engine, session=cls.session) cls.pybel_manager.create_all() @classmethod def tearDownClass(cls): """Close the connection in the manager and deletes the temporary database.""" cls.session.close() super().tearDownClass() protein_a = protein(namespace=HGNC, name='DNMT1') protein_b = protein(namespace=HGNC, name='POLA1') gene_c = gene(namespace=HGNC, name='PGLS') pathway_a = bioprocess(namespace=WIKIPATHWAYS, name='Codeine and Morphine Metabolism') def get_enrichment_graph(): """Build a simple test graph with 2 proteins, one gene, and one kegg pathway all contained in HGNC.""" graph = BELGraph( name='My test graph for enrichment', version='0.0.1' ) protein_a_tuple = graph.add_node_from_data(protein_a) protein_b_tuple = graph.add_node_from_data(protein_b) gene_c_tuple = graph.add_node_from_data(gene_c)
def test_protein_pmod(self): node = protein(name='PLCG1', namespace='HGNC', variants=[pmod(name='Ph', code='Tyr')]) self.assertEqual('p(HGNC:PLCG1, pmod(Ph, Tyr))', str(node))
def test_protein_reference(self): self.assertEqual('p(HGNC:AKT1)', str(protein(namespace='HGNC', name='AKT1')))
def uniprot(name=None, identifier=None): return protein(namespace=UNIPROT, name=name, identifier=identifier)
def test_1(self): """Test iterating over annotation/value pairs.""" graph = BELGraph() graph.annotation_list.update({ 'A': set('1234'), 'B': set('XYZ'), 'C': set('abcde'), }) u = protein('HGNC', name='U') v = protein('HGNC', name='V') w = protein('HGNC', name='W') graph.add_increases(u, v, evidence=n(), citation=n(), annotations={ 'A': {'1', '2'}, 'B': {'X'} }) graph.add_increases( u, w, evidence=n(), citation=n(), annotations={ 'A': {'1', '3'}, 'C': {'a'}, }, ) graph.add_increases( w, v, evidence=n(), citation=n(), ) x = dict( Counter((key, entity.identifier) for key, entity in iter_annotation_value_pairs(graph))) self.assertEqual( { ('A', '1'): 2, ('A', '2'): 1, ('A', '3'): 1, ('B', 'X'): 1, ('C', 'a'): 1, }, x) y = Counter(iter_annotation_values(graph, 'A')) self.assertEqual(x['A', '1'] + x['A', '2'] + x['A', '3'], sum(y.values())) y = Counter(iter_annotation_values(graph, 'B')) self.assertEqual(x['B', 'X'], sum(y.values())) y = Counter(iter_annotation_values(graph, 'C')) self.assertEqual(x['C', 'a'], sum(y.values()))
# -*- coding: utf-8 -*- import json import unittest from pybel import BELGraph from pybel.constants import * from pybel.dsl import protein from pybel.struct.operations import ( left_full_join, left_node_intersection_join, left_outer_join, node_intersection, union, ) HGNC = 'HGNC' p1 = protein(namespace=HGNC, name='a') p2 = protein(namespace=HGNC, name='b') p3 = protein(namespace=HGNC, name='c') p1_tuple = p1.as_tuple() p2_tuple = p2.as_tuple() p3_tuple = p3.as_tuple() class TestLeftFullJoin(unittest.TestCase): """Tests the variants of the left full join, including the exhaustive vs. hash algorithms and calling by function or magic functions""" def setUp(self): g = BELGraph()
import pybel.constants as pc from indra.assemblers.pybel import assembler as pa from indra.databases import hgnc_client from indra.statements import * from pybel.dsl import abundance, activity, bioprocess, complex_abundance, hgvs, pmod, protein, reaction def id(gene_name): return hgnc_client.get_hgnc_id(gene_name) phos_dsl = pmod('Ph', 'Ser', 218) ub_dsl = pmod('Ub', 'Ser', 218) egfr_phos_dsl = pmod('Ph', 'Tyr', 1173) braf_dsl = protein(namespace='HGNC', name='BRAF') map2k1_dsl = protein(namespace='HGNC', name='MAP2K1') tp53_dsl = protein(namespace='HGNC', name='TP53') mdm2_dsl = protein(namespace='HGNC', name='MDM2') egfr_dsl = protein(namespace='HGNC', name='EGFR') chebi_17534 = abundance(namespace='CHEBI', name='17634') chebi_4170 = abundance(namespace='CHEBI', name='4170') chebi_17534_to_4170 = reaction(chebi_17534, chebi_4170) grb2_dsl = protein(namespace='HGNC', name='GRB2') sos1_dsl = protein(namespace='HGNC', name='SOS1') sos1_phosphorylated_dsl = sos1_dsl.with_variants(pmod('Ph')) kras_node = protein(namespace='HGNC', name='KRAS') egfr_grb2_sos1_complex_dsl = complex_abundance([
import unittest from pybel import BELGraph from pybel.constants import CITATION_AUTHORS, CITATION_TYPE_PUBMED, IDENTIFIER, NAMESPACE from pybel.dsl import BaseEntity, gene, protein, rna from pybel.struct.mutation.expansion import expand_upstream_causal from pybel.struct.mutation.induction import get_subgraph_by_annotation_value from pybel.struct.mutation.induction.citation import get_subgraph_by_authors, get_subgraph_by_pubmed from pybel.struct.mutation.induction.paths import get_nodes_in_all_shortest_paths, get_subgraph_by_all_shortest_paths from pybel.struct.mutation.induction.upstream import get_upstream_causal_subgraph from pybel.struct.mutation.induction.utils import get_subgraph_by_induction from pybel.testing.utils import n trem2_gene = gene(namespace='HGNC', name='TREM2') trem2_rna = rna(namespace='HGNC', name='TREM2') trem2_protein = protein(namespace='HGNC', name='TREM2') class TestGraphMixin(unittest.TestCase): """A mixin to enable testing nodes and edge membership in the graph.""" def assert_in_edge(self, source, target, graph): """Assert the edge is in the graph. :param source: :param target: :type graph: pybel.BELGraph :rtype: bool """ self.assertIn(target, graph[source]) def assert_all_nodes_are_base_entities(self, graph):
def test_translation(self): """ 3.3.3 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_translatedto """ statement = 'r(HGNC:AKT1,loc(GOCC:intracellular)) >> p(HGNC:AKT1)' result = self.parser.relation.parseString(statement) # [[RNA, ['HGNC', 'AKT1']], TRANSLATED_TO, [PROTEIN, ['HGNC', 'AKT1']]] expected_result = { SUBJECT: { FUNCTION: RNA, NAMESPACE: 'HGNC', NAME: 'AKT1', LOCATION: { NAMESPACE: 'GOCC', NAME: 'intracellular' } }, RELATION: TRANSLATED_TO, OBJECT: { FUNCTION: PROTEIN, NAMESPACE: 'HGNC', NAME: 'AKT1', } } self.assertEqual(expected_result, result.asDict()) self.assertEqual(2, self.graph.number_of_nodes()) source = RNA, 'HGNC', 'AKT1' source_dict = rna(name='AKT1', namespace='HGNC') self.assertIn(source, self.graph) self.assertEqual(source_dict, self.graph.node[source]) self.assertTrue(self.graph.has_node_with_data(source_dict)) target = PROTEIN, 'HGNC', 'AKT1' target_dict = protein(name='AKT1', namespace='HGNC') self.assertIn(target, self.graph) self.assertEqual(target_dict, self.graph.node[target]) self.assertTrue(self.graph.has_node_with_data(target_dict)) self.assertEqual(1, self.graph.number_of_edges()) self.assertTrue(self.graph.has_edge(source, target)) key_data = self.parser.graph.edge[source][target] self.assertEqual(1, len(key_data)) key = list(key_data)[0] data = key_data[key] self.assertIn(RELATION, data) self.assertEqual(TRANSLATED_TO, data[RELATION]) calculated_source_data = self.graph.node[source] self.assertTrue(calculated_source_data) calculated_target_data = self.graph.node[target] self.assertTrue(calculated_target_data) calculated_edge_bel = edge_to_bel(calculated_source_data, calculated_target_data, data=data) self.assertEqual( 'r(HGNC:AKT1, loc(GOCC:intracellular)) translatedTo p(HGNC:AKT1)', calculated_edge_bel)
def test_composite_abundance(self): node = composite_abundance(members=[ protein(namespace='HGNC', name='FOS'), protein(namespace='HGNC', name='JUN') ]) self.assertEqual('composite(p(HGNC:FOS), p(HGNC:JUN))', str(node))
from pybel.language import Entity from pybel.struct.filters import false_node_predicate, true_node_predicate from pybel.struct.filters.edge_predicate_builders import build_relation_predicate from pybel.struct.filters.edge_predicates import ( edge_has_activity, edge_has_annotation, edge_has_degradation, edge_has_translocation, has_authors, has_polarity, has_provenance, has_pubmed, is_associative_relation, is_causal_relation, is_direct_causal_relation, ) from pybel.struct.filters.node_predicates import ( has_activity, has_causal_in_edges, has_causal_out_edges, has_fragment, has_gene_modification, has_hgvs, has_protein_modification, has_variant, is_abundance, is_causal_central, is_causal_sink, is_causal_source, is_degraded, is_gene, is_pathology, is_protein, is_translocated, none_of, not_pathology, one_of, ) from pybel.testing.utils import n p1 = protein(name='BRAF', namespace='HGNC') p2 = protein(name='BRAF', namespace='HGNC', variants=[hgvs('p.Val600Glu'), pmod('Ph')]) p3 = protein(name='APP', namespace='HGNC', variants=fragment(start=672, stop=713)) p4 = protein(name='2', namespace='HGNC') g1 = gene(name='BRAF', namespace='HGNC', variants=gmod('Me')) class TestNodePredicates(unittest.TestCase): """Tests for node predicates.""" def test_none_data(self): """Test permissive node predicate with a node data dictionary.""" self.assertTrue(true_node_predicate(p1)) self.assertFalse(false_node_predicate(p1))
def test_fragments(self): self.assertTrue(has_fragment( protein(name='APP', namespace='HGNC', variants=[fragment(start=672, stop=713, description='random text')]))) self.assertTrue(has_fragment(protein(name='APP', namespace='HGNC', variants=[fragment()])))
# -*- coding: utf-8 -*- """Tests for functions for grouping BEL graphs into sub-graphs.""" import unittest from pybel import BELGraph from pybel.constants import CITATION_TYPE_PUBMED, FUNCTION, PROTEIN from pybel.dsl import protein from pybel.struct.grouping import get_subgraphs_by_annotation, get_subgraphs_by_citation from pybel.testing.utils import n test_namespace_url = n() test_annotation_url = n() citation, evidence = n(), n() a, b, c, d = [protein(namespace='test', name=str(i)) for i in range(4)] class TestAnnotation(unittest.TestCase): """Tests for getting sub-graphs by annotation.""" def setUp(self): """Set up the test case with a pre-populated BEL graph.""" self.graph = BELGraph() self.graph.namespace_url['test'] = test_namespace_url self.graph.annotation_url['subgraph'] = test_annotation_url self.graph.add_increases(a, b, citation=citation, evidence=evidence, annotations={'subgraph': {'1', '2'}})
# fill temporary database with test data cls.manager.populate( pathways_url=test_pathways_path, protein_pathway_url=test_proteins_path, ) @classmethod def tearDownClass(cls): """Close the connection in the manager and deletes the temporary database.""" cls.manager.drop_all() cls.manager.session.close() super().tearDownClass() protein_a = protein(namespace=HGNC, identifier='4458', name='GPI') protein_b = protein(namespace=HGNC, identifier='8878', name='PFKP') gene_c = gene(namespace=HGNC, identifier='8903', name='PGLS') pathway_a = bioprocess(namespace=KEGG, identifier='hsa00030', name='Pentose phosphate pathway - H**o sapiens (human)') def enrichment_graph() -> BELGraph: """Build a test graph with 2 proteins, one gene, and one kegg pathway all contained in HGNC.""" graph = BELGraph( name='My test graph for enrichment', version='0.0.1', ) graph.add_directly_increases(protein_a, protein_b,
class ManagerMixin(unittest.TestCase): def setUp(self): super(ManagerMixin, self).setUp() self.db_fd, self.db_file = tempfile.mkstemp() self.connection = 'sqlite:///' + self.db_file self.manager = Manager(connection=self.connection) def tearDown(self): os.close(self.db_fd) os.unlink(self.db_file) protein_a = protein(namespace=HGNC, name='a') protein_b = protein(namespace=HGNC, name='b') gene_c = gene(namespace=HGNC, name='c') rna_d = rna(namespace=HGNC, name='d') protein_e = protein(namespace=HGNC, name='e') gene_f = gene(namespace=HGNC, name='f') protein_g = protein(namespace=HGNC, name='g') protein_h = protein(namespace=HGNC, name='h') protein_i = protein(namespace=HGNC, name='i') protein_j = protein(namespace=HGNC, name='j') def make_graph_1() -> BELGraph: graph = BELGraph( name='Lab course example', version='1.1.0',
def expasy(name=None, identifier=None): return protein(namespace=MODULE_NAME, name=name, identifier=identifier)
def test_regulates_with_multiple_annotations(self): """ 3.1.7 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_regulates_reg Test nested definitions""" statement = 'pep(complex(p(HGNC:F3),p(HGNC:F7))) regulates pep(p(HGNC:F9))' result = self.parser.relation.parseString(statement) expected_dict = { SUBJECT: { MODIFIER: ACTIVITY, EFFECT: { NAME: 'pep', NAMESPACE: BEL_DEFAULT_NAMESPACE }, TARGET: { FUNCTION: COMPLEX, MEMBERS: [ { FUNCTION: PROTEIN, CONCEPT: {NAMESPACE: 'HGNC', NAME: 'F3'} }, { FUNCTION: PROTEIN, CONCEPT: {NAMESPACE: 'HGNC', NAME: 'F7'} }, ] } }, RELATION: REGULATES, OBJECT: { MODIFIER: ACTIVITY, EFFECT: { NAME: 'pep', NAMESPACE: BEL_DEFAULT_NAMESPACE }, TARGET: { FUNCTION: PROTEIN, CONCEPT: { NAMESPACE: 'HGNC', NAME: 'F9', }, }, }, } self.assertEqual(expected_dict, result.asDict()) sub_member_1 = protein('HGNC', 'F3') self.assert_has_node(sub_member_1) sub_member_2 = protein('HGNC', 'F7') self.assert_has_node(sub_member_2) sub = complex_abundance([sub_member_1, sub_member_2]) self.assert_has_node(sub) self.assert_has_edge(sub_member_1, sub, relation=PART_OF) self.assert_has_edge(sub_member_2, sub, relation=PART_OF) obj = protein('HGNC', 'F9') self.assert_has_node(obj) self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
def test_get_nodes(self): """Test nodes.""" glycolysis_genes, glycolysis_compounds, glycolysis_maps, glycolysis_orthologs = get_entity_nodes( tree=self.glycolysis_tree, hgnc_manager=self.hgnc_manager, chebi_manager=self.chebi_manager, ) notch_genes, notch_compounds, notch_maps, notch_orthologs = get_entity_nodes( tree=self.notch_tree, hgnc_manager=self.hgnc_manager, chebi_manager=self.chebi_manager, ) ppar_genes, ppar_compounds, ppar_maps, ppar_orthologs = get_entity_nodes( self.ppar_tree, self.hgnc_manager, self.chebi_manager, ) glycolysis_nodes = xml_entities_to_bel( graph=self.glycolysis_empty_graph, genes_dict=glycolysis_genes, compounds_dict=glycolysis_compounds, maps_dict=glycolysis_maps, flattened=False, ) flat_glycolysis_nodes = xml_entities_to_bel( graph=self.glycolysis_empty_flatten_graph, genes_dict=glycolysis_genes, compounds_dict=glycolysis_compounds, maps_dict=glycolysis_maps, flattened=True, ) notch_nodes = xml_entities_to_bel( graph=self.notch_empty_graph, genes_dict=notch_genes, compounds_dict=notch_compounds, maps_dict=notch_maps, flattened=False, ) flat_notch_nodes = xml_entities_to_bel( graph=self.notch_empty_flatten_graph, genes_dict=notch_genes, compounds_dict=notch_compounds, maps_dict=notch_maps, flattened=True, ) ppar_nodes = xml_entities_to_bel( graph=self.ppar_empty_graph, genes_dict=ppar_genes, compounds_dict=ppar_compounds, maps_dict=ppar_maps, flattened=False, ) flat_ppar_nodes = xml_entities_to_bel( graph=self.ppar_empty_flatten_graph, genes_dict=ppar_genes, compounds_dict=ppar_compounds, maps_dict=ppar_maps, flattened=True, ) self.assertEqual(len(glycolysis_nodes), 73) self.assertEqual(len(flat_glycolysis_nodes), 73) self.assertEqual(len(notch_nodes), 24) self.assertEqual(len(flat_notch_nodes), 24) # Test un-flattened protein nodes self.assertEqual( glycolysis_nodes['53'], composite_abundance([ protein(namespace=HGNC, name='PKLR', identifier='9020'), protein(namespace=HGNC, name='PKM', identifier='9021'), ]), ) self.assertEqual( notch_nodes['22'], composite_abundance([ protein(namespace=HGNC, name='NOTCH1', identifier='7881'), protein(namespace=HGNC, name='NOTCH2', identifier='7882'), protein(namespace=HGNC, name='NOTCH3', identifier='7883'), protein(namespace=HGNC, name='NOTCH4', identifier='7884'), ]), ) # Test flattened list of protein nodes self.assertEqual( flat_glycolysis_nodes['53'], [ protein(namespace=HGNC, name='PKLR', identifier='9020'), protein(namespace=HGNC, name='PKM', identifier='9021'), ], ) self.assertEqual( flat_notch_nodes['22'], [ protein(namespace=HGNC, name='NOTCH1', identifier='7881'), protein(namespace=HGNC, name='NOTCH2', identifier='7882'), protein(namespace=HGNC, name='NOTCH3', identifier='7883'), protein(namespace=HGNC, name='NOTCH4', identifier='7884'), ], ) # Test pathway map nodes self.assertEqual( flat_glycolysis_nodes['54'], bioprocess( namespace=KEGG.upper(), name='Citrate cycle (TCA cycle)', identifier='path:hsa00020', ), ) self.assertEqual( flat_notch_nodes['4'], bioprocess(namespace=KEGG.upper(), name='MAPK signaling pathway', identifier='path:hsa04010'), ) # Test un-flattened compound nodes self.assertEqual( ppar_nodes['48'], composite_abundance([ abundance(namespace=CHEBI.upper(), name='9(S)-HODE', identifier=' 34496'), abundance(namespace=CHEBI.upper(), name='13(S)-HODE', identifier='34154'), ]), ) # Test flattened compound nodes self.assertEqual( flat_ppar_nodes['48'], [ abundance(namespace=CHEBI.upper(), name='9(S)-HODE', identifier=' 34496'), abundance(namespace=CHEBI.upper(), name='13(S)-HODE', identifier='34154'), ], ) self.assertEqual( flat_glycolysis_nodes['85'], abundance(namespace=CHEBI.upper(), name='2-phospho-D-glyceric acid', identifier='17835'), )