theislab / scarches

Reference mapping for single-cell genomics
https://docs.scarches.org/en/latest/
BSD 3-Clause "New" or "Revised" License
323 stars 50 forks source link

fail to use the sca.models.SCVI #206

Open melancholy12 opened 12 months ago

melancholy12 commented 12 months ago

vae = sca.models.SCVI( adata_ref, n_layers=2, encode_covariates=True, deeply_inject_covariates=False, use_layer_norm="both", use_batch_norm="none", )

ValueError: Expected parameter loc (Tensor of shape (128, 10)) of distribution Normal(loc: torch.Size([128, 10]), scale: torch.Size([128, 10])) to satisfy the constraint Real(), but found invalid values: tensor([[ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], [ 0.260, 0.540, 0.078, -0.767, 0.169, 0.835, -0.062, 0.543, -0.479, -0.110], [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], [ 0.320, 0.559, 0.204, -0.554, 0.267, 1.067, 0.112, 0.654, -0.443, -0.260], [ 0.516, 0.640, -0.024, -0.396, 0.299, 0.797, -0.157, 0.369, -0.568, -0.112], [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], ..., [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], [ 0.260, 0.063, -0.155, -0.576, 0.270, 0.842, 0.015, 0.408, -0.723, -0.015], [ 0.204, 0.617, 0.028, -0.464, 0.411, 0.688, -0.238, 0.208, -0.392, 0.019], [-0.025, 0.790, 0.028, -0.647, 0.395, 0.345, -0.034, 0.466, -0.304, -1.005], [ 0.406, 0.497, 0.257, -0.780, 0.227, 0.585, 0.059, 0.210, -0.440, -0.059], [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], [ 0.384, 0.563, -0.295, -0.336, 0.161, 0.682, 0.300, 0.584, -0.774, -0.457]], grad_fn=)

Koncopd commented 11 months ago

Could you provide more information? Maybe your input is not raw counts?

melancholy12 commented 11 months ago

@Koncopd No.. It is the processed data.

Koncopd commented 11 months ago

Still could you give me more info? versions of the packages, when exactly this error happens etc. The data should not be preprocessed, it should contain raw counts.

melancholy12 commented 11 months ago

Thanks for your hand. I didn't check the email. Sorry for the delay. scvi-tools 1.0.2 seaborn 0.12.2 scikit-learn 1.3.0 scanpy 1.9.3 scArches 0.5.9

sojichld commented 9 months ago

Any developments on this issue? I am having the same problem. I have a target dataset with raw data but the atlas does not contain the raw matrix.

Koncopd commented 8 months ago

How do you SCVI.setup_anndata? The raw counts normally should be in adata.X to use with SCVI.

sojichld commented 8 months ago

For me it is sca.models.SCVI.setup_anndata(source_adata, batch_key=condition_key)

This source_data is a reference atlas, that has no adata.raw object. The data was not formatted similarly to the target and some transformation had to be done, so its the best that I have at the moment.

That setup_anndata method will run, the code fails when I run model.train() with the target. From that method I get a similar error to the original issue.

However, it seems that without the raw data available it is not possible to use these methods? I may just have to find alternative methods or backtrack to find some earlier versions of the project.

Update: I was able to do this with just the raw target data. This solved the issue as the atlas has long since been transformed.