dynverse / dyno

Inferring, interpreting and visualising trajectories using a streamlined set of packages 🦕
https://dynverse.github.io/dyno
Other
167 stars 32 forks source link

Error: Error during trajectory inference - Error in normalise(counts) : trying to get slot "x" from an object of a basic class ("matrix") with no slots #47

Closed pablommesas closed 4 years ago

pablommesas commented 5 years ago

Hi! I ran into this issue when trying to infer a trajectory in one of your gold/datasets: gold/stimulated-dendritic-cells-LPS_shalek. I'm loading the dataset.rds which I assume contains everything that I need to run infer_trajectory() and other downstream analysis.

The error occurs when I use the infer_trajectory() using 'count' methods such as "monocle_ddrtree" or "paga_tree", as opposed to 'expression' methods such as "slingshot" and "comp1" (for which it works).

The error should be reproducible with the following code.

dataset_file <- c("real/gold/stimulated-dendritic-cells-LPS_shalek/dataset.rds")

## Import data
dataset <- read_rds(derived_file(dataset_file, "01-datasets"))

#c("slingshot", "monocle_ddrtree", "comp1", "paga_tree")
## Select Method
methods_selected <- "monocle_ddrtree" ## "paga_tree"
#methods_selected <- ti_monocle_ddrtree() ##  ti_paga_tree()

## Infer trajectory
trajectory <- infer_trajectory(dataset, methods_selected, verbose = TRUE)

which returns: (for "monocle_ddrtree")

Executing 'monocle_ddrtree' on 'real/gold/stimulated-dendritic-cells-LPS_shalek'
With parameters: list(reduction_method = "ICA", max_components = 2L, norm_method = "log",     auto_param_selection = TRUE, filter_features = TRUE, filter_features_mean_expression = 0.1),
inputs: counts, and
priors : 
Input saved to /tmp/RtmpCyjjsc/file88774270f8b5/ti
Running /usr/bin/docker run -e 'TMPDIR=/tmp2' --workdir /ti/workspace -v '/tmp/RtmpCyjjsc/file88774270f8b5/ti:/ti' -v \
  '/tmp/RtmpCyjjsc/file88772160a383/tmp:/tmp2' 'dynverse/ti_monocle_ddrtree:v0.9.9.01' --dataset /ti/input.h5 --output /ti/output.h5
Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> -> parse_dataset -> normalise
Execution halted
Error: Error during trajectory inference 
Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> -> parse_dataset -> normalise
Execution halted

Similarly for "paga_tree":

Executing 'paga_tree' on 'real/gold/stimulated-dendritic-cells-LPS_shalek'
With parameters: list(n_neighbors = 15L, n_comps = 50L, n_dcs = 15L, resolution = 1L,     embedding_type = "fa"),
inputs: counts, and
priors : start_id
Input saved to /tmp/RtmpCyjjsc/file887759e3f4e5/ti
Running /usr/bin/docker run -e 'TMPDIR=/tmp2' --workdir /ti/workspace -v '/tmp/RtmpCyjjsc/file887759e3f4e5/ti:/ti' -v \
  '/tmp/RtmpCyjjsc/file88773e675320/tmp:/tmp2' 'dynverse/ti_paga_tree:v0.9.9.01' --dataset /ti/input.h5 --output /ti/output.h5
R[write to console]: Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> parse_dataset -> normalise

Traceback (most recent call last):
  File "/code/run.py", line 22, in <module>
    task = dynclipy.main()
  File "/usr/local/lib/python3.7/site-packages/dynclipy/read.py", line 123, in main
    """)
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/__init__.py", line 389, in __call__
    res = self.eval(p)
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 192, in __call__
    .__call__(*args, **kwargs))
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 121, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
  File "/usr/local/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py", line 28, in _
    cdata = function(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rpy2/rinterface.py", line 773, in __call__
    raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> parse_dataset -> normalise

Error: Error during trajectory inference 
R[write to console]: Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> parse_dataset -> normalise

Traceback (most recent call last):
  File "/code/run.py", line 22, in <module>
    task = dynclipy.main()
  File "/usr/local/lib/python3.7/site-packages/dynclipy/read.py", line 123, in main
    """)
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/__init__.py", line 389, in __call__
    res = self.eval(p)
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 192, in __call__
    .__call__(*args, **kwargs))
  File "/usr/local/lib/python3.7/site-packages/rpy2/robjects/functions.py", line 121, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
  File "/usr/local/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py", line 28, in _
    cdata = function(*args, *

The error seems to be similar:

Error in normalise(counts) : 
  trying to get slot "x" from an object of a basic class ("matrix") with no slots
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> parse_dataset -> normalise

I guess that it has to do with the fact that both methods are using the 'count' data instead of the 'expression' data, but I haven't found a way to solve this. I'm using your data wrong?

Thanks in advance!!

zouter commented 5 years ago

Hi Pablo

Thanks for pointing this out. This is because our datasets were generated (and put on zenodo) before we converted everything to sparse matrices.

Currently, a quick and dirty workaround for this is:

dataset$counts <- Matrix::Matrix(dataset$counts, sparse = TRUE)
dataset$expression <- Matrix::Matrix(dataset$expression, sparse = TRUE)

We will update the datasets soon on zenodo in which the expression and counts are saved as sparse objects.

pablommesas commented 5 years ago

Thank you guys! That did the trick :)

I would only point out that to be consistent with my previous code, the 'dataset' object does not actually contain the expression/count matrices explicitly but a function to load them from file, therefore, one should call the function explicitly dataset$expression()/dataset$counts()

The fixed code would look like:

dataset_file <- c("real/gold/stimulated-dendritic-cells-LPS_shalek/dataset.rds")

## Import data
dataset <- read_rds(derived_file(dataset_file, "01-datasets"))

## Currently, a quick and dirty workaround for this is: (https://github.com/dynverse/dyno/issues/47)
dataset$counts <- Matrix::Matrix(dataset$counts(), sparse = TRUE)
dataset$expression <- Matrix::Matrix(dataset$expression(), sparse = TRUE)

#c("slingshot", "monocle_ddrtree", "comp1", "paga_tree")
## Select Method
methods_selected <- "monocle_ddrtree" ## "paga_tree"
#methods_selected <- ti_monocle_ddrtree() ##  ti_paga_tree()

## Infer trajectory
trajectory <- infer_trajectory(dataset, methods_selected, verbose = TRUE)
rcannood commented 5 years ago

Ahh! You used the dynbenchmark/scripts/01-datasets/00-download_from_zenodo.R script :) I would recommend using this approach instead, then:

dataset$counts <- Matrix::Matrix(get_expression(dataset, "counts"), sparse = TRUE)
dataset$expression <- Matrix::Matrix(get_expression(dataset), sparse = TRUE)
zouter commented 4 years ago

Assuming this problem has been solved by now, if not feel free to request a reopen!