def test_list_abundance_has_contents(self): """Test that the construction of list abundance doesn't have empty lists.""" with self.assertRaises(ListAbundanceEmptyException): ComplexAbundance([]) with self.assertRaises(ListAbundanceEmptyException): CompositeAbundance([])
def test_complex_with_name(self): """Test what happens with a named complex. .. code-block:: complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:HUS1) complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD1) complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD9A) """ hus1 = Protein(namespace='HGNC', name='HUS1') rad1 = Protein(namespace='HGNC', name='RAD1') rad9a = Protein(namespace='HGNC', name='RAD9A') members = [hus1, rad1, rad9a] nine_one_one = ComplexAbundance(members=members, namespace='SCOMP', name='9-1-1 Complex') graph = BELGraph() graph.add_node_from_data(nine_one_one) self.assertIn(nine_one_one, graph) self.assertIn(hus1, graph) self.assertIn(rad1, graph) self.assertIn(rad9a, graph)
def _tf_down(graph, protein, rna): graph.add_directly_decreases( ComplexAbundance([protein, rna.get_gene()]), rna, citation=n(), evidence=n(), )
def setUp(self) -> None: """Set up a small test graph.""" self.graph = BELGraph() self.graph.add_increases(ComplexAbundance([p1, g2]), r2, citation=n(), evidence=n()) self.graph.add_increases(p2, p3, citation=n(), evidence=n())
def test_complex(self): node = ComplexAbundance(members=[fos, jun]) self.graph.add_node_from_data(node) self.assertIn(node, self.graph) self.assertEqual(3, self.graph.number_of_nodes()) self.assertEqual(2, self.graph.number_of_edges()) assert_unqualified_edge(self, fos, node, PART_OF) assert_unqualified_edge(self, jun, node, PART_OF)
def test_binds(self): """Test the ``binds`` relation.""" statement = 'p(HGNC:X) binds p(HGNC:Y)' self.parser.relation.parseString(statement) source = Protein('HGNC', 'X') target = Protein('HGNC', 'Y') x_y_complex = ComplexAbundance([source, target]) self.assert_has_node(x_y_complex) self.assert_has_edge(source, x_y_complex, relation=PART_OF) self.assert_has_edge(target, x_y_complex, relation=PART_OF)
def test_named_complex(self): x = ComplexAbundance(namespace='a', identifier='b', members=[ Protein(namespace='c', identifier='d'), Protein(namespace='c', identifier='e'), ]) y = parse_result_to_dsl(dict(x)) self.assertIsInstance(y, ComplexAbundance) self.assertIn(pc.MEMBERS, y) self.assertIn(pc.CONCEPT, y)
def test_get_tf_pairs(self): """Test iterating over transcription factor pairs.""" graph = BELGraph() p1, p2, p3 = (Protein('test', str(i)) for i in range(1, 4)) r4, r5, r6 = (Rna('test', str(j)) for j in range(4, 7)) g4 = r4.get_gene() self.assertIsNotNone(g4) g5 = r5.get_gene() self.assertIsNotNone(g5) c14, c25 = ComplexAbundance([p1, g4]), ComplexAbundance([p2, g5]) _tf_up(graph, p1, r4) _tf_down(graph, p2, r5) graph.add_correlation(p3, r6, citation=n(), evidence=n()) self.assertEqual({p1, p2, p3, r4, r5, r6, g4, g5, c14, c25}, set(graph)) expected_edges = [ (c14, r4), (p1, c14), (g4, c14), (c25, r5), (p2, c25), (g5, c25), (p3, r6), (r6, p3), ] sorted_expected_edges = sorted(expected_edges, key=_bel_pair_key) sorted_actual_edges = sorted(graph.edges(), key=_bel_pair_key) self.assertEqual(sorted_expected_edges, sorted_actual_edges) pairs = set(get_tf_pairs(graph)) expected_pairs = {(p1, r4, +1), (p2, r5, -1)} self.assertEqual(expected_pairs, pairs)
def bel_isolated_reconstituted(self, graph: BELGraph): """Run the isolated node test.""" self.assertIsNotNone(graph) self.assertIsInstance(graph, BELGraph) adgrb1 = Protein(namespace='HGNC', name='ADGRB1') adgrb2 = Protein(namespace='HGNC', name='ADGRB2') adgrb_complex = ComplexAbundance([adgrb1, adgrb2]) achlorhydria = Pathology(namespace='MESHD', name='Achlorhydria') for node in graph: self.assertIsInstance(node, BaseEntity) self.assertIn(adgrb1, graph) self.assertIn(adgrb2, graph) self.assertIn(adgrb_complex, graph) self.assertIn(achlorhydria, graph) assert_has_edge(self, adgrb1, adgrb_complex, graph, relation=PART_OF) assert_has_edge(self, adgrb2, adgrb_complex, graph, relation=PART_OF)
def test_import(self): """Test importing a hipathia network as a BEL graph.""" graph = from_hipathia_paths( name='test1', att_path=TEST_1_ATT_PATH, sif_path=TEST_1_SIF_PATH, ) a = Protein(namespace='ncbigene', identifier='1') b_family = Protein(namespace='hipathia.family', identifier='B_Family') b_2 = Protein(namespace='ncbigene', identifier='2') b_3 = Protein(namespace='ncbigene', identifier='3') c_family = Protein(namespace='hipathia.family', identifier='C_Family') c_4 = Protein(namespace='ncbigene', identifier='4') c_5 = Protein(namespace='ncbigene', identifier='5') d = Protein(namespace='ncbigene', identifier='6') c_d = ComplexAbundance([c_family, d]) self.assertEqual( sorted({a, b_family, b_2, b_3, c_family, c_4, c_5, d, c_d}, key=str), sorted(graph, key=str), )
BelReconstitutionMixin, akt1, casp8, egfr, expected_test_simple_metadata, fadd, test_citation_dict, test_evidence_text, ) fos = hgnc(name='FOS') jun = hgnc(name='JUN') mirna_1 = mirbase(name=n()) mirna_2 = mirbase(name=n()) pathology_1 = Pathology('DO', n()) ap1_complex = ComplexAbundance([fos, jun]) egfr_dimer = ComplexAbundance([egfr, egfr]) yfg_data = hgnc(name='YFG') e2f4_data = hgnc(name='E2F4') bound_ap1_e2f4 = ComplexAbundance([ap1_complex, e2f4_data]) superoxide = chebi(name='superoxide') hydrogen_peroxide = chebi(name='hydrogen peroxide') oxygen = chebi(name='oxygen') superoxide_decomposition = Reaction(reactants=[superoxide], products=[hydrogen_peroxide, oxygen]) def assert_unqualified_edge(test_case, u: BaseEntity, v: BaseEntity,
def test_complex_abundance(self): node = ComplexAbundance(members=[ Protein(namespace='HGNC', name='FOS'), Protein(namespace='HGNC', name='JUN') ]) self.assertEqual('complex(p(HGNC:FOS), p(HGNC:JUN))', str(node))
pmod, protein_fusion, protein_substitution, reaction, rna, ) from pybel.utils import citation_dict example_graph = BELGraph() ptk2 = Protein(namespace='hgnc', name='PTK2', variants=pmod('Ph', 'Tyr', 925)) mapk1 = Protein(namespace='hgnc', name='MAPK1') mapk3 = Protein(namespace='hgnc', name='MAPK3') grb2 = Protein(namespace='hgnc', name='GRB2') sos1 = Protein(namespace='hgnc', name='SOS1') ptk2_rgb2_sos1 = ComplexAbundance([mapk1, grb2, sos1]) ras_family = Protein(namespace='fplx', name='RAS') pi3k_complex = named_complex_abundance(namespace='fplx', name='p85/p110 PI3Kinase Complex') kinase_activity = activity('kin') catalytic_activity = activity('cat') gtp_activity = activity('gtp') c1 = '10446041' e1 = "FAK also combines with, and may activate, phosphoinositide 3-OH kinase (PI 3-kinase), either directly or " \ "through the Src kinase (13). Finally, there is evidence that Src phosphorylates FAK at Tyr925, creating a" \ " binding site for the complex of the adapter Grb2 and Ras guanosine 5'-triphosphate exchange factor mSOS (10)." \ " These interactions link FAK to signaling pathways that modify the cytoskeleton and activate mitogen-activated" \ " protein kinase (MAPK) cascades (Fig. 3A)."
citation_2 = citation_dict(db=CITATION_TYPE_PUBMED, db_id='123456') evidence_1 = "Evidence 1" dummy_evidence = 'These are mostly made up' akt1 = hgnc(name='AKT1') egfr = hgnc(name='EGFR') fadd = hgnc(name='FADD') casp8 = hgnc(name='CASP8') mia = hgnc(name='MIA') il6 = Protein('HGNC', 'IL6') adgrb1 = Protein(namespace='HGNC', name='ADGRB1') adgrb2 = Protein(namespace='HGNC', name='ADGRB2') adgrb_complex = ComplexAbundance([adgrb1, adgrb2]) achlorhydria = Pathology(namespace='MESHD', name='Achlorhydria') akt1_rna = akt1.get_rna() akt1_gene = akt1_rna.get_gene() akt_methylated = akt1_gene.with_variants(GeneModification('Me')) akt1_phe_508_del = akt1_gene.with_variants(Hgvs('p.Phe508del')) cftr = hgnc('CFTR') cftr_protein_unspecified_variant = cftr.with_variants(HgvsUnspecified()) cftr_protein_phe_508_del = cftr.with_variants(Hgvs('p.Phe508del')) adenocarcinoma = Pathology('MESHD', 'Adenocarcinoma') interleukin_23_complex = NamedComplexAbundance('GO', 'interleukin-23 complex') oxygen_atom = Abundance(namespace='CHEBI', name='oxygen atom')
Protein('HGNC', 'LCK'), Protein('SFAM', 'Chemokine Receptor Family'), Protein('HGNC', 'CXCL9'), Pathology('SDIS', 'T-cell migration'), Protein('HGNC', 'CXCR3'), Abundance('CHEBI', 'acrolein'), Protein('HGNC', 'IDO2'), Pathology('MESHD', 'Pulmonary Disease, Chronic Obstructive'), Protein('HGNC', 'IFNG'), Protein('HGNC', 'TNFRSF4'), Protein('HGNC', 'CTLA4'), Protein('HGNC', 'GZMA'), Protein('HGNC', 'PRF1'), Protein('HGNC', 'TNF'), Protein('SFAM', 'Chemokine Receptor Family'), ComplexAbundance([Protein('HGNC', 'CD8A'), Protein('HGNC', 'CD8B')]), ComplexAbundance([Protein('HGNC', 'CD8A'), Protein('HGNC', 'CD8B')]), Protein('HGNC', 'PLCG1', variants=ProteinModification('Ph', 'Tyr')), Protein('EGID', '21577'), } jgif_expected_edges = [ (calcium, calcineurin_complex, { RELATION: DIRECTLY_INCREASES, EVIDENCE: 'NMDA-mediated influx of calcium led to activated of the calcium-dependent phosphatase calcineurin and the subsequent dephosphorylation and activation of the protein-tyrosine phosphatase STEP', CITATION: { NAMESPACE: CITATION_TYPE_PUBMED, IDENTIFIER: '12483215' },
pf1 = Protein('INTERPRO', '1') d1 = Pathology('MESH', '1') b1 = BiologicalProcess('GO', '1') b2 = BiologicalProcess('GO', '2') m1 = MicroRna('MIRBASE', '1') r1 = Rna('HGNC', '1') r2 = Rna('HGNC', '2') nca1 = NamedComplexAbundance('FPLX', '1') pop1 = Population('taxonomy', '1') p2 = Protein('HGNC', identifier='9236') p3 = Protein('HGNC', identifier='9212') r3 = p3.get_rna() g3 = r3.get_gene() c1 = ComplexAbundance([p2, g3]) c2 = ComplexAbundance([p1, p2]) c3 = ComplexAbundance([a1, p2]) converters_true_list = [ (PartOfNamedComplexConverter, p1, nca1, _rel(PART_OF), ('HGNC:1', 'partOf', 'FPLX:1')), (SubprocessPartOfBiologicalProcessConverter, b1, b2, _rel(PART_OF), ('GO:1', 'partOf', 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(INCREASES), ('GO:1', INCREASES, 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(DECREASES), ('GO:1', DECREASES, 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(DIRECTLY_INCREASES), ('GO:1', DIRECTLY_INCREASES, 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(DIRECTLY_DECREASES),
# -*- coding: utf-8 -*- import unittest from pybel import BELGraph from pybel.dsl import ComplexAbundance, Fragment, Protein from pybel.dsl.namespaces import hgnc from pybel_tools.selection.group_nodes import get_mapped_nodes ccl2 = hgnc(name='CCL2') ccr2 = hgnc(name='CCR2') ccl2_mgi = Protein('MGI', 'Ccl2') ccl2_ccr2_complex = ComplexAbundance([ccl2, ccr2]) chemokine_family = Protein('FPLX', 'chemokine protein family') HGNC = 'hgnc' class TestMapping(unittest.TestCase): def test_variants_mapping(self): graph = BELGraph() app = Protein(HGNC, 'APP') app_fragment = app.with_variants(Fragment('1_49')) graph.add_node_from_data(app_fragment) mapped_nodes = get_mapped_nodes(graph, HGNC, {'APP'}) self.assertEqual(1, len(mapped_nodes)) self.assertIn(app, mapped_nodes) self.assertEqual({app_fragment}, mapped_nodes[app])
PROTEIN_NAMESPACE = 'ncbigene' FAMILY_NAMESPACE = 'hipathia.family' a = Protein(namespace='ncbigene', identifier='P001', name='A') b_family = Protein(namespace='hipathia.family', identifier='F001', name='B_Family') b1 = Protein(namespace='ncbigene', identifier='P002', name='B1') b2 = Protein(namespace='ncbigene', identifier='P003', name='B2') c_family = Protein(namespace='hipathia.family', identifier='F002', name='C_Family') c1 = Protein(namespace='ncbigene', identifier='P004', name='C1') c2 = Protein(namespace='ncbigene', identifier='P005', name='C2') d = Protein(namespace='ncbigene', identifier='P006', name='D') c_d = ComplexAbundance([c_family, d]) e = Protein(namespace='ncbigene', identifier='P007', name='E') f = Protein(namespace='ncbigene', identifier='P008', name='F') e_f = ComplexAbundance([e, f]) name = 'test' class TestExportHipathia(unittest.TestCase): """Test Hipathia.""" def setUp(self) -> None: self.graph = BELGraph(name=name) def _get_dfs(self) -> Tuple[pd.DataFrame, pd.DataFrame]: return to_hipathia_dfs(self.graph)
pf1 = Protein('INTERPRO', '1') d1 = Pathology('MESH', '1') b1 = BiologicalProcess('GO', '1') b2 = BiologicalProcess('GO', '2') m1 = MicroRna('MIRBASE', '1') r1 = Rna('HGNC', '1') r2 = Rna('HGNC', '2') nca1 = NamedComplexAbundance('FPLX', '1') pop1 = Population('taxonomy', '1') p2 = Protein('HGNC', identifier='9236') p3 = Protein('HGNC', identifier='9212') r3 = p3.get_rna() g3 = r3.get_gene() c1 = ComplexAbundance([p2, g3]) c2 = ComplexAbundance([p1, p2]) c3 = ComplexAbundance([a1, p2]) p1_homodimer = ComplexAbundance([p1, p1]) p1_homotrimer = ComplexAbundance([p1, p1, p1]) converters_true_list = [ (PartOfNamedComplexConverter, p1, nca1, _rel(PART_OF), ('HGNC:1', 'partOf', 'FPLX:1')), (SubprocessPartOfBiologicalProcessConverter, b1, b2, _rel(PART_OF), ('GO:1', 'partOf', 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(INCREASES), ('GO:1', INCREASES, 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(DECREASES), ('GO:1', DECREASES, 'GO:2')), (tsvc.ProcessCausalConverter, b1, b2, _rel(DIRECTLY_INCREASES),
def test_empty_complex(self): """Test that an empty complex causes a failure.""" with self.assertRaises(ValueError): ComplexAbundance(members=[])