Skip to content

Commit

Permalink
rather fix in phenotype
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiener committed Mar 1, 2024
1 parent 5578ca1 commit f4a7007
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions micom/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def production_rates(results):
"""
fluxes = results.exchanges
pos = fluxes[(fluxes.direction == "export") & (fluxes.taxon != "medium")]
rates = pos.groupby(["sample_id", "metabolite"]).apply(
lambda df: pd.Series({"flux": np.sum(df.abundance * df.flux.abs())})
).reset_index()
rates = pd.merge(rates, results.annotations, on="metabolite")
rates = (
pos.groupby(["sample_id", "metabolite"])
.apply(lambda df: pd.Series({"flux": np.sum(df.abundance * df.flux.abs())}))
.reset_index()
)
rates = pd.merge(
rates,
results.annotations.drop_duplicates(subset=["metabolite"]),
on="metabolite",
)
return rates


Expand Down Expand Up @@ -63,8 +69,14 @@ def consumption_rates(results):
"""
fluxes = results.exchanges
neg = fluxes[(fluxes.direction == "import") & (fluxes.taxon != "medium")]
rates = neg.groupby(["sample_id", "metabolite"]).apply(
lambda df: pd.Series({"flux": np.sum(df.abundance * df.flux.abs())})
).reset_index()
rates = pd.merge(rates, results.annotations, on="metabolite")
rates = (
neg.groupby(["sample_id", "metabolite"])
.apply(lambda df: pd.Series({"flux": np.sum(df.abundance * df.flux.abs())}))
.reset_index()
)
rates = pd.merge(
rates,
results.annotations.drop_duplicates(subset=["metabolite"]),
on="metabolite",
)
return rates
2 changes: 1 addition & 1 deletion micom/viz/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def plot_fit(
"""
exchanges = results.exchanges
anns = results.annotations
anns = results.annotations.drop_duplicates(subset=["metabolite"])
anns.index = anns.metabolite
if flux_type == "import":
exchanges = exchanges[
Expand Down

0 comments on commit f4a7007

Please sign in to comment.