R/bm_select.r

Defines functions is.chr.mt is.chr.y is.chr.x is.autosome which.inds which.snps test.inds test.snps select.inds select.snps

Documented in is.autosome is.chr.mt is.chr.x is.chr.y select.inds select.snps test.inds test.snps which.inds which.snps

select.snps <- function(x, condition) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  w <- eval(substitute(condition), x@snps, parent.frame())
  miss <- is.na(w)
  if(sum(miss)>0) {
    warning(paste(sum(miss), 'SNP(s) with undefined condition are removed from bed.matrix'))
    w <- w & !miss
  }
  x[,w]
}

select.inds <- function(x, condition) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  w <- eval(substitute(condition), x@ped, parent.frame())
  miss <- is.na(w)
  if(sum(miss)>0) {
    warning(paste(sum(miss), 'individual(s) with undefined condition are removed from bed.matrix'))
    w <- w & !miss
  }
  x[w,]
}

test.snps <- function(x, condition, na.to.false = TRUE) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  w <- eval(substitute(condition), x@snps, parent.frame())
  miss <- is.na(w)
  if(na.to.false & sum(miss)>0)
    return(w & !miss)
  w
}

test.inds <- function(x, condition, na.to.false = TRUE) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  w <- eval(substitute(condition), x@ped, parent.frame())
  miss <- is.na(w)
  if(sum(miss)>0)
    return(w & !miss)
  w
}

which.snps <- function(x, condition) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  which(eval(substitute(condition), x@snps, parent.frame()))
}

which.inds <- function(x, condition) {
  if(!is(x, "bed.matrix")) stop("x is not a bed.matrix")
  which(eval(substitute(condition), x@ped, parent.frame()))
}

is.autosome <- function(chr) chr %in% getOption("gaston.autosomes")
is.chr.x    <- function(chr) chr %in% getOption("gaston.chr.x")
is.chr.y    <- function(chr) chr %in% getOption("gaston.chr.y")
is.chr.mt   <- function(chr) chr %in% getOption("gaston.chr.mt")

Try the gaston package in your browser

Any scripts or data that you put into this service are public.

gaston documentation built on Dec. 28, 2022, 1:30 a.m.