Last active
November 9, 2018 14:58
-
-
Save privefl/42b41d771bbeae63245b8304ef283c70 to your computer and use it in GitHub Desktop.
Get genes associated with SNPs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("bigstatsr") | |
#' Get genes | |
#' | |
#' Get genes associated with SNPs. | |
#' | |
#' @param rsid A character vector of 'rs' ID of SNPs to investigate. | |
#' @param ncores Number of cores to use. | |
#' | |
#' @return A character vector of genes in the form `"<name>:<ID>". Note that | |
#' there can be multiple genes per SNP (separated by a comma), or none (`NA`). | |
#' @export | |
#' | |
#' @examples | |
#' rsid <- c("rs3934834", "rs3737728", "rs6687776", "rs9651273", "rs4970405", | |
#' "rs12726255", "rs2298217", "rs4970362", "rs9660710", "rs4970420") | |
#' snp_gene(rsid) | |
snp_gene <- function(rsid, ncores = 1) { | |
if (requireNamespace("rsnps", quietly = TRUE)) { | |
big_apply(FBM(1, 1), a.FUN = function(X, ind, ID) { | |
rsnps::ncbi_snp_summary(ID[ind])$gene2 | |
}, a.combine = 'c', ind = seq_along(rsid), | |
block.size = 300, ncores = ncores, ID = rsid) | |
} else { | |
stop(paste("Please install R package {rsnps}", | |
"with `devtools::install_github('ropensci/rsnps')`.")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment