dynverse / dynmethods

A collection of 50+ trajectory inference methods within a common interface 📥📤
https://dynverse.org
Other
118 stars 26 forks source link

NULL model slots after running infer_trajectories #175

Closed shaln closed 4 months ago

shaln commented 4 months ago

Hi, apologies in advance about the lengthy post! Tried to include as much information as possible, since I'm not quite sure how to fix this. I have been getting the following error when I tried plotting the inferred trajectories.

> model <- dynwrap::infer_trajectories(dataset, verbose = TRUE,
                                     method = list(ti_slingshot(),
                                                   ti_paga(), ti_paga_tree(), ti_raceid_stemid()),
                                     give_priors = c('start_id','end_id'))
> plot_dimred(model)
Error: dynwrap::is_wrapper_with_trajectory(trajectory = trajectory) is not TRUE

When I checked the object model, model$model seems to be empty, with no trajectories being output if I understood this correctly?

> model$summary
[[1]]
# A tibble: 1 × 12
  method_name method_id dataset_id      stdout stderr error prior_df time_sessionsetup time_preprocessing time_method
  <chr>       <chr>     <chr>           <chr>  <chr>  <chr> <list>               <dbl>              <dbl>       <dbl>
1 Slingshot   slingshot 20240417_19513… ""     ""     "Err… <tibble>              92.0                  0          NA
# ℹ 2 more variables: time_postprocessing <dbl>, time_sessioncleanup <dbl>

[[2]]
# A tibble: 1 × 12
  method_name method_id dataset_id      stdout stderr error prior_df time_sessionsetup time_preprocessing time_method
  <chr>       <chr>     <chr>           <chr>  <chr>  <chr> <list>               <dbl>              <dbl>       <dbl>
1 PAGA        paga      20240417_19513… ""     ""     "Err… <tibble>              87.6                  0          NA
# ℹ 2 more variables: time_postprocessing <dbl>, time_sessioncleanup <dbl>

[[3]]
# A tibble: 1 × 12
  method_name method_id dataset_id      stdout stderr error prior_df time_sessionsetup time_preprocessing time_method
  <chr>       <chr>     <chr>           <chr>  <chr>  <chr> <list>               <dbl>              <dbl>       <dbl>
1 PAGA Tree   paga_tree 20240417_19513… ""     ""     "Err… <tibble>              87.7                  0          NA
# ℹ 2 more variables: time_postprocessing <dbl>, time_sessioncleanup <dbl>

[[4]]
# A tibble: 1 × 12
  method_name     method_id  dataset_id stdout stderr error prior_df time_sessionsetup time_preprocessing time_method
  <chr>           <chr>      <chr>      <chr>  <chr>  <chr> <list>               <dbl>              <dbl>       <dbl>
1 RaceID / StemID raceid_st… 20240417_… ""     ""     "Err… <tibble>              88.1                  0          NA
# ℹ 2 more variables: time_postprocessing <dbl>, time_sessioncleanup <dbl>

> head(model)
# A tibble: 4 × 7
  dataset_ix method_ix dataset_id                                method_id     method_name     model  summary 
       <int>     <int> <chr>                                     <chr>         <chr>           <list> <list>  
1          1         1 20240417_195130__data_wrapper__4DmAh8WqNR slingshot     Slingshot       <NULL> <tibble>
2          1         2 20240417_195130__data_wrapper__4DmAh8WqNR paga          PAGA            <NULL> <tibble>
3          1         3 20240417_195130__data_wrapper__4DmAh8WqNR paga_tree     PAGA Tree       <NULL> <tibble>
4          1         4 20240417_195130__data_wrapper__4DmAh8WqNR raceid_stemid RaceID / StemID <NULL> <tibble> 

I'm not quite sure what went wrong, as I could run infer_trajectories without any errors (via containers).

> model <- dynwrap::infer_trajectories(dataset, verbose = TRUE,
+                                      method = list(ti_slingshot(),
+                                                    ti_paga(), ti_paga_tree(), ti_raceid_stemid()),
+                                      give_priors = c('start_id','end_id'))
Executing 'slingshot' on '20240417_195130__data_wrapper__4DmAh8WqNR'
With parameters: list(cluster_method = "pam", ndim = 20L, shrink = 1L, reweight = TRUE,     reassign = TRUE, thresh = 0.001, maxit = 10L, stretch = 2L,     smoother = "smooth.spline", shrink.method = "cosine")
inputs: expression
priors : start_id, end_id
Input saved to /tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a348584166/ti
Running method using babelwhale
Running /usr/local/bin/docker run --name 20240417_205958__container__ixZCOmWYAb -e 'TMPDIR=/tmp2' --workdir \
  /ti/workspace -v '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a348584166/ti:/ti' -v \
  '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a345a2d93d1/tmp:/tmp2' \
  'dynverse/ti_slingshot:v1.0.3' --dataset /ti/input.h5 --output /ti/output.h5 --use_priors all
Executing 'paga' on '20240417_195130__data_wrapper__4DmAh8WqNR'
With parameters: list(filter_features = TRUE, n_neighbors = 15L, n_comps = 50L,     n_dcs = 15L, resolution = 1L, embedding_type = "fa", connectivity_cutoff = 0.05)
inputs: counts
priors : start_id
Input saved to /tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a3474894049/ti
Running method using babelwhale
Running /usr/local/bin/docker run --name 20240417_210737__container__bLYxYH1eEL -e 'TMPDIR=/tmp2' --workdir \
  /ti/workspace -v '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a3474894049/ti:/ti' -v \
  '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a345edbb464/tmp:/tmp2' \
  'dynverse/ti_paga:v0.9.9.05' --dataset /ti/input.h5 --output /ti/output.h5 --use_priors all
Executing 'paga_tree' on '20240417_195130__data_wrapper__4DmAh8WqNR'
With parameters: list(filter_features = TRUE, n_neighbors = 15L, n_comps = 50L,     n_dcs = 15L, resolution = 1L, embedding_type = "fa")
inputs: counts
priors : start_id
Input saved to /tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a343ab601d6/ti
Running method using babelwhale
Running /usr/local/bin/docker run --name 20240417_211032__container__BS1cEho5Lo -e 'TMPDIR=/tmp2' --workdir \
  /ti/workspace -v '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a343ab601d6/ti:/ti' -v \
  '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a34332a6b7/tmp:/tmp2' \
  'dynverse/ti_paga_tree:v0.9.9.06' --dataset /ti/input.h5 --output /ti/output.h5 --use_priors all
Executing 'raceid_stemid' on '20240417_195130__data_wrapper__4DmAh8WqNR'
With parameters: list(knn = 10L, ccor = 0.4, metric = "pearson", sat = TRUE, samp = 1000L,     cln = 30L, clustnr = 30L, bootnr = 50L, FUNcluster = "kmedoids",     probthr = 0.001, outminc = 5L, outlg = 2L, outdistquant = 0.95,     initial_cmd = TRUE, perplexity = 30L, cthr = 5L, nmode = TRUE,     projcells_knn = 3L, fr = FALSE, pdishuf = 500L, fast = FALSE,     pthr = 0.01, scthr = 0.2)
inputs: counts
priors : 
Input saved to /tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a343cfa677e/ti
Running method using babelwhale
Running /usr/local/bin/docker run --name 20240417_211341__container__nvN04F1HUX -e 'TMPDIR=/tmp2' --workdir \
  /ti/workspace -v '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a343cfa677e/ti:/ti' -v \
  '/tmp/folders/tn/9np01dtn13dgk_k10m3f92j80000gp/T//Rtmp7eZ4bI/file2a345ba0a078/tmp:/tmp2' \
  'dynverse/ti_raceid_stemid:v0.9.9.01' --dataset /ti/input.h5 --output /ti/output.h5

Here are the rest of the code I ran prior to running infer_trajectories. In case it matters, the 10X data all.samples was previously processed in Seurat v5 using scTransform v2, R v4.3.3, RStudio Build 524. Any help would be much appreciated!

library(dyno)
library(tidyverse)
library(SeuratDisk)
library(Seurat)
set.seed(123)

# LOAD DATA
> all.samples <- readRDS("RDS Files/all.samples_clusters_prepsctfindmarkers.RDS")
> Idents(all.samples) <- 'orig.ident'

# PREPARE DATA
> start.cells <- WhichCells(all.samples, idents = 'Control_D1')
> end.cells <- WhichCells(all.samples, idents = 'Treatment_D9')

> dataset <- wrap_expression(
  expression = Matrix::t(all.samples@assays$SCT@data),
  counts = Matrix::t(all.samples@assays$SCT@counts)
)

> dataset <- add_grouping(
  dataset,
  all.samples$orig.ident
)
> names(dataset)[9] <- 'orig.ident_levels'
> names(dataset)[10] <- 'orig.ident'

> dataset <- add_grouping(
  dataset,
  all.samples$condition
)
> names(dataset)[11] <- 'condition_levels'
> names(dataset)[12] <- 'condition'

> dataset <- add_grouping(
  dataset,
  all.samples$seurat_clusters
)
> names(dataset)[13] <- 'seurat_clusters_levels'
> names(dataset)[14] <- 'seurat_clusters'

> dataset <- add_grouping(
  dataset,
  all.samples$clusters.cond
)
> names(dataset)[15] <- 'clusters.cond_levels'
> names(dataset)[16] <- 'clusters.cond'

> dataset <- add_grouping(
  dataset,
  all.samples$clusters.orig.ident
)
> names(dataset)[17] <- 'clusters.orig.ident_levels'
> names(dataset)[18] <- 'clusters.orig.ident'

> dataset <- add_prior_information(
  dataset,
  start_id <- start.cells,
  end_id <- end.cells,
)

> dataset <- add_dimred(
  dataset,
  all.samples@reductions$umap@cell.embeddings,
  all.samples@reductions$pca@cell.embeddings
)

model <- dynwrap::infer_trajectories(dataset, verbose = TRUE,
                                     method = list(ti_slingshot(),
                                                   ti_paga(), ti_paga_tree(), ti_raceid_stemid()),
                                     give_priors = c('start_id','end_id'))

plot_dimred(model)
shaln commented 4 months ago

Did not realise there was an error message within the individual tibbles. Seems like a memory issue!

"Error: Container was killed, possibly because it ran out of memory (error code 137)\n"