Skip to content

Commit 4162182

Browse files
Fixing some indentation
1 parent 871162e commit 4162182

File tree

9 files changed

+176
-184
lines changed

9 files changed

+176
-184
lines changed

R/compared_methods.R

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
# Copyright (C) 2016 University of Southern California and
2-
# Chao Deng and Andrew D. Smith and Timothy Daley
1+
# Copyright (C) 2016-2022 University of Southern California and
2+
# Chao Deng and Andrew D. Smith and Timothy Daley
33
#
4-
# Authors: Chao Deng
4+
# Authors: Chao Deng
55
#
6-
# This program is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
1010
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
11+
# This program is distributed in the hope that it will be useful, but
12+
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# General Public License for more details.
1815
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1918

2019
## Zero Truncated Poisson (ZTP) estimator
21-
## Cohen, A. Clifford. "Estimating the parameter in a conditional Poisson
20+
## Cohen, A. Clifford. "Estimating the parameter in a conditional Poisson
2221
## distribution." Biometrics 16, no. 2 (1960): 203-211.
23-
ztp.rSAC <- function(n, r=1)
22+
ztp.rSAC <- function(n, r=1)
2423
{
2524
## mle based on zero-truncated Poisson
2625
n[, 2] <- as.numeric(n[, 2])
@@ -31,22 +30,22 @@ ztp.rSAC <- function(n, r=1)
3130
lambda <- result$root
3231
L <- sum(n[, 2]) / (1 - ppois(0, lambda))
3332

34-
## estimator
33+
## estimator
3534
function(x) {
3635
L * ppois(q=r - 1, lambda=lambda * x, lower.tail=FALSE)}
3736
}
3837

3938

4039
## BBC estimator
4140
## Boneh, Shahar, Arnon Boneh, and Richard J. Caron. "Estimating the prediction
42-
## function and the number of unseen species in sampling with replacement."
41+
## function and the number of unseen species in sampling with replacement."
4342
## Journal of the American Statistical Association 93, no. 441 (1998): 372-379.
4443
bbc.rSAC <- function(n, r=1) {
4544
n[, 2] <- as.numeric(n[, 2])
4645
S <- sum(n[, 2])
4746
## BBC estimator without bias correction
4847
tmp <- function(t) {sapply(t, function(x) {
49-
n[, 2] %*% (exp(-n[, 1]) - ppois(r-1, n[, 1] * x)) + S})}
48+
n[, 2] %*% (exp(-n[, 1]) - ppois(r-1, n[, 1] * x)) + S})}
5049
## bias correction
5150
index.f1 <- which(n[, 1] == 1)
5251
f1 <- n[index.f1, 2]
@@ -66,8 +65,8 @@ bbc.rSAC <- function(n, r=1) {
6665

6766

6867
## CS estimator
69-
## Chao, Anne, and Tsung-Jen Shen. "Nonparametric prediction in species
70-
## sampling." Journal of agricultural, biological, and environmental
68+
## Chao, Anne, and Tsung-Jen Shen. "Nonparametric prediction in species
69+
## sampling." Journal of agricultural, biological, and environmental
7170
## statistics 9, no. 3 (2004): 253-269.
7271
cs.rSAC <- function(n, r=1, k=10) {
7372
n[, 2] <- as.numeric(n[, 2])
@@ -82,9 +81,9 @@ cs.rSAC <- function(n, r=1, k=10) {
8281
S.rare <- sum(n[index.rare, 2])
8382
C.rare <- 1 - f1 / (n[index.rare, 1] %*% n[index.rare, 2])
8483
## estimate parameters
85-
gamma.rare <- max(S.rare / C.rare *
84+
gamma.rare <- max(S.rare / C.rare *
8685
((n[index.rare, 1] * (n[index.rare, 1] - 1)) %*% n[index.rare, 2]) /
87-
(n[index.rare, 1] %*% n[index.rare, 2])^2 - 1, 0)
86+
(n[index.rare, 1] %*% n[index.rare, 2])^2 - 1, 0)
8887
f0 <- S.rare / C.rare + f1 / C.rare * gamma.rare - S.rare
8988
## estimator
9089
# consistent type for estimator arithmetic to avoid warnings
@@ -104,7 +103,7 @@ fisher.alpha <- function(n) {
104103
n[, 2] <- as.numeric(n[, 2])
105104
N <- n[, 1] %*% n[, 2]
106105
S <- sum(n[, 2])
107-
result <- uniroot(function(x) (exp(x) - 1) / x - N / S, c(0.001, 1e9),
106+
result <- uniroot(function(x) (exp(x) - 1) / x - N / S, c(0.001, 1e9),
108107
tol=0.0001, extendInt="upX")
109108
alpha <- S / result$root
110109
return(alpha)
@@ -115,20 +114,22 @@ fisher.rSAC <- function(n, r=1) {
115114
n[, 2] <- as.numeric(n[, 2])
116115
alpha <- fisher.alpha(n)
117116
N <- n[, 1] %*% n[, 2]
118-
f.rSAC <- function(t) {sapply(t, function(x) alpha *
119-
integrate(function(z) (z^(r-1) / (1 - z)), lower=0,
120-
upper=N*x / (N*x + alpha))$value)}
117+
f.rSAC <- function(t) {
118+
sapply(t, function(x) alpha *
119+
integrate(function(z) (z^(r-1) / (1 - z)), lower=0,
120+
upper=N*x / (N*x + alpha))$value)
121+
}
121122
return(f.rSAC)
122123
}
123124

124125

125126
## fit a Poisson distribution
126127
pois.rSAC <- function(n, L, r=1) {
127-
lambda <- n[, 1] %*% n[, 2] / L
128-
f.rSAC <- function(t) {
129-
L * ppois(q=r - 1, lambda=lambda * t, lower.tail=FALSE)
130-
}
131-
return(f.rSAC)
128+
lambda <- n[, 1] %*% n[, 2] / L
129+
f.rSAC <- function(t) {
130+
L * ppois(q=r - 1, lambda=lambda * t, lower.tail=FALSE)
131+
}
132+
return(f.rSAC)
132133
}
133134

134135
## estimate the parameter for negative binomial distribuiton
@@ -145,14 +146,14 @@ nb.fitting <- function(n, L, size=SIZE.INIT)
145146

146147
## target function f
147148
f <- function(x) {
148-
return( -nb.loglikelihood(n, zero.counts, size = x, mu = m)/L )
149+
return( -nb.loglikelihood(n, zero.counts, size = x, mu = m)/L )
149150
}
150151

151152
## derivative of f
152153
gr <- function(x)
153154
{
154155
first.term <- ( digamma(x) * zero.counts +
155-
digamma(n[, 1] + x) %*% n[, 2] )/L
156+
digamma(n[, 1] + x) %*% n[, 2] )/L
156157
second.term <- digamma(x)
157158
third.term <- log(x) - log(x + m)
158159
result <- first.term - second.term + third.term
@@ -163,10 +164,10 @@ nb.fitting <- function(n, L, size=SIZE.INIT)
163164
## optimization
164165
if (v > m) {
165166
res <- optim(m^2 / (v - m), f, gr, method = "L-BFGS-B",
166-
lower = 0.00001, upper = 100000)
167+
lower = 0.00001, upper = 100000)
167168
} else {
168169
res <- optim(size, f, gr, method = "L-BFGS-B",
169-
lower = 0.00001, upper = 100000)
170+
lower = 0.00001, upper = 100000)
170171
}
171172

172173
loglikelihood <- nb.loglikelihood(n, zero.counts, size=res$par, mu=m)

R/kmer.R

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
# Copyright (C) 2016 University of Southern California and
2-
# Chao Deng and Andrew D. Smith and Timothy Daley
1+
# Copyright (C) 2016-2022 University of Southern California and
2+
# Chao Deng and Andrew D. Smith and Timothy Daley
33
#
4-
# Authors: Chao Deng
4+
# Authors: Chao Deng
55
#
6-
# This program is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
1010
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
11+
# This program is distributed in the hope that it will be useful, but
12+
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# General Public License for more details.
1515
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18-
#
19-
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2018

2119
## predict the fraction of k-mers represented at least r times in the sample
2220
kmer.frac <- function(n, r=2, mt=20) {
2321
return(preseqR.sample.cov(n=n, r=r-1, mt=mt))
2422
}
2523

2624

27-
## the fraction of k-mers represented at least r times as a function of
25+
## the fraction of k-mers represented at least r times as a function of
2826
## sample sizes
2927
kmer.frac.curve <- function(n, k, read.len, seq, r=2, mt=20) {
3028
f <- kmer.frac(n, r=r, mt=mt)
@@ -50,7 +48,7 @@ kmer.frac.bootstrap <- function(n, r=2, mt=20, times=30, conf=0.95) {
5048
}
5149

5250

53-
## the fraction of k-mers represented at least r times as a function of
51+
## the fraction of k-mers represented at least r times as a function of
5452
## sample sizes
5553
kmer.frac.curve.bootstrap <- function(n, k, read.len, seq, r=2, mt=20,
5654
times=30, conf=0.95)
@@ -66,9 +64,9 @@ kmer.frac.curve.bootstrap <- function(n, k, read.len, seq, r=2, mt=20,
6664
# consistent vector-vector arithmetic
6765
unit <- as.numeric(unit)
6866
seq.effort <- seq / unit
69-
result <- matrix(c(seq, f$f(seq.effort), f$lb(seq.effort),
67+
result <- matrix(c(seq, f$f(seq.effort), f$lb(seq.effort),
7068
f$ub(seq.effort)), ncol=4, byrow=FALSE)
71-
colnames(result) <- c("bases", paste("frac(X>=", r, ")", sep=""),
69+
colnames(result) <- c("bases", paste("frac(X>=", r, ")", sep=""),
7270
"lb", "ub")
7371
return(result)
7472
}

R/rSAC.R

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
# Copyright (C) 2016 University of Southern California and
1+
# Copyright (C) 2016-2022 University of Southern California and
22
# Chao Deng and Andrew D. Smith and Timothy Daley
33
#
4-
# Authors: Chao Deng
4+
# Authors: Chao Deng
55
#
6-
# This program is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
1010
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
11+
# This program is distributed in the hope that it will be useful, but
12+
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# General Public License for more details.
1815
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>
1918

20-
## the pair, a pole and a root, is a defect if the distance is less than
19+
## the pair, a pole and a root, is a defect if the distance is less than
2120
## the value defined by the variable PRECISION
2221
PRECISION <- 1e-3
2322

@@ -62,8 +61,8 @@ preseqR.interpolate.rSAC <- function(n, ss, r=1)
6261
if (x <= r - 1) {
6362
return(1)
6463
} else {
65-
# consistent vector-vector arithmetic
66-
denom <- as.numeric(denom)
64+
# consistent vector-vector arithmetic
65+
denom <- as.numeric(denom)
6766
logp = lchoose(N - x, size - 0:(r-1)) + lchoose(x, 0:(r-1)) - denom
6867
return(sum(exp(logp)))
6968
}})
@@ -93,7 +92,7 @@ preseqR.interpolate.rSAC <- function(n, ss, r=1)
9392
# frequencies <- lapply(1:i, function(x) rbinom(n[x, 2], n[x, 1], p))
9493
# f <- unlist(frequencies)
9594
# h <- hist(f, breaks=-1:max(f), plot=FALSE)$counts[-1]
96-
# matrix(c(which(h != 0), h[which(h != 0)]), byrow = FALSE, ncol=2)
95+
# matrix(c(which(h != 0), h[which(h != 0)]), byrow = FALSE, ncol=2)
9796
#}
9897

9998

@@ -113,7 +112,7 @@ discoveryrate.ps <- function(n, mt)
113112
change.sign <- 0
114113
for (i in 1:(min(mt-1, length(hist.count)))) {
115114
PS.coeffs <- c(
116-
PS.coeffs,
115+
PS.coeffs,
117116
(-1)^change.sign * hist.count[i] - PS.coeffs[length(PS.coeffs)])
118117
change.sign <- change.sign + 1
119118
}
@@ -250,7 +249,7 @@ ds.rSAC.bootstrap <- function(n, r=1, mt=20, times=30, conf=0.95)
250249
return(apply(result, FUN=var, MARGIN=1))
251250
}
252251
}
253-
252+
254253
se <- function(x) sqrt(variance(x))
255254

256255
## prevent later binding!!!
@@ -298,7 +297,7 @@ preseqR.rSAC <- function(n, r=1, mt=20, size=SIZE.INIT, mu=MU.INIT)
298297

299298
## the bootstrap version of preseqR.rSAC
300299
## with confidence interval
301-
preseqR.rSAC.bootstrap <- function(n, r=1, mt=20, size=SIZE.INIT,
300+
preseqR.rSAC.bootstrap <- function(n, r=1, mt=20, size=SIZE.INIT,
302301
mu=MU.INIT, times=30, conf=0.95)
303302
{
304303
checking.hist(n)

0 commit comments

Comments
 (0)