Learn R Programming

qtl2pattern (version 1.2.1)

create_probs_query_func: Create a function to query genotype probabilities

Description

Create a function that will connect to a database of genotype probability information and return a list with `probs` object and a `map` object.

Usage

create_probs_query_func(dbfile, method_val = "fst", probdir_val = "genoprob")

Value

Function with six arguments, `chr`, `start`, `end`, `allele`, `method` and `probdir`. It returns a list with `probs` and `map` objects spanning the region specified by the first three arguments. The `probs` element should be either a `calc_genoprob` or `fst_genoprob` object (see fst_genoprob).

Arguments

dbfile

Name of database file

method_val

either "fst" or "calc" for type of genotype probabilities

probdir_val

name of probability directory (default "genoprob")

Details

Note that this function assumes that probdir_val has a file with the physical map with positions in Mbp and other files with genotype probabilities. See read_probs for details on how probabilities are read. See create_variant_query_func for original idea.

Examples

Run this code
dirpath <- "https://raw.githubusercontent.com/rqtl/qtl2data/master/DOex"

create_qv <- function(dirpath) {
  # Download SNP info for DOex from web via RDS.
  # snpinfo is referenced internally in the created function.
  
  tmpfile <- tempfile()
  download.file(file.path(dirpath, "c2_snpinfo.rds"), tmpfile, quiet=TRUE)
  snpinfo <- readRDS(tmpfile)
  unlink(tmpfile)
  snpinfo <- dplyr::rename(snpinfo, pos = pos_Mbp)
  
  function(chr, start, end) {
    if(chr != "2") return(NULL)
    if(start < 96.5) start <- 96.5
    if(end > 98.5) end <- 98.5
    if(start >= end) return(NULL)
    dplyr::filter(snpinfo, .data$pos >= start, .data$pos <= end)
  }
}
# \donttest{
query_variants <- create_qv(dirpath)
# }

create_qg <- function(dirpath) {
  # Download Gene info for DOex from web via RDS
  # gene_tbl is referenced internally in the created function.
  
  tmpfile <- tempfile()
  download.file(file.path(dirpath, "c2_genes.rds"), tmpfile, quiet=TRUE)
  gene_tbl <- readRDS(tmpfile)
  unlink(tmpfile)
  
  function(chr, start, end) {
    if(chr != "2") return(NULL)
    if(start < 96.5) start <- 96.5
    if(end > 98.5) end <- 98.5
    if(start >= end) return(NULL)
    dplyr::filter(gene_tbl, .data$end >= start, .data$start <= end)
  }
}
# \donttest{
query_genes <- create_qg(dirpath)
# }

# Examples for probs require either FST or RDS storage of data.

Run the code above in your browser using DataLab