# HG changeset patch # User simon-gladman # Date 1542888447 18000 # Node ID 52f009b255a105b91e4b22aa4fb86156903615ef # Parent ae9cd53b7760150ab1e9703721bf5e113916a86b Updated tool diff -r ae9cd53b7760 -r 52f009b255a1 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Nov 22 07:07:27 2018 -0500 @@ -0,0 +1,52 @@ +# Phloseq Ordination Plot + +A Galaxy tool to produce NMDS plots using Phyloseq from either a BIOM1 file or 2 input tables. + +Currently produces the plots embedded in a html file for output with links to a PDF file. + +Requires: + +Phyloseq 1.22.3 +r-getopt 1.20.0 +r-doparallel 1.0.11 +ghostscript 9.18 + + +### Run phyloseq_ordination_plot.R with three input files +Rscript 'phyloseq_ordination_plot.R' --otu_table='GP_OTU_TABLE.txt' --tax_table='GP_TAX_TABLE.txt' --meta_table='GP_SAMPLE_TABLE.txt' --method='bray' --kingdom=2 --cutoff=5 --category=6 --outdir='outputdir' --htmlfile='test.html' + +### Run phyloseq_nmds.R with biom file +Rscript 'phyloseq_ordinate_plot.R' --biom='GP.biom' --subset='Primer' --method='NMDS' --distance='bray' --kingdom='Phylum' --plottype='2' --outdir='outputdir' --htmlfile='biom_out.html' + +## Version history: + +**XML Wrapper:** + +Alpha version by Michael Thang of QFAB, Australia. + +1.22.3.1: Simon Gladman Melbourne Bioinformatics + +* Incorporated tests +* Requirements +* Version statement +* Citations + +1.22.3.2: Michael Thang QFAB, Simon Gladman Melbourne Bioinformatics + +* Uses new version of BIOM1 datatype to get metadata +* Output label changed as per user requirements + + +**R Script: phyloseq_nmds.R** + +0.1.0: Michael Thang QFAB + +* Original version + +0.1.1: Michael Thang QFAB + +* Added extra BIOM import functionality so it doesn't solely rely on phyloseq's internal importer. + +0.1.2: Michael Thang QFAB + +* BIOM functionality now requires the column header name in text. diff -r ae9cd53b7760 -r 52f009b255a1 README.txt --- a/README.txt Wed Sep 05 02:07:22 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -# Phloseq Ordination Plot - -A Galaxy tool to produce NMDS plots using Phyloseq from either a BIOM1 file or 2 input tables. - -Currently produces the plots embedded in a html file for output with links to a PDF file. - -Requires: - -Phyloseq 1.22.3 -r-getopt 1.20.0 -r-doparallel 1.0.11 -ghostscript 9.18 - - -### Run phyloseq_ordination_plot.R with three input files -Rscript 'phyloseq_ordination_plot.R' --otu_table='GP_OTU_TABLE.txt' --tax_table='GP_TAX_TABLE.txt' --meta_table='GP_SAMPLE_TABLE.txt' --method='bray' --kingdom=2 --cutoff=5 --category=6 --outdir='outputdir' --htmlfile='test.html' - -### Run phyloseq_nmds.R with biom file -Rscript 'phyloseq_ordinate_plot.R' --biom='GP.biom' --subset='Primer' --method='NMDS' --distance='bray' --kingdom='Phylum' --plottype='2' --outdir='outputdir' --htmlfile='biom_out.html' - -## Version history: - -**XML Wrapper:** - -Alpha version by Michael Thang of QFAB, Australia. - -1.22.3.1: Simon Gladman Melbourne Bioinformatics - -* Incorporated tests -* Requirements -* Version statement -* Citations - -1.22.3.2: Michael Thang QFAB, Simon Gladman Melbourne Bioinformatics - -* Uses new version of BIOM1 datatype to get metadata -* Output label changed as per user requirements - - -**R Script: phyloseq_nmds.R** - -0.1.0: Michael Thang QFAB - -* Original version - -0.1.1: Michael Thang QFAB - -* Added extra BIOM import functionality so it doesn't solely rely on phyloseq's internal importer. - -0.1.2: Michael Thang QFAB - -* BIOM functionality now requires the column header name in text. diff -r ae9cd53b7760 -r 52f009b255a1 phyloseq_ordinate_plot.R --- a/phyloseq_ordinate_plot.R Wed Sep 05 02:07:22 2018 -0400 +++ b/phyloseq_ordinate_plot.R Thu Nov 22 07:07:27 2018 -0500 @@ -26,6 +26,7 @@ 'kingdom','k',2,'character', 'plottype','e',2,'numeric', 'category','g',2,'numeric', + 'log','l',2,'character', 'outdir','r',2,'character', 'htmlfile','h',2,'character' ),byrow=TRUE,ncol=4); @@ -53,7 +54,7 @@ pngfile_nmds <- gsub("[ ]+", "", paste(options$outdir,"/nmds.png")) pngfile_nmds_facet <- gsub("[ ]+", "", paste(options$outdir,"/nmds_facet.png")) htmlfile <- gsub("[ ]+", "", paste(options$htmlfile)) - +output_summary <- gsub("[ ]+", "", paste(options$log)) ### This function accepts different two different type of BIOM file format readBIOM<-function(inBiom){ @@ -83,21 +84,21 @@ create_OTU_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,kingdom_str,htmlfile,pngfile_nmds,pngfile_nmds_facet){ pdf(pdf_file); - p1<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color="Phylum",title="taxa") + p1<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color=kingdom_str,title="taxa") + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p1) - p2<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color="Phylum",title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) + p2<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color=kingdom_str,title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p2) garbage<-dev.off(); #png('nmds.png') - bitmap(pngfile_nmds,"png16m") - p3<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color="Phylum",title="taxa") + bitmap(pngfile_nmds,"png16m",res=120) + p3<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color=kingdom_str,title="taxa") + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p3) garbage<-dev.off() #png('nmds_facet.png') - bitmap(pngfile_nmds_facet,"png16m") - p4<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color="Phylum",title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) + bitmap(pngfile_nmds_facet,"png16m",res=120) + p4<-plot_ordination(phyloseq_obj,phyloseq_ord,type="taxa",color=kingdom_str,title="taxa") + facet_wrap(formula(paste('~',kingdom_str)),3) + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p4) garbage<-dev.off() @@ -107,14 +108,14 @@ create_SAMPLE_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,htmlfile,pngfile_nmds,category_type){ pdf(pdf_file); p <- plot_ordination(phyloseq_obj, phyloseq_ord, type="samples", color=category_type) - p <- p + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle("samples") + p <- p + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle(paste("Samples - Stress value",formatC(phyloseq_ord$stress,digits=4,format="f"),sep=":")) + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p) garbage<-dev.off(); #png('nmds.png') - bitmap(pngfile_nmds,"png16m") + bitmap(pngfile_nmds,"png16m",res=120) p1 <- plot_ordination(phyloseq_obj, phyloseq_ord, type="samples", color=category_type) - p1 <- p1 + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle("samples") + p1 <- p1 + geom_point(aes(fill=category_type)) + geom_point(size=5) + ggtitle(paste("Samples - Stress value",formatC(phyloseq_ord$stress,digits=4,format="f"),sep=":")) + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p1) garbage<-dev.off(); @@ -124,12 +125,12 @@ create_BIPLOT_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,kingdom_str,htmlfile,pngfile_nmds,category_type){ pdf(pdf_file); print(category_type) - p_biplot <- plot_ordination(phyloseq_obj, phyloseq_ord, type="biplot", color=category_type, shape=kingdom_str,title="BIPLOT") + p_biplot <- plot_ordination(phyloseq_obj, phyloseq_ord, type="biplot", color=category_type, shape=kingdom_str,title="BIPLOT") + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p_biplot) garbage<-dev.off(); - bitmap(pngfile_nmds,"png16m") - p_biplot_png <- plot_ordination(phyloseq_obj, phyloseq_ord, type="biplot", color=category_type, shape=kingdom_str,title="BIPLOT") + bitmap(pngfile_nmds,"png16m",res=120) + p_biplot_png <- plot_ordination(phyloseq_obj, phyloseq_ord, type="biplot", color=category_type, shape=kingdom_str,title="BIPLOT") + theme(legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(p_biplot_png) garbage<-dev.off(); @@ -139,13 +140,13 @@ create_SPLITPLOT_PDF<-function(pdf_file,phyloseq_obj,phyloseq_ord,kingdom_str,htmlfile,pngfile_nmds,category_type){ pdf(pdf_file,width=10, height=6); split_plot <- plot_ordination(phyloseq_obj, phyloseq_ord, type="split", color=kingdom_str, shape=kingdom_str, label=category_type, title="SPLIT PLOT") - split_plot <- split_plot + theme(plot.margin = unit(c(12,18,12,18),"pt")) + split_plot <- split_plot + theme(plot.margin = unit(c(12,18,12,18),"pt"),legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(split_plot) garbage<-dev.off(); - bitmap(pngfile_nmds,"png16m", width=6, height=4, units="in",res=200) + bitmap(pngfile_nmds,"png16m", res=120) split_plot <- plot_ordination(phyloseq_obj, phyloseq_ord, type="split", color=kingdom_str, shape=kingdom_str, label=category_type, title="SPLIT PLOT") - split_plot <- split_plot + theme(plot.margin = unit(c(12,18,12,18),"pt")) + split_plot <- split_plot + theme(plot.margin = unit(c(12,18,12,18),"pt"),legend.position="bottom",legend.box="vertical",legend.direction="horizontal") print(split_plot) garbage<-dev.off(); create_HTML_2(htmlfile) @@ -154,15 +155,15 @@ create_HTML_1<-function(htmlfile){ htmlfile_handle <- file(htmlfile) html_output = c('', - '', '', '', '', '', '', '', '
', - '', + '', '
', - '', + '', '
', @@ -174,10 +175,10 @@ create_HTML_2<-function(htmlfile){ htmlfile_handle <- file(htmlfile) html_output = c('', - '', '', '', '', '
', - '', + '', '
', @@ -233,12 +234,51 @@ ### create a phyloseq object physeq = phyloseq(OTU,TAX,sample_object) } -# sample_data(physeq_filter)$category_input <- factor(category_input) + category_input = get_variable(physeq, category_type) %in% category_option sample_data(physeq)$category_input <- factor(category_input) -# physeq_ord<-ordinate(physeq_filter,method,distance) +# compute distance matrix physeq_ord<-ordinate(physeq,method,distance) + +# get column sum + sum_table<-data.frame(column_sum=as.matrix(colSums(otu_table(physeq)))) + + rowname_table<-data.frame(sample=rownames(sum_table)) + + output_table<-as.data.frame(cbind(rowname_table,sum_table)) + + output_table<-output_table[order(output_table$column_sum),] + +# Reformat distance matrix + distance_matrix<-as.data.frame(physeq_ord$points) + distance_matrix<-cbind(sample=rownames(distance_matrix),distance_matrix) + + sink(output_summary) + cat('--------------------------------------') + cat('\n') + cat('Stress value') + cat('\n') + cat(formatC(physeq_ord$stress,digits=4,format="f")) + cat('\n') + cat('--------------------------------------') + cat('\n') + cat('Sample - Column Sum') + cat('\n') + cat('--------------------------------------') + cat('\n') + write.table(output_table,row.names=F,quote=F) + cat('\n') + cat('--------------------------------------') + cat('\n') + cat('Distance Matrix') + cat('\n') + cat('--------------------------------------') + cat('\n') + write.table(distance_matrix,row.names=F,quote=F) + cat('\n') + cat('--------------------------------------') + sink() if(plottype == 1){ #kingdom_str = colnames(tax_table)[2] diff -r ae9cd53b7760 -r 52f009b255a1 phyloseq_ordinate_plot.xml --- a/phyloseq_ordinate_plot.xml Wed Sep 05 02:07:22 2018 -0400 +++ b/phyloseq_ordinate_plot.xml Thu Nov 22 07:07:27 2018 -0500 @@ -20,10 +20,16 @@ --meta_table='$META_TABLE' --category='$file_source.category' #end if + #if str($plot_selection.plot_type) == "2": + --plottype='$plot_selection.plot_type' + --kingdom='null' + #else: + --plottype='$plot_selection.plot_type' + --kingdom='$plot_selection.kingdom_field' + #end if --method='$ord_method' --distance='$distance' - --kingdom='$kingdom_field' - --plottype='$plot_type' + --log='$log' --outdir="$htmlfile.files_path" --htmlfile='$htmlfile' ]]> @@ -37,7 +43,7 @@ - + @@ -47,7 +53,7 @@ - + @@ -66,7 +72,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -114,21 +159,19 @@ **What it does** -Creates NMDS plot using R package called phyloseq_. +Creates various ordination plot using an R_package_called_phyloseq_,specifically according to the methods outlined in the Phyloseq_Ordination_Plot_Tutorial_. -.. _phyloseq: https://joey711.github.io/phyloseq/plot_ordination-examples.html +.. _R_package_called_phyloseq: https://joey711.github.io/phyloseq/index.html +.. _Phyloseq_Ordination_Plot_Tutorial: https://joey711.github.io/phyloseq/plot_ordination-examples.html ----- **Input** -- **Choose an input file type** - BIOM File or TABULAR file -- **Select variable for ordination** - This column is used to extract unique value from the column of interest for ordination plot -- **OTU TABLE** - this is a OTU matrix -- **Taxonomy TABLE** - this is a TAX matrix -- **Metadata TABLE** - this is a metadata file of the experiment design -- **Select Ordination method** - select ordination method -- **Select Distance method** - select distance method for ordination plot +- **Choose an input file type** - either 1 BIOM File or 3 TABULAR files (OTU, taxonomy and Metadata tables) +- **Classify plot by** - points on the plot will be colour coded according to their value of the selected feature +- **Select Ordination method** - several methods are supported +- **Select Distance method** - several methods are supported - **Select a taxonomic rank for the analysis** - select a taxonomy for ordination plot ----- diff -r ae9cd53b7760 -r 52f009b255a1 test-data/biom_out.html --- a/test-data/biom_out.html Wed Sep 05 02:07:22 2018 -0400 +++ b/test-data/biom_out.html Thu Nov 22 07:07:27 2018 -0500 @@ -1,8 +1,8 @@ -
- +
diff -r ae9cd53b7760 -r 52f009b255a1 test-data/test.html --- a/test-data/test.html Wed Sep 05 02:07:22 2018 -0400 +++ b/test-data/test.html Thu Nov 22 07:07:27 2018 -0500 @@ -1,8 +1,8 @@ -
- +