From bb1fdfbf4b5c4836bd19b4455b466087bd6a7789 Mon Sep 17 00:00:00 2001 From: MiquelSendra Date: Fri, 10 Oct 2025 01:32:34 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20replace=20deprecated=20.A=20attribut?= =?UTF-8?q?e=20with=20.toarray()=20in=20read=5Fanndata()=20for=20SciPy=20?= =?UTF-8?q?=E2=89=A51.11=20compatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sc3D/sc3D.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/sc3D/sc3D.py b/src/sc3D/sc3D.py index d96d97b..6440c07 100644 --- a/src/sc3D/sc3D.py +++ b/src/sc3D/sc3D.py @@ -35,6 +35,13 @@ class Embryo: for other kinds of datasets. """ + # --- RECENT EDIT --- small helper function to keep compatibility with old and new SciPy versions. + @staticmethod + def _to_dense(matrix): + """Return dense array if input is sparse, otherwise unchanged.""" + return matrix.toarray() if hasattr(matrix, "toarray") else matrix + # --- END OF RECENT EDIT --- + def set_zpos(self): """ Creates the dictionary containing @@ -182,13 +189,15 @@ def read_anndata( elif genes_of_interest == "all": genes_of_interest = data.var_names self.all_genes = sorted(genes_of_interest) + + # --- RECENT EDIT --- Keeps compatibility with old and new SciPy versions. if 0 < len(genes_of_interest): - self.gene_expression = dict( - zip(ids, np.array(data.raw[:, self.all_genes].X.A)) - ) - self.data = data.raw[:, self.all_genes].X.A + raw_X = self._to_dense(data.raw[:, self.all_genes].X) + self.gene_expression = dict(zip(ids, np.array(raw_X))) + self.data = raw_X else: self.gene_expression = {id_: [] for id_ in ids} + # --- END OF RECENT EDIT --- self.array_id_num_pos = array_id_num_pos if array_id in data.obs_keys(): @@ -784,18 +793,19 @@ def downsample(self, spacing=10, pos_id="pos_3D"): if 0 < len(v) ] ) - final_expr = np.array( - [ - np.mean( - self.anndata.raw[ - mapping_from_removed[[cells[vi] for vi in v]] - ].X.A, - axis=0, - ) - for v in mapping - if 0 < len(v) - ] - ) + + # --- RECENT EDIT --- Keeps compatibility with old and new SciPy versions. + final_expr = np.array([ + np.mean( + self._to_dense(self.anndata.raw[ + mapping_from_removed[[cells[vi] for vi in v]] + ].X), + axis=0, + ) + for v in mapping if len(v) > 0 + ]) + # --- END OF RECENT EDIT --- + nb_cells = np.array([len(v) for v in mapping if 0 < len(v)]) tissue = [ np.unique( From 823951878f18f9f0a0d924bbf6034964234b131b Mon Sep 17 00:00:00 2001 From: MiquelSendra Date: Fri, 17 Oct 2025 12:00:53 +0200 Subject: [PATCH 2/2] remove unnecesasary "edited line" anotations --- src/sc3D/sc3D.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/sc3D/sc3D.py b/src/sc3D/sc3D.py index 6440c07..02c84a3 100644 --- a/src/sc3D/sc3D.py +++ b/src/sc3D/sc3D.py @@ -35,12 +35,10 @@ class Embryo: for other kinds of datasets. """ - # --- RECENT EDIT --- small helper function to keep compatibility with old and new SciPy versions. @staticmethod def _to_dense(matrix): """Return dense array if input is sparse, otherwise unchanged.""" return matrix.toarray() if hasattr(matrix, "toarray") else matrix - # --- END OF RECENT EDIT --- def set_zpos(self): """ @@ -190,14 +188,12 @@ def read_anndata( genes_of_interest = data.var_names self.all_genes = sorted(genes_of_interest) - # --- RECENT EDIT --- Keeps compatibility with old and new SciPy versions. if 0 < len(genes_of_interest): raw_X = self._to_dense(data.raw[:, self.all_genes].X) self.gene_expression = dict(zip(ids, np.array(raw_X))) self.data = raw_X else: self.gene_expression = {id_: [] for id_ in ids} - # --- END OF RECENT EDIT --- self.array_id_num_pos = array_id_num_pos if array_id in data.obs_keys(): @@ -794,7 +790,6 @@ def downsample(self, spacing=10, pos_id="pos_3D"): ] ) - # --- RECENT EDIT --- Keeps compatibility with old and new SciPy versions. final_expr = np.array([ np.mean( self._to_dense(self.anndata.raw[ @@ -804,7 +799,6 @@ def downsample(self, spacing=10, pos_id="pos_3D"): ) for v in mapping if len(v) > 0 ]) - # --- END OF RECENT EDIT --- nb_cells = np.array([len(v) for v in mapping if 0 < len(v)]) tissue = [