R/GenePixResultSet.XTRA.R

setMethodS3("extractRGArray", "RGList", function(this, ...) {
  # To please R CMD check
  data <- this;

  # Extract signals into an array
  dim <- dim(data);
  dimnames <- dimnames(data);
  dim <- c(dim, 2L);
  dimnames <- c(dimnames, list(c("R", "G")));

  if (is.null(dimnames[[1]])) {
    ids <- sprintf("%s,%s", data$genes$ID, data$genes$Name);
    dimnames[[1]] <- ids;
    rm(ids);
  }

  X <- array(c(data$R, data$G), dim=dim, dimnames=dimnames);

  # Not needed anymore
  rm(data, dim, dimnames);

  # Reorder dimensions such that probes are first and samples are last.
  X <- aperm(X, perm=c(1,3,2));

  class(X) <- c(class(X), "RGArray");

  X;  
}) # extractRGArray()


setMethodS3("extractRGArray", "GenePixResultSet", function(this, ...) {
  # Read data
  data <- readLimmaRGList(this, ...);
  extractRGArray(data, ...);
}) # extractRGArray()



setMethodS3("extractAMArray", "GenePixResultSet", function(this, ...) {
  X <- extractRGArray(this, ...);
  X <- asAMArray(X);
  X;
}) # extractAMArray()


setMethodS3("asAMArray", "RGArray", function(X, ...) {
  # Argument 'X':
  dim <- dim(X);
  stopifnot(length(dim) == 3);
  stopifnot(dim[2] == 2);

  # Log-transform signals
  Y <- log2(X);

  # Calculate (A,M)
  M <- Y[,1L,] - Y[,2L,];
  A <- (Y[,1L,] + Y[,2L,])/2;

  # Assign
  Y[,1L,] <- A;
  Y[,2L,] <- M;
  dimnames(Y)[[2]] <- c("A", "M");

  cls <- class(Y);
  cls <- cls[seq(length=which(cls == "RGArray")-1L)];
  cls <- c(cls, "AMArray");
  class(Y) <- cls;
  
  Y;  
}) # asAMArray()



##############################################################################
# HISTORY:
# 2011-06-24
# o Now extractRGArray() for GenePixResultSet utilizes asRGArray() for RGList.
# o Added asRGArray() for RGList.
# 2011-05-23
# o Added asAMArray() to the RGArray class.
# o Added extractRGArray() and extractAMArray().
# o Created.
##############################################################################
HenrikBengtsson/aroma.axon documentation built on May 7, 2019, 1:52 a.m.