I'm trying to run SAM on already-preprocessed data, zf_data.
zf_data
AnnData object with n_obs × n_vars = 567 × 18342
obs: 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt'
var: 'gene_name', 'gene_ids', 'n_cells', 'mt', 'n_cells_by_counts', 'mean_counts', 'pct_dropout_by_counts', 'total_counts', 'highly_variable', 'highly_variable_rank', 'means', 'variances', 'variances_norm', 'mean', 'std'
uns: 'hvg', 'log1p'
However, I'm getting an AttributeError. Looking at the SAM code on GitHub, it seems to be a problem with how D is defined within the SAM code. In line 1096, D is defined as D = adata.X, and when I run type(sam.adata.X) it gives numpy.ndarray. It seems that line 1143 relies on D being a sparse array/matrix when D is defined as a ndarray to begin with. Am I misunderstanding something? What should I be doing?
My code:
from samalg import SAM
sam = SAM(counts = zf_data)
sam.run(preprocessing="None", npcs=30)
sam.scatter()
The result:
RUNNING SAM
Iteration: 0, Convergence: 1.0
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[34], line 3
1 from samalg import SAM
2 sam = SAM(counts = zf_data)
----> 3 sam.run(preprocessing="None", npcs=30)
4 sam.scatter()
File ~\miniconda3\envs\SingleCellSAM\Lib\site-packages\samalg\__init__.py:1053, in SAM.run(self, max_iter, verbose, projection, stopping_condition, num_norm_avg, k, distance, preprocessing, npcs, n_genes, weight_PCs, sparse_pca, proj_kwargs, seed, weight_mode, components, batch_key)
1050 else:
1051 first=False
-> 1053 W = self.calculate_nnm(batch_key=batch_key,
1054 n_genes=n_genes, preprocessing=preprocessing, npcs=npcs, num_norm_avg=nnas,
1055 weight_PCs=weight_PCs, sparse_pca=sparse_pca,weight_mode=weight_mode,seed=seed,components=components,first=first
1056 )
1057 gc.collect()
1058 new = W
File ~\miniconda3\envs\SingleCellSAM\Lib\site-packages\samalg\__init__.py:1143, in SAM.calculate_nnm(self, adata, batch_key, g_weighted, n_genes, preprocessing, npcs, num_norm_avg, weight_PCs, sparse_pca, update_manifold, weight_mode, seed, components, first)
1140 Ds = Ds.multiply(1/v**0.5).tocsr()
1142 else:
-> 1143 Ds = D[:, gkeep].toarray()
1145 if sp.issparse(Ds):
1146 D_sub = Ds.multiply(W[gkeep]).tocsr()
AttributeError: 'numpy.ndarray' object has no attribute 'toarray'
I'm trying to run SAM on already-preprocessed data, zf_data.
zf_dataHowever, I'm getting an AttributeError. Looking at the SAM code on GitHub, it seems to be a problem with how D is defined within the SAM code. In line 1096, D is defined as
D = adata.X, and when I runtype(sam.adata.X)it givesnumpy.ndarray. It seems that line 1143 relies on D being a sparse array/matrix when D is defined as a ndarray to begin with. Am I misunderstanding something? What should I be doing?My code:
The result: