aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2016-08-02 16:27:11 +1000
committerJustin Bedo <cu@cua0.org>2016-08-02 16:27:11 +1000
commitd483c1112e838440f332efece783b20d980d42af (patch)
tree11238c97928840e84408460ffcc03c668a6195d1
Initial implementation
-rw-r--r--DESCRIPTION9
-rw-r--r--LICENSE13
-rw-r--r--NAMESPACE1
-rw-r--r--R/pmt.R53
-rw-r--r--man/pmt-package.Rd26
-rw-r--r--man/pmt.Rd33
6 files changed, 135 insertions, 0 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..5da1874
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,9 @@
+Package: pmt
+Type: Package
+Title: Poission Margin Test for Normalisation Free Significance Analysis of NGS Data
+Version: 1.0
+Date: 2016-08-02
+Author: Justin Bedo
+Maintainer: Justin Bedo <cu@cua0.org>
+Description: An implementation of the PMT for calling differental counts of NGS data.
+License: ISC
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c462bea
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright © 2016 by Justin Bedő
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..d75f824
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1 @@
+exportPattern("^[[:alpha:]]+")
diff --git a/R/pmt.R b/R/pmt.R
new file mode 100644
index 0000000..090ceca
--- /dev/null
+++ b/R/pmt.R
@@ -0,0 +1,53 @@
+# Copyright © 2016 by Justin Bedő
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+pmt <- function(a, b, two.sided=F) {
+ ce <- function(mu){
+ pt1 <- mapply(function(xa, mu, rho) logsumexp(cumsum(log(((1 + rho) * (xa - (0:xa-1))/(2 * mu))))), a, mu, rho)
+ pt2 <- mapply(function(xb, mu, rho) logsumexp(cumsum(log((2*mu*rho) / ((1 + rho)*(xb + (1:100)))))), b, mu, rho)
+ rho + rho * (exp(pt1) - exp(pt2))
+ }
+
+ logsumexp <- function(x) {
+ x <- sort(x, decreasing=T)
+ log1p(sum(exp(x[-1] - x[1]))) + x[1]
+ }
+
+ Ra <- sum(a)
+ Rb <- sum(b)
+ chi <- a/b
+ rho <- rep(Ra/Rb, length(a))
+
+ msk <- a/Ra > b/Rb
+ rho[msk] <- 1/rho[msk]
+ tmp <- a[msk]
+ a[msk] <- b[msk]
+ b[msk] <- tmp
+ chi[msk] <- 1/chi[msk]
+
+ lb <- (rho - chi + sqrt(((rho - chi)^2 + 4 * chi * rho * (1 + rho)))) / (4 * rho) * b * 0.75
+ ub <- (1 + chi) * (1 + rho) / (2 * rho + 1) * b * 1.25
+
+ while(max(ub - lb) > 1e-6){
+ mu <- (ub + lb) / 2
+ scmu <- ce(mu) >= 0
+ ub <- ub * scmu + mu * (1 - scmu)
+ lb <- lb * (1 - scmu) + mu * scmu
+ }
+
+ t1 <- mapply(function(xa, mu, rho) { i <- 0:xa; logsumexp(i * log(2 * mu) - lfactorial(i) - i * log(1 + rho))}, a, mu, rho)
+ t2 <- mapply(function(xb, mu, rho) { j <- xb:(xb*100); logsumexp(j * log(2 * mu * rho) - lfactorial(j) - j * log(1 + rho))}, b, mu, rho)
+
+ (2*mu-t1-t2) / log(10)
+}
diff --git a/man/pmt-package.Rd b/man/pmt-package.Rd
new file mode 100644
index 0000000..5c653d1
--- /dev/null
+++ b/man/pmt-package.Rd
@@ -0,0 +1,26 @@
+\name{pmt-package}
+\alias{pmt-package}
+\alias{pmt}
+\docType{package}
+\title{
+\packageTitle{pmt}
+Poisson Margin Test
+}
+\description{
+\packageDescription{pmt}
+Computes p-values using the Poission Margin Test for two vectors of counts arising from NGS data.
+}
+\details{
+\packageDESCRIPTION{pmt}
+\packageIndices{pmt}
+}
+\author{
+\packageAuthor{pmt}
+
+Maintainer: \packageMaintainer{pmt}
+}
+\references{
+Kowalczyk, A., Bedő, J., Conway, T., Beresford-Smith, B., 2011. The Poisson margin test for normalization-free significance analysis of NGS data. Journal of Computational Biology 18, 391–400. doi:10.1089/cmb.2010.0272
+}
+\keyword{NGS}
+\keyword{Poisson}
diff --git a/man/pmt.Rd b/man/pmt.Rd
new file mode 100644
index 0000000..c9e0250
--- /dev/null
+++ b/man/pmt.Rd
@@ -0,0 +1,33 @@
+\name{pmt}
+\alias{pmt}
+\title{Poisson Margin Test}
+\description{
+ Computes p-values for two sets of counts using the Poisson Margin Test.
+}
+\usage{
+pmt(a, b)
+}
+\arguments{
+ \item{a}{
+ Vector of counts
+}
+ \item{b}{
+ Vector of counts
+}
+}
+\details{
+ This function computes the Poisson Margin Test (PMT) for two sets of counts.
+}
+\value{
+ A vector of log10 p-values is returned, corresponding to the input vectors.
+}
+\references{
+Kowalczyk, A., Bedő, J., Conway, T., Beresford-Smith, B., 2011. The Poisson margin test for normalization-free significance analysis of NGS data. Journal of Computational Biology 18, 391–400. doi:10.1089/cmb.2010.0272
+}
+\author{
+ Justin Bedő
+}
+%\examples{
+%}
+\keyword{NGS}
+\keyword{Poisson}