Skip to content

Commit

Permalink
Add dependency calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ainefairbrother committed Nov 6, 2022
1 parent 304c90a commit dcdf056
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions R/ensemblQueryLD.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @export
#'
#' @examples
#' query.ensemble.ld.with.snp(rsid="rs3851179", r2=0.8, d.prime=0.8, window.size=500, pop="1000GENOMES:phase_3:EUR")
#' ensemblQueryLDwithSNP(rsid="rs3851179", r2=0.8, d.prime=0.8, window.size=500, pop="1000GENOMES:phase_3:EUR")
ensemblQueryLDwithSNP = function(rsid, r2=0.8, d.prime=0.8, window.size=500, pop="1000GENOMES:phase_3:EUR"){

# load libs
Expand Down Expand Up @@ -100,11 +100,13 @@ ensemblQueryLDwithSNP = function(rsid, r2=0.8, d.prime=0.8, window.size=500, pop
#'
ensemblQueryLDwithSNPlist = function(rsid.list, r2=0.8, d.prime=0.8, window.size=500, pop="1000GENOMES:phase_3:EUR"){

library(magrittr)

# max query length ensembl REST API will accept
max.query.len=1000

if(length(rsid.list)<=max.query.len){
lapply(X=rsid.list, FUN=ensemblQueryLDwithSNP, r2=r2, d.prime=d.prime, window.size=window.size, pop=pop) %>%
lapply(X=rsid.list, FUN=ensemblQueryR::ensemblQueryLDwithSNP, r2=r2, d.prime=d.prime, window.size=window.size, pop=pop) %>%
do.call("rbind", .) %>%
return()
} else{
Expand All @@ -128,6 +130,7 @@ ensemblQueryLDwithSNPlist = function(rsid.list, r2=0.8, d.prime=0.8, window.size
#' @export
#'
#' @examples
#'require(magrittr)
#'data.frame(rsid=rep(c("rs7153434","rs1963154","rs12672022","rs3852802","rs12324408","rs56346870"), 500)) %>%
#' ensemblQueryLDwithLargeSNPdf(in.table=.,
#' r2=0.8,
Expand All @@ -136,6 +139,10 @@ ensemblQueryLDwithSNPlist = function(rsid.list, r2=0.8, d.prime=0.8, window.size
#' pop="1000GENOMES:phase_3:EUR")
ensemblQueryLDwithLargeSNPdf = function(in.table, r2=0.8, d.prime=0.8, window.size=500, pop="1000GENOMES:phase_3:EUR"){

library(dplyr)
library(magrittr)
library(purrr)

# max query length ensembl REST API will accept
max.query.len=1000

Expand Down Expand Up @@ -163,7 +170,7 @@ ensemblQueryLDwithLargeSNPdf = function(in.table, r2=0.8, d.prime=0.8, window.si

out.list[[i]] = in.table[[i]] %>%
dplyr::pull(rsid) %>%
ensemblQueryLDwithSNPlist(rsid.list=., r2=r2, d.prime=d.prime, window.size=window.size, pop=pop)
ensemblQueryR::ensemblQueryLDwithSNPlist(rsid.list=., r2=r2, d.prime=d.prime, window.size=window.size, pop=pop)

}
}
Expand All @@ -186,7 +193,7 @@ ensemblQueryLDwithLargeSNPdf = function(in.table, r2=0.8, d.prime=0.8, window.si

in.table %>%
dplyr::pull(rsid) %>%
ensemblQueryLDwithSNPlist(rsid.list=., r2=r2, d.prime=d.prime, window.size=window.size, pop=pop) %>%
ensemblQueryR::ensemblQueryLDwithSNPlist(rsid.list=., r2=r2, d.prime=d.prime, window.size=window.size, pop=pop) %>%
dplyr::mutate(r2 = as.numeric(r2),
d_prime = as.numeric(d_prime)) %>%
tibble::tibble() %>%
Expand Down
2 changes: 1 addition & 1 deletion man/ensemblQueryLDwithSNP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dcdf056

Please sign in to comment.