How to use the pybel.dsl.Abundance 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_dsl.py View on Github external
def test_str_has_identifier(self):
        namespace, identifier = n(), n()
        node = Abundance(namespace=namespace, identifier=identifier)
        self.assertEqual(
            'a({namespace}:{identifier})'.format(namespace=namespace, identifier=ensure_quotes(identifier)),
            node.as_bel(),
        )
github pybel / pybel / tests / test_io / test_tsv.py View on Github external
from pybel.typing import EdgeData


def _rel(x):
    return {RELATION: x}


def _rela(x, y=None):
    return {RELATION: x, OBJECT: activity(y)}


def _assoc(y):
    return {RELATION: ASSOCIATION, 'association_type': y}


a1 = Abundance('CHEBI', '1')
p1 = Protein('HGNC', '1')
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()
github pybel / pybel / tests / constant_helper.py View on Github external
ComplexAbundance([Protein('HGNC', 'F3'), Protein('HGNC', 'F7')]),
    Protein('HGNC', 'F3'),
    Protein('HGNC', 'F7'),
    Protein('HGNC', 'F9'),
    Protein('HGNC', 'GSK3B', variants=ProteinModification('Ph', 'Ser', 9)),
    Protein('HGNC', 'GSK3B'),
    Pathology('MESHD', 'Psoriasis'),
    Pathology('MESHD', 'Skin Diseases'),
    Reaction(
        reactants=[
            Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
            Abundance('CHEBI', 'NADPH'),
            Abundance('CHEBI', 'hydron')
        ],
        products=[
            Abundance('CHEBI', 'NADP(+)'),
            Abundance('CHEBI', 'mevalonate')
        ]
    ),
    Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
    Abundance('CHEBI', 'NADPH'),
    Abundance('CHEBI', 'hydron'),
    Abundance('CHEBI', 'mevalonate'),
    Abundance('CHEBI', 'NADP(+)'),
    Abundance('CHEBI', 'nitric oxide'),
    ComplexAbundance([
        Protein('HGNC', 'ITGAV'),
        Protein('HGNC', 'ITGB3')
    ]),
    Protein('HGNC', 'ITGAV'),
    Protein('HGNC', 'ITGB3'),
    Protein('HGNC', 'FADD'),
github pybel / pybel / tests / test_tokens.py View on Github external
)

        self.assertEqual(
            Abundance(namespace=namespace, name=name, identifier=identifier),
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
                    NAME: name,
                    IDENTIFIER: identifier,
                },
            })
        )

        self.assertEqual(
            Abundance(namespace=namespace, identifier=identifier),
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
                    IDENTIFIER: identifier,
                },
            })
        )

        with self.assertRaises(ValueError):
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
                },
github pybel / pybel / tests / constant_helper.py View on Github external
Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
            Abundance('CHEBI', 'NADPH'),
            Abundance('CHEBI', 'hydron')
        ),
        products=(
            Abundance('CHEBI', 'NADP(+)'),
            Abundance('CHEBI', 'mevalonate')
        )
    ),
     Abundance('CHEBI', 'NADPH'), {
         RELATION: HAS_REACTANT,
     }),
    (
        Reaction(
            reactants=(
                Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
                Abundance('CHEBI', 'NADPH'),
                Abundance('CHEBI', 'hydron')
            ),
            products=(
                Abundance('CHEBI', 'NADP(+)'),
                Abundance('CHEBI', 'mevalonate')
            )
        ),
        Abundance('CHEBI', 'hydron'), {
            RELATION: HAS_REACTANT,
        }),
    (Reaction(
        reactants=(
            Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
            Abundance('CHEBI', 'NADPH'),
            Abundance('CHEBI', 'hydron')
github pybel / pybel / tests / test_tokens.py View on Github external
"""Test converting a simple dictionary."""
        namespace, name, identifier = n(), n(), n()

        self.assertEqual(
            Abundance(namespace=namespace, name=name),
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
                    NAME: name,
                },
            })
        )

        self.assertEqual(
            Abundance(namespace=namespace, name=name, identifier=identifier),
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
                    NAME: name,
                    IDENTIFIER: identifier,
                },
            })
        )

        self.assertEqual(
            Abundance(namespace=namespace, identifier=identifier),
            _simple_po_to_dict({
                FUNCTION: ABUNDANCE,
                CONCEPT: {
                    NAMESPACE: namespace,
github pybel / pybel / tests / test_canonicalization.py View on Github external
def test_Abundance(self):
        """Test canonicalization of abundances."""
        short = Abundance(namespace='CHEBI', name='water')
        self.assertEqual('a(CHEBI:water)', str(short))

        long = Abundance(namespace='CHEBI', name='test name')
        self.assertEqual('a(CHEBI:"test name")', str(long))
github pybel / pybel / tests / constant_helper.py View on Github external
Abundance('CHEBI', 'NADPH'),
            Abundance('CHEBI', 'hydron')
        ),
        products=(
            Abundance('CHEBI', 'NADP(+)'),
            Abundance('CHEBI', 'mevalonate')
        )
    ),
     Abundance('CHEBI', 'NADPH'), {
         RELATION: HAS_REACTANT,
     }),
    (
        Reaction(
            reactants=(
                Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
                Abundance('CHEBI', 'NADPH'),
                Abundance('CHEBI', 'hydron')
            ),
            products=(
                Abundance('CHEBI', 'NADP(+)'),
                Abundance('CHEBI', 'mevalonate')
            )
        ),
        Abundance('CHEBI', 'hydron'), {
            RELATION: HAS_REACTANT,
        }),
    (Reaction(
        reactants=(
            Abundance('CHEBI', '(3S)-3-hydroxy-3-methylglutaryl-CoA'),
            Abundance('CHEBI', 'NADPH'),
            Abundance('CHEBI', 'hydron')
        ),
github sorgerlab / indra / indra / sources / bel / processor.py View on Github external
def get_agent(node_data, node_modifier_data=None):
    """Get an INDRA agent from a PyBEL node."""
    # Check the node type/function
    if not isinstance(node_data, dsl.BaseEntity):
        raise TypeError('Non-pybel dict given: ({}) {}'.format(
            type(node_data), node_data))

    if not isinstance(node_data, (
        dsl.Protein, dsl.Rna, dsl.BiologicalProcess, dsl.ComplexAbundance,
        dsl.NamedComplexAbundance, dsl.Pathology, dsl.Abundance,
        dsl.MicroRna, dsl.Gene,
    )):
        mod_data = node_modifier_data or 'No node data'
        logger.info("Nodes of type %s not handled: %s",
                    node_data.function, mod_data)
        return None

    # Skip gene/protein fusions
    if isinstance(node_data, dsl.FusionBase):
        logger.info("Gene and protein fusions not handled: %s", node_data)
        return None
    # COMPLEXES ------------
    # First, handle complexes, which will consist recursively of other agents
    if isinstance(node_data, dsl.ComplexAbundance):
        # First, check for members: if there are no members, we assume this
        # is a named complex
github pybel / pybel / src / pybel / io / sbgnml / convert.py View on Github external
variants=states or None,
        )
        # print('found protein', rv)
        return rv

    elif cls == 'phenotype' and entity and entity['identifier']:
        rv = dsl.BiologicalProcess(
            namespace=entity['prefix'],
            identifier=entity['identifier'],
            name=entity['name'],
        )
        # print('found BP', rv)
        return rv

    elif cls == 'simple chemical' and entity and entity['prefix'] == 'chebi':
        rv = dsl.Abundance(
            namespace=entity['prefix'],
            identifier=entity['identifier'],
            name=entity['name'],
        )
        # print('found chemical', rv)
        return rv
    elif cls == 'complex' and components:
        if len(components) == 1:
            c = list(components.values())[0]
            if not c['entity']['identifier']:
                print('unhandled complex of ', components)
                return
            return dsl.NamedComplexAbundance(
                namespace=c['entity']['prefix'],
                identifier=c['entity']['identifier'],
                name=c['entity']['name'],