flatironinstitute / inferelator

Task-based gene regulatory network inference using single-cell or bulk gene expression data conditioned on a prior network.
BSD 2-Clause "Simplified" License
47 stars 12 forks source link

Attribute error in InferelatorRegressWorkflow when calling cv wrap #63

Open jsacco1 opened 1 year ago

jsacco1 commented 1 year ago

I am trying to run Inferelator on a h5ad file, but I get the following error when trying to run the cv wrap function. The h5ad file originates from a loom file that I made by subsetting a Seurat R object on an expression threshold 0.5<. I am using a TF name list with 3 TFs. The problem is in getting the betas usig a list comprehension. Paths modified for clarity:

This is the log of stdout:

2 Inferelator parallelized using engine joblib
1 Loading AnnData file FILENAME.h5ad (Layer: X)
1 Data loaded: InferelatorData [float32 (427, 28570), Metadata (427, 22)] Memory: 12.20 MB
2 Loading TF feature names from file 3_tf.tsv
2 Loading prior data from file updated_matrix.tsv
2 Loading gold_standard data from file updated_matrix.tsv
1 Setting crossvalidation param random_seed to 42
2 Writing results to /path/to/amu_sr/random_seed_42
1 Gold standard (62611, 1021) split on axis 0. Prior knowledge network (50088, 1021) [16254778 edges] used for activity and gold standard network (12523, 1021) [4041369 edges] used for testing.
2 Filtered prior to 3 TFs from the TF name list
2 Trimming Expression matrix (427, 28570) to 18112 columns
1 Skipping metadata because parsing requires missing columns: Index(['del.t', 'isTs', 'prevCol'], dtype='object')
2 Constructed design (427, 18112) and response (427, 18112) matrices
2 Rebuilt design matrix (427, 3) with TF activity

This is the traceback:

~/anaconda3/envs/infer_test/lib/python3.7/site-packages/inferelator-0.6.2-py3.7.egg/inferelator/utils/inferelator_data.py:397: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
  X=expression_data
Traceback (most recent call last):
  File "new_org.py", line 67, in <module>
    cv_wrap.run()
  File "~/anaconda3/envs/infer_test/lib/python3.7/site-packages/inferelator-0.6.2-py3.7.egg/inferelator/crossvalidation_workflow.py", line 232, in run
    results = self._grid_search()
  File "~/anaconda3/envs/infer_test/lib/python3.7/site-packages/inferelator-0.6.2-py3.7.egg/inferelator/crossvalidation_workflow.py", line 412, in _grid_search
    result = cv_workflow.run()
  File "~/anaconda3/envs/infer_test/lib/python3.7/site-packages/inferelator-0.6.2-py3.7.egg/inferelator/workflows/tfa_workflow.py", line 167, in run
    betas, rescaled_betas, full_betas, full_rescale = self.run_regression()
  File "~/anaconda3/envs/infer_test/lib/python3.7/site-packages/inferelator-0.6.2-py3.7.egg/inferelator/regression/base_regression.py", line 186, in run_regression
    betas = [[] for _ in range(self._n_tasks)]
AttributeError: 'InferelatorRegressWorkflow' object has no attribute '_n_tasks'

Packages in my conda env:

# packages in environment at ~/anaconda3/envs/infer_test:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
anndata                   0.9.1                    pypi_0    pypi
ca-certificates           2023.5.7             hbcca054_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
dbus                      1.13.6               hfdff14a_1    conda-forge
expat                     2.5.0                hcb278e6_1    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
freetype                  2.12.1               hca18f0e_1    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
glib                      2.66.3               h58526e2_0    conda-forge
gst-plugins-base          1.14.5               h0935bb2_2    conda-forge
gstreamer                 1.14.5               h36ae1b5_2    conda-forge
h5py                      3.3.0           nompi_py37ha3df211_100    conda-forge
hdf5                      1.10.6          nompi_h3c11f04_101    conda-forge
icu                       64.2                 he1b5a44_1    conda-forge
importlib-metadata        4.11.4           py37h89c1867_0    conda-forge
importlib_metadata        4.11.4               hd8ed1ab_0    conda-forge
inferelator               0.6.2                    pypi_0    pypi
joblib                    1.2.0              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h0b41bf4_3    conda-forge
kiwisolver                1.4.4            py37h7cecad7_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libblas                   3.9.0                8_openblas    conda-forge
libcblas                  3.9.0                8_openblas    conda-forge
libclang                  9.0.1           default_hb4e5071_5    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.2.1             he1b5a44_1007    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgfortran-ng            7.5.0               h14aa051_20    conda-forge
libgfortran4              7.5.0               h14aa051_20    conda-forge
libglib                   2.66.3               hbe7bbb4_0    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
liblapack                 3.9.0                8_openblas    conda-forge
libllvm9                  9.0.1           default_hc23dcda_7    conda-forge
libopenblas               0.3.12          pthreads_hb3c22a3_1    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libsqlite                 3.42.0               h2797004_0    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxcb                    1.15                 h0b41bf4_0    conda-forge
libxkbcommon              0.10.0               he1b5a44_0    conda-forge
libxml2                   2.9.10               hee79883_0    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
matplotlib                3.1.3                    py37_0    conda-forge
matplotlib-base           3.1.3            py37h250f245_0    conda-forge
natsort                   8.3.1              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.89                 he45b914_0    conda-forge
numpy                     1.18.1           py37h8960a57_1    conda-forge
openssl                   1.1.1t               h0b41bf4_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandas                    1.0.1            py37hb3f55d8_0    conda-forge
pcre                      8.45                 h9c3ff4c_0    conda-forge
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.12.3           py37h8685d9f_3    conda-forge
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtchart                 5.12                     pypi_0    pypi
pyqtwebengine             5.12.1                   pypi_0    pypi
python                    3.7.6           cpython_h8356626_6    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.7                     2_cp37m    conda-forge
pytz                      2023.3             pyhd8ed1ab_0    conda-forge
qt                        5.12.5               hd8c4c69_1    conda-forge
readline                  8.2                  h8228510_1    conda-forge
scikit-learn              0.22.1           py37hcdab131_1    conda-forge
scipy                     1.4.1            py37ha3d9a3c_3    conda-forge
setuptools                59.8.0           py37h89c1867_1    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.42.0               h2c6b66d_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
tornado                   6.2              py37h540881e_0    conda-forge
typing-extensions         4.6.2                hd8ed1ab_0    conda-forge
typing_extensions         4.6.2              pyha770c72_0    conda-forge
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zipp                      3.15.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h166bdaf_4    conda-forge
asistradition commented 1 year ago

The amusr regression method is explicitly a multi-task method (it doesn't work without breaking your training data into tasks). inferelator_workflow(regression='amusr', workflow='tfa') won't work and needs to be inferelator_workflow(regression='amusr', workflow='multitask'), with tasks defined.

Alternatively you can try using inferelator_workflow(regression='stars', workflow='tfa') or inferelator_workflow(regression='bbsr', workflow='tfa') with your existing workflow.

I will fix this to provide a useful error message (instead of this cryptic message).