Beispiel #1
0
def add_m_model_content(me_model, m_model, complex_metabolite_ids=None):
    """
    Add metabolite and reaction attributes to me_model from m_model. Also
    creates StoichiometricData objects for each reaction in m_model, and adds
    reactions directly to me_model if they are exchanges or demands.

    Parameters
    ----------
    me_model : :class:`cobrame.core.model.MEModel`
        The MEModel object to which the content will be added

    m_model : :class:`cobra.core.model.Model`
        The m_model which will act as the source of metabolic content for
        MEModel

    complex_metabolite_ids : list
        List of complexes which are 'metabolites' in the m-model reaction
        matrix, but should be treated as complexes

    """
    if not complex_metabolite_ids:
        complex_metabolite_ids = []

    for met in m_model.metabolites:
        if met.id in complex_metabolite_ids:
            new_met = cobrame.Complex(met.id)
        elif met.id.startswith("RNA"):
            raise ValueError('Processed M-model should not contain RNAs (%s)' %
                             met.id)
        else:
            new_met = cobrame.Metabolite(met.id)
        new_met.name = met.name
        new_met.formula = met.formula
        new_met.compartment = met.compartment
        new_met.charge = met.charge
        new_met.annotation = met.annotation
        new_met.notes = met.notes
        me_model.add_metabolites(new_met)

    for reaction in m_model.reactions:
        if reaction.id.startswith("EX_") or reaction.id.startswith("DM_"):
            new_reaction = cobrame.MEReaction(reaction.id)
            me_model.add_reaction(new_reaction)
            new_reaction.lower_bound = reaction.lower_bound
            new_reaction.upper_bound = reaction.upper_bound
            for met, stoichiometry in iteritems(reaction.metabolites):
                new_reaction.add_metabolites(
                    {me_model.metabolites.get_by_id(met.id): stoichiometry})

        else:
            reaction_data = cobrame.StoichiometricData(reaction.id, me_model)
            reaction_data.lower_bound = reaction.lower_bound
            reaction_data.upper_bound = reaction.upper_bound
            reaction_data._stoichiometry = {
                k.id: v
                for k, v in iteritems(reaction.metabolites)
            }
Beispiel #2
0
def update_metabolite_formulas(m_model):
    # Formulas of metabolites not included in metabolites.txt
    # 3a1hac1p_c has a typo in the formula in metabolites.txt
    formulas = [('4fe4s_c', 'Fe4S4'), ('2fe2s_c', 'Fe2S2'),
                ('LI_c', 'Li'), ('3a1hac1p_c', 'C3H7NO5P'),
                ]

    for met, formula in formulas:
        try:
            met_obj = m_model.metabolites.get_by_id(met)
        except KeyError:
            warn('Creating new metabolite (%s)' % met)
            met_obj = cobrame.Metabolite(met)
            m_model.add_metabolites([met_obj])
        met_obj.formula = formula
Beispiel #3
0
def add_iron_sulfur_modifications(me_model):

    for name, complexes in generic_fes_transfer_complexes.items():
        generic_fes_transfer = cobrame.GenericData(name, me_model, complexes)
        generic_fes_transfer.create_reactions()

    for fes in ['2fe2s_c', '4fe4s_c']:
        me_model.add_metabolites([cobrame.Metabolite(fes)])
        for name in fes_transfer.values():
            rxn = cobrame.MEReaction('_'.join([name, fes, 'unloading']))
            me_model.add_reactions([rxn])
            rxn.add_metabolites({
                name + '_mod_1:' + fes.replace('_c', ''): -1,
                fes: 1,
                name: 1
            })

    # add fes transfer enzymes to proper modification data
    mod_2fe2s = me_model.process_data.mod_2fe2s_c
    mod_2fe2s.enzyme = 'generic_2fe2s_transfer_complex'
    mod_2fe2s.stoichiometry = {'2fe2s_c': -1.}

    mod_4fe4s = me_model.process_data.mod_4fe4s_c
    mod_4fe4s.enzyme = 'generic_4fe4s_transfer_complex'
    mod_4fe4s.stoichiometry = {'4fe4s_c': -1.}

    mod_3fe4s = me_model.process_data.mod_3fe4s_c
    mod_3fe4s.enzyme = 'generic_4fe4s_transfer_complex'
    mod_3fe4s.stoichiometry = {'4fe4s_c': -1., 'fe2_c': 1}
    mod_3fe4s._element_contribution = {'Fe': 3, 'S': 4}

    for chaperone in set(fes_chaperones.values()):
        new_mod = cobrame.SubreactionData('mod_2fe2s_c_' + chaperone, me_model)
        new_mod.enzyme = [chaperone, 'generic_2fe2s_transfer_complex']
        new_mod.stoichiometry = {'2fe2s_c': -1.}

    for cplx_data in me_model.process_data.get_by_id(
            'mod_2fe2s_c').get_complex_data():
        cplx_id = cplx_data.id.split('_mod')[0]
        if cplx_id in fes_chaperones:
            cplx_data.subreactions['mod_2fe2s_c_' + fes_chaperones[
                cplx_id]] = \
                cplx_data.subreactions.pop('mod_2fe2s_c')
