theislab / scgen

Single cell perturbation prediction
https://scgen.readthedocs.io
GNU General Public License v3.0
262 stars 54 forks source link

tutorial does not run -- version issues with scvi-tools #90

Closed kiristern closed 7 months ago

kiristern commented 11 months ago

Hello, I am trying to run the scgen_perturbation_prediction.ipynb tutorial but am having dependency issues, namely with scvi-tools.

I created a new conda env with the latest releases: scgen 2.1.0 scvi-tools 1.0.4

When simply running the tutorial, on import scgen, I got:

from ._scgenvae import SCGENVAE
  File "~/miniconda3/envs/scgen/lib/python3.11/site-packages/scgen/_scgenvae.py", line 6, in <module>
    from scvi.module.base import BaseModuleClass, LossRecorder, auto_move_data
ImportError: cannot import name 'LossRecorder' from 'scvi.module.base'

It appears as if LossRecorder was renamed to LossOutput. I simply changed LossRecorder to LossOutput but then kept getting new errors such as "Literal is deprecated, use typing instead" (again, just modified from typing import Literal), but then more errors... i ended up just restarting and installing pip install git+https://github.com/theislab/scgen.git development version, but now get the error:

scgen.SCGEN.setup_anndata(train_new, batch_key="condition", labels_key="cell_type")
"~/miniconda3/envs/scgen/lib/python3.11/site-packages/scvi/data/_utils.py", line 245, in _check_if_view
    raise ValueError("Please run `adata = adata.copy()`")
ValueError: Please run `adata = adata.copy()`

I was wondering what is the last stable versions to run the tutorial without having to manually go through all these errors? Thanks!

kiristern commented 11 months ago

I tried running the same tutorial via Google Colab as well and have the same dependencies issues.

matwasilewski commented 10 months ago

Hi! This fork has resolved some of my issues, I hope it helps: https://github.com/szhorvat/scgen

printfisnotgood commented 5 months ago

I encountered this problem, too.

scgen.SCGEN.setup_anndata(train_new, batch_key="condition", labels_key="cell_type")
"~/miniconda3/envs/scgen/lib/python3.11/site-packages/scvi/data/_utils.py", line 245, in _check_if_view
    raise ValueError("Please run `adata = adata.copy()`")
ValueError: Please run `adata = adata.copy()`

I finally solved it by adding ".copy()" to "train_new = train[~((train.obs["cell_type"] == "CD4T") & (train.obs["condition"] == "stimulated"))]" at the end

MEFarhadieh commented 3 months ago

I resolved the issue with scgen by downgrading scvi-tools to version 0.17 and installing scgen with pip in Google Colab:

import sys
#if branch is stable, will install via pypi, else will install from source
branch = "stable"
IN_COLAB = "google.colab" in sys.modules

!pip install --quiet scvi-tools==0.17
!pip install --quiet scgen
if IN_COLAB and branch == "stable":
    !pip install --quiet scgen[tutorials]
elif IN_COLAB and branch != "stable":
    !pip install --quiet --upgrade jsonschema
    !pip install --quiet git+https://github.com/theislab/scgen@$branch#egg=scgen[tutorials]
M0hammadL commented 3 months ago

@chelseabright96