morris-lab / CellOracle

This is the alpha version of the CellOracle package
Other
316 stars 56 forks source link

ImportError: cannot import name 'default_motifs' from 'gimmemotifs.motif' #158

Open acv21 opened 1 year ago

acv21 commented 1 year ago

Hello,

I am following this tutorial to obtain a base GRN, with the code below. I get the following error message:

Traceback (most recent call last):
  File "15_4_CellOracle_base-GRN-preparation.py", line 12, in <module>
    import celloracle as co
  File "/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/celloracle/__init__.py", line 8, in <module>
    from . import utility, network, network_analysis, go_analysis, data, data_conversion, oracle_utility
  File "/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/celloracle/utility/__init__.py", line 18, in <module>
    from .load_hdf5 import load_hdf5
  File "/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/celloracle/utility/load_hdf5.py", line 8, in <module>
    from ..motif_analysis.tfinfo_core import load_TFinfo
  File "/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/celloracle/motif_analysis/__init__.py", line 13, in <module>
    from .tfinfo_core import (load_TFinfo, load_TFinfo_from_parquets,
  File "/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/celloracle/motif_analysis/tfinfo_core.py", line 38, in <module>
    from gimmemotifs.motif import default_motifs
ImportError: cannot import name 'default_motifs' from 'gimmemotifs.motif' (/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/gimmemotifs/motif/__init__.py)

I am not sure why it's not loading the default motifs from gimmemotifs. I have both gimmemotifs and celloracle installed in the same conda environment.

Here's the code:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import os, sys, shutil, importlib, glob
from tqdm.notebook import tqdm
from genomepy import Genome

import celloracle as co
from celloracle import motif_analysis as ma
from celloracle.utility import save_as_pickled_object
co.__version__

ref_genome = "hg38"

genome_installation = ma.is_genome_installed(ref_genome=ref_genome, genomes_dir="/dir/genomes")
print(ref_genome, "installation: ", genome_installation)

peaks = pd.read_csv("./objects/15_CellOracle_input-links.csv")
peaks.head()

peaks = ma.check_peak_format(peaks, ref_genome, genomes_dir="/dir/genomes")

# Instantiate TFinfo object
tfi = ma.TFinfo(peak_data_frame=peaks,
                ref_genome=ref_genome, genomes_dir="/dir/genomes")

# Scan motifs. !!CAUTION!! This step may take several hours if you have many peaks!
tfi.scan(fpr=0.02,
         motifs=None,  # If you enter None, default motifs will be loaded.
         verbose=True)

# Save tfinfo object
tfi.to_hdf5(file_path="test1.celloracle.tfinfo")

# Check motif scan results
tfi.scanned_df.head()

# ## Filter motifs

# Reset filtering
tfi.reset_filtering()

# Do filtering
tfi.filter_motifs_by_score(threshold=10)

# Format post-filtering results.
tfi.make_TFinfo_dataframe_and_dictionary(verbose=True)

# ## Final base GRN

df = tfi.to_dataframe()
df.head()

# ## Save data

# Save result as a dataframe
df = tfi.to_dataframe()
df.to_parquet("./objects/15_CellOracle_base-GRN.parquet")
df.to_csv("./objects/15_CellOracle_base-GRN.csv")

Thank you for your time!

KenjiKamimoto-ac commented 1 year ago

@acv21

I'm Kenji, developer of celloracle. Thank you for the feedback. I want to know the package versions to identify the cause of the issue. On your computational environment, could you please run the following command and tell me the output?

import celloracle as co
co.check_python_requirements()
acv21 commented 1 year ago

Thanks @KenjiKamimoto-wustl122, here's the code I run and the outputs:

python Python 3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:46:39) [GCC 10.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.

>>> import celloracle as co /dir/envs/celloracle_env/lib/python3.8/site-packages/loompy/bus_file.py:68: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details. def twobit_to_dna(twobit: int, size: int) -> str: /dir/envs/celloracle_env/lib/python3.8/site-packages/loompy/bus_file.py:85: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details. def dna_to_twobit(dna: str) -> int: /dir/envs/celloracle_env/lib/python3.8/site-packages/loompy/bus_file.py:102: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details. def twobit_1hamming(twobit: int, size: int) -> List[int]: which: no R in (/dir/envs/celloracle_env/bin:/ceph/home/a/acavallo/.vscode-server/bin/abd2f3db4bdb28f9e95536dfa84d8479f1eb312d/bin/remote-cli:/home/miniconda3/condabin:/package/environment-modules/4.5.1/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/.local/bin:/home/bin)

>>> co.check_python_requirements() package_name installed_version required_version requirement_satisfied 0 numpy 1.24.4 auto True 1 scipy 1.10.1 auto True 2 cython 0.29.35 auto True 3 numba 0.57.0 0.50.1 True 4 matplotlib 3.7.3 auto True 5 seaborn 0.12.2 auto True 6 scikit-learn 1.3.1 auto True 7 h5py 3.8.0 3.1.0 True 8 pandas 1.5.3 1.0.3 True 9 velocyto 0.17.17 0.17 True 10 umap-learn 0.5.3 auto True 11 pyarrow 12.0.1 0.17 True 12 tqdm 4.65.0 4.45 True 13 igraph 0.10.4 0.10.1 True 14 louvain 0.8.0 auto True 15 jupyter 1.0.0 auto True 16 anndata 0.9.1 0.7.5 True 17 scanpy 1.9.3 1.6 True 18 joblib 1.3.2 auto True 19 goatools 1.3.1 auto True 20 genomepy 0.16.1 0.8.4 True 21 gimmemotifs 0.17.0 0.14.4 True

The celloracle version I'm using is 0.14.0. I am also attaching the file referenced in the error message (/dir/Packages/envs/celloracle_env/lib/python3.8/site-packages/gimmemotifs/motif/__init__.py), in case it can be useful for troubleshooting: __init__.py

Thanks again for your help!

990618 commented 1 year ago

Have you solved this problem? I also encountered this problem.

acv21 commented 1 year ago

Have you solved this problem? I also encountered this problem.

Sadly not! Hopefully @KenjiKamimoto-wustl122 can shed some light on this?

KenjiKamimoto-ac commented 1 year ago

@990618 @acv21

Sorry for the slow response. Unfortunately I could not reproduce the error on my side. I guess there is something wrong in the gimmemotifs installation. Can you please try the below to check your gimmemotifs installation status?

from gimmemotifs.motif import default_motifs

If you can get the error, I recommend uninstall gimmemotifs and reinstall it.

PedroMBarcelos commented 1 month ago

Hey there, just run into this error and I downgraded the gimmemotif version from 0.18.0 to 0.14.4 and it worked. Not sure what is causing this in the most updated version yet but this should be a quick fix.