R/rg-to-mu.r

Defines functions is.mu rg.to.mu

# Convert to methylated/unmethylated signal
#
# Converts Cy5/Cy3 signals to methylated/unmethylated signals from a
# Infinium HumanMethylation450 BeadChip.
#
# @param rg Cy5/Cy3 signal generated by \code{\link{read.rg}()}.
#
# @return List containing methylated and unmethylated signals.
rg.to.mu <- function(rg, probes) {
    stopifnot(is.rg(rg))
    
    probes.M.R <- probes[which(probes$target == "M" & probes$dye == "R"),]
    probes.M.G <- probes[which(probes$target == "M" & probes$dye == "G"),]
    probes.U.R <- probes[which(probes$target == "U" & probes$dye == "R"),]
    probes.U.G <- probes[which(probes$target == "U" & probes$dye == "G"),]
    
    stopifnot(all(c(probes.M.R$address, probes.U.R$address) %in% rownames(rg$R)))
    stopifnot(all(c(probes.M.G$address, probes.U.G$address) %in% rownames(rg$G)))
    
    M <- c(rg$R[probes.M.R$address,"Mean"],
           rg$G[probes.M.G$address,"Mean"])
    U <- c(rg$R[probes.U.R$address,"Mean"],
           rg$G[probes.U.G$address,"Mean"])

    names(M) <- c(probes.M.R$name, probes.M.G$name)
    names(U) <- c(probes.U.R$name, probes.U.G$name)

    list(class="mu",
         version=packageVersion("meffil"),
         M=M,
         U=U[names(M)])
}

is.mu <- function(object)
    is.list(object) && "class" %in% names(object) && object$class == "mu"
perishky/meffil documentation built on June 9, 2024, 5:59 p.m.