Skip to content

Instantly share code, notes, and snippets.

@jnpaulson
Created October 22, 2014 18:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jnpaulson/11c9c96ab036377b3e1a to your computer and use it in GitHub Desktop.
metagenomeSeq RMarkdown file to share MRexperiment objects through shinyapps
---
title: "metagenomeSeq"
author: "jpaulson"
date: "October 22, 2014"
output: html_document
runtime: shiny
---
This R Markdown document is made interactive using Shiny and allows you to explore MRexperiment objects.
Replace
```
data = mouseData
```
with your MRexperiment object's name.
```{r, echo=FALSE,warning=FALSE}
suppressMessages(require(metagenomeSeq))
data(mouseData)
data = mouseData
```
# Metadata
## Feature information
```{r,echo=FALSE}
renderDataTable({
fd = fData(data)
Index = 1:nrow(fd)
Rownames = rownames(fd)
fd = cbind(Index,Rownames,fd)
return(fd)
},options = list(iDisplayLength = 10))
```
## Phenotype information
```{r,echo=FALSE}
renderDataTable({
return(pData(data))
},options = list(iDisplayLength = 10))
```
# Plots
## Input for all plots
```{r,echo=FALSE}
inputPanel(
checkboxInput("norm","Normalize data (CSS-Normalization)",value=TRUE),
numericInput("pd","Phenotype column:",1,min=1)
)
```
### Feature Abundance
```{r,echo=FALSE}
inputPanel(
numericInput("featureIndex","Display feature (index):",1,min=1)
)
renderPlot({
mat = MRcounts(data,norm=input$norm,log=input$norm)
pd = factor(pData(data)[,input$pd])
#if(ncol(pd)==0) pd = as.matrix(rep(1,nrow(pd)))
ylabel = ifelse(input$norm,yes=expression(bold("Log"[2]*" Abundance")),no="No. raw reads")
plotFeature(mat,otuIndex = input$featureIndex,ylab=ylabel,main=rownames(mat)[input$featureIndex],
classIndex = list(All_samples=1:ncol(mat)),col=pd,font.lab=2,font.axis=1,sort=FALSE,xaxt="n")
legend("topleft",legend=unique(pd),fill=unique(pd),box.col="NA")
})
```
### Heatmap
```{r,echo=FALSE}
inputPanel(
numericInput("noFeatures","Number of features:",15,min=1,max =200),
radioButtons("heatMethod","Choose features by:",c("Median Absolute Deviation"="mad","Variability"="sd"))
)
renderPlot({
mat = MRcounts(data,norm=input$norm,log=input$norm)
trials = pData(data)[,input$pd]
otusToKeep = which(rowSums(mat) > 0)
otuStats = apply(mat[otusToKeep, ], 1, input$heatMethod)
otuIndices = otusToKeep[order(otuStats, decreasing = TRUE)[1:input$noFeatures]]
my_mat <- mat[otuIndices,]
heatmapColColors=brewer.pal(12,"Set3")[as.integer(factor(trials))];
heatmapCols = colorRampPalette(brewer.pal(9, "RdBu"))(50)
gplots::heatmap.2(my_mat,trace="none",cexRow=.8,cexCol=.8,col = heatmapCols,ColSideColors = heatmapColColors)
legend("left",fill=unique(heatmapColColors),legend=unique(trials))
},height=800)
```
### PCA/PCoA
```{r,echo=FALSE}
inputPanel(
radioButtons("pcaOrMds","PCA or MDS:",c("PCA"="TRUE","MDS"="FALSE"),selected="TRUE"),
radioButtons("useDist","Make use of count distances:",c("False"="FALSE","True"="TRUE"),selected="FALSE"),
conditionalPanel(condition = "input.useDist == 'TRUE'",
selectInput("distance", "Distance:",
choices=c("euclidean","manhattan","canberra","bray",
"kulczynski","jaccard","gower","altGower","morisita",
"horn","raup","binomial","chao","cao"),selected="euclidean")
),
numericInput('dimensionx', 'X-axis dimension:', 1,
min = 1, max = 4),
numericInput('dimensiony', 'Y-axis dimension:', 2,
min = 1, max = 4)
)
renderPlot({
mat = MRcounts(data,norm=input$norm,log=input$norm)
useDist = input$useDist
pd = factor(pData(data)[,input$pd])
plotOrd(mat,n=100,pch=21,bg=pd,usePCA=input$pcaOrMds,
comp=c(input$dimensionx,input$dimensiony),
useDist=useDist,distfun=vegan::vegdist,dist.method=input$distance)
legend("topleft",levels(pd),fill=factor(levels(pd)),box.col="NA")
})
```
### Diversity
```{r,echo=FALSE}
inputPanel(selectInput("diversity","Diversity index:",choices=c("shannon", "simpson", "invsimpson")))
renderPlot({
mat = t(MRcounts(data))
pd = factor(pData(data)[,input$pd])
H = vegan::diversity(mat,index=input$diversity)
boxplot(H~pd,ylab=paste(input$diversity,"diversity index"))
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment