#' plotlymut function
#'
#' Draws plotly plot of mutations
#'
#' @param pat2 data frame generated by rnasubset function
#' @param mut data frame of mutation matrix
#' @param genemut data frame generated from diffmut function
#' @param gene character(1) gene of interest
#'
#' @import data.table
#' @import ggplot2
#' @import plotly
#'
#' @return interactive oncoprint-like plot for top 20 differentially mutated genes
#'
#' @examples
#' data(skcm)
#' gene <- "SOX10"
#' sox10.pat <- rnasubset(pat, rna, gene, 10)
#' sox10.mut <- diffmut(sox10.pat, mut)
#' plotlymut(sox10.pat, mut, sox10.mut, gene)
#'
#' @export
#'
plotlymut <- function(pat2, mut, genemut, gene) {
setkey(pat2, gene2)
#add n for number of genes to plot, after (pat2, mut, genemut, gene, n)
#gets patients with rnaseq, clinical and mutation data
overlap.high <- intersect(pat2[levels(pat2$gene2)[1], bcr_patient_barcode], colnames(mut))
overlap.low <- intersect(pat2[levels(pat2$gene2)[2], bcr_patient_barcode], colnames(mut))
setkey(mut, Gene)
glist <- c(genemut$Gene[1:20], gene)
glist <- glist[!duplicated(glist)]
#getting mutation table for high group
mut1 <- mut[glist,c("Gene", overlap.high), with=FALSE]
mut1 <- mut1[!(is.na(rowSums(mut1[, colnames(mut1)[-1], with=FALSE])))]
#getting mutation table for low group
mut2 <- mut[glist,c("Gene", overlap.low), with=FALSE]
mut2 <- mut2[!(is.na(rowSums(mut2[, colnames(mut2)[-1], with=FALSE])))]
#gets order of patients
mut1.melt.high <- melt(mut1, variable.name="bcr_patient_barcode", id.vars="Gene")
gg1.high <- dcast.data.table(mut1.melt.high, bcr_patient_barcode ~ Gene)
gene.order.high <- names(sort(apply(gg1.high[,colnames(gg1.high)[-1], with=F], 2, sum), decreasing=T))
setkeyv(gg1.high, gene.order.high)
mut1.melt.high[, gene2 := levels(pat2$gene2)[1]]
mut1.melt.low <- melt(mut2, variable.name="bcr_patient_barcode", id.vars="Gene")
gg1.low <- dcast.data.table(mut1.melt.low, bcr_patient_barcode ~ Gene)
gene.order.low <- names(sort(apply(gg1.low[,colnames(gg1.low)[-1], with=F], 2, sum), decreasing=T))
setkeyv(gg1.low, gene.order.low)
mut1.melt.low[, gene2 := levels(pat2$gene2)[2]]
#combine mutation groups order patients according to sorting from individual dcasts
mut1.melt <- rbind(mut1.melt.high, mut1.melt.low)
mut1.melt$bcr_patient_barcode <- factor(mut1.melt$bcr_patient_barcode,
levels = c(as.character(rev(gg1.high$bcr_patient_barcode)),
as.character(rev(gg1.low$bcr_patient_barcode))))
mut1.melt$Gene <- factor(mut1.melt$Gene, levels = rev(gene.order.high))
gg3 <- ggplot(mut1.melt, aes(x = bcr_patient_barcode, y = Gene, fill = as.factor(value))) +
geom_tile(colour = "white") +
labs(x = "Patient", y = "Gene") +
theme(title = element_text(size = 16),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
legend.text = element_text(size = 12)) +
scale_fill_brewer(type = "qual",
name = "Legend",
palette = 6,
labels = c("Wild-type", "Mutated")) +
ggtitle(paste(gene)) +
facet_grid(. ~ gene2, scales = "free", space = "free")
gg3
#ggplotly(gg3)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.