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

snp_grid_stacking error - task 1 failed - "'from' must be a finite number" #76

Closed
dheerajbobbili1988 opened this issue Apr 17, 2020 · 26 comments

Comments

@dheerajbobbili1988
Copy link

Hi,

I am trying to use your method to calculate the PRS, I am following your tutorial from here (https://github.com/privefl/bigsnpr/blob/master/vignettes/SCT.Rmd). However, I have run into some error at this stage. I have restricted my data only to a subset of SNPs common between the summary stats and plink.bed data before proceeding to make sure that I have the same dimensions. Any pointers would be helpful. Look forward to your response.

final_mod <- snp_grid_stacking(multi_PRS, y[ind.train], ncores = NCORES, K = 4)

Error in { : task 1 failed - "'from' must be a finite number"
Calls: snp_grid_stacking
Execution halted

Regards,
Dheeraj.

@privefl
Copy link
Owner

privefl commented Apr 17, 2020

You can run with debug using debugonce(snp_grid_stacking) and running it again to see where the error occurred.

@dheerajbobbili1988
Copy link
Author

Thanks for your response. So, I ran this command. I'm not sure what I'm missing here.

debugonce(snp_grid_stacking)
final_mod <- snp_grid_stacking(multi_PRS, y[ind.train], ncores = NCORES, K = 4)

and below is the log

debugging in: snp_grid_stacking(multi_PRS, y[ind.train], ncores = NCORES, K = 4)
debug: {
lpS <- attr(multi_PRS, "lpS")
lpS_thr <- attr(multi_PRS, "grid.lpS.thr")
beta_gwas <- attr(multi_PRS, "betas")
all_keep <- attr(multi_PRS, "all_keep")
suppressWarnings(mod <- (if (length(unique(y.train)) == 2)
big_spLogReg
else big_spLinReg)(multi_PRS, y.train, alphas = alphas, ncores = ncores,
...))
best_mod <- summary(mod, best.only = TRUE)
beta_best_mod <- best_mod$beta[[1]]
beta_stacking <- rep(0, ncol(multi_PRS))
ind_col <- attr(mod, "ind.col")
beta_stacking[ind_col] <- head(beta_best_mod, length(ind_col))
ind_last_thr <- 1L + sapply(lpS, function(lp) sum(lp > lpS_thr))
coef <- rep(0, length(beta_gwas))
n_thr_pval <- length(lpS_thr)
ind <- seq_len(n_thr_pval)
for (ind.keep in unlist(all_keep, recursive = FALSE)) {
b <- beta_stacking[ind]
b2 <- c(0, cumsum(b))
coef[ind.keep] <- coef[ind.keep] + b2[ind_last_thr[ind.keep]]
ind <- ind + n_thr_pval
}
list(intercept = best_mod$intercept, beta.G = coef * beta_gwas,
beta.covar = tail(beta_best_mod, -length(ind_col)), mod = mod)
}
debug: lpS <- attr(multi_PRS, "lpS")
Error in summary(final_mod$mod) : object 'final_mod' not found
Calls: snp_grid_stacking -> summary
Error: object 'final_mod' not found
Error in which(new_beta != 0) : object 'new_beta' not found
Calls: snp_grid_stacking -> which
Error in data.frame(y = new_beta, x = beta) : object 'new_beta' not found
Calls: snp_grid_stacking -> ggplot -> data.frame
debug: lpS_thr <- attr(multi_PRS, "grid.lpS.thr")
Error: object 'final_mod' not found
Error in lengths(list(...)) : object 'pred' not found
Calls: snp_grid_stacking -> AUCBoot -> assert_lengths -> lengths
debug: beta_gwas <- attr(multi_PRS, "betas")
Error in data.frame(Phenotype = factor(y[ind.test], levels = 0:1, labels = c("Control", :
object 'pred' not found
Calls: snp_grid_stacking -> ggplot -> data.frame
debug: all_keep <- attr(multi_PRS, "all_keep")
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ tibble 3.0.0 ✔ dplyr 0.8.5
✔ tidyr 1.0.2 ✔ stringr 1.4.0
✔ readr 1.3.1 ✔ forcats 0.5.0
✔ purrr 0.3.3
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
Warning message:
cols is now required.
Please use cols = c(thr.lp)
Error in { :
task 1 failed - "task 1 failed - "Error when subsetting (missing values? out of bounds?)""
Calls: snp_grid_stacking ... big_parallelize -> -> %dopar% ->
debug: suppressWarnings(mod <- (if (length(unique(y.train)) == 2) big_spLogReg else big_spLinReg)(multi_PRS,
y.train, alphas = alphas, ncores = ncores, ...))
Error: object 'auc' not found
debug: big_spLogReg
Error in as_mapper(.f, ...) : object 'max_prs' not found
Calls: snp_grid_stacking
Error: object 'ind.keep' not found
Error in as.list.environment(parent.frame()) :
object 'ind.keep' not found
Calls: snp_grid_stacking
Error in { : task 1 failed - "'from' must be a finite number"
Calls: snp_grid_stacking
Execution halted

@privefl
Copy link
Owner

privefl commented Apr 17, 2020

I would like you to run it interactively after using debugonce().
You should be able to run it line by line inside the function.

@privefl
Copy link
Owner

privefl commented Apr 17, 2020

Alternatively, can you paste the output of str(attributes(multi_PRS))?

And also tell what the versions of bigstatsr and bigsnpr are you using.

@dheerajbobbili1988
Copy link
Author

I had a long output from this command, I removed the lines in the middle.

The version of bigsnpr is ‘1.3.0’ whereas the version of bigstatsr is ‘1.2.3’

str(attributes(multi_PRS))

_List of 6
$ .xData :<environment: 0x562c72215f10>
$ class : chr "FBM"
..- attr(*, "package")= chr "bigstatsr"
$ lpS : num [1:74] 69.76 21.8 8.35 28.95 21.6 ...
$ grid.lpS.thr: num [1:50] 7.4 7.87 8.38 8.91 9.48 ...
$ betas : num [1:74] 1.83 -0.47 0.93 -1.11 1.14 -1.09 1.12 -1.08 1.2 -0.84 ...
$ all_keep :List of 21
..$ 1 :List of 28
.. ..$ : int [1:6] 1 2 3 4 6 7
.. ..$ : int [1:5] 1 2 3 4 7
.. ..$ : int [1:5] 1 2 3 4 7
.. ..$ : int [1:3] 1 2 4
.. ..$ : int [1:6] 1 2 3 4 6 7
....................

..- attr(, "grid")='data.frame': 28 obs. of 4 variables:
.. ..$ size : int [1:28] 5000 10000 20000 50000 1000 2000 4000 10000 500 1000 ...
.. ..$ thr.r2 : num [1:28] 0.01 0.01 0.01 0.01 0.05 0.05 0.05 0.05 0.1 0.1 ...
.. ..$ grp.num: int [1:28] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ thr.imp: num [1:28] 1 1 1 1 1 1 1 1 1 1 ...
.. ..- attr(
, "out.attrs")=List of 2
.. .. ..$ dim : Named int [1:4] 4 7 1 1
.. .. .. ..- attr(*, "names")= chr [1:4] "size" "thr.r2" "grp.num" "thr.imp"
.. .. ..$ dimnames:List of 4
.. .. .. ..$ size : chr [1:4] "size= 50" "size=100" "size=200" "size=500"
.. .. .. ..$ thr.r2 : chr [1:7] "thr.r2=0.01" "thr.r2=0.05" "thr.r2=0.10" "thr.r2=0.20" ...
.. .. .. ..$ grp.num: chr "grp.num=1"
.. .. .. ..$ thr.imp: chr "thr.imp=1"._

@dheerajbobbili1988
Copy link
Author

If it helps, I just ran the script interactively and this is the error

Error in { : task 1 failed - "'from' must be a finite number"

@privefl
Copy link
Owner

privefl commented Apr 17, 2020

It is normal that you have only 74 variants?

I know what the error is, I just want to know what is the line that causes this error in the function.
Are you using RStudio? Does it output anything? Can you run every line interactively after using debugonce()?

Another option would be to use options(error = recover) (make sure to use options(error = NULL) when you're finished). Many debugging options are described at https://adv-r.hadley.nz/debugging.html.

@privefl privefl changed the title snp_grid_stacking error snp_grid_stacking error - task 1 failed - "'from' must be a finite number" Apr 17, 2020
@dheerajbobbili1988
Copy link
Author

dheerajbobbili1988 commented Apr 17, 2020

Yes, I am only using the 74 genome-wide significant SNPs. I understand that it is not the point of using SCT. I'm just testing different methods in terms of practicality. I'm using the same set of SNPs for the other methods as well. I will change to larger set of SNPs in the later stages.

Regarding the error, I think the function is failing in this line. I used the debugonce() function. Hope it helps.

Browse[8]>
debug: big_spLogReg
Browse[8]>
Error during wrapup: task 1 failed - "'from' must be a finite number"

@privefl
Copy link
Owner

privefl commented Apr 17, 2020

What is "this line"?
The lines of code are available at https://github.com/privefl/bigsnpr/blob/master/R/SCT.R#L266-L299.
You should see the same when running the debugger.
At what line of code do you get the error you mention?

Sorry, it is 1am, I need to go..

@dheerajbobbili1988
Copy link
Author

dheerajbobbili1988 commented Apr 19, 2020

Hi,
Sorry, here is the line

Browse[8]> best_mod <- summary(mod, best.only = TRUE)
Error during wrapup: object 'mod' not found

Please let me know if this is what you are looking for.

@privefl
Copy link
Owner

privefl commented Apr 19, 2020

No, it is not the error you reported.

@dheerajbobbili1988
Copy link
Author

Probably this one?

debug at #6: suppressWarnings(mod <- (if (length(unique(y.train)) == 2) big_spLogReg else big_spLinReg)(multi_PRS,
y.train, alphas = alphas, ncores = ncores, ...))
Browse[13]>
debug: big_spLogReg
Browse[13]>
Error during wrapup: task 1 failed - "'from' must be a finite number"

@privefl
Copy link
Owner

privefl commented Apr 19, 2020

Looks like it.
Then, try to run big_spLinReg(multi_PRS, y[ind.train], ncores = NCORES, K = 4).

@dheerajbobbili1988
Copy link
Author

dheerajbobbili1988 commented Apr 20, 2020

Here is the output

Browse[12]> big_spLinReg(multi_PRS, y[ind.train], ncores = NCORES, K = 4)
Error during wrapup: task 1 failed - "'from' must be a finite number"

@privefl
Copy link
Owner

privefl commented Apr 20, 2020

Good, then you need to do the same thing with debugonce() on big_spLinReg, i.e. find the line of code where you get this error.

@dheerajbobbili1988
Copy link
Author

Browse[14]> do.call(COPY_biglasso_main, args)
Error during wrapup: task 1 failed - "'from' must be a finite number"

@privefl
Copy link
Owner

privefl commented Apr 20, 2020

Ok, this won't be very useful.
When you run line by line, there is another button that you can use to go inside the function called by this line.
Do this when you arrive at this line, and you will be able to run line by line inside COPY_biglasso_main.

@dheerajbobbili1988
Copy link
Author

dheerajbobbili1988 commented Apr 20, 2020

Browse[24]> assert_lengths(y.train, ind.train, rows_along(covar.train), base.train, ind.sets)
Error during wrapup: argument must be coercible to non-negative integer

@dheerajbobbili1988
Copy link
Author

Also, if it helps:

Browse[26]> length(y.train)
[1] 60
Browse[26]> length(ind.train)
[1] 60
Browse[26]> length(rows_along(covar.train))
Error during wrapup: argument must be coercible to non-negative integer
Browse[26]> length(base.train)
[1] 0
Browse[26]> length(ind.sets)
[1] 0

@privefl
Copy link
Owner

privefl commented Apr 20, 2020

It should be the same error.

@dheerajbobbili1988
Copy link
Author

_cross.res <- foreach(alpha = alphas) %:% foreach(ic = 1:K) %dopar%
{
in.val <- (ind.sets == ic)
center <- do.call("c", lapply(list_summaries, function(x) x[["center"]][ic,
]))[keep]
scale <- do.call("c", lapply(list_summaries, function(x) x[["scale"]][ic,
]))[keep]
resid <- do.call("c", lapply(list_summaries, function(x) x[["resid"]][ic,
]))[keep]
center <- c(center, summaries.covar[["center"]][ic,
])
scale <- c(scale, summaries.covar[["scale"]][ic,
])
resid <- c(resid, summaries.covar[["resid"]][ic,
])
lambda.max <- max(abs(resid/pf.keep)[pf.keep !=
0])/alpha
lambda <- exp(seq(log(lambda.max), log(lambda.max *
lambda.min.ratio), length.out = nlambda))
res <- COPY_biglasso_part(X, y.train = y.train[!in.val],
ind.train = ind.train[!in.val], ind.col = ind.col[keep],
covar.train = covar.train[!in.val, , drop = FALSE],
family, lambda, center, scale, resid, alpha,
eps, max.iter, dfmax, ind.val = ind.train[in.val],
covar.val = covar.train[in.val, , drop = FALSE],
y.val = y.train[in.val], n.abort, nlam.min,
base.train = base.train[!in.val], base.val = base.train[in.val],
pf.keep)
res$intercept <- res$intercept + beta0
res$beta <- res$beta + c(beta.X[keep], beta.covar)
res
}

Error during wrapup: task 1 failed - "'from' must be a finite number"_

@privefl
Copy link
Owner

privefl commented Apr 21, 2020

Thanks for this.
However, even with this, it is not clear for me where it comes from. The easiest would be to have a reproducible example that I could investigate myself.

Are you sure you have checked your inputs for weird things?
Basically, you have only multi_PRS and y[ind.train] here.
You can check e.g. big_colstats(multi_PRS) and summary(y[ind.train]).

@dheerajbobbili1988
Copy link
Author

Thank you for your help. Where can I share the data?

@privefl
Copy link
Owner

privefl commented Apr 21, 2020

Are you allowed to do that?
If yes, some drive/dropbox would work.
And the script to reproduce your problem.

@dheerajbobbili1988
Copy link
Author

Hi,

I have solved the error. Before sending you the error I decided to clean up the script that I was using and reformat everything in the same way as you described in the tutorial. I guess the problem was coming from the summary statistics file that I was using and now it works 🙂 . Thank you for your help.

Regards,
Dheeraj.

@privefl
Copy link
Owner

privefl commented Apr 21, 2020

Good it now works.

@privefl privefl closed this as completed Apr 21, 2020
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

2 participants