From ae3b4db8c71c273ffeb29650b34131d14e48d7f4 Mon Sep 17 00:00:00 2001 From: LLehner Date: Wed, 9 Oct 2024 23:04:05 +0200 Subject: [PATCH] Remove unused imports and print statements --- src/squidpy/gr/_niche.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/squidpy/gr/_niche.py b/src/squidpy/gr/_niche.py index cc3be22c..10457449 100644 --- a/src/squidpy/gr/_niche.py +++ b/src/squidpy/gr/_niche.py @@ -1,6 +1,5 @@ from __future__ import annotations -import itertools from collections.abc import Iterator from typing import Any @@ -10,12 +9,10 @@ import scanpy as sc import scipy.sparse as sps from anndata import AnnData -from scipy.sparse import csr_matrix, hstack, issparse, spdiags -from scipy.stats import ranksums +from scipy.sparse import hstack, issparse, spdiags from sklearn import metrics -from sklearn.metrics import adjusted_rand_score, fowlkes_mallows_score, normalized_mutual_info_score from sklearn.mixture import GaussianMixture -from sklearn.preprocessing import StandardScaler, normalize +from sklearn.preprocessing import normalize from spatialdata import SpatialData from squidpy._utils import NDArrayA @@ -26,7 +23,7 @@ def calculate_niche( adata: AnnData | SpatialData, flavor: str = "neighborhood", - library_key: str | None = None, + library_key: str | None = None, # TODO: calculate niches on a per-slide basis table_key: str | None = None, mask: pd.core.series.Series = None, groups: str | None = None, @@ -132,9 +129,7 @@ def calculate_niche( adata_neighborhood = adata_neighborhood[mask] # required for leiden clustering (note: no dim reduction performed in original implementation) - print("calculating neighbors...") sc.pp.neighbors(adata_neighborhood, n_neighbors=n_neighbors, use_rep="X") - print("finished calculating neighbors") if resolutions is not None: if not isinstance(resolutions, list): @@ -143,13 +138,11 @@ def calculate_niche( raise ValueError("Please provide resolutions for leiden clustering.") # For each resolution, apply leiden on neighborhood profile. Each cluster label equals to a niche label - print("starting clustering...") for res in resolutions: sc.tl.leiden(adata_neighborhood, resolution=res, key_added=f"neighborhood_niche_res={res}") adata.obs[f"neighborhood_niche_res={res}"] = adata.obs.index.map( adata_neighborhood.obs[f"neighborhood_niche_res={res}"] ).fillna("not_a_niche") - print(f"finished clustering at resolution {res}") # filter niches with n_cells < min_niche_size if min_niche_size is not None: @@ -337,13 +330,9 @@ def _get_GMM_clusters(A: np.ndarray[np.float64, Any], n_components: int, random_ """Returns niche labels generated by GMM clustering. Compared to cellcharter this approach is simplified by using sklearn's GaussianMixture model without stability analysis.""" - print("initializing GMM...") gmm = GaussianMixture(n_components=n_components, random_state=random_state, init_params="random_from_data") - print("fitting GMM...") gmm.fit(A) - print("predicting labels...") labels = gmm.predict(A) - print("done") return labels