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

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

Open wuxiangning opened 1 week ago

wuxiangning commented 1 week ago

hello i have the same issue,when run tnode = sct.train.Trainer(adata)tnode = sct.train.Trainer(adata) its error like this "ValueError Traceback (most recent call last) Cell In[22], line 1 ----> 1 tnode = sct.train.Trainer(adata)

File ~\AppData\Roaming\Python\Python312\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."

but my .X and .raw.X all integers and my seurat counts are also integers,.help!thk!

LiQian-XC commented 5 days ago

Can you run the following code on your .X? If it returns True, it then means that not all of the values in .X are integers and you need to check what causes some non-integer values in your .X.

np.any(~np.equal(np.mod(X, 1), 0))

wuxiangning commented 5 days ago

I run it np.any(~np.equal(np.mod(adata.x, 1), 0)) this code seems to check if adata.x is an integer It return error like this: TypeError: unsupported operand type(s) for %: 'csr_matrix' and 'int' this error seems my adata.X type isnt right,why? 屏幕截图 2024-09-25 102601 This adata is convert from seurate by using MuDataSeurat::WriteH5AD(seurate, "F:/数据分析/R.h5ad", assay="RNA"). Is there a problem with this conversion function?but this adata can use Scanpy as normal! Thanks!

LiQian-XC commented 3 days ago

Can you try this np.any(~np.equal(np.mod(adata.X.data, 1), 0))?

wuxiangning commented 3 days ago

Sure 。It seems something is wrong in my anadata.because when i use the standard data . It return false ![Uploading {B59D15FB-21CF-4593-B47A-F47AD2052E7C}.png…]()

wuxiangning commented 3 days ago

{129E44D2-7F93-4ABD-8B79-2F41075B3423}

wuxiangning commented 3 days ago

I dont know why my adata has this wrong,because it seems every object is right and ture

LiQian-XC commented 3 days ago

I think you can first check which values in your .X are non-integers. Then you can go back to your original Seurat object to see where the issue occurred.

wuxiangning commented 3 days ago

I don't quite know how to determine which value makes my .X are non-integers. Can you help me!help!!!

LiQian-XC commented 2 days ago

One quick, though possibly inefficient, way is:

np.where(~np.equal(np.mod(adata.X.toarray(), 1), 0))

The first array returned is the row index and the second one is column index for non-integer values in .X

wuxiangning commented 2 days ago

{84F94562-BA2D-4524-A9BC-DEE39855F058} It looks like there are a lot of non-integers, how do I go and change these in Seurate