示例#1
0
def ubiquitize_model(in_sbml,
                     chebi,
                     groups_sbml,
                     ub_s_ids=None,
                     ub_chebi_ids=None):
    """
    Infers and marks ubiquitous species in the model.
    :param in_sbml: str, path to the input SBML file
    :param chebi: mod_sbml.onto.obo_ontology.Ontology ChEBI ontology
    :param groups_sbml: str, path to the output SBML file (with groups extension)
    :param ub_s_ids: optional, ids of ubiquitous species (will be inferred if set to None)
    :param ub_chebi_ids: optional, ids of ubiquitous ChEBI terms (will be inferred if set to None)
    :return: tuple (s_id2chebi_id, ub_s_ids): dict {species_id: ChEBI_term_id},  collection of ubiquitous species_ids.
    """
    input_doc = libsbml.SBMLReader().readSBML(in_sbml)
    input_model = input_doc.getModel()
    annotate_metabolites(input_model, chebi)

    logging.info("mapping species to ChEBI")
    s_id2chebi_id = get_species_id2chebi_id(input_model)
    _, ub_s_ids = get_ub_elements(input_model, chebi, s_id2chebi_id,
                                  ub_chebi_ids, ub_s_ids)

    save_as_comp_generalized_sbml(input_model, None, groups_sbml, {}, {},
                                  ub_s_ids, chebi)
    return s_id2chebi_id, ub_s_ids
示例#2
0
def ubiquitize_model(in_sbml, chebi, groups_sbml, ub_s_ids=None, ub_chebi_ids=None):
    """
    Infers and marks ubiquitous species in the model.
    :param in_sbml: str, path to the input SBML file
    :param chebi: mod_sbml.onto.obo_ontology.Ontology ChEBI ontology
    :param groups_sbml: str, path to the output SBML file (with groups extension)
    :param ub_s_ids: optional, ids of ubiquitous species (will be inferred if set to None)
    :param ub_chebi_ids: optional, ids of ubiquitous ChEBI terms (will be inferred if set to None)
    :return: tuple (s_id2chebi_id, ub_s_ids): dict {species_id: ChEBI_term_id},  collection of ubiquitous species_ids.
    """
    input_doc = libsbml.SBMLReader().readSBML(in_sbml)
    input_model = input_doc.getModel()
    annotate_metabolites(input_model, chebi)

    logging.info("mapping species to ChEBI")
    s_id2chebi_id = get_species_id2chebi_id(input_model)
    _, ub_s_ids = get_ub_elements(input_model, chebi, s_id2chebi_id, ub_chebi_ids, ub_s_ids)

    save_as_comp_generalized_sbml(input_model, None, groups_sbml, {}, {}, ub_s_ids, chebi)
    return s_id2chebi_id, ub_s_ids
示例#3
0
def generalize_model(in_sbml, chebi, groups_sbml, out_sbml, ub_s_ids=None, ub_chebi_ids=None, ignore_biomass=True):
    """
    Generalizes a model.
    :param in_sbml: str, path to the input SBML file
    :param chebi: mod_sbml.onto.obo_ontology.Ontology ChEBI ontology
    :param groups_sbml: str, path to the output SBML file (with groups extension)
    :param out_sbml: str, path to the output SBML file (generalized)
    :param ub_s_ids: optional, ids of ubiquitous species (will be inferred if set to None)
    :param ub_chebi_ids: optional, ids of ubiquitous ChEBI terms (will be inferred if set to None)
    :param ignore_biomass: boolean, whether to ignore the biomass reaction (and its stoichiometry preserving constraint)
    :return: tuple (r_id2g_eq, s_id2gr_id, s_id2chebi_id, ub_s_ids):
    dict {reaction_id: reaction_group_id}, dict {species_id: species_group_id}, dict {species_id: ChEBI_term_id},
    collection of ubiquitous species_ids.
    """
    # input_model
    input_doc = libsbml.SBMLReader().readSBML(in_sbml)
    input_model = input_doc.getModel()
    r_ids_to_ignore = get_biomass_r_ids(input_model) if ignore_biomass else None

    remove_is_a_reactions(input_model)
    annotate_metabolites(input_model, chebi)
    # TODO: fix comp separation
    # separate_boundary_metabolites(input_model)
    remove_unused_elements(input_model)

    logging.info("mapping species to ChEBI")
    s_id2chebi_id = get_species_id2chebi_id(input_model)
    ub_chebi_ids, ub_s_ids = get_ub_elements(input_model, chebi, s_id2chebi_id, ub_chebi_ids, ub_s_ids)

    terms = (t for t in (chebi.get_term(t_id) for t_id in s_id2chebi_id.values()) if t)
    old_onto_len = len(chebi)
    filter_ontology(chebi, terms, relationships=EQUIVALENT_RELATIONSHIPS, min_deepness=3)
    logging.info('Filtered the ontology from %d terms to %d' % (old_onto_len, len(chebi)))

    threshold = min(max(3, int(0.1 * input_model.getNumReactions())), UBIQUITOUS_THRESHOLD)
    s_id2clu, ub_s_ids = generalize_species(input_model, s_id2chebi_id, ub_s_ids, chebi, ub_chebi_ids, threshold,
                                            r_ids_to_ignore=r_ids_to_ignore)
    logging.info("generalized species")
    r_id2clu = generalize_reactions(input_model, s_id2clu, s_id2chebi_id, ub_chebi_ids,
                                    r_ids_to_ignore=r_ids_to_ignore)
    logging.info("generalized reactions")

    clu2s_ids = {(c_id, term): s_ids for ((c_id, (term, )), s_ids) in invert_map(s_id2clu).items()}
    r_id2g_eq, s_id2gr_id = save_as_comp_generalized_sbml(input_model, out_sbml, groups_sbml, r_id2clu, clu2s_ids,
                                                          ub_s_ids, chebi)
    return r_id2g_eq, s_id2gr_id, s_id2chebi_id, ub_s_ids
