Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kainanli opened this issue Jun 29, 2022 · 13 comments
Open

Comments

@kainanli
Copy link

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

@agitter
Copy link
Member

agitter commented Jun 29, 2022

@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?

@thevaachandereng
Copy link
Member

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

@agitter
Copy link
Member

agitter commented Jul 26, 2022

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 agitter closed this as completed Jul 26, 2022
@likainan001
Copy link

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
Copy link

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!

@agitter
Copy link
Member

agitter commented Nov 13, 2022

@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.

@likainan001
Copy link

test.txt
Yes,here is my sample data

@likainan001
Copy link

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.

@agitter
Copy link
Member

agitter commented Nov 15, 2022

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

@agitter
Copy link
Member

agitter commented Nov 25, 2022

@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

@thevaachandereng
Copy link
Member

thevaachandereng commented Nov 25, 2022 via email

@agitter
Copy link
Member

agitter commented Nov 29, 2022

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

LPWC/R/bestlag.R

Lines 72 to 73 in 56d076d

lags[j] <- val[which.max(corr)]
bcorr[j] <- max(corr)

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

LPWC/R/score.R

Line 32 in 56d076d

return(uni.lags[which.max(value)])

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

LPWC/R/score.R

Lines 22 to 23 in 56d076d

stopifnot(length(corr) == length(lags), all(is.numeric(corr)),
all(is.numeric(lags)))

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
Copy link
Member

agitter commented Dec 19, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants