Ejemplo n.º 1
0
def capitulo_6():
    model = cobra.test.create_test_model("textbook")
    prod_env = production_envelope(model, ["EX_glc__D_e", "EX_o2_e"])
    prod_env.head()
    prod_env = production_envelope(model, ["EX_o2_e"],
                                   objective="EX_ac_e",
                                   c_source="EX_glc__D_e")
    prod_env.head()
    prod_env[prod_env.direction == 'maximum'].plot(kind='line',
                                                   x='EX_o2_e',
                                                   y='carbon_yield')
Ejemplo n.º 2
0
def productionEnvelopes():  #aka phenotype phase planes
    # will show distinct phases of optimal growth with different use of two different substrates.
    import cobra.test
    from cobra.flux_analysis import production_envelope
    model = cobra.test.create_test_model("textbook")

    prod_env = production_envelope(model, ["EX_glc__D_e", "EX_o2_e"])
    prod_env.head()
    prod_env = production_envelope(model, ["EX_o2_e"],
                                   objective="EX_ac_e",
                                   c_source="EX_glc__D_e")
    prod_env.head()
    prod_env[prod_env.direction == 'maximum'].plot(kind='line',
                                                   x='EX_o2_e',
                                                   y='carbon_yield')
Ejemplo n.º 3
0
def test_envelope_two(model: Model) -> None:
    """Test production of envelope."""
    df = production_envelope(model, ["EX_glc__D_e", "EX_o2_e"],
                             objective="EX_ac_e")
    assert np.isclose(df["flux_maximum"].sum(), 1737.466, atol=1e-3)
    assert np.isclose(df["carbon_yield_maximum"].sum(), 83.579, atol=1e-3)
    assert np.isclose(df["mass_yield_maximum"].sum(), 82.176, atol=1e-3)
Ejemplo n.º 4
0
    def _robustness_ppp(self,
                        conditions,
                        sheet,
                        reactions,
                        points=20,
                        reactions_constraints=None,
                        dense_output=False,
                        columns_to_drop=None,
                        output=None,
                        output_sheet=None,
                        minimum_growth=0.1,
                        ):

        if not columns_to_drop:
            columns_to_drop = []

        if not reactions_constraints:
            reactions_constraints = {}

        # just a wrapper for cobrapy production_envelope function
        df = read_excel(os.path.join(self.conditions_directory, conditions), sheet)

        with self.model:

            self.apply_conditions(data_frame=df)

            for rxn, bds in reactions_constraints.items():
                self.get_reaction(rxn).bounds = bds

            _growth = self.maximize(is_pfba=True)
            if _growth < minimum_growth:
                raise ValueError(f'Wrong Environmental Conditions, as growth rate is {_growth}')

            sol = production_envelope(model=self.model,
                                      reactions=reactions,
                                      points=points, )

        sol.drop(columns_to_drop, axis=1, inplace=True)

        # transform the sparse ppp dataframe to dense ppp dataframe
        if dense_output:

            new_sol = DataFrame()

            for row in sol.values:
                _val, _col, _row = row
                new_sol.loc[_row, _col] = _val

            sol = new_sol

            sol.fillna(0, inplace=True)

            sol.sort_index(inplace=True)
            sol.sort_index(axis=1, inplace=True)

        return sol
Ejemplo n.º 5
0
print(maxval)

#model.reactions.get_by_id('PGI').lower_bound = 0
#model.reactions.get_by_id('PGI').upper_bound = 0

#print (model.slim_optimize())

#from cobra .medium import minimal_medium
#max_growth= model.slim_optimize()
#print (minimal_medium(model,max_growth))
#print (len (minimal_medium(model,max_growth)))
cobra.io.write_sbml_model(model, "iRsp_1066_v1.5.xml", use_fbc_package=False)
#en=production_envelope  (model,['EX_o2_e','EX_glc__D_e'],objective= 'DM_ipdp', carbon_sources= 'EX_glc__D_e',points = 5)
en = np.array(
    production_envelope(model, ["DM_ipdp"],
                        objective="BIOMASS_aerobic",
                        carbon_sources='EX_glc__D_e',
                        points=2000))
np.savetxt('MEP_Product_Nh4.csv', en, fmt='%s')
np.savetxt('MEP_ProductFVA_NH4.csv', FVA, fmt='%s')
print(en)

#OptKnock
'''KO= OptKnock (model)

result_OK = optknock.run(max_knockouts = NrKnockOuts,
                      target        = "RXN0569",
                      biomass       = biomass,
                      max_results   = 50)

OptKnockResult = pandas.DataFrame(result_OK.data_frame)
OptKnockResult.to_csv(path_or_buf = "/home//%s.csv" % RUN, sep = ";", decimal = ",")'''
Ejemplo n.º 6
0
def test_envelope_one(model: Model) -> None:
    """Test flux of production envelope."""
    df = production_envelope(model, ["EX_o2_e"])
    assert np.isclose(df["flux_maximum"].sum(), 9.342, atol=1e-3)
Ejemplo n.º 7
0
def test_multi_variable_envelope(model: Model, variables: str,
                                 num: int) -> None:
    """Test production of envelope (multiple variable)."""
    df = production_envelope(model, variables, points=num)
    assert len(df) == num**len(variables)
Ejemplo n.º 8
0
def test_envelope_multi_reaction_objective(model: Model) -> None:
    """Test production of multiple objectives."""
    obj = {model.reactions.EX_ac_e: 1, model.reactions.EX_co2_e: 1}
    with pytest.raises(ValueError):
        production_envelope(model, "EX_o2_e", obj)
Ejemplo n.º 9
0
            for reaction in model.metabolites.get_by_id(
                    metabolite.id).reactions:
                print reaction


result = buscarMetabolito("gln__L")
result = buscarMetabolito("glc__D")
result = buscarMetabolito("xoltri25_e")
result = buscarMetabolito("lac")
result = buscarMetabolito("nh4")

# In[77]:

print
get_ipython().magic(u'matplotlib inline')
prod_env = production_envelope(model, ["EX_gln__L_e", "EX_glc__D_e"])
prod_env.head(20)

# In[86]:

x = np.unique(-1 * prod_env["EX_glc__D_e"])
y = np.unique(-1 * prod_env["EX_gln__L_e"])
z = prod_env["flux_maximum"]

MATRIZ_SOLUCION = np.zeros((20, 20))
for i in range(datos):
    print prod_env["flux_maximum"][i * 20:(i + 1) * 20]
    MATRIZ_SOLUCION[i, 0:20] = z[i * 20:(i + 1) * 20]
print "Matriz solución"
print "====================="
print MATRIZ_SOLUCION