Exemple #1
0
def test_grow(tmp_path):
    data = md.test_data()
    built = build(data, db, str(tmp_path), cutoff=0)
    grown = grow(built, str(tmp_path), medium, 0.5)
    assert len(grown) == 3
    assert "growth_rate" in grown.growth_rates.columns
    assert "flux" in grown.exchanges.columns
    with pytest.raises(OptimizationError):
        grow(built, str(tmp_path), medium, 1.5)
Exemple #2
0
def grow(models: CommunityModelDirectory,
         medium: pd.DataFrame,
         tradeoff: float = 0.5,
         threads: int = 1,
         strategy: str = "pFBA") -> mw.core.GrowthResults:
    """Simulate growth for a set of community models."""
    if strategy == "minimal uptake":
        strategy = "minimal imports"
    model_folder = str(models.model_files.path_maker(model_id="blub")).replace(
        "blub.pickle", "")
    manifest = models.manifest.view(pd.DataFrame)
    results = mw.grow(manifest,
                      model_folder,
                      medium,
                      tradeoff,
                      threads,
                      strategy=strategy)

    return results
Exemple #3
0
# save this community to file (Can I save one pickle file per GEM?)
comm_fp = model_path + "/" + sample + "_community.pickle"
com.to_pickle(comm_fp)
#load it:
# com = load_pickle("1_interm_files/community.pickle")
# see exchanges:
#com.exchanges

print("\n simulating growth\n")

#############################
# SIMULATE GROWTH
comm_filename = sample + "_community.pickle"
manifest = pd.DataFrame({
    "sample_id": sample,
    "file": comm_filename
},
                        index=[0])

res = grow(manifest, model_path, medium=medium, tradeoff=0.5, threads=12)
res.exchanges

## save to file:
out_fp = "exchanges_grow_" + sample + ".csv"
outfile = open(out_fp, "w")
res.exchanges.to_csv(outfile)
outfile.close()

print("\nDONE!!\n")
Exemple #4
0
def growth_data(tmp_path):
    """Generate some growth simulation data."""
    data = md.test_data()
    built = build(data, md.test_db, str(tmp_path), cutoff=0)
    grown = grow(built, str(tmp_path), medium, 0.5)
    return grown
Exemple #5
0
manifest = pd.DataFrame({
    "sample_id": sample,
    "file": comm_filename
},
                        index=[0])

# Medium (western diet, after diluting nutrients absorbed in the small intestine)
med = pd.DataFrame(com.medium.items(), columns=['reaction', 'flux'])

# test increasing flux
med['flux'] = med['flux'] * 6

# grow!! using parsimonious FBA
res = grow(manifest,
           pickles_path,
           medium=med,
           tradeoff=trade_off,
           threads=th,
           strategy="pFBA")
res.exchanges

# divide fluxes by the 600 (100 added in the build_comm_models, multiplied by 6 here)
res.exchanges['flux'] = res.exchanges['flux'] / 600

## add sample name:
res.exchanges['sample_id'] = sample
res.growth_rates['sample_id'] = sample

## save to file:
out_fp_exc = out_dir + "/" + "exchanges_grow_" + sample + ".csv"
outfile = open(out_fp_exc, "w")
res.exchanges.to_csv(out_fp_exc)