Skip to content

Commit

Permalink
add FROGS Phyloseq Manova
Browse files Browse the repository at this point in the history
  • Loading branch information
mariabernard committed Jun 21, 2017
1 parent e2a0154 commit e4aeb4a
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 65 deletions.
2 changes: 2 additions & 0 deletions RELEASES_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* FROGS Phyloseq Alpha Diversity with richness plot
* FROGS Phyloseq Beta Diversity distance matrix
* FROGS Phyloseq Structure
* FROGS Phyloseq Clustering
* FROGS Phyloseq Manova

### Bugs fixes:
* Preprocess : min overlap at least equal to 1
Expand Down
1 change: 1 addition & 0 deletions app/r_manova.Rmd
1 change: 1 addition & 0 deletions app/r_manova.py
1 change: 1 addition & 0 deletions app/r_manova.xml
Binary file added img/phyloseq_manova.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 0 additions & 65 deletions tools/phylo_clustering/data/Bray_Curtis.tsv

This file was deleted.

65 changes: 65 additions & 0 deletions tools/phylo_manova/data/Unifrac.tsv

Large diffs are not rendered by default.

Binary file added tools/phylo_manova/data/data.Rdata
Binary file not shown.
136 changes: 136 additions & 0 deletions tools/phylo_manova/r_manova.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
output: html_document
params:
data:
value: x
varExp:
value: x
method:
value: x
---
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
code.r{ /* Code block */
font-size: 11px;
}
pre{ /* Code block */
font-size: 11px
}
.button {
background-color: #2a7ecc; /* Blue */
border : none;
color : white;
padding: 5px 10px;
text-align: center;
text-decoration: none;
display : inline-block;
font-size: 12px;
margin : 4px 2px;
cursor : pointer;
border-radius: 8px;
}
h4 {
display : block;
font-size : 1em;
margin-top: 1.33em;
margin-bottom: 1.33em;
margin-left : 0;
margin-right: 0;
font-weight : bold;
color : #2a7ecc;
}
</style>

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/FileSaver.js"></script>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<h3>FROGS Phyloseq: Multivariate Analysis of Variance</h3>

Phyloseq `r packageVersion("phyloseq")`

```{r include=FALSE, echo=FALSE}
library(phyloseq)
library(vegan)
load(params$data)
##get dist object from distance matrix file
setwd(dirname(params$method))
A <- read.table(file=basename(params$method), row.names=1)
dist.a <- as.dist(A)
metadata <- as(sample_data(data), "data.frame") ## convert sample_data to data.frame
```

#{.tabset .tabset-fade .tabset-pills}
##Multivariate ANOVA performed with adonis
```{r, echo=FALSE, cach=FALSE, comment=NA}
adonis <- paste('adonis(dist.a ~ ', params$varExp, ', data = metadata, perm = 9999)')
eval(parse(text = adonis))
```

##Canonical Analysis of Principal Coordinates through capscale
```{r, echo=FALSE, cach=FALSE, comment=NA, warning=FALSE}
capcap <- paste('cap <- capscale(dist.a ~ ', params$varExp, ', data = metadata)')
eval(parse(text = capcap))
cap
anova(cap, permutations = 999)
```

##R code
<h4>Loading packages & data</h4>
```{r, eval=FALSE}
library(vegan)
## if in new session
# library(phyloseq)
#
## load phyloseq object
# data <- path to Rdata file
# load(data)
# extract sample metadata in a dataframe
metadata <- as(sample_data(data), "data.frame")
## load beta distance matrix
method <- # path to Beta diversity tsv file
A <- read.table(file=method, row.names=1)
beta_dist <- as.dist(A)
```
<h4>With adonis</h4>
```{r, comment=NA, cache=FALSE, echo=FALSE}
cat(paste(sep="","## change experiment variable (currently ", params$varExp, " )if you wish\n","## Multivariate ANOVA performed with adonis",'\nadonis(beta_dist ~ ', params$varExp, ', data = metadata, perm = 9999)'))
```

<h4>Through capscale</h4>
```{r, comment=NA, cache=FALSE, echo=FALSE}
cat(paste(sep="","## change experiment variable (currently ", params$varExp, " ) if you wish\n", "## Canonical Analysis of Principal Coordinates through capscale",'\ncap <- capscale(beta_dist ~ ', params$varExp, ', data = metadata)'), "\nanova(cap, permutations = 999)")
```

<div id="code-r-file" style="display:none;">
library(vegan)
&#10;#if in new session
&#10;#library(phyloseq)
&#10;#data <- path to Rdata file
&#10;#load(data)
&#10;varExp <- #Experiment variable
&#10;method <- # path to Beta diversity tsv file
&#10;
&#10;A <- read.table(file=basename(method), row.names=1)
&#10;dist.a <- as.dist(A)
&#10;metadata <- as(sample_data(data), \"data.frame\")
&#10;
&#10;capcap <- paste(\'adonis(dist.a ~ \',varExp, \', data = metadata, perm = 9999)\')
&#10;eval(parse(text = capcap))
&#10;
&#10;capcap <- paste(\'cap <- capscale(dist.a ~ \',varExp, \', data = metadata)\')
&#10;eval(parse(text = capcap))
&#10;anova(cap, permutations = 999)
</div>

<script>
function download(){
var text = document.getElementById("code-r-file").textContent;
var blob = new Blob([text],{type:"text/plain;charset=utf-8"});
saveAs(blob,"manova_code.R");
}
</script>
<input type="button" value="Download R code" class="button" onclick="download();"/>
101 changes: 101 additions & 0 deletions tools/phylo_manova/r_manova.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python2.7
#
# Copyright (C) 2017 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Ta Thi Ngan & Maria Bernard INRA - SIGENAE'
__copyright__ = 'Copyright (C) 2017 INRA'
__license__ = 'GNU General Public License'
__version__ = '1.0.0'
__email__ = '[email protected]'
__status__ = 'prod'

import os
import sys
import argparse
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
# PATH
BIN_DIR = os.path.abspath(os.path.join(os.path.dirname(CURRENT_DIR), "libexec"))
os.environ['PATH'] = BIN_DIR + os.pathsep + os.environ['PATH']
# PYTHONPATH
LIB_DIR = os.path.abspath(os.path.join(os.path.dirname(CURRENT_DIR), "lib"))
sys.path.append(LIB_DIR)
if os.getenv('PYTHONPATH') is None: os.environ['PYTHONPATH'] = LIB_DIR
else: os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.pathsep + LIB_DIR

from frogsUtils import *
##################################################################################################################################################
#
# COMMAND LINES
#
##################################################################################################################################################

class Rscript(Cmd):
"""
@summary: Launch Rmarkdown script to Multivariate Analysis of Variance (MANOVA) test with CAP (Canonical Analysis of Principal Coordinates) by adonis.
@see: http://rmarkdown.rstudio.com/
https://joey711.github.io/phyloseq/
@return: the html file containing manova test result.
"""
def __init__(self, html, data, varExp, matrix):
"""
@param html: [str] The path to store resulting html file.
@param data: [str] One phyloseq object in Rdata file, the result of FROGS Phyloseq Import Data.
@param varExp: [str] The experiment variable.
@param matrix: [str] Path of data file containing beta diversity distance matrix. These file is the result of FROGS Phyloseq Beta Diversity.
"""
rmd = os.path.join(CURRENT_DIR, "r_manova.Rmd")
Cmd.__init__( self,
'Rscript',
'Run 1 code Rmarkdown',
'-e "rmarkdown::render('+"'"+rmd+"',output_file='"+html+"', params=list(data='"+data+"', varExp='"+varExp+"',method='"+matrix+"'), intermediates_dir='"+os.path.dirname(html)+"')"+'" 2> /dev/null',
"-e '(sessionInfo()[[1]][13])[[1]][1]; paste(\"Rmarkdown version: \",packageVersion(\"rmarkdown\")) ; library(phyloseq); paste(\"Phyloseq version: \",packageVersion(\"phyloseq\"))'")
def get_version(self):
"""
@summary: Returns the program version number.
@return: [str] Version number if this is possible, otherwise this method return 'unknown'.
"""
return Cmd.get_version(self, 'stdout')

##################################################################################################################################################
#
# MAIN
#
##################################################################################################################################################

if __name__ == "__main__":

# Manage parameters
parser = argparse.ArgumentParser( description='Multivariate Analysis of Variance (MANOVA) test with CAP (Canonical Analysis of Principal Coordinates) by adonis.' )
parser.add_argument('-v', '--varExp', type=str, required=True, default=None, help='The experiment variable you want to analyse.')

# Inputs
group_input = parser.add_argument_group( 'Inputs' )
group_input.add_argument('-d','--data', required=True, default=None, help="The path of RData file containing a phyloseq object-the result of FROGS Phyloseq Import Data" )
group_input.add_argument('-m','--distance-matrix', required=True, default=None, help="The path of data file containing beta diversity distance matrix. These file is the result of FROGS Phyloseq Beta Diversity." )

# output
group_output = parser.add_argument_group( 'Outputs' )
group_output.add_argument('-o','--html', default='manova.html', help="The path to store resulting html file. [Default: %(default)s]" )
group_output.add_argument( '-l', '--log_file', default=sys.stdout, help='This output file will contain several information on executed commands.')

args = parser.parse_args()
prevent_shell_injections(args)
# Process
Logger.static_write(args.log_file, "## Application\nSoftware :" + sys.argv[0] + " (version : " + str(__version__) + ")\nCommand : " + " ".join(sys.argv) + "\n\n")
html=os.path.abspath(args.html)
data=os.path.abspath(args.data)
matrix=os.path.abspath(args.distance_matrix)
Rscript(html, data, args.varExp, matrix).submit( args.log_file )
93 changes: 93 additions & 0 deletions tools/phylo_manova/r_manova.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0"?>
<!--
# Copyright (C) 2017 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<tool name="FROGS Phyloseq Multivariate Analysis Of Variance" id="FROGS_Phyloseq_Multivariate_Analysis_Of_Variance" version="1.0.0">
<description>with Canonical Analysis of Principal Coordinates</description>
<command interpreter="python">r_manova.py
--data $data
--varExp $varExp
--method $method
--html $html
</command>
<inputs>
<!-- Files -->
<param format="rdata" name="data" type="data" label="Phyloseq object (format rdata)" help="This is the result of FROGS Phyloseq Import Data." optional="false">
<validator type="empty_field" message="This parameter is required." />
</param>
<param name="method" format="tabular" type="data" label="The beta diversity distance matrix file" help="These file is the result of FROGS Phyloseq Beta Diversity." optional="false">
<validator type="empty_field" message="This parameter is required." />
</param>
<!-- Parameters -->
<param name="varExp" type="text" label="Experiment variable" help="The experiment variable that you want to analyse." optional="false" value="" size="40">
<validator type="empty_field" message="This parameter is required." />
</param>
</inputs>
<outputs>
<data format="html" name="html" label="${tool.name}: manova.html" from_work_dir="manova.html"/>
</outputs>
<help>

.. image:: ${static_path}/images/tools/frogs/FROGS_logo.png
:height: 144
:width: 110

.. class:: infomark page-header h2

What it does

Using `phyloseq &lt;https://joey711.github.io/phyloseq/&gt;`_ and customized R function for testing Multivariate Analysis of Variance (MANOVA) with CAP (Canonical Analysis of Principal Coordinates) by adonis.

.. class:: infomark page-header h2

Inputs/Outputs

.. class:: h3

Input

**data file** (format RData):
The informations of data in one phyloseq object.
This is the result of FROGS Phyloseq Import Data.

**distance file** (format tabular):
The data file containing beta diversity distance matrix.
These file is the result of FROGS Phyloseq Beta Diversity.

.. class:: h3

Output

**html file** (format `HTML &lt;https://en.wikipedia.org/wiki/HTML&gt;`_): The review of Manova test.

.. image:: ${static_path}/images/tools/frogs/phyloseq_manova.png
:height: 316
:width: 927

.. class:: infomark page-header h2

**Contact**

Contacts: [email protected]

Repository: https://github.com/geraldinepascal/FROGS

Please cite the FROGS Publication: *Escudie F., Auer L., Bernard M., Cauquil L., Vidal K., Maman S., Mariadassou M., Hernadez-Raquet G., Pascal G., 2015. FROGS: Find Rapidly OTU with Galaxy Solution. In: The environmental genomic Conference, Montpellier, France,* http://bioinfo.genotoul.fr/fileadmin/user_upload/FROGS_2015_GE_Montpellier_poster.pdf

Depending on the help provided you can cite us in acknowledgements, references or both.

</help>
</tool>
17 changes: 17 additions & 0 deletions tools/phylo_manova/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
export PATH=../../libexec:$PATH
export PYTHONPATH=../../lib:$PYTHONPATH

if [ -d test ]
then
rm -r test/*
else
mkdir test
fi


python r_manova.py --data data/data.Rdata \
--varExp EnvType \
--distance-matrix data/Unifrac.tsv \
--html test/phylo_manova.html \
-l test/phylo_manova.log

0 comments on commit e4aeb4a

Please sign in to comment.