MAFDash

View examples on github.io

How to get help for MAFDash

Please post all the questions or queries related to MAFDash package on Github Issues. This will help us to build an information repository which can be used by other users.

https://github.com/ashishjain1988/MAFDash/issues

Getting started

Installation from CRAN

install.packages("MAFDash")

Installation from Github

install.packages(c("dplyr","ensurer","ggplot2","tidyr","DT","rmarkdown","knitr","flexdashboard","htmltools","data.table","ggbeeswarm","plotly","circlize","canvasXpress","crosstalk","bsplus","BiocManager","maftools","ComplexHeatmap"))
BiocManager::install(c("TCGAbiolinks"))
install.packages(devtools)
library(devtools)
devtools::install_github("ashishjain1988/MAFDash")

Scope

Mutation Annotation Format (MAF) is a tabular data format used for storing genetic mutation data. For example, The Cancer Genome Atlas (TCGA) project has made MAF files from each project publicly available.

The package – MAFDash – contains a set of R tools to easily create an HTML dashboard to summarize and visualize data from MAF file.

The resulting HTML file serves as a self-contained report that can be used to explore the result. Currently, MAFDash produces mostly static plots powered by maftools, ComplexHeatmap and circlize, as well as interactive visualizations using canvasXpress and plotly. The report is generated with a parameterized R Markdown script that uses flexdashboard to arrange all the information.

This package is a companion to the Shiny app, MAFWiz. Instead of relying on a Shiny server, this dashboard is an attempt to try some of those things using client-side javascript functionality.

Make the dashboard

Mutation Annotation Format (MAF) is a tabular data format used for storing genetic mutation data. For example, The Cancer Genome Atlas (TCGA) project has made MAF files from each project publicly available. The main function of MAFDash (getMAFDashboard) creates an HTML dashboard to summarize and visualize data from MAF files. The resulting HTML file serves as a self-contained report that can be used to explore and share the results. The example below shows how we can create an HTML MAF dashboard file. The first argument of getMAFDashboard can be anything that’s accepted by maftools’s read.maf function (path to a file, or a MAF , data.frame, or data.table object)

library(MAFDash)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
getMAFDashboard(maf, outputFileName="output", outputFileTitle=paste0("MAF Dashboard - Test"),outputFilePath = tempdir())

Example

Here are some example dashboards created using TCGA data: - TCGA-UVM - TCGA-BRCA

Downloading TCGA mutation data in MAF format

MAFDash also provides a wrapper function getMAFdataTCGA around the TCGABiolinks, which returns the mutation data of different cancers in MAF format from TCGA website. See this page for a list of TCGA codes.

library("MAFDash")
# Download MAF data from TCGA
CancerCode <- c("ACC","UVM")
inputFolderPath <- tempdir() ## This folder will be created if it doesn't exist 
maf <- getMAFdataTCGA(cancerCode = CancerCode, outputFolder = inputFolderPath)

#Creating individual plots using the MAF dataset

##Oncoplot The oncoplot shows the number and types of mutations in a set of genes across the samples. The function generateOncoPlot can be used to generate the oncoplot.

library(MAFDash)
library(maftools)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
generateOncoPlot(read.maf(maf,verbose = FALSE))

##Burden Plot The burdenplot compares the total number of mutations between the samples using a dotplot. The figure also have a barplot showing the distribution of different type of mutations across the samples using a barplot.

library(MAFDash)
library(maftools)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
generateBurdenPlot(read.maf(maf,verbose = FALSE), plotType="Dotplot")

generateBurdenPlot(read.maf(maf,verbose = FALSE), plotType="Barplot")

##Mutation Type plot This function generates silent and non-silent mutation plot using the MAF data.

library(MAFDash)
library(maftools)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
generateMutationTypePlot(read.maf(maf,verbose = FALSE))

##TiTv plot This function plot the frequency of Transitions and Transversions of gene mutations

library(MAFDash)
library(maftools)
library(plotly)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
plots<-generateTiTvPlot(read.maf(maf,verbose = FALSE))
plotly::subplot(plotly::subplot(plots$tiTvPatterns,plots$TiTv, nrows = 1, widths = c(0.5, 0.25)),plots$barplot,nrows = 2)

