knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This vignette demonstrates how to construct a simple NG-CHM, export it to a file, and embed it into RMarkdown.
This vignette uses an additional package of demo data, NGCHMDemoData, which can be installed from our R-Universe repository:
install.packages('NGCHMDemoData', repos = c('https://md-anderson-bioinformatics.r-universe.dev', 'https://cloud.r-project.org'))
and loaded into the current environment:
library(NGCHMDemoData)
The sample data includes a matrix of gene expression data, TCGA.BRCA.Expression, containing 3437 genes (rows) and 200 samples (columns) of breast cancer data from The Cancer Genome Atlas (TCGA). IMPORTANT: In order to be used as the basis for an NG-CHM, a matrix should have both rownames and colnames. Here the rownames are genes and the colnames are TCGA sample identifiers:
BRCA Expression Data Matrix:
TCGA.BRCA.ExpressionData[1:4,1:2]
The sample data also includes a vector of TP35 mutation status for the TCGA samples in the matrix. This data will be used to construct a covariate bar in Covariate Bars and Discrete Color Maps. IMPORTANT: In order to be used as the basis for a covariate bar, a vector should have at least one name in common with the colnames of the matrix.
TP53 Mutation Data Vector:
TCGA.BRCA.TP53MutationData[1:2]
Using the data loaded above, the chmNew()
function can be used to create an NG-CHM:
library(NGCHM) hm <- chmNew('tcga-brca', TCGA.BRCA.ExpressionData)
A covariate bar of the TP53 mutation status can be added with:
covariateBar <- chmNewCovariate('TP53 Mutation',TCGA.BRCA.TP53MutationData) hm <- chmAddCovariateBar(hm, 'column', covariateBar)
The NG-CHM can be exported to two different file types:
Both methods use files from the NGCHMSupportFiles package referenced in the Installation page. When loaded, NGCHMSupportFiles sets environment variables pointing to these additional files.
library(NGCHMSupportFiles)
The NG-CHM can be exported as a stand-alone HTML file with the chmExportToHTML()
function.
The first argument is the NG-CHM created above. The second argument is the desired filename.
chmExportToHTML(hm,'tcga-brca.html')
The file 'tcga-brca.html' can be shared with collaborators and opened in a standard web browser.
Alternatively, .ngchm file can be created with the chmExportToFile()
function.
chmExportToFile(hm,'tcga-brca.ngchm')
The file 'tcga-brca.ngchm' can be opened in the NG-CHM Viewer. IMPORTANT: The filename must end with '.ngchm' to open in the NG-CHM Viewer.
The .html file can be embedded into RMarkdown via htmltools::includeHTML()
:
library('htmltools') filePath = paste(getwd(),'/tcga-brca.html',sep='') htmltools::includeHTML(filePath)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.