Example #1
0
def add_remaining_complex_formulas(model, modification_formulas):
    """
        Add formula to complexes that are not formed from a complex formation
        reaction (ie. complexes involved in metabolic reactions)
    """
    element_dict = {}

    # Reset all formulas first
    complex_list = []
    for c in model.metabolites:
        # If not complex or formed by complex formation reaction, do not reset
        if not isinstance(c, cobrame.Complex) or c.id in model.process_data:
            continue
        for r in c.reactions:
            if hasattr(r, 'update'):
                r.update()

        c.formula = ''
        c.elements = {}
        complex_list.append(c)

    # Get formulas only for complexes without complex formation reaction
    for c in complex_list:
        element_dict[c] = get_remaining_complex_elements(
            model, c, modification_formulas)

    # Adding elements for complexes dynamically can change function output
    # Update all of them after
    for c, elements in element_dict.items():
        massbalance.elements_to_formula(c, elements)
Example #2
0
    def _add_formula_to_transcript(self, transcript):
        """

        Add element formula to transcript based on nucleotide composition.
        1 OH group is removed for each nucleotide to account for polymerization
        of mononucleotides. This was done to instead of considering the 3'
        diphosphate group as a simplification to avoid keeping track of the
        3' nucleotide in cases of transcription unit splicing.

        Parameters
        ----------
        transcript : :class:`cobra.core.component.TranscribedGene`
            Instance of gene being transcribed

        """

        elements = defaultdict(int)

        for nuc, value in iteritems(transcript.nucleotide_count):
            nuc_obj = self._model.metabolites.get_by_id(nuc)
            for e, n in iteritems(nuc_obj.elements):
                elements[e] += value * n

        # Remove -OH for each
        elements['H'] -= len(transcript.nucleotide_sequence)
        elements['O'] -= len(transcript.nucleotide_sequence)

        massbalance.elements_to_formula(transcript, elements)
Example #3
0
    def _add_formula_to_complex(self, complex_data, complex_met):
        """
        Add chemical formula as sum of all protein and modification components
        detailed in subreaction data.

        Parameters
        ----------
        complex_data : :class:`cobrame.core.processdata.ComplexData`
            Complex data for complex being formed in the reaction

        complex_met : :class:`cobrame.core.processdata.ComplexData`
            Metabolite of complex being formed in the reaction

        """
        elements = defaultdict(int)
        for component, count in iteritems(complex_data.stoichiometry):
            component_obj = self._model.metabolites.get_by_id(component)
            for e, n in iteritems(component_obj.elements):
                elements[e] += n * count
        elements = \
            massbalance.get_elements_from_process_data(self, complex_data,
                                                       elements)

        # Convert element dict to formula string and associate it with complex
        massbalance.elements_to_formula(complex_met, elements)
Example #4
0
    def _add_formula_to_protein(self, translation_data, protein):
        """
        Adds formula to protein based on amino acid sequence and subreactions

        Some subreactions modify the composition of the protein, therefore
        this must be accounted for.

        Water is subtracted from the formula to with a multiplier of
        len(amino_acid_sequence) - 1 to account for the condensation
        reactions that occur during amino acid polymerization.

        Parameters
        ----------
        translation_data : :class:`cobra.core.processdata.TranslationData`
            This is required to subtract elements removed/added to protein
            when applying reaction defined in subreaction

        protein : :class:`cobra.core.processdata.TranslationData`
            Protein product that needs a chemical formula

        """
        elements = defaultdict(int)
        aa_count = self.translation_data.amino_acid_count
        for aa_name, value in iteritems(aa_count):
            aa_obj = self._model.metabolites.get_by_id(aa_name)
            for e, n in iteritems(aa_obj.elements):
                elements[e] += n * value
        elements = massbalance.get_elements_from_process_data(
            self, translation_data, elements)
        # subtract water from composition
        protein_length = len(translation_data.amino_acid_sequence)
        elements["H"] -= (protein_length - 1) * 2
        elements["O"] -= protein_length - 1

        massbalance.elements_to_formula(protein, elements)
Example #5
0
    def calculate_biomass_contribution(self):
        """
        Calculate net biomass increase/decrease as a result of the subreaction
        process.

        If subreaction adds a chemical moiety to a macromolecules via a
        modification or other means, the biomass contribution of the
        modification process should be accounted for and ultimately included
        in the reaction it is involved in.

        Returns
        -------
        float
            Mass of moiety transferred to macromolecule by subreaction

        """
        elements = self.element_contribution

        # Create temporary metabolite for calculating formula weight
        tmp_met = cobra.Metabolite('mass')
        elements_to_formula(tmp_met, elements)

        return tmp_met.formula_weight
Example #6
0
    def update(self, verbose=True):
        """
        Creates reaction using the associated posttranslation data and adds
        chemical formula to processed protein product

        This function adds the following components to the reaction
        stoichiometry (using 'data' as shorthand for
        :class:`cobrame.core.processdata.PostTranslationData`):

        1) Processed protein product defined in data.processed_protein_id

        2) Unprocessed protein reactant defined in data.unprocessed_protein_id

        3) Metabolites and enzymes defined in data.subreactions

        4) Translocation pathways defined in data.translocation

        5) Folding mechanism defined in data.folding_mechanims w/ coupling
           coefficients defined in data.keq_folding, data.k_folding,
           model.global_info['temperature'], data.aggregation_propensity,
           and data.propensity_scaling

        6) Surface area constraints defined in data.surface_are

        7) Biomass if a significant chemical modification takes place (i.e.
           lipid modifications for lipoproteins)

        Parameters
        ----------
        verbose : bool
            Prints when new metabolites are added to the model when executing
            update()

        """
        self.clear_metabolites()
        stoichiometry = defaultdict(float)
        metabolites = self._model.metabolites
        posttranslation_data = self.posttranslation_data
        unprocessed_protein = posttranslation_data.unprocessed_protein_id
        processed_protein = posttranslation_data.processed_protein_id

        # folding properties
        folding_mechanism = posttranslation_data.folding_mechanism
        aggregation_propensity = posttranslation_data.aggregation_propensity
        scaling = posttranslation_data.propensity_scaling
        if folding_mechanism:
            temp = str(self._model.global_info['temperature'])
            keq_folding = posttranslation_data.keq_folding[temp]
            k_folding = posttranslation_data.k_folding[temp] * 3600.  # in hr-1

        # Get or make processed protein metabolite
        try:
            protein_met = metabolites.get_by_id(processed_protein)
        except KeyError:
            protein_met = cobrame.ProcessedProtein(processed_protein,
                                                   unprocessed_protein)
            self._model.add_metabolites(protein_met)

        # Add subreactions (e.g. lipid modifications for lipoproteins)
        stoichiometry = self.add_subreactions(posttranslation_data.id,
                                              stoichiometry)

        # Add translocation pathways, if applicable
        if posttranslation_data.translocation:
            stoichiometry = \
                self.add_translocation_pathways(posttranslation_data.id,
                                                unprocessed_protein,
                                                stoichiometry)

        # Add folding protein coupling coefficients, if applicable
        if folding_mechanism == 'folding_spontaneous':
            dilution = (keq_folding + mu / k_folding)
            stoichiometry[unprocessed_protein] -= (dilution + 1.)
            stoichiometry[protein_met.id] += 1.

        elif folding_mechanism:
            dilution = aggregation_propensity * scaling * (keq_folding + 1.)+1.
            stoichiometry[unprocessed_protein] -= (1. / dilution + 1.)

            stoichiometry[protein_met.id] += 1. / dilution
            stoichiometry[protein_met.id.replace('_folded', '')] += (1.)
        else:
            stoichiometry[unprocessed_protein] = -1.
            stoichiometry[protein_met.id] = 1.

        # Add surface area constraints for all translocated proteins, if
        # applicable
        surface_area = posttranslation_data.surface_area
        if surface_area:
            for SA, value in iteritems(surface_area):
                try:
                    sa_constraint = metabolites.get_by_id(SA)
                except KeyError:
                    warn('Constraint %s added to model' % SA)
                    sa_constraint = cobrame.Constraint(SA)
                    self._model.add_metabolites([sa_constraint])

                stoichiometry[sa_constraint.id] += value

        # Convert metabolite strings to metabolite objects
        object_stoichiometry = self.get_components_from_ids(stoichiometry,
                                                            verbose=verbose)

        # Add formula as sum of unprocessed protein and modification components
        elements = defaultdict(int)
        elements.update(metabolites.get_by_id(unprocessed_protein).elements)
        elements = \
            massbalance.get_elements_from_process_data(self,
                                                       posttranslation_data,
                                                       elements)

        # Convert element dict to formula string and associate it with complex
        massbalance.elements_to_formula(protein_met, elements)

        # Add biomass from significant modifications (i.e. lipids for
        # lipoproteins)
        biomass = self.add_biomass_from_subreactions(posttranslation_data)
        if biomass > 0 and posttranslation_data.biomass_type:
            self.add_metabolites({metabolites.get_by_id(
                posttranslation_data.biomass_type): biomass})
        elif biomass > 0 and not posttranslation_data.biomass_type:
            raise ValueError('If subreactions in PostTranslationData modify '
                             'the protein, the biomass_type must be provided')

        self.add_metabolites(object_stoichiometry, combine=False)