Skip to content

Commit 683fa40

Browse files
committed
Merge branch 'main' of github.com:waldronlab/taxPPro
2 parents 94143f1 + b20514b commit 683fa40

File tree

3 files changed

+211
-6
lines changed

3 files changed

+211
-6
lines changed

R/taxPPro.R

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ getDataReady <- function(tbl) {
173173
output <- dataset |>
174174
tidyr::complete(NCBI_ID, Attribute, fill = list(Score = 0)) |>
175175
dplyr::arrange(NCBI_ID, Attribute)
176-
} else if (attr_type == 'range') { # al numeric are converted to range when imported with the physiologies function
176+
} else if (attr_type == 'range') { # all numeric are converted to range when imported with the physiologies function
177177
set_with_ids <- getSetWithIDs(tbl) |>
178178
purrr::discard(~ all(is.na(.x)))
179179
set_without_ids <- getSetWithoutIDs(tbl, set_with_ids = set_with_ids) |>
@@ -265,10 +265,14 @@ getSetWithIDs <- function(tbl) {
265265
) |>
266266
dplyr::group_by(.data$NCBI_ID) |>
267267
dplyr::slice_max(
268-
.data$Confidence_in_curation, n = 1, with_ties = FALSE
268+
.data$Confidence_in_curation, n = 1, with_ties = TRUE
269269
) |>
270270
dplyr::mutate(
271-
Attribute_value = mean(.data$Attribute_value_min, .data$Attribute_value_max)
271+
Attribute_value = mean(cbind(.data$Attribute_value_min, .data$Attribute_value_max))
272+
) |>
273+
# dplyr::mutate(Attribute_value = mean(Attribute_value)) |>
274+
dplyr::slice_max(
275+
.data$Confidence_in_curation, n = 1, with_ties = FALSE
272276
) |>
273277
dplyr::ungroup() |>
274278
dplyr::select(-Attribute_value_min, -Attribute_value_max) |>
@@ -349,9 +353,13 @@ getSetWithoutIDs <- function(tbl, set_with_ids = NULL) {
349353
dplyr::mutate(Taxon_name = taxizedb::taxid2name(.data$NCBI_ID, db = 'ncbi')) |>
350354
dplyr::mutate(Confidence_in_curation = conf2Fct(.data$Confidence_in_curation)) |>
351355
dplyr::group_by(.data$NCBI_ID) |>
352-
dplyr::slice_max(.data$Confidence_in_curation, n = 1, with_ties = FALSE) |>
356+
dplyr::slice_max(.data$Confidence_in_curation, n = 1, with_ties = TRUE) |>
353357
dplyr::mutate(
354-
Attribute_value = mean(.data$Attribute_value_min, .data$Attribute_value_max)
358+
Attribute_value = mean(cbind(.data$Attribute_value_min, .data$Attribute_value_max))
359+
) |>
360+
# dplyr::mutate(Attribute_value = mean(Attribute_value)) |>
361+
dplyr::slice_max(
362+
.data$Confidence_in_curation, n = 1, with_ties = FALSE
355363
) |>
356364
dplyr::ungroup() |>
357365
dplyr::select(-Attribute_value_min, -Attribute_value_max) |>

vignettes/articles/figure_example.Rmd

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "Example numeric"
3+
---
4+
5+
```{r, include = FALSE}
6+
knitr::opts_chunk$set(
7+
collapse = TRUE,
8+
comment = "#>"
9+
)
10+
```
11+
12+
```{r setup, message=FALSE}
13+
library(taxPPro)
14+
library(ape)
15+
library(phytools)
16+
library(castor)
17+
library(ggtree)
18+
```
19+
20+
```{r}
21+
set.seed(1234)
22+
tree <- rtree(n = 7, rooted = TRUE)
23+
tree$node.label <- paste0("n", Ntip(tree) + 1:Nnode(tree))
24+
plot(tree)
25+
```
26+
## Numeric
27+
28+
```{r}
29+
states <- c(t1 = 37, t2 = NA, t3 = NA, t4 = NA, t5 = 10, t6 = 80, t7 = NA)
30+
states <- states[match(tree$tip.label, names(states))]
31+
res <- hsp_squared_change_parsimony(
32+
tree = tree, tip_states = states, check_input = FALSE, weighted = TRUE
33+
)
34+
pred <- res$states
35+
names(pred) <- c(tree$tip.label, tree$node.label)
36+
```
37+
38+
39+
```{r}
40+
tip_data <- data.frame(
41+
label = names(pred),
42+
value = floor(pred)
43+
)
44+
p <- ggtree(tree) %<+% tip_data
45+
p +
46+
geom_tiplab() +
47+
geom_nodelab(nudge_x = -0.07, nudge_y = 0.15) +
48+
geom_label(aes(label = value), nudge_x = 0.11)
49+
```
50+
51+
52+
```{r}
53+
pruned_tree <- keep.tip(tree, c("t1", "t5", "t6"))
54+
plot(pruned_tree)
55+
```
56+
57+
```{r}
58+
ace(x = c(t5 = 10, t1 = 37, t6 = 80 ), phy = pruned_tree)$ace
59+
```
60+
61+
62+
## Session info
63+
64+
```{r}
65+
sessioninfo::session_info()
66+
```

vignettes/articles/smaller_example.Rmd

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ the t1 tip.
2525
```{r}
2626
set.seed(1234)
2727
randomTree <- rtree(7, rooted = TRUE)
28+
2829
mat <- matrix(
2930
data = rep(0.5, Ntip(randomTree) * 2), ncol = 2, dimnames = list(
3031
rownames = paste0('t', 1:Ntip(randomTree)), colnames = c('A--TRUE', 'A--FALSE')
@@ -147,9 +148,139 @@ mergedPlot
147148
```
148149

149150

151+
152+
153+
154+
# Example 2
155+
156+
```{r}
157+
mat <- matrix(
158+
data = rep(0.5, Ntip(randomTree) * 2), ncol = 2, dimnames = list(
159+
rownames = paste0('t', 1:Ntip(randomTree)), colnames = c('A--TRUE', 'A--FALSE')
160+
)
161+
)
162+
annotated_tips <- c('t3', 't2')
163+
for (i in seq_along(randomTree$tip.label)) {
164+
if (randomTree$tip.label[i] %in% annotated_tips) {
165+
mat[randomTree$tip.label[i], ] <- c(1, 0)
166+
}
167+
}
168+
mat
169+
```
170+
171+
172+
```{r, fig.width=15, fig.height=10}
173+
models <- c('ER', 'ARD', 'SYM')
174+
pis <- c('fitzjohn', 'equal', 'estimated')
175+
plotList <- vector('list', length(models) * length(pis))
176+
n <- 1
177+
for (i in seq_along(models)) {
178+
for (j in seq_along(pis)) {
179+
fit <- fitMk(tree = randomTree, x = mat, model = models[i], pi = pis[j])
180+
ace <- ancr(fit, tips = TRUE)
181+
plotList[[n]] <- plotT(
182+
randomTree, ace = ace, input_tips = annotated_tips,
183+
model = models[i], pi = pis[j]
184+
)
185+
n <- n + 1
186+
}
187+
}
188+
mergedPlot <- ggarrange(plotlist = plotList, ncol = 3, nrow = 3)
189+
mergedPlot
190+
```
191+
192+
193+
194+
195+
```{r}
196+
mat <- matrix(
197+
data = rep(0.5, Ntip(randomTree) * 2), ncol = 2, dimnames = list(
198+
rownames = paste0('t', 1:Ntip(randomTree)), colnames = c('A--TRUE', 'A--FALSE')
199+
)
200+
)
201+
annotated_tips <- c('t1', 't5')
202+
for (i in seq_along(randomTree$tip.label)) {
203+
if (randomTree$tip.label[i] %in% annotated_tips) {
204+
mat[randomTree$tip.label[i], ] <- c(1, 0)
205+
}
206+
}
207+
mat
208+
```
209+
210+
211+
212+
```{r}
213+
models <- c('ER', 'ARD', 'SYM')
214+
pis <- c('fitzjohn', 'equal', 'estimated')
215+
plotList <- vector('list', length(models) * length(pis))
216+
n <- 1
217+
for (i in seq_along(models)) {
218+
for (j in seq_along(pis)) {
219+
fit <- fitMk(tree = randomTree, x = mat, model = models[i], pi = pis[j])
220+
ace <- ancr(fit, tips = TRUE)
221+
plotList[[n]] <- plotT(
222+
randomTree, ace = ace, input_tips = annotated_tips,
223+
model = models[i], pi = pis[j]
224+
)
225+
n <- n + 1
226+
}
227+
}
228+
mergedPlot <- ggarrange(plotlist = plotList, ncol = 3, nrow = 3)
229+
```
230+
```{r, fig.width=15, fig.height=10}
231+
mergedPlot
232+
```
233+
234+
235+
236+
# Example 3
237+
238+
```{r}
239+
mat <- matrix(
240+
data = rep(0.5, Ntip(randomTree) * 2), ncol = 2, dimnames = list(
241+
rownames = paste0('t', 1:Ntip(randomTree)), colnames = c('A--TRUE', 'A--FALSE')
242+
)
243+
)
244+
annotated_tips <- c('t1', 't5')
245+
for (i in seq_along(randomTree$tip.label)) {
246+
if (randomTree$tip.label[i] %in% annotated_tips) {
247+
mat[randomTree$tip.label[i], ] <- c(1, 0)
248+
} else {
249+
mat[randomTree$tip.label[i], ] <- c(0, 1)
250+
}
251+
}
252+
mat["t4",] <- c(0.5, 0.5)
253+
mat["t7",] <- c(0.5, 0.5)
254+
mat["t2",] <- c(0.5, 0.5)
255+
mat
256+
```
257+
258+
259+
```{r}
260+
models <- c('ER', 'ARD', 'SYM')
261+
pis <- c('fitzjohn', 'equal', 'estimated')
262+
plotList <- vector('list', length(models) * length(pis))
263+
n <- 1
264+
for (i in seq_along(models)) {
265+
for (j in seq_along(pis)) {
266+
fit <- fitMk(tree = randomTree, x = mat, model = models[i], pi = pis[j])
267+
ace <- ancr(fit, tips = TRUE)
268+
plotList[[n]] <- plotT(
269+
randomTree, ace = ace, input_tips = c("t1", "t5", "t3", "t6"),
270+
model = models[i], pi = pis[j]
271+
)
272+
n <- n + 1
273+
}
274+
}
275+
mergedPlot <- ggarrange(plotlist = plotList, ncol = 3, nrow = 3)
276+
```
277+
278+
```{r, fig.width=15, fig.height=10}
279+
mergedPlot
280+
```
281+
150282
## Session info
151283

152284
```{r}
153285
sessioninfo::session_info()
154286
```
155-

0 commit comments

Comments
 (0)