LouisFaure / scFates

a scalable python suite for tree inference and advanced pseudotime analysis from scRNAseq data.
https://scfates.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
50 stars 2 forks source link

Unable to import scFates #3

Closed Marius1311 closed 3 years ago

Marius1311 commented 3 years ago

Dear scFates developers, I've installed scFates via pip and I've been trying to import it in a jupyter notebook by simply calling import scFates as scf. However, that raises the error in the traceback below. This is an rpy2 error, and know from experience that rpy2 can cause all sorts of difficulties. I think it would be much more convenient for the user if rpy2, and related modules, were only to be loaded when they're actually needed, i.e. as optional dependencies. In your installation instructions, it says: "scFates rely on the R package mgcv to perform testing and fitting of the features on the peudotime tree. Package is installed in an R session with the following command:"

If you really only need R dependencies for gene trend testing, then I would make mgcv and rpy2 optional dependencies and prompt the user to install them when calling the relevant functions. That way, you make sure that everyone can install and import scFates easily, even if rpy2 is not installed/causes difficulties. There are similar optional dependencies in CellRank (check out https://cellrank.readthedocs.io/en/stable/classes.html#cellrank.ul.models.GAMR, which also relies on mgcv) or scanpy (e.g. multicore TSNE). Again, these packages have dependencies which can be tricky to install and are only used in one part of the code, so they're made optional. Could this be done for scFates as well?

Traceback

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-10-ee10c269e254> in <module>
----> 1 import scFates as scf

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/scFates/__init__.py in <module>
      8 from anndata import AnnData
      9 
---> 10 from . import pp
     11 from . import tl
     12 from . import pl

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/scFates/pp.py in <module>
----> 1 from scFates.preprocessing import *

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/scFates/preprocessing/__init__.py in <module>
----> 1 from .pagoda2 import filter_cells, batch_correct, find_overdispersed
      2 from .diffusion import diffusion

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/scFates/preprocessing/pagoda2.py in <module>
      8 from anndata import AnnData
      9 
---> 10 from rpy2.robjects import pandas2ri, Formula
     11 from rpy2.robjects.packages import importr
     12 import rpy2.rinterface

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/rpy2/robjects/__init__.py in <module>
     17 import rpy2.rlike.container as rlc
     18 
---> 19 from rpy2.robjects.robject import RObjectMixin, RObject
     20 import rpy2.robjects.functions
     21 from rpy2.robjects.environments import (Environment,

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/rpy2/robjects/robject.py in <module>
     56 
     57 
---> 58 class RObjectMixin(object):
     59     """ Class to provide methods common to all RObject instances. """
     60 

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/rpy2/robjects/robject.py in RObjectMixin()
     68     __readlines = rpy2.rinterface.baseenv.find("readLines")
     69     __unlink = rpy2.rinterface.baseenv.find("unlink")
---> 70     __show = _get_exported_value('methods', 'show')
     71 
     72     __slots = None

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs)
     43 def _cdata_res_to_rinterface(function):
     44     def _(*args, **kwargs):
---> 45         cdata = function(*args, **kwargs)
     46         # TODO: test cdata is of the expected CType
     47         return _cdata_to_rinterface(cdata)

~/miniconda3/envs/py38_devel/lib/python3.8/site-packages/rpy2/rinterface.py in __call__(self, *args, **kwargs)
    678             )
    679             if error_occured[0]:
--> 680                 raise embedded.RRuntimeError(_rinterface._geterrmessage())
    681         return res
    682 

RRuntimeError: Fehler in library.dynam(lib, package, package.lib) : 
  shared object ‘methods.dylib’ nicht gefunden
LouisFaure commented 3 years ago

Thank you so much @Marius1311 for pointing this out!

This is now implemented in the new release v0.2.4, depencency reliance has been reduced as much as possible.

For clarification, functions needing a specific dependency are now mentionned in the documentation and will prompt a message when called, as you have suggested!

Marius1311 commented 3 years ago

Fantastic, I think that's much more convenient! I'm eager to check this out.