##TCGA Compare plot This function plot the comparison of the mutation load against TCGA cohorts

library(MAFDash)
library(maftools)
maf <- system.file("extdata", "test.mutect2.maf.gz", package = "MAFDash")
maf <- read.maf(maf = maf,verbose = FALSE)
l<-generateTCGAComparePlot(maf = maf, cohortName = "test")
l$tcga_compare_plot

Adding Custom Plots

The getMAFDashboard() function will accept a named list for adding arbitrary objects to the dashboard. Each item in the list will be displayed in separate tabs, and the name of the element will be used as the title of the tab.

Elements of the list can be:

  • A boolean value: indicates whether or not to draw one of the preset plots provided by MAFDasoh
  • A file path: any image format (or PDF)
  • An R plot object: ggplot, plotly, ComplexHeatmap

This functionality can be used with or without providing a MAF file. When MAF data is not provided, the “Variant Table” tab of the dashboard is automatically omitted.

Toy example with iris data

library(ggplot2)
library(plotly)
library(ComplexHeatmap)

data(iris)

## Simple ggplot
myplot <- ggplot(iris) + geom_point(aes(x=Sepal.Length, y=Sepal.Width, color=Species))

## Save as PNG (provide absolute file path)
mycustomimage_png <- file.path(getwd(),"custom_ggplot.png")
ggsave(mycustomimage_png, plot=myplot, width=5, height=4)

## Save as PDF (provide absolute file path)
mycustomimage_pdf <- file.path(getwd(),"custom_ggplot.pdf")
ggsave(mycustomimage_pdf, plot=myplot, width=5, height=4)

## Convert ggplot to plotly
myplotly <- ggplotly(myplot)

## Make heatmap with ComplexHeatmap
hmdata <- t(iris[,1:4])
hmanno <- HeatmapAnnotation(df=data.frame(Species=iris[,5]))
myhm <- Heatmap(hmdata, bottom_annotation = hmanno)

## Customizable plotly from https://github.com/mtandon09/Dynamic_Plotly
source("https://raw.githubusercontent.com/mtandon09/Dynamic_Plotly/master/make_cutomizable_plotly.R")
custom_plotly <- make_customizable_plotly(iris)

## Put together objects/filepaths into a list
toyplotlist <- list("ggplot"= myplot,
                   "plotly"= myplotly,
                   "PNG"= mycustomimage_png,
                   "PDF"= mycustomimage_pdf,
                   "ComplexHeatmap"= myhm,
                   "Customizable"= custom_plotly
)

## Filename to output to
html_filename="toy_dash.html"

## Render dashboard
getMAFDashboard(plotList = toyplotlist,
                outputFileName = html_filename,
                outputFileTitle = "Iris")

Output The output can be seen here.

#Advanced Example

Download TCGA data

MAFDash provides a wrapper function that tries to simplify retrieving data using TCGABiolinks. Valid project codes can be viewed by running TCGABiolinks::getGDCprojects() and checking the “tumor” column.

library(MAFDash)
library(TCGAbiolinks)

tcga_code <- c("ACC","UVM")
#inputFolderPath <- paste0(tempdir()) ## This folder will be created if it doesn't exist 
caller = "mutect2"
title_label = paste0("TCGA-",tcga_code)

maf_files <- getMAFdataTCGA(tcga_code,outputFolder = tempdir(),variant_caller = caller)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================| 100%
## 

