Esempio n. 1
0
    def test_increases(self):
        """Test composite in subject. See BEL 2.0 specification
        `3.1.1 <http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#Xincreases>`_
        """
        statement = 'composite(p(HGNC:CASP8),p(HGNC:FADD),a(CHEBI:"Abeta_42")) -> bp(GO:"neuron apoptotic process")'
        result = self.parser.relation.parseString(statement)

        expected = [[
            COMPOSITE, [PROTEIN, ['HGNC', 'CASP8']],
            [PROTEIN, ['HGNC', 'FADD']], [ABUNDANCE, ['CHEBI', 'Abeta_42']]
        ], INCREASES, [BIOPROCESS, ['GO', 'neuron apoptotic process']]]
        self.assertEqual(expected, result.asList())

        sub_member_1 = protein('HGNC', 'CASP8')
        self.assert_has_node(sub_member_1)

        sub_member_2 = protein('HGNC', 'FADD')
        self.assert_has_node(sub_member_2)

        sub_member_3 = abundance('CHEBI', 'Abeta_42')
        self.assert_has_node(sub_member_3)

        sub = composite_abundance([sub_member_1, sub_member_2, sub_member_3])
        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)
        self.assert_has_edge(sub_member_3, sub, relation=PART_OF)

        obj = bioprocess('GO', 'neuron apoptotic process')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=INCREASES)
Esempio n. 2
0
    def test_singleton(self):
        """Test singleton composite in subject."""
        statement = 'composite(p(HGNC:CASP8),p(HGNC:FADD),a(CHEBI:"Abeta_42"))'
        result = self.parser.statement.parseString(statement)

        expected = [
            COMPOSITE, [PROTEIN, ['HGNC', 'CASP8']],
            [PROTEIN, ['HGNC', 'FADD']], [ABUNDANCE, ['CHEBI', 'Abeta_42']]
        ]
        self.assertEqual(expected, result.asList())

        sub_member_1 = protein('HGNC', 'CASP8')
        self.assert_has_node(sub_member_1)

        sub_member_2 = protein('HGNC', 'FADD')
        self.assert_has_node(sub_member_2)

        sub_member_3 = abundance('CHEBI', 'Abeta_42')
        self.assert_has_node(sub_member_3)

        sub = composite_abundance([sub_member_1, sub_member_2, sub_member_3])
        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)
Esempio n. 3
0
    def test_spia_matrix_composites(self):
        """Test handling of composites."""
        shp = composite_abundance([shp1, shp2])

        self.sialic_acid_graph.add_increases(
            shp,
            trem2,
            citation=citation,
            annotations={'Species': '9606', 'Confidence': 'High'},
            evidence=evidence_1,
            target_modifier=activity(),
        )

        spia_dfs = to_spia_dfs(self.sialic_acid_graph)

        self.assertEqual(spia_dfs["activation"][shp1.name][trem2.name], 1)
        self.assertEqual(spia_dfs["activation"][shp2.name][trem2.name], 1)
Esempio n. 4
0
def gene_to_bel_node(graph, node):
    """Create a protein or protein composite BEL node and add to BEL Graph.

    :param pybel.BELGraph graph: BEL Graph
    :param list[dict[str,str]] node: dictionary of node attributes
    :return: corresponding BEL node
    :rtype: pybel.dsl.BaseEntity
    """
    members = list()

    # Create a protein BEL node
    if len(node) == 1:
        for attribute in node:

            if HGNC in attribute:
                protein_node = protein(namespace=HGNC,
                                       name=attribute[HGNC_SYMBOL],
                                       identifier=attribute[HGNC])
                graph.add_node_from_data(protein_node)
                return protein_node

            elif UNIPROT in attribute:
                protein_node = protein(
                    namespace=UNIPROT.upper(),
                    name=attribute[UNIPROT],
                    identifier=attribute[UNIPROT],
                )
                graph.add_node_from_data(protein_node)
                return protein_node

            else:
                protein_node = protein(namespace=KEGG.upper(),
                                       name=attribute[KEGG_ID],
                                       identifier=attribute[KEGG_ID])
                graph.add_node_from_data(protein_node)
                return protein_node

    # Create a composite abundance BEL node
    else:
        for member in node:
            bel_node = gene_to_bel_node(graph, [member])
            members.append(bel_node)

        protein_composite = composite_abundance(members=members)
        graph.add_node_from_data(protein_composite)
        return protein_composite
Esempio n. 5
0
def compound_to_bel(graph, node):
    """Create an abundance BEL node or composite abundances BEL node and add to BEL Graph.

    :param pybel.BELGraph graph: BEL Graph
    :param dict node: dictionary of node attributes
    :return: corresponding BEL node
    :rtype: pybel.dsl.BaseEntity
    """
    members = list()

    # Create a compound BEL node
    if len(node) == 1:
        node_dict = node[0]

        if CHEBI in node_dict:
            compound = abundance(namespace=CHEBI.upper(),
                                 name=node_dict[CHEBI_NAME],
                                 identifier=node_dict[CHEBI])
            graph.add_node_from_data(compound)
            return compound

        elif PUBCHEM in node_dict:
            compound = abundance(namespace=PUBCHEM.upper(),
                                 name=node_dict[PUBCHEM],
                                 identifier=node_dict[PUBCHEM])
            graph.add_node_from_data(compound)
            return compound

        else:
            compound = abundance(namespace=KEGG.upper(),
                                 name=node_dict[KEGG_ID],
                                 identifier=node_dict[KEGG_ID])
            graph.add_node_from_data(compound)
            return compound

    # Create a composite abundance BEL node
    else:
        for member in node:
            bel_node = compound_to_bel(graph, [member])
            members.append(bel_node)

        compound_composite = composite_abundance(members=members)
        graph.add_node_from_data(compound_composite)
        return compound_composite
Esempio n. 6
0
def node_to_bel(node: Dict, graph, hgnc_manager: HgncManager,
                chebi_manager: ChebiManager, species) -> 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, species)
    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, species)

                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:
        log.warning('Entity type not recognized', node_types)
Esempio n. 7
0
 def test_empty_composite(self):
     """Test that an empty complex causes a failure."""
     with self.assertRaises(ValueError):
         composite_abundance(members=[])
Esempio n. 8
0
 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))
Esempio n. 9
0
    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'),
        )