How to use the pybel.constants 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 sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
logger.warning('Agent %s has no grounding.', agent)
        return None, None

    variants = []
    for mod in agent.mods:
        pybel_mod = pmod_namespace.get(mod.mod_type)
        if not pybel_mod:
            logger.info('Skipping modification of type %s on agent %s',
                        mod.mod_type, agent)
            continue
        var = pmod(namespace=pc.BEL_DEFAULT_NAMESPACE, name=pybel_mod)
        if mod.residue is not None:
            res = amino_acids[mod.residue]['short_name'].capitalize()
            var[pc.PMOD_CODE] = res
        if mod.position is not None:
            var[pc.PMOD_POSITION] = int(mod.position)
        variants.append(var)

    for mut in agent.mutations:
        var = hgvs(mut.to_hgvs())
        variants.append(var)

    if variants and not isinstance(node_data, CentralDogma):
        logger.warning('Node should not have variants: %s, %s', node_data,
                       variants)
    elif variants:
        node_data = node_data.with_variants(variants)

    if isinstance(node_data, (bioprocess, pathology)):
        return node_data, None

    # Also get edge data for the agent
github sorgerlab / indra / indra / explanation / reporting.py View on Github external
# May be a symmetric edge
            all_edges = model[target[0]][source[0]]
            reverse = True
        # Only keep the edges with correct sign or non-causal
        edges = {}
        key = 0
        for edge_data in all_edges.values():
            if edge_data['relation'] not in pc.CAUSAL_RELATIONS:
                edges[key] = edge_data
                key += 1
            if positive and \
                    edge_data['relation'] in pc.CAUSAL_INCREASE_RELATIONS:
                edges[key] = edge_data
                key += 1
            elif not positive and \
                    edge_data['relation'] in pc.CAUSAL_DECREASE_RELATIONS:
                edges[key] = edge_data
                key += 1
            else:
                continue
        hashes = set()
        for j in range(len(edges)):
            try:
                hashes.add(edges[j]['annotations']['stmt_hash'])
            # partOf and hasVariant edges don't have hashes
            except KeyError:
                continue
        # If we didn't get any hashes, we can get PybelEdge object from
        # partOf and hasVariant edges
        if not hashes:
            statements = []
            # Can't get statements without hash from db
github sorgerlab / indra / indra / explanation / reporting.py View on Github external
source = path[i]
        target = path[i+1]
        # Check if the signs of source and target nodes are the same
        positive = (source[1] == target[1])
        reverse = False
        try:
            all_edges = model[source[0]][target[0]]
        except KeyError:
            # May be a symmetric edge
            all_edges = model[target[0]][source[0]]
            reverse = True
        # Only keep the edges with correct sign or non-causal
        edges = {}
        key = 0
        for edge_data in all_edges.values():
            if edge_data['relation'] not in pc.CAUSAL_RELATIONS:
                edges[key] = edge_data
                key += 1
            if positive and \
                    edge_data['relation'] in pc.CAUSAL_INCREASE_RELATIONS:
                edges[key] = edge_data
                key += 1
            elif not positive and \
                    edge_data['relation'] in pc.CAUSAL_DECREASE_RELATIONS:
                edges[key] = edge_data
                key += 1
            else:
                continue
        hashes = set()
        for j in range(len(edges)):
            try:
                hashes.add(edges[j]['annotations']['stmt_hash'])
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def _get_evidence(evidence):
    text = evidence.text if evidence.text else 'No evidence text.'
    pybel_ev = {pc.EVIDENCE: text}
    # If there is a PMID, use it as the citation
    if evidence.pmid:
        citation = {pc.CITATION_DB: pc.CITATION_TYPE_PUBMED,
                    pc.CITATION_IDENTIFIER: evidence.pmid}
    # If no PMID, include the interface and source_api for now--
    # in general this should probably be in the annotations for all evidence
    else:
        cit_source = evidence.source_api if evidence.source_api else 'Unknown'
        cit_id = evidence.source_id if evidence.source_id else 'Unknown'
        cit_ref_str = '%s:%s' % (cit_source, cit_id)
        citation = {pc.CITATION_DB: pc.CITATION_TYPE_OTHER,
                    pc.CITATION_IDENTIFIER: cit_ref_str}
    pybel_ev[pc.CITATION] = citation

    annotations = {}
    if evidence.source_api:
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def _assemble_gef(self, stmt):
        """Example: act(p(HGNC:SOS1), ma(gef)) => act(p(HGNC:KRAS), ma(gtp))"""
        gef = deepcopy(stmt.gef)
        gef.activity = ActivityCondition('gef', True)
        ras = deepcopy(stmt.ras)
        ras.activity = ActivityCondition('gtpbound', True)
        self._add_nodes_edges(gef, ras, pc.DIRECTLY_INCREASES,
                              stmt.get_hash(refresh=True), stmt.evidence)
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def _combine_edge_data(relation, subj_edge, obj_edge, stmt):
    edge_data = {
        pc.RELATION: relation,
        pc.ANNOTATIONS: _get_annotations_from_stmt(stmt),
    }
    if subj_edge:
        edge_data[pc.SUBJECT] = subj_edge
    if obj_edge:
        edge_data[pc.OBJECT] = obj_edge
    if not stmt.evidence:
        return [edge_data]

    return [
        _update_edge_data_from_evidence(evidence, edge_data)
        for evidence in stmt.evidence
    ]
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def _assemble_gap(self, stmt):
        """Example: act(p(HGNC:RASA1), ma(gap)) =| act(p(HGNC:KRAS), ma(gtp))"""
        gap = deepcopy(stmt.gap)
        gap.activity = ActivityCondition('gap', True)
        ras = deepcopy(stmt.ras)
        ras.activity = ActivityCondition('gtpbound', True)
        self._add_nodes_edges(gap, ras, pc.DIRECTLY_DECREASES,
                              stmt.get_hash(refresh=True), stmt.evidence)