示例#4
0
def generalize_model(in_sbml,
                     chebi,
                     groups_sbml,
                     out_sbml,
                     ub_s_ids=None,
                     ub_chebi_ids=None,
                     ignore_biomass=True):
    """
    Generalizes a model.
    :param in_sbml: str, path to the input SBML file
    :param chebi: mod_sbml.onto.obo_ontology.Ontology ChEBI ontology
    :param groups_sbml: str, path to the output SBML file (with groups extension)
    :param out_sbml: str, path to the output SBML file (generalized)
    :param ub_s_ids: optional, ids of ubiquitous species (will be inferred if set to None)
    :param ub_chebi_ids: optional, ids of ubiquitous ChEBI terms (will be inferred if set to None)
    :param ignore_biomass: boolean, whether to ignore the biomass reaction (and its stoichiometry preserving constraint)
    :return: tuple (r_id2g_eq, s_id2gr_id, s_id2chebi_id, ub_s_ids):
    dict {reaction_id: reaction_group_id}, dict {species_id: species_group_id}, dict {species_id: ChEBI_term_id},
    collection of ubiquitous species_ids.
    """
    # input_model
    input_doc = libsbml.SBMLReader().readSBML(in_sbml)
    input_model = input_doc.getModel()
    r_ids_to_ignore = get_biomass_r_ids(
        input_model) if ignore_biomass else None

    remove_is_a_reactions(input_model)
    annotate_metabolites(input_model, chebi)
    # TODO: fix comp separation
    # separate_boundary_metabolites(input_model)
    remove_unused_elements(input_model)

    logging.info("mapping species to ChEBI")
    s_id2chebi_id = get_species_id2chebi_id(input_model)
    ub_chebi_ids, ub_s_ids = get_ub_elements(input_model, chebi, s_id2chebi_id,
                                             ub_chebi_ids, ub_s_ids)

    terms = (t for t in (chebi.get_term(t_id)
                         for t_id in s_id2chebi_id.values()) if t)
    old_onto_len = len(chebi)
    filter_ontology(chebi,
                    terms,
                    relationships=EQUIVALENT_RELATIONSHIPS,
                    min_deepness=3)
    logging.info('Filtered the ontology from %d terms to %d' %
                 (old_onto_len, len(chebi)))

    threshold = min(max(3, int(0.1 * input_model.getNumReactions())),
                    UBIQUITOUS_THRESHOLD)
    s_id2clu, ub_s_ids = generalize_species(input_model,
                                            s_id2chebi_id,
                                            ub_s_ids,
                                            chebi,
                                            ub_chebi_ids,
                                            threshold,
                                            r_ids_to_ignore=r_ids_to_ignore)
    logging.info("generalized species")
    r_id2clu = generalize_reactions(input_model,
                                    s_id2clu,
                                    s_id2chebi_id,
                                    ub_chebi_ids,
                                    r_ids_to_ignore=r_ids_to_ignore)
    logging.info("generalized reactions")

    clu2s_ids = {(c_id, term): s_ids
                 for ((c_id, (term, )), s_ids) in invert_map(s_id2clu).items()}
    r_id2g_eq, s_id2gr_id = save_as_comp_generalized_sbml(
        input_model, out_sbml, groups_sbml, r_id2clu, clu2s_ids, ub_s_ids,
        chebi)
    return r_id2g_eq, s_id2gr_id, s_id2chebi_id, ub_s_ids