Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vignettes to use ReadMrBayesTrees() #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Rogue
Title: Identify Rogue Taxa in Sets of Phylogenetic Trees
Version: 2.1.6
Version: 2.1.6.9001
Authors@R: c(person("Martin R.", 'Smith',
email = "[email protected]",
role = c("aut", "cre", "cph"),
Expand Down Expand Up @@ -37,12 +37,15 @@ Imports:
Rfast,
stats,
TreeDist (> 2.2.0),
TreeTools (>= 1.9.1.9003),
TreeTools (>= 1.10.0),
utils,
Remotes:
ms609/TreeTools,
Suggests:
knitr,
PlotTools,
rmarkdown,
RCurl,
spelling,
testthat,
Config/Needs/github-actions:
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Rogue v2.1.6.9001 (development)

- Simplify vignette with new `TreeTools::ReadMrBayesTrees()`.


# Rogue v2.1.6

- Legend annotations in documentation.
Expand Down
2 changes: 1 addition & 1 deletion src/rnr
Submodule rnr updated 1 files
+2 −4 Tree.c
65 changes: 12 additions & 53 deletions vignettes/Bayesian.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ library("Rogue") # Find rogue taxa
```

```{r test-connection, echo = FALSE}
online <- tryCatch({
read.csv("https://raw.githubusercontent.com/ms609/hyoliths/master/MrBayes/hyo.nex.pstat")
TRUE
},
online <- tryCatch(RCurl::url.exists("https://raw.githubusercontent.com/"),
warning = function(w) invokeRestart(""),
error = function(e) FALSE
)
Expand All @@ -51,63 +48,25 @@ analysis of early brachiopods [@Sun2018] using
[MrBayes](https://nbisweden.github.io/MrBayes/) [@Hulsenbeck2001].
Our data files are stored on
[GitHub](https://github.com/ms609/hyoliths/tree/master/MrBayes).
Let's load the results of run 1:
Let's sample 100 trees from the posterior (after discarding a 25% burn-in):

```{R load-trees}
if (online) {
dataFolder <- "https://raw.githubusercontent.com/ms609/hyoliths/master/MrBayes/"
run1.t <- paste0(dataFolder, "hyo.nex.run1.t")
# Reading 10k trees takes a second or two...
run1Trees <- ape::read.nexus(run1.t)
if (packageVersion('ape') <= "5.6.1") {
# Workaround for a bug in ape, hopefully fixed in v5.6.2
run1Trees <- structure(lapply(run1Trees, function(tr) {
tr$tip.label <- attr(run1Trees, 'TipLabel')
tr
}), class = 'multiPhylo')
}
# Downloading all trees takes a second or two...
trees <- ReadMrBayesTrees(
"https://raw.githubusercontent.com/ms609/hyoliths/master/MrBayes/hyo.nex",
n = 100,
burninFrac = 0.25
)
} else {
# If no internet connection, we can generate some example trees instead
run1Trees <- structure(unlist(lapply(0:21, function(backbone) {
AddTipEverywhere(ape::as.phylo(0, nTip = 12), 'ROGUE')
}), recursive = FALSE), class = 'multiPhylo')
trees <- structure(unlist(lapply(0:21, function(backbone) {
AddTipEverywhere(ape::as.phylo(0, nTip = 12), "ROGUE")
}), recursive = FALSE), class = "multiPhylo")
}
```


## Select trees to analyse

Our tree file contains all trees generated. We typically want to discard
a proportion of trees as burn-in:

```{R discard-burnin}
burninFrac <- 0.25
nTrees <- length(run1Trees)
trees <- run1Trees[seq(from = burninFrac * nTrees, to = nTrees)]
```

This is a large number of trees to analyse. We could save time for an initial
analysis by thinning our sample somewhat.

```{R thin-trees}
sampleSize <- 100
trees <- run1Trees[seq(from = burninFrac * nTrees, to = nTrees,
length.out = sampleSize)]
```

For a full analysis, we ought to consider the output from the other runs of our
analysis, perhaps with

```r
nRuns <- 4
allTrees <- lapply(seq_len(nRuns), function(run) {
runTrees <- ape::read.nexus(paste0(dataFolder, 'hyo.nex.run', run, .'t'))
runTrees <- runTrees[seq(from = burninFrac * nTrees, to = nTrees,
length.out = sampleSize / nRuns)]
})
trees <- structure(unlist(allTrees, recursive = FALSE), class = 'multiPhylo')
```

## Initial appraisal

Let's start by looking at the majority rule consensus tree.
Expand All @@ -122,7 +81,7 @@ plenary <- Consensus(trees, p = 0.5)
par(mar = rep(0, 4), cex = 0.85)
plot(plenary, tip.color = ColByStability(trees))
PlotTools::SpectrumLegend(
"bottomright", legend = c("Stable", "Unstable"),
"bottomright", legend = c("Stable", " ", "Unstable"),
palette = hcl.colors(131, 'inferno')[1:101]
)
```
Expand Down
Loading