Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sw1 authored and cran-robot committed Dec 20, 2017
0 parents commit 8c64857
Show file tree
Hide file tree
Showing 51 changed files with 2,298 additions and 0 deletions.
35 changes: 35 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,35 @@
Package: theseus
Type: Package
Title: Analysis and Visualization Tools for Microbial Community Data
Version: 0.1.0
Authors@R: c(
person("Jacob", "Price", email = "jrp355@drexel.edu", role = c("aut")),
person("Stephen", "Woloszynek", email = "sw424@drexel.edu", role = c("cre","aut"))
)
Description: An approach to the visualization, analysis, and interpretation of
(microbial) community composition data, especially those originating from
amplicon sequencing. Analysis techniques include constrained and unconstrained
ordination and visualizing taxonomic abundances and spatial patterns, among
others. Methods intended to assist bioinformaticians and ecologists in
selecting read trimming by quality scores and preprocessing/denoising of
datasets are also provided.
License: MIT + file LICENSE
URL: http://github.com/EESI/theseus
BugReports: http://github.com/EESI/theseus/issues
Encoding: UTF-8
LazyData: TRUE
Depends: R (>= 3.3.0)
Imports: dplyr, ggplot2 (>= 2.2.1), gridExtra, magrittr (>= 1.5),
parallel (>= 3.4.1), phyloseq (>= 1.20.0), ShortRead (>=
1.34.0), splancs, tidyverse (>= 1.1.1), tidyr, vegan (>=
2.3.5), viridis (>= 0.4.0)
Suggests: covr, knitr, rmarkdown, testthat
VignetteBuilder: knitr
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2017-12-20 14:50:53 UTC; sw1
Author: Jacob Price [aut],
Stephen Woloszynek [cre, aut]
Maintainer: Stephen Woloszynek <sw424@drexel.edu>
Repository: CRAN
Date/Publication: 2017-12-20 16:30:53 UTC
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2017
COPYRIGHT HOLDER: Jacob R. Price
50 changes: 50 additions & 0 deletions MD5
@@ -0,0 +1,50 @@
59d3a39288ceb8f0fe5dd52ae995b991 *DESCRIPTION
2c2363b99fe377f5f12d0facb102d9a1 *LICENSE
059bde17125ec613230f3a95977149b3 *NAMESPACE
dcbd9db04464280430451e1a335ee87a *NEWS.md
4dc3288130c6430b7c7d6cfa28f55f5d *R/cohort_relabund.R
2dd5ac84ff08809c1e2ecae3326c4864 *R/constord.R
384e3e8125444284ea8be7ce13fe774a *R/data_WWTP_Impact.R
831076f68f2c61a8982ee6cc4d7243a0 *R/data_seqtab.2vs3.R
cdff655314a9907bbdf2df69be6dd544 *R/data_seqtab.R
562eb616187c3f57375243f05e1c0164 *R/envtoverlay.R
165f199fbf2be26c1a4a31de85c1b75f *R/misc.R
eb37a34591b06316d60637c3da5df788 *R/prev.R
f4b666deb166165658915f89c0d732b6 *R/pstoveg_otu.R
de8a1b4705fd19b52dcf13dbff2193aa *R/pstoveg_sample.R
64188d7b2b6bd858219516345a5cd8e2 *R/pstoveg_sd.R
1d1c05e8b8a5cc89e5d05e1bfac6ab15 *R/qualcontour.R
529ef7af731485e8c8e65f99e2725d90 *R/utils.R
2628fa47d7d9f912c46ed4f79913bcc3 *README.md
00b39ee1382469cd71c77abace310140 *build/vignette.rds
46009cefc529bb6afbe1999556a04f56 *data/WWTP_Impact.RData
84ebf41ff653529cd2789e881853736c *data/sigtab.2vs3.RData
91e2e5c1c22a91e8816493f87da114b9 *data/sigtab.RData
00aaad90eb2ceb966aff6873b999d51f *inst/CITATION
e4f10a71145707d13b62ea38621f905b *inst/doc/general_usage.R
99c285aa3354c367077ea07c16f118e0 *inst/doc/general_usage.Rmd
1c6cbd42950ae779b94616767a39dd34 *inst/doc/general_usage.html
4ce15504a6287a760e5522e4715df85f *inst/testdata/sample1_R1.fastq.gz
7957b1564084964551ea64d86a108406 *inst/testdata/sample1_R2.fastq.gz
0f5d5c73d2f0dba0dfb77ef289339813 *inst/testdata/sample2_R1.fastq.gz
92ff41e67c790e3f7f83d852a400f5d7 *inst/testdata/sample2_R2.fastq.gz
a18d75d4e199b6f1db9479fa4075d005 *man/WWTP_Impact.Rd
9e8ea1081830c57f6d08de5b70b66d18 *man/cohort_relabund.Rd
afb157d72b93887a17d5fe4bb351e59e *man/constord.Rd
5434a1b83f6dba6ffeb8b6c8ad7b4c9b *man/envtoverlay.Rd
b553be0c9adc706380507835afff3c35 *man/prev.Rd
65161921a3d904cad105798a4576ce76 *man/pstoveg_otu.Rd
601b6e6c6dc267108d0f4a3e07ed9c80 *man/pstoveg_sample.Rd
599a43291ca24f9b86836e65014da5e9 *man/pstoveg_sd.Rd
3f621de6d164eb97fc6532811dbfeec1 *man/qualcontour.Rd
01dc6ddd7c976a13d72a587f3938f483 *man/reexports.Rd
e2761cadc94f71a915d9a9576c05bbcf *man/sigtab.2vs3.Rd
d7c077a6ee9a778a5c254940e68a05bb *man/sigtab.Rd
d970962f446e6b4b66c98511ba071afe *tests/testthat.R
1052aea0f05b2dd6003f165039ce704a *tests/testthat/test-helpers.R
99c285aa3354c367077ea07c16f118e0 *vignettes/general_usage.Rmd
b5f516aa7bf9c9647a03dddfb40d9f59 *vignettes/p.co.png
788aa3636cea9d859848c1f75118c7de *vignettes/p.cra.png
6b9eac634279acf6f0ae2ad9eaafba8c *vignettes/p.eo.png
aeda3287e002a57877bf07b0b50e919e *vignettes/p.prev.png
91768f498ae6724a6ca7675d08db386c *vignettes/p.qc.png
24 changes: 24 additions & 0 deletions NAMESPACE
@@ -0,0 +1,24 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export("otu_table<-")
export("sample_data<-")
export("tax_table<-")
export(cohort_relabund)
export(constord)
export(envtoverlay)
export(prev)
export(pstoveg_otu)
export(pstoveg_sample)
export(pstoveg_sd)
export(qualcontour)
import(ggplot2)
importFrom(magrittr,"%>%")
importFrom(phyloseq,"otu_table<-")
importFrom(phyloseq,"sample_data<-")
importFrom(phyloseq,"tax_table<-")
importFrom(phyloseq,otu_table)
importFrom(phyloseq,plot_bar)
importFrom(phyloseq,sample_data)
importFrom(phyloseq,tax_table)
importFrom(phyloseq,transform_sample_counts)
3 changes: 3 additions & 0 deletions NEWS.md
@@ -0,0 +1,3 @@
# theseus 0.1.0

* First release.
140 changes: 140 additions & 0 deletions R/cohort_relabund.R
@@ -0,0 +1,140 @@
#' @import ggplot2
#' @importFrom phyloseq transform_sample_counts plot_bar
NULL

#' Creates a relative abundance cohort plot
#'
#' This function plots the relative abundance of taxa within a phyloseq
#' object 'PS' according to thier pre-determined cohort memberships.
#' See Details for more information.
#'
#' @param PS (required) A phyloseq object.
#' @param xvar (required) Variable in sample_data(PS) to be displayed on the
#' x-axis. Defaults to 'SampleID'.
#' @param taxfill Taxonomic level to display in plot. Defaults to 'Phylum'.
#' @param comp1 (required) First comparison (hence 'comp1') object of
#' 'DESeqResults' class, or a dataframe with similar structure. In the case
#' that a 'DESeqResults' class object is not being used, the object must
#' contain a 'log2FoldChange' vector/column. Row names must be a subset (but
#' not necessarily a proper subset) of taxa_names(PS). See Details for more
#' information.
#' @param comp2 (required) Second comparison (hence 'comp2') object. Refer to
#' documentation for 'comp1' for remaining details.
#' @param comp1lab Labels for comparison 1. Defaults to c('Decreased Comp1',
#' 'No Change Comp1','Increased Comp1').
#' @param comp2lab Labels for comparison 2. Defaults to c('Decreased Comp2',
#' 'No Change Comp2','Increased Comp2').
#' @param justdata Return only the data table (no plot). Defaults to FALSE.
#' @param PSisRelAbund Does the PS object contain compositional (relative
#' abundance) taxa counts? Defaults to FALSE.
#'
#' @details
#' \subsection{General}{
#' The results from a single pairwise comparison, such as pre- and
#' post-treatment, carried out with the DESeq2 package can be plotted or read
#' and interpreted in tabular form with relative ease. When two pairwise
#' comparisons are being performed, interpreting the results becomes more
#' difficult. This function is intended to assist with interpreting the
#' results from multiple differential abundance analyses carried out with the
#' DESeq2 r-package. This function takes a phyloseq object ('PS') and two
#' 'DESeqResults' objects ('comp1', 'comp2') and plots the relative abundance
#' of taxa within 'PS', partitioning the taxa according to their membership
#' to one the 9 possible cohort combinations determined by their values
#' specified within 'comp1' and 'comp2'.
#' }
#' \subsection{Approach}{
#' The \code{\link[DESeq2]{DESeq}} function carries out differential abundance
#' testing and produces a 'DESeqDataSet' object. The
#' \code{\link[DESeq2]{results}} function can be used to access the results and
#' create a 'DESeqResults' object, which is a subclass of DataFrame. Note that
#' the 'alpha' parameter for \code{\link[DESeq2]{results}} can be used to
#' specify the significance level of the test being performed. NOTE: Testing
#' with DESeq2 must be carried out, and the non-significant taxa should be
#' removed from the 'comp1' and 'comp2' objects before using this function.
#' Using the log2FoldChange columns in 'comp1' and 'comp2' this function
#' identifies which taxa decrease, do not change, or increase over course of
#' both comparisons. Because there are three options for both comparisons
#' there are 3^2=9 possible combinations, or cohorts, which an OTU may fall
#' into. These cohort assignments are used when plotting the relative abundance
#' plot.
#' }
#'
#'
#' @return A ggplot object.
#'
#' @seealso \code{\link[phyloseq]{plot_bar}}
#' \code{\link[phyloseq]{transform_sample_counts}}
#' \code{\link[DESeq2]{DESeq}} \code{\link[DESeq2]{results}}
#' \code{\link[DESeq2]{DESeqDataSet}}
#'
#' @examples
#' \dontrun{
#' cohort_relabund(
#' PS=prune_samples(sample_data(WWTP_Impact)$site %in% c(1,2,3,4),
#' WWTP_Impact),
#' comp1=sigtab,
#' comp2=sigtab.2vs3,
#' comp1lab=c('Decreased at Effluent',
#' 'No change at Effluent',
#' 'Increased at effluent'),
#' comp2lab=c('Decreased btwn plants',
#' 'No change btwn plants',
#' 'Increased btwn plants'))
#' }
#'
#' @export

cohort_relabund <- function(PS,xvar='SampleID',taxfill='Phylum',comp1,comp2,comp1lab=c('Decreased Comp1','No Change Comp1','Increased Comp1'),comp2lab=c('Decreased Comp2','No Change Comp2','Increased Comp2'), justdata=FALSE, PSisRelAbund=FALSE){

ls.comp1.up <- rownames(comp1[comp1$log2FoldChange>0,])
ls.comp1.down <- rownames(comp1[comp1$log2FoldChange<0,])

ls.comp2.up <- rownames(comp2[comp2$log2FoldChange>0,])
ls.comp2.down <- rownames(comp2[comp2$log2FoldChange<0,])

if (PSisRelAbund==FALSE){
psra <- transform_sample_counts(PS,function(x) {x / sum(x)})
} else {
psra <- PS
}

bp <- plot_bar(psra, x=xvar, fill=taxfill)
bpdat <- bp$data

#bpdat$comp1 <- comp1lab[2]
#bpdat$comp1[bpdat$OTU %in% ls.comp1.up]
bpdat$comp1cat[bpdat$OTU %in% ls.comp1.down] <- comp1lab[1]
bpdat$comp1cat[!bpdat$OTU %in% c(ls.comp1.down,ls.comp1.up)] <- comp1lab[2]
bpdat$comp1cat[bpdat$OTU %in% ls.comp1.up] <- comp1lab[3]
bpdat$comp1cat <-
factor(bpdat$comp1cat,
levels=c(comp1lab[1], comp1lab[2], comp1lab[3]), ordered=TRUE)


bpdat$comp2cat[bpdat$OTU %in% ls.comp2.down] <- comp2lab[1]
bpdat$comp2cat[!bpdat$OTU %in% c(ls.comp2.down,ls.comp2.up)] <- comp2lab[2]
bpdat$comp2cat[bpdat$OTU %in% ls.comp2.up] <- comp2lab[3]
bpdat$comp2cat <-
factor(bpdat$comp2cat,
levels=c(comp2lab[1], comp2lab[2], comp2lab[3]), ordered=TRUE)

if (justdata==TRUE){
bpdat
} else {

p1 <-
ggplot(bpdat, aes_string(x=xvar, y='Abundance', fill=taxfill)) +
geom_bar(stat='identity', position='stack') +
theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=0)) +
facet_grid(comp2cat~comp1cat) +
theme(legend.position = 'bottom') +
#theme(legend.title=element_blank()) +
theme(axis.title.x=element_blank()) #+
#geom_vline(xintercept=35-5-0.5, linetype='solid', alpha=1.0, size=1.5)
#ylab('Relative Abundance (Phylum)')

p1
}
}


0 comments on commit 8c64857

Please sign in to comment.