R/get_snp_genes.R

Defines functions get_snp_genes

Documented in get_snp_genes

#' @title Get Gene info from SNP ID
#' @description Parse gene IDs from list of SNP IDs (rs IDs). Annotation file is required!
#' @param snp Character. Vector with rs IDs.
#' @param ref Scalar character. Path to file with SNP and gene info (table with "SNP" and "GENE" columns).
#' @return Character vector with gene IDs.
#' @author CainĂ£ Max Couto-Silva
#' @export

get_snp_genes <- function(snp, ref = "~/cmcouto.silva@usp.br/lab_files/all_datasets/Reference_annotation", 
                          include = NULL) {
  ref <- data.table::fread(ref)
  snp <- data.table::data.table(SNP = snp)
  snp.genes <- merge(snp, ref, by = "SNP", sort = F, all.x = T)
  if(!is.null(include)) {
    snp.genes <- snp.genes[, .SD, .SDcols = c("GENE", include)]
  } else {
    snp.genes <- snp.genes[, GENE]
  }
  return(snp.genes)
}
cmcouto-silva/gt documentation built on June 6, 2021, 7:14 p.m.