While you are at it, please also check my interactive SUMMARIZEplot for abundance tables: http://userweb.eng.gla.ac.uk/umer.ijaz/bioinformatics/summarize_v0.2/summarize.html
You can get the source files from here: http://userweb.eng.gla.ac.uk/umer.ijaz/bioinformatics/summarize_v0.2/
All you then need is summarize.html
and a data.js
file.
You can generate data.js
quite easily by using the following R code if your abundance table is in a csv format
rm(list=ls())
library(vegan)
x<- read.csv("PTS_phylotypes_Nov2013_N1_blast_F_ENVO_samples_labels.csv",header=TRUE,row.names=1)
MDS<-metaMDS(x, distance = "bray", k = 2, trymax = 50)
x<-x/rowSums(x)
x<-x[,order(colSums(x),decreasing=TRUE)]
#Extract list of top N Taxa
N<-21
taxa_list<-colnames(x)[1:N]
#remove "__Unknown__" and add it to others
taxa_list<-taxa_list[!grepl("__Unknown__",taxa_list)]
N<-length(taxa_list)
new_x<-data.frame(x[,colnames(x) %in% taxa_list],Others=rowSums(x[,!colnames(x) %in% taxa_list]))
names<-gsub("\\.","_",gsub(" ","_",colnames(new_x)))
sink("data.js")
cat("var freqData=[\n")
for (i in (1:dim(new_x)[1])){
cat(paste("{Samples:\'",rownames(new_x)[i],"\',",sep=""))
cat(paste("freq:{",paste(paste(names,":",new_x[i,],sep=""),collapse=","),"},",sep=""))
cat(paste("MDS:{",paste(paste(colnames(MDS$points),MDS$points[rownames(new_x)[i],],sep=":"),collapse=","),"}}\n",sep=""))
if(i!=dim(new_x)[1]){cat(",")}
}
cat("];")
sink()
I still have to update the D3 code by incorporating legends for different sample types though.
There is also a D3 interactive webpage for plotting collapsible trees in Newick format (Instructions and source code given on the page itself with tree shown in the bottom):
http://userweb.eng.gla.ac.uk/umer.ijaz/bioinformatics/PHYLObar_v0.1/PHYLObar.html
Best Wishes,
Umer
Sorry guys, just bear with this structure for a while. As soon as I get some time free, I'll annotate and update the page. Many thanks for your feedback!
Much appreciated!
No worries, it was just a suggestion. Thanks again for sharing and for all effort it must have took to put this together. I've got it bookmarked!
This is really nice but it would be more useful if you put the code on github so people could contribute and provide feedback. Or, create an R package to provide these functions. Copy and pasting code from a webpage is not the best way to share code. Also, the function links make the code harder to read, for me at least. Thanks for sharing.
Was this done using
knitr
? Maybe you can then shareRmd
too :-)?Hi Umer,
Thank you very much for your sharing, I am learning from your code. I am trying to run your code again and everything seem to be work, but it does not show any chart as the attached pictures. Could you please tell me what's happen?. I am not good at bioinformatic, so I am sorry if that is a silly question.
Thank you very much
Cheers
Thanh