sctour icon indicating copy to clipboard operation
sctour copied to clipboard

`.X`. error using sct.train.Trainer()

Open pandaqiuqiu opened this issue 8 months ago • 11 comments

Hi, Qian,

I am using adata as input of the h5ad file converted from Seurat. Adding data from RNA as X, adding counts from RNA as raw, transferring meta.data to obs.

During model training, I encountered the following error at the step involving sct.train.Trainer(). Even after adding the step adata.X <- adata.raw.X, the issue persists. Can you help me solve this problem? Thanks so much!

Related codes ad follows: adata.X <Compressed Sparse Row sparse matrix of dtype 'float64' with 486880 stored elements and shape (5000, 1000)> adata.raw.X <Compressed Sparse Row sparse matrix of dtype 'float64' with 17799636 stored elements and shape (5000, 33694)>

sc.pp.calculate_qc_metrics(adata, percent_top=None, log1p=False, inplace=True) sc.pp.highly_variable_genes(adata, flavor='seurat_v3', n_top_genes=1000, subset=True)

/.../python3.10/site-packages/scanpy/preprocessing/_highly_variable_genes.py:75: UserWarning: flavor='seurat_v3' expects raw count data, but non-integers were found. warnings.warn(

tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5) tnode.train()


ValueError Traceback (most recent call last) Cell In[36], line 1 ----> 1 tnode = sct.train.Trainer(adata, loss_mode='nb', alpha_recon_lec=0.5, alpha_recon_lode=0.5) 2 tnode.train()

File /.../python3.10/site-packages/sctour/train.py:168, in Trainer.init(self, adata, percent, n_latent, n_ode_hidden, n_vae_hidden, batch_norm, ode_method, step_size, alpha_recon_lec, alpha_recon_lode, alpha_kl, loss_mode, nepoch, batch_size, drop_last, lr, wt_decay, eps, random_state, val_frac, use_gpu) 166 X = self.adata.X.data if sparse.issparse(self.adata.X) else self.adata.X 167 if (X.min() < 0) or np.any(~np.equal(np.mod(X, 1), 0)): --> 168 raise ValueError( 169 f"Invalid expression matrix in .X. {self.loss_mode} mode expects raw UMI counts in .X of the AnnData." 170 ) 172 self.n_cells = adata.n_obs 173 self.batch_size = batch_size

ValueError: Invalid expression matrix in .X. nb mode expects raw UMI counts in .X of the AnnData.

pandaqiuqiu avatar Jun 26 '24 15:06 pandaqiuqiu