Skip to content

Commit 7800574

Browse files
committed
Version submitted to CRAN 0.2-1
1 parent 27126e3 commit 7800574

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+348
-147
lines changed

.Rbuildignore

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ README[.]md
3636
inst/CODECOV_EXCLUSIONS
3737
^docker$
3838
^\.github$
39+
40+
# Wont include it for now
41+
^R/aphylo_hier\.R

DESCRIPTION

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Package: aphylo
22
Title: Statistical Inference and Prediction of Annotations in Phylogenetic Trees
33
Authors@R: person("George", "Vega Yon", role=c("aut","cre"),
44
email="g.vegayon@gmail.com", comment = c(ORCID = "0000-0002-3171-0844"))
5-
Version: 0.2-0
6-
Date: 2021-11-16
5+
Version: 0.2-1
6+
Date: 2022-01-01
77
Description: aphylo implements a parsimonious evolutionary model to analyze and
88
predict gene-functional annotations in phylogenetic trees as described in Vega
99
Yon et al. (2021) <doi:10.1371/journal.pcbi.1007948>. With a focus on
@@ -19,7 +19,7 @@ Imports: Rcpp (>= 0.12.1), Matrix, methods, coda, fmcmc,
1919
Suggests: covr, knitr, tinytest, AUC, rmarkdown,
2020
VignetteBuilder: knitr
2121
LinkingTo: Rcpp
22-
RoxygenNote: 7.1.1
22+
RoxygenNote: 7.1.2
2323
Encoding: UTF-8
2424
URL: https://github.com/USCbiostats/aphylo
2525
BugReports: https://github.com/USCbiostats/aphylo/issues

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export(accuracy_sifter)
8787
export(aphylo_cv)
8888
export(aphylo_formula)
8989
export(aphylo_from_data_frame)
90-
export(aphylo_hier)
9190
export(aphylo_mcmc)
9291
export(aphylo_mle)
9392
export(auc)

NEWS.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Changes in aphylo version 0.3-0
2+
3+
* Preparing for CRAN.
4+
5+
* Added examples to every function.
6+
7+
* Fixed bug in `auc()`: Was still using NAs in the predicted values.
8+
9+
* Fixed bug in `aphylo_formulae()`: Passing subsetted trees, e.g., `atree[[1]]`,
10+
now works.
11+
12+
113
# Changes in aphylo version 0.1.99
214

315
* First version

