Esempio n. 1
0
 def testRun(self):
     model = load_odemodel(KINETIC_MODEL)
     save_sbml_model(model, KINETIC_MODEL_COPY)
     model_copy = load_odemodel(KINETIC_MODEL_COPY)
     self.assertEqual(model.id, model_copy.id)
     self.assertListEqual(model.compartments.keys(),
                          model_copy.compartments.keys())
     for c1, c2 in zip(model.compartments.values(),
                       model_copy.compartments.values()):
         self.assertEqual(c1.size, c2.size)
     self.assertListEqual(model.metabolites.keys(),
                          model_copy.metabolites.keys())
     self.assertListEqual(model.reactions.keys(),
                          model_copy.reactions.keys())
     for r1, r2 in zip(model.reactions.values(),
                       model_copy.reactions.values()):
         self.assertEqual(r1.name, r2.name)
         self.assertEqual(r1.reversible, r2.reversible)
         self.assertDictEqual(r1.stoichiometry, r2.stoichiometry)
         self.assertDictEqual(r1.regulators, r2.regulators)
     self.assertDictEqual(model.ratelaws, model_copy.ratelaws)
     self.assertDictEqual(model.constant_params, model_copy.constant_params)
     self.assertDictEqual(model.variable_params, model_copy.variable_params)
     for p1, p2 in zip(model.local_params.values(),
                       model_copy.local_params.values()):
         self.assertDictEqual(p1, p2)
Esempio n. 2
0
def carveme(open_bounds, fungi_id, universal_model_path, reaction_scores):
    """
    Calls the CarveMe algorithm for the model reconstruction.
    :param open_bounds: True/False depending on the exchange constrains of the universal model.
    :param fungi_id: Fungi id.
    :param universal_model_path: Path to the universal csv file.
    :param reaction_scores: Scores for the reactions.
    :return: The number of models reconstructed and the average objective value of the models in the ensemble.
    """
    # Open Framed model
    universal_model_framed = load_cbmodel(universal_model_path, exchange_detection_mode='unbalanced', flavor='fbc2',
                                          load_gprs=False, load_metadata=False)

    # Set the bounds of the model
    for reaction in universal_model_framed.reactions:
        if universal_model_framed.reactions[reaction].lb is None:
            universal_model_framed.reactions[reaction].lb = -100
        if universal_model_framed.reactions[reaction].ub is None:
            universal_model_framed.reactions[reaction].ub = 100

    if not open_bounds:
        # Glucose, ammonium, water, O2,...
        universal_model_framed.reactions['R_UF03376_E'].lb = -100
        universal_model_framed.reactions['R_UF02549_E'].lb = -100
        universal_model_framed.reactions['R_UF03382_E'].lb = -100
        universal_model_framed.reactions['R_UF03474_E'].lb = -100
        universal_model_framed.reactions['R_UF02765_E'].lb = -100
        universal_model_framed.reactions['R_UF03268_E'].lb = -100
        universal_model_framed.reactions['R_UF03456_E'].lb = -100
        universal_model_framed.reactions['R_UF03314_E'].lb = -100
        universal_model_framed.reactions['R_UF03288_E'].lb = -100
    else:
        for reaction in universal_model_framed.reactions:
            if reaction.endswith('_E'):
                universal_model_framed.reactions[reaction].lb = -100
                universal_model_framed.reactions[reaction].ub = 100

    # Run CarveMe
    objective, reconstructed_models = CarveMeFuncPool.carve_model(
        universal_model_framed, reaction_scores, eps=1e-3, min_growth=0.1, min_atpm=0.1, feast=1e-7, opti=1e-7)

    # Save the models into files (to be able to work with cobra and update the sbml files)
    if not open_bounds:
        reconstructed_counter = 0
        for modelCreated in reconstructed_models:
            save_sbml_model(modelCreated, 'results/' + fungi_id +
                            str(reconstructed_counter) + 'M.sbml', flavor='cobra')
            reconstructed_counter = reconstructed_counter + 1
    else:
        reconstructed_counter = 0
        for modelCreated in reconstructed_models:
            save_sbml_model(modelCreated, 'results/' + fungi_id +
                            str(reconstructed_counter) + 'O.sbml', flavor='cobra')
            reconstructed_counter = reconstructed_counter + 1
    return reconstructed_counter, objective
Esempio n. 3
0
    def toSBML(self, output_file):
        """
        Writes the generated model to an SBML file.

        Args:
            output_file: string, path to the file where the model should be written. A blank file with no file
            extension shall be used.

        Returns:
            An sbml file
        """
        if self.specific_model is not None:
            save_sbml_model(self.specific_model, output_file + '.xml')
        else:
            print('No tissue specific metabolic model has been built yet')
            return
Esempio n. 4
0
 def testRun(self):
     model = load_cbmodel(SMALL_TEST_MODEL, flavor='cobra')
     save_sbml_model(model, TEST_MODEL_COPY3, flavor='fbc2')
     model_copy = load_cbmodel(TEST_MODEL_COPY3, flavor='fbc2')
     self.assertEqual(model.id, model_copy.id)
     self.assertListEqual(model.compartments.keys(),
                          model_copy.compartments.keys())
     self.assertListEqual(model.metabolites.keys(),
                          model_copy.metabolites.keys())
     self.assertListEqual(model.reactions.keys(),
                          model_copy.reactions.keys())
     for r1, r2 in zip(model.reactions.values(),
                       model_copy.reactions.values()):
         self.assertEqual(r1.name, r2.name)
         self.assertEqual(r1.reversible, r2.reversible)
         self.assertDictEqual(r1.stoichiometry, r2.stoichiometry)
         self.assertEqual(r1.lb, r2.lb)
         self.assertEqual(r1.ub, r2.ub)
         self.assertEqual(str(r1.gpr), str(r2.gpr))
     self.assertListEqual(model.genes.keys(), model_copy.genes.keys())