Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wuxiangning opened this issue Sep 21, 2024 · 10 comments

Comments

@wuxiangning
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

@wuxiangning
Copy link
Author

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
Copy link
Author

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

@wuxiangning
Copy link
Author

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

@LiQian-XC
Copy link
Owner

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
Copy link
Author

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

@LiQian-XC
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants