Winnie09 / Lamian

39 stars 9 forks source link

Failing when running lamian_test with permutation: Error: $ operator is invalid for atomic vectors #11

Closed nickilott closed 1 year ago

nickilott commented 1 year ago

Hi,

Thanks for developing the tool! I'm just getting started with it but am having a problem running the lamian_test(). I get the following error:

[1] "fitting model: overall: CovariateTest (Model 3 vs.1) or ConstantTest (Model 1) ..."
[1] "The length of fit is ..."
 [1] 1 0 1 0 1 0 1 0 1 0 1
   Mode   FALSE    TRUE 
logical       6       5 
[1] "The length of fit after removing null is ..."
[1] 1 1 1 1 1 1
   Mode   FALSE 
logical       6 
Error: $ operator is invalid for atomic vectors
In addition: Warning message:
In mclapply(seq_len(permuiter + 1), function(i) { :
  scheduled core 1 encountered error in user code, all values of the job will be affected

I am running with the following function call:

tde_test <- lamian_test(
  expr = for_lamian[["expression"]],
  cellanno = for_lamian[["cellanno"]],
  pseudotime = for_lamian[["pseudotime"]],
  design = design,
  test.type = 'time',
  fix.all.zero=FALSE,
  test.method="permutation", 
  ncores=2,
  permuiter = 10,
  verbose.output = TRUE)

where my inputs look like:

for_lamian[["expression"]]

> str(for_lamian[["expression"]])
'data.frame':   7500 obs. of  7047 variables:
 $ EP1_1_AAGGTTCCATGAACCT : num  -0.0119 -0.0494 -0.3792 -0.3093 -0.0119 ...
 $ EP1_1_ACCAGTATCTGTTTGT : num  -0.0119 -0.0494 -0.3792 -0.3093 -0.0119 ...

for_lamian[["cellanno"]]

> str(for_lamian[["cellanno"]])
'data.frame':   7047 obs. of  3 variables:
 $ cell    : chr  "EP1_1_AAGGTTCCATGAACCT" "EP1_1_ACCAGTATCTGTTTGT" "EP1_1_ACCCACTAGCGTCTAT" "EP1_1_ACCCACTCAAGGTGTG" ...
 $ sample  : chr  "GI6642" "GI6642" "GI6642" "GI6642" ...
 $ celltype: Factor w/ 8 levels "Stem/Undifferentiated",..: 4 1 1 1 1 7 1 3 1 4 ...

for_lamian[["pseudotime"]]

>str(for_lamian[["pseudotime"]])
 Named int [1:9811] 1 2 3 4 5 6 7 8 9 10 ...
 - attr(*, "names")= chr [1:9811] "EP1_1_AAGTCTGAGCCCAATT" "EP3_2_CCAGCGAAGTTCCACA" "EP3_1_TTCTACAGTCACACGC" "EP1_2_CTACCCAGTAGAAAGG" ...

design

>str(design)
'data.frame':   8 obs. of  2 variables:
 $ sample : num  1 1 1 1 1 1 1 1
 $ disease: num  2 1 2 1 0 1 0 2

Any help with this issue much appreciated!

Nick

Winnie09 commented 1 year ago

Hi! In your data, expression, cellanno, and pseudotime have different numbers of cells (7500, 7047, 9811). This could lead to the expression being empty when running the line expr <- expr[, names(pseudotime), drop = FALSE]. Please try to only use the cells in the intersect of the cells in these three objects. Please let me know if the issue persists. Thanks!

buriedsand commented 5 months ago

I had the same issue. The error happens because for_lamian[["expression"]] is represented as a dataframe instead of a matrix. Convert it to a matrix with as.matrix().