LiQian-XC / sctour

A deep learning architecture for robust inference and accurate prediction of cellular dynamics
https://sctour.readthedocs.io
MIT License
51 stars 4 forks source link

Invalid expression matrix #11

Open gototry2000 opened 1 month ago

gototry2000 commented 1 month ago

The first and second step can be run,but when I run follow mode:

tnode = sct.train.Trainer(atest2)

such an error can occur:

ValueError Traceback (most recent call last) Cell In[145], line 1 ----> 1 tnode = sct.train.Trainer(atest2)

File ~/miniconda3/envs/scanpy/lib/python3.12/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.

Does It mean the data is not raw data? How do I fix it? THANKS!

LiQian-XC commented 1 month ago

Hi, The error occurred because it detected that the values in .X were not integers. Can you check whether you provided raw UMI counts (instead of normalized values) in .X of your anndata object?

gototry2000 commented 1 month ago

Thanks for your reply! yeah ,I checked my data. Because I used SeuratDisk R package to convert Seurat format data to data that Scanpy can recognize. Following the protocol of this R package, the .x were filled with data of seurat data, raw.X were filled with  counts of seurat data. Indeed the values were not integers, but there was no difference between the two data sets. Should I change the data format further? Thanks !

LiQian-XC commented 1 month ago

If neither .X nor .raw.X are integers, check your original Seurat object to see whether the raw UMI counts are missing or if they have been corrected for some factors, making them non-integers. If the latter is the case, you can probably convert them to integers using a function like round.