changeset 1:52f009b255a1 draft default tip

Updated tool
author simon-gladman
date Thu, 22 Nov 2018 07:07:27 -0500
parents ae9cd53b7760
children
files README.md README.txt phyloseq_ordinate_plot.R phyloseq_ordinate_plot.xml test-data/biom_out.html test-data/test.html
diffstat 6 files changed, 182 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- /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.
--- 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.
--- 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('<html><body>',
-                    '<table align="center>',
+                    '<table align="center">',
                     '<tr>',
                     '<td valign="middle" style="vertical-align:middle;">',
-                        '<a href="pdffile.pdf"><img src="nmds.png"/></a>',
+                        '<a href="pdffile.pdf"><img src="nmds.png" width="800" height="800"/></a>',
                     '</td>',
                     '</tr>',
                     '<tr>',
                     '<td valign="middle" style="vertical-align:middle;">',
-                    '<a href="pdffile.pdf"><img src="nmds_facet.png"/></a>',
+                    '<a href="pdffile.pdf"><img src="nmds_facet.png" width="800" height="800"/></a>',
                     '</td>',
                     '</tr>',
                     '</table>',
@@ -174,10 +175,10 @@
 create_HTML_2<-function(htmlfile){
     htmlfile_handle <- file(htmlfile)
     html_output = c('<html><body>',
-                    '<table align="center>',
+                    '<table align="center">',
                     '<tr>',
                     '<td valign="middle" style="vertical-align:middle;">',
-                        '<a href="pdffile.pdf"><img src="nmds.png"/></a>',
+                        '<a href="pdffile.pdf"><img src="nmds.png" width="800" height="800"/></a>',
                     '</td>',
                     '</tr>',
                     '</table>',
@@ -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]
--- 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 @@
             </param>
             <when value="set_biom">
                 <param format="biom1" name="input" type="data" label="Input File"/>
-                <param name="subsetColumn" type="select" label="Select variable for ordination">
+                <param name="subsetColumn" type="select" label="Classify plot by">
                     <options>
                         <filter type="data_meta" ref="input" key="table_column_metadata_headers" />
                     </options>
@@ -47,7 +53,7 @@
                 <param format="tabular" name="OTU_TABLE" type="data" label="OTU table"/>
                 <param format="tabular" name="TAX_TABLE" type="data" label="Taxonomy table"/>
                 <param format="tabular" name="META_TABLE" type="data" label="Metadata table"/>
-                <param name="category" type="data_column" data_ref="META_TABLE" use_header_names="True" label="Select variable for ordination"/>
+                <param name="category" type="data_column" data_ref="META_TABLE" use_header_names="True" label="Classify plot by"/>
             </when>
         </conditional>
         <param name="ord_method" type="select" display="radio" label="Select Ordination method">
@@ -66,7 +72,7 @@
             <option value="unifrac">unifrac (unweighted UniFrac distance)</option>
             <option value="wunifrac">wunifrac (weighted-UniFrac distance)</option>
         </param>
-        <param name="kingdom_field" type="select" display="radio" label="Select a taxonomic rank for the analysis">
+<!--    <param name="kingdom_field" type="select" display="radio" label="Select a taxonomic rank for the analysis">
             <option value="Kingdom">Kingdom</option>
             <option value="Phylum" selected="true">Phylum</option>
             <option value="Class">Class</option>
@@ -75,14 +81,53 @@
             <option value="Genus">Genus</option>
             <option value="Species">Species</option>
         </param>
-        <param name="plot_type" type="select" label="Type of Plot" help="Ordination plot type (Plot OTUs, Plot SAMPLE, Biplot graphic, Split plot graphic)">
-            <option value="1">OTU</option>
-            <option value="2" selected="true">SAMPLE</option>
-            <option value="3">BIPLOT</option>
-            <option value="4">SPLIT PLOT</option>
-        </param>
+ -->
+        <conditional name="plot_selection">
+            <param name="plot_type" type="select" label="Type of Plot" help="Ordination plot type (Plot OTUs, Plot SAMPLE, Biplot graphic, Split plot graphic)">
+                <option value="1">OTU</option>
+                <option value="2" selected="true">SAMPLE</option>
+                <option value="3">BIPLOT</option>
+                <option value="4">SPLIT PLOT</option>
+            </param>
+            <when value="1">
+                <param name="kingdom_field" type="select" display="radio" label="Select a taxonomic rank for the analysis">
+                    <option value="Kingdom">Kingdom</option>
+                    <option value="Phylum" selected="true">Phylum</option>
+                    <option value="Class">Class</option>
+                    <option value="Order">Order</option>
+                    <option value="Family">Family</option>
+                    <option value="Genus">Genus</option>
+                    <option value="Species">Species</option>
+                </param>
+            </when>
+            <when value="2">
+            </when>
+            <when value="3">
+                <param name="kingdom_field" type="select" display="radio" label="Select a taxonomic rank for the analysis">
+                    <option value="Kingdom">Kingdom</option>
+                    <option value="Phylum" selected="true">Phylum</option>
+                    <option value="Class">Class</option>
+                    <option value="Order">Order</option>
+                    <option value="Family">Family</option>
+                    <option value="Genus">Genus</option>
+                    <option value="Species">Species</option>
+                </param>
+            </when>
+            <when value="4">
+                <param name="kingdom_field" type="select" display="radio" label="Select a taxonomic rank for the analysis">
+                    <option value="Kingdom">Kingdom</option>
+                    <option value="Phylum" selected="true">Phylum</option>
+                    <option value="Class">Class</option>
+                    <option value="Order">Order</option>
+                    <option value="Family">Family</option>
+                    <option value="Genus">Genus</option>
+                    <option value="Species">Species</option>
+                </param>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
+        <data format="txt" name="log" label="${tool.name} - stress value - distance matrix - sample column sum"/>
         <data format="html" name="htmlfile" label="${tool.name} - ${ord_method.value_label}_${distance.value_label}.html"/>
     </outputs>
 
@@ -114,21 +159,19 @@
 
     <help>
 **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
 
 -----
--- 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 @@
 <html><body>
-<table align="center>
+<table align="center">
 <tr>
 <td valign="middle" style="vertical-align:middle;">
-<a href="pdffile.pdf"><img src="nmds.png"/></a>
+<a href="pdffile.pdf"><img src="nmds.png" width="800" height="800"/></a>
 </td>
 </tr>
 </table>
--- 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 @@
 <html><body>
-<table align="center>
+<table align="center">
 <tr>
 <td valign="middle" style="vertical-align:middle;">
-<a href="pdffile.pdf"><img src="nmds.png"/></a>
+<a href="pdffile.pdf"><img src="nmds.png" width="800" height="800"/></a>
 </td>
 </tr>
 </table>