github sorgerlab / indra / indra / sources / bel / processor.py View on Github external
def _get_activity_condition(node_modifier_data):
    if node_modifier_data is None or node_modifier_data == {}:
        return None
    modifier = node_modifier_data.get(pc.MODIFIER)
    if modifier is None or modifier != pc.ACTIVITY:
        return None
    effect = node_modifier_data.get(pc.EFFECT)
    # No specific effect, just return generic activity
    if not effect:
        return ActivityCondition('activity', True)

    activity_ns = effect[pc.NAMESPACE]
    if activity_ns == pc.BEL_DEFAULT_NAMESPACE:
        activity_name = effect[pc.NAME]
        activity_type = _pybel_indra_act_map.get(activity_name)
        # If an activity type in Bel/PyBEL that is not implemented in INDRA,
        # return generic activity
        if activity_type is None:
            return ActivityCondition('activity', True)
        return ActivityCondition(activity_type, True)
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
logger.warning('Agent %s has no grounding.', agent)
        return None, None

    variants = []
    for mod in agent.mods:
        pybel_mod = pmod_namespace.get(mod.mod_type)
        if not pybel_mod:
            logger.info('Skipping modification of type %s on agent %s',
                        mod.mod_type, agent)
            continue
        var = pmod(namespace=pc.BEL_DEFAULT_NAMESPACE, name=pybel_mod)
        if mod.residue is not None:
            res = amino_acids[mod.residue]['short_name'].capitalize()
            var[pc.PMOD_CODE] = res
        if mod.position is not None:
            var[pc.PMOD_POSITION] = int(mod.position)
        variants.append(var)

    for mut in agent.mutations:
        var = hgvs(mut.to_hgvs())
        variants.append(var)

    if variants and not isinstance(node_data, CentralDogma):
        logger.warning('Node should not have variants: %s, %s', node_data, variants)
    elif variants:
        node_data = node_data.with_variants(variants)

    if isinstance(node_data, (bioprocess, pathology)):
        return node_data, None

    # Also get edge data for the agent
    edge_data = _get_agent_activity(agent)
github sorgerlab / indra / indra / assemblers / pybel / assembler.py View on Github external
def get_causal_edge(stmt, activates):
    """Returns the causal, polar edge with the correct "contact"."""
    any_contact = any(
        evidence.epistemics.get('direct', False)
        for evidence in stmt.evidence
    )
    if any_contact:
        return pc.DIRECTLY_INCREASES if activates else pc.DIRECTLY_DECREASES

    return pc.INCREASES if activates else pc.DECREASES