Skip to content

Commit

Permalink
Update visualization.py
Browse files Browse the repository at this point in the history
Normalize cell-type abundance plots
  • Loading branch information
canergen authored Feb 12, 2024
1 parent 5780226 commit 83bc75a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions popv/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def prediction_score_bar_plot(
def celltype_ratio_bar_plot(
adata,
popv_prediction: str | None = "popv_prediction",
normalize: bool = True
save_folder: str | None = None,
):
"""
Expand All @@ -167,6 +168,8 @@ def celltype_ratio_bar_plot(
AnnData object.
popv_prediction
Key in adata.obs for predictions.
normalize
Plot relative cell-type abundance. Set to False to plot absolute abundance.
save_folder
Path to a folder for storing the plot. Defaults to None and plot is not stored.
Expand All @@ -182,6 +185,8 @@ def celltype_ratio_bar_plot(
for x in cell_types:
prop.loc[x, "query"] = np.sum(labels[is_query] == x)
prop.loc[x, "ref"] = np.sum(labels[~is_query] == x)
if normalize:
prop = prop.div(prop.sum(axis=1))

ax = prop.loc[cell_types].plot(kind="bar", figsize=(len(cell_types) * 0.5, 4), logy=True)
ax.set_ylabel("Celltype")
Expand Down

0 comments on commit 83bc75a

Please sign in to comment.