[1mindexed
[0m 
[32m2.79kB
[0m in 
[36m 0s
[0m, 
[32m278.82MB/s
[0m
                                                                              

[1mindexed
[0m 
[32m1.00TB
[0m in 
[36m 0s
[0m, 
[32m15.52TB/s
[0m
                                                                              

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================| 100%
## 

[1mindexed
[0m 
[32m2.44kB
[0m in 
[36m 0s
[0m, 
[32m310.63MB/s
[0m
                                                                              

[1mindexed
[0m 
[32m1.00TB
[0m in 
[36m 0s
[0m, 
[32m72.77TB/s
[0m
                                                                              
# tcga_clinical <- getTCGAClinicalAnnotation#TCGAbiolinks::GDCquery_clinic(project = paste0("TCGA-",tcga_code), type = "clinical")
# tcga_clinical$Tumor_Sample_Barcode <- tcga_clinical$submitter_id
defaultW <- getOption("warn")
options(warn = -1)
tcga_clinical<-getTCGAClinicalAnnotation(cancerCodes = tcga_code)
options(warn = defaultW)

Make a customized oncoplot

Filter data

The filterMAF function can be used to filter the MAF data in various ways. Importantly, by default, it will remove commonly occurring mutations that are often considered to be false position ( FLAG genes )

filtered_mafdata <- do.call("rbind",lapply(maf_files, function(maf_file){filterMAF(maf_file)}))

Add clinical data

The easiest way to add clinical annotations to the oncoplot is to add clinical data to the clinical.data slot of a MAF object before passing it to the generateOncoplot() function.

MAFDash also provides a function that defines reasonable colors for some common clinical annotations provided with TCGA datasets.

filtered_maf <- read.maf(filtered_mafdata, clinicalData = tcga_clinical$annodata,verbose = FALSE)
annotation_colors <- getTCGAClinicalColors(ageRange = range(tcga_clinical$annodata$age_at_diagnosis, na.rm=T))

Make an annotated oncoplot

The add_clinical_annotations argument can be:

  • A boolean indicating whether or not to add annotations built from the clinical.data slot of the MAF object. Columns with all missing values are ignored. Maximum number of annotations plotted is 10 (first 10 non-empty columns of clinical.data)
  • A character vector of column names provided as clinical data
custom_onco <- generateOncoPlot(filtered_maf, 
                                add_clinical_annotations = names(annotation_colors), 
                                clin_data_colors = annotation_colors)
custom_onco

Make some other figures

TCGA Comparison

A lot of maftools’s plots are base graphics, so they’re drawn to a device and not returned. But we can simply save them to a file and provide the file path.

tcgaComparePlot<-generateTCGAComparePlot(maf = filtered_maf, cohortName = "test")
tcgaComparePlot$tcga_compare_plot

Chord Diagram of mutation co-occurrence

This function is built on top of maftools’s somaticInteractions() function. It’s just a different way of visualizing co-occurence or mutual exclusivity between genes.

#ribbonplot_file <- file.path(getwd(),"ribbon.pdf")
generateRibbonPlot(filtered_maf,save_name = NULL)

###Plot similarity to COSMIC signatures The function generateCOSMICMutSigSimHeatmap computes the cosine similarity of each individual signature against each COSMIC signature. The COSMIC signatures are also annotated using the etiologies behind the mutational signatures that were identified by analyzing thousands of whole-genome sequencing samples from TCGA. A crawler script was used to scrape the etiologies in the “Acceptance criteria” section of each signature page from COSMIC database v3.2.

library(MAFDash)
library(maftools)
library(ComplexHeatmap)
val<-generateCOSMICMutSigSimHeatmap(filtered_maf)
## -Extracting 5' and 3' adjacent bases
## -Extracting +/- 20bp around mutated bases for background C>T estimation
## -Estimating APOBEC enrichment scores
## --Performing one-way Fisher's test for APOBEC enrichment
## ---APOBEC related mutations are enriched in  17.059 % of samples (APOBEC enrichment score > 2 ;  29  of  170  samples)
## -Creating mutation matrix
## --matrix of dimension 172x96
draw(val)

Render the dashboard

customplotlist <- list("summary_plot"=T,
                       "burden"=T,
                       "TCGA_Comparison"=tcgaComparePlot$tcga_compare_plot,
                       "oncoplot"=T,
                       "Annotated Oncoplot"=custom_onco
                       )

## Filename to output to; if output directory doesn't exist, it will be created
html_filename=file.path(paste0(tempdir(),"/TCGA-UVM.custom.mafdash.html"))

## Render dashboard
getMAFDashboard(MAFfilePath = filtered_maf,
                plotList = customplotlist,
                outputFileName = html_filename, 
                outputFileTitle = "Customized Dashboard")

Output

The output can be seen here.