R/heat_vis.R

Defines functions heat_vis

Documented in heat_vis

#' Using correlation information to draw a heatmaps
#'
#' This function would base on Fold-Change information
#' from the output of \link{negative_cor},
#' \link{differExp_discrete} and show heatmaps to users.
#' Note that if miRNA-gene interactions (row) from input
#' are larger than 100, the lable in plot would be unclear.
#'
#' @return heatmap plots  of miRNA and gene.
#'
#' @seealso \code{\link[gplots]{heatmap.2}} for plot.
#'
#' @param cor_data matrix format generated from
#'    \link{negative_cor}.
#' @param mrna_d differential expressed data in data.frame format, with
#'    sample name in columns and gene symbol in rows, which is generated by
#'    \link{differExp_discrete} or \link{differExp_continuous}.
#' @param mirna_21 differential expressed data in data.frame format, with
#'    sample name in columns and miRNAl in rows, which is generated by
#'    \link{differExp_discrete} or \link{differExp_continuous}, miRNA should
#'    be miRBase 21 version now.
#'
#' @examples
#' ## Use the internal dataset
#' data("mirna", package = "anamiR", envir = environment())
#' data("pheno.mirna", package = "anamiR", envir = environment())
#' data("mrna", package = "anamiR", envir = environment())
#' data("pheno.mrna", package = "anamiR", envir = environment())
#'
#' ## SummarizedExperiment class
#' require(SummarizedExperiment)
#' mirna_se <- SummarizedExperiment(
#'  assays = SimpleList(counts=mirna),
#'  colData = pheno.mirna)
#'
#' ## SummarizedExperiment class
#' require(SummarizedExperiment)
#' mrna_se <- SummarizedExperiment(
#'  assays = SimpleList(counts=mrna),
#'  colData = pheno.mrna)
#'
#' ## Finding differential miRNA from miRNA expression data with t.test
#' mirna_d <- differExp_discrete(
#'    se = mirna_se,
#'    class = "ER",
#'    method = "t.test"
#' )
#'
#' ## Finding differential mRNA from mRNA expression data with t.test
#' mrna_d <- differExp_discrete(
#'    se = mrna_se,
#'    class = "ER",
#'    method = "t.test"
#' )
#'
#' ## Convert annotation to miRBse 21
#' mirna_21 <- miR_converter(data = mirna_d, original_version = 17)
#'
#' ## Correlation
#' cor <- negative_cor(mrna_data = mrna_d, mirna_data = mirna_21)
#'
#' ## Draw heatmap
#' heat_vis(cor, mrna_d, mirna_21)
#'
#' @import stats
#' @importFrom gplots heatmap.2
#' @export

heat_vis <- function(
  cor_data,
  mrna_d,
  mirna_21
) {

  mirna <- cor_data[, 1]
  gene <- cor_data[, 2]

  mirna_da <- mirna_21[, 1:(ncol(mirna_21)-5)]
  mrna_da <- mrna_d[, 1:(ncol(mrna_d)-5)]

  mirna_exp <- mirna_da[mirna, ]
  mrna_exp <- mrna_da[gene, ]

  hmcols <- rev(gplots::redgreen(100));

  gplots::heatmap.2(mirna_exp, trace="none", col = hmcols, Rowv = FALSE, scale = "row", Colv = "Rowv", margins = c(9, 9), dendrogram = "none")
  gplots::heatmap.2(mrna_exp, trace="none", col = hmcols, Rowv = FALSE, scale = "row", Colv = "Rowv", margins = c(9, 9), dendrogram = "none")

}
AllenTiTaiWang/anamiR documentation built on May 5, 2019, 4:55 a.m.