├── .Rbuildignore ├── .covrignore ├── .gitattributes ├── .github └── workflows │ ├── ASan.yml │ ├── R-CMD-check.yml │ ├── RcppDeepState.yml │ ├── codemeta.yml │ ├── memcheck.yml │ ├── pkgdown.yml │ ├── rchk.yml │ ├── revdep.yml │ ├── rhub.yaml │ └── update-csl.yml ├── .gitignore ├── .lintr ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── AddTip.R ├── ArtificialExtinction.R ├── BigInteger.R ├── ClusterTable.R ├── Combinatorics.R ├── Consensus.R ├── Decompose.R ├── DropTip.R ├── ImposeConstraint.R ├── Information.R ├── KeptPaths.R ├── KeptVerts.R ├── MatchNodes.R ├── PathLengths.R ├── RUtreebalance.R ├── RcppExports-manual.R ├── RcppExports.R ├── ReadMrBayes.R ├── ReadTntTree.R ├── RoguePlot.R ├── SplitFunctions.R ├── Splits.R ├── Stemwardness.R ├── Support.R ├── TipTimedTree.R ├── TopologyOnly.R ├── TotalCopheneticIndex.R ├── TreeNumber.R ├── TreeTools-package.R ├── as.matrix.R ├── as.multiPhylo.R ├── data.R ├── helper_functions.R ├── in.R ├── match.R ├── mst.R ├── parse_files.R ├── phylo.R ├── sort.R ├── split_analysis.R ├── sysdata.rda ├── tree_ancestors.R ├── tree_comparison.R ├── tree_descendants.R ├── tree_display.R ├── tree_generation.R ├── tree_information.R ├── tree_numbering.R ├── tree_properties.R ├── tree_rearrangement.R ├── tree_shape.R ├── tree_write.R └── zzz.R ├── README.md ├── TreeTools.Rproj ├── benchmark ├── DropTip.R └── SplitList.R ├── codemeta.json ├── cran-comments.md ├── data-raw ├── _double_factorials.R └── unrootedKeys.R ├── data ├── Lobo.RData ├── brewer.R ├── nRootedShapes.R ├── nUnrootedShapes.R └── unrootedKeys.rda ├── inst ├── CITATION ├── REFERENCES.bib ├── WORDLIST ├── _pkgdown.yml ├── apa-old-doi-prefix.csl ├── extdata │ ├── input │ │ ├── dataset.nex │ │ └── notes.nex │ ├── otherfolder │ │ └── empty.file │ ├── output │ │ ├── named.tre │ │ └── numbered.tre │ └── tests │ │ ├── ape-tree.nex │ │ ├── continuous.nex │ │ ├── encoding.nex │ │ ├── parse-nexus.nexus │ │ ├── taxon-notes.nex │ │ ├── tnt-bare-tree.tnt │ │ ├── tnt-dna.tnt │ │ ├── tnt-matrix.tnt │ │ ├── tnt-namedtree.tre │ │ ├── tnt-tree.tre │ │ └── tnt-trees-and-matrix.tnt └── include │ ├── TreeTools.h │ └── TreeTools │ ├── ClusterTable.h │ ├── SplitList.h │ ├── assert.h │ ├── keep_tip.h │ ├── renumber_tree.h │ ├── root_tree.h │ └── types.h ├── man-roxygen ├── LoboMods.R ├── MRS.R ├── characterNumParam.R ├── constraintParam.R ├── datasetParam.R ├── edgeLengthParam.R ├── edgeParam.R ├── exampleNodeSupport.R ├── nTipParam.R ├── outgroupTipsParam.R ├── preorderTreeParam.r ├── returnPhydat.R ├── split12Params.R ├── splitsObjectParam.R ├── tipLabelsParam.R ├── tipsForTreeGeneration.R ├── tree(s)Param.R ├── treeChild.R ├── treeNEdgeOptional.R ├── treeParam.r ├── treeParent.r └── xPhylo.R ├── man ├── AddTip.Rd ├── AncestorEdge.Rd ├── ApeTime.Rd ├── ArtificialExtinction.Rd ├── CharacterInformation.Rd ├── CladeSizes.Rd ├── CladisticInfo.Rd ├── ClusterTable-methods.Rd ├── ClusterTable.Rd ├── CollapseNode.Rd ├── CompatibleSplits.Rd ├── Consensus.Rd ├── ConsensusWithout.Rd ├── ConstrainedNJ.Rd ├── Decompose.Rd ├── DescendantEdges.Rd ├── DoubleFactorial.Rd ├── DropTip.Rd ├── EdgeAncestry.Rd ├── EdgeDistances.Rd ├── EndSentence.Rd ├── EnforceOutgroup.Rd ├── ExtractTaxa.Rd ├── GenerateTree.Rd ├── Hamming.Rd ├── ImposeConstraint.Rd ├── J1Index.Rd ├── KeptPaths.Rd ├── KeptVerts.Rd ├── LabelSplits.Rd ├── LeafLabelInterchange.Rd ├── ListAncestors.Rd ├── Lobo.data.Rd ├── MRCA.Rd ├── MSTEdges.Rd ├── MakeTreeBinary.Rd ├── MatchEdges.Rd ├── MatrixToPhyDat.Rd ├── MorphoBankDecode.Rd ├── N1Spr.Rd ├── NDescendants.Rd ├── NJTree.Rd ├── NPartitionPairs.Rd ├── NRooted.Rd ├── NSplits.Rd ├── NTip.Rd ├── NewickTree.Rd ├── Neworder.Rd ├── NodeDepth.Rd ├── NodeNumbers.Rd ├── NodeOrder.Rd ├── PairwiseDistances.Rd ├── PathLengths.Rd ├── PhyToString.Rd ├── PolarizeSplits.Rd ├── ReadCharacters.Rd ├── ReadMrBayesTrees.Rd ├── ReadTntTree.Rd ├── Renumber.Rd ├── RenumberTips.Rd ├── Reorder.Rd ├── RightmostCharacter.Rd ├── RoguePlot.Rd ├── RootNode.Rd ├── RootTree.Rd ├── SampleOne.Rd ├── SortTree.Rd ├── SpectrumLegend.Rd ├── SplitFrequency.Rd ├── SplitInformation.Rd ├── SplitMatchProbability.Rd ├── Splits.Rd ├── SplitsInBinaryTree.Rd ├── Stemwardness.Rd ├── Subsplit.Rd ├── Subtree.Rd ├── SupportColour.Rd ├── TipLabels.Rd ├── TipTimedTree.Rd ├── TipsInSplits.Rd ├── TopologyOnly.Rd ├── TotalCopheneticIndex.Rd ├── TreeIsRooted.Rd ├── TreeNumber.Rd ├── TreeShape.Rd ├── TreeTools-package.Rd ├── TreesMatchingSplit.Rd ├── TreesMatchingTree.Rd ├── TrivialSplits.Rd ├── TrivialTree.Rd ├── Unquote.Rd ├── UnrootedTreesMatchingSplit.Rd ├── UnshiftTree.Rd ├── WriteTntCharacters.Rd ├── as.Newick.Rd ├── as.multiPhylo.Rd ├── brewer.Rd ├── dot-RandomParent.Rd ├── doubleFactorials.Rd ├── edge_to_splits.Rd ├── figures │ ├── Stemwardness.png │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-stable.svg │ └── lifecycle-superseded.svg ├── is.TreeNumber.Rd ├── logDoubleFactorials.Rd ├── match.Splits.Rd ├── match.multiPhylo.Rd ├── nRootedShapes.Rd ├── print.TreeNumber.Rd ├── root_on_node.Rd ├── sapply64.Rd ├── sort.multiPhylo.Rd └── xor.Rd ├── memcheck ├── examples.R ├── tests.R └── vignettes.R ├── src ├── ClusterTable.cpp ├── RcppExports-manual.cpp ├── RcppExports.cpp ├── ape_reorder.cpp ├── ape_reorder.h ├── as_newick.cpp ├── consensus.cpp ├── descendant_edges.cpp ├── int_to_tree.cpp ├── kept_vertices.cpp ├── minimum_spanning_tree.cpp ├── path_lengths.cpp ├── splits.cpp ├── splits_to_tree.cpp ├── tips_in_splits.cpp └── tree_shape.cpp ├── tests ├── benchmark │ ├── benchmark-as.splits.R │ ├── benchmark-consensus.R │ └── benchmark-preorder.R ├── figs │ └── rogueplot.svg ├── spelling.R ├── testthat.R └── testthat │ ├── _snaps │ ├── RoguePlot │ │ ├── rogueplot-poly.svg │ │ ├── rogueplot-simple.svg │ │ ├── rogueplot-trees1.svg │ │ └── rogueplot-trees2.svg │ ├── Support │ │ ├── labelsplits-nameless.svg │ │ ├── labelsplits-names.svg │ │ └── labelsplits.svg │ ├── helper_functions │ │ └── spectrumlegend.svg │ ├── mst │ │ └── mst-plotting.svg │ └── tree_display │ │ └── sorted-tree.svg │ ├── test-AddTip.R │ ├── test-ArtificialExtinction.R │ ├── test-BigInteger.R │ ├── test-ClusterTable.R │ ├── test-Decompose.R │ ├── test-DropTip.R │ ├── test-ImposeConstraint.R │ ├── test-KeptPaths.R │ ├── test-KeptVerts.R │ ├── test-MatchNodes.R │ ├── test-PathLengths.R │ ├── test-RUtreebalance.R │ ├── test-ReadMrBayes.R │ ├── test-ReadTntTree.R │ ├── test-RoguePlot.R │ ├── test-SplitFunctions.R │ ├── test-Splits.R │ ├── test-Stemwardness.R │ ├── test-Support.R │ ├── test-TipTimedTree.R │ ├── test-TopologyOnly.R │ ├── test-TotalCopheneticIndex.R │ ├── test-TreeNumber.R │ ├── test-as.matrix.R │ ├── test-as.multiPhylo.R │ ├── test-combinatorics.R │ ├── test-consensus.R │ ├── test-helper_functions.R │ ├── test-information.R │ ├── test-int_to_tree.cpp.R │ ├── test-match.R │ ├── test-mst.R │ ├── test-parsers.R │ ├── test-phylo.R │ ├── test-root_tree.h.R │ ├── test-sort.R │ ├── test-split_analysis.R │ ├── test-splits.cpp.R │ ├── test-tree_ancestors.R │ ├── test-tree_comparison.R │ ├── test-tree_descendants.R │ ├── test-tree_display.R │ ├── test-tree_generation-random.R │ ├── test-tree_generation.R │ ├── test-tree_information.R │ ├── test-tree_numbering.R │ ├── test-tree_properties.R │ ├── test-tree_rearrange.R │ ├── test-tree_shape.R │ ├── test-tree_write.R │ └── testdata │ └── nonPreCons.nex └── vignettes ├── filesystem-navigation.Rmd ├── load-data.Rmd └── load-trees.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | CONTRIBUTING.md 2 | README.md 3 | cran-comments.md 4 | benchmark 5 | data-raw 6 | DELETE 7 | man-roxygen 8 | memcheck 9 | vignettes/.RData 10 | .github 11 | ^\.git/ 12 | ^\.lintr$ 13 | ^_pkgdown\.yml$ 14 | ^.*\.o$ 15 | ^.*\.dll$ 16 | ^.*\.yml$ 17 | ^.*\.Rproj$ 18 | ^\.Rproj\.user$ 19 | ^\.Rdata$ 20 | ^\.covrignore$ 21 | ^\.?R+prof.*$ 22 | ^\.zenodo\.json$ 23 | /^benchmark/ 24 | /^src\-/ 25 | ^CODE_OF_CONDUCT\.md$ 26 | ^codemeta\.json$ 27 | ^CRAN-SUBMISSION$ 28 | ^docs$ 29 | ^doc$ 30 | ^data-raw$ 31 | ^pkgdown$ 32 | ^revdep$ 33 | -------------------------------------------------------------------------------- /.covrignore: -------------------------------------------------------------------------------- 1 | src/ape_reorder.h 2 | src/phangorn_bip.cpp 3 | R/zzz.R 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/workflows/RcppDeepState.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | - '**valgrind**' 7 | paths: 8 | - '.github/workflows/RcppDeepState.yml' 9 | - 'src/**' 10 | - 'inst/include/**' 11 | - 'memcheck/**' 12 | - 'tests/testthat/**.R' 13 | - 'vignettes/**.Rmd' 14 | 15 | name: 'RcppDeepState analysis' 16 | jobs: 17 | RcppDeepState: 18 | runs-on: ubuntu-latest 19 | 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | 26 | - uses: FabrizioSandri/RcppDeepState-action@main 27 | with: 28 | fail_ci_if_error: 'true' 29 | location: '/' 30 | seed: '-1' 31 | max_seconds_per_function: '2' 32 | max_inputs: '3' 33 | comment: 'true' 34 | verbose: 'true' 35 | -------------------------------------------------------------------------------- /.github/workflows/codemeta.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | push: 4 | branches: 5 | - main 6 | - master 7 | paths: 8 | - 'DESCRIPTION' 9 | - '**codemeta.yml' 10 | 11 | name: codemeta 12 | 13 | jobs: 14 | codemeta: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | 19 | steps: 20 | - uses: ms609/actions/codemeta@main 21 | -------------------------------------------------------------------------------- /.github/workflows/memcheck.yml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | - '**valgrind**' 9 | paths: 10 | - '.github/workflows/memcheck.yml' 11 | - 'src/**' 12 | - 'inst/include/**' 13 | - 'memcheck/**' 14 | - 'tests/testthat/**.R' 15 | - 'vignettes/**.Rmd' 16 | pull_request: 17 | branches: 18 | - main 19 | - master 20 | paths: 21 | - '.github/workflows/memcheck.yml' 22 | - 'src/**' 23 | - 'inst/include/**' 24 | - 'memcheck/**' 25 | - 'tests/testthat/**.R' 26 | - 'vignettes/**.Rmd' 27 | 28 | name: mem-check 29 | 30 | jobs: 31 | mem-check: 32 | runs-on: ubuntu-24.04 33 | 34 | name: valgrind ${{ matrix.config.test }} 35 | 36 | strategy: 37 | fail-fast: false 38 | matrix: 39 | config: 40 | - {test: 'tests'} 41 | - {test: 'examples'} 42 | - {test: 'vignettes'} 43 | 44 | env: 45 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 46 | _R_CHECK_FORCE_SUGGESTS_: false 47 | RSPM: https://packagemanager.rstudio.com/cran/__linux__/noble/latest 48 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 49 | ASAN_OPTIONS: verify_asan_link_order=0 50 | 51 | steps: 52 | - uses: ms609/actions/memcheck@main 53 | with: 54 | test: ${{ matrix.config.test}} 55 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | paths: 7 | - 'DESCRIPTION' 8 | - '**pkgdown.yml' 9 | - '*.md' 10 | - 'inst/CITATION' 11 | - 'inst/*.bib' 12 | - 'man/**.Rd' 13 | - 'vignettes/**.Rmd' 14 | release: 15 | types: [published] 16 | workflow_dispatch: 17 | 18 | name: pkgdown 19 | 20 | jobs: 21 | pkgdown: 22 | runs-on: ubuntu-latest 23 | 24 | env: 25 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 26 | 27 | steps: 28 | - uses: ms609/actions/pkgdown@main 29 | -------------------------------------------------------------------------------- /.github/workflows/rchk.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | paths: 7 | - '.github/workflows/rchk.yml' 8 | - 'src/**' 9 | - 'inst/include/**' 10 | - 'memcheck/**' 11 | - 'tests/testthat/**.R' 12 | - 'vignettes/**.Rmd' 13 | pull_request: 14 | paths: 15 | - '.github/workflows/rchk.yml' 16 | - 'src/**' 17 | - 'inst/include/**' 18 | - 'memcheck/**' 19 | - 'tests/testthat/**.R' 20 | - 'vignettes/**.Rmd' 21 | 22 | name: rchk 23 | 24 | jobs: 25 | rchk: 26 | runs-on: ubuntu-latest 27 | container: 28 | image: rhub/ubuntu-rchk 29 | options: --user=root 30 | steps: 31 | - uses: actions/checkout@v4 32 | 33 | - name: Set up rchk 34 | uses: r-lib/actions/run-rchk@v2 35 | with: 36 | setup-only: true 37 | 38 | - uses: randy3k/gh-actions/r-install-deps@main 39 | with: 40 | cache-version: rchk-1 41 | 42 | - name: Install package 43 | run: | 44 | remotes::install_local() 45 | shell: Rscript {0} 46 | 47 | - uses: r-lib/actions/run-rchk@v2 48 | with: 49 | run-only: true 50 | -------------------------------------------------------------------------------- /.github/workflows/revdep.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | paths-ignore: 7 | - "Meta**" 8 | - "data-raw**" 9 | - "docs**" 10 | - "inst**" 11 | - "man**" 12 | - "memcheck**" 13 | - "tests**" 14 | - "vignettes**" 15 | - "**.git" 16 | - "**.json" 17 | - "**.md" 18 | - "**.yaml" 19 | - "**.yml" 20 | - "!**revdep.yml" 21 | - "**.R[dD]ata" 22 | - "**.Rpro*" 23 | pull_request: 24 | branches: 25 | - main 26 | - master 27 | paths-ignore: 28 | - "Meta**" 29 | - "memcheck**" 30 | - "data-raw**" 31 | - "docs**" 32 | - "inst**" 33 | - "man**" 34 | - "tests**" 35 | - "vignettes**" 36 | - "**.git" 37 | - "**.json" 38 | - "**.md" 39 | - "**.yaml" 40 | - "**.yml" 41 | - "!**revdep.yml" 42 | - "**.R[dD]ata" 43 | - "**.Rpro*" 44 | 45 | name: revdep-check 46 | 47 | jobs: 48 | mem-check: 49 | runs-on: ubuntu-latest 50 | 51 | name: revdepcheck 52 | 53 | strategy: 54 | fail-fast: false 55 | matrix: 56 | config: 57 | - {deps: '"Depends"'} 58 | - {deps: '"Suggests"'} 59 | - {deps: '"Imports"'} 60 | - {deps: '"LinkingTo"'} 61 | 62 | env: 63 | _R_CHECK_CRAN_INCOMING_: true # Seemingly not set by --as-cran 64 | _R_CHECK_FORCE_SUGGESTS_: false # CRAN settings 65 | R_COMPILE_AND_INSTALL_PACKAGES: 'never' 66 | _R_CHECK_THINGS_IN_CHECK_DIR_: false 67 | R_REMOTES_STANDALONE: true 68 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 69 | RSPM: ${{ matrix.config.rspm }} 70 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 71 | 72 | steps: 73 | - uses: ms609/actions/revdepcheck@main 74 | with: 75 | deps: ${{ matrix.config.deps }} 76 | -------------------------------------------------------------------------------- /.github/workflows/update-csl.yml: -------------------------------------------------------------------------------- 1 | name: Update CSL file 2 | on: 3 | schedule: 4 | - cron: '0 0 * * 1' # Runs weekly on Monday at 00:00 UTC 5 | workflow_dispatch: # Allows manual triggering 6 | 7 | jobs: 8 | update-csl: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | 13 | - name: Download latest CSL file 14 | run: | 15 | curl -o inst/apa-old-doi-prefix.csl https://raw.githubusercontent.com/citation-style-language/styles/master/apa-old-doi-prefix.csl 16 | 17 | - name: Check for changes 18 | id: changes 19 | run: | 20 | if git diff --quiet inst/apa-old-doi-prefix.csl; then 21 | echo "::set-output name=changed::false" 22 | echo "No changes to commit" 23 | else 24 | echo "::set-output name=changed::true" 25 | fi 26 | 27 | - name: Commit and push 28 | if: steps.changes.outputs.changed == 'true' 29 | run: | 30 | git config --local user.email "actions@github.com" 31 | git config --local user.name "GitHub Actions" 32 | git add inst/apa-old-doi-prefix.csl 33 | git commit -m "Update CSL file from upstream" 34 | git push 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | doc 3 | docs 4 | src-* 5 | src/*.o 6 | src/*.so 7 | src/*.dll 8 | .Rdata 9 | .Rprofile 10 | *.def 11 | *.gcno 12 | *.out 13 | *.Rhistory 14 | *.log 15 | /* *.Rd */ 16 | inst/ape 17 | inst/doc 18 | revdep/ 19 | vignettes/*.html 20 | vignettes/*.pdf 21 | vignettes/*_files 22 | vignettes/*_cache* 23 | *.Rproj* 24 | .Rproj.user 25 | !TreeTools.Rproj 26 | *.site 27 | *.bak 28 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: with_defaults( 2 | object_name_linter(styles = c("CamelCase", "camelCase")) 3 | ) 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (https://www.contributor-covenant.org), version 1.0.0, available at 25 | https://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /R/BigInteger.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/R/BigInteger.R -------------------------------------------------------------------------------- /R/KeptPaths.R: -------------------------------------------------------------------------------- 1 | #' Paths present in reduced tree 2 | #' 3 | #' Lists which paths present in a master tree are present when leaves are 4 | #' dropped. 5 | #' 6 | #' @param paths `data.frame` of paths in master tree, perhaps generated using 7 | #' [`PathLengths()`]. 8 | #' @param keptVerts Logical specifying whether each entry is retained in the 9 | #' reduced tree, perhaps generated using [`KeptVerts()`]. 10 | #' @param all Logical: if `TRUE`, return all paths that occur in the reduced 11 | #' tree; if `FALSE`, return only those paths that correspond to a single edge. 12 | #' that correspond to edges in the reduced tree. 13 | #' Ignored if `paths` is a matrix. 14 | #' @return `KeptPaths()` returns a logical vector specifying whether each path 15 | #' in `paths` occurs when `keptVerts` vertices are retained. 16 | #' @family tree manipulation 17 | #' @examples 18 | #' master <- BalancedTree(9) 19 | #' paths <- PathLengths(master) 20 | #' keptTips <- c(1, 5, 7, 9) 21 | #' keptVerts <- KeptVerts(master, keptTips) 22 | #' KeptPaths(paths, keptVerts) 23 | #' paths[KeptPaths(paths, keptVerts, all = FALSE), ] 24 | #' @export 25 | #' @template MRS 26 | KeptPaths <- function(paths, keptVerts, all = TRUE) UseMethod("KeptPaths") 27 | 28 | #' @rdname KeptPaths 29 | #' @export 30 | KeptPaths.data.frame <- function(paths, keptVerts, all = TRUE) { 31 | kept <- apply(matrix(as.integer(unlist(paths[, 1:2])) %in% which(keptVerts), 32 | ncol = 2L), 1, all) 33 | 34 | if (!all) { 35 | kept[kept][duplicated(paths[kept, "end"], fromLast = TRUE)] <- FALSE 36 | } 37 | # Return: 38 | kept 39 | } 40 | 41 | #' @rdname KeptPaths 42 | #' @export 43 | KeptPaths.matrix <- function(paths, keptVerts, all = TRUE) { 44 | kept <- array(FALSE, dim = dim(paths)) 45 | kept[keptVerts, keptVerts] <- TRUE 46 | kept 47 | } 48 | -------------------------------------------------------------------------------- /R/KeptVerts.R: -------------------------------------------------------------------------------- 1 | #' Identify vertices retained when leaves are dropped 2 | #' 3 | #' @param tree Original tree of class `phylo`, in [`Preorder`]. 4 | #' @param keptTips Either: 5 | #' - a logical vector stating whether each leaf should be retained, in a 6 | #' sequence corresponding to `tree[["tip.label"]]`; or 7 | #' - a character vector listing the leaf labels to retain; or 8 | #' - a numeric vector listing the indices of leaves to retain. 9 | #' @param tipLabels Optional character vector naming the leaves of `tree`, 10 | #' if `keptTips` is not logical. Inferred from `tree` if unspecified. 11 | #' @examples 12 | #' master <- BalancedTree(12) 13 | #' master <- Preorder(master) # Nodes must be listed in Preorder sequence 14 | #' plot(master) 15 | #' nodelabels() 16 | #' 17 | #' allTips <- master[["tip.label"]] 18 | #' keptTips <- sample(allTips, 8) 19 | #' plot(KeepTip(master, keptTips)) 20 | #' kept <- KeptVerts(master, allTips %in% keptTips) 21 | #' 22 | #' map <- which(kept) 23 | #' # Node `i` in the reduced tree corresponds to node `map[i]` in the original. 24 | #' @template MRS 25 | #' @export 26 | #' @family tree manipulation 27 | KeptVerts <- function(tree, keptTips, tipLabels = TipLabels(tree)) { 28 | UseMethod("KeptVerts") 29 | } 30 | 31 | #' @rdname KeptVerts 32 | #' @export 33 | KeptVerts.phylo <- function(tree, keptTips, tipLabels = TipLabels(tree)) { 34 | order <- attr(tree, "order") 35 | if (is.null(order) || order != "preorder") { 36 | stop("`tree` must be in preorder; try `Preorder(tree)`") 37 | } 38 | KeptVerts(tree[["edge"]], keptTips, tipLabels = tipLabels) 39 | } 40 | 41 | #' @rdname KeptVerts 42 | #' @export 43 | KeptVerts.numeric <- function(tree, keptTips, tipLabels = TipLabels(tree)) { 44 | switch(mode(keptTips), 45 | "numeric" = { 46 | x <- logical(length(tipLabels)) 47 | x[keptTips] <- TRUE 48 | keptTips <- x 49 | }, 50 | "character" = { 51 | keptTips <- tipLabels %in% keptTips 52 | }, 53 | "logical" = {}, 54 | stop("Unrecognized format for `keptTips`") 55 | ) 56 | dims <- dim(tree) 57 | if (is.null(dims) || dims[2] != 2L) { 58 | stop("`tree` must be the numeric edge matrix of a `phylo` object") 59 | } 60 | ret <- kept_vertices(tree, keptTips) 61 | # Return: 62 | ret[-1] > 1L 63 | } 64 | -------------------------------------------------------------------------------- /R/PathLengths.R: -------------------------------------------------------------------------------- 1 | #' Calculate length of paths between each pair of vertices within tree 2 | #' 3 | #' Given a weighted rooted tree `tree`, `PathLengths()` returns the distance 4 | #' from each vertex to each of its descendant vertices. 5 | #' 6 | #' @param tree Original tree of class `phylo`, in [`Preorder`]. 7 | #' @param fullMatrix Logical specifying return format; see "value" section`. 8 | #' @return If `fullMatrix = TRUE`, `PathLengths()` returns a square matrix in 9 | #' which entry `[i, j]` denotes the distance from internal node `i` to the 10 | #' descendant vertex `j`. 11 | #' Vertex pairs without a continuous directed path are denoted `NA`. 12 | #' If `fullMatrix = FALSE`, `PathLengths()` returns a `data.frame` with three 13 | #' columns: `start` lists the deepest node in each path (i.e. that closest 14 | #' to the root); `end` lists the shallowest node (i.e. that closest to a leaf); 15 | #' `length` lists the total length of that path. 16 | #' @examples 17 | #' tree <- rtree(6) 18 | #' plot(tree) 19 | #' add.scale.bar() 20 | #' nodelabels() 21 | #' tiplabels() 22 | #' PathLengths(tree) 23 | #' @template MRS 24 | #' @export 25 | #' @family tree properties 26 | PathLengths <- function(tree, fullMatrix = FALSE) { 27 | if (!inherits(tree, "phylo")) { 28 | stop("`tree` must be an object of class `phylo`.") 29 | } 30 | weights <- tree[["edge.length"]] 31 | if (is.null(weights)) { 32 | weights <- rep_len(1L, dim(tree[["edge"]])[1]) 33 | } 34 | mat <- path_lengths(tree[["edge"]], weights) 35 | 36 | # Return: 37 | if (fullMatrix) { 38 | mat 39 | } else { 40 | paths <- !is.na(mat) 41 | data.frame(start = row(paths)[paths], 42 | end = col(paths)[paths], 43 | length = mat[paths]) 44 | } 45 | } -------------------------------------------------------------------------------- /R/RcppExports-manual.R: -------------------------------------------------------------------------------- 1 | # Manual exports are required for functions that are defined in the 2 | # TreeTools namespace in header files. 3 | keep_tip <- function(edge, keep) { 4 | .Call(`_TreeTools_keep_tip`, edge, keep) 5 | } 6 | 7 | postorder_order <- function(edge) { 8 | .Call(`_TreeTools_postorder_order`, edge) 9 | } 10 | 11 | root_binary <- function(edge, outgroup) { 12 | .Call(`_TreeTools_root_binary`, edge, outgroup) 13 | } 14 | 15 | #' Wrapper for internal C function `root_on_node()` 16 | #' 17 | #' Direct entry point to `root_on_node()`; recommended for expert use only. 18 | #' `RootTree()` checks that input is properly formatted and is recommended 19 | #' for general use. 20 | #' @param phy Minimally, a named list with entries `edge` and `Nnode`, in the 21 | #' format of equivalent entries in a tree of class `phylo`. `edge.length` will 22 | #' also be considered if supplied. 23 | #' @param outgroup Integer specifying index of leaf or node to set as the 24 | #' outgroup. 25 | #' @returns `root_on_node()` returns `phy` rooted on the specified node. 26 | #' 27 | #' @template MRS 28 | #' @export 29 | #' @keywords internal 30 | root_on_node <- function(phy, outgroup) { 31 | .Call(`_TreeTools_root_on_node`, phy, outgroup) 32 | } 33 | -------------------------------------------------------------------------------- /R/TipTimedTree.R: -------------------------------------------------------------------------------- 1 | #' Display time-calibrated tree using tip information only 2 | #' 3 | #' `TipTimedTree()` plots a phylogenetic tree against time using an 4 | #' _ad hoc_ approach based on dates associated with the leaves. 5 | #' Nodes are dated to the youngest possible value, plus an additional "buffer" 6 | #' (specified with `minEdge`) to ensure that branching order is readable. 7 | #' 8 | #' This experimental function is liable to change its behaviour, or to 9 | #' be deprecated, in coming releases. 10 | #' Please contact the maintainer if you find it useful, so that a 11 | #' production-ready version can be prioritized. 12 | #' 13 | #' @template treeParam 14 | #' @param tipAge Numeric vector specifying the age (in units-of-time ago) 15 | #' associated with each tip in `tree$tip.label` in turn. 16 | #' Older ages signify earlier tips. 17 | #' @param minEdge Minimum length of edge to allow (in units-of-time) 18 | #' 19 | #' @return `TipTimedTree()` returns a tree with edge lengths set based on the 20 | #' ages of each tip. 21 | #' 22 | #' @examples 23 | #' tree <- BalancedTree(6) 24 | #' plot(TipTimedTree(tree, tipAge = 1:6, minEdge = 2)) 25 | #' @family utility functions 26 | #' @family tree manipulation 27 | #' @export 28 | TipTimedTree <- function(tree, tipAge, minEdge = 1) { 29 | edge <- tree[["edge"]] 30 | nEdge <- dim(edge)[1] 31 | if (nEdge < 2) { 32 | warning("`tree` does not contain multiple edges") 33 | tree[["edge.length"]] <- rep_len(minEdge, nEdge) 34 | return(tree) 35 | } 36 | nTip <- NTip(tree) 37 | if (nTip != length(tipAge)) { 38 | stop("`tipAge` must list one age per leaf in `tree`") 39 | } 40 | nNode <- nEdge - nTip 41 | 42 | age <- c(tipAge, rep_len(-Inf, max(edge) - nTip)) 43 | 44 | for (i in PostorderOrder(tree)) { 45 | age[edge[i, 1]] <- max(age[edge[i, 2]] + minEdge, age[edge[i, 1]]) 46 | } 47 | tree[["edge.length"]] <- apply(edge, 1, function(i) age[i[1]] - age[i[2]]) 48 | # Return: 49 | tree 50 | } 51 | -------------------------------------------------------------------------------- /R/TopologyOnly.R: -------------------------------------------------------------------------------- 1 | #' Remove metadata from trees 2 | #' 3 | #' `TopologyOnly()` removes all information from trees except for their 4 | #' topologies and leaf labels. This allows other functions to process 5 | #' trees more rapidly, as they do not need to process unneeded metadata. 6 | #' 7 | #' @inheritParams Preorder 8 | #' @return Returns `tree`, with each tree in [`Preorder`], with edge lengths, 9 | #' node labels and other attributes removed. 10 | #' @template MRS 11 | #' @export 12 | TopologyOnly <- function(tree) UseMethod("TopologyOnly") 13 | 14 | #' @export 15 | TopologyOnly.phylo <- function(tree) { 16 | Preorder(structure(list(edge = tree[["edge"]], 17 | Nnode = tree[["Nnode"]], 18 | tip.label = tree[["tip.label"]]), 19 | order = attr(tree, "order"), 20 | class = "phylo")) 21 | } 22 | 23 | #' @export 24 | TopologyOnly.multiPhylo <- function(tree) { 25 | tree[] <- lapply(tree, TopologyOnly) 26 | tree 27 | } 28 | 29 | #' @export 30 | TopologyOnly.list <- function(tree) { 31 | lapply(tree, TopologyOnly) 32 | } 33 | 34 | #' @export 35 | TopologyOnly.default <- function(tree) { 36 | tree 37 | } 38 | -------------------------------------------------------------------------------- /R/TreeTools-package.R: -------------------------------------------------------------------------------- 1 | #' TreeTools 2 | #' 3 | #' "TreeTools" is an R package that provides functions for creating, modifying and 4 | #' analysing phylogenetic trees. 5 | #' It complements packages such as 6 | #' [\pkg{ape}](https://cran.r-project.org/package=ape), 7 | #' [\pkg{phangorn}](https://cran.r-project.org/package=phangorn) and 8 | #' [\pkg{phytools}](https://cran.r-project.org/package=phytools), 9 | #' aiming for efficient and robust implementations of functions, typically 10 | #' applied to unweighted trees (i.e. those without edge lengths). 11 | #' 12 | #' Full documentation is available [online](https://ms609.github.io/TreeTools/). 13 | #' 14 | #' @keywords internal 15 | "_PACKAGE" 16 | 17 | # Suppress "NOTE: Nothing imported from Rdpack": 18 | #' @importFrom Rdpack reprompt 19 | NULL 20 | 21 | # The following block is used by usethis to automatically manage 22 | # roxygen namespace tags. Modify with care! 23 | ## usethis namespace: start 24 | ## usethis namespace: end 25 | NULL 26 | -------------------------------------------------------------------------------- /R/as.matrix.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | as.matrix.phylo <- function(x, ...) { 3 | sp <- as.Splits(x) 4 | as.logical(sp) * 1 5 | } 6 | 7 | #' @export 8 | as.logical.phylo <- function(x, ...) { 9 | as.logical(as.Splits(x)) 10 | } 11 | 12 | #' @export 13 | as.matrix.phyDat <- function(x, ambigNA = FALSE, inappNA = ambigNA, ...) { 14 | PhyDatToMatrix(x, ambigNA, inappNA) 15 | } 16 | -------------------------------------------------------------------------------- /R/in.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/R/in.R -------------------------------------------------------------------------------- /R/sort.R: -------------------------------------------------------------------------------- 1 | #' Sort a list of phylogenetic trees 2 | #' 3 | #' Trees are sorted by their \link[=TreeNumber]{mixed base representation}, 4 | #' treating their leaves in the order of their labels (i.e. alphabetically, 5 | #' if leaves are labelled with text). 6 | #' 7 | #' @param x,decreasing,na.last,\dots As in [`sort()`]. 8 | #' 9 | #' @examples 10 | #' sort(as.phylo(5:0, 7)) 11 | #' @template MRS 12 | #' @family utility functions 13 | #' @export 14 | sort.multiPhylo <- function(x, decreasing = FALSE, na.last = NA, ...) { 15 | maxTip <- max(NTip(x)) 16 | sortable <- vapply(x, .Sortable, integer(maxTip - 3), maxTip) 17 | # Return: 18 | x[do.call(order, as.data.frame(t(sortable)), ...)] 19 | } 20 | 21 | #' @rdname sort.multiPhylo 22 | #' @param e1,e2 Objects to be compared. 23 | #' @export 24 | `==.phylo` <- function(e1, e2) { 25 | isTRUE(all.equal(.Comparable(e1), .Comparable(e2))) 26 | } 27 | 28 | .Comparable <- function(tree) { 29 | as.MixedBase(RenumberTips(tree, sort(tree[["tip.label"]]))) 30 | } 31 | 32 | .Sortable <- function(tree, maxTip = NTip(tree)) { 33 | c(rep(-1L, maxTip - NTip(tree)), 34 | as.integer(.Comparable(tree))) 35 | } 36 | 37 | #' @rdname sort.multiPhylo 38 | #' @export 39 | `<.phylo` <- function(e1, e2) { 40 | .Comparable(e1) < .Comparable(e2) 41 | } 42 | 43 | #' @rdname sort.multiPhylo 44 | #' @export 45 | `>.phylo` <- function(e1, e2) `<.phylo`(e2, e1) 46 | 47 | 48 | #' @rdname sort.multiPhylo 49 | #' @export 50 | `==.MixedBase` <- function(e1, e2) { 51 | isTRUE(all.equal(e1, e2)) 52 | } 53 | 54 | #' @rdname sort.multiPhylo 55 | #' @export 56 | `<.MixedBase` <- function(e1, e2) { 57 | s1 <- as.integer(e1) 58 | s2 <- as.integer(e2) 59 | if (length(s1) == length(s2)) { 60 | s1Less <- s1 < s2 61 | if (any(s1Less)) { 62 | s1More <- s1 > s2 63 | if (any(s1More)) { 64 | which.max(s1Less) < which.max(s1More) 65 | } else { 66 | TRUE 67 | } 68 | } else { 69 | FALSE 70 | } 71 | } else { 72 | length(s1) < length(s2) 73 | } 74 | } 75 | 76 | #' @rdname sort.multiPhylo 77 | #' @export 78 | `>.MixedBase` <- function(e1, e2) e2 < e1 79 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/R/sysdata.rda -------------------------------------------------------------------------------- /R/tree_comparison.R: -------------------------------------------------------------------------------- 1 | #' Distances between each pair of trees 2 | #' 3 | #' @param trees List of trees of class `phylo`. 4 | #' @param Func Function returning a distance between two trees. 5 | #' @param valueLength Integer specifying expected length of the value returned 6 | #' by `Func`. 7 | #' @param \dots Additional arguments to `Func`. 8 | #' 9 | #' @return Matrix detailing distance between each pair of trees. 10 | #' Identical trees are assumed to have zero distance. 11 | #' @examples 12 | #' trees <- list(BalancedTree(8), PectinateTree(8), StarTree(8)) 13 | #' TCIDiff <- function(tree1, tree2) { 14 | #' TotalCopheneticIndex(tree1) - TotalCopheneticIndex(tree2) 15 | #' } 16 | #' PairwiseDistances(trees, TCIDiff, 1) 17 | #' TCIRange <- function(tree1, tree2) { 18 | #' range(TotalCopheneticIndex(tree1), TotalCopheneticIndex(tree2)) 19 | #' } 20 | #' PairwiseDistances(trees, TCIRange, 2) 21 | #' @template MRS 22 | #' @family pairwise tree distances 23 | #' @importFrom stats as.dist 24 | #' @export 25 | PairwiseDistances <- function(trees, Func, valueLength = 1L, ...) { 26 | ret <- array(0, c(length(trees), length(trees), valueLength)) 27 | for (i in seq_along(trees)) { 28 | trI <- trees[[i]] 29 | for (j in i + seq_len(length(trees) - i)) { 30 | val <- Func(trI, trees[[j]], ...) 31 | ret[j, i, ] <- unlist(val) 32 | } 33 | } 34 | 35 | # Return: 36 | if (valueLength > 1L) { 37 | structure(lapply(seq_len(valueLength), function(i) { 38 | as.dist(ret[, , i], upper = TRUE) 39 | }), names = names(val)) 40 | } else { 41 | as.dist(ret[, , 1], upper = TRUE) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onUnload <- function(libpath) { 2 | library.dynam.unload("TreeTools", libpath) 3 | } 4 | 5 | ## Reminders when releasing for CRAN 6 | release_questions <- function() { 7 | c( 8 | "Is the code free of #TODOs?", 9 | "Have you checked the Vignettes for sanity?" 10 | ) 11 | } 12 | 13 | 14 | # Additional steps: 15 | # 16 | # Propagate changes in README.md to R/TreeTools-package.R 17 | 18 | 19 | # Additional tests: 20 | # 21 | # spell_check() 22 | # pkgdown::build_reference_index() 23 | # 24 | # run_examples() 25 | # build_vignettes() 26 | # 27 | # devtools::check_win_devel(quiet = TRUE); rhub::check_for_cran() 28 | # Check valgrind results on Github Actions 29 | # revdepcheck::revdep_check() 30 | # 31 | # codemetar::write_codemeta() 32 | # 33 | # tools::resaveRdaFiles("R", compress="auto") - is default bzip2 the optimal? 34 | # tools::checkRdaFiles("R") - set optimal compression in `data-raw` 35 | -------------------------------------------------------------------------------- /TreeTools.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: dd8d3be0-9522-4f39-a3c3-7f2bc1bdcfd7 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageUseDevtools: Yes 18 | PackageInstallArgs: --no-multiarch --with-keep.source 19 | PackageRoxygenize: rd,collate,namespace 20 | -------------------------------------------------------------------------------- /benchmark/DropTip.R: -------------------------------------------------------------------------------- 1 | ub <- microbenchmark::microbenchmark 2 | pv <- profvis::profvis 3 | 4 | devtools::load_all() 5 | 6 | set.seed(100) 7 | tree <- rtree(100) 8 | unif <- tree 9 | unif$edge.length <- NULL 10 | 11 | ub(DropTip(tree, 5), DropTip(unif, 5)) # edge lengths = 10x slower 12 | pv(replicate(10000, DropTip.phylo(tree, 5))) # Bottleneck: path_lengths 13 | -------------------------------------------------------------------------------- /benchmark/SplitList.R: -------------------------------------------------------------------------------- 1 | ub <- microbenchmark::microbenchmark 2 | pv <- profvis::profvis 3 | 4 | devtools::load_all() 5 | 6 | bigSplits <- as.Splits(as.phylo(100, 64*32)) 7 | someSplits <- as.Splits(as.phylo(100, 64*3)) 8 | 9 | # Test: -3 or keep power of 2 for SL_MAX_SPLITS? 10 | # See: #define SL_MAX_SPLITS (SL_MAX_TIPS - 3) in SplitList.h 11 | ub(as.phylo(someSplits), as.phylo(bigSplits)) 12 | # No replicable difference. 13 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | 3 | * Local PC: 4 | - Windows 10, R 4.6.0 devel 5 | 6 | * [GitHub Actions](https://github.com/ms609/TreeTools/actions) 7 | - Ubuntu latest 8 | - R 3.6 9 | - R release (tests, examples & vignettes run with valgrind) 10 | - R devel 11 | - Mac OS X latest, R release 12 | - Microsoft Windows Server latest, R release 13 | - RHub checks 14 | 15 | 16 | ## R CMD check results 17 | 18 | There were no ERRORs or WARNINGs or NOTEs. 19 | 20 | ## Downstream dependencies 21 | 22 | Reverse dependencies have been checked using "revdepcheck" on 23 | [GitHub Actions](https://github.com/ms609/TreeTools/actions/workflows/revdep.yml). 24 | -------------------------------------------------------------------------------- /data-raw/_double_factorials.R: -------------------------------------------------------------------------------- 1 | # Memoizing this function makes it MUCH slower... 2 | #' @describeIn DoubleFactorial Returns the logarithm of the double factorial. 3 | LogDoubleFactorial <- (function(x) { 4 | x[x < 2L] <- 1L 5 | odds <- as.logical(x %% 2L) 6 | 7 | oddX <- x[odds] 8 | xPlusOneOverTwo <- (oddX + 1L) / 2L 9 | evenX <- x[!odds] 10 | xOverTwo <- evenX / 2L 11 | 12 | ret <- integer(length(x)) 13 | ret[odds] <- lgamma(oddX + 1L) - 14 | (lgamma(xPlusOneOverTwo) + (xPlusOneOverTwo - 1L) * log(2L)) 15 | ret[!odds] <- log(evenX) + lgamma(xOverTwo) + (xOverTwo - 1L) * log(2L) 16 | 17 | # Return: 18 | ret 19 | }) 20 | 21 | logDoubleFactorials <- vapply(seq_len(50000), LogDoubleFactorial, double(1)) 22 | log2DoubleFactorials <- logDoubleFactorials / log(2) 23 | 24 | DoubleFactorial <- function(x) { 25 | if (any(x > 300)) stop("301!! is too large to represent numerically. Use LogDoubleFactorial instead.") 26 | 27 | 28 | x[x < 2L] <- 1L 29 | odds <- as.logical(x %% 2L) 30 | 31 | oddX <- x[odds] 32 | xPlusOneOverTwo <- (oddX + 1L) / 2L 33 | evenX <- x[!odds] 34 | xOverTwo <- evenX / 2L 35 | 36 | ret <- integer(length(x)) 37 | ret[odds] <- gamma(oddX + 1L) / (gamma(xPlusOneOverTwo) * 2L^(xPlusOneOverTwo - 1L)) 38 | ret[!odds] <- evenX * gamma(xOverTwo) * 2^(xOverTwo - 1L) 39 | 40 | # Return: 41 | ret 42 | } 43 | 44 | doubleFactorials <- c(1L, 2L, 3L, 8L, 15L, 48L, 105L, 384L, 945L, 45 | 3840L, 10395L, 46080L, 135135L, 645120L, 2027025L, 46 | 10321920L, 34459425L, 185794560L, 654729075L, 47 | # Use integers where possible to avoid rounding errors 48 | exp(logDoubleFactorials[20:300])) 49 | # Greater than 300 -> "Inf" 50 | 51 | usethis::use_data(logDoubleFactorials, log2DoubleFactorials, doubleFactorials, 52 | internal = TRUE, overwrite = TRUE, compress = "xz") 53 | -------------------------------------------------------------------------------- /data-raw/unrootedKeys.R: -------------------------------------------------------------------------------- 1 | suppressPackageStartupMessages(devtools::load_all()) 2 | 3 | .UnrootedKeys <- function(nTip) { 4 | if (nTip > 28L) { 5 | stop("Too many shapes to calculate with ", nTip, " tips.") 6 | } else if (nTip > 5L) { 7 | #TODO make efficient - this is horrible! 8 | shapes <- as.integer(structure( 9 | vapply(seq_len(as.integer(NRootedShapes(nTip))) - 1L, 10 | function(shape) UnrootedTreeKey(RootedTreeWithShape(shape, nTip)), 11 | integer64(1L)), 12 | class = "integer64")) 13 | uniqueShapes <- unique(shapes) 14 | } else { 15 | uniqueShapes <- 0 16 | } 17 | 18 | # Return: 19 | sort(uniqueShapes) 20 | } 21 | 22 | data("unrootedKeys", package = "TreeTools") 23 | message("Calculating unrootedKeys for ", length(unrootedKeys) + 1L, " tips.") 24 | unrootedKeys <- c(unrootedKeys, list(.UnrootedKeys(length(unrootedKeys) + 1L))) 25 | message(length(unrootedKeys[[length(unrootedKeys)]]), " keys found.") 26 | 27 | usethis::use_data(unrootedKeys, overwrite = TRUE, compress = "xz") 28 | -------------------------------------------------------------------------------- /data/Lobo.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/data/Lobo.RData -------------------------------------------------------------------------------- /data/brewer.R: -------------------------------------------------------------------------------- 1 | brewer <- list( 2 | c("#fc8d59"), 3 | c("#fc8d59", "#91bfdb"), 4 | c("#fc8d59", "#e2e2a2", "#91bfdb"), 5 | c("#d7191c", "#fdae61", "#abd9e9", "#2c7bb6"), 6 | c("#d7191c", "#fdae61", "#e2e2a2", "#abd9e9", "#2c7bb6"), 7 | c("#d73027", "#fc8d59", "#fee090", "#e0f3f8", "#91bfdb", "#4575b4"), 8 | c("#d73027", "#fc8d59", "#fee090", "#e2e2a2", "#e0f3f8", "#91bfdb", 9 | "#4575b4"), 10 | c("#d73027", "#f46d43", "#fdae61", "#fee090", "#e0f3f8", "#abd9e9", "#74add1", 11 | "#4575b4"), 12 | c("#d73027", "#f46d43", "#fdae61", "#fee090", "#e2e2a2", "#e0f3f8", "#abd9e9", 13 | "#74add1", "#4575b4"), 14 | c("#a50026", "#d73027", "#f46d43", "#fdae61", "#fee090", "#e0f3f8", "#abd9e9", 15 | "#74add1", "#4575b4", "#313695"), 16 | c("#a50026", "#d73027", "#f46d43", "#fdae61", "#fee090", "#e2e2a2", "#e0f3f8", 17 | "#abd9e9", "#74add1", "#4575b4", "#313695"), 18 | c("#006e82", "#8214a0", "#005ac8", "#00a0fa", "#fa78fa", "#14d2dc", "#aa0a3c", 19 | "#fa7850", "#0ab45a", "#f0f032", "#a0fa82", "#fae6be") 20 | ) 21 | -------------------------------------------------------------------------------- /data/nRootedShapes.R: -------------------------------------------------------------------------------- 1 | # https://oeis.org/A001190/b001190.txt 2 | nRootedShapes <- bit64::as.integer64(c( 3 | '1', 4 | '1', 5 | '1', 6 | '2', 7 | '3', 8 | '6', 9 | '11', 10 | '23', 11 | '46', 12 | '98', 13 | '207', 14 | '451', 15 | '983', 16 | '2179', 17 | '4850', 18 | '10905', 19 | '24631', 20 | '56011', 21 | '127912', 22 | '293547', 23 | '676157', 24 | '1563372', 25 | '3626149', 26 | '8436379', 27 | '19680277', 28 | '46026618', 29 | '107890609', 30 | '253450711', 31 | '596572387', 32 | '1406818759', 33 | '3323236238', 34 | '7862958391', 35 | '18632325319', 36 | '44214569100', 37 | '105061603969', 38 | '249959727972', 39 | '595405363473', 40 | '1419855914607', 41 | '3389524479050', 42 | '8099766813570', 43 | '19374186136140', 44 | '46384328517112', 45 | '111146809165122', 46 | '266552682265118', 47 | '639754054803187', 48 | '1536638374367584', 49 | '3693555574543651', 50 | '8884204649055027', 51 | '21383602613828364', 52 | '51501493576783437', 53 | '124115016908960463', 54 | '299284329327592851', 55 | '722086038540594854', 56 | '1743130822668362889', 57 | '4210157426126929793')) 58 | -------------------------------------------------------------------------------- /data/nUnrootedShapes.R: -------------------------------------------------------------------------------- 1 | # https://oeis.org/A000672/b000672.txt 2 | nUnrootedShapes <- bit64::as.integer64(c( 3 | "1", 4 | "1", 5 | "1", 6 | "1", 7 | "1", 8 | "2", 9 | "2", 10 | "4", 11 | "6", 12 | "11", 13 | "18", 14 | "37", 15 | "66", 16 | "135", 17 | "265", 18 | "552", 19 | "1132", 20 | "2410", 21 | "5098", 22 | "11020", 23 | "23846", 24 | "52233", 25 | "114796", 26 | "254371", 27 | "565734", 28 | "1265579", 29 | "2841632", 30 | "6408674", 31 | "14502229", 32 | "32935002", 33 | "75021750", 34 | "171404424", 35 | "392658842", 36 | "901842517", 37 | "2076217086", 38 | "4790669518", 39 | "11077270335", 40 | "25664800714", 41 | "59574334817", 42 | "138533927938", 43 | "322690700787", 44 | "752860182166", 45 | "1759156815134", 46 | "4116478586883", 47 | "9646022938064", 48 | "22633126704463", 49 | "53172713889998", 50 | "125071176763917", 51 | "294528476482361", 52 | "694349339794639", 53 | "1638663224680963", 54 | "3871184184258786", 55 | "9154254468736845", 56 | "21667596943783526", 57 | "51332411092604902", 58 | "121716968125202836", 59 | "288851967888729724", 60 | "686042815448602639", 61 | "1630671297982206272", 62 | "3878905739725127334")) 63 | -------------------------------------------------------------------------------- /data/unrootedKeys.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/data/unrootedKeys.rda -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | mrs <- person(c("Martin", "R."), "Smith", email = "martin.smith@durham.ac.uk") 2 | vers <- paste("R package version", meta$Version) 3 | 4 | bibentry( 5 | bibtype = "Manual", 6 | key = "Smith2019", 7 | title = "TreeTools: create, modify and analyse phylogenetic trees", 8 | author = mrs, 9 | note = vers, 10 | year = 2019, 11 | doi = "10.32614/CRAN.package.TreeTools", 12 | organization = "Comprehensive R Archive Network", 13 | textVersion = paste0( 14 | "Smith (2019). TreeTools: create, modify and analyse phylogenetic trees. ", 15 | "Comprehensive R Archive Network. doi: 10.32614/CRAN.package.TreeTools" 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | mfrow 2 | edgelabels 3 | etc 4 | nodelabels 5 | png 6 | ABCD 7 | Brazeau 8 | Cavalli 9 | CavalliSforza 10 | CDFGH 11 | CIC 12 | Cladewise 13 | Colless 14 | CollessLike 15 | ColourBrewer 16 | CSV 17 | DD 18 | EFGH 19 | FGH 20 | Foulds 21 | Guillerme 22 | HCL 23 | Hennig's 24 | Klopfstein 25 | Krzywinski 26 | Lemant 27 | Ln 28 | Maddison 29 | Mersenne 30 | MorphoBank 31 | Morphy 32 | MrBayes 33 | NCL 34 | Newick 35 | OEIS 36 | ORCID 37 | Pectinate 38 | PhyDat 39 | PlotTools 40 | Postorder 41 | Preorder 42 | Pruningwise 43 | R's 44 | RStudio 45 | Rcpp 46 | RdMacros 47 | Rdpack 48 | Rohlf 49 | Sackin's 50 | Sforza 51 | Spasojevic 52 | SPR 53 | Stemmier 54 | Stemwardness 55 | TNT's 56 | TreeDist 57 | TreeDistData 58 | TreeNumber 59 | TreeSearch 60 | Tromp 61 | Unrooted 62 | Wedderburn 63 | YYYY 64 | ac 65 | ar 66 | bipartitions 67 | cladewise 68 | cladistic 69 | codecov 70 | colourblind 71 | crownwards 72 | doi 73 | durham 74 | endopods 75 | fastmatch 76 | gotchas 77 | hh 78 | homoplasy 79 | hyperexponential 80 | ingroup 81 | lillo 82 | mbs 83 | memoization 84 | memoized 85 | multiPhylo 86 | neomorphic 87 | org 88 | outgroup 89 | papillate 90 | pectinate 91 | phangorn 92 | phytools 93 | phylo 94 | polytomies 95 | polytomy 96 | postorder 97 | preorder 98 | pruningwise 99 | raws 100 | readxl 101 | regraft 102 | sensu 103 | ss 104 | stemwardness 105 | syab 106 | syac 107 | sysbio 108 | taxon's 109 | tci 110 | testthat 111 | tnt 112 | tre 113 | uk 114 | un 115 | unroot 116 | unrooted 117 | vdiffr 118 | www 119 | -------------------------------------------------------------------------------- /inst/extdata/input/dataset.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | 3 | BEGIN DATA; 4 | DIMENSIONS NTAX = 5 NCHAR = 7; 5 | CHARSTATELABELS 6 | 1 'Character one' / absent present, 7 | 2 Character_two / absent present, 8 | 3 'lots-of-punctuation, and "so on"!' / here there 'everywhere', 9 | 4 Character_n / a_long_description present, 10 | 5 Character_5 / simple more_complex 'with (parentheses)' 'more complex, 6 still', 11 | 6 Character_6 / 12 | 'this one has' 13 | 'multiple lines', 14 | 7 final_character / absent present; 15 | MATRIX 16 | 'taxon_a' 0000000 17 | 'taxon_b' 0000000 18 | 'taxon_c' 1111?00 19 | 'taxon_d' 111??11 20 | 'taxon_e' 1111?11 21 | ; 22 | ENDBLOCK; 23 | -------------------------------------------------------------------------------- /inst/extdata/input/notes.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | 3 | BEGIN TAXA; 4 | TITLE Taxa; 5 | Dimensions Ntax = 5; 6 | TaxLabels 7 | taxon_a taxon_b taxon_c taxon_d taxon_e 8 | ; 9 | END; 10 | 11 | BEGIN DATA; 12 | DIMENSIONS NTAX=5 NCHAR = 7; 13 | MATRIX 14 | 'taxon_a' 0000000 15 | 'taxon_b' 0000000 16 | 'taxon_c' 1111?00 17 | 'taxon_d' 111??11 18 | 'taxon_e' 1111?11 19 | ; 20 | ENDBLOCK; 21 | 22 | BEGIN NOTES; 23 | TEXT TAXON = 1 CHARACTER = 3 TEXT = "Tax1-Char3"; 24 | TEXT TAXON=2 CHARACTER=2 TEXT="Taxon 2, char 2"; 25 | text taxon=3 text = "Taxon Three"; 26 | text Character = 3 text = 'Three''s a crowd.'; 27 | END; 28 | -------------------------------------------------------------------------------- /inst/extdata/otherfolder/empty.file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/inst/extdata/otherfolder/empty.file -------------------------------------------------------------------------------- /inst/extdata/output/named.tre: -------------------------------------------------------------------------------- 1 | tread 'tree(s) from TNT, for data in C:\TreeTools\input\dataset.nex' 2 | ('taxon_a' ('taxon_b' ('taxon_c' ('taxon_d' 'taxon_e' )))); 3 | proc-; 4 | -------------------------------------------------------------------------------- /inst/extdata/output/numbered.tre: -------------------------------------------------------------------------------- 1 | tread 'tree(s) from TNT, for data in C:\TreeTools\input\dataset.nex' 2 | (0 (1 (2 (3 4 ))))* 3 | (0 (1 (2 (3 4 )))); 4 | proc-; 5 | -------------------------------------------------------------------------------- /inst/extdata/tests/ape-tree.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | [R-package APE, Wed Jul 18 13:47:46 2018] 3 | 4 | BEGIN TAXA; 5 | END; 6 | -------------------------------------------------------------------------------- /inst/extdata/tests/continuous.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | 3 | BEGIN TAXA; 4 | TITLE Taxa; 5 | DIMENSIONS NTAX=3; 6 | TAXLABELS 7 | A_taxon B_alienus C_andinus 8 | ; 9 | END; 10 | 11 | 12 | BEGIN CHARACTERS; 13 | DIMENSIONS NTAX=3 NCHAR=6; 14 | FORMAT DATATYPE=CONTINUOUS MISSING = ?; 15 | MATRIX 16 | 17 | A_taxon 1.111 1 1.33 1.444 1.555 1.666 18 | B_alienus 2.111 2.222 2.333 ? 2.55 2.666 19 | C_andinus 3.111 3.222 3.333 3.444 3.555 3.666 20 | ; 21 | END; 22 | 23 | -------------------------------------------------------------------------------- /inst/extdata/tests/encoding.nex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/inst/extdata/tests/encoding.nex -------------------------------------------------------------------------------- /inst/extdata/tests/taxon-notes.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | 3 | BEGIN TAXA; 4 | DIMENSIONS NTAX=3; 5 | TAXLABELS 6 | One Two Three 7 | ; 8 | END; 9 | 10 | BEGIN NOTES; 11 | TEXT TAXON = 2 TEXT = "€ncoding"; 12 | END; 13 | 14 | 15 | BEGIN CHARACTERS; 16 | DIMENSIONS NCHAR=292; 17 | FORMAT DATATYPE = STANDARD GAP = - MISSING = ? SYMBOLS = " 0 1 2 3 4 5 6 7 8 9"; 18 | CHARSTATELABELS 1 'Presence' / absent present, 2 'Absence' / open closed; 19 | MATRIX 20 | One 01 21 | Two 10 22 | Three 11 23 | ; 24 | END; 25 | -------------------------------------------------------------------------------- /inst/extdata/tests/tnt-bare-tree.tnt: -------------------------------------------------------------------------------- 1 | tread (0 (1 (3 (2 (4 5 )))))*; 2 | -------------------------------------------------------------------------------- /inst/extdata/tests/tnt-dna.tnt: -------------------------------------------------------------------------------- 1 | nstates 8; 2 | nstates nogaps; 3 | xread 4 | 10 5 5 | &[num] 6 | Tax_a 0000 7 | Tax_b 0002 8 | Tax_c 1000 9 | Tax_d 1001 10 | Tax_e 1010 11 | 12 | &[dna] 13 | Tax_a GGCCCG 14 | Tax_b GGTTA[A G] 15 | Tax_c ATACGT 16 | Tax_d ATATAT 17 | Tax_e TGTG?C 18 | 19 | ; 20 | 21 | proc /; 22 | -------------------------------------------------------------------------------- /inst/extdata/tests/tnt-tree.tre: -------------------------------------------------------------------------------- 1 | tread 'tree(s) from TNT, for data in tnt-matrix.tnt' 2 | (0 (15 (14 (18 (((22 ((16 (((25 (24 (((4 (3 (1 2 )))(30 31 ))(((33 (17 32 ))(27 34 ))(28 29 )))))(8 9 ))((10 26 )(11 12 ))))(13 (6 7 ))))(19 (20 21 )))(5 23 ))))))* 3 | (0 (14 (15 (18 (((22 ((16 (((25 (24 (((4 (3 (1 2 )))(30 31 ))(((33 (17 32 ))(27 34 ))(28 29 )))))(8 9 ))((10 26 )(11 12 ))))(13 (6 7 ))))(19 (20 21 )))(5 23 )))))); 4 | ttags + 67 NoTreeSelected; 5 | ttag-; 6 | ttag*!; 7 | tt +67 SixtySeven; 8 | tread 'tree(s) from TNT, for data in tnt-matrix.tnt' 9 | (0 (14 (15 (18 (((22 ((16 (((25 (24 (((4 (3 (1 2 )))(30 31 ))(((33 (17 32 ))(27 34 ))(28 29 )))))(8 9 ))((10 26 )(11 12 ))))(13 (6 7 ))))(19 (20 21 )))(5 23 ))))))*; 10 | 11 | ttag* 1 ; 12 | ttag +68 AcanLing; 13 | ttag *!; 14 | ttag +0 Origin; 15 | ttag +35 Root; 16 | tta +36 Nov+1; 17 | tta +37 Nov+2; 18 | tta +38 Nov+3; 19 | tta +39 Nov; 20 | tta +39 +4; 21 | tta +40 Nov+5; 22 | tta +68 Nis+1; 23 | proc/; 24 | -------------------------------------------------------------------------------- /inst/extdata/tests/tnt-trees-and-matrix.tnt: -------------------------------------------------------------------------------- 1 | nsta 32 ; 2 | xread 3 | 'Test 4 | 0 1 23 456 78' 7 6 5 | a 0 - -- --- 6 | b 0 - -- --- 7 | c 1 0 0- 100 8 | d 1 0 0- 101 9 | e 1 0 10 110 10 | f 1 0 11 0-- 11 | ; 12 | cname 13 | {0 sup_tail absent present ; 14 | {1 sub_tail_color red blue ; 15 | {2 sub_tail_sup_knob absent present ; 16 | {3 sub_knob_cover scaly smooth hairy ; 17 | {4 sub_tail_sup_apophysis absent present ; 18 | {5 sub_apophysis_texture rigid flexible ; 19 | {6 sub_apophysis_color black white ; 20 | 21 | smat & ; 22 | tread 'test trees' 23 | (0 (1 (2 (5 (3 4 )))))* 24 | (0 25 | ((1 2 )( 26 | (3 (4 5 )))))* 27 | (0 (1 (2 (3 (4 5 ))))); 28 | tread (0 (1 (2 (4 3 5)))); 29 | proc/; 30 | -------------------------------------------------------------------------------- /inst/include/TreeTools.h: -------------------------------------------------------------------------------- 1 | #ifndef TreeTools_H_GEN_ 2 | #define TreeTools_H_GEN_ 3 | 4 | #include "TreeTools/types.h" 5 | 6 | 7 | #endif // TreeTools_H_GEN_ 8 | -------------------------------------------------------------------------------- /inst/include/TreeTools/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef TreeTools_assert_ 2 | #define TreeTools_assert_ 3 | #include 4 | 5 | #ifdef DEBUG 6 | #define ASSERT(x) if (!(x)) { \ 7 | std::ostringstream oss; \ 8 | oss << "Assertion failed: " << #x; \ 9 | Rcpp::stop(oss.str()); \ 10 | } 11 | #else 12 | #define ASSERT(x) ((void)0) 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /inst/include/TreeTools/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TreeTools_types_ 2 | #define TreeTools_types_ 3 | 4 | #include /* for uint_fast32_t, int_fast32_t, INTPTR_MAX */ 5 | 6 | typedef int_fast16_t int16; 7 | typedef int_fast32_t int32; 8 | typedef int_fast32_t intx; 9 | typedef uint_fast32_t uintx; 10 | 11 | namespace TreeTools { 12 | const intx INTX_MAX = intx(INT_FAST32_MAX); 13 | const uintx UINTX_MAX = uintx(UINT_FAST32_MAX); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /man-roxygen/LoboMods.R: -------------------------------------------------------------------------------- 1 | #' Modified so that absences are treated appropriately: 2 | #' \describe{ 3 | #' \item{Character 7 }{inapplicable to absent where cephalic shield (char 3) 4 | #' is absent} 5 | #' \item{Character 40}{inapplicable to absent where paired appendages absent} 6 | #' \item{Character 46}{inapplicable to absent} 7 | #' \item{Character 64}{76: stet; trunk annulations / limbs may primitively 8 | #' have been papillate or non-papillate} 9 | #' \item{Character 69}{a good case that the fusion of flaps with endopods is 10 | #' secondary; thus inapplicable to absent where 67 is 11 | #' applicable} 12 | #' \item{Character 72}{inapplicable to absent where appendages are present} 13 | #' \item{Character 77}{inapplicable to absent where papillae applicable, as 14 | #' spine is a secondary elaboration of papillae} 15 | #' \item{Character 78}{inapplicable to absent} 16 | #' \item{Character 79}{stet, as possible that limbs evolved by extension of 17 | #' plate-like exoskeletal element } 18 | #' \item{Character 80}{inapplicable to absent, on assumption that ancestral 19 | #' claws were simple } 20 | #' \item{Characters 83, 84, 86, 87, 92}{inapplicable to absent; an obvious 21 | #' elaboration } 22 | #' \item{Character 93}{inapplicable to absent; ancestrally undifferentiated 23 | #' by definition? } 24 | #' \item{Character 96}{inapplicable to absent; ancestrally undifferentiated 25 | #' by definition. Ambiguous in taxa that lack claws as 26 | #' rotation would not be observed. ]} 27 | #' } 28 | -------------------------------------------------------------------------------- /man-roxygen/MRS.R: -------------------------------------------------------------------------------- 1 | #' @author [Martin R. Smith](https://orcid.org/0000-0001-5660-1727) 2 | #' () 3 | -------------------------------------------------------------------------------- /man-roxygen/characterNumParam.R: -------------------------------------------------------------------------------- 1 | #' @param character_num Index of character(s) to return. 2 | #' `NULL`, the default, returns all characters. 3 | -------------------------------------------------------------------------------- /man-roxygen/constraintParam.R: -------------------------------------------------------------------------------- 1 | #' @param constraint Either an object of class `phyDat`, in which case returned 2 | #' trees will be perfectly compatible with each character in `constraint`; 3 | #' or a tree of class `phylo`, in which each node in `constraint` will occur in 4 | #' the returned tree. 5 | #' See [vignette](https://ms609.github.io/TreeSearch/articles/tree-search.html) 6 | #' for further examples. 7 | -------------------------------------------------------------------------------- /man-roxygen/datasetParam.R: -------------------------------------------------------------------------------- 1 | #' @param dataset A phylogenetic data matrix of \pkg{phangorn} class `phyDat`, 2 | #' whose names correspond to the labels of any accompanying tree. 3 | # Duplicated in TreeSearch; please propagate any changes there. 4 | -------------------------------------------------------------------------------- /man-roxygen/edgeLengthParam.R: -------------------------------------------------------------------------------- 1 | #' @param edgeLength Numeric specifying edge lengths of consensus tree; 2 | #' `NULL` aligns tips by scaling edges proportional to clade size; `1` sets 3 | #' all edges to unit length. 4 | -------------------------------------------------------------------------------- /man-roxygen/edgeParam.R: -------------------------------------------------------------------------------- 1 | #' @param edge A matrix with two columns, with each row listing the parent and 2 | #' child node of an edge in a phylogenetic tree. Property `edge` of objects 3 | #' of class `phylo`. 4 | -------------------------------------------------------------------------------- /man-roxygen/exampleNodeSupport.R: -------------------------------------------------------------------------------- 1 | #' @examples 2 | #' # An example forest of 100 trees, some identical 3 | #' forest <- as.phylo(c(1, rep(10, 79), rep(100, 15), rep(1000, 5)), nTip = 9) 4 | #' 5 | #' # Generate an 80% consensus tree 6 | #' cons <- ape::consensus(forest, p = 0.8) 7 | #' plot(cons) 8 | #' 9 | #' # Calculate split frequencies 10 | #' splitFreqs <- SplitFrequency(cons, forest) 11 | #' 12 | #' # Optionally, colour edges by corresponding frequency. 13 | #' # Note that not all edges are associated with a unique split 14 | #' # (and two root edges may be associated with one split - not handled here) 15 | #' edgeSupport <- rep(1, nrow(cons$edge)) # Initialize trivial splits to 1 16 | #' childNode <- cons$edge[, 2] 17 | #' edgeSupport[match(names(splitFreqs), childNode)] <- splitFreqs / 100 18 | #' 19 | #' plot(cons, edge.col = SupportColour(edgeSupport), edge.width = 3) 20 | #' 21 | #' # Annotate nodes by frequency 22 | #' LabelSplits(cons, splitFreqs, unit = "%", 23 | #' col = SupportColor(splitFreqs / 100), 24 | #' frame = "none", pos = 3L) 25 | #' 26 | -------------------------------------------------------------------------------- /man-roxygen/nTipParam.R: -------------------------------------------------------------------------------- 1 | #' @param nTip Integer specifying number of tips (leaves). 2 | -------------------------------------------------------------------------------- /man-roxygen/outgroupTipsParam.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/man-roxygen/outgroupTipsParam.R -------------------------------------------------------------------------------- /man-roxygen/preorderTreeParam.r: -------------------------------------------------------------------------------- 1 | #' @param tree A tree of class [`phylo`][ape::read.tree], with internal 2 | #' numbering in cladewise order (use \code{\link{Preorder}(tree)} or (slower) 3 | #' \code{\link{Cladewise}(tree)}) . 4 | -------------------------------------------------------------------------------- /man-roxygen/returnPhydat.R: -------------------------------------------------------------------------------- 1 | #' @return This function returns a data matrix in `phyDat` format. 2 | -------------------------------------------------------------------------------- /man-roxygen/split12Params.R: -------------------------------------------------------------------------------- 1 | #' @param split1,split2 Logical vectors listing terminals in same order, such that 2 | #' each terminal is identified as a member of the ingroup (`TRUE`) or outgroup 3 | #' (`FALSE`) of the respective bipartition split. 4 | -------------------------------------------------------------------------------- /man-roxygen/splitsObjectParam.R: -------------------------------------------------------------------------------- 1 | #' @param splits An object of class [`Splits`][as.Splits]. 2 | -------------------------------------------------------------------------------- /man-roxygen/tipLabelsParam.R: -------------------------------------------------------------------------------- 1 | #' @param tipLabels Character vector listing the labels assigned to each tip 2 | #' in a tree, perhaps obtained using [`TipLabels()`]. 3 | -------------------------------------------------------------------------------- /man-roxygen/tipsForTreeGeneration.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/man-roxygen/tipsForTreeGeneration.R -------------------------------------------------------------------------------- /man-roxygen/tree(s)Param.R: -------------------------------------------------------------------------------- 1 | #' @param tree A tree of class [`phylo`][ape::read.tree], or a list of trees 2 | #' of class `list` or `multiPhylo`. 3 | -------------------------------------------------------------------------------- /man-roxygen/treeChild.R: -------------------------------------------------------------------------------- 1 | #' @param child Integer vector corresponding to the second column of the edge 2 | #' matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 3 | #' `tree[["edge"]][, 2]`. 4 | -------------------------------------------------------------------------------- /man-roxygen/treeNEdgeOptional.R: -------------------------------------------------------------------------------- 1 | #' @param nEdge (optional) integer specifying the number of edges of a tree of 2 | #' class \code{\link{phylo}}, i.e. \code{dim(tree[["edge"]])[1]} 3 | -------------------------------------------------------------------------------- /man-roxygen/treeParam.r: -------------------------------------------------------------------------------- 1 | #' @param tree A tree of class [`phylo`][ape::read.tree]. 2 | -------------------------------------------------------------------------------- /man-roxygen/treeParent.r: -------------------------------------------------------------------------------- 1 | #' @param parent Integer vector corresponding to the first column of the edge 2 | #' matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 3 | #' `tree[["edge"]][, 1]` 4 | -------------------------------------------------------------------------------- /man-roxygen/xPhylo.R: -------------------------------------------------------------------------------- 1 | #' @param x A tree of class `phylo`, its `$edge` property, or a list thereof. 2 | -------------------------------------------------------------------------------- /man/AncestorEdge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_ancestors.R 3 | \name{AncestorEdge} 4 | \alias{AncestorEdge} 5 | \title{Ancestral edge} 6 | \usage{ 7 | AncestorEdge(edge, parent, child) 8 | } 9 | \arguments{ 10 | \item{edge}{Number of an edge} 11 | 12 | \item{parent}{Integer vector corresponding to the first column of the edge 13 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 14 | \code{tree[["edge"]][, 1]}} 15 | 16 | \item{child}{Integer vector corresponding to the second column of the edge 17 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 18 | \code{tree[["edge"]][, 2]}.} 19 | } 20 | \value{ 21 | \code{AncestorEdge} returns a logical vector identifying whether each edge 22 | is the immediate ancestor of the given edge. 23 | } 24 | \description{ 25 | Ancestral edge 26 | } 27 | \examples{ 28 | tree <- BalancedTree(6) 29 | parent <- tree$edge[, 1] 30 | child <- tree$edge[, 2] 31 | plot(tree) 32 | ape::edgelabels() 33 | AncestorEdge(5, parent, child) 34 | which(AncestorEdge(5, parent, child)) 35 | 36 | } 37 | \seealso{ 38 | Other tree navigation: 39 | \code{\link{CladeSizes}()}, 40 | \code{\link{DescendantEdges}()}, 41 | \code{\link{EdgeAncestry}()}, 42 | \code{\link{EdgeDistances}()}, 43 | \code{\link{ListAncestors}()}, 44 | \code{\link{MRCA}()}, 45 | \code{\link{MatchEdges}()}, 46 | \code{\link{NDescendants}()}, 47 | \code{\link{NodeDepth}()}, 48 | \code{\link{NodeNumbers}()}, 49 | \code{\link{NodeOrder}()}, 50 | \code{\link{RootNode}()} 51 | } 52 | \concept{tree navigation} 53 | \keyword{internal} 54 | -------------------------------------------------------------------------------- /man/ApeTime.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{ApeTime} 4 | \alias{ApeTime} 5 | \title{Read modification time from "ape" Nexus file} 6 | \usage{ 7 | ApeTime(filepath, format = "double") 8 | } 9 | \arguments{ 10 | \item{filepath}{Character string specifying path to the file.} 11 | 12 | \item{format}{Format in which to return the time: "double" as a sortable numeric; 13 | any other value to return a string in the format 14 | \verb{YYYY-MM-DD hh:mm:ss}.} 15 | } 16 | \value{ 17 | \code{ApeTime()} returns the time that the specified file was created by 18 | ape, in the format specified by \code{format}. 19 | } 20 | \description{ 21 | \code{ApeTime()} reads the time that a tree written with "ape" was modified, 22 | based on the comment in the Nexus file. 23 | } 24 | \author{ 25 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 26 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 27 | } 28 | -------------------------------------------------------------------------------- /man/CharacterInformation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Information.R 3 | \name{CharacterInformation} 4 | \alias{CharacterInformation} 5 | \title{Character information content} 6 | \usage{ 7 | CharacterInformation(tokens) 8 | } 9 | \arguments{ 10 | \item{tokens}{Character vector specifying the tokens assigned to each taxon for 11 | a character. Example: \code{c(0, 0, 0, 1, 1, 1, "?", "-")}. 12 | 13 | Note that ambiguous tokens such as \code{(01)} are not supported, and should be 14 | replaced with \verb{?}.} 15 | } 16 | \value{ 17 | \code{CharacterInformation()} returns a numeric specifying the 18 | phylogenetic information content of the character 19 | (\emph{sensu} \insertCite{Steel2006;nobrackets}{TreeTools}), in bits. 20 | } 21 | \description{ 22 | \code{CharacterInformation()} calculates the cladistic information content 23 | \insertCite{Steel2006}{TreeTools} of a given character, in bits. 24 | The total information in all characters gives a measure of the potential 25 | utility of a dataset \insertCite{Cotton2008}{TreeTools}, which can be 26 | compared with a profile parsimony score \insertCite{Faith2001}{TreeTools} to 27 | evaluate the degree of homoplasy within a dataset. 28 | } 29 | \references{ 30 | \insertAllCited{} 31 | } 32 | \seealso{ 33 | Other split information functions: 34 | \code{\link{SplitInformation}()}, 35 | \code{\link{SplitMatchProbability}()}, 36 | \code{\link{TreesMatchingSplit}()}, 37 | \code{\link{UnrootedTreesMatchingSplit}()} 38 | } 39 | \author{ 40 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 41 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 42 | } 43 | \concept{split information functions} 44 | -------------------------------------------------------------------------------- /man/CladeSizes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo.R 3 | \name{CladeSizes} 4 | \alias{CladeSizes} 5 | \title{Clade sizes} 6 | \usage{ 7 | CladeSizes(tree, internal = FALSE, nodes = NULL) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | 12 | \item{internal}{Logical specifying whether internal nodes should be counted 13 | towards the size of each clade.} 14 | 15 | \item{nodes}{Integer specifying indices of nodes at the base of clades 16 | whose sizes should be returned. 17 | If unspecified, counts will be provided for all nodes (including leaves).} 18 | } 19 | \value{ 20 | \code{CladeSizes()} returns the number of nodes (including leaves) that 21 | are descended from each node, not including the node itself. 22 | } 23 | \description{ 24 | \code{CladeSizes()} reports the number of nodes in each clade in a tree. 25 | } 26 | \examples{ 27 | tree <- BalancedTree(6) 28 | plot(tree) 29 | ape::nodelabels() 30 | CladeSizes(tree, nodes = c(1, 8, 9)) 31 | 32 | } 33 | \seealso{ 34 | Other tree navigation: 35 | \code{\link{AncestorEdge}()}, 36 | \code{\link{DescendantEdges}()}, 37 | \code{\link{EdgeAncestry}()}, 38 | \code{\link{EdgeDistances}()}, 39 | \code{\link{ListAncestors}()}, 40 | \code{\link{MRCA}()}, 41 | \code{\link{MatchEdges}()}, 42 | \code{\link{NDescendants}()}, 43 | \code{\link{NodeDepth}()}, 44 | \code{\link{NodeNumbers}()}, 45 | \code{\link{NodeOrder}()}, 46 | \code{\link{RootNode}()} 47 | } 48 | \concept{tree navigation} 49 | -------------------------------------------------------------------------------- /man/ClusterTable-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ClusterTable.R 3 | \name{ClusterTable-methods} 4 | \alias{ClusterTable-methods} 5 | \alias{as.matrix.ClusterTable} 6 | \alias{print.ClusterTable} 7 | \alias{summary.ClusterTable} 8 | \title{S3 methods for \code{ClusterTable} objects} 9 | \usage{ 10 | \method{as.matrix}{ClusterTable}(x, ...) 11 | 12 | \method{print}{ClusterTable}(x, ...) 13 | 14 | \method{summary}{ClusterTable}(object, ...) 15 | } 16 | \arguments{ 17 | \item{x, object}{Object of class \code{ClusterTable}.} 18 | 19 | \item{\dots}{Additional arguments for consistency with S3 methods.} 20 | } 21 | \description{ 22 | S3 methods for \code{\link{ClusterTable}} objects. 23 | } 24 | \examples{ 25 | clustab <- as.ClusterTable(TreeTools::BalancedTree(6)) 26 | as.matrix(clustab) 27 | print(clustab) 28 | summary(clustab) 29 | } 30 | \seealso{ 31 | Other utility functions: 32 | \code{\link{ClusterTable}}, 33 | \code{\link{Hamming}()}, 34 | \code{\link{MSTEdges}()}, 35 | \code{\link{SampleOne}()}, 36 | \code{\link{TipTimedTree}()}, 37 | \code{\link{UnshiftTree}()}, 38 | \code{\link{as.multiPhylo}()}, 39 | \code{\link{match,phylo,phylo-method}}, 40 | \code{\link{sapply64}()}, 41 | \code{\link{sort.multiPhylo}()} 42 | } 43 | \author{ 44 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 45 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 46 | } 47 | \concept{utility functions} 48 | -------------------------------------------------------------------------------- /man/CompatibleSplits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SplitFunctions.R 3 | \name{CompatibleSplits} 4 | \alias{CompatibleSplits} 5 | \alias{.CompatibleSplit} 6 | \alias{.CompatibleRaws} 7 | \title{Which splits are compatible?} 8 | \usage{ 9 | CompatibleSplits(splits, splits2) 10 | 11 | .CompatibleSplit(a, b, nTip) 12 | 13 | .CompatibleRaws(rawA, rawB, bitmask) 14 | } 15 | \arguments{ 16 | \item{splits}{An object of class \code{\link[=as.Splits]{Splits}}.} 17 | 18 | \item{splits2}{A second \code{Splits} object.} 19 | 20 | \item{a, b}{\link[=raw]{Raw} representations of splits, from a row of a \code{Splits} 21 | object.} 22 | 23 | \item{rawA, rawB}{Raw representations of splits.} 24 | 25 | \item{bitmask}{Raw masking bits that do not correspond to tips.} 26 | } 27 | \value{ 28 | \code{CompatibleSplits} returns a logical matrix specifying whether each 29 | split in \code{splits} is compatible with each split in \code{splits2}. 30 | 31 | \code{.CompatibleSplit} returns a logical vector stating whether splits 32 | are compatible. 33 | 34 | \code{.CompatibleRaws} returns a logical vector specifying whether input 35 | raws are compatible. 36 | } 37 | \description{ 38 | Which splits are compatible? 39 | } 40 | \examples{ 41 | splits <- as.Splits(BalancedTree(8)) 42 | splits2 <- as.Splits(PectinateTree(8)) 43 | 44 | summary(splits) 45 | summary(splits2) 46 | 47 | CompatibleSplits(splits, splits2) 48 | 49 | } 50 | \author{ 51 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 52 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 53 | } 54 | \keyword{internal} 55 | -------------------------------------------------------------------------------- /man/Consensus.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Consensus.R 3 | \name{Consensus} 4 | \alias{Consensus} 5 | \title{Construct consensus trees} 6 | \usage{ 7 | Consensus(trees, p = 1, check.labels = TRUE) 8 | } 9 | \arguments{ 10 | \item{trees}{List of trees, optionally of class \code{multiPhylo}.} 11 | 12 | \item{p}{Proportion of trees that must contain a split for it to be reported 13 | in the consensus. \code{p = 0.5} gives the majority-rule consensus; \code{p = 1} (the 14 | default) gives the strict consensus.} 15 | 16 | \item{check.labels}{Logical specifying whether to check that all trees have 17 | identical labels. Defaults to \code{TRUE}, which is slower.} 18 | } 19 | \value{ 20 | \code{Consensus()} returns an object of class \code{phylo}, rooted as in the 21 | first entry of \code{trees}. 22 | } 23 | \description{ 24 | \code{Consensus()} calculates the consensus of a set of trees, using the 25 | algorithm of \insertCite{Day1985}{TreeTools}. 26 | } 27 | \examples{ 28 | Consensus(as.phylo(0:2, 8)) 29 | } 30 | \references{ 31 | \insertAllCited{} 32 | } 33 | \seealso{ 34 | \code{TreeDist::ConsensusInfo()} calculates the information content of a consensus 35 | tree. 36 | 37 | Other consensus tree functions: 38 | \code{\link{ConsensusWithout}()}, 39 | \code{\link{RoguePlot}()} 40 | 41 | Other tree characterization functions: 42 | \code{\link{CladisticInfo}()}, 43 | \code{\link{J1Index}()}, 44 | \code{\link{Stemwardness}}, 45 | \code{\link{TotalCopheneticIndex}()} 46 | } 47 | \author{ 48 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 49 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 50 | } 51 | \concept{consensus tree functions} 52 | \concept{tree characterization functions} 53 | -------------------------------------------------------------------------------- /man/ConstrainedNJ.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_generation.R 3 | \name{ConstrainedNJ} 4 | \alias{ConstrainedNJ} 5 | \title{Constrained neighbour-joining tree} 6 | \usage{ 7 | ConstrainedNJ(dataset, constraint, weight = 1L, ratio = TRUE, ambig = "mean") 8 | } 9 | \arguments{ 10 | \item{dataset}{A phylogenetic data matrix of \pkg{phangorn} class \code{phyDat}, 11 | whose names correspond to the labels of any accompanying tree.} 12 | 13 | \item{constraint}{Either an object of class \code{phyDat}, in which case returned 14 | trees will be perfectly compatible with each character in \code{constraint}; 15 | or a tree of class \code{phylo}, in which each node in \code{constraint} will occur in 16 | the returned tree. 17 | See \href{https://ms609.github.io/TreeSearch/articles/tree-search.html}{vignette} 18 | for further examples.} 19 | 20 | \item{weight}{Numeric specifying degree to up-weight characters in 21 | \code{constraint}.} 22 | 23 | \item{ambig, ratio}{Settings of \code{ambig} and \code{ratio} to be used when 24 | computing \code{\link[=Hamming]{Hamming()}} distances between sequences.} 25 | } 26 | \value{ 27 | \code{ConstrainedNJ()} returns a tree of class \code{phylo}. 28 | } 29 | \description{ 30 | Constructs an approximation to a neighbour-joining tree, modified in order 31 | to be consistent with a constraint. Zero-length branches are collapsed 32 | at random. 33 | } 34 | \examples{ 35 | dataset <- MatrixToPhyDat(matrix( 36 | c(0, 1, 1, 1, 0, 1, 37 | 0, 1, 1, 0, 0, 1), ncol = 2, 38 | dimnames = list(letters[1:6], NULL))) 39 | constraint <- MatrixToPhyDat( 40 | c(a = 0, b = 0, c = 0, d = 0, e = 1, f = 1)) 41 | plot(ConstrainedNJ(dataset, constraint)) 42 | } 43 | \seealso{ 44 | Other tree generation functions: 45 | \code{\link{GenerateTree}}, 46 | \code{\link{NJTree}()}, 47 | \code{\link{TreeNumber}}, 48 | \code{\link{TrivialTree}} 49 | } 50 | \author{ 51 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 52 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 53 | } 54 | \concept{tree generation functions} 55 | -------------------------------------------------------------------------------- /man/DoubleFactorial.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Combinatorics.R 3 | \name{DoubleFactorial} 4 | \alias{DoubleFactorial} 5 | \alias{DoubleFactorial64} 6 | \alias{LnDoubleFactorial} 7 | \alias{Log2DoubleFactorial} 8 | \alias{LogDoubleFactorial} 9 | \alias{LnDoubleFactorial.int} 10 | \alias{LogDoubleFactorial.int} 11 | \title{Double factorial} 12 | \usage{ 13 | DoubleFactorial(n) 14 | 15 | DoubleFactorial64(n) 16 | 17 | LnDoubleFactorial(n) 18 | 19 | Log2DoubleFactorial(n) 20 | 21 | LogDoubleFactorial(n) 22 | 23 | LnDoubleFactorial.int(n) 24 | 25 | LogDoubleFactorial.int(n) 26 | } 27 | \arguments{ 28 | \item{n}{Vector of integers.} 29 | } 30 | \value{ 31 | Returns the double factorial, \emph{n} * (\emph{n} - 2) * (\emph{n} - 4) * 32 | (\emph{n} - 6) * ... 33 | } 34 | \description{ 35 | Calculate the double factorial of a number, or its logarithm. 36 | } 37 | \section{Functions}{ 38 | \itemize{ 39 | \item \code{DoubleFactorial64()}: Returns the exact double factorial as a 64-bit 40 | \code{integer64}, for \code{n} < 34. 41 | 42 | \item \code{LnDoubleFactorial()}: Returns the logarithm of the double factorial. 43 | 44 | \item \code{Log2DoubleFactorial()}: Returns the logarithm of the double factorial. 45 | 46 | \item \code{LnDoubleFactorial.int()}: Slightly faster, when x is known to be length one 47 | and below 50001 48 | 49 | }} 50 | \examples{ 51 | DoubleFactorial (-4:0) # Return 1 if n < 2 52 | DoubleFactorial (2) # 2 53 | DoubleFactorial (5) # 1 * 3 * 5 54 | exp(LnDoubleFactorial.int (8)) # log(2 * 4 * 6 * 8) 55 | DoubleFactorial64(31) 56 | } 57 | \seealso{ 58 | Other double factorials: 59 | \code{\link{doubleFactorials}}, 60 | \code{\link{logDoubleFactorials}} 61 | } 62 | \author{ 63 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 64 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 65 | } 66 | \concept{double factorials} 67 | -------------------------------------------------------------------------------- /man/EdgeAncestry.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_ancestors.R 3 | \name{EdgeAncestry} 4 | \alias{EdgeAncestry} 5 | \title{Ancestors of an edge} 6 | \usage{ 7 | EdgeAncestry(edge, parent, child, stopAt = (parent == min(parent))) 8 | } 9 | \arguments{ 10 | \item{edge}{Integer specifying the number of the edge whose child edges 11 | should be returned.} 12 | 13 | \item{parent}{Integer vector corresponding to the first column of the edge 14 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 15 | \code{tree[["edge"]][, 1]}} 16 | 17 | \item{child}{Integer vector corresponding to the second column of the edge 18 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 19 | \code{tree[["edge"]][, 2]}.} 20 | 21 | \item{stopAt}{Integer or logical vector specifying the edge(s) at which to 22 | terminate the search; defaults to the edges with the smallest parent, 23 | which will be the root edges if nodes are numbered \link{Cladewise} or in 24 | \link{Preorder}.} 25 | } 26 | \value{ 27 | \code{EdgeAncestry()} returns a logical vector stating whether each edge 28 | in turn is a descendant of the specified edge. 29 | } 30 | \description{ 31 | Quickly identify edges that are "ancestral" to a particular edge in a tree. 32 | } 33 | \examples{ 34 | tree <- PectinateTree(6) 35 | plot(tree) 36 | ape::edgelabels() 37 | parent <- tree$edge[, 1] 38 | child <- tree$edge[, 2] 39 | EdgeAncestry(7, parent, child) 40 | which(EdgeAncestry(7, parent, child, stopAt = 4)) 41 | 42 | } 43 | \seealso{ 44 | Other tree navigation: 45 | \code{\link{AncestorEdge}()}, 46 | \code{\link{CladeSizes}()}, 47 | \code{\link{DescendantEdges}()}, 48 | \code{\link{EdgeDistances}()}, 49 | \code{\link{ListAncestors}()}, 50 | \code{\link{MRCA}()}, 51 | \code{\link{MatchEdges}()}, 52 | \code{\link{NDescendants}()}, 53 | \code{\link{NodeDepth}()}, 54 | \code{\link{NodeNumbers}()}, 55 | \code{\link{NodeOrder}()}, 56 | \code{\link{RootNode}()} 57 | } 58 | \author{ 59 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 60 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 61 | } 62 | \concept{tree navigation} 63 | -------------------------------------------------------------------------------- /man/EdgeDistances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{EdgeDistances} 4 | \alias{EdgeDistances} 5 | \title{Distance between edges} 6 | \usage{ 7 | EdgeDistances(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | \code{EdgeDistances()} returns a symmetrical matrix listing the number 14 | of edges that must be traversed to travel from each numbered edge to each 15 | other. 16 | The two edges straddling the root of a rooted tree 17 | are treated as a single edge. Add a "root" tip using \code{\link[=AddTip]{AddTip()}} if the 18 | position of the root is significant. 19 | } 20 | \description{ 21 | Number of nodes that must be traversed to navigate from each edge to 22 | each other edge within a tree 23 | } 24 | \examples{ 25 | 26 | tree <- BalancedTree(5) 27 | plot(tree) 28 | ape::edgelabels() 29 | 30 | EdgeDistances(tree) 31 | 32 | } 33 | \seealso{ 34 | Other tree navigation: 35 | \code{\link{AncestorEdge}()}, 36 | \code{\link{CladeSizes}()}, 37 | \code{\link{DescendantEdges}()}, 38 | \code{\link{EdgeAncestry}()}, 39 | \code{\link{ListAncestors}()}, 40 | \code{\link{MRCA}()}, 41 | \code{\link{MatchEdges}()}, 42 | \code{\link{NDescendants}()}, 43 | \code{\link{NodeDepth}()}, 44 | \code{\link{NodeNumbers}()}, 45 | \code{\link{NodeOrder}()}, 46 | \code{\link{RootNode}()} 47 | } 48 | \author{ 49 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 50 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 51 | } 52 | \concept{tree navigation} 53 | -------------------------------------------------------------------------------- /man/EndSentence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{EndSentence} 4 | \alias{EndSentence} 5 | \title{Add full stop to end of a sentence} 6 | \usage{ 7 | EndSentence(string) 8 | } 9 | \arguments{ 10 | \item{string}{Input string} 11 | } 12 | \value{ 13 | \code{EndSentence()} returns \code{string}, punctuated with a final full stop 14 | (period).` 15 | } 16 | \description{ 17 | Add full stop to end of a sentence 18 | } 19 | \examples{ 20 | EndSentence("Hello World") # "Hello World." 21 | } 22 | \seealso{ 23 | Other string parsing functions: 24 | \code{\link{MorphoBankDecode}()}, 25 | \code{\link{RightmostCharacter}()}, 26 | \code{\link{Unquote}()} 27 | } 28 | \author{ 29 | Martin R. Smith 30 | } 31 | \concept{string parsing functions} 32 | -------------------------------------------------------------------------------- /man/EnforceOutgroup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_generation.R 3 | \name{EnforceOutgroup} 4 | \alias{EnforceOutgroup} 5 | \alias{EnforceOutgroup.phylo} 6 | \alias{EnforceOutgroup.character} 7 | \title{Generate a tree with a specified outgroup} 8 | \usage{ 9 | EnforceOutgroup(tree, outgroup) 10 | 11 | \method{EnforceOutgroup}{phylo}(tree, outgroup) 12 | 13 | \method{EnforceOutgroup}{character}(tree, outgroup) 14 | } 15 | \arguments{ 16 | \item{tree}{Either a tree of class \code{phylo}; or (for \code{EnforceOutgroup()}) 17 | a character vector listing the names of all the taxa in the tree, from which 18 | a random tree will be generated.} 19 | 20 | \item{outgroup}{Character vector containing the names of taxa to include in 21 | the outgroup.} 22 | } 23 | \value{ 24 | \code{EnforceOutgroup()} returned a tree of class \code{phylo} where all 25 | outgroup taxa are sister to all remaining taxa, without modifying the 26 | ingroup topology. 27 | } 28 | \description{ 29 | \strong{Deprecated.} This function will be removed in a future version of 30 | \pkg{TreeTools}. 31 | Use \code{RootTree()} instead. 32 | } 33 | \details{ 34 | Given a tree or a list of taxa, \code{EnforceOutgroup()} rearranged the ingroup 35 | and outgroup taxa such that the two are sister taxa across the root, without 36 | changing the relationships within the ingroup or within the outgroup. 37 | } 38 | \seealso{ 39 | For a more robust implementation, see \code{\link[=RootTree]{RootTree()}}, which will 40 | eventually replace this function 41 | (\href{https://github.com/ms609/TreeTools/issues/30}{#30}). 42 | 43 | Other tree manipulation: 44 | \code{\link{AddTip}()}, 45 | \code{\link{CollapseNode}()}, 46 | \code{\link{ConsensusWithout}()}, 47 | \code{\link{DropTip}()}, 48 | \code{\link{ImposeConstraint}()}, 49 | \code{\link{KeptPaths}()}, 50 | \code{\link{KeptVerts}()}, 51 | \code{\link{LeafLabelInterchange}()}, 52 | \code{\link{MakeTreeBinary}()}, 53 | \code{\link{Renumber}()}, 54 | \code{\link{RenumberTips}()}, 55 | \code{\link{RenumberTree}()}, 56 | \code{\link{RootTree}()}, 57 | \code{\link{SortTree}()}, 58 | \code{\link{Subtree}()}, 59 | \code{\link{TipTimedTree}()}, 60 | \code{\link{TrivialTree}} 61 | } 62 | \author{ 63 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 64 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 65 | } 66 | \concept{tree manipulation} 67 | -------------------------------------------------------------------------------- /man/ExtractTaxa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{ExtractTaxa} 4 | \alias{ExtractTaxa} 5 | \alias{NexusTokens} 6 | \title{Extract taxa from a matrix block} 7 | \usage{ 8 | ExtractTaxa(matrixLines, character_num = NULL, continuous = FALSE) 9 | 10 | NexusTokens(tokens, character_num = NULL) 11 | } 12 | \arguments{ 13 | \item{matrixLines}{Character vector containing lines of a file that include 14 | a phylogenetic matrix. See \code{\link[=ReadCharacters]{ReadCharacters()}} for expected format.} 15 | 16 | \item{character_num}{Index of character(s) to return. 17 | \code{NULL}, the default, returns all characters.} 18 | 19 | \item{continuous}{Logical specifying whether characters are continuous. 20 | Treated as discrete if \code{FALSE}.} 21 | 22 | \item{tokens}{Vector of character strings corresponding to phylogenetic 23 | tokens.} 24 | } 25 | \value{ 26 | \code{ExtractTaxa()} returns a matrix with \emph{n} rows, each named for the 27 | relevant taxon, and \emph{c} columns, 28 | each corresponding to the respective character specified in \code{character_num}. 29 | 30 | \code{NexusTokens()} returns a character vector in which each entry 31 | corresponds to the states of a phylogenetic character, or a list containing 32 | an error message if input is invalid. 33 | } 34 | \description{ 35 | Extract leaf labels and character states from a Nexus-formatted matrix. 36 | } 37 | \examples{ 38 | fileName <- paste0(system.file(package = "TreeTools"), 39 | "/extdata/input/dataset.nex") 40 | matrixLines <- readLines(fileName)[6:11] 41 | ExtractTaxa(matrixLines) 42 | 43 | NexusTokens("01[01]-?") 44 | } 45 | \keyword{internal} 46 | -------------------------------------------------------------------------------- /man/KeptPaths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/KeptPaths.R 3 | \name{KeptPaths} 4 | \alias{KeptPaths} 5 | \alias{KeptPaths.data.frame} 6 | \alias{KeptPaths.matrix} 7 | \title{Paths present in reduced tree} 8 | \usage{ 9 | KeptPaths(paths, keptVerts, all = TRUE) 10 | 11 | \method{KeptPaths}{data.frame}(paths, keptVerts, all = TRUE) 12 | 13 | \method{KeptPaths}{matrix}(paths, keptVerts, all = TRUE) 14 | } 15 | \arguments{ 16 | \item{paths}{\code{data.frame} of paths in master tree, perhaps generated using 17 | \code{\link[=PathLengths]{PathLengths()}}.} 18 | 19 | \item{keptVerts}{Logical specifying whether each entry is retained in the 20 | reduced tree, perhaps generated using \code{\link[=KeptVerts]{KeptVerts()}}.} 21 | 22 | \item{all}{Logical: if \code{TRUE}, return all paths that occur in the reduced 23 | tree; if \code{FALSE}, return only those paths that correspond to a single edge. 24 | that correspond to edges in the reduced tree. 25 | Ignored if \code{paths} is a matrix.} 26 | } 27 | \value{ 28 | \code{KeptPaths()} returns a logical vector specifying whether each path 29 | in \code{paths} occurs when \code{keptVerts} vertices are retained. 30 | } 31 | \description{ 32 | Lists which paths present in a master tree are present when leaves are 33 | dropped. 34 | } 35 | \examples{ 36 | master <- BalancedTree(9) 37 | paths <- PathLengths(master) 38 | keptTips <- c(1, 5, 7, 9) 39 | keptVerts <- KeptVerts(master, keptTips) 40 | KeptPaths(paths, keptVerts) 41 | paths[KeptPaths(paths, keptVerts, all = FALSE), ] 42 | } 43 | \seealso{ 44 | Other tree manipulation: 45 | \code{\link{AddTip}()}, 46 | \code{\link{CollapseNode}()}, 47 | \code{\link{ConsensusWithout}()}, 48 | \code{\link{DropTip}()}, 49 | \code{\link{EnforceOutgroup}()}, 50 | \code{\link{ImposeConstraint}()}, 51 | \code{\link{KeptVerts}()}, 52 | \code{\link{LeafLabelInterchange}()}, 53 | \code{\link{MakeTreeBinary}()}, 54 | \code{\link{Renumber}()}, 55 | \code{\link{RenumberTips}()}, 56 | \code{\link{RenumberTree}()}, 57 | \code{\link{RootTree}()}, 58 | \code{\link{SortTree}()}, 59 | \code{\link{Subtree}()}, 60 | \code{\link{TipTimedTree}()}, 61 | \code{\link{TrivialTree}} 62 | } 63 | \author{ 64 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 65 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 66 | } 67 | \concept{tree manipulation} 68 | -------------------------------------------------------------------------------- /man/LeafLabelInterchange.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_rearrangement.R 3 | \name{LeafLabelInterchange} 4 | \alias{LeafLabelInterchange} 5 | \title{Leaf label interchange} 6 | \usage{ 7 | LeafLabelInterchange(tree, n = 2L) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | 12 | \item{n}{Integer specifying number of leaves whose positions should be 13 | exchanged.} 14 | } 15 | \value{ 16 | \code{LeafLabelInterchange()} returns a tree of class \code{phylo} on which 17 | the position of \code{n} leaves have been exchanged. 18 | The tree's internal topology will not change. 19 | } 20 | \description{ 21 | \code{LeafLabelInterchange()} exchanges the position of leaves within a tree. 22 | } 23 | \details{ 24 | Modifies a tree by switching the positions of \emph{n} leaves. To avoid 25 | later swaps undoing earlier exchanges, all \emph{n} leaves are guaranteed 26 | to change position. Note, however, that no attempt is made to avoid 27 | swapping equivalent leaves, for example, a pair that are each others' 28 | closest relatives. As such, the relationships within a tree are not 29 | guaranteed to be changed. 30 | } 31 | \examples{ 32 | tree <- PectinateTree(8) 33 | plot(LeafLabelInterchange(tree, 3L)) 34 | 35 | } 36 | \seealso{ 37 | Other tree manipulation: 38 | \code{\link{AddTip}()}, 39 | \code{\link{CollapseNode}()}, 40 | \code{\link{ConsensusWithout}()}, 41 | \code{\link{DropTip}()}, 42 | \code{\link{EnforceOutgroup}()}, 43 | \code{\link{ImposeConstraint}()}, 44 | \code{\link{KeptPaths}()}, 45 | \code{\link{KeptVerts}()}, 46 | \code{\link{MakeTreeBinary}()}, 47 | \code{\link{Renumber}()}, 48 | \code{\link{RenumberTips}()}, 49 | \code{\link{RenumberTree}()}, 50 | \code{\link{RootTree}()}, 51 | \code{\link{SortTree}()}, 52 | \code{\link{Subtree}()}, 53 | \code{\link{TipTimedTree}()}, 54 | \code{\link{TrivialTree}} 55 | } 56 | \author{ 57 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 58 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 59 | } 60 | \concept{tree manipulation} 61 | -------------------------------------------------------------------------------- /man/Lobo.data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{Lobo.data} 5 | \alias{Lobo.data} 6 | \alias{Lobo.phy} 7 | \title{Data from Zhang et al. 2016} 8 | \format{ 9 | An object of class \code{list} of length 48. 10 | 11 | An object of class \code{phyDat} of length 48. 12 | } 13 | \source{ 14 | \insertCite{Zhang2016;textual}{TreeTools} 15 | } 16 | \usage{ 17 | Lobo.data 18 | 19 | Lobo.phy 20 | } 21 | \description{ 22 | Phylogenetic data from \insertCite{Zhang2016;textual}{TreeTools} in raw 23 | (\code{Lobo.data}) and \code{phyDat} (\code{Lobo.phy}) formats. 24 | } 25 | \examples{ 26 | data("Lobo", package = "TreeTools") 27 | Lobo.data 28 | Lobo.phy 29 | } 30 | \references{ 31 | \insertAllCited{} 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/MRCA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_ancestors.R 3 | \name{MRCA} 4 | \alias{MRCA} 5 | \title{Most recent common ancestor} 6 | \usage{ 7 | MRCA(x1, x2, ancestors) 8 | } 9 | \arguments{ 10 | \item{x1, x2}{Integer specifying index of leaves or nodes whose most 11 | recent common ancestor should be found.} 12 | 13 | \item{ancestors}{List of ancestors for each node in a tree. Perhaps 14 | produced by \code{\link[=ListAncestors]{ListAncestors()}}.} 15 | } 16 | \value{ 17 | \code{MRCA()} returns an integer specifying the node number of the last 18 | common ancestor of \code{x1} and \code{x2}. 19 | } 20 | \description{ 21 | \code{MRCA()} calculates the last common ancestor of specified nodes. 22 | } 23 | \details{ 24 | \code{MRCA()} requires that node values within a tree increase away from the root, 25 | which will be true of trees listed in \code{Preorder}. 26 | No warnings will be given if trees do not fulfil this requirement. 27 | } 28 | \examples{ 29 | tree <- BalancedTree(7) 30 | 31 | # Verify that node numbering increases away from root 32 | plot(tree) 33 | nodelabels() 34 | 35 | # ListAncestors expects a tree in Preorder 36 | tree <- Preorder(tree) 37 | edge <- tree$edge 38 | ancestors <- ListAncestors(edge[, 1], edge[, 2]) 39 | MRCA(1, 4, ancestors) 40 | 41 | # If a tree must be in postorder, use: 42 | tree <- Postorder(tree) 43 | edge <- tree$edge 44 | ancestors <- lapply(seq_len(max(edge)), ListAncestors, 45 | parent = edge[, 1], child = edge[, 2]) 46 | 47 | } 48 | \seealso{ 49 | Other tree navigation: 50 | \code{\link{AncestorEdge}()}, 51 | \code{\link{CladeSizes}()}, 52 | \code{\link{DescendantEdges}()}, 53 | \code{\link{EdgeAncestry}()}, 54 | \code{\link{EdgeDistances}()}, 55 | \code{\link{ListAncestors}()}, 56 | \code{\link{MatchEdges}()}, 57 | \code{\link{NDescendants}()}, 58 | \code{\link{NodeDepth}()}, 59 | \code{\link{NodeNumbers}()}, 60 | \code{\link{NodeOrder}()}, 61 | \code{\link{RootNode}()} 62 | } 63 | \author{ 64 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 65 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 66 | } 67 | \concept{tree navigation} 68 | -------------------------------------------------------------------------------- /man/MakeTreeBinary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_rearrangement.R 3 | \name{MakeTreeBinary} 4 | \alias{MakeTreeBinary} 5 | \title{Generate binary tree by collapsing polytomies} 6 | \usage{ 7 | MakeTreeBinary(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | \code{MakeTreeBinary()} returns a rooted binary tree of class \code{phylo}, 14 | corresponding to tree uniformly selected from all those compatible with 15 | the input tree topologies. 16 | } 17 | \description{ 18 | \code{MakeTreeBinary()} resolves, at random, all polytomies in a tree or set of 19 | trees, such that all trees compatible with the input topology are drawn 20 | with equal probability. 21 | } 22 | \examples{ 23 | MakeTreeBinary(CollapseNode(PectinateTree(7), c(9, 11, 13))) 24 | UnrootTree(MakeTreeBinary(StarTree(5))) 25 | } 26 | \seealso{ 27 | Since ape v5.5, this functionality is available through 28 | \code{\link[ape:multi2di]{ape::multi2di()}}; previous versions of "ape" did not return topologies 29 | in equal frequencies. 30 | 31 | Other tree manipulation: 32 | \code{\link{AddTip}()}, 33 | \code{\link{CollapseNode}()}, 34 | \code{\link{ConsensusWithout}()}, 35 | \code{\link{DropTip}()}, 36 | \code{\link{EnforceOutgroup}()}, 37 | \code{\link{ImposeConstraint}()}, 38 | \code{\link{KeptPaths}()}, 39 | \code{\link{KeptVerts}()}, 40 | \code{\link{LeafLabelInterchange}()}, 41 | \code{\link{Renumber}()}, 42 | \code{\link{RenumberTips}()}, 43 | \code{\link{RenumberTree}()}, 44 | \code{\link{RootTree}()}, 45 | \code{\link{SortTree}()}, 46 | \code{\link{Subtree}()}, 47 | \code{\link{TipTimedTree}()}, 48 | \code{\link{TrivialTree}} 49 | } 50 | \author{ 51 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 52 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 53 | } 54 | \concept{tree manipulation} 55 | -------------------------------------------------------------------------------- /man/MatchEdges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MatchNodes.R 3 | \name{MatchEdges} 4 | \alias{MatchEdges} 5 | \alias{MatchNodes} 6 | \title{Match nodes and edges between trees} 7 | \usage{ 8 | MatchEdges(x, table, nomatch = NA_integer_) 9 | 10 | MatchNodes(x, table, nomatch = NA_integer_, tips = FALSE) 11 | } 12 | \arguments{ 13 | \item{x}{Tree whose nodes are to be matched.} 14 | 15 | \item{table}{Tree containing nodes to be matched against.} 16 | 17 | \item{nomatch}{Integer value that will be used in place of \code{NA} in the case 18 | where no match is found.} 19 | 20 | \item{tips}{Logical specifying whether to return matches for tips; 21 | unless \code{TRUE}, only the matches for internal nodes will be returned.} 22 | } 23 | \description{ 24 | \code{MatchNodes()} and \code{MatchEdges()} matches nodes or edges in one tree to 25 | entries in the second that denote a clade with identical tip labels. 26 | } 27 | \details{ 28 | The current implementation is potentially inefficient. 29 | Please contact the maintainer to request a more efficient implementation if 30 | this function is proving a bottleneck. 31 | } 32 | \examples{ 33 | MatchNodes(BalancedTree(8), RootTree(BalancedTree(8))) 34 | } 35 | \seealso{ 36 | Other tree navigation: 37 | \code{\link{AncestorEdge}()}, 38 | \code{\link{CladeSizes}()}, 39 | \code{\link{DescendantEdges}()}, 40 | \code{\link{EdgeAncestry}()}, 41 | \code{\link{EdgeDistances}()}, 42 | \code{\link{ListAncestors}()}, 43 | \code{\link{MRCA}()}, 44 | \code{\link{NDescendants}()}, 45 | \code{\link{NodeDepth}()}, 46 | \code{\link{NodeNumbers}()}, 47 | \code{\link{NodeOrder}()}, 48 | \code{\link{RootNode}()} 49 | 50 | Other tree properties: 51 | \code{\link{ConsensusWithout}()}, 52 | \code{\link{NSplits}()}, 53 | \code{\link{NTip}()}, 54 | \code{\link{NodeNumbers}()}, 55 | \code{\link{PathLengths}()}, 56 | \code{\link{SplitsInBinaryTree}()}, 57 | \code{\link{TipLabels}()}, 58 | \code{\link{TreeIsRooted}()} 59 | } 60 | \author{ 61 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 62 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 63 | } 64 | \concept{tree navigation} 65 | \concept{tree properties} 66 | -------------------------------------------------------------------------------- /man/MorphoBankDecode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{MorphoBankDecode} 4 | \alias{MorphoBankDecode} 5 | \title{Decode MorphoBank text} 6 | \usage{ 7 | MorphoBankDecode(string) 8 | } 9 | \arguments{ 10 | \item{string}{String to process} 11 | } 12 | \value{ 13 | \code{MorphoBankDecode()} returns a string with new lines and punctuation 14 | reformatted. 15 | } 16 | \description{ 17 | Converts strings from MorphoBank notes into a Latex-compatible format. 18 | } 19 | \seealso{ 20 | Other string parsing functions: 21 | \code{\link{EndSentence}()}, 22 | \code{\link{RightmostCharacter}()}, 23 | \code{\link{Unquote}()} 24 | } 25 | \author{ 26 | Martin R. Smith 27 | } 28 | \concept{string parsing functions} 29 | -------------------------------------------------------------------------------- /man/N1Spr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Combinatorics.R 3 | \name{N1Spr} 4 | \alias{N1Spr} 5 | \alias{IC1Spr} 6 | \title{Number of trees one SPR step away} 7 | \usage{ 8 | N1Spr(n) 9 | 10 | IC1Spr(n) 11 | } 12 | \arguments{ 13 | \item{n}{Integer vector specifying the number of tips in a tree.} 14 | } 15 | \value{ 16 | \code{N1Spr()} returns an integer vector denoting the number of trees one 17 | SPR rearrangement away from the input tree.. 18 | 19 | \code{IC1Spr()} returns an numeric vector giving the phylogenetic 20 | information content of trees 0 or 1 SPR rearrangement from an \emph{n}-leaf tree, 21 | in bits. 22 | } 23 | \description{ 24 | \code{N1Spr()} calculates the number of trees one subtree prune-and-regraft 25 | operation away from a binary input tree using the formula given by 26 | \insertCite{Allen2001;textual}{TreeTools}; 27 | \code{IC1Spr()} calculates the information content of trees at this 28 | distance: i.e. the entropy corresponding to the proportion of all possible 29 | \emph{n}-tip trees whose SPR distance is at most one from a specified tree. 30 | } 31 | \examples{ 32 | N1Spr(4:6) 33 | IC1Spr(5) 34 | 35 | } 36 | \references{ 37 | \insertAllCited{} 38 | } 39 | -------------------------------------------------------------------------------- /man/NDescendants.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_descendants.R 3 | \name{NDescendants} 4 | \alias{NDescendants} 5 | \title{Count descendants for each node in a tree} 6 | \usage{ 7 | NDescendants(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | \code{NDescendants()} returns an integer listing the number of direct 14 | descendants (leaves or internal nodes) for each node in a tree. 15 | } 16 | \description{ 17 | \code{NDescendants()} counts the number of nodes (including leaves) directly 18 | descended from each node in a tree. 19 | } 20 | \examples{ 21 | tree <- CollapseNode(BalancedTree(8), 12:15) 22 | NDescendants(tree) 23 | plot(tree) 24 | nodelabels(NDescendants(tree)) 25 | 26 | } 27 | \seealso{ 28 | Other tree navigation: 29 | \code{\link{AncestorEdge}()}, 30 | \code{\link{CladeSizes}()}, 31 | \code{\link{DescendantEdges}()}, 32 | \code{\link{EdgeAncestry}()}, 33 | \code{\link{EdgeDistances}()}, 34 | \code{\link{ListAncestors}()}, 35 | \code{\link{MRCA}()}, 36 | \code{\link{MatchEdges}()}, 37 | \code{\link{NodeDepth}()}, 38 | \code{\link{NodeNumbers}()}, 39 | \code{\link{NodeOrder}()}, 40 | \code{\link{RootNode}()} 41 | } 42 | \author{ 43 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 44 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 45 | } 46 | \concept{tree navigation} 47 | -------------------------------------------------------------------------------- /man/NJTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_generation.R 3 | \name{NJTree} 4 | \alias{NJTree} 5 | \title{Generate a neighbour joining tree} 6 | \usage{ 7 | NJTree(dataset, edgeLengths = FALSE, ratio = TRUE, ambig = "mean") 8 | } 9 | \arguments{ 10 | \item{dataset}{A phylogenetic data matrix of \pkg{phangorn} class \code{phyDat}, 11 | whose names correspond to the labels of any accompanying tree.} 12 | 13 | \item{edgeLengths}{Logical specifying whether to include edge lengths.} 14 | 15 | \item{ambig, ratio}{Settings of \code{ambig} and \code{ratio} to be used when 16 | computing \code{\link[=Hamming]{Hamming()}} distances between sequences.} 17 | } 18 | \value{ 19 | \code{NJTree} returns an object of class \code{phylo}. 20 | } 21 | \description{ 22 | \code{NJTree()} generates a rooted neighbour joining tree from a phylogenetic 23 | dataset. 24 | } 25 | \examples{ 26 | data("Lobo") 27 | NJTree(Lobo.phy) 28 | 29 | } 30 | \seealso{ 31 | Other tree generation functions: 32 | \code{\link{ConstrainedNJ}()}, 33 | \code{\link{GenerateTree}}, 34 | \code{\link{TreeNumber}}, 35 | \code{\link{TrivialTree}} 36 | } 37 | \author{ 38 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 39 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 40 | } 41 | \concept{tree generation functions} 42 | -------------------------------------------------------------------------------- /man/NPartitionPairs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SplitFunctions.R 3 | \name{NPartitionPairs} 4 | \alias{NPartitionPairs} 5 | \title{Distributions of tips consistent with a partition pair} 6 | \usage{ 7 | NPartitionPairs(configuration) 8 | } 9 | \arguments{ 10 | \item{configuration}{Integer vector of length four specifying the number of 11 | terminals that occur in both 12 | (1) splits A1 and A2; 13 | (2) splits A1 and B2; 14 | (3) splits B1 and A2; 15 | (4) splits B1 and B2.} 16 | } 17 | \value{ 18 | The number of ways to distribute \code{sum(configuration)} taxa according 19 | to the specified pattern. 20 | } 21 | \description{ 22 | \code{NPartitionPairs()} calculates the number of terminal arrangements matching 23 | a specified configuration of two splits. 24 | } 25 | \details{ 26 | Consider splits that divide eight terminals, labelled A to H. 27 | 28 | \tabular{rcll}{ 29 | Bipartition 1:\tab ABCD:EFGH\tab A1 = ABCD\tab B1 = EFGH \cr 30 | Bipartition 2:\tab ABE:CDFGH\tab A2 = ABE\tab B2 = CDFGH 31 | } 32 | 33 | This can be represented by an association matrix: 34 | 35 | \tabular{rll}{ 36 | \tab \emph{A2} \tab \emph{B2} \cr 37 | \emph{A1} \tab AB \tab C \cr 38 | \emph{B1} \tab E \tab FGH 39 | } 40 | 41 | The cells in this matrix contain 2, 1, 1 and 3 terminals respectively; this 42 | four-element vector (\code{c(2, 1, 1, 3)}) is the \code{configuration} implied by 43 | this pair of bipartition splits. 44 | } 45 | \examples{ 46 | NPartitionPairs(c(2, 1, 1, 3)) 47 | } 48 | \author{ 49 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 50 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 51 | } 52 | -------------------------------------------------------------------------------- /man/NSplits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{NSplits} 4 | \alias{NSplits} 5 | \alias{NPartitions} 6 | \alias{NSplits.phylo} 7 | \alias{NSplits.list} 8 | \alias{NSplits.multiPhylo} 9 | \alias{NSplits.Splits} 10 | \alias{NSplits.numeric} 11 | \alias{NSplits.NULL} 12 | \alias{NSplits.ClusterTable} 13 | \alias{NSplits.character} 14 | \title{Number of distinct splits} 15 | \usage{ 16 | NSplits(x) 17 | 18 | NPartitions(x) 19 | 20 | \method{NSplits}{phylo}(x) 21 | 22 | \method{NSplits}{list}(x) 23 | 24 | \method{NSplits}{multiPhylo}(x) 25 | 26 | \method{NSplits}{Splits}(x) 27 | 28 | \method{NSplits}{numeric}(x) 29 | 30 | \method{NSplits}{`NULL`}(x) 31 | 32 | \method{NSplits}{ClusterTable}(x) 33 | 34 | \method{NSplits}{character}(x) 35 | } 36 | \arguments{ 37 | \item{x}{A phylogenetic tree of class \code{phylo}; a list of such trees 38 | (of class \code{list} or \code{multiPhylo}); a \code{Splits} object; 39 | a vector of integers; or a character vector listing tips of a tree, 40 | or a character of length one specifying a tree in Newick format.} 41 | } 42 | \value{ 43 | \code{NSplits()} returns an integer specifying the number of bipartitions in 44 | the specified objects, or in a binary tree with \code{x} tips. 45 | } 46 | \description{ 47 | \code{NSplits()} counts the unique bipartition splits in a tree or object. 48 | } 49 | \examples{ 50 | NSplits(8L) 51 | NSplits(PectinateTree(8)) 52 | NSplits(as.Splits(BalancedTree(8))) 53 | } 54 | \seealso{ 55 | Other tree properties: 56 | \code{\link{ConsensusWithout}()}, 57 | \code{\link{MatchEdges}()}, 58 | \code{\link{NTip}()}, 59 | \code{\link{NodeNumbers}()}, 60 | \code{\link{PathLengths}()}, 61 | \code{\link{SplitsInBinaryTree}()}, 62 | \code{\link{TipLabels}()}, 63 | \code{\link{TreeIsRooted}()} 64 | 65 | Other Splits operations: 66 | \code{\link{LabelSplits}()}, 67 | \code{\link{NTip}()}, 68 | \code{\link{PolarizeSplits}()}, 69 | \code{\link{SplitFrequency}()}, 70 | \code{\link{Splits}}, 71 | \code{\link{SplitsInBinaryTree}()}, 72 | \code{\link{TipLabels}()}, 73 | \code{\link{TipsInSplits}()}, 74 | \code{\link{match,Splits,Splits-method}}, 75 | \code{\link{xor}()} 76 | } 77 | \author{ 78 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 79 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 80 | } 81 | \concept{Splits operations} 82 | \concept{tree properties} 83 | -------------------------------------------------------------------------------- /man/NTip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{NTip} 4 | \alias{NTip} 5 | \alias{NTip.default} 6 | \alias{NTip.Splits} 7 | \alias{NTip.list} 8 | \alias{NTip.phylo} 9 | \alias{NTip.multiPhylo} 10 | \alias{NTip.phyDat} 11 | \alias{NTip.matrix} 12 | \title{Number of leaves in a phylogenetic tree} 13 | \usage{ 14 | NTip(phy) 15 | 16 | \method{NTip}{default}(phy) 17 | 18 | \method{NTip}{Splits}(phy) 19 | 20 | \method{NTip}{list}(phy) 21 | 22 | \method{NTip}{phylo}(phy) 23 | 24 | \method{NTip}{multiPhylo}(phy) 25 | 26 | \method{NTip}{phyDat}(phy) 27 | 28 | \method{NTip}{matrix}(phy) 29 | } 30 | \arguments{ 31 | \item{phy}{Object representing one or more phylogenetic trees.} 32 | } 33 | \value{ 34 | \code{NTip()} returns an integer specifying the number of tips in each 35 | object in \code{phy}. 36 | } 37 | \description{ 38 | \code{NTip()} extends \code{\link[ape:summary.phylo]{ape::Ntip()}} to handle 39 | objects of class \code{Splits} and \code{list}, and edge matrices 40 | (equivalent to \code{tree$edge}). 41 | } 42 | \seealso{ 43 | Other tree properties: 44 | \code{\link{ConsensusWithout}()}, 45 | \code{\link{MatchEdges}()}, 46 | \code{\link{NSplits}()}, 47 | \code{\link{NodeNumbers}()}, 48 | \code{\link{PathLengths}()}, 49 | \code{\link{SplitsInBinaryTree}()}, 50 | \code{\link{TipLabels}()}, 51 | \code{\link{TreeIsRooted}()} 52 | 53 | Other Splits operations: 54 | \code{\link{LabelSplits}()}, 55 | \code{\link{NSplits}()}, 56 | \code{\link{PolarizeSplits}()}, 57 | \code{\link{SplitFrequency}()}, 58 | \code{\link{Splits}}, 59 | \code{\link{SplitsInBinaryTree}()}, 60 | \code{\link{TipLabels}()}, 61 | \code{\link{TipsInSplits}()}, 62 | \code{\link{match,Splits,Splits-method}}, 63 | \code{\link{xor}()} 64 | } 65 | \concept{Splits operations} 66 | \concept{tree properties} 67 | -------------------------------------------------------------------------------- /man/NewickTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{NewickTree} 4 | \alias{NewickTree} 5 | \title{Write Newick Tree} 6 | \usage{ 7 | NewickTree(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | \code{NewickTree()} returns a character string denoting \code{tree} in Newick 14 | format. 15 | } 16 | \description{ 17 | \code{NewickTree()} encodes a tree as a Newick-format string. 18 | This differs from \code{\link[ape:write.tree]{write.tree()}} in the encoding of 19 | spaces as spaces, rather than underscores. 20 | } 21 | \examples{ 22 | NewickTree(BalancedTree(LETTERS[4:9])) 23 | 24 | } 25 | \seealso{ 26 | Use tip numbers, rather than leaf labels: \code{\link{as.Newick}} 27 | } 28 | -------------------------------------------------------------------------------- /man/Neworder.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_numbering.R 3 | \name{Neworder} 4 | \alias{Neworder} 5 | \alias{NeworderPruningwise} 6 | \alias{NeworderPhylo} 7 | \title{Reorder edges of a phylogenetic tree} 8 | \usage{ 9 | NeworderPruningwise(nTip, nNode, parent, child, nEdge) 10 | 11 | NeworderPhylo(nTip, parent, child, nEdge, whichwise) 12 | } 13 | \arguments{ 14 | \item{nTip, nNode, nEdge}{Integer specifying the number of tips, nodes 15 | and edges in the input tree.} 16 | 17 | \item{parent}{Integer vector corresponding to the first column of the edge 18 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 19 | \code{tree[["edge"]][, 1]}} 20 | 21 | \item{child}{Integer vector corresponding to the second column of the edge 22 | matrix of a tree of class \code{\link[ape]{phylo}}, i.e. 23 | \code{tree[["edge"]][, 2]}.} 24 | 25 | \item{whichwise}{Integer specifying whether to order edges (1) 26 | cladewise; or (2) in postorder.} 27 | } 28 | \value{ 29 | \code{NeworderPruningwise} returns an integer vector specifying the 30 | pruningwise order of edges within a tree. 31 | 32 | \code{NeworderPhylo} returns an integer vector specifying the order 33 | of edges under the ordering sequence specified by \code{whichwise}. 34 | } 35 | \description{ 36 | Wrappers for the C functions called by 37 | \code{ape::\link[ape:reorder.phylo]{reorder.phylo}}. 38 | These call the C functions directly, so are faster -- but don't perform 39 | as many checks on user input. Bad input could crash R. 40 | } 41 | \examples{ 42 | nTip <- 8L 43 | tree <- BalancedTree(nTip) 44 | edge <- tree[["edge"]] 45 | pruningwise <- NeworderPruningwise(nTip, tree$Nnode, edge[, 1], edge[, 2], 46 | dim(edge)[1]) 47 | cladewise <- NeworderPhylo(nTip, edge[, 1], edge[, 2], dim(edge)[1], 1L) 48 | postorder <- NeworderPhylo(nTip, edge[, 1], edge[, 2], dim(edge)[1], 2L) 49 | 50 | tree[["edge"]] <- tree[["edge"]][pruningwise, ] 51 | 52 | } 53 | \seealso{ 54 | Other C wrappers: 55 | \code{\link{RenumberTree}()} 56 | } 57 | \author{ 58 | \itemize{ 59 | \item C algorithm: Emmanuel Paradis 60 | \item R wrapper: Martin R. Smith 61 | } 62 | } 63 | \concept{C wrappers} 64 | \keyword{internal} 65 | -------------------------------------------------------------------------------- /man/NodeDepth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{NodeDepth} 4 | \alias{NodeDepth} 5 | \title{Distance of each node from tree exterior} 6 | \usage{ 7 | NodeDepth(x, shortest = FALSE, includeTips = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{A tree of class \code{phylo}, its \verb{$edge} property, or a list thereof.} 11 | 12 | \item{shortest}{Logical specifying whether to calculate the length of the 13 | shortest away-from-root path to a leaf. If \code{FALSE}, the length of the 14 | longest such route will be returned.} 15 | 16 | \item{includeTips}{Logical specifying whether to include leaves 17 | (each of depth zero) in return value.} 18 | } 19 | \value{ 20 | \code{NodeDepth()} returns an integer vector specifying the depth of 21 | each external and internal node in \code{x}. 22 | } 23 | \description{ 24 | \code{NodeDepth()} evaluates how "deep" each node is within a tree. 25 | } 26 | \details{ 27 | For a rooted tree, the depth of a node is the minimum (if \code{shortest = TRUE}) 28 | or maximum (\code{shortest = FALSE}) number of edges that must be traversed, 29 | moving away from the root, to reach a leaf. 30 | 31 | Unrooted trees are treated as if a root node occurs in the "middle" of the 32 | tree, meaning the position that will minimise the maximum node depth. 33 | } 34 | \examples{ 35 | tree <- CollapseNode(BalancedTree(10), c(12:13, 19)) 36 | plot(tree) 37 | nodelabels(NodeDepth(tree, includeTips = FALSE)) 38 | 39 | 40 | } 41 | \seealso{ 42 | \code{\link[ape:node.depth]{ape::node.depth}} returns the number of tips descended from a 43 | node. 44 | 45 | Other tree navigation: 46 | \code{\link{AncestorEdge}()}, 47 | \code{\link{CladeSizes}()}, 48 | \code{\link{DescendantEdges}()}, 49 | \code{\link{EdgeAncestry}()}, 50 | \code{\link{EdgeDistances}()}, 51 | \code{\link{ListAncestors}()}, 52 | \code{\link{MRCA}()}, 53 | \code{\link{MatchEdges}()}, 54 | \code{\link{NDescendants}()}, 55 | \code{\link{NodeNumbers}()}, 56 | \code{\link{NodeOrder}()}, 57 | \code{\link{RootNode}()} 58 | } 59 | \author{ 60 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 61 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 62 | } 63 | \concept{tree navigation} 64 | -------------------------------------------------------------------------------- /man/NodeNumbers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{NodeNumbers} 4 | \alias{NodeNumbers} 5 | \title{Numeric index of each node in a tree 6 | \code{NodeNumbers()} returns a sequence corresponding to the nodes in a tree} 7 | \usage{ 8 | NodeNumbers(tree, tips = FALSE) 9 | } 10 | \arguments{ 11 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 12 | 13 | \item{tips}{Logical specifying whether to also include the indices of leaves.} 14 | } 15 | \value{ 16 | \code{NodeNumbers()} returns an integer vector corresponding to the 17 | indices of nodes within a tree. 18 | } 19 | \description{ 20 | Numeric index of each node in a tree 21 | \code{NodeNumbers()} returns a sequence corresponding to the nodes in a tree 22 | } 23 | \seealso{ 24 | Other tree properties: 25 | \code{\link{ConsensusWithout}()}, 26 | \code{\link{MatchEdges}()}, 27 | \code{\link{NSplits}()}, 28 | \code{\link{NTip}()}, 29 | \code{\link{PathLengths}()}, 30 | \code{\link{SplitsInBinaryTree}()}, 31 | \code{\link{TipLabels}()}, 32 | \code{\link{TreeIsRooted}()} 33 | 34 | Other tree navigation: 35 | \code{\link{AncestorEdge}()}, 36 | \code{\link{CladeSizes}()}, 37 | \code{\link{DescendantEdges}()}, 38 | \code{\link{EdgeAncestry}()}, 39 | \code{\link{EdgeDistances}()}, 40 | \code{\link{ListAncestors}()}, 41 | \code{\link{MRCA}()}, 42 | \code{\link{MatchEdges}()}, 43 | \code{\link{NDescendants}()}, 44 | \code{\link{NodeDepth}()}, 45 | \code{\link{NodeOrder}()}, 46 | \code{\link{RootNode}()} 47 | } 48 | \author{ 49 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 50 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 51 | } 52 | \concept{tree navigation} 53 | \concept{tree properties} 54 | -------------------------------------------------------------------------------- /man/NodeOrder.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{NodeOrder} 4 | \alias{NodeOrder} 5 | \title{Number of edges incident to each node in a tree} 6 | \usage{ 7 | NodeOrder(x, includeAncestor = TRUE, internalOnly = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{A tree of class \code{phylo}, its \verb{$edge} property, or a list thereof.} 11 | 12 | \item{includeAncestor}{Logical specifying whether to count edge leading to 13 | ancestral node in calculation of order.} 14 | 15 | \item{internalOnly}{Logical specifying whether to restrict to results 16 | to internal nodes, i.e. to omit leaves. Irrelevant if 17 | \code{includeAncestor = FALSE}.} 18 | } 19 | \value{ 20 | \code{NodeOrder()} returns an integer listing the order of each node; 21 | entries are named with the number of each node. 22 | } 23 | \description{ 24 | \code{NodeOrder()} calculates the order of each node: the number of edges 25 | incident to it in a tree. 26 | This value includes the root edge in rooted trees. 27 | } 28 | \examples{ 29 | tree <- CollapseNode(BalancedTree(8), 12:15) 30 | NodeOrder(tree) 31 | plot(tree) 32 | nodelabels(NodeOrder(tree, internalOnly = TRUE)) 33 | 34 | } 35 | \seealso{ 36 | Other tree navigation: 37 | \code{\link{AncestorEdge}()}, 38 | \code{\link{CladeSizes}()}, 39 | \code{\link{DescendantEdges}()}, 40 | \code{\link{EdgeAncestry}()}, 41 | \code{\link{EdgeDistances}()}, 42 | \code{\link{ListAncestors}()}, 43 | \code{\link{MRCA}()}, 44 | \code{\link{MatchEdges}()}, 45 | \code{\link{NDescendants}()}, 46 | \code{\link{NodeDepth}()}, 47 | \code{\link{NodeNumbers}()}, 48 | \code{\link{RootNode}()} 49 | } 50 | \author{ 51 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 52 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 53 | } 54 | \concept{tree navigation} 55 | -------------------------------------------------------------------------------- /man/PairwiseDistances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_comparison.R 3 | \name{PairwiseDistances} 4 | \alias{PairwiseDistances} 5 | \title{Distances between each pair of trees} 6 | \usage{ 7 | PairwiseDistances(trees, Func, valueLength = 1L, ...) 8 | } 9 | \arguments{ 10 | \item{trees}{List of trees of class \code{phylo}.} 11 | 12 | \item{Func}{Function returning a distance between two trees.} 13 | 14 | \item{valueLength}{Integer specifying expected length of the value returned 15 | by \code{Func}.} 16 | 17 | \item{\dots}{Additional arguments to \code{Func}.} 18 | } 19 | \value{ 20 | Matrix detailing distance between each pair of trees. 21 | Identical trees are assumed to have zero distance. 22 | } 23 | \description{ 24 | Distances between each pair of trees 25 | } 26 | \examples{ 27 | trees <- list(BalancedTree(8), PectinateTree(8), StarTree(8)) 28 | TCIDiff <- function(tree1, tree2) { 29 | TotalCopheneticIndex(tree1) - TotalCopheneticIndex(tree2) 30 | } 31 | PairwiseDistances(trees, TCIDiff, 1) 32 | TCIRange <- function(tree1, tree2) { 33 | range(TotalCopheneticIndex(tree1), TotalCopheneticIndex(tree2)) 34 | } 35 | PairwiseDistances(trees, TCIRange, 2) 36 | } 37 | \author{ 38 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 39 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 40 | } 41 | \concept{pairwise tree distances} 42 | -------------------------------------------------------------------------------- /man/PathLengths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PathLengths.R 3 | \name{PathLengths} 4 | \alias{PathLengths} 5 | \title{Calculate length of paths between each pair of vertices within tree} 6 | \usage{ 7 | PathLengths(tree, fullMatrix = FALSE) 8 | } 9 | \arguments{ 10 | \item{tree}{Original tree of class \code{phylo}, in \code{\link{Preorder}}.} 11 | 12 | \item{fullMatrix}{Logical specifying return format; see "value" section`.} 13 | } 14 | \value{ 15 | If \code{fullMatrix = TRUE}, \code{PathLengths()} returns a square matrix in 16 | which entry \verb{[i, j]} denotes the distance from internal node \code{i} to the 17 | descendant vertex \code{j}. 18 | Vertex pairs without a continuous directed path are denoted \code{NA}. 19 | If \code{fullMatrix = FALSE}, \code{PathLengths()} returns a \code{data.frame} with three 20 | columns: \code{start} lists the deepest node in each path (i.e. that closest 21 | to the root); \code{end} lists the shallowest node (i.e. that closest to a leaf); 22 | \code{length} lists the total length of that path. 23 | } 24 | \description{ 25 | Given a weighted rooted tree \code{tree}, \code{PathLengths()} returns the distance 26 | from each vertex to each of its descendant vertices. 27 | } 28 | \examples{ 29 | tree <- rtree(6) 30 | plot(tree) 31 | add.scale.bar() 32 | nodelabels() 33 | tiplabels() 34 | PathLengths(tree) 35 | } 36 | \seealso{ 37 | Other tree properties: 38 | \code{\link{ConsensusWithout}()}, 39 | \code{\link{MatchEdges}()}, 40 | \code{\link{NSplits}()}, 41 | \code{\link{NTip}()}, 42 | \code{\link{NodeNumbers}()}, 43 | \code{\link{SplitsInBinaryTree}()}, 44 | \code{\link{TipLabels}()}, 45 | \code{\link{TreeIsRooted}()} 46 | } 47 | \author{ 48 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 49 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 50 | } 51 | \concept{tree properties} 52 | -------------------------------------------------------------------------------- /man/PolarizeSplits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Splits.R 3 | \name{PolarizeSplits} 4 | \alias{PolarizeSplits} 5 | \title{Polarize splits on a single taxon} 6 | \usage{ 7 | PolarizeSplits(x, pole = 1L) 8 | } 9 | \arguments{ 10 | \item{x}{Object of class \code{\link{Splits}}.} 11 | 12 | \item{pole}{Numeric or character identifying tip that should polarize each 13 | split.} 14 | } 15 | \value{ 16 | \code{PolarizeSplits()} returns a \code{Splits} object in which \code{pole} is 17 | represented by a zero bit 18 | } 19 | \description{ 20 | Polarize splits on a single taxon 21 | } 22 | \seealso{ 23 | Other Splits operations: 24 | \code{\link{LabelSplits}()}, 25 | \code{\link{NSplits}()}, 26 | \code{\link{NTip}()}, 27 | \code{\link{SplitFrequency}()}, 28 | \code{\link{Splits}}, 29 | \code{\link{SplitsInBinaryTree}()}, 30 | \code{\link{TipLabels}()}, 31 | \code{\link{TipsInSplits}()}, 32 | \code{\link{match,Splits,Splits-method}}, 33 | \code{\link{xor}()} 34 | } 35 | \concept{Splits operations} 36 | -------------------------------------------------------------------------------- /man/ReadMrBayesTrees.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ReadMrBayes.R 3 | \name{ReadMrBayesTrees} 4 | \alias{ReadMrBayesTrees} 5 | \alias{ReadMrBayes} 6 | \alias{MrBayesTrees} 7 | \title{Read posterior tree sample produced by MrBayes} 8 | \usage{ 9 | ReadMrBayesTrees(filepath, n = NULL, burninFrac = NULL) 10 | 11 | ReadMrBayes(filepath, n = NULL, burninFrac = NULL) 12 | 13 | MrBayesTrees(filepath, n = NULL, burninFrac = NULL) 14 | } 15 | \arguments{ 16 | \item{filepath}{character string specifying path to \code{.nex} input file used 17 | to initialize the MrBayes analysis, 18 | relative to the R working directory (visible with \code{getwd()}).} 19 | 20 | \item{n}{Integer specifying number of trees to sample from posterior.} 21 | 22 | \item{burninFrac}{Fraction of trees to discard from each run as burn-in. 23 | If \code{NULL} (the default), this will be read from the last \code{mcmc} or \code{mcmcp} 24 | command in \code{filepath}.} 25 | } 26 | \value{ 27 | \code{ReadMrBayesTrees()} returns a 'multiPhylo' object containing 28 | \code{n} trees sampled evenly from all runs generated by analysis of \code{filepath}, 29 | or \code{NULL} if no trees are found. 30 | } 31 | \description{ 32 | Read posterior trees from \href{https://nbisweden.github.io/MrBayes/}{'MrBayes'} output files, discarding burn-in 33 | generations. 34 | } 35 | \details{ 36 | \code{ReadMrBayesTrees()} samples trees from the posterior distributions 37 | computed using the Bayesian inference software \href{https://nbisweden.github.io/MrBayes/}{'MrBayes'} 38 | } 39 | \examples{ 40 | \dontrun{ # Download will take a few seconds 41 | url <- 42 | "https://raw.githubusercontent.com/ms609/hyoliths/master/MrBayes/hyo.nex" 43 | trees <- ReadMrBayesTrees(url, n = 40) 44 | plot(Consensus(trees, p = 0.5)) 45 | } 46 | } 47 | \seealso{ 48 | Other tree import functions: 49 | \code{\link{ReadTntTree}()} 50 | } 51 | \author{ 52 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 53 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 54 | } 55 | \concept{tree import functions} 56 | -------------------------------------------------------------------------------- /man/Renumber.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo.R 3 | \name{Renumber} 4 | \alias{Renumber} 5 | \title{Renumber a tree's nodes and tips} 6 | \usage{ 7 | Renumber(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | \code{Renumber()} returns a tree of class \code{phylo}, numbered in a 14 | \link{Cladewise} fashion consistent with the expectations of \pkg{ape} functions. 15 | } 16 | \description{ 17 | \code{Renumber()} numbers the nodes and tips in a tree to conform with the 18 | \code{phylo} standards. 19 | } 20 | \details{ 21 | The \pkg{ape} class \code{phylo} is not formally defined, but expects trees' internal 22 | representation to conform to certain principles: for example, nodes should 23 | be numbered sequentially, with values increasing away from the root. 24 | 25 | \code{Renumber()} attempts to reformat any tree into a representation that will 26 | not cause \pkg{ape} functions to produce unwanted results or to crash R. 27 | } 28 | \examples{ 29 | tree <- RandomTree(letters[1:10]) 30 | Renumber(tree) 31 | 32 | } 33 | \seealso{ 34 | \code{Preorder()} provides a faster and simpler alternative, but also 35 | rotates nodes. 36 | 37 | Other tree manipulation: 38 | \code{\link{AddTip}()}, 39 | \code{\link{CollapseNode}()}, 40 | \code{\link{ConsensusWithout}()}, 41 | \code{\link{DropTip}()}, 42 | \code{\link{EnforceOutgroup}()}, 43 | \code{\link{ImposeConstraint}()}, 44 | \code{\link{KeptPaths}()}, 45 | \code{\link{KeptVerts}()}, 46 | \code{\link{LeafLabelInterchange}()}, 47 | \code{\link{MakeTreeBinary}()}, 48 | \code{\link{RenumberTips}()}, 49 | \code{\link{RenumberTree}()}, 50 | \code{\link{RootTree}()}, 51 | \code{\link{SortTree}()}, 52 | \code{\link{Subtree}()}, 53 | \code{\link{TipTimedTree}()}, 54 | \code{\link{TrivialTree}} 55 | } 56 | \author{ 57 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 58 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 59 | } 60 | \concept{tree manipulation} 61 | -------------------------------------------------------------------------------- /man/RenumberTips.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_numbering.R 3 | \name{RenumberTips} 4 | \alias{RenumberTips} 5 | \alias{RenumberTips.phylo} 6 | \alias{RenumberTips.multiPhylo} 7 | \alias{RenumberTips.list} 8 | \alias{RenumberTips.NULL} 9 | \title{Renumber a tree's tips} 10 | \usage{ 11 | RenumberTips(tree, tipOrder) 12 | 13 | \method{RenumberTips}{phylo}(tree, tipOrder) 14 | 15 | \method{RenumberTips}{multiPhylo}(tree, tipOrder) 16 | 17 | \method{RenumberTips}{list}(tree, tipOrder) 18 | 19 | \method{RenumberTips}{`NULL`}(tree, tipOrder) 20 | } 21 | \arguments{ 22 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 23 | 24 | \item{tipOrder}{A character vector containing the values of 25 | \code{tree[["tip.label"]]} in the desired sort order, or an object 26 | (perhaps of class \code{phylo} or \code{Splits}) with tip labels.} 27 | } 28 | \value{ 29 | \code{RenumberTips()} returns \code{tree}, with the tips' internal 30 | representation numbered to match \code{tipOrder}. 31 | } 32 | \description{ 33 | \code{RenumberTips(tree, tipOrder)} sorts the tips of a phylogenetic tree \code{tree} 34 | such that the indices in \code{tree[["edge"]][, 2]} correspond to the order of 35 | leaves given in \code{tipOrder}. 36 | } 37 | \examples{ 38 | data("Lobo") # Loads the phyDat object Lobo.phy 39 | tree <- RandomTree(Lobo.phy) 40 | tree <- RenumberTips(tree, names(Lobo.phy)) 41 | 42 | } 43 | \seealso{ 44 | Other tree manipulation: 45 | \code{\link{AddTip}()}, 46 | \code{\link{CollapseNode}()}, 47 | \code{\link{ConsensusWithout}()}, 48 | \code{\link{DropTip}()}, 49 | \code{\link{EnforceOutgroup}()}, 50 | \code{\link{ImposeConstraint}()}, 51 | \code{\link{KeptPaths}()}, 52 | \code{\link{KeptVerts}()}, 53 | \code{\link{LeafLabelInterchange}()}, 54 | \code{\link{MakeTreeBinary}()}, 55 | \code{\link{Renumber}()}, 56 | \code{\link{RenumberTree}()}, 57 | \code{\link{RootTree}()}, 58 | \code{\link{SortTree}()}, 59 | \code{\link{Subtree}()}, 60 | \code{\link{TipTimedTree}()}, 61 | \code{\link{TrivialTree}} 62 | } 63 | \author{ 64 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 65 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 66 | } 67 | \concept{tree manipulation} 68 | -------------------------------------------------------------------------------- /man/RightmostCharacter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{RightmostCharacter} 4 | \alias{RightmostCharacter} 5 | \title{Rightmost character of string} 6 | \usage{ 7 | RightmostCharacter(string, len = nchar(string)) 8 | } 9 | \arguments{ 10 | \item{string}{Character string.} 11 | 12 | \item{len}{(Optional) Integer specifying number of characters in \code{string}.} 13 | } 14 | \value{ 15 | \code{RightmostCharacter()} returns the rightmost character of a string. 16 | } 17 | \description{ 18 | \code{RightmostCharacter()} is a convenience function that returns the final 19 | character of a string. 20 | } 21 | \examples{ 22 | RightmostCharacter("Hello, World!") 23 | 24 | } 25 | \seealso{ 26 | Other string parsing functions: 27 | \code{\link{EndSentence}()}, 28 | \code{\link{MorphoBankDecode}()}, 29 | \code{\link{Unquote}()} 30 | } 31 | \author{ 32 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 33 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 34 | } 35 | \concept{string parsing functions} 36 | -------------------------------------------------------------------------------- /man/RootNode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{RootNode} 4 | \alias{RootNode} 5 | \title{Which node is a tree's root?} 6 | \usage{ 7 | RootNode(x) 8 | } 9 | \arguments{ 10 | \item{x}{A tree of class \code{phylo}, or its edge matrix; or a list or 11 | \code{multiPhylo} object containing multiple trees.} 12 | } 13 | \value{ 14 | \code{RootNode()} returns an integer denoting the root node for each tree. 15 | Badly conformed trees trigger an error. 16 | } 17 | \description{ 18 | \code{RootNode()} identifies the root node of a (rooted or unrooted) phylogenetic 19 | tree. 20 | Unrooted trees are represented internally by a rooted tree with a polytomy 21 | at the root. 22 | } 23 | \examples{ 24 | RootNode(BalancedTree(8)) 25 | RootNode(UnrootTree(BalancedTree(8))) 26 | 27 | 28 | } 29 | \seealso{ 30 | Test whether a tree is rooted: \code{\link[=TreeIsRooted]{TreeIsRooted()}} 31 | 32 | \code{phangorn::getRoot()} 33 | 34 | Other tree navigation: 35 | \code{\link{AncestorEdge}()}, 36 | \code{\link{CladeSizes}()}, 37 | \code{\link{DescendantEdges}()}, 38 | \code{\link{EdgeAncestry}()}, 39 | \code{\link{EdgeDistances}()}, 40 | \code{\link{ListAncestors}()}, 41 | \code{\link{MRCA}()}, 42 | \code{\link{MatchEdges}()}, 43 | \code{\link{NDescendants}()}, 44 | \code{\link{NodeDepth}()}, 45 | \code{\link{NodeNumbers}()}, 46 | \code{\link{NodeOrder}()} 47 | } 48 | \author{ 49 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 50 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 51 | } 52 | \concept{tree navigation} 53 | -------------------------------------------------------------------------------- /man/SampleOne.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helper_functions.R 3 | \name{SampleOne} 4 | \alias{SampleOne} 5 | \title{Select element at random} 6 | \usage{ 7 | SampleOne(x, len = length(x)) 8 | } 9 | \arguments{ 10 | \item{x}{A vector to sample.} 11 | 12 | \item{len}{(Optional) Integer specifying length of \code{x}.} 13 | } 14 | \value{ 15 | \code{SampleOne()} returns a length one vector, randomly sampled from \code{x}. 16 | } 17 | \description{ 18 | \code{SampleOne()} is a fast alternative to \code{\link[=sample]{sample()}} that avoids some checks. 19 | } 20 | \examples{ 21 | SampleOne(9:10) 22 | SampleOne(letters[1:4]) 23 | 24 | } 25 | \seealso{ 26 | Other utility functions: 27 | \code{\link{ClusterTable}}, 28 | \code{\link{ClusterTable-methods}}, 29 | \code{\link{Hamming}()}, 30 | \code{\link{MSTEdges}()}, 31 | \code{\link{TipTimedTree}()}, 32 | \code{\link{UnshiftTree}()}, 33 | \code{\link{as.multiPhylo}()}, 34 | \code{\link{match,phylo,phylo-method}}, 35 | \code{\link{sapply64}()}, 36 | \code{\link{sort.multiPhylo}()} 37 | } 38 | \author{ 39 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 40 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 41 | } 42 | \concept{utility functions} 43 | -------------------------------------------------------------------------------- /man/SplitMatchProbability.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SplitFunctions.R 3 | \name{SplitMatchProbability} 4 | \alias{SplitMatchProbability} 5 | \alias{LnSplitMatchProbability} 6 | \title{Probability of matching this well} 7 | \usage{ 8 | SplitMatchProbability(split1, split2) 9 | 10 | LnSplitMatchProbability(split1, split2) 11 | } 12 | \arguments{ 13 | \item{split1, split2}{Logical vectors listing terminals in same order, such that 14 | each terminal is identified as a member of the ingroup (\code{TRUE}) or outgroup 15 | (\code{FALSE}) of the respective bipartition split.} 16 | } 17 | \value{ 18 | \code{SplitMatchProbability()} returns a numeric giving the proportion 19 | of permissible non-trivial splits that divide the terminals into bipartitions 20 | of the sizes given, that match as well as \code{split1} and \code{split2} do. 21 | 22 | \code{LnSplitMatchProbability()} returns the natural logarithm of the 23 | probability. 24 | } 25 | \description{ 26 | (\code{Ln})\code{SplitMatchProbability()}calculates the probability that two random 27 | splits of the sizes provided will be at least as similar as the two 28 | specified. 29 | } 30 | \examples{ 31 | split1 <- as.Splits(c(rep(TRUE, 4), rep(FALSE, 4))) 32 | split2 <- as.Splits(c(rep(TRUE, 3), rep(FALSE, 5))) 33 | SplitMatchProbability(split1, split2) 34 | LnSplitMatchProbability(split1, split2) 35 | } 36 | \seealso{ 37 | Other split information functions: 38 | \code{\link{CharacterInformation}()}, 39 | \code{\link{SplitInformation}()}, 40 | \code{\link{TreesMatchingSplit}()}, 41 | \code{\link{UnrootedTreesMatchingSplit}()} 42 | } 43 | \author{ 44 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 45 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 46 | } 47 | \concept{split information functions} 48 | -------------------------------------------------------------------------------- /man/Subsplit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SplitFunctions.R 3 | \name{Subsplit} 4 | \alias{Subsplit} 5 | \title{Subset of a split on fewer leaves} 6 | \usage{ 7 | Subsplit(splits, tips, keepAll = FALSE, unique = TRUE) 8 | } 9 | \arguments{ 10 | \item{splits}{An object of class \code{\link[=as.Splits]{Splits}}.} 11 | 12 | \item{tips}{A vector specifying a subset of the leaf labels applied to \code{split}.} 13 | 14 | \item{keepAll}{logical specifying whether to keep entries that define trivial 15 | splits (i.e. splits of zero or one leaf) on the subset of leaves.} 16 | 17 | \item{unique}{logical specifying whether to remove duplicate splits.} 18 | } 19 | \value{ 20 | \code{Subsplit()} returns an object of class \code{Splits}, defined on the 21 | leaves \code{tips}. 22 | } 23 | \description{ 24 | \code{Subsplit()} removes leaves from a \code{Splits} object. 25 | } 26 | \examples{ 27 | splits <- as.Splits(PectinateTree(letters[1:9])) 28 | splits 29 | efgh <- Subsplit(splits, tips = letters[5:8], keepAll = TRUE) 30 | summary(efgh) 31 | 32 | TrivialSplits(efgh) 33 | 34 | summary(Subsplit(splits, tips = letters[5:8], keepAll = FALSE)) 35 | } 36 | \seealso{ 37 | \code{\link[=KeepTip]{KeepTip()}} is a less flexible but faster equivalent. 38 | 39 | Other split manipulation functions: 40 | \code{\link{DropTip}()}, 41 | \code{\link{TrivialSplits}()} 42 | } 43 | \author{ 44 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 45 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 46 | } 47 | \concept{split manipulation functions} 48 | -------------------------------------------------------------------------------- /man/Subtree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo.R 3 | \name{Subtree} 4 | \alias{Subtree} 5 | \title{Extract a subtree} 6 | \usage{ 7 | Subtree(tree, node) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}, with internal 11 | numbering in cladewise order (use \code{\link{Preorder}(tree)} or (slower) 12 | \code{\link{Cladewise}(tree)}) .} 13 | 14 | \item{node}{The number of the node at the base of the clade to be extracted.} 15 | } 16 | \value{ 17 | \code{Subtree()} returns a tree of class \code{phylo} that represents a 18 | clade extracted from the original tree. 19 | } 20 | \description{ 21 | \code{Subtree()} safely extracts a clade from a phylogenetic tree. 22 | } 23 | \details{ 24 | Modified from the \pkg{ape} function \code{\link[ape]{extract.clade}}, which 25 | sometimes behaves unpredictably. 26 | Unlike extract.clade, this function supports the extraction of "clades" 27 | that constitute a single tip. 28 | } 29 | \examples{ 30 | tree <- Preorder(BalancedTree(8)) 31 | plot(tree) 32 | ape::nodelabels() 33 | ape::nodelabels(13, 13, bg="yellow") 34 | 35 | plot(Subtree(tree, 13)) 36 | 37 | } 38 | \seealso{ 39 | Other tree manipulation: 40 | \code{\link{AddTip}()}, 41 | \code{\link{CollapseNode}()}, 42 | \code{\link{ConsensusWithout}()}, 43 | \code{\link{DropTip}()}, 44 | \code{\link{EnforceOutgroup}()}, 45 | \code{\link{ImposeConstraint}()}, 46 | \code{\link{KeptPaths}()}, 47 | \code{\link{KeptVerts}()}, 48 | \code{\link{LeafLabelInterchange}()}, 49 | \code{\link{MakeTreeBinary}()}, 50 | \code{\link{Renumber}()}, 51 | \code{\link{RenumberTips}()}, 52 | \code{\link{RenumberTree}()}, 53 | \code{\link{RootTree}()}, 54 | \code{\link{SortTree}()}, 55 | \code{\link{TipTimedTree}()}, 56 | \code{\link{TrivialTree}} 57 | } 58 | \author{ 59 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 60 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 61 | } 62 | \concept{tree manipulation} 63 | -------------------------------------------------------------------------------- /man/TopologyOnly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TopologyOnly.R 3 | \name{TopologyOnly} 4 | \alias{TopologyOnly} 5 | \title{Remove metadata from trees} 6 | \usage{ 7 | TopologyOnly(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 11 | } 12 | \value{ 13 | Returns \code{tree}, with each tree in \code{\link{Preorder}}, with edge lengths, 14 | node labels and other attributes removed. 15 | } 16 | \description{ 17 | \code{TopologyOnly()} removes all information from trees except for their 18 | topologies and leaf labels. This allows other functions to process 19 | trees more rapidly, as they do not need to process unneeded metadata. 20 | } 21 | \author{ 22 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 23 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 24 | } 25 | -------------------------------------------------------------------------------- /man/TreeIsRooted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_properties.R 3 | \name{TreeIsRooted} 4 | \alias{TreeIsRooted} 5 | \title{Is tree rooted?} 6 | \usage{ 7 | TreeIsRooted(tree) 8 | } 9 | \arguments{ 10 | \item{tree}{A phylogenetic tree of class \code{phylo}.} 11 | } 12 | \value{ 13 | \code{TreeIsRooted()} returns a logical specifying whether a root node is 14 | resolved. 15 | } 16 | \description{ 17 | \code{TreeIsRooted()} is a fast alternative to \code{ape::is.rooted()}. 18 | } 19 | \examples{ 20 | TreeIsRooted(BalancedTree(6)) 21 | TreeIsRooted(UnrootTree(BalancedTree(6))) 22 | 23 | } 24 | \seealso{ 25 | Other tree properties: 26 | \code{\link{ConsensusWithout}()}, 27 | \code{\link{MatchEdges}()}, 28 | \code{\link{NSplits}()}, 29 | \code{\link{NTip}()}, 30 | \code{\link{NodeNumbers}()}, 31 | \code{\link{PathLengths}()}, 32 | \code{\link{SplitsInBinaryTree}()}, 33 | \code{\link{TipLabels}()} 34 | } 35 | \author{ 36 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 37 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 38 | } 39 | \concept{tree properties} 40 | -------------------------------------------------------------------------------- /man/TreeTools-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TreeTools-package.R 3 | \docType{package} 4 | \name{TreeTools-package} 5 | \alias{TreeTools} 6 | \alias{TreeTools-package} 7 | \title{TreeTools} 8 | \description{ 9 | "TreeTools" is an R package that provides functions for creating, modifying and 10 | analysing phylogenetic trees. 11 | It complements packages such as 12 | \href{https://cran.r-project.org/package=ape}{\pkg{ape}}, 13 | \href{https://cran.r-project.org/package=phangorn}{\pkg{phangorn}} and 14 | \href{https://cran.r-project.org/package=phytools}{\pkg{phytools}}, 15 | aiming for efficient and robust implementations of functions, typically 16 | applied to unweighted trees (i.e. those without edge lengths). 17 | } 18 | \details{ 19 | Full documentation is available \href{https://ms609.github.io/TreeTools/}{online}. 20 | } 21 | \seealso{ 22 | Useful links: 23 | \itemize{ 24 | \item \url{https://ms609.github.io/TreeTools/} 25 | \item \url{https://github.com/ms609/TreeTools/} 26 | \item Report bugs at \url{https://github.com/ms609/TreeTools/issues/} 27 | } 28 | 29 | } 30 | \author{ 31 | \strong{Maintainer}: Martin R. Smith \email{martin.smith@durham.ac.uk} (\href{https://orcid.org/0000-0001-5660-1727}{ORCID}) [copyright holder] 32 | 33 | Other contributors: 34 | \itemize{ 35 | \item Emmanuel Paradis (\href{https://orcid.org/0000-0003-3092-2199}{ORCID}) [copyright holder] 36 | \item Robert Noble (\href{https://orcid.org/0000-0002-8057-4252}{ORCID}) [copyright holder] 37 | } 38 | 39 | } 40 | \keyword{internal} 41 | -------------------------------------------------------------------------------- /man/TreesMatchingSplit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Information.R 3 | \name{TreesMatchingSplit} 4 | \alias{TreesMatchingSplit} 5 | \alias{LnTreesMatchingSplit} 6 | \alias{Log2TreesMatchingSplit} 7 | \title{Number of trees matching a bipartition split} 8 | \usage{ 9 | TreesMatchingSplit(A, B = A[2]) 10 | 11 | LnTreesMatchingSplit(A, B = A[2]) 12 | 13 | Log2TreesMatchingSplit(A, B = A[2]) 14 | } 15 | \arguments{ 16 | \item{A, B}{Integer specifying the number of taxa in each partition.} 17 | } 18 | \value{ 19 | \code{TreesMatchingSplit()} returns a numeric specifying the number of trees 20 | that are compatible with the given split. 21 | 22 | \code{LnTreesMatchingSplit()} and \code{Log2TreesMatchingSplit()} give the natural 23 | and base-2 logarithms of this number. 24 | } 25 | \description{ 26 | Calculates the number of unrooted bifurcated trees that are consistent with 27 | a bipartition split that divides taxa into groups of size \code{A} and \code{B}. 28 | } 29 | \examples{ 30 | TreesMatchingSplit(5, 6) 31 | LnTreesMatchingSplit(5, 6) 32 | Log2TreesMatchingSplit(5, 6) 33 | 34 | } 35 | \seealso{ 36 | Other split information functions: 37 | \code{\link{CharacterInformation}()}, 38 | \code{\link{SplitInformation}()}, 39 | \code{\link{SplitMatchProbability}()}, 40 | \code{\link{UnrootedTreesMatchingSplit}()} 41 | } 42 | \author{ 43 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 44 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 45 | } 46 | \concept{split information functions} 47 | -------------------------------------------------------------------------------- /man/TreesMatchingTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_information.R 3 | \name{TreesMatchingTree} 4 | \alias{TreesMatchingTree} 5 | \alias{LnTreesMatchingTree} 6 | \alias{Log2TreesMatchingTree} 7 | \title{Number of trees containing a tree} 8 | \usage{ 9 | TreesMatchingTree(tree) 10 | 11 | LnTreesMatchingTree(tree) 12 | 13 | Log2TreesMatchingTree(tree) 14 | } 15 | \arguments{ 16 | \item{tree}{A tree of class \code{\link[ape:read.tree]{phylo}}.} 17 | } 18 | \value{ 19 | \code{TreesMatchingTree()} returns a numeric specifying the number of 20 | unrooted binary trees that contain all the edges present in the input tree. 21 | 22 | \code{LnTreesMatchingTree()} gives the natural logarithm of this number. 23 | } 24 | \description{ 25 | \code{TreesMatchingTree()} calculates the number of unrooted binary trees that 26 | are consistent with a tree topology on the same leaves. 27 | } 28 | \details{ 29 | Remember to unroot a tree first if the position of its root is arbitrary. 30 | } 31 | \examples{ 32 | partiallyResolvedTree <- CollapseNode(BalancedTree(8), 12:15) 33 | TreesMatchingTree(partiallyResolvedTree) 34 | LnTreesMatchingTree(partiallyResolvedTree) 35 | 36 | # Number of rooted trees: 37 | rootedTree <- AddTip(partiallyResolvedTree, where = 0) 38 | TreesMatchingTree(partiallyResolvedTree) 39 | } 40 | \seealso{ 41 | Other tree information functions: 42 | \code{\link{CladisticInfo}()}, 43 | \code{\link{NRooted}()} 44 | } 45 | \author{ 46 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 47 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 48 | } 49 | \concept{tree information functions} 50 | -------------------------------------------------------------------------------- /man/TrivialSplits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SplitFunctions.R 3 | \name{TrivialSplits} 4 | \alias{TrivialSplits} 5 | \alias{WithoutTrivialSplits} 6 | \title{Identify and remove trivial splits} 7 | \usage{ 8 | TrivialSplits(splits, nTip = attr(splits, "nTip")) 9 | 10 | WithoutTrivialSplits(splits, nTip = attr(splits, "nTip")) 11 | } 12 | \arguments{ 13 | \item{splits}{An object of class \code{\link[=as.Splits]{Splits}}.} 14 | 15 | \item{nTip}{Integer specifying number of tips (leaves).} 16 | } 17 | \value{ 18 | \code{TrivialSplits()} returns a logical vector specifying whether each 19 | split in \code{splits} is trivial, i.e. includes or excludes only a single tip or 20 | no tips at all. 21 | 22 | \code{WithoutTrivialSplits()} returns a \code{Splits} object with trivial 23 | splits removed. 24 | } 25 | \description{ 26 | \code{TrivialSplits()} identifies trivial splits (which separate one or zero 27 | leaves from all others); \code{WithoutTrivialSplits()} removes them from a 28 | \code{Splits} object. 29 | } 30 | \examples{ 31 | splits <- as.Splits(PectinateTree(letters[1:9])) 32 | efgh <- Subsplit(splits, tips = letters[5:8], keepAll = TRUE) 33 | summary(efgh) 34 | 35 | TrivialSplits(efgh) 36 | summary(WithoutTrivialSplits(efgh)) 37 | } 38 | \seealso{ 39 | Other split manipulation functions: 40 | \code{\link{DropTip}()}, 41 | \code{\link{Subsplit}()} 42 | } 43 | \author{ 44 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 45 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 46 | } 47 | \concept{split manipulation functions} 48 | -------------------------------------------------------------------------------- /man/TrivialTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo.R 3 | \name{TrivialTree} 4 | \alias{TrivialTree} 5 | \alias{SingleTaxonTree} 6 | \alias{ZeroTaxonTree} 7 | \title{Generate trivial trees} 8 | \usage{ 9 | SingleTaxonTree(label = "t1", lengths = NULL) 10 | 11 | ZeroTaxonTree() 12 | } 13 | \arguments{ 14 | \item{label}{a character vector specifying the label of the tip.} 15 | 16 | \item{lengths}{a numeric vector specifying the edge lengths of the tree.} 17 | } 18 | \value{ 19 | \code{SingleTaxonTree()} returns a \code{phylo} object containing a single 20 | tip with the specified label. 21 | 22 | \code{ZeroTaxonTree()} returns an empty \code{phylo} object. 23 | } 24 | \description{ 25 | \code{SingleTaxonTree()} creates a phylogenetic "tree" that contains a single 26 | taxon. 27 | \code{ZeroTaxonTree()} creates an empty \code{phylo} object with zero leaves or edges. 28 | } 29 | \examples{ 30 | SingleTaxonTree("Homo_sapiens") 31 | plot(SingleTaxonTree("root") + BalancedTree(4)) 32 | 33 | ZeroTaxonTree() 34 | } 35 | \seealso{ 36 | Other tree manipulation: 37 | \code{\link{AddTip}()}, 38 | \code{\link{CollapseNode}()}, 39 | \code{\link{ConsensusWithout}()}, 40 | \code{\link{DropTip}()}, 41 | \code{\link{EnforceOutgroup}()}, 42 | \code{\link{ImposeConstraint}()}, 43 | \code{\link{KeptPaths}()}, 44 | \code{\link{KeptVerts}()}, 45 | \code{\link{LeafLabelInterchange}()}, 46 | \code{\link{MakeTreeBinary}()}, 47 | \code{\link{Renumber}()}, 48 | \code{\link{RenumberTips}()}, 49 | \code{\link{RenumberTree}()}, 50 | \code{\link{RootTree}()}, 51 | \code{\link{SortTree}()}, 52 | \code{\link{Subtree}()}, 53 | \code{\link{TipTimedTree}()} 54 | 55 | Other tree generation functions: 56 | \code{\link{ConstrainedNJ}()}, 57 | \code{\link{GenerateTree}}, 58 | \code{\link{NJTree}()}, 59 | \code{\link{TreeNumber}} 60 | } 61 | \concept{tree generation functions} 62 | \concept{tree manipulation} 63 | \keyword{tree} 64 | -------------------------------------------------------------------------------- /man/Unquote.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/parse_files.R 3 | \name{Unquote} 4 | \alias{Unquote} 5 | \title{Remove quotation marks from a string} 6 | \usage{ 7 | Unquote(string) 8 | } 9 | \arguments{ 10 | \item{string}{Input string} 11 | } 12 | \value{ 13 | \code{Unquote()} returns \code{string}, with any matched punctuation marks 14 | and trailing whitespace removed. 15 | } 16 | \description{ 17 | Remove quotation marks from a string 18 | } 19 | \examples{ 20 | Unquote("'Hello World'") 21 | } 22 | \seealso{ 23 | Other string parsing functions: 24 | \code{\link{EndSentence}()}, 25 | \code{\link{MorphoBankDecode}()}, 26 | \code{\link{RightmostCharacter}()} 27 | } 28 | \author{ 29 | Martin R. Smith 30 | } 31 | \concept{string parsing functions} 32 | -------------------------------------------------------------------------------- /man/UnrootedTreesMatchingSplit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Information.R 3 | \name{UnrootedTreesMatchingSplit} 4 | \alias{UnrootedTreesMatchingSplit} 5 | \alias{LnUnrootedTreesMatchingSplit} 6 | \alias{Log2UnrootedTreesMatchingSplit} 7 | \title{Number of trees consistent with split} 8 | \usage{ 9 | UnrootedTreesMatchingSplit(...) 10 | 11 | LnUnrootedTreesMatchingSplit(...) 12 | 13 | Log2UnrootedTreesMatchingSplit(...) 14 | } 15 | \arguments{ 16 | \item{\dots}{A series or vector of integers listing the number of tips in 17 | each of a number of tree splits (e.g. bipartitions). 18 | For example, \verb{3, 5} states that a character divides a set of eight tips into 19 | a group of three and a group of five.} 20 | } 21 | \value{ 22 | \code{UnrootedTreesMatchingSplit()} returns an integer specifying the 23 | number of unrooted bifurcating trees consistent with the specified split. 24 | } 25 | \description{ 26 | Calculates the number of unrooted bifurcating trees consistent with the 27 | specified multi-partition split, using theorem two of 28 | \insertCite{Carter1990;textual}{TreeTools}. 29 | } 30 | \examples{ 31 | UnrootedTreesMatchingSplit(c(3, 5)) 32 | UnrootedTreesMatchingSplit(3, 2, 1, 2) 33 | } 34 | \references{ 35 | \insertAllCited{} 36 | } 37 | \seealso{ 38 | Other split information functions: 39 | \code{\link{CharacterInformation}()}, 40 | \code{\link{SplitInformation}()}, 41 | \code{\link{SplitMatchProbability}()}, 42 | \code{\link{TreesMatchingSplit}()} 43 | } 44 | \author{ 45 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 46 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 47 | } 48 | \concept{split information functions} 49 | -------------------------------------------------------------------------------- /man/UnshiftTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helper_functions.R 3 | \name{UnshiftTree} 4 | \alias{UnshiftTree} 5 | \title{Add tree to start of list} 6 | \usage{ 7 | UnshiftTree(add, treeList) 8 | } 9 | \arguments{ 10 | \item{add}{Tree to add to the list, of class \code{\link[ape:read.tree]{phylo}}.} 11 | 12 | \item{treeList}{A list of trees, of class \code{list}, 13 | \code{\link[ape:multiphylo]{multiPhylo}}, or, if a single tree, 14 | \code{\link[ape:read.tree]{phylo}}.} 15 | } 16 | \value{ 17 | \code{UnshiftTree()} returns a list of class \code{list} or \code{multiPhylo} 18 | (following the original class of \code{treeList}), whose first element is the 19 | tree specified as `add. 20 | } 21 | \description{ 22 | \code{UnshiftTree()} adds a phylogenetic tree to the start of a list of trees. 23 | This is useful where the class of a list of trees is unknown, or where 24 | names of trees should be retained. 25 | } 26 | \details{ 27 | Caution: adding a tree to a \code{multiPhylo} object whose own attributes apply 28 | to all trees, for example trees read from a Nexus file, causes data to be 29 | lost. 30 | } 31 | \examples{ 32 | forest <- as.phylo(0:5, 6) 33 | tree <- BalancedTree(6) 34 | 35 | UnshiftTree(tree, forest) 36 | UnshiftTree(tree, tree) 37 | } 38 | \seealso{ 39 | \code{\link[=c]{c()}} joins a tree or series of trees to a \code{multiPhylo} object, but loses 40 | names and does not handle lists of trees. 41 | 42 | Other utility functions: 43 | \code{\link{ClusterTable}}, 44 | \code{\link{ClusterTable-methods}}, 45 | \code{\link{Hamming}()}, 46 | \code{\link{MSTEdges}()}, 47 | \code{\link{SampleOne}()}, 48 | \code{\link{TipTimedTree}()}, 49 | \code{\link{as.multiPhylo}()}, 50 | \code{\link{match,phylo,phylo-method}}, 51 | \code{\link{sapply64}()}, 52 | \code{\link{sort.multiPhylo}()} 53 | } 54 | \author{ 55 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 56 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 57 | } 58 | \concept{utility functions} 59 | -------------------------------------------------------------------------------- /man/WriteTntCharacters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_write.R 3 | \name{WriteTntCharacters} 4 | \alias{WriteTntCharacters} 5 | \alias{WriteTntCharacters.phyDat} 6 | \alias{WriteTntCharacters.matrix} 7 | \title{Write morphological character matrix to TNT file} 8 | \usage{ 9 | WriteTntCharacters( 10 | dataset, 11 | filepath = NULL, 12 | comment = "Dataset written by `TreeTools::WriteTntCharacters()`", 13 | types = NULL, 14 | pre = "", 15 | post = "" 16 | ) 17 | 18 | \method{WriteTntCharacters}{phyDat}( 19 | dataset, 20 | filepath = NULL, 21 | comment = "Dataset written by `TreeTools::WriteTntCharacters()`", 22 | types = NULL, 23 | pre = "", 24 | post = "" 25 | ) 26 | 27 | \method{WriteTntCharacters}{matrix}( 28 | dataset, 29 | filepath = NULL, 30 | comment = "Dataset written by `TreeTools::WriteTntCharacters()`", 31 | types = NULL, 32 | pre = "", 33 | post = "" 34 | ) 35 | } 36 | \arguments{ 37 | \item{dataset}{Morphological dataset of class \code{phyDat} or \code{matrix}.} 38 | 39 | \item{filepath}{Path to file; if \code{NULL}, returns a character vector.} 40 | 41 | \item{comment}{Optional comment with which to entitle matrix.} 42 | 43 | \item{types}{Optional list specifying where different data types begin. 44 | \code{c(num = 1, dna = 10)} sets characters 1..9 as numeric, 10..end as DNA.} 45 | 46 | \item{pre, post}{Character vector listing text to print before and after the 47 | character matrix. Specify \verb{pre = 'piwe=;} if the matrix is to be analysed 48 | using extended implied weighting (\verb{xpiwe=}).} 49 | } 50 | \description{ 51 | Write morphological character matrix to TNT file 52 | } 53 | \examples{ 54 | data("Lobo", package = "TreeTools") 55 | 56 | WriteTntCharacters(Lobo.phy) 57 | 58 | # Read with extended implied weighting 59 | WriteTntCharacters(Lobo.phy, pre = "piwe=10;", post = "xpiwe=;") 60 | 61 | # Write to a file with: 62 | # WriteTntCharacters(Lobo.phy, "example_file.tnt") 63 | } 64 | \seealso{ 65 | \code{\link[=ReadTntCharacters]{ReadTntCharacters()}} 66 | } 67 | \author{ 68 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 69 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 70 | } 71 | -------------------------------------------------------------------------------- /man/as.Newick.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_write.R 3 | \name{as.Newick} 4 | \alias{as.Newick} 5 | \alias{as.Newick.phylo} 6 | \alias{as.Newick.list} 7 | \alias{as.Newick.multiPhylo} 8 | \title{Write a phylogenetic tree in Newick format} 9 | \usage{ 10 | as.Newick(x) 11 | 12 | \method{as.Newick}{phylo}(x) 13 | 14 | \method{as.Newick}{list}(x) 15 | 16 | \method{as.Newick}{multiPhylo}(x) 17 | } 18 | \arguments{ 19 | \item{x}{Object to convert to Newick format. 20 | See Usage section for supported classes.} 21 | } 22 | \value{ 23 | \code{as.Newick()} returns a character string representing \code{tree} in Newick 24 | format. 25 | } 26 | \description{ 27 | \code{as.Newick()} creates a character string representation of a phylogenetic 28 | tree, in the Newick format, using R's internal tip numbering. 29 | Use \code{\link[=RenumberTips]{RenumberTips()}} to ensure that the internal numbering follows the 30 | order you expect. 31 | } 32 | \examples{ 33 | trees <- list(BalancedTree(1:8), PectinateTree(8:1)) 34 | trees <- lapply(trees, RenumberTips, 1:8) 35 | as.Newick(trees) 36 | 37 | } 38 | \seealso{ 39 | \itemize{ 40 | \item Retain leaf labels: \code{\link[=NewickTree]{NewickTree()}} 41 | \item Change R's internal numbering of leaves: \code{\link[=RenumberTips]{RenumberTips()}} 42 | \item Write tree to text or file: \code{\link[ape:write.tree]{ape::write.tree()}} 43 | } 44 | } 45 | \author{ 46 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 47 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 48 | } 49 | -------------------------------------------------------------------------------- /man/as.multiPhylo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as.multiPhylo.R 3 | \name{as.multiPhylo} 4 | \alias{as.multiPhylo} 5 | \alias{as.multiPhylo.phylo} 6 | \alias{as.multiPhylo.list} 7 | \alias{as.multiPhylo.phyDat} 8 | \alias{as.multiPhylo.Splits} 9 | \title{Convert object to \code{multiPhylo} class} 10 | \usage{ 11 | as.multiPhylo(x) 12 | 13 | \method{as.multiPhylo}{phylo}(x) 14 | 15 | \method{as.multiPhylo}{list}(x) 16 | 17 | \method{as.multiPhylo}{phyDat}(x) 18 | 19 | \method{as.multiPhylo}{Splits}(x) 20 | } 21 | \arguments{ 22 | \item{x}{Object to be converted} 23 | } 24 | \value{ 25 | \code{as.multiPhylo} returns an object of class \code{multiPhylo} 26 | 27 | \code{as.multiPhylo.phyDat()} returns a list of trees, each corresponding 28 | to the partitions implied by each non-ambiguous character in \code{x}. 29 | } 30 | \description{ 31 | Converts representations of phylogenetic trees to an object of the "ape" 32 | class \code{multiPhylo}. 33 | } 34 | \examples{ 35 | as.multiPhylo(BalancedTree(8)) 36 | as.multiPhylo(list(BalancedTree(8), PectinateTree(8))) 37 | data("Lobo") 38 | as.multiPhylo(Lobo.phy) 39 | } 40 | \seealso{ 41 | Other utility functions: 42 | \code{\link{ClusterTable}}, 43 | \code{\link{ClusterTable-methods}}, 44 | \code{\link{Hamming}()}, 45 | \code{\link{MSTEdges}()}, 46 | \code{\link{SampleOne}()}, 47 | \code{\link{TipTimedTree}()}, 48 | \code{\link{UnshiftTree}()}, 49 | \code{\link{match,phylo,phylo-method}}, 50 | \code{\link{sapply64}()}, 51 | \code{\link{sort.multiPhylo}()} 52 | } 53 | \concept{utility functions} 54 | -------------------------------------------------------------------------------- /man/brewer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{brewer} 5 | \alias{brewer} 6 | \title{Brewer palettes} 7 | \format{ 8 | An object of class \code{list} of length 12. 9 | } 10 | \source{ 11 | { 12 | \itemize{ 13 | \item \href{https://colorbrewer2.org/#type=diverging&scheme=RdYlBu&n=3}{ColourBrewer2.org} 14 | \item \href{http://mkweb.bcgsc.ca/colorblind/}{Martin Krzywinski} 15 | } 16 | } 17 | } 18 | \usage{ 19 | brewer 20 | } 21 | \description{ 22 | A list of eleven Brewer palettes containing one to eleven colours that 23 | are readily distinguished by colourblind viewers, followed by a twelfth 24 | 12-colour palette adapted for colour blindness. 25 | } 26 | \examples{ 27 | data("brewer", package="TreeTools") 28 | plot(0, type="n", xlim=c(1, 12), ylim=c(12, 1), 29 | xlab = "Colour", ylab="Palette") 30 | for (i in seq_along(brewer)) text(seq_len(i), i, col=brewer[[i]]) 31 | 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/dot-RandomParent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tree_generation.R 3 | \name{.RandomParent} 4 | \alias{.RandomParent} 5 | \title{Random parent vector} 6 | \usage{ 7 | .RandomParent(n, seed = sample.int(2147483647L, 1L)) 8 | } 9 | \arguments{ 10 | \item{n}{Integer specifying number of leaves.} 11 | 12 | \item{seed}{(Optional) Integer with which to seed Mersenne Twister random 13 | number generator in C++.} 14 | } 15 | \value{ 16 | Integer vector corresponding to the "parent" entry of 17 | \code{tree[["edge"]]}, where the "child" entry, i.e. column 2, is numbered 18 | sequentially from \code{1:n}. 19 | } 20 | \description{ 21 | Random parent vector 22 | } 23 | \author{ 24 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 25 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/doubleFactorials.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{doubleFactorials} 5 | \alias{doubleFactorials} 6 | \title{Double factorials} 7 | \format{ 8 | An object of class \code{numeric} of length 300. 9 | } 10 | \usage{ 11 | doubleFactorials 12 | } 13 | \description{ 14 | A vector with pre-calculated values of double factorials up to 300!!, 15 | and the logarithms of double factorials up to 50 000!!. 16 | } 17 | \details{ 18 | 301!! is too large to store as an integer; use \code{logDoubleFactorials} instead. 19 | } 20 | \seealso{ 21 | Other double factorials: 22 | \code{\link{DoubleFactorial}()}, 23 | \code{\link{logDoubleFactorials}} 24 | } 25 | \concept{double factorials} 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/edge_to_splits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Splits.R 3 | \name{edge_to_splits} 4 | \alias{edge_to_splits} 5 | \title{Efficiently convert edge matrix to splits} 6 | \usage{ 7 | edge_to_splits( 8 | edge, 9 | edgeOrder, 10 | tipLabels = NULL, 11 | asSplits = TRUE, 12 | nTip = NTip(edge), 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{edge}{A matrix with two columns, with each row listing the parent and 18 | child node of an edge in a phylogenetic tree. Property \code{edge} of objects 19 | of class \code{phylo}.} 20 | 21 | \item{edgeOrder}{Integer vector such that \code{edge[edgeOrder, ]} returns a 22 | postorder ordering of edges.} 23 | 24 | \item{tipLabels}{Character vector specifying sequence in which to order 25 | tip labels. Label order must (currently) match to combine or compare separate 26 | \code{Splits} objects.} 27 | 28 | \item{asSplits}{Logical specifying whether to return a \code{Splits} object, 29 | or an unannotated two-dimensional array (useful where performance is 30 | paramount).} 31 | 32 | \item{nTip}{Integer specifying number of leaves in tree.} 33 | 34 | \item{...}{Presently unused.} 35 | } 36 | \value{ 37 | \code{edge_to_splits()} uses the same return format as \code{as.Splits()}. 38 | } 39 | \description{ 40 | Wrapper for internal C++ function for maximum efficiency. 41 | Improper input may crash R. Behaviour not guaranteed. 42 | It is advisable to contact the package maintainers before 43 | relying on this function. 44 | } 45 | \seealso{ 46 | \code{\link[=Splits]{as.Splits()}} offers a safe access point to this 47 | function that should be suitable for most users. 48 | } 49 | \concept{C++ wrappers} 50 | -------------------------------------------------------------------------------- /man/figures/Stemwardness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/man/figures/Stemwardness.png -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclearchivedarchived -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledefunctdefunct -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycledeprecateddeprecated -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecycleexperimentalexperimental -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclematuringmaturing -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclequestioningquestioning -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclestablestable -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | lifecyclelifecyclesupersededsuperseded -------------------------------------------------------------------------------- /man/is.TreeNumber.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TreeNumber.R 3 | \name{is.TreeNumber} 4 | \alias{is.TreeNumber} 5 | \title{Is an object a \code{TreeNumber} object?} 6 | \usage{ 7 | is.TreeNumber(x) 8 | } 9 | \arguments{ 10 | \item{x}{R object.} 11 | } 12 | \value{ 13 | \code{is.TreeNumber()} returns a logical vector of length one specifying 14 | whether \code{x} inherits the class \code{"TreeNumber"}. 15 | } 16 | \description{ 17 | Is an object a \code{TreeNumber} object? 18 | } 19 | \examples{ 20 | is.TreeNumber(FALSE) # FALSE 21 | is.TreeNumber(as.TreeNumber(BalancedTree(5))) # TRUE 22 | } 23 | \seealso{ 24 | Other 'TreeNumber' utilities: 25 | \code{\link{TreeNumber}}, 26 | \code{\link{print.TreeNumber}()} 27 | } 28 | \author{ 29 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 30 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 31 | } 32 | \concept{'TreeNumber' utilities} 33 | -------------------------------------------------------------------------------- /man/logDoubleFactorials.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{logDoubleFactorials} 5 | \alias{logDoubleFactorials} 6 | \title{Natural logarithms of double factorials} 7 | \format{ 8 | An object of class \code{numeric} of length 50000. 9 | } 10 | \usage{ 11 | logDoubleFactorials 12 | } 13 | \description{ 14 | \code{logDoubleFactorials} is a numeric vector with pre-calculated values of 15 | double factorials up to 50 000!!. 16 | } 17 | \seealso{ 18 | Other double factorials: 19 | \code{\link{DoubleFactorial}()}, 20 | \code{\link{doubleFactorials}} 21 | } 22 | \concept{double factorials} 23 | \keyword{datasets} 24 | -------------------------------------------------------------------------------- /man/match.Splits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/match.R 3 | \name{match,Splits,Splits-method} 4 | \alias{match,Splits,Splits-method} 5 | \alias{in.Splits} 6 | \alias{match} 7 | \alias{\%in\%,Splits,Splits-method} 8 | \title{Split matching} 9 | \usage{ 10 | \S4method{match}{Splits,Splits}(x, table, nomatch = NA_integer_, incomparables = NULL) 11 | 12 | in.Splits(x, table) 13 | 14 | match(x, table, nomatch = NA_integer_, incomparables = NULL) 15 | 16 | \S4method{\%in\%}{Splits,Splits}(x, table) 17 | } 18 | \arguments{ 19 | \item{x, table}{Object of class \code{Splits}.} 20 | 21 | \item{nomatch}{Integer value that will be used in place of \code{NA} in the case 22 | where no match is found.} 23 | 24 | \item{incomparables}{Ignored. (Included for consistency with generic.)} 25 | } 26 | \value{ 27 | \code{match()} returns an integer vector specifying the position in 28 | \code{table} that matches each element in \code{x}, or \code{nomatch} if no match is found. 29 | } 30 | \description{ 31 | \code{match()} returns a vector of the positions of (first) matches of splits in 32 | its first argument in its second. 33 | \code{\%in\%} is a more intuitive interface as a binary operator, which returns 34 | a logical vector indicating whether there is a match or not for each 35 | split in its left operand. 36 | } 37 | \details{ 38 | \code{in.Splits()} is an alias for \code{\%in\%}, included for backwards compatibility. 39 | It is deprecated and will be removed in a future release. 40 | } 41 | \examples{ 42 | splits1 <- as.Splits(BalancedTree(7)) 43 | splits2 <- as.Splits(PectinateTree(7)) 44 | 45 | match(splits1, splits2) 46 | } 47 | \seealso{ 48 | Corresponding base functions are documented in 49 | \code{\link[base:match]{match()}}. 50 | 51 | Other Splits operations: 52 | \code{\link{LabelSplits}()}, 53 | \code{\link{NSplits}()}, 54 | \code{\link{NTip}()}, 55 | \code{\link{PolarizeSplits}()}, 56 | \code{\link{SplitFrequency}()}, 57 | \code{\link{Splits}}, 58 | \code{\link{SplitsInBinaryTree}()}, 59 | \code{\link{TipLabels}()}, 60 | \code{\link{TipsInSplits}()}, 61 | \code{\link{xor}()} 62 | } 63 | \concept{Splits operations} 64 | \keyword{methods} 65 | -------------------------------------------------------------------------------- /man/nRootedShapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{nRootedShapes} 5 | \alias{nRootedShapes} 6 | \alias{nUnrootedShapes} 7 | \title{Number of rooted / unrooted tree shapes} 8 | \format{ 9 | An object of class \code{integer64} of length 55. 10 | 11 | An object of class \code{integer64} of length 60. 12 | } 13 | \source{ 14 | \code{nRootedShapes} corresponds to the Wedderburn-Etherington numbers, 15 | \href{https://oeis.org/A001190}{\acronym{OEIS} A001190} 16 | 17 | \code{nUnrootedShapes} is \href{https://oeis.org/A000672}{\acronym{OEIS} A000672} 18 | } 19 | \usage{ 20 | nRootedShapes 21 | 22 | nUnrootedShapes 23 | } 24 | \description{ 25 | \code{nRootedShapes} and \code{nUnrootedShapes} give the number of (un)rooted binary 26 | trees on \emph{n} unlabelled leaves. 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/print.TreeNumber.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/TreeNumber.R 3 | \name{print.TreeNumber} 4 | \alias{print.TreeNumber} 5 | \title{Print \code{TreeNumber} object} 6 | \usage{ 7 | \method{print}{TreeNumber}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{Object of class \code{TreeNumber}.} 11 | 12 | \item{\dots}{Additional arguments for consistency with S3 method (unused).} 13 | } 14 | \description{ 15 | S3 method for objects of class \code{TreeNumber}. 16 | } 17 | \seealso{ 18 | Other 'TreeNumber' utilities: 19 | \code{\link{TreeNumber}}, 20 | \code{\link{is.TreeNumber}()} 21 | } 22 | \concept{'TreeNumber' utilities} 23 | -------------------------------------------------------------------------------- /man/root_on_node.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports-manual.R 3 | \name{root_on_node} 4 | \alias{root_on_node} 5 | \title{Wrapper for internal C function \code{root_on_node()}} 6 | \usage{ 7 | root_on_node(phy, outgroup) 8 | } 9 | \arguments{ 10 | \item{phy}{Minimally, a named list with entries \code{edge} and \code{Nnode}, in the 11 | format of equivalent entries in a tree of class \code{phylo}. \code{edge.length} will 12 | also be considered if supplied.} 13 | 14 | \item{outgroup}{Integer specifying index of leaf or node to set as the 15 | outgroup.} 16 | } 17 | \value{ 18 | \code{root_on_node()} returns \code{phy} rooted on the specified node. 19 | } 20 | \description{ 21 | Direct entry point to \code{root_on_node()}; recommended for expert use only. 22 | \code{RootTree()} checks that input is properly formatted and is recommended 23 | for general use. 24 | } 25 | \author{ 26 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 27 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/sort.multiPhylo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sort.R 3 | \name{sort.multiPhylo} 4 | \alias{sort.multiPhylo} 5 | \alias{==.phylo} 6 | \alias{<.phylo} 7 | \alias{>.phylo} 8 | \alias{==.MixedBase} 9 | \alias{<.MixedBase} 10 | \alias{>.MixedBase} 11 | \title{Sort a list of phylogenetic trees} 12 | \usage{ 13 | \method{sort}{multiPhylo}(x, decreasing = FALSE, na.last = NA, ...) 14 | 15 | \method{==}{phylo}(e1, e2) 16 | 17 | \method{<}{phylo}(e1, e2) 18 | 19 | \method{>}{phylo}(e1, e2) 20 | 21 | \method{==}{MixedBase}(e1, e2) 22 | 23 | \method{<}{MixedBase}(e1, e2) 24 | 25 | \method{>}{MixedBase}(e1, e2) 26 | } 27 | \arguments{ 28 | \item{x, decreasing, na.last, \dots}{As in \code{\link[=sort]{sort()}}.} 29 | 30 | \item{e1, e2}{Objects to be compared.} 31 | } 32 | \description{ 33 | Trees are sorted by their \link[=TreeNumber]{mixed base representation}, 34 | treating their leaves in the order of their labels (i.e. alphabetically, 35 | if leaves are labelled with text). 36 | } 37 | \examples{ 38 | sort(as.phylo(5:0, 7)) 39 | } 40 | \seealso{ 41 | Other utility functions: 42 | \code{\link{ClusterTable}}, 43 | \code{\link{ClusterTable-methods}}, 44 | \code{\link{Hamming}()}, 45 | \code{\link{MSTEdges}()}, 46 | \code{\link{SampleOne}()}, 47 | \code{\link{TipTimedTree}()}, 48 | \code{\link{UnshiftTree}()}, 49 | \code{\link{as.multiPhylo}()}, 50 | \code{\link{match,phylo,phylo-method}}, 51 | \code{\link{sapply64}()} 52 | } 53 | \author{ 54 | \href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith} 55 | (\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk}) 56 | } 57 | \concept{utility functions} 58 | -------------------------------------------------------------------------------- /man/xor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Splits.R 3 | \name{xor} 4 | \alias{xor} 5 | \alias{xor,Splits,Splits-method} 6 | \title{Exclusive OR operation} 7 | \usage{ 8 | xor(x, y) 9 | 10 | \S4method{xor}{Splits,Splits}(x, y) 11 | } 12 | \arguments{ 13 | \item{x, y}{Objects to be compared.} 14 | } 15 | \description{ 16 | Exclusive OR operation 17 | } 18 | \seealso{ 19 | Other Splits operations: 20 | \code{\link{LabelSplits}()}, 21 | \code{\link{NSplits}()}, 22 | \code{\link{NTip}()}, 23 | \code{\link{PolarizeSplits}()}, 24 | \code{\link{SplitFrequency}()}, 25 | \code{\link{Splits}}, 26 | \code{\link{SplitsInBinaryTree}()}, 27 | \code{\link{TipLabels}()}, 28 | \code{\link{TipsInSplits}()}, 29 | \code{\link{match,Splits,Splits-method}} 30 | } 31 | \concept{Splits operations} 32 | -------------------------------------------------------------------------------- /memcheck/examples.R: -------------------------------------------------------------------------------- 1 | # Code to be run with 2 | # R -d "valgrind --tool=memcheck --leak-check=full --error-exitcode=1" --vanilla < memcheck/thisfile.R 3 | devtools::run_examples() 4 | -------------------------------------------------------------------------------- /memcheck/tests.R: -------------------------------------------------------------------------------- 1 | # Code to be run with 2 | # R -d "valgrind --tool=memcheck --leak-check=full --error-exitcode=1" --vanilla < memcheck/thisfile.R 3 | library("TreeTools") 4 | devtools::test() 5 | -------------------------------------------------------------------------------- /memcheck/vignettes.R: -------------------------------------------------------------------------------- 1 | # Code to be run with 2 | # R -d "valgrind --tool=memcheck --leak-check=full --error-exitcode=1" --vanilla < memcheck/thisfile.R 3 | devtools::build_vignettes(install = FALSE) 4 | -------------------------------------------------------------------------------- /src/ClusterTable.cpp: -------------------------------------------------------------------------------- 1 | #include "../inst/include/TreeTools/ClusterTable.h" 2 | #include 3 | 4 | // Modelled on https://CRAN.R-project.org/package=Rcpp/vignettes/Rcpp-modules.pdf 5 | // [[Rcpp::export]] 6 | SEXP ClusterTable_new(Rcpp::List phylo) { 7 | Rcpp::XPtr 8 | ptr(new TreeTools::ClusterTable(phylo), true); 9 | 10 | return ptr; 11 | } 12 | 13 | // [[Rcpp::export]] 14 | Rcpp::IntegerMatrix ClusterTable_matrix(SEXP xp) { 15 | Rcpp::XPtr ptr(xp); 16 | return ptr->X_contents(); 17 | } 18 | 19 | // [[Rcpp::export]] 20 | Rcpp::IntegerVector ClusterTable_decode(SEXP xp) { 21 | Rcpp::XPtr ptr(xp); 22 | return ptr->X_decode(); 23 | } 24 | -------------------------------------------------------------------------------- /src/ape_reorder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ape_reorder.h" 3 | using namespace Rcpp; 4 | 5 | // [[Rcpp::export]] 6 | IntegerVector ape_neworder_phylo(IntegerVector n_tips, IntegerVector parent, 7 | IntegerVector child, IntegerVector n_edges, 8 | IntegerVector order) { 9 | IntegerVector neworder(parent.size() * 2); 10 | 11 | ape_neworder_phylo( 12 | reinterpret_cast(n_tips.begin()), 13 | reinterpret_cast(parent.begin()), 14 | reinterpret_cast(child.begin()), 15 | reinterpret_cast(n_edges.begin()), 16 | reinterpret_cast(neworder.begin()), 17 | reinterpret_cast(order.begin()) 18 | ); 19 | 20 | return neworder; 21 | } 22 | 23 | // [[Rcpp::export]] 24 | IntegerVector ape_neworder_pruningwise( 25 | IntegerVector n_tips, IntegerVector n_node, 26 | IntegerVector parent, IntegerVector child, 27 | IntegerVector n_edges) { 28 | IntegerVector neworder(parent.size() * 2); 29 | 30 | ape_neworder_pruningwise( 31 | reinterpret_cast(n_tips.begin()), 32 | reinterpret_cast(n_node.begin()), 33 | reinterpret_cast(parent.begin()), 34 | reinterpret_cast(child.begin()), 35 | reinterpret_cast(n_edges.begin()), 36 | reinterpret_cast(neworder.begin()) 37 | ); 38 | 39 | return neworder; 40 | } 41 | -------------------------------------------------------------------------------- /src/kept_vertices.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include /* for make_unique */ 3 | #include "../inst/include/TreeTools/types.h" 4 | using namespace Rcpp; 5 | 6 | #define PARENT(i) edge(i, 0) 7 | #define CHILD(i) edge(i, 1) 8 | 9 | // edge must be a two-column edge matrix in preorder 10 | // [[Rcpp::export]] 11 | IntegerVector kept_vertices(const IntegerMatrix edge, 12 | const LogicalVector kept) { 13 | const int 14 | start_edge = edge.nrow(), 15 | n_tip = kept.length(), 16 | root_node = n_tip + 1, 17 | all_nodes = start_edge + 2 18 | ; 19 | 20 | IntegerVector ret(edge.nrow() + 2); 21 | // Initialize leaves 22 | for (intx i = kept.length(); i--; ) { 23 | if (kept[i]) { 24 | ret[i + 1] = 2; 25 | } 26 | } 27 | 28 | int root_edges = 0; 29 | auto one_child = std::make_unique(all_nodes); 30 | // Traverse in postorder 31 | for (intx i = edge.nrow(); i--; ) { 32 | const int 33 | edge_child = CHILD(i), 34 | edge_parent = PARENT(i), 35 | downstream = ret[edge_child] 36 | ; 37 | if (edge_parent == root_node) { 38 | ++root_edges; 39 | } 40 | if (downstream) { 41 | ++ret[edge_parent]; 42 | if (downstream == 1) { 43 | one_child[edge_parent] = one_child[edge_child]; 44 | } else { 45 | one_child[edge_parent] = edge_child; 46 | } 47 | } 48 | } 49 | 50 | // Collapse root if necessary 51 | int new_root = root_node; 52 | if (ret[root_node] == 1) { 53 | // We've deleted one side of the tree entirely, creating a trailing root 54 | new_root = one_child[root_node]; 55 | } 56 | const bool rooted = root_edges == 2; 57 | if (!rooted && ret[new_root] == 2) { 58 | // In preorder, the first node after root is its descendant, 59 | // which is redundant -- we need to zap it. 60 | for (int i = new_root + 1; i != ret.length(); ++i) { 61 | if (ret[i] > 1) { 62 | ret[i] = -1; 63 | break; 64 | } 65 | } 66 | } 67 | 68 | return ret; 69 | } 70 | -------------------------------------------------------------------------------- /src/path_lengths.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include /* for make_unique */ 3 | #include "../inst/include/TreeTools/types.h" 4 | using namespace Rcpp; 5 | 6 | #define PARENT(i) edge(i, 0) 7 | #define CHILD(i) edge(i, 1) 8 | 9 | // edge must be a two-column edge matrix in preorder 10 | // [[Rcpp::export]] 11 | NumericMatrix path_lengths(const IntegerMatrix edge, const DoubleVector weight) { 12 | const intx 13 | root_node = edge[0], 14 | n_tip = root_node - 1, 15 | n_edge = edge.nrow(), 16 | n_vert = n_edge + 1, 17 | r_to_c = 1 18 | ; 19 | 20 | NumericMatrix ret(n_vert + 1, n_vert + 1); 21 | ret.fill(NumericVector::get_na()); 22 | auto 23 | parent_of = std::make_unique(n_vert + r_to_c), 24 | parent_edge = std::make_unique(n_vert + r_to_c) 25 | ; 26 | for (intx i = n_edge; i--; ) { 27 | parent_of[CHILD(i)] = PARENT(i); 28 | parent_edge[CHILD(i)] = i; 29 | ret(PARENT(i), CHILD(i)) = weight[i]; 30 | } 31 | auto this_path = std::make_unique(n_tip); 32 | for (intx tip = 1; tip <= n_tip; ++tip) { 33 | this_path[0] = tip; 34 | intx path_len = 1; 35 | for(;;) { 36 | intx this_parent = parent_of[this_path[path_len - 1]]; 37 | if (this_parent) { 38 | this_path[path_len] = this_parent; 39 | } else { 40 | break; 41 | } 42 | ++path_len; 43 | } 44 | // span = number of nodes spanned; i.e. edges included - 1 45 | for (intx span = 1; span < path_len - 1; ++span) { 46 | for (intx i = 0; i != path_len - span - 1; ++i) { 47 | const intx 48 | start = this_path[i + span + 1], 49 | add_to = this_path[i + span], 50 | end = this_path[i] 51 | ; 52 | ret(start, end) = ret(start, add_to) + ret(add_to, end); 53 | } 54 | } 55 | } 56 | return ret(Range(1, n_vert), Range(1, n_vert)); 57 | } 58 | -------------------------------------------------------------------------------- /src/tips_in_splits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include /* for errors */ 4 | #include "../inst/include/TreeTools.h" 5 | using namespace Rcpp; 6 | 7 | const uint_fast32_t powers_of_two[32] = { 8 | 0x1, 0x2, 0x4, 0x8, 9 | 0x10, 0x20, 0x40, 0x80, 10 | 0x100, 0x200, 0x400, 0x800, 11 | 0x1000, 0x2000, 0x4000, 0x8000, 12 | 0x10000, 0x20000, 0x40000, 0x80000, 13 | 0x100000, 0x200000, 0x400000, 0x800000, 14 | 0x1000000, 0x2000000, 0x4000000, 0x8000000, 15 | 0x10000000, 0x20000000, 0x40000000, 0x80000000 16 | }; 17 | 18 | uint_fast32_t bitcounts[65536]; // the bytes representing bit count of each number 0-65535 19 | __attribute__((constructor)) 20 | void initialize_bitcounts() { 21 | for (int_fast32_t i = 0; i < 65536; i++) { 22 | int_fast32_t n_bits = 0; 23 | for (int_fast8_t j = 0; j != 16; j++) { 24 | if ((i & powers_of_two[j])) ++n_bits; 25 | } 26 | bitcounts[i] = n_bits; 27 | } 28 | } 29 | 30 | // [[Rcpp::export]] 31 | IntegerVector tips_in_splits(RawMatrix splits) { 32 | const int32 33 | n_tip = splits.attr("nTip"), 34 | n_split = splits.nrow(), 35 | n_bin = (n_tip % 8 == 0 ? 0 : 1) + (n_tip / 8) 36 | ; 37 | if (n_tip < 0) { 38 | Rcpp::stop("nTip < 0"); 39 | } 40 | if (n_bin != splits.ncol()) { 41 | Rcpp::stop("nTip does not match split size"); 42 | } 43 | 44 | IntegerVector ret(n_split); 45 | for (int32 i = n_split; i--; ) { 46 | for (int32 bin = n_bin; bin--; ) { 47 | ret[i] += decltype(ret[0])(bitcounts[splits(i, bin)]); 48 | } 49 | } 50 | 51 | return ret; 52 | } 53 | -------------------------------------------------------------------------------- /tests/benchmark/benchmark-as.splits.R: -------------------------------------------------------------------------------- 1 | devtools::load_all() 2 | ub <- microbenchmark::microbenchmark 3 | set.seed(0) 4 | 5 | trees1k <- Cladewise(as.phylo(1:200, 1001)) 6 | 7 | bench <- summary(ub(Preorder(trees1k[[1]]), as.Splits(trees1k[[1]]))) 8 | meds <- bench$median 9 | meds[2] / meds[1] # 22.2 -> 8.8 10 | 11 | -------------------------------------------------------------------------------- /tests/benchmark/benchmark-consensus.R: -------------------------------------------------------------------------------- 1 | devtools::dev_mode() 2 | recompile <- FALSE 3 | pkgload::load_all(compile = recompile, export_all = FALSE, 4 | attach_testthat = FALSE) 5 | message("Generating trees") 6 | trs <- as.phylo(0:10000, 8888) 7 | message("Generating consensus") 8 | Consensus(trs, p = 0.5) 9 | if (interactive()) { 10 | trs <- as.phylo(0:1000, 888) 11 | microbenchmark::microbenchmark(Consensus(trs), # 434 → 404 → 43! 12 | consensus(trs), # 2000... 13 | times = c(12, 1)) 14 | } 15 | -------------------------------------------------------------------------------- /tests/benchmark/benchmark-preorder.R: -------------------------------------------------------------------------------- 1 | devtools::load_all() 2 | set.seed(0) 3 | 4 | trees1k <- Cladewise(as.phylo(1:200, 1001)) 5 | treesRl <- ape::read.tree("C:/research/r/rogue-ms/data-raw/simulations/431/all.bs") 6 | 7 | message(Sys.time(), ": Starting.") 8 | 9 | mb <- microbenchmark::microbenchmark 10 | times <- if (interactive()) 24 else 200 11 | mb(Preorder(trees1k), # 59-66 --> 38 12 | Postorder(trees1k), # 127-143 --> 51 13 | Preorder(treesRl), # 33-37 --> 23 14 | Postorder(treesRl), # 34-38 --> 30 15 | times = times) 16 | 17 | ub(Postorder(trees1k[[1]]$edge), 18 | postorder_order(trees1k[[1]]$edge)) 19 | 20 | message(Sys.time(), ": End.") 21 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test(vignettes = TRUE, error = TRUE, 3 | skip_on_cran = TRUE) 4 | } 5 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library("testthat") 2 | library("TreeTools", quietly = TRUE, warn.conflicts = FALSE) 3 | 4 | suppressPackageStartupMessages(test_check("TreeTools")) 5 | -------------------------------------------------------------------------------- /tests/testthat/test-ArtificialExtinction.R: -------------------------------------------------------------------------------- 1 | nTax <- 6L 2 | dataset <- matrix(seq_len(nTax), nrow = nTax, ncol = 6, 3 | dimnames = list(LETTERS[1:nTax], 1:6)) 4 | dataset[4, 3:5] <- "-" 5 | dataset[5:6, 4:6] <- "?" 6 | dataset[6, 3] <- "?" 7 | 8 | test_that("Errors are handled", { 9 | expect_error(ArtificialExtinction(dataset, "A", "E", replaceAmbiguous = "INVALID")) 10 | expect_error(ArtificialExtinction(dataset, "A", "E", replaceCoded = "INVALID")) 11 | }) 12 | 13 | test_that("Replacements ok", { 14 | expectation <- matrix(rep("?", 6), 2, 3, dimnames = list(c("A", "B"), 4:6)) 15 | expect_equal(expectation, 16 | ArtificialExtinction(dataset, subject = c("A", "B"), 17 | template = "E", 18 | replaceAmbiguous = "ambig")[1:2, 4:6]) 19 | 20 | expectation[] <- 1 21 | colnames(expectation) <- NULL 22 | expect_equal(PhyDatToMatrix(ArtificialExtinction( 23 | MatrixToPhyDat(dataset), 24 | c("A", "B"), "F", "unif", sampleFrom = "A" 25 | ))[1:2, 4:6], 26 | expectation 27 | ) 28 | 29 | expect_true(all(!"?" == ArtificialExtinction( 30 | dataset[-6, ], 1:2, 5, "freq" 31 | )[1:2, 4:6])) 32 | 33 | 34 | expect_true(all(ArtificialExtinction(dataset, subject = "E", template = "F", 35 | replaceAmbiguous = "binary")["E", 3:6] %in% 0:1)) 36 | 37 | expect_equal(setNames(rep("?", 3), 4:6), 38 | ArtificialExtinction(dataset, subject = "E", template = "F", 39 | replaceAmbiguous = "binary", 40 | replaceAll = FALSE)["E", 4:6]) 41 | 42 | nChar <- 100 43 | dataset <- rbind(subj = c(rep(2, nChar)), 44 | templ = c(rep(3, nChar / 2), rep("?", nChar / 2))) 45 | suppressWarnings(expect_gt(chisq.test(as.integer( 46 | ArtEx(dataset, 1, 2, "binary", "binary")[1, ]))$p.value, 0.05)) 47 | }) 48 | -------------------------------------------------------------------------------- /tests/testthat/test-BigInteger.R: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ms609/TreeTools/50fbe63afdb9f12de9768ed89bc8824793c223bf/tests/testthat/test-BigInteger.R -------------------------------------------------------------------------------- /tests/testthat/test-ClusterTable.R: -------------------------------------------------------------------------------- 1 | test_that("ClusterTable fails gracefully", { 2 | bigTree <- PectinateTree(2^14 + 1) 3 | expect_error( 4 | as.ClusterTable(bigTree), 5 | "Tree has too many leaves. Contact the .TreeTools. maintainer." 6 | ) 7 | }) 8 | 9 | test_that("ClusterTable class behaves", { 10 | tree <- RootTree(BalancedTree(6), 1) 11 | ct <- as.ClusterTable(tree) 12 | expect_equal(matrix(c(0, 2, rep(1, 4), 0, 3, 3:6), 6), 13 | as.matrix.ClusterTable(ct)) 14 | expect_equal(ClusterTable_decode(ct), 6:1) 15 | 16 | expect_equal(capture.output(ct), 17 | "ClusterTable on 6 leaves: t1 .. t6") 18 | 19 | expect_equal( 20 | capture.output(summary(ct)), 21 | c("ClusterTable on 6 leaves:", 22 | " 123456", 23 | " .**...", 24 | " ***...", 25 | " ****..", 26 | " *****.", 27 | " ******", 28 | " 1: t6 2: t5 3: t4 4: t3 5: t2 6: t1 ") 29 | ) 30 | 31 | ClusterSummary <- function(...) capture.output(summary(as.ClusterTable(...))) 32 | t1..8 <- paste0("t", 1:8) 33 | t8..1 <- rev(t1..8) 34 | expect_equal( 35 | ClusterSummary(BalancedTree(t8..1), 36 | tipLabels = t1..8), 37 | ClusterSummary(BalancedTree(t1..8)) 38 | ) 39 | 40 | byList <- as.ClusterTable(list(BalancedTree(t8..1), PectinateTree(t8..1)), 41 | tipLabels = t1..8) 42 | listBy <- list(as.ClusterTable(BalancedTree(t1..8)), 43 | as.ClusterTable(PectinateTree(t1..8))) 44 | expect_equal(capture.output(summary(byList[[2]])), 45 | capture.output(summary(listBy[[2]]))) 46 | 47 | }) 48 | 49 | test_that("Attributes are correct", { 50 | t6 <- as.ClusterTable(BalancedTree(6)) 51 | t7 <- as.ClusterTable(PectinateTree(7)) 52 | t8 <- as.ClusterTable(BalancedTree(8)) 53 | s8 <- StarTree(8) 54 | expect_equal(3, NSplits(t6)) 55 | expect_equal(4:5, NSplits(list(t7, t8))) 56 | 57 | expect_equal(6, NTip(t6)) 58 | expect_equal(7:8, NTip(list(t7, t8))) 59 | 60 | #TODO test TipLabels, SplitsInBalancedTree 61 | }) 62 | -------------------------------------------------------------------------------- /tests/testthat/test-Decompose.R: -------------------------------------------------------------------------------- 1 | test_that("Decompose()", { 2 | data("Lobo") 3 | 4 | expect_error(Decompose("Lobo.phy"), "phyDat") 5 | 6 | expect_error(Decompose(Lobo.phy, logical(11)), 7 | "length.indices.* number of characters in .dataset.") 8 | 9 | expect_warning(decomposed <- Decompose(Lobo.phy, c(1234:1235, 11)), 10 | "115 characters; .*1234, 1235 not found") 11 | 12 | NumberOfChars <- function(x) sum(attr(x, "weight")) 13 | expect_equal(NumberOfChars(decomposed), 14 | NumberOfChars(Lobo.phy) + 1) 15 | 16 | expect_equal(attr(decomposed, "originalIndex"), 17 | c(1:11, 11:115)) 18 | 19 | expect_equal(attr(Decompose(Lobo.phy, 10:12), "originalIndex"), 20 | c(1:11, 11:115)) 21 | 22 | decompMat <- as.matrix(decomposed) 23 | taxa <- c(8, 11, 12, 37, 36) 24 | if (interactive()) { 25 | dput(as.character(as.matrix(Lobo.phy)[taxa, 11])) 26 | # = c("?", "{01}", "0", "1", "2") 27 | } 28 | expect_equal(decompMat[taxa, 11:12], 29 | matrix(c("?", "{01}", "0", "1", "1", 30 | "?", "0", "0", "0", "1"), ncol = 2, 31 | dimnames = list(names(Lobo.phy)[taxa]))) 32 | 33 | unchanged <- Decompose(Lobo.phy, logical(115)) 34 | 35 | expect_equal(gsub("\\{\\-(\\d)\\}", "{\\1-}", perl = TRUE, 36 | as.matrix(unchanged)), # Order unimportant 37 | as.matrix(Lobo.phy)) 38 | 39 | expect_equal(Decompose(Lobo.phy[, 1], TRUE), 40 | structure(Lobo.phy[, 1], originalIndex = 1)) 41 | 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-KeptPaths.R: -------------------------------------------------------------------------------- 1 | test_that("KeptPaths() works", { 2 | tree <- BalancedTree(7) 3 | tree$edge.length <- 1:12 4 | paths <- PathLengths(tree) 5 | keptTips <- c(2, 4, 6) 6 | kept <- KeptVerts(tree, 1:7 %in% keptTips) 7 | lengths <- c(1 + 2 + 4, 8 | 2 + 4, 9 | 1 + 5 + 7, 10 | 5 + 7, 11 | 8 + 9 + 11, 12 | 1) 13 | expect_equal(paths[KeptPaths(paths, kept), "length"], lengths) 14 | expect_equal(paths[KeptPaths(paths, kept, FALSE), "length"], 15 | lengths[c(2, 4:6)]) 16 | expected <- PathLengths(KeepTip(tree, keptTips)) 17 | expected[, 1:2] <- which(kept)[unlist(expected[, 1:2])] 18 | 19 | KeptPaths(PathLengths(tree, TRUE), kept) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-PathLengths.R: -------------------------------------------------------------------------------- 1 | test_that("PathLengths() works", { 2 | expect_error(PathLengths(matrix(0, 2, 2)), 3 | "object of class") 4 | bal9 <- BalancedTree(9) 5 | bal9$edge.length <- 1:16 6 | pl <- PathLengths(bal9, fullMatrix = TRUE) 7 | expect_equal(dim(pl), rep(17L, 2)) 8 | Test <- function(tr) { 9 | calculated <- PathLengths(tr, full = TRUE) 10 | edge <- tr$edge 11 | parent <- edge[, 1] 12 | child <- edge[, 2] 13 | weight <- tr[["edge.length"]] 14 | nVert <- tr$Nnode + NTip(tr) 15 | anc <- AllAncestors(parent, child) 16 | parentEdge <- match(seq_len(nVert), child) 17 | lapply(seq_len(nVert)[-(NTip(tr) + 1L)], function(end) { 18 | ancs <- anc[[end]] 19 | expect_equal(calculated[ancs, end], 20 | cumsum(weight[parentEdge[c(end, ancs[-length(ancs)])]])) 21 | }) 22 | } 23 | Test(bal9) 24 | 25 | pec8 <- CollapseNode(PectinateTree(8), 12:13) 26 | pec8$edge.length <- 1:12 27 | Test(pec8) 28 | 29 | bal9$edge.length <- rep_len(1, 16) 30 | expect_equal(PathLengths(BalancedTree(9)), PathLengths(bal9)) 31 | 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-ReadMrBayes.R: -------------------------------------------------------------------------------- 1 | test_that("ReadMrBayes() fails gracefully", { 2 | expect_error(MrBayesTrees("notA-file", burninFrac = 1), 3 | "Cannot find notA-file\\.run1") 4 | }) 5 | -------------------------------------------------------------------------------- /tests/testthat/test-Stemwardness.R: -------------------------------------------------------------------------------- 1 | test_that("Stemwardness functions", { 2 | bal8 <- BalancedTree(8) 3 | pec8 <- PectinateTree(8) 4 | pr3 <- RootTree(pec8, "t3") 5 | 6 | expect_equal(1L, SisterSize(bal8, 3)) 7 | expect_equal(2L, RootNodeDist(bal8, 3)) 8 | 9 | expect_equal(5L, SisterSize(pec8, "t3")) 10 | expect_equal(2L, RootNodeDist(pec8, "t3")) 11 | 12 | expect_equal(7L, SisterSize(pr3, "t3")) 13 | expect_equal(0L, RootNodeDist(pr3, "t3")) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-TipTimedTree.R: -------------------------------------------------------------------------------- 1 | test_that("TipTimedTree() example works", { 2 | expect_equal( 3 | TipTimedTree(BalancedTree(6), tipAge = 1:6, minEdge = 2)[["edge.length"]], 4 | c(5, 2, 3, 2, 3, 2, 2, 3, 2, 3) 5 | ) 6 | expect_equal( 7 | TipTimedTree(Postorder(BalancedTree(6)), tipAge = 1:6, minEdge = .5)$edge.l, 8 | c(0.5, 1.5, 1, 0.5, 0.5, 1.5, 1, 0.5, 0.5, 3.5) 9 | ) 10 | expect_error(TipTimedTree(BalancedTree(5), 1:10), "one age per leaf") 11 | expect_error(TipTimedTree(BalancedTree(5), double(0)), "one age per leaf") 12 | expect_warning(expect_equal(TipTimedTree(SingleTaxonTree(1), 1, 100)$edge.l, 13 | 100), "does not contain multiple edges") 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-TopologyOnly.R: -------------------------------------------------------------------------------- 1 | test_that("TopologyOnly() works", { 2 | topol <- as.phylo(10, 5) 3 | tree <- topol 4 | tree[["edge.length"]] <- topol[["edge"]][, 1] 5 | tree[["node.label"]] <- seq_len(topol$Nnode) 6 | 7 | # .phylo 8 | expect_equal(TopologyOnly(tree), topol) 9 | expect_equal(TopologyOnly(Postorder(tree)), topol) 10 | 11 | # .list 12 | expect_equal(TopologyOnly(list(tree, tree)), list(topol, topol)) 13 | 14 | # .multiPhylo 15 | expect_equal(TopologyOnly(c(tree, tree)), c(topol, topol)) 16 | 17 | # .Splits 18 | expect_equal(TopologyOnly(as.Splits(tree)), as.Splits(topol)) 19 | 20 | # .NULL 21 | expect_null(TopologyOnly(NULL)) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-as.matrix.R: -------------------------------------------------------------------------------- 1 | test_that("as.matrix(phylo)", { 2 | bal8 <- BalancedTree(8) 3 | sp8 <- as.Splits(bal8) 4 | expect_equal(as.matrix(bal8), 1 * as.logical(sp8)) 5 | expect_equal(TipLabels(as.matrix(bal8)), TipLabels(bal8)) 6 | expect_equal(as.logical(bal8), as.logical(sp8)) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-as.multiPhylo.R: -------------------------------------------------------------------------------- 1 | test_that("as.multiPhylo()", { 2 | expect_equal(structure(list(BalancedTree(8), PectinateTree(8)), 3 | class = "multiPhylo"), 4 | as.multiPhylo(list(BalancedTree(8), PectinateTree(8)))) 5 | expect_equal(structure(list(BalancedTree(8)), class = "multiPhylo"), 6 | as.multiPhylo(BalancedTree(8))) 7 | 8 | char <- MatrixToPhyDat(matrix(c(1,1,1,0,0,0), ncol = 1, 9 | dimnames = list(letters[1:6], NULL))) 10 | expect_equal(ape::read.tree(text = "((a, b, c), (d, e, f));"), 11 | as.multiPhylo(char)[[1]]) 12 | 13 | char2 <- MatrixToPhyDat(matrix(c(1,1,1,0,0,0, 14 | 0,1,1,1,1,"?", 15 | 0,0,1,1,"-",2, 16 | 0,1,1,1,1,"?"), ncol = 4, 17 | dimnames = list(letters[1:6], NULL))) 18 | mpChar2 <- as.multiPhylo(char2) 19 | 20 | expect_equal(ape::read.tree(text = "((a, b, c), (d, e, f));"), 21 | mpChar2[[1]]) 22 | expect_equal(ape::read.tree(text = "(b, c, d, e);"), 23 | mpChar2[[2]]) 24 | expect_equal(ape::read.tree(text = "((a, b), (c, d));"), 25 | mpChar2[[3]]) 26 | expect_equal(mpChar2[[2]], mpChar2[[4]]) 27 | 28 | mpSplits <- as.Splits(PectinateTree(letters[1:6])) 29 | expect_true(all.equal(as.multiPhylo(mpSplits), structure(list( 30 | "9" = ape::read.tree(text = "((a, b), (c, d, e, f));"), 31 | "10" = ape::read.tree(text = "((a, b, c), (d, e, f));"), 32 | "11" = ape::read.tree(text = "((a, b, c, d), (e, f));")), 33 | class = "multiPhylo"))) 34 | 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-helper_functions.R: -------------------------------------------------------------------------------- 1 | test_that("UnshiftTree() works", { 2 | t1 <- as.phylo(1, 8) 3 | t2..9 <- setNames(as.phylo(2:3, 8), letters[2:3]) 4 | t1..9 <- setNames(as.phylo(1:3, 8), c("", letters[2:3])) 5 | attr(t1..9, "tip.label") <- NULL 6 | expect_true(all.equal(UnshiftTree(t1, t2..9), t1..9)) 7 | expect_equal(unclass(t1..9), UnshiftTree(t1, unclass(t2..9))) 8 | expectation <- as.phylo(1:2, 8) 9 | attr(expectation, "tip.label") <- NULL 10 | expect_equal(expectation, UnshiftTree(t1, as.phylo(2, 8))) 11 | }) 12 | 13 | 14 | test_that("SpectrumLegend()", { 15 | skip_if(packageVersion("graphics") < "4.1") 16 | skip_if(packageVersion("vdiffr") < "1.0") 17 | vdiffr::expect_doppelganger("SpectrumLegend", function() { 18 | 19 | # Set up blank plot 20 | plot(0:1, 10:11, asp = 1, type = "n", frame.plot = FALSE, 21 | xlab = "x", ylab = "y") 22 | expect_warning( 23 | SpectrumLegend(legend = c("Bottom", "Middle", "Top"), 24 | lwd = 5, 25 | palette = rev(hcl.colors(256L, "RdYlBu")), 26 | text.col = c("blue", "brown", "red"), 27 | title = "Blue title", title.font = 3, title.cex = 0.5), 28 | "'SpectrumLegend' is deprecated.") 29 | expect_warning( 30 | SpectrumLegend(0.4, 10.6, 0.2, 11, abs = TRUE, 31 | legend = seq(0, 10, by = 2), palette = 0:10, 32 | lty = "dotted", pos = 2, 33 | lmitre = 2, lend = "round", ljoin = "round", 34 | title = "Multi-\nline\ntitle", xpd = NA), 35 | "'SpectrumLegend' is deprecated.") 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-information.R: -------------------------------------------------------------------------------- 1 | test_that("Trees matching splits calculated correctly", { 2 | expect_equal(NUnrooted(9), TreesMatchingSplit(0, 9)) 3 | expect_equal(NUnrooted(9), TreesMatchingSplit(9, 0)) 4 | expect_equal(NUnrooted(9), TreesMatchingSplit(8, 1)) 5 | expect_equal(LnUnrooted(9), LnTreesMatchingSplit(0, 9)) 6 | expect_equal(LnUnrooted.int(9), LnTreesMatchingSplit(9, 0)) 7 | expect_equal(LnUnrooted.int(9), LnTreesMatchingSplit(1, 8)) 8 | expect_equal(NUnrooted(9), TreesMatchingSplit(8, 1)) 9 | expect_equal(Log2Unrooted(9), Log2TreesMatchingSplit(0, 9)) 10 | expect_equal(Log2Unrooted.int(9), Log2TreesMatchingSplit(9, 0)) 11 | expect_equal(Log2Unrooted.int(9), Log2TreesMatchingSplit(1, 8)) 12 | expect_equal(log(315/10395)/-log(2), SplitInformation(3, 5)) 13 | }) 14 | 15 | test_that("UnrootedTreesMatchingSplit() correct", { 16 | expect_equal(NRooted(3) * NRooted(5), UnrootedTreesMatchingSplit(c(3, 5))) 17 | expect_equal(LnRooted(30) + LnRooted(50), LnUnrootedTreesMatchingSplit(30, 50)) 18 | expect_equal(sum(log2DoubleFactorials[15], 19 | Log2DoubleFactorial(1:4 + 1:4 - 3L)) 20 | - log2DoubleFactorials[11], 21 | Log2UnrootedTreesMatchingSplit(1:4)) 22 | }) 23 | 24 | test_that("MultiSplitInformation() works", { 25 | expect_equal(12.8323, MultiSplitInformation(3:5), tolerance = 6) 26 | expect_equal(CharacterInformation(rep(c("-", "?", 0:2), 1:5)), 27 | MultiSplitInformation(3:5)) 28 | }) 29 | 30 | test_that("TreesMatchingSplit() accepts different formats", { 31 | expect_equal(TreesMatchingSplit(4, 5), TreesMatchingSplit(4:5)) 32 | expect_equal(LnTreesMatchingSplit(4, 5), LnTreesMatchingSplit(4:5)) 33 | expect_equal(Log2TreesMatchingSplit(4, 5), Log2TreesMatchingSplit(4:5)) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-match.R: -------------------------------------------------------------------------------- 1 | test_that("match.multiPhylo()", { 2 | t1 <- BalancedTree(6) 3 | t2 <- PectinateTree(7) 4 | t9 <- StarTree(99) 5 | trees <- c(t2, t1, StarTree(5), t2, t1) 6 | 7 | expect_true(t1 %in% t1) 8 | expect_false(t9 %in% t1) 9 | expect_false(t1 %in% t9) 10 | expect_true(t2 %in% trees) 11 | expect_false(t9 %in% trees) 12 | expect_equal(trees %in% t1, c(FALSE, TRUE, FALSE, FALSE, TRUE)) 13 | 14 | expect_equal(trees[1:2] %in% trees, c(TRUE, TRUE)) 15 | expect_equal(trees %in% trees[1:2], c(TRUE, TRUE, FALSE, TRUE, TRUE)) 16 | 17 | 18 | expect_equal(match(t1, t9, nomatch = 123), 123) 19 | expect_equal(match(t1, t1, nomatch = 123), 1) 20 | expect_equal(match(t2, c(t1, t2)), 2) 21 | expect_equal(match(t9, c(t1, t2)), NA_integer_) 22 | 23 | expect_equal(match(c(t1, t2), t2),c(NA, 1)) 24 | expect_equal(match(c(t1, t2), t9), rep(NA_integer_, 2)) 25 | 26 | expect_equal(match(c(t1, t2), c(t2, t1, t9)), match(1:2, 2:0)) 27 | expect_equal(match(c(t1, t2, t9), c(t2, t1)), match(1:3, 2:1)) 28 | expect_equal(match(c(t1, t2, t1), c(t9, t9)), match(1:3, 5:6)) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-mst.R: -------------------------------------------------------------------------------- 1 | test_that("MSTEdges() handles bad input", { 2 | expect_error(MSTEdges(matrix(1:12, 6, 2)), "distance") 3 | }) 4 | 5 | test_that("minimum_spanning_tree.cpp handles bad input", { 6 | expect_equal(minimum_spanning_tree(numeric(0)), matrix(0, 0, 0)) 7 | expect_error(minimum_spanning_tree(c(1:-1)), 8 | "`order` contains entries < 0") 9 | expect_error(minimum_spanning_tree(c(3, 100, 1)), 10 | "`order` contains entries > `length.order.`") 11 | expect_error(minimum_spanning_tree(c(3, 1, NA_real_)), 12 | "`order` contains NA") 13 | expect_error(minimum_spanning_tree(0:13), 14 | "`length.order.`.* not.* triangular") 15 | }) 16 | 17 | test_that("MST edges calculated correctly", { 18 | set.seed(0) 19 | points <- matrix(c(0.1, 0, 1.9, 2, 1.1, 1, 20 | 0.1, 2, 0, 2, 1, 1.1, 21 | 0, 0, 0, 0, 1, -1), 6) 22 | distances <- dist(points) 23 | apeMst <- matrix(c(5, 6, 6, 5, 5, 1, 1:4), 5) 24 | distMat <- as.matrix(distances) 25 | expect_equal(MSTLength(distances, apeMst), 26 | MSTLength(distances)) 27 | expect_equal(MSTLength(distances), 28 | MSTLength(distMat)) 29 | MSTPlot <- function() { 30 | plot(points, asp = 1, ann = FALSE) 31 | expect_equal(MSTEdges(distances, FALSE), 32 | MSTEdges(distances, TRUE, points[, 1], points[, 2])) 33 | } 34 | skip_if_not_installed("vdiffr", minimum_version = "1.0.0") 35 | skip_if(packageVersion("graphics") < "4.1.0") 36 | vdiffr::expect_doppelganger("MST plotting", MSTPlot) 37 | }) 38 | 39 | test_that("MST handles large distance matrices", { 40 | x <- dist(0:300) 41 | expect_equal(c(300, 2), dim(MSTEdges(x))) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-sort.R: -------------------------------------------------------------------------------- 1 | test_that("Trees are sorted", { 2 | trees <- setNames(as.phylo(0:8, 8), paste0("as.phy", 0:8)) 3 | expect_true(trees[[1]] == trees[[1]]) 4 | expect_false(trees[[1]] == trees[[2]]) 5 | 6 | for (i in 1:8) { 7 | expect_true(trees[[i]] == trees[[i]]) 8 | expect_false(trees[[i]] > trees[[i]]) 9 | expect_false(trees[[i]] < trees[[i]]) 10 | for (j in (i + 1):9) { 11 | expect_true(trees[[i]] < trees[[j]]) 12 | expect_true(trees[[j]] > trees[[i]]) 13 | expect_false(trees[[j]] == trees[[i]]) 14 | expect_false(trees[[i]] == trees[[j]]) 15 | expect_false(trees[[i]] > trees[[j]]) 16 | expect_false(trees[[j]] < trees[[i]]) 17 | } 18 | } 19 | 20 | expect_equal(sort(trees), sort(rev(trees))) 21 | expect_equal(names(sort(rev(trees))), names(trees)) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-split_analysis.R: -------------------------------------------------------------------------------- 1 | test_that("TipsInSplits() family", { 2 | test <- TipsInSplits(BalancedTree(letters[1:5])) 3 | expect_identical(test, c("7" = 3L, "8" = 2L, "9" = 2L)[names(test)]) 4 | expect_equal(TipsInSplits(PectinateTree(7), smallest = TRUE), 5 | c("10" = 2, "11" = 3, "12" = 3, "13" = 2)) 6 | expect_identical(15:2, TipsInSplits(PectinateTree(17), keep.names = FALSE)) 7 | 8 | test <- SplitImbalance(BalancedTree(7)) 9 | expectation <- c("9" = 1L, "10" = 3L, "11" = 3L, "12" = 1L, "13" = 3L) 10 | expect_identical(test, expectation[names(test)]) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-splits.cpp.R: -------------------------------------------------------------------------------- 1 | test_that("Bad data results in error", { 2 | skip_if(Sys.getenv("USING_ASAN") != "") 3 | expect_error(cpp_edge_to_splits(matrix(1, 3, 3), 1:3, 3), 4 | "must contain two col") 5 | expect_equal(cpp_edge_to_splits(matrix(1, 10, 2), 1:10, 0), 6 | matrix(raw(0), 0, 0)) 7 | expect_error(cpp_edge_to_splits(matrix(1, 10, 2), 1:10, -10), 8 | "Tree must contain non-negative number of tips") 9 | expect_error(cpp_edge_to_splits(matrix(1, 10, 2), 1:9, 5), 10 | "ength of `order` must equal number of edges") 11 | expect_error(cpp_edge_to_splits(matrix(1, 2, 2), 1:2, 6), 12 | "Not enough edges") # Impossible anyway... 13 | 14 | s9 <- as.Splits(BalancedTree(9)) 15 | expect_error(duplicated_splits(structure(s9, nTip = NULL), TRUE), 16 | "`nTip` attribute") 17 | expect_error(duplicated_splits(structure(s9, nTip = 999L), TRUE), 18 | "tip number") 19 | 20 | expect_error(s9 & s9[[1]], "same number of splits") 21 | expect_error(s9 | s9[[1]], "same number of splits") 22 | expect_error(xor(s9, s9[[1]]), "same number of splits") 23 | 24 | noNTip <- structure(s9, nTip = NULL) 25 | expect_error(noNTip & s9, "`x` lacks nTip attrib") 26 | expect_error(noNTip | s9, "`x` lacks nTip attrib") 27 | expect_error(xor(noNTip, s9), "`x` lacks nTip attrib") 28 | 29 | expect_error(s9 & noNTip, "`y` lacks nTip attrib") 30 | expect_error(s9 | noNTip, "`y` lacks nTip attrib") 31 | expect_error(xor(s9, noNTip), "`y` lacks nTip attrib") 32 | 33 | wrongTip <- structure(s9, nTip = 15L) 34 | expect_error(xor(s9, wrongTip), "`y` differ in `nTip`") 35 | expect_error(s9 & wrongTip, "`y` differ in `nTip`") 36 | expect_error(s9 | wrongTip, "`y` differ in `nTip`") 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-tree_ancestors.R: -------------------------------------------------------------------------------- 1 | test_that("EdgeAncestry() works", { 2 | tree <- BalancedTree(10) 3 | edge <- tree$edge 4 | parent <- edge[, 1] 5 | child <- edge[, 2] 6 | expect_equal(which(EdgeAncestry(4L, parent, child)), 1:3) 7 | expect_equal(which(EdgeAncestry(2, parent, child)), 1) 8 | expect_equal(which(EdgeAncestry(1, parent, child)), integer(0)) 9 | expect_equal(EdgeAncestry(10, parent, child), logical(18)) 10 | }) 11 | 12 | test_that("MRCA() works", { 13 | bal7 <- BalancedTree(7) 14 | allAnc <- AllAncestors(bal7$edge[, 1], bal7$edge[, 2]) 15 | expect_equal(9, MRCA(1, 4, allAnc)) 16 | expect_equal(8, MRCA(1, 6, allAnc)) 17 | expect_equal(8, MRCA(1, 7, allAnc)) 18 | expect_equal(1, MRCA(1, 1, allAnc)) 19 | expect_equal(9, MRCA(1, 11, allAnc)) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-tree_comparison.R: -------------------------------------------------------------------------------- 1 | test_that("Pairwise distances calculated correctly", { 2 | nTrees <- 6L 3 | nTip <- 16L 4 | 5 | set.seed(0) 6 | trees <- lapply(rep(nTip, nTrees), RandomTree, root = TRUE) 7 | trees[[1]] <- BalancedTree(nTip) 8 | trees[[nTrees - 1L]] <- PectinateTree(nTip) 9 | class(trees) <- "multiPhylo" 10 | 11 | # From example 12 | TCIRange <- function(tree1, tree2) { 13 | range(TotalCopheneticIndex(tree1), TotalCopheneticIndex(tree2)) 14 | } 15 | tciPairs <- PairwiseDistances(trees, TCIRange, 2) 16 | expect_equal(length(tciPairs), 2) 17 | expect_equal(as.matrix(tciPairs[[1]])[3, 6], 18 | TCIRange(trees[[3]], trees[[6]])[1]) 19 | 20 | skip_if_not_installed("phangorn") 21 | trees <- reorder(trees, "cladewise") 22 | dists <- PairwiseDistances(trees, phangorn::RF.dist) 23 | expect_equal(as.integer(phangorn::RF.dist(trees)), as.integer(dists)) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-tree_generation-random.R: -------------------------------------------------------------------------------- 1 | test_that("Random trees are set by R seed", { 2 | 3 | set.seed(0) 4 | tr1 <- RandomTree(123) 5 | tr2 <- RandomTree(123) 6 | set.seed(0) 7 | tr3 <- RandomTree(123) 8 | tr4 <- RandomTree(123) 9 | expect_identical(tr1, tr3) 10 | expect_identical(tr2, tr4) 11 | expect_false(identical(tr1, tr2)) 12 | 13 | set.seed(1) 14 | tr5 <- RandomTree(123) 15 | set.seed(1) 16 | tr6 <- RandomTree(123) 17 | expect_identical(tr5, tr6) 18 | expect_false(identical(tr1, tr5)) 19 | 20 | }) 21 | 22 | test_that("Random trees drawn from uniform distribution", { 23 | # NB We're also testing sapply64 and vapply64 in this chunk 24 | expect_error(.RandomParent(1)) 25 | expect_error(.RandomParent(0)) 26 | expect_error(.RandomParent(-1)) 27 | 28 | nSamples <- 100 29 | # Ape's trees are not uniformly distributed: 30 | ape_counts <- table(vapply64(lapply(rep(5, nSamples), ape::rtree), 31 | as.TreeNumber, 1)) 32 | expect_lt(chisq.test(ape_counts)$p.value, 0.005) 33 | 34 | # Our trees are: 35 | counts <- table(sapply64(lapply(rep(5, nSamples), RandomTree), as.TreeNumber)) 36 | expect_gt(chisq.test(counts)$p.value, 0.001) 37 | 38 | if (FALSE) { # Takes many seconds - but worth checking manually? 39 | counts <- table(sapply64(lapply(rep(8, 200000), RandomTree), as.TreeNumber)) 40 | expect_gt(chisq.test(counts)$p.value, 0.001) 41 | } 42 | 43 | expect_false(is.rooted(RandomTree(6, root = FALSE))) 44 | expect_true(is.rooted(RandomTree(6, root = TRUE))) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-tree_information.R: -------------------------------------------------------------------------------- 1 | test_that("Cladistic info calculated correctly", { 2 | bal8 <- BalancedTree(8) 3 | expect_equal(1, TreesMatchingTree(bal8)) 4 | expect_equal(0, LnTreesMatchingTree(bal8)) 5 | expect_equal(Log2Unrooted(8), CladisticInfo(bal8)) 6 | expect_equal(0L, CladisticInfo(StarTree(8))) 7 | expect_equal(rep(CladisticInfo(PectinateTree(6)), 4), 8 | CladisticInfo(as.phylo(1:4, 6))) 9 | 10 | tr1 <- CollapseNode(bal8, 12:15) 11 | expect_equal(NUnrooted(4) * NUnrooted(5), 12 | TreesMatchingTree(tr1)) 13 | expect_equal(Log2Unrooted(8) - log2(45), CladisticInfo(tr1)) 14 | 15 | sizes <- 2:7 16 | expect_equal(setNames(-log2(apply(cbind(2:7, 7:2), 1, TreesMatchingSplit) / 17 | NUnrooted(9)), 12:17), 18 | CladisticInfo(as.Splits(PectinateTree(9)))) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-tree_write.R: -------------------------------------------------------------------------------- 1 | test_that("Write is successful", { 2 | Test <- function (tree) expect_equal(ape::write.tree(tree), as.Newick(tree)) 3 | Test(BalancedTree(0:7)) 4 | Test(UnrootTree(BalancedTree(0:7))) 5 | Test(PectinateTree(0:7)) 6 | Test(UnrootTree(PectinateTree(0:7))) 7 | Test(ape::read.tree(text="(0,1,2,3,4);")) 8 | Test(ape::read.tree(text="((0,1,2,3,4), ((5, 6), (7, 8, 9)), 10, 11);")) 9 | Test(as.phylo(1:4, 5, 0:4)) 10 | 11 | nasty <- structure(list(edge = structure( 12 | c(9, 12, 10, 13, 11, 10, 11, 13, 10, 13, 12, 9, 13 | 5, 10, 1, 2, 3, 13, 9, 4, 11, 7, 8, 6), 14 | .Dim = c(12, 2)), 15 | Nnode = 5L, 16 | tip.label = 0:7), 17 | class = "phylo") # Danger: Do not plot! 18 | Test(nasty) 19 | }) 20 | 21 | test_that("WriteTntCharacters()", { 22 | nTax <- 4L 23 | dataset <- matrix(seq_len(nTax), nrow = nTax, ncol = 6, 24 | dimnames = list(LETTERS[1:nTax], 1:6)) 25 | dataset[4, 4:6] <- "-" 26 | dataset[3, 3] <- "(23)" 27 | dataset[3:2, 4:6] <- "?" 28 | 29 | expect_equal( 30 | WriteTntCharacters(dataset, comment = c("COM", "MENT"), 31 | pre = c("PRE", "FIX"), 32 | post = c("POST", "SCRIPT")), 33 | "PRE\nFIX\nxread 'COM MENT'\n6 4\nA 1 1 1 1 1 1\nB 2 2 2 ? ? ?\nC 3 3 [23] ? ? ?\nD 4 4 4 - - -\n;\nPOST\nSCRIPT" 34 | ) 35 | expect_equal(WriteTntCharacters(dataset), 36 | WriteTntCharacters(MatrixToPhyDat(dataset))) 37 | 38 | expect_equal( 39 | WriteTntCharacters(dataset, types = c(num = 1, dna = 3)), 40 | "\nxread 'Dataset written by `TreeTools::WriteTntCharacters()`'\n6 4\n&[num]\n A 1 1\nB 2 2\nC 3 3\nD 4 4\n&[dna]\n A 1 1 1 1\nB 2 ? ? ?\nC [23] ? ? ?\nD 4 - - -\n;\n" 41 | ) 42 | 43 | written <- tempfile() 44 | WriteTntCharacters(dataset, written) 45 | on.exit(file.remove(written)) 46 | colnames(dataset) <- NULL 47 | expect_equal(ReadTntCharacters(written), 48 | gsub("(23)", "[23]", fixed = TRUE, dataset)) 49 | }) 50 | -------------------------------------------------------------------------------- /tests/testthat/testdata/nonPreCons.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | [R-package APE, Mon Apr 14 14:21:04 2025] 3 | 4 | BEGIN TAXA; 5 | DIMENSIONS NTAX = 4; 6 | TAXLABELS 7 | Lucernaria 8 | Haliclystus 9 | Calvadosia 10 | Placozoa 11 | ; 12 | END; 13 | BEGIN TREES; 14 | TRANSLATE 15 | 1 Lucernaria, 16 | 2 Haliclystus, 17 | 3 Calvadosia, 18 | 4 Placozoa 19 | ; 20 | TREE * UNTITLED = [&R] (((1,2),3),4); 21 | TREE * UNTITLED = [&R] (((1,2),3),4); 22 | TREE * UNTITLED = [&R] (((4,3),2),1); 23 | TREE * UNTITLED = [&R] (((4,3),2),1); 24 | END; 25 | -------------------------------------------------------------------------------- /vignettes/filesystem-navigation.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "File system navigation in R" 3 | author: "Martin R. Smith " 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | bibliography: ../inst/REFERENCES.bib 7 | csl: ../inst/apa-old-doi-prefix.csl 8 | vignette: > 9 | %\VignetteIndexEntry{File system navigation in R} 10 | %\VignetteEngine{knitr::rmarkdown} 11 | %\VignetteEncoding{UTF-8} 12 | --- 13 | 14 | Before you can open a file, you need to tell R where to find it. 15 | You can do this by providing the full path to the file on your system. 16 | Be careful to use forward slashes (`/`, not `\`, which you'll get if you 17 | copy file paths in Windows). 18 | 19 | ```r 20 | filename <- "C:/nexus/matrix.nex" 21 | ``` 22 | 23 | You can save typing by giving R a working directory. You can 24 | think of R as having a file explorer window open invisibly in the 25 | background. 26 | 27 | You can see the folder that's open at the moment by typing `getwd()` at the console. 28 | 29 | `setwd()` tells R to open a different folder instead. 30 | 31 | `setwd('../')` tells R to go up to a parent directory. 32 | (You can [do this using the Graphical User Interface]( 33 | https://www.princeton.edu/~otorres/RStudio101.pdf) in RStudio). 34 | 35 | By setting the directory that your files are in as the working directory, 36 | you only need to specify the filename: 37 | 38 | ```r 39 | setwd("C:/nexus/") # You only need to do this once 40 | filename <- "matrix.nex" 41 | # Do something with this file 42 | # 43 | 44 | filename <- "tree.nex" 45 | # Do something with this file 46 | # 47 | ``` 48 | 49 | ## What next? 50 | 51 | Now you know how to locate files, you might want to load a 52 | [dataset](load-data.html) or [phylogenetic tree](load-trees.html) into R. 53 | --------------------------------------------------------------------------------