def test_fix_medium(tmp_path): data = md.test_data() built = build(data, db, str(tmp_path), cutoff=0) bad_medium = medium.iloc[0:2, :] fixed = fix_medium(built, str(tmp_path), bad_medium, 0.5, 0.001, 10) assert fixed.shape[0] > 3 assert "description" in fixed.columns
def test_tradeoff(tmp_path): data = md.test_data() built = build(data, db, str(tmp_path), cutoff=0) rates = tradeoff(built, str(tmp_path), medium) assert "growth_rate" in rates.columns assert "tradeoff" in rates.columns assert rates.dropna().shape[0] < rates.shape[0]
def test_media(tmp_path): data = md.test_data() built = build(data, db, str(tmp_path), cutoff=0) media = minimal_media(built, str(tmp_path), 0.5) assert media.shape[0] > 3 assert "flux" in media.columns assert "reaction" in media.columns
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)
def test_build(tmp_path): data = md.test_data() built = build(data, db, str(tmp_path), cutoff=0) assert built.shape[0] == 4 assert "sample_id" in built.columns assert "found_fraction" in built.columns assert "file" in built.columns for fi in built.file: assert (tmp_path / fi).exists()
def build(abundance: biom.Table, taxonomy: pd.Series, models: JSONDirectory, threads: int = 1, cutoff: float = 0.0001, strict: bool = False, solver: str = "auto") -> CommunityModelDirectory: """Build the community models.""" if solver == "auto": solver = None tax = build_spec(abundance, taxonomy, models, cutoff, strict) out = CommunityModelDirectory() out_folder = str(out.model_files.path_maker(model_id="test")).replace( "test.pickle", "") model_folder = str(models.json_files.path_maker(model_id="test")).replace( "test.json", "") mw.build(tax, model_folder, out_folder, cutoff, threads, solver) os.rename(os.path.join(out_folder, "manifest.csv"), out.manifest.path_maker()) return out
def tradeoff_data(tmp_path): """Generate some growth simulation data.""" data = md.test_data() built = build(data, md.test_db, str(tmp_path), cutoff=0) rates = tradeoff(built, str(tmp_path), medium) return rates
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