# Path: indra/ontology/standardize.py
# def get_standard_name(db_refs, ontology=None, ns_order=None):
#     """Return a standardized name for a given db refs dict.
# 
#     Parameters
#     ----------
#     db_refs : dict
#         A dict of db refs that may not be standardized, i.e., may be
#         missing an available UP ID corresponding to an existing HGNC ID.
#     ontology : Optional[indra.ontology.IndraOntology]
#         An IndraOntology object, if not provided, the default BioOntology
#         is used.
#     ns_order : Optional[list]
#         A list of namespaces which are in order of priority with higher
#         priority namespaces appearing earlier in the list.
# 
#     Returns
#     -------
#     str or None
#         The standard name based on the db refs, None if not available.
#     """
#     if ontology is None:
#         from indra.ontology.bio import bio_ontology
#         ontology = bio_ontology
# 
#     # We next look for prioritized grounding, if missing, we return
#     db_ns, db_id = get_grounding(db_refs, ns_order=ns_order)
# 
#     # If there's no grounding then we can't do more to standardize the
#     # name and return
#     if not db_ns or not db_id:
#         return None
# 
#     # If there is grounding available, we can try to get the standardized name
#     # and in the rare case that we don't get it, we don't set it.
#     standard_name = ontology.get_name(db_ns, db_id)
#     # Handle special case with UPPRO, if we can't get a feature name
#     # we fall back on regular gene/protein naming
#     if not standard_name and db_ns == 'UPPRO':
#         db_ns, db_id = get_grounding(db_refs, ns_order=['HGNC', 'UP'])
#         if not db_ns or not db_id:
#             return None
#         standard_name = ontology.get_name(db_ns, db_id)
#     if not standard_name:
#         return None
# 
#     return standard_name
# 
# Path: indra/sources/minerva/id_mapping.py
# def indra_db_refs_from_minerva_refs(refs):
#     db_refs = {}
#     for db_ns, db_id in refs:
#         db_ns = minerva_to_indra_map[db_ns] \
#             if db_ns in minerva_to_indra_map else db_ns
#         db_ns, db_id = fix_id_standards(db_ns, db_id)
#         db_refs[db_ns] = db_id
#     # We need some special handling here for issues in the curated maps
#     # If we have a specific gene grounding, remove ECCODE grounding since
#     # it can incorrectly result in a family interpretation
#     if 'HGNC' in db_refs:
#         db_refs.pop('ECCODE', None)
#     db_refs = standardize_db_refs(db_refs)
#     return db_refs


import logging
from indra.ontology.standardize import get_standard_name
from indra.ontology.bio import bio_ontology
from indra.statements import *
from .minerva_client import get_ids_to_refs, default_map_name
from .id_mapping import indra_db_refs_from_minerva_refs
                    main_agent.bound_conditions.append(BoundCondition(ag))
            return main_agent
    # Now we have either individual agents or complexes with complex level
    # grounding (e.g. from GO, MESH, UNIPROT)
    else:
        return get_agent_from_refs(filtered_refs)


def get_family(agents):
    """Get a FamPlex family if all of its members are given."""
    family_sets = []
    ag_groundings = []
    for ag in agents:
        gr = ag.get_grounding()
        ag_groundings.append(gr)
        parents = bio_ontology.get_parents(*gr)
        families = {p for p in parents if p[0] == 'FPLX'}
        family_sets.append(families)
    common_families = family_sets[0].intersection(*family_sets)
    if not common_families:
        return
    for fam in common_families:
        children = bio_ontology.get_children(*fam)
        # Check if all family members are present
        if set(children) == set(ag_groundings):
            return fam[1]


def get_agent_from_refs(db_refs):
    """Get an agent given its db_refs."""

# Path: indra/ontology/standardize.py
# def get_standard_name(db_refs, ontology=None, ns_order=None):
#     """Return a standardized name for a given db refs dict.
# 
#     Parameters
#     ----------
#     db_refs : dict
#         A dict of db refs that may not be standardized, i.e., may be
#         missing an available UP ID corresponding to an existing HGNC ID.
#     ontology : Optional[indra.ontology.IndraOntology]
#         An IndraOntology object, if not provided, the default BioOntology
#         is used.
#     ns_order : Optional[list]
#         A list of namespaces which are in order of priority with higher
#         priority namespaces appearing earlier in the list.
# 
#     Returns
#     -------
#     str or None
#         The standard name based on the db refs, None if not available.
#     """
#     if ontology is None:
#         from indra.ontology.bio import bio_ontology
#         ontology = bio_ontology
# 
#     # We next look for prioritized grounding, if missing, we return
#     db_ns, db_id = get_grounding(db_refs, ns_order=ns_order)
# 
#     # If there's no grounding then we can't do more to standardize the
#     # name and return
#     if not db_ns or not db_id:
#         return None
# 
#     # If there is grounding available, we can try to get the standardized name
#     # and in the rare case that we don't get it, we don't set it.
#     standard_name = ontology.get_name(db_ns, db_id)
#     # Handle special case with UPPRO, if we can't get a feature name
#     # we fall back on regular gene/protein naming
#     if not standard_name and db_ns == 'UPPRO':
#         db_ns, db_id = get_grounding(db_refs, ns_order=['HGNC', 'UP'])
#         if not db_ns or not db_id:
#             return None
#         standard_name = ontology.get_name(db_ns, db_id)
#     if not standard_name:
#         return None
# 
#     return standard_name
# 
# Path: indra/sources/minerva/id_mapping.py
# def indra_db_refs_from_minerva_refs(refs):
#     db_refs = {}
#     for db_ns, db_id in refs:
#         db_ns = minerva_to_indra_map[db_ns] \
#             if db_ns in minerva_to_indra_map else db_ns
#         db_ns, db_id = fix_id_standards(db_ns, db_id)
#         db_refs[db_ns] = db_id
#     # We need some special handling here for issues in the curated maps
#     # If we have a specific gene grounding, remove ECCODE grounding since
#     # it can incorrectly result in a family interpretation
#     if 'HGNC' in db_refs:
#         db_refs.pop('ECCODE', None)
#     db_refs = standardize_db_refs(db_refs)
#     return db_refs


# Path: indra/sources/minerva/processor.py
import logging
from indra.ontology.standardize import get_standard_name
from indra.ontology.bio import bio_ontology
from indra.statements import *
from .minerva_client import get_ids_to_refs, default_map_name
from .id_mapping import indra_db_refs_from_minerva_refs

                    main_agent.bound_conditions.append(BoundCondition(ag))
            return main_agent
    # Now we have either individual agents or complexes with complex level
    # grounding (e.g. from GO, MESH, UNIPROT)
    else:
        return get_agent_from_refs(filtered_refs)


def get_family(agents):
    """Get a FamPlex family if all of its members are given."""
    family_sets = []
    ag_groundings = []
    for ag in agents:
        gr = ag.get_grounding()
        ag_groundings.append(gr)
        parents = bio_ontology.get_parents(*gr)
        families = {p for p in parents if p[0] == 'FPLX'}
        family_sets.append(families)
    common_families = family_sets[0].intersection(*family_sets)
    if not common_families:
        return
    for fam in common_families:
        children = bio_ontology.get_children(*fam)
        # Check if all family members are present
        if set(children) == set(ag_groundings):
            return fam[1]


def get_agent_from_refs(db_refs):
    """Get an agent given its db_refs."""

    name = get_standard_name(db_refs)