YosefLab / ImpulseDE2

37 stars 10 forks source link

computeModelFits error : invalid argument to unary operator #14

Open gomeznick86 opened 4 years ago

gomeznick86 commented 4 years ago

I tried running the computeModelFits function using my own data and it errors out with the message:

"Error in -vecImpulseParam[1] : invalid argument to unary operator".

I looked through the traceback but aren't familiar with where its calling the function.

Below is the traceback.

9.FUN(X[[i]], ...) 8.lapply(X = X, FUN = FUN, ...) 7.sapply(vecTimepoints, function(t) { (1/vecImpulseParam[3]) (vecImpulseParam[2] + (vecImpulseParam[3] - vecImpulseParam[2]) (1/(1 + exp(-vecImpulseParam[1] (t - vecImpulseParam[5]))))) (vecImpulseParam[4] + ... 6.ImpulseDE2:::evalImpulse_comp(vecImpulseParam = get_lsModelFits(obj = objectImpulseDE2)$case[[x]]$lsImpulseFit$vecImpulseParam, vecTimepoints = dfAnnot$Time) 5.FUN(X[[i]], ...) 4.lapply(objectImpulseDE2@vecAllIDs, function(x) { vecSfValues <- get_vecSizeFactors(obj = objectImpulseDE2) vecImpulseValuesCase <- ImpulseDE2:::evalImpulse_comp(vecImpulseParam = get_lsModelFits(obj = objectImpulseDE2)$case[[x]]$lsImpulseFit$vecImpulseParam, vecTimepoints = dfAnnot$Time) ... 3.lapply(objectImpulseDE2@vecAllIDs, function(x) { vecSfValues <- get_vecSizeFactors(obj = objectImpulseDE2) vecImpulseValuesCase <- ImpulseDE2:::evalImpulse_comp(vecImpulseParam = get_lsModelFits(obj = objectImpulseDE2)$case[[x]]$lsImpulseFit$vecImpulseParam, vecTimepoints = dfAnnot$Time) ... 2.do.call(rbind, lapply(objectImpulseDE2@vecAllIDs, function(x) { vecSfValues <- get_vecSizeFactors(obj = objectImpulseDE2) vecImpulseValuesCase <- ImpulseDE2:::evalImpulse_comp(vecImpulseParam = get_lsModelFits(obj = objectImpulseDE2)$case[[x]]$lsImpulseFit$vecImpulseParam, vecTimepoints = dfAnnot$Time) ... 1.computeModelFits(objectImpulseDE2 = objectImpulseDE2)

Edit: I think it has to do with the evalImpulse function. Any ideas? Simulated data seems to return things just fine.

davidsebfischer commented 4 years ago

Hi @gomeznick86, the input format may be wrong, can you check that the count data is numeric and the time is numeric?

gomeznick86 commented 4 years ago

I double checked and they both are numeric.

is.numeric(txi_counts_ordered)
[1] TRUE
is.numeric(df_annotation_ordered$Time)
[1] TRUE

Then I used this command which completes successfully.

objectImpulseDE2_2 <- runImpulseDE2(
  matCountData    = txi_counts_ordered, 
  dfAnnotation    = df_annotation_ordered,
  boolCaseCtrl    = FALSE,
  vecConfounders  = NULL,
  boolIdentifyTransients =TRUE,
  scaNProc        = 12)

I'm able to plot heatmaps which makes me think that its able to compute and fit a model. Is there another way to extract the values from the object?

davidsebfischer commented 4 years ago

Can you post me the full call from the code snippet involving runImpulseDE2 until the error? This might just a minor mistake in code usage but I am not 100% sure what you are doing. This here might be related too: https://github.com/YosefLab/ImpulseDE2/issues/11

EinarBaldvin commented 8 months ago

Hi,

I am quite late to the party but there is a bug in the computeModelFits code.

computeModelFits uses all vecAllIDs in objectImpulseDE2 but if your input had any IDs that got discarded due to having zero counts across all samples that throws the error as those IDs will not have any data behind them.

First and easiest solution is to manually remove these entries first with mat <- mat[as.logical(rowSums(mat != 0)), ]

Second would be to modify the function code to use "names(ObjectImpulseDE2@vecDispersions)" instead of objectImpulseDE2@vecAllIDs.