Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ fail_fast: false
default_language_version:
python: python3
default_stages:
- pre-commit
- pre-push
- commit
minimum_pre_commit_version: 2.16.0
repos:
- repo: https://github.com/asottile/blacken-docs
Expand All @@ -18,7 +17,7 @@ repos:
types: [yaml]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.22
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -31,7 +30,7 @@ repos:
)$

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.45.0
rev: v0.47.0
hooks:
- id: markdownlint-fix
exclude: |
Expand All @@ -41,7 +40,7 @@ repos:
)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.1
rev: v0.15.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
13 changes: 9 additions & 4 deletions popv/algorithms/_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ def compute_integration(self, adata):
logging.info("Integrating data with bbknn")
if len(adata.obs[self.batch_key].unique()) > 100:
self.method_kwargs["neighbors_within_batch"] = 1
if settings.cuml:
if len(adata.obs[self.batch_key].unique()) > 200 and settings.cuml:
logging.warning(
f"Number of batches is {len(adata.obs[self.batch_key].unique())}, skipping RAPIDS BBKNN and running on CPU."
)
cuml = False
else:
cuml = settings.cuml
if cuml:
import rapids_singlecell as rsc

self.method_kwargs.pop("approx", None) # approx not supported in rsc
self.method_kwargs.pop("use_annoy", None) # use_annoy not supported in rsc
rsc.pp.bbknn(
adata, batch_key=self.batch_key, use_rep="X_pca", algorithm="ivfflat", **self.method_kwargs, trim=0
)
rsc.pp.bbknn(adata, batch_key=self.batch_key, use_rep="X_pca", algorithm="ivfflat", **self.method_kwargs)
else:
sc.external.pp.bbknn(adata, batch_key=self.batch_key, use_rep="X_pca", **self.method_kwargs)

Expand Down
2 changes: 2 additions & 0 deletions popv/algorithms/_onclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def predict(self, adata):
else:
adata.obs[col] = adata.uns["unknown_celltype_label"]
adata.obs[col] = adata.obs[col].astype(str) # Set dtype to string
adata.obs[self.result_key] = adata.obs[self.result_key].astype(str)
adata.obs[self.seen_result_key] = adata.obs[self.seen_result_key].astype(str)
adata.obs.loc[adata.obs["_predict_cells"] == "relabel", result_df.columns] = result_df
if self.return_probabilities:
if f"{self.result_key}_probabilities" not in adata.obsm:
Expand Down
2 changes: 1 addition & 1 deletion popv/algorithms/_scanvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def compute_umap(self, adata):
Anndata object. Results are stored in adata.obsm[self.umap_key].
"""
if self.compute_umap_embedding:
logging.info(f'Saving UMAP of BBKNN results to adata.obsm["{self.umap_key}"]')
logging.info(f'Saving UMAP of scANVI results to adata.obsm["{self.umap_key}"]')
if settings.cuml:
import rapids_singlecell as rsc

Expand Down
17 changes: 11 additions & 6 deletions popv/hub/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def from_anndata(
Additional keyword arguments to pass to the HubMetadata initializer.
"""
setup_dict = adata.uns["_setup_dict"]
prediction_keys = adata.uns["prediction_keys"]
methods = adata.uns["methods"]
prediction_keys = list(adata.uns["prediction_keys"])
methods = list(adata.uns["methods"])
method_kwargs = adata.uns["method_kwargs"]

return cls(
Expand Down Expand Up @@ -122,6 +122,8 @@ class HubModelCardHelper:
The version of `scvi-tools` that the model was trained with.
anndata_version
The version of anndata used during model training.
popv_version
The version of popV that the model was trained with.
scikit_learn_version
The version of scikit-learn used during model training.
organism
Expand Down Expand Up @@ -153,6 +155,7 @@ class HubModelCardHelper:

license_info: str
anndata_version: str
popv_version: str
scikit_learn_version: str
organism: str
tissues: list[str] = field(default_factory=list)
Expand All @@ -172,6 +175,7 @@ def from_dir(
license_info: str,
anndata_version: str,
scikit_learn_version: str,
popv_version: str,
organism: str,
metrics_report: str | None = None,
**kwargs,
Expand Down Expand Up @@ -210,6 +214,7 @@ def from_dir(
return cls(
license_info,
anndata_version,
popv_version,
scikit_learn_version,
organism,
metrics_report=metrics_report,
Expand All @@ -222,11 +227,11 @@ def _to_model_card(self) -> ModelCard:
"biology",
"genomics",
"single-cell",
f"anndata_version:{self.anndata_version}",
f"scikit_learn_version:{self.scikit_learn_version}",
f"AnnData:{self.anndata_version}",
f"scikit_learn:{self.scikit_learn_version}",
f"organism:{self.organism}",
f"python_version:{'.'.join([str(i) for i in sys.version_info[:3]])}",
"popV",
f"Python:{'.'.join([str(i) for i in sys.version_info[:3]])}",
f"popV:{self.popv_version}",
]
for t in self.tissues:
tags.append(f"tissue: {t}")
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude = ["resources/*", "tests/*", "dataset/*"]

[project]
name = "popV"
version = "0.6.0"
version = "0.6.1"
description = "Consensus prediction of cell type labels with popV"
readme = "README.md"
requires-python = ">=3.10"
Expand Down Expand Up @@ -41,16 +41,17 @@ dependencies = [
"anndata",
"bbknn",
"celltypist",
"harmonypy",
"harmonypy<0.1.0",
"huggingface-hub",
"onclass",
"scanorama",
"scanpy",
"scikit-misc",
"scvi-tools",
"tensorflow",
"tensorflow<2.18",
"huggingface",
"xgboost",
"scikit-learn<1.8.0",
"faiss-cpu",
"leidenalg",
"cellxgene_census",
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def test_annotation_hub(private: bool):
"references": "Tabula Sapiens reveals transcription factor expression, senescence effects, and sex-specific features in cell types from 28 human organs and tissues, The Tabula Sapiens Consortium; bioRxiv, doi: https://doi.org/10.1101/2024.12.03.626516",
"license_info": "cc-by-4.0",
}
hmch = popv.hub.HubModelCardHelper.from_dir(output_folder, anndata_version=anndata.__version__, **model_json)
hmch = popv.hub.HubModelCardHelper.from_dir(
output_folder, anndata_version=anndata.__version__, popv_version=popv.__version__, **model_json
)
hm = popv.hub.HubMetadata.from_anndata(
adata,
popv_version=popv.__version__,
Expand Down
Loading