R/plotSNPcalls.R

Defines functions .plotSNPcallmat plotSNPcalls

Documented in plotSNPcalls

#' call and plot SNPs from a matrix of SNP betas 
#' 
#' plot SNPs living in metadata(x)$SNPs, provided they match sampleNames(x)
#' 
#' @param x       a grSet with SNPs in its metadata(), or a SNP matrix 
#' @param rotate  rotate the subjects onto the side? (FALSE)
#' @param ...     other arguments passed on to Heatmap
#' 
#' @details
#' The plotting itself is done by miser:::.plotSNPcallmat(). 
#' 
#' @import ComplexHeatmap
#' @import circlize
#' 
#' @export
plotSNPcalls <- function(x, rotate=FALSE, ...) { 

  if (is(x, "GenomicRatioSet") | is(x, "RGChannelSet")) { 
    SNPs <- as.matrix(metadata(x)$SNPs) 
    if (is.null(SNPs) | !all(colnames(x) %in% colnames(SNPs))) {
      stop("Your SNPs don't match your samples. Aborting.")
    }
    SNPs <- SNPs[, colnames(x)]
  } else { 
    SNPs <- as.matrix(x)
  }
  SNPcalls <- SNPcalls(SNPs)
  if (rotate) SNPcalls <- t(SNPcalls)
  .plotSNPcallmat(SNPcalls, ...) 

}


# helper fn
.plotSNPcallmat <- function(SNPs_called, ...) {

  SNP_colors <- colorRamp2(seq(0, 2), c("#00007F", "yellow", "#7F0000"))
  
  Heatmap(SNPs_called,
          col=SNP_colors, 
          name="Alleles",
          clustering_method_columns='ward.D2', 
          clustering_distance_columns='manhattan', 
          clustering_method_rows='ward.D2', 
          clustering_distance_rows='manhattan',
          ...)

}
ttriche/sesamizeGEO documentation built on Nov. 12, 2023, 5:42 p.m.