kaizhang / SnapATAC2

Single-cell epigenomics analysis tools
https://kzhang.org/SnapATAC2/
223 stars 24 forks source link

annotation notebook does not run within container #238

Open vjcitn opened 8 months ago

vjcitn commented 8 months ago

The recommended interactive container built nicely on ubuntu 22.04 but attempt to run first chunk of annotation.ipynb led to

2024-02-13 14:15:57 - INFO - generated new fontManager

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 8
      6 import pandas as pd
      7 import scanpy as sc
----> 8 import scvi
      9 import numpy as np
     11 scvi.settings.seed = 0

File [/usr/local/lib/python3.11/site-packages/scvi/__init__.py:11](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scvi/__init__.py#line=10)
      8 from ._settings import settings
     10 # this import needs to come after prior imports to prevent circular import
---> 11 from . import autotune, data, model, external, utils, criticism
     13 from importlib.metadata import version
     15 package_name = "scvi-tools"

File [/usr/local/lib/python3.11/site-packages/scvi/autotune/__init__.py:1](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scvi/autotune/__init__.py#line=0)
----> 1 from ._manager import TuneAnalysis, TunerManager
      2 from ._tuner import ModelTuner
      3 from ._types import Tunable, TunableMixin

File [/usr/local/lib/python3.11/site-packages/scvi/autotune/_manager.py:11](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scvi/autotune/_manager.py#line=10)
      9 import lightning.pytorch as pl
     10 import rich
---> 11 from chex import dataclass
     13 try:
     14     import ray

File [/usr/local/lib/python3.11/site-packages/chex/__init__.py:17](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/chex/__init__.py#line=16)
      1 # Copyright 2020 DeepMind Technologies Limited. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     13 # limitations under the License.
     14 # ==============================================================================
     15 """Chex: Testing made fun, in JAX!"""
---> 17 from chex._src.asserts import assert_axis_dimension
     18 from chex._src.asserts import assert_axis_dimension_comparator
     19 from chex._src.asserts import assert_axis_dimension_gt

File [/usr/local/lib/python3.11/site-packages/chex/_src/asserts.py:26](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/chex/_src/asserts.py#line=25)
     23 import unittest
     24 from unittest import mock
---> 26 from chex._src import asserts_internal as _ai
     27 from chex._src import pytypes
     28 import jax

File [/usr/local/lib/python3.11/site-packages/chex/_src/asserts_internal.py:34](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/chex/_src/asserts_internal.py#line=33)
     31 from typing import Any, Sequence, Union, Callable, List, Optional, Set, Tuple, Type
     33 from absl import logging
---> 34 from chex._src import pytypes
     35 import jax
     36 from jax.experimental import checkify

File [/usr/local/lib/python3.11/site-packages/chex/_src/pytypes.py:54](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/chex/_src/pytypes.py#line=53)
     52 Numeric = Union[Array, Scalar]
     53 Shape = jax.core.Shape
---> 54 PRNGKey = jax.random.KeyArray
     55 PyTreeDef = jax.tree_util.PyTreeDef
     56 Device = jax.Device

File [/usr/local/lib/python3.11/site-packages/jax/_src/deprecations.py:53](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/jax/_src/deprecations.py#line=52), in deprecation_getattr.<locals>.getattr(name)
     51   warnings.warn(message, DeprecationWarning, stacklevel=2)
     52   return fn
---> 53 raise AttributeError(f"module {module!r} has no attribute {name!r}")

AttributeError: module 'jax.random' has no attribute 'KeyArray'
njmei commented 7 months ago

@vjcitn Since I had added those Dockerfiles, I'll try to take a look over this weekend when I have some time! Thanks for your patience. Can you provide a link to the annotation.ipynb that you're referring to in your opening post?

NVM I think I found it. Just to confirm it's this? https://github.com/kaizhang/SnapATAC2/blob/main/docs/tutorials/annotation.ipynb

njmei commented 7 months ago

@vjcitn So it turns out that you were a bit unlucky when you built the image as the error you encountered looks to be a dependency issue with a package upstream of scvi-tools.

If you rebuild your Docker images today (2024-03-09), they should now work properly.

If you want the full details of the issue you encountered, please see: https://github.com/scverse/scvi-tools/issues/2530

@kaizhang I think this issue can be closed now.

vjcitn commented 6 months ago

Thanks, there's been more progress, but

sc.pp.filter_genes(data, min_cells=5)
sc.pp.highly_variable_genes(
    data,
    n_top_genes = 5000,
    flavor="seurat_v3",
    batch_key="batch",
    subset=True
)

fails with

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File [/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py:63](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py#line=62), in _highly_variable_genes_seurat_v3(adata, flavor, layer, n_top_genes, batch_key, check_values, span, subset, inplace)
     62 try:
---> 63     from skmisc.loess import loess
     64 except ImportError:

ModuleNotFoundError: No module named 'skmisc'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
back (most recent call last)
Cell In[5], line 2
      1 sc.pp.filter_genes(data, min_cells=5)
----> 2 sc.pp.highly_variable_genes(
      3     data,
      4     n_top_genes = 5000,
      5     flavor="seurat_v3",
      6     batch_key="batch",
      7     subset=True
      8 )

File [/usr/local/lib/python3.11/site-packages/legacy_api_wrap/__init__.py:80](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/legacy_api_wrap/__init__.py#line=79), in legacy_api.<locals>.wrapper.<locals>.fn_compatible(*args_all, **kw)
     77 @wraps(fn)
     78 def fn_compatible(*args_all: P.args, **kw: P.kwargs) -> R:
     79     if len(args_all) <= n_positional:
---> 80         return fn(*args_all, **kw)
     82     args_pos: P.args
     83     args_pos, args_rest = args_all[:n_positional], args_all[n_positional:]

File [/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py:626](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py#line=625), in highly_variable_genes(adata, layer, n_top_genes, min_disp, max_disp, min_mean, max_mean, span, n_bins, flavor, subset, inplace, batch_key, check_values)
    624         sig = signature(_highly_variable_genes_seurat_v3)
    625         n_top_genes = cast(int, sig.parameters["n_top_genes"].default)
--> 626     return _highly_variable_genes_seurat_v3(
    627         adata,
    628         flavor=flavor,
    629         layer=layer,
    630         n_top_genes=n_top_genes,
    631         batch_key=batch_key,
    632         check_values=check_values,
    633         span=span,
    634         subset=subset,
    635         inplace=inplace,
    636     )
    638 cutoff = _Cutoffs.validate(
    639     n_top_genes=n_top_genes,
    640     min_disp=min_disp,
   (...)
    643     max_mean=max_mean,
    644 )
    645 del min_disp, max_disp, min_mean, max_mean, n_top_genes

File [/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py:65](http://127.0.0.1:8888/usr/local/lib/python3.11/site-packages/scanpy/preprocessing/_highly_variable_genes.py#line=64), in _highly_variable_genes_seurat_v3(adata, flavor, layer, n_top_genes, batch_key, check_values, span, subset, inplace)
     63     from skmisc.loess import loess
     64 except ImportError:
---> 65     raise ImportError(
     66         "Please install skmisc package via `pip install --user scikit-misc"
     67     )
     68 df = pd.DataFrame(index=adata.var_names)
     69 data = _get_obs_rep(adata, layer=layer)

ImportError: Please install skmisc package via `pip install --user scikit-misc

this is on ubuntu

njmei commented 6 months ago

@vjcitn Hi, that is rather weird. So it looks like the error is complaining that about the scikit-misc package not being installed. However, I specifically had the following added to snapATAC2's pyproject.toml file recently: https://github.com/kaizhang/SnapATAC2/blob/b73dcfd2f9b1cc9d592522927af0ca8d52031792/snapatac2-python/pyproject.toml#L60

Here is the relevant commit that got merged in: https://github.com/kaizhang/SnapATAC2/commit/b73dcfd2f9b1cc9d592522927af0ca8d52031792

This should make it so that when snapATAC2 is installed with pip install snapatac2[recommend] it should automatically also include scikit-misc. Since you've been building your Docker image from source, can you check that the state of your snapATAC2 repo is up to date (e.g. do a git pull and check that your local version of the snapATAC2 pyproject.toml has that line I highlighted)?

EDIT: I see what is going on now, the changes in https://github.com/kaizhang/SnapATAC2/commit/b73dcfd2f9b1cc9d592522927af0ca8d52031792 haven't been released to PyPi yet as it looks like v2.6.0 is still the latest that has been released. You'll need to wait until @kaizhang releases v2.6.1 of SnapATAC2 to PyPi