LPWC icon indicating copy to clipboard operation
LPWC copied to clipboard

Error in shift[i] <- score(bcorr, lags) : replacement has length zero

Open kainanli opened this issue 3 years ago • 13 comments

I have this error when I use it, what should I do, thanks for the answer: Error in shift[i] <- score(bcorr, lags) : replacement has length zero

kainanli avatar Jun 29 '22 09:06 kainanli

@kainanli thanks for the error report. @thevaachandereng and I can work to help with this. Can you please tell us more about when you encounter this error message? Are you calling the corr.bestlag function?

agitter avatar Jun 29 '22 14:06 agitter

Is this from using corr.bestlag function or some other function? Can you please provide the time point you used?

thevaachandereng avatar Jun 30 '22 15:06 thevaachandereng

Hi @kainanli I'm closing this issue because we cannot debug the error without more information. Please reopen it if you can answer the questions above.

agitter avatar Jul 26 '22 14:07 agitter

Sorry for not seeing your reply in time. Yes, I am using the corr.bestlag. The command is :output.Low<- corr.bestlag (data=num. data, timepoints=c (0.0001,6, 12, 24, 48, 96, 120), max.lag=1, severity="low", iter=10), error in shift [i]<- score (bcorr, lags): replacement has length zero

likainan001 avatar Nov 13 '22 09:11 likainan001

I used example. R script, but I get this error when I use my data, my data format is consistent with the example, what can I do to solve it, thank you very much!

likainan001 avatar Nov 13 '22 15:11 likainan001

@likainan001 would you be able to share the data with us that causes the error? If the example script runs and your data causes an error, we may need to see that dataset to understand the underlying issue. Thanks.

agitter avatar Nov 13 '22 22:11 agitter

test.txt Yes,here is my sample data

likainan001 avatar Nov 14 '22 01:11 likainan001

I find that this error occurs when all data after the first time point is the same or when all values before the last time point are the same.

likainan001 avatar Nov 14 '22 02:11 likainan001

@thevaachandereng can you please see if you can reproduce this error with the dataset provided?

agitter avatar Nov 15 '22 14:11 agitter

@likainan001 I was able to reproduce this error with your dataset but have not yet investigated the cause. I loaded the dataset, set timepoints <- c(0, 6, 12, 24, 48, 96, 120) and ran

> corr.bestlag(dataset, timepoints = timepoints, max.lag = 1, penalty = "high", iter = 10)
Error in shift[i] <- score(bcorr, lags) : replacement has length zero

agitter avatar Nov 25 '22 15:11 agitter

I will look into this right away! My email changed and I have no access to my columbia email. I just changed my email and have access to the notification now.

Thevaa

On Nov 25, 2022, at 10:28 AM, Anthony Gitter @.***> wrote:

@likainan001 https://github.com/likainan001 I was able to reproduce this error with your dataset but have not yet investigated the cause. I loaded the dataset, set timepoints <- c(0, 6, 12, 24, 48, 96, 120) and ran

corr.bestlag(dataset, timepoints = timepoints, max.lag = 1, penalty = "high", iter = 10) Error in shift[i] <- score(bcorr, lags) : replacement has length zero — Reply to this email directly, view it on GitHub https://github.com/gitter-lab/LPWC/issues/60#issuecomment-1327628500, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADDOXTWNY2BOK2BOVH6PQRLWKDLJFANCNFSM52FALZUA. You are receiving this because you were mentioned.

thevaachandereng avatar Nov 25 '22 16:11 thevaachandereng

I was able to narrow down the range of genes that causes this error, which should help the debugging:

corr.bestlag(dataset[56:59, ], timepoints=timepoints, max.lag = 1, penalty = "high", iter = 10)

Still gives the error. I used a debugger and noticed a few potential problems with bestlag.R. We get can NaN correlations that go undetected. That is a problem here https://github.com/gitter-lab/LPWC/blob/56d076d31adf00e6b466e2e7cd27c7983e6056ab/R/bestlag.R#L72-L73 because which.max(corr) and max(corr) seem to handle NaN inconsistently.

This seemed to happen when the expression data was constant

Browse[3]> data[j, 1:(length(timepoints) - m)]
       X0h        X6h       X12h       X24h       X48h       X96h 
-0.3779645 -0.3779645 -0.3779645 -0.3779645 -0.3779645 -0.3779645

I wasn't able to catch when the actual error happened inside the score function. Sometimes it was being called with bcorr that had NaN values, but those were being ignored here https://github.com/gitter-lab/LPWC/blob/56d076d31adf00e6b466e2e7cd27c7983e6056ab/R/score.R#L32 Possibly when all the non-NaN values are negative then this is a problem? Or something like that?

We also need better error handling in score because this test is not detecting NaN values in bcorr https://github.com/gitter-lab/LPWC/blob/56d076d31adf00e6b466e2e7cd27c7983e6056ab/R/score.R#L22-L23

I'm guessing this row of the dataset could be causing problems:

59	F01067	-0.377964473	-0.377964473	-0.377964473	-0.377964473	-0.377964473	-0.377964473	2.267786838

When we have a lag of 1, all the remaining values are the same. @thevaachandereng do we account for that possibility anywhere in the code?

agitter avatar Nov 29 '22 21:11 agitter

@thevaachandereng have you had a chance to try to investigate the behavior I described above?

@likainan001 if you need to run LPWC before we fix this, you could try removing genes like the example I showed were all values are the same except for the first or last value. Are these real experimental measurements? It would be surprising to have nonzero measurements that are all the same except for one timepoint.

agitter avatar Dec 19 '22 20:12 agitter