Skip to content

Commit

Permalink
Merge pull request #37 from YosefLab/canergen-parent
Browse files Browse the repository at this point in the history
Canergen parent
  • Loading branch information
canergen authored Feb 13, 2024
2 parents e6152d4 + f3d0c74 commit e6df35b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion popv/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def annotate_data(
adata.obs[["popv_prediction", "popv_prediction_score"]] = adata.obs[
["popv_majority_vote_prediction", "popv_majority_vote_score"]
]
adata.obs[["popv_prediction_parent"]] = adata.obs[["popv_majority_vote_prediction"]]
adata.obs[["popv_parent"]] = adata.obs[["popv_majority_vote_prediction"]]
else:
ontology_vote_onclass(adata, all_prediction_keys)
ontology_parent_onclass(adata, all_prediction_keys)
Expand Down
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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies = [
"gdown>4.6.0",
"h5py>3.7.0",
"huggingface-hub>=0.11.1",
"jax<0.4.24", # Remove with scvi-tools 1.1
"jaxlib<0.4.24",
"onclass>=1.3",
"scanorama>1.7.2",
"scanpy>1.9.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_celltypist():
def test_annotation():
"""Test Annotation and Plotting pipeline."""
adata = _get_test_anndata().adata
popv.annotation.annotate_data(adata, methods=["svm", "rf"], save_path=None)
popv.annotation.annotate_data(adata, methods=["svm", "rf"], save_path="tests/tmp_testing/popv_test_results/")
popv.visualization.agreement_score_bar_plot(adata)
popv.visualization.prediction_score_bar_plot(adata)
popv.visualization.make_agreement_plots(adata, prediction_keys=adata.uns["prediction_keys"])
Expand All @@ -190,7 +190,7 @@ def test_annotation():
def test_annotation_no_ontology():
"""Test Annotation and Plotting pipeline without ontology."""
adata = _get_test_anndata(cl_obo_folder=False).adata
popv.annotation.annotate_data(adata, methods=["svm", "rf"], save_path=None)
popv.annotation.annotate_data(adata, methods=["svm", "rf"], save_path="tests/tmp_testing/popv_test_results/")
popv.visualization.agreement_score_bar_plot(adata)
popv.visualization.prediction_score_bar_plot(adata)
popv.visualization.make_agreement_plots(adata, prediction_keys=adata.uns["prediction_keys"])
Expand Down

0 comments on commit e6df35b

Please sign in to comment.