diff --git a/pertpy/preprocessing/_guide_rna.py b/pertpy/preprocessing/_guide_rna.py index ada15573..9ebded21 100644 --- a/pertpy/preprocessing/_guide_rna.py +++ b/pertpy/preprocessing/_guide_rna.py @@ -48,7 +48,7 @@ def assign_by_threshold( """ counts = adata.X if layer is None else adata.layers[layer] if scipy.sparse.issparse(counts): - counts = counts.A + counts = counts.toarray() assigned_grnas = np.where(counts >= assignment_threshold, 1, 0) assigned_grnas = scipy.sparse.csr_matrix(assigned_grnas) @@ -92,7 +92,7 @@ def assign_to_max_guide( """ counts = adata.X if layer is None else adata.layers[layer] if scipy.sparse.issparse(counts): - counts = counts.A + counts = counts.toarray() assigned_grna = np.where( counts.max(axis=1).squeeze() >= assignment_threshold, @@ -152,9 +152,9 @@ def plot_heatmap( if order_by is None: if scipy.sparse.issparse(data): - max_values = data.max(axis=1).A.squeeze() + max_values = data.max(axis=1).toarray().squeeze() data_argmax = data.argmax(axis=1).A.squeeze() - max_guide_index = np.where(max_values != data.min(axis=1).A.squeeze(), data_argmax, -1) + max_guide_index = np.where(max_values != data.min(axis=1).toarray().squeeze(), data_argmax, -1) else: max_guide_index = np.where( data.max(axis=1).squeeze() != data.min(axis=1).squeeze(), data.argmax(axis=1).squeeze(), -1 diff --git a/pertpy/tools/_milo.py b/pertpy/tools/_milo.py index cffc108d..6fa99959 100644 --- a/pertpy/tools/_milo.py +++ b/pertpy/tools/_milo.py @@ -1014,7 +1014,7 @@ def plot_nhood_counts_by_cond( if subset_nhoods is None: subset_nhoods = nhood_adata.obs_names - pl_df = pd.DataFrame(nhood_adata[subset_nhoods].X.A, columns=nhood_adata.var_names).melt( + pl_df = pd.DataFrame(nhood_adata[subset_nhoods].X.toarray(), columns=nhood_adata.var_names).melt( var_name=nhood_adata.uns["sample_col"], value_name="n_cells" ) pl_df = pd.merge(pl_df, nhood_adata.var) diff --git a/pertpy/tools/_perturbation_space/_discriminator_classifiers.py b/pertpy/tools/_perturbation_space/_discriminator_classifiers.py index 33fc2768..72644abf 100644 --- a/pertpy/tools/_perturbation_space/_discriminator_classifiers.py +++ b/pertpy/tools/_perturbation_space/_discriminator_classifiers.py @@ -408,7 +408,7 @@ def __len__(self): def __getitem__(self, idx): """Returns a sample and corresponding perturbations applied (labels)""" - sample = self.data[idx].A.squeeze() if scipy.sparse.issparse(self.data) else self.data[idx] + sample = self.data[idx].toarray().squeeze() if scipy.sparse.issparse(self.data) else self.data[idx] num_label = self.labels.iloc[idx] str_label = self.pert_labels.iloc[idx]