R/RcppExports.R

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ Tree_get_ann <- function(phy) {
8383
#' - `auc` A numeric value. Area Under the Curve.
8484
#' - `cutoffs` A vector of length `nc` with the cutoffs used.
8585
#' @export
86+
#' @examples
87+
#' set.seed(8381)
88+
#' x <- rdrop_annotations(raphylo(50), .3)
89+
#' ans <- aphylo_mcmc(x ~ mu_d + mu_s + Pi)
90+
#' ans_auc <- auc(predict(ans, loo = TRUE), x[,1,drop=TRUE])
91+
#' print(ans_auc)
92+
#' plot(ans_auc)
8693
auc <- function(pred, labels, nc = 200L, nine_na = TRUE) {
8794
.Call(`_aphylo_auc`, pred, labels, nc, nine_na)
8895
}

R/accuracy_sifter.R

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#'
2525
#' When `highlight = ""`, no highlight is done.
2626
#'
27+
#' @examples
28+
#' set.seed(81231)
29+
#' atree <- raphylo(100, psi = c(0,0), P = 3)
30+
#' ans <- aphylo_mcmc(atree ~ mu_d + mu_s + Pi)
31+
#'
32+
#' accuracy_sifter(ans)
33+
#'
2734
#' @export
2835
accuracy_sifter <- function(
2936
pred,

R/aphylo-ape-info.R

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
#' @name ape-methods
88
#' @family information
99
#' @importFrom ape as.phylo plot.phylo Nedge Ntip Nnode
10+
#' @examples
11+
#' set.seed(12312)
12+
#' atree <- raphylo(50, P = 2)
13+
#' Nnode(atree)
14+
#' Ntip(atree)
15+
#' Nedge(atree)
16+
#'
17+
#' multitree <- rmultiAphylo(10, 50, P = 2)
18+
#' Nnode(multitree)
19+
#' Ntip(multitree)
20+
#' Nedge(multitree)
1021
NULL
1122

1223
#' @method Nedge aphylo

R/aphylo_hier.R

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212
#' @family parameter estimation
1313
#' @details The parameters `priors`, `check_informative`, and `reduced_pseq`
1414
#' are silently ignored in this function.
15-
#' @export
15+
# #' @export # NOT FOR
16+
#' @noRd
17+
#' @examples
18+
#' set.seed(123189)
19+
#' aphylos <- rmultiAphylo(10, 50, P = 2)
20+
#'
21+
#' ans <- aphylo_hier(
22+
#' aphylos ~ mu_d + mu_s + Pi,
23+
#' params = c(0.9, .5, .1, .05, .5),
24+
#' classes = rep(c(1,2), 5)
25+
#' )
1626
aphylo_hier <- function(
1727
model,
1828
params,
@@ -22,9 +32,8 @@ aphylo_hier <- function(
2232
hyper_params = NULL,
2333
env = parent.frame(),
2434
verbose = TRUE,
25-
multicore = FALSE,
26-
nchains = 1L,
2735
use_optim = TRUE,
36+
control = ls(),
2837
priors = NULL,
2938
check_informative = NULL,
3039
reduced_pseq = NULL
@@ -238,3 +247,4 @@ aphylo_hier <- function(
238247
# return(ans)
239248

240249
}
250+

R/aphylo_mcmc.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#' @rdname aphylo_mcmc
33
#' @details `APHYLO_DEFAULT_MCMC_CONTROL` lists the default values for the MCMC
44
#' estimation:
5-
#' - `nsteps`: \Sexpr{aphylo::APHYLO_DEFAULT_MCMC_CONTROL$nsteps}
6-
#' - `burnin`: \Sexpr{aphylo::APHYLO_DEFAULT_MCMC_CONTROL$burnin}
7-
#' - `thin` : \Sexpr{aphylo::APHYLO_DEFAULT_MCMC_CONTROL$thin}
8-
#' - `nchains` : \Sexpr{aphylo::APHYLO_DEFAULT_MCMC_CONTROL$nchains}
9-
#' - `multicore` : \Sexpr{aphylo::APHYLO_DEFAULT_MCMC_CONTROL$multicore}
5+
#' - `nsteps`: `1e4L`
6+
#' - `burnin`: `5e3L`
7+
#' - `thin` : `10L`
8+
#' - `nchains` : `2L`
9+
#' - `multicore` : `FALSE`
1010
#' - `conv_checker` : `fmcmc::convergence_auto(5e3)`
1111
#'
1212
#' For more information about the MCMC estimation process, see [fmcmc::MCMC()].
@@ -44,7 +44,7 @@ APHYLO_DEFAULT_MCMC_CONTROL <- list(
4444
#' tree <- sim_tree(200)
4545
#'
4646
#' # Simulating functions
47-
#' dat <- raphylo(
47+
#' atree <- raphylo(
4848
#' tree = tree,
4949
#' psi = c(.01, .03),
5050
#' mu_d = c(.05, .02),

R/balance.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Functional banlance of a tree
1+
#' Functional balance of a tree
22
#'
33
#' This function computes the distance between .5 and the observed proportion
44
#' of ones for each function in a tree.

R/cv.R

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
#' with argument `loo = TRUE`.
1919
#'
2020
#' @export
21+
#' @examples
22+
#' # It takes about two minutes to run this example
23+
#' \dontrun{
24+
#'
25+
#' set.seed(123)
26+
#' atrees <- rmultiAphylo(10, 10, P = 1)
27+
#'
28+
#' cv_multi <- aphylo_cv(atrees ~ mu_d + mu_s + Pi)
29+
#' cv_single <- aphylo_cv(atrees[[1]] ~ mu_d + mu_s + Pi)
30+
#'
31+
#' }
2132
aphylo_cv <- function(...) UseMethod("aphylo_cv")
2233

2334
#' @export

R/estimation.R

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ try_solve <- function(x, ...) {
4444
#' \item{varcovar}{A matrix of size 5*5. The estimated covariance matrix.}
4545
#'
4646
#' @name aphylo_estimates
47+
#' @examples
48+
#' set.seed(7881)
49+
#' atree <- raphylo(40, P = 2)
50+
#' res <- aphylo_mcmc(atree ~ mu_d + mu_s + Pi)
51+
#'
52+
#' print(res)
53+
#' coef(res)
54+
#' vcov(res)
55+
#' plot(res)
4756
NULL
4857

4958
new_aphylo_estimates <- function(

R/formulas.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ APHYLO_PARAM_NAMES <- c(
100100
#' - `Pi`: \Sexpr[results=text]{as.list(aphylo::APHYLO_PARAM_DEFAULT)$Pi}
101101
#'
102102
APHYLO_PARAM_DEFAULT <- structure(
103-
.Data = c(.1, .1, .9, .9, .1, .1, .9, .9, .1),
103+
.Data = c(.1, .05, .9, .5, .1, .05, 1.0, 1.0, .5),
104104
names = APHYLO_PARAM_NAMES
105105
)
106106

@@ -392,10 +392,10 @@ aphylo_formula <- function(fm, params, priors, env = parent.frame()) {
392392
model_call <- aphylo_call(params, priors)
393393

394394
# Is the LHS an aphylo object?
395-
if (!exists(as.character(val[[2]]), envir = env))
396-
stop("The object -", as.character(val[[2]]), "- can't be found.", call. = FALSE)
395+
LHS <- tryCatch(eval(val[[2]], envir = env), error = function(e) e)
396+
if (inherits(LHS, "error"))
397+
stop("The object -", deparse(val[[2]]), "- can't be found.", call. = FALSE)
397398

398-
LHS <- eval(val[[2]], envir = env)
399399
if (!is.aphylo(LHS) && !is.multiAphylo(LHS) && !inherits(LHS, "aphylo_pruner"))
400400
stop(
401401
"The LHS of the equation should be either a list or a single ",

R/indexing.R

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#' the [aphylo] object. Whenever `i` is specified, then aphylo returns the corresponding
99
#' annotations.
1010
#' @name aphylo-index
11+
#' @examples
12+
#' set.seed(12312)
13+
#' atree <- raphylo(50, P = 4)
14+
#' atree[1:10,]
15+
#' atree[,2:3]
16+
#' atree[, 2:3, drop = TRUE]
17+
#'
18+
#'
1119
NULL
1220

1321
#' @export

R/plot.R

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#' @return In the case of `plot.aphylo`, `NULL`.
2424
#' @family aphylo methods
2525
#' @export
26+
#' @examples
27+
#' set.seed(7172)
28+
#' atree <- raphylo(20)
29+
#' plot(atree)
2630
plot.aphylo <- function(
2731
x,
2832
y = NULL,

R/prediction_score.R

+8
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ blue <- function(x) {
351351
#' If `include.labels = NULL` and `ncol(x$expected) > 40`,
352352
#' then `include.labels=FALSE` by default.
353353
#' @aliases plot-prediction
354+
#' @examples
355+
#' set.seed(8783)
356+
#' atree <- raphylo(29)
357+
#' ans <- aphylo_mle(atree ~ mu_d + mu_s + Pi)
358+
#' pred_s <- prediction_score(ans)
359+
#'
360+
#' pred_s
361+
#' plot(pred_s)
354362
plot.aphylo_prediction_score <- function(
355363
x,
356364
y = NULL,

R/prune.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#'
1515
#' @examples
1616
#' set.seed(1)
17-
#' x <- raphylo(10)
17+
#' x <- raphylo(20)
1818
#' pruner <- new_aphylo_pruner(x)
1919
#'
2020
#' # Computing loglike
@@ -26,6 +26,9 @@
2626
#' Pi = .05,
2727
#' eta = c(.90, .80)
2828
#' )
29+
#'
30+
#' dist2root(pruner)
31+
#' get_postorder(pruner)
2932
#' @name new_aphylo_pruner
3033
NULL
3134

R/read_nhx.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' )
1818
#' @export
1919
#' @references "NHX - New Hampshire eXtended \[version 2.0\]",
20-
#' \url{https://sites.google.com/site/cmzmasek/home/software/forester/nhx}
20+
#' \url{https://en.wikipedia.org/wiki/Newick_format#New_Hampshire_X_format}
2121
#' @family reading
2222
read_nhx <- function(fn, txt) {
2323

R/read_sifter.R

+44
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,50 @@ read_pli <- function(fn, dropNAs = TRUE) {
7979
#' @param family_id Character scalar. Name of the family
8080
#' @param file Character scalar passed to [cat].
8181
#' @export
82+
#' @examples
83+
#' set.seed(882)
84+
#' atree <- raphylo(5)
85+
#' write_pli(
86+
#' family_id = "a family",
87+
#' protein_name = atree$tree$tip.label,
88+
#' protein_number = 1:Ntip(atree),
89+
#' go_number = "GO:123123123123"
90+
#' )
91+
#' # Possible outcome:
92+
#' #<?xml version="1.0"?>
93+
#' #<Family>
94+
#' # <FamilyID>a family</FamilyID>
95+
#' # <Protein>
96+
#' # <ProteinName>1</ProteinName>
97+
#' # <ProteinNumber>1</ProteinNumber>
98+
#' # <GONumber>[GO:123123123123]</GONumber>
99+
#' # <MOC>[EXP]</MOC>
100+
#' # </Protein>
101+
#' # <Protein>
102+
#' # <ProteinName>2</ProteinName>
103+
#' # <ProteinNumber>2</ProteinNumber>
104+
#' # <GONumber>[GO:123123123123]</GONumber>
105+
#' # <MOC>[EXP]</MOC>
106+
#' # </Protein>
107+
#' # <Protein>
108+
#' # <ProteinName>3</ProteinName>
109+
#' # <ProteinNumber>3</ProteinNumber>
110+
#' # <GONumber>[GO:123123123123]</GONumber>
111+
#' # <MOC>[EXP]</MOC>
112+
#' # </Protein>
113+
#' # <Protein>
114+
#' # <ProteinName>4</ProteinName>
115+
#' # <ProteinNumber>4</ProteinNumber>
116+
#' # <GONumber>[GO:123123123123]</GONumber>
117+
#' # <MOC>[EXP]</MOC>
118+
#' # </Protein>
119+
#' # <Protein>
120+
#' # <ProteinName>5</ProteinName>
121+
#' # <ProteinNumber>5</ProteinNumber>
122+
#' # <GONumber>[GO:123123123123]</GONumber>
123+
#' # <MOC>[EXP]</MOC>
124+
#' # </Protein>
125+
#' #</Family>
82126
write_pli <- function(
83127
family_id, protein_name, protein_number, go_number, moc = "EXP",
84128
file = "") {

R/simulation.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ raphylo <- function(
273273
node.type = function(n) sample.int(2, size = n, replace = TRUE, prob = c(.2, .8)) - 1,
274274
P = 1L,
275275
psi = c(.05, .05),
276-
mu_d = c(.90, .90),
277-
mu_s = c(.10, .05),
276+
mu_d = c(.90, .50),
277+
mu_s = c(.05, .02),
278278
eta = c(1.0, 1.0),
279279
Pi = 0.2,
280280
informative = getOption("aphylo_informative", FALSE),

0 commit comments

Comments
 (0)