Beispiel #4
0
def get_remaining_complex_elements(model, complex, modification_formulas):

    tmp_met = cobrame.Metabolite('tmp_met')
    mets = model.metabolites
    components = complex.id.split('_mod_')
    base_complex = components[0]
    elements = Counter()

    # If a the completely unmodified complex is present in the model
    # has a formula, initialize the elements dictionary with that
    if base_complex in mets and mets.get_by_id(base_complex).formula:
        elements.update(mets.get_by_id(base_complex).elements)
    for component in components[1:]:
        new_elements = elements.copy()
        new_complex = '_mod_'.join([base_complex, component])
        if new_complex in mets and mets.get_by_id(new_complex).formula:

            # default to new_complex elements if both new and old exist
            if base_complex in mets and mets.get_by_id(base_complex).formula:
                new_elements = Counter()
            formula = mets.get_by_id(new_complex).formula
            tmp_met.formula = formula
            new_elements.update(tmp_met.elements)

        # Net effect of an SH modification is adding a Sulfur to elements
        elif ':SH' in component:
            new_elements['S'] += 1

        # modifies O- to SH
        elif component == 'cosh':
            new_elements['O'] -= 1
            new_elements['S'] += 1
            new_elements['H'] += 1

        elif component in modification_formulas:
            formula = modification_formulas[component]
            tmp_met.formula = formula
            new_elements.update(tmp_met.elements)

        elif ':' in component:
            value, component = component.split(':')
            if component in modification_formulas:
                formula = modification_formulas[component]['formula']
            elif component + '_c' in mets:
                formula = mets.get_by_id(component + '_c').formula
            else:
                raise UserWarning('No formula found for modification (%s)' %
                                  component)
            tmp_met.formula = formula

            for e, v in tmp_met.elements.items():
                new_elements[e] += v * float(value)

        elif 'Oxidized' in component and 'FLAVODOXIN' not in base_complex:
            new_elements.update({'H': -2})

        if elements == new_elements and 'FLAVODOXIN' not in base_complex:
            print(complex.id, base_complex, component)
        base_complex = '_mod_'.join([base_complex, component])
        elements = new_elements.copy()

    return elements
Beispiel #5
0
def process_m_model(m_model,
                    metabolites_file,
                    m_to_me_map_file,
                    reaction_info_file,
                    reaction_matrix_file,
                    protein_complex_file,
                    defer_to_rxn_matrix=set()):

    m_model = m_model.copy()

    met_info = pandas.read_csv(
        fixpath(metabolites_file),
        delimiter="\t",
        header=None,
        index_col=0,
        names=["id", "name", "formula", "compartment", "data_source"])
    met_info.rename(lambda x: x.replace('_DASH_', '__'), inplace=True)

    complex_set = \
        set(get_complex_subunit_stoichiometry(protein_complex_file).keys())

    rxn_info = get_reaction_info_frame(reaction_info_file)
    reaction_matrix_dict = get_reaction_matrix_dict(reaction_matrix_file,
                                                    complex_set=complex_set)

    m_to_me_df = pandas.read_csv(fixpath(m_to_me_map_file),
                                 index_col=0,
                                 names=['m_name', 'me_name'])

    for rxn in list(m_model.reactions):
        if rxn.id.startswith('EX_') or rxn.id.startswith('DM_'):
            continue
        if rxn.id not in reaction_matrix_dict.keys() \
                or rxn.id in defer_to_rxn_matrix:
            rxn.remove_from_model(remove_orphans=True)
    for rxn_id in reaction_matrix_dict:
        if rxn_id in m_model.reactions:
            continue
        rxn_stoichiometry = reaction_matrix_dict[rxn_id]
        for met in rxn_stoichiometry:
            try:
                met_obj = m_model.metabolites.get_by_id(met)
            except KeyError:
                met_obj = cobrame.Metabolite(str(met))
                m_model.add_metabolites([met_obj])
            met_id = remove_compartment(met_obj.id)
            if met_id in met_info.index and not met_obj.formula:
                met_obj.formula = met_info.loc[met_id, 'formula']
                met_obj.name = met_info.loc[met_id, 'name']

        rxn = cobrame.MEReaction(rxn_id)
        m_model.add_reactions([rxn])
        rxn.add_metabolites(rxn_stoichiometry)
        reversible = rxn_info.loc[rxn_id, 'is_reversible']
        rxn.lower_bound = -1000 if reversible else 0

    for met in list(m_model.metabolites):
        met_id = remove_compartment(met.id)
        if met_id not in met_info.index and met_id in m_to_me_df.index:
            met_id = m_to_me_df.loc[met.id, 'me_name']
            if met_id != '' and met_id != 'N/A':
                met.id = met_id
            else:
                met.remove_from_model()

    # Add formulas not included in metabolites.txt
    corrections.update_metabolite_formulas(m_model)

    m_model.repair()

    return m_model