From 166fed09934716499bd2c2dc96956d0076201e2a Mon Sep 17 00:00:00 2001 From: burtonrj Date: Mon, 30 Oct 2023 19:40:54 +0000 Subject: [PATCH] PR corrections - inplace instead of copy on flowsom function --- .pre-commit-config.yaml | 2 +- docs/tutorials/flowsom.ipynb | 10 +++------- pytometry/tools/clustering/_flowsom.py | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c256d00..470d542 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: language_version: python3 args: - --max-line-length=88 - - --ignore=E203 + - --ignore=E203,TYP001 exclude: | (?x)( __init__.py diff --git a/docs/tutorials/flowsom.ipynb b/docs/tutorials/flowsom.ipynb index d7474d9..966fe24 100644 --- a/docs/tutorials/flowsom.ipynb +++ b/docs/tutorials/flowsom.ipynb @@ -14,11 +14,7 @@ "cell_type": "code", "execution_count": null, "id": "fa01f5013e68d3d2", - "metadata": { - "jupyter": { - "outputs_hidden": false - } - }, + "metadata": {}, "outputs": [], "source": [ "import scanpy as sc\n", @@ -163,7 +159,7 @@ "metadata": {}, "source": [ "We can now cluster our data with the `flowsom_clustering` function from the `tl` (tools) module of `pytometry`. The FlowSOM algorithm works in the following stages:\n", - "1. A self-organsing map is trained that learns a low dimensional embedding of the single cell feature space\n", + "1. A self-organising map is trained that learns a low dimensional embedding of the single cell feature space\n", "2. Consensus clustering (https://github.com/burtonrj/consensusclustering) of the SOM nodes identifies the optimal number of clusters to retain\n", "3. Each observation is assigned to a cluster according to its nearest meta-cluster in the SOM\n", "\n", @@ -202,7 +198,7 @@ " max_clusters=20,\n", " return_clustering_objs=True,\n", " verbose=True,\n", - " copy=True,\n", + " inplace=True,\n", " agglomerative_clustering_kwargs={\"metric\": \"euclidean\", \"linkage\": \"ward\"},\n", ")" ] diff --git a/pytometry/tools/clustering/_flowsom.py b/pytometry/tools/clustering/_flowsom.py index cda1137..71dcb73 100644 --- a/pytometry/tools/clustering/_flowsom.py +++ b/pytometry/tools/clustering/_flowsom.py @@ -141,7 +141,7 @@ def flowsom_clustering( max_clusters: int = 10, n_resamples: int = 100, resample_frac: float = 0.9, - copy: bool = False, + inplace: bool = True, verbose: bool = False, agglomerative_clustering_kwargs: dict | None = None, return_clustering_objs: bool = False, @@ -169,7 +169,7 @@ def flowsom_clustering( max_clusters (int, default=10): maximum number of clusters to consider n_resamples (int, default=100): number of resamples for consensus clustering resample_frac (float, default=0.5): fraction of samples to resample for - copy (bool, default=False): whether to copy the AnnData object or modify it + inplace (bool, default=False): whether to copy the AnnData object or modify it verbose (bool, default=False) agglomerative_clustering_kwargs (dict, default=None): keyword arguments for sklearn.cluster.AgglomerativeClustering. If None, defaults to @@ -183,7 +183,7 @@ def flowsom_clustering( containing the annotated data matrix and the clustering objects is returned. """ - adata = adata.copy() if copy else adata + adata = adata if inplace else adata.copy() logger.info("Running FlowSOM clustering") logger.info("Training SOM") som = som_clustering(