Skip to content

Commit

Permalink
version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tpq authored and cran-robot committed Aug 27, 2016
1 parent 87c5062 commit 16894e1
Show file tree
Hide file tree
Showing 32 changed files with 1,239 additions and 740 deletions.
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: propr
Title: Calculating Proportionality Between Vectors of Compositional
Data
Version: 1.1.0
Version: 2.0.0
URL: http://github.com/tpq/propr
BugReports: http://github.com/tpq/propr/issues
Authors@R: c(
Expand All @@ -16,20 +16,21 @@ Description: The bioinformatic evaluation of gene co-expression often begins wit
analysis, a branch of math dealing specifically with relative data. In a
subsequent publication, Erb and Nicodemus expounded these efforts by elaborating
on another proportionality metric, rho. This package introduces a programmatic
framework for the calculation of feature dependence using proportionality and
other compositional data methods discussed in the cited publications.
framework for the calculation of feature dependence through proportionality, as
discussed in the cited publications.
License: GPL-2
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 5.0.1
Depends: R (>= 3.2.2)
Imports: methods
Imports: methods, Rcpp
Suggests: compositions, dendextend, ggplot2, ggthemes, knitr,
rmarkdown, testthat
NeedsCompilation: no
Packaged: 2016-07-06 00:08:59 UTC; thom
LinkingTo: Rcpp
NeedsCompilation: yes
Packaged: 2016-08-27 10:09:40 UTC; thom
Author: Thomas Quinn [aut, cre],
David Lovell [aut]
Maintainer: Thomas Quinn <contacttomquinn@gmail.com>
Repository: CRAN
Date/Publication: 2016-07-06 09:44:00
Date/Publication: 2016-08-27 14:22:08
54 changes: 29 additions & 25 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
455c771cf8481b26401d90907353a3aa *DESCRIPTION
156ec54e98b9e35ed47a671d223edf1b *NAMESPACE
d42464af95b40021761560662d6f709d *NEWS.md
202017784e399813d15f595fff4440e4 *R/propr-backend.R
a50b04d7046c0b703e4e7098de5f3ddf *R/propr-classes.R
9c4cd2f34759be4bea23c8eed7d7bb7f *R/propr-methods.R
e71cf145895d640e635811964126b17c *R/propr-perb.R
628ec584b94b4b595b5f3b7c9aae07ba *R/propr-phit.R
eb65f255609f369fa209912ea0065afb *README.md
d059c5cfd0ae6d49d3ad206f30e81551 *DESCRIPTION
abca9c6df0bbaa00132e035a2f45cd07 *NAMESPACE
86f9ea9dbd4141deb84cb8b6ea7488bb *NEWS.md
63b6059302761d78cac73c0a061e42af *R/RcppExports.R
9edd9c2a76f3d62afb4c952bc696893d *R/backend.R
879cf2cba4859c162b1ddb23cffdcdd6 *R/classes.R
d8aaf1df117330520b66ce586bd97f1d *R/methods.R
0d32a2a2d574ddf523364de75909dfc6 *R/perb.R
d956e0a6be76b159d703c14b16220e29 *R/phit.R
c2b8cbefab7357aadca5dbe49ca9fda9 *README.md
79086a6786543eda37d50ee59b2d9da5 *build/vignette.rds
7e8b32c5ecd2d10e82aed71f928be93a *inst/doc/propr-vignette.R
d4bfa5c80c697c188330a0c205b86d13 *inst/doc/propr-vignette.Rmd
2cdfc1f722d89face3c159481581484a *inst/doc/propr-vignette.html
3a1924d0443f34ddfc7e8a051dea4b37 *man/perb.Rd
e82dfb7b8d74048aa755b946858288ff *man/phit.Rd
c1f20b8969faf5bbd5a0399e54ab615d *man/propr-class.Rd
d5ccc56298a3b1d5e04968cfc4d8d74e *man/propr.Rd
0fe59d89c9611cf4301cbc8f43cb2fa3 *man/proprALR.Rd
b3c307949b6b75260172ed7ef0997fdd *man/proprCLR.Rd
f3ca7b8b03b6b44ee558ae5c00010048 *man/proprPairs.Rd
2287bdb852156bbe3d98830c561dc115 *man/proprPerb.Rd
18fb6daf85bb1e408a53dde4b679a392 *man/proprPhit.Rd
6082a9b422e214509bfac10bd6f93a2c *man/proprSym.Rd
d2e912419a153a83fb9753300bfd7d9d *man/proprTri.Rd
d3b180f9c085eb5ee6cb51db23dbe723 *man/proprVLR.Rd
76af6a0eefb17a39e9abb65f4f1863fa *inst/doc/propr-vignette.R
ea81a5e66116c32b2af3ffcf8f5a27a2 *inst/doc/propr-vignette.Rmd
d8c966a5849ce485e471c8a1fe8f6969 *inst/doc/propr-vignette.html
79e934eb5df289c87d2c969ef49e9a44 *man/perb.Rd
aa9d8b8c2a05fe4f6e87c03ad2adac25 *man/phit.Rd
6254e24d72b8f3c50cc74ebe23fce600 *man/propr-class.Rd
34f13a665f4c8eaad4053520258bac54 *man/propr.Rd
85ab40d6e380c797d17562532076f126 *man/proprALR.Rd
67b85829d0471a87b07a9c86ec2ac38d *man/proprCLR.Rd
c8e131841455fe7e2a761d5b5581cbe0 *man/proprPairs.Rd
d022f2c881c3bf28115196ba7b0e7e40 *man/proprPerb.Rd
5e20133ee7cf3cbdf2d428ab0b028ced *man/proprPhit.Rd
50d59ee28ccfb5eccda2fe08e26cc1de *man/proprSym.Rd
ae05d59999662a5cda9edd24c95dc2c7 *man/proprTri.Rd
30cf7ef2f3541d1115cdf201024af289 *man/proprVLR.Rd
e034c70dc15e875cd83c36c9844d484d *src/RcppExports.cpp
5dd779e7a1530c9f45ff65109ff87f63 *src/backend.cpp
38a416384180a93d31020bdffb37ccee *tests/testthat.R
247f6465b01f02caa7c8c8ea380b05b3 *tests/testthat/test-Rcpp.R
fc05d9b4d260a59e5ee9868520801bd6 *tests/testthat/test-logratio.R
18bea904004f38c52e8236832c08f21a *tests/testthat/test-perb.R
fb995286047319340ea951b7fb50b49a *tests/testthat/test-phit.R
23378d943d79a9bf3fb14ed100337e57 *tests/testthat/test-vlr.R
d4bfa5c80c697c188330a0c205b86d13 *vignettes/propr-vignette.Rmd
ea81a5e66116c32b2af3ffcf8f5a27a2 *vignettes/propr-vignette.Rmd
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ export(dendrogram)
export(perb)
export(phit)
exportClasses(propr)
exportMethods("$")
exportMethods("[")
exportMethods(image)
exportMethods(plot)
exportMethods(show)
exportMethods(subset)
importFrom(Rcpp,sourceCpp)
importFrom(grDevices,rainbow)
importFrom(methods,new)
importFrom(methods,show)
importFrom(stats,as.dendrogram)
importFrom(stats,as.dist)
importFrom(stats,ecdf)
importFrom(stats,hclust)
importFrom(stats,order.dendrogram)
importFrom(stats,p.adjust)
useDynLib(propr)
35 changes: 34 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
## propr 2.0.0
---------------------
* Modified `phit`, `perb` functions
* Permutation testing removed
* Added `lazyPairs` construct
* Slot @pairs not populated until after `[`
* Modified `propr` Class
* `@pairs` slot now integer vector
* Populated with `indexPairs` function
* Translate with `indexToCoord` function
* `show` method updated for `lazyPairs` construct
* `[` method completely redesigned
* First argument specifies operation
* Second argument specifies reference
* Indexes @matrix based on these
* `subset` method revised but still copy-on-modify
* Resets @pairs when called
* `$` method removed
* Visualization tools revised
* `plot`, `image`, `dendrogram` methods
* Improved performance
* Compatible with new @pairs indexing
* No longer requires column names
* Modified backend code
* Rephrased code for `proprPhit`
* Rephrased code for `proprPerb`
* Rephrased code for `proprVLR`
* All functions translated into C++
* Estimated 80% reduction in RAM overhead
* Estimated 100-fold performance increase
* ALR methods no longer drop dimension
* All have modify-in-place behavior

## propr 1.1.0
---------------------
* New orientation expected for input data
* Updated back-end and vignette accordingly
* Updated backend and vignette accordingly
* Removed redundant transpositions
* Fixed rare subsetting errors
* Tweaked plot methods
Expand Down
39 changes: 39 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

covRcpp <- function(X, norm_type = 0L) {
.Call('propr_covRcpp', PACKAGE = 'propr', X, norm_type)
}

vlrRcpp <- function(X) {
.Call('propr_vlrRcpp', PACKAGE = 'propr', X)
}

clrRcpp <- function(X) {
.Call('propr_clrRcpp', PACKAGE = 'propr', X)
}

alrRcpp <- function(X, ivar = 0L) {
.Call('propr_alrRcpp', PACKAGE = 'propr', X, ivar)
}

symRcpp <- function(X) {
.Call('propr_symRcpp', PACKAGE = 'propr', X)
}

phiRcpp <- function(X, sym = 1L) {
.Call('propr_phiRcpp', PACKAGE = 'propr', X, sym)
}

rhoRcpp <- function(X, ivar = 0L) {
.Call('propr_rhoRcpp', PACKAGE = 'propr', X, ivar)
}

indexPairs <- function(X, op = "==", ref = 0) {
.Call('propr_indexPairs', PACKAGE = 'propr', X, op, ref)
}

indexToCoord <- function(V, N) {
.Call('propr_indexToCoord', PACKAGE = 'propr', V, N)
}

71 changes: 38 additions & 33 deletions R/propr-backend.R → R/backend.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ proprPhit <- function(counts, symmetrize = TRUE){
# Replace zeroes with next smallest number
counts[counts == 0] <- unique(sort(as.matrix(counts)))[2]

# Calculate the variance of the log-ratio ("variation array")
counts.vlr <- proprVLR(counts)
colnames(counts.vlr) <- colnames(counts)
rownames(counts.vlr) <- colnames(counts)
# Calculate the variance of the log-ratio (i.e., "variation array")
mat <- proprVLR(counts)
colnames(mat) <- colnames(counts)
rownames(mat) <- colnames(counts)

# Calculate feature variance across clr transformed treatments
# Perform clr-transformation of "count matrix"
counts.clr <- proprCLR(counts)
counts.clr.var <- apply(counts.clr, 2, stats::var)

# Sweep out feature clr variance from the variation array
phi <- sweep(counts.vlr, 2, counts.clr.var, FUN = "/")
for(i in 1:ncol(mat)){

mat[, i] <- mat[, i] / stats::var(counts.clr[, i])
}

# Symmetrize matrix if symmetrize = TRUE
if(symmetrize) phi <- proprSym(phi)
if(symmetrize) mat <- proprSym(mat)

return(phi)
return(mat)
}

#' Calculate proportionality metric rho (Erb 2016).
Expand All @@ -39,36 +41,34 @@ proprPerb <- function(counts, ivar = 0){
# Replace zeroes with next smallest number
counts[counts == 0] <- unique(sort(as.matrix(counts)))[2]

# Calculate the variance of the log-ratio ("variation array")
counts.vlr <- proprVLR(counts)
colnames(counts.vlr) <- colnames(counts)
rownames(counts.vlr) <- colnames(counts)
# Calculate the variance of the log-ratio (i.e., "variation array")
mat <- proprVLR(counts)
colnames(mat) <- colnames(counts)
rownames(mat) <- colnames(counts)

# Perform *lr-transformation of "count matrix"
if(ivar != 0){

# Calculate feature variance across alr transformed treatments
counts.vlr <- counts.vlr[-ivar, -ivar] # returns one less dimension
counts.alr <- proprALR(counts, ivar = ivar) # returns one less dimension
counts.var <- apply(counts.alr, 2, stats::var)
mat <- mat[-ivar, -ivar] # returns one less dimension
counts.lr <- proprALR(counts, ivar = ivar) # returns one less dimension

}else{

# Calculate feature variance across clr transformed treatments
counts.clr <- proprCLR(counts)
counts.var <- apply(counts.clr, 2, stats::var)
counts.lr <- proprCLR(counts)
}

# Divide variation array by sum of feature variances
for(i in 1:ncol(counts.vlr)){
for(j in 1:nrow(counts.vlr)){
counts.vlr[i, j] <- counts.vlr[i, j] / (counts.var[i] + counts.var[j])
# Sweep out feature *lr variance from the variation array
var.lr <- apply(counts.lr, 2, stats::var)
for(i in 1:ncol(mat)){

for(j in 1:nrow(mat)){

# Calculate: rho = 1 - (var(x - y))/(var(x) + var(y))
mat[i, j] <- 1 - (mat[i, j] / (var.lr[i] + var.lr[j]))
}
}

# Calculate: p = 1 - (var(x - y))/(var(x) + var(y))
rho <- 1 - counts.vlr

return(rho)
return(mat)
}

#' Calculates the variance of the log of the ratios.
Expand All @@ -86,11 +86,16 @@ proprVLR <- function(X, check = FALSE){
if(any(is.na(X))) stop("NA values found")
}

logX <- log(X)
Cov <- stats::var(logX) ## Note the avoidance of compositions::var
D <- ncol(logX)
VarCol <- matrix(rep(diag(Cov), D), ncol = D)
return(-2 * Cov + VarCol + t(VarCol))
X <- log(X)
X <- stats::var(X)
X.diag <- diag(X)

for(col in 1:ncol(X)){

X[, col] <- -2 * X[, col] + X.diag + X.diag[col]
}

return(X)
}

#' Calculates the centered log-ratio transformation.
Expand Down
37 changes: 21 additions & 16 deletions R/propr-classes.R → R/classes.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#' @useDynLib propr
#' @importFrom Rcpp sourceCpp
NULL

#' The propr Package
#'
#' @description
#' Welcome to the \code{propr} package!
#'
#' To learn more about how to calculate metrics of proportionality,
#' see the help file for the method definitions \code{\link{phit}}
#' see the help file for the functions \code{\link{phit}}
#' and \code{\link{perb}}.
#'
#' To learn more about the resultant \code{propr} class object, see
#' the help file for the class definition \code{\link{propr-class}}.
#'
#' To learn more about compositional data analysis, and its relevance
#' to biological count data, see the attached vignette.
#' to biological count data, see the bundled vignette.
#'
#' To learn more about \code{propr} class methods, see below.
#'
Expand All @@ -20,27 +24,28 @@ NULL

#' An S4 class to hold results from proportionality analysis.
#'
#' @slot counts A data.frame. Stores the original "count matrix" input.
#' @slot logratio A data.frame. Stores the log-ratio transformed "count matrix".
#' @slot matrix A matrix. Stores the proportionality matrix calculated by \code{phit} or \code{perb}.
#' @slot pairs A data.frame. Projects the proportionality matrix pairwise.
#' @slot counts A matrix. Stores the original "count matrix" input.
#' @slot logratio A matrix. Stores the log-ratio transformed "count matrix".
#' @slot matrix A matrix. Stores the proportionality matrix calculated by
#' \code{phiRcpp} or \code{rhoRcpp}.
#' @slot pairs A vector. Indexes the proportionality metrics of interest.
#'
#' @seealso \code{\link{propr}}, \code{\link{phit}}, \code{\link{perb}}
#'
#' @examples
#' randomNum <- sample(1:1000, size = 25 * 10, replace = TRUE)
#' counts <- matrix(randomNum, nrow = 25, ncol = 10)
#' prop <- perb(counts, ivar = 0, iter = 0)
#' prop[1:5, ]
#' prop$prop
#' prop[1:5, "prop"]
#' subset(prop, 1:5)
#' set.seed(12345)
#' N <- 100
#' X <- data.frame(a=(1:N), b=(1:N) * rnorm(N, 10, 0.1),
#' c=(N:1), d=(N:1) * rnorm(N, 10, 1.0))
#' rho <- perb(X, ivar = 0)
#' rho[">", .99]
#' subset(rho, 1:2)
#' @export
setClass("propr",
slots = c(
counts = "data.frame",
logratio = "data.frame",
counts = "matrix",
logratio = "matrix",
matrix = "matrix",
pairs = "data.frame"
pairs = "numeric"
)
)

0 comments on commit 16894e1

Please sign in to comment.