scverse / scvi-tools

Deep probabilistic analysis of single-cell and spatial omics data
http://scvi-tools.org/
BSD 3-Clause "New" or "Revised" License
1.25k stars 354 forks source link

MultiVI NaN in latent representation #1422

Closed yuxuanChen777 closed 2 years ago

yuxuanChen777 commented 2 years ago

I encountered this error when I was running mvi.train():

mvi.train()
ValueError: Expected parameter loc (Tensor of shape (128, 11)) of distribution Normal(loc: torch.Size([128, 11]), scale: torch.Size([128, 11])) to satisfy the constraint Real(), but found invalid values:
tensor([[    nan,     nan,     nan,  ...,     nan,     nan,     nan],
        [    nan,     nan,     nan,  ...,     nan,     nan,     nan],
        [    nan,     nan,     nan,  ...,     nan,     nan,     nan],
        ...,
        [-0.6378, -0.6456,  0.6350,  ..., -0.2785, -0.6156, -0.0385],
        [    nan,     nan,     nan,  ...,     nan,     nan,     nan],
        [-0.4364, -0.2716,  0.3634,  ...,  0.4258, -0.7137,  0.2691]],
       grad_fn=<AddmmBackward0>)

​I tried both datasets and encountered this error.Is this error because I used raw count? Or other reasons?
Please help me, I really want to know how to solve this problem.Thank you

adamgayoso commented 2 years ago

Can you describe more about your data? And the code you're using to run the model?

yuxuanChen777 commented 2 years ago

Can you describe more about your data? And the code you're using to run the model? This is my scRNA-seq raw count: image Then,I convert this count to anndata: image And atac-seq data is processed in the same way. image Then,scRNA-seq and ATAC-seq were integrated: image Then follow the standard procedures provided on the website : image image

adamgayoso commented 2 years ago

If I'm understanding, you only have 778 cells, all of which you measured RNA and chromatin for?

adamgayoso commented 2 years ago

If this is the case, you would want to run multivi only on what you're callingmulti_adata where the genes come first in multi_adata.var. However, it will be tough to learn a good model with only 778 cells.

yuxuanChen777 commented 2 years ago

If this is the case, you would want to run multivi only on what you're callingmulti_adata where the genes come first in multi_adata.var. However, it will be tough to learn a good model with only 778 cells.

But I tried a dataset of more than 2,000 cells and encountered the same error

adamgayoso commented 2 years ago

The issue might be that your data is fully paired, yet you are running organize_multiome_anndatas. Can you try with just the fully paired data? Organized such that genes are before atac regions? Then give a batch key where every value is just "paired" or whatever you like.

adamgayoso commented 2 years ago

But I tried a dataset of more than 2,000 cells and encountered the same error

2000 is also very few, can you add in any unpaired rna or atac datasets?

yuxuanChen777 commented 2 years ago

The issue might be that your data is fully paired, yet you are running organize_multiome_anndatas. Can you try with just the fully paired data? Organized such that genes are before atac regions? Then give a batch key where every value is just "paired" or whatever you like.

My datasets are all paired, there are no unpaired datasets.How do you run MultiVI in this case?Could you elaborate on that? Thank you very much.

adamgayoso commented 2 years ago

all you need to do is run multivi with anndata that has RNA features before ATAC features (don't run organize_multiome_anndatas). Then do

multi_adata.obs["modality"] = "paired"

then

model = MULTIVI.setup_anndata(multi_adata, batch_key="modality")
...

proceeding with the code you have

adamgayoso commented 2 years ago

I'm going to close this issue, we'd appreciate moving usage questions like this to:

https://discourse.scverse.org/

yuxuanChen777 commented 2 years ago

all you need to do is run multivi with anndata that has RNA features before ATAC features (don't run organize_multiome_anndatas). Then do

multi_adata.obs["modality"] = "paired"

then

model = MULTIVI.setup_anndata(multi_adata, batch_key="modality")
...

proceeding with the code you have Thank you very much. It's very kind of you. I'll try it on at once

yuxuanChen777 commented 2 years ago

all you need to do is run multivi with anndata that has RNA features before ATAC features (don't run organize_multiome_anndatas). Then do

multi_adata.obs["modality"] = "paired"

then

model = MULTIVI.setup_anndata(multi_adata, batch_key="modality")
...

proceeding with the code you have

It worked! Thank you very much

yuxuanChen777 commented 2 years ago

Hello, at this website https://docs.scvi-tools.org/en/stable/tutorials/notebooks/MultiVI_tutorial.html,scvi.settings.seed =420,If all my data are paired,Is the seed still set to 420? thank you

guagua20210407

@. | 签名由网易邮箱大师定制 On 3/11/2022 10:32,Adam @.> wrote:

Closed #1422.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>