Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Extensions #90

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ on:
jobs:
phylo-tests:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
continue-on-error: false
strategy:
matrix:
julia-version:
- '1.6'
- '1.9'
- '1'
os:
- ubuntu-latest
- macOS-latest
- macos-latest
- windows-latest
R-version:
- 'release'
arch:
- x64
experimental:
- false
r-testing:
- ${{ true }}
- ${{ false }}
exclude:
- os: ubuntu-latest
r-testing: ${{ true }}
- os: windows-latest
r-testing: ${{ true }}
- os: macOS-latest
r-testing: ${{ false }}
fail-fast: false
steps:
- name: Checkout code
Expand All @@ -37,12 +44,10 @@ jobs:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.arch }}
- name: Install R
if: matrix.os == 'macOS-latest'
if: ${{ matrix.r-testing }}
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.R-version }}
- name: Install ape
if: matrix.os == 'macOS-latest'
if: ${{ matrix.r-testing }}
run: |
install.packages("ape", repos="http://cran.r-project.org")
shell: R --vanilla --file={0}
Expand Down
1 change: 0 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ Returns a vector of nodes for a OneTree tree. Either _getnodes() must be
implemented for any OneTree tree type.
"""
function _getnodes end
_getnodes(::T) where T <: AbstractTree = error("No _getnodes() method for tree type $T")
_getnodes(tree::AbstractTree{OneTree}, order::TraversalOrder) =
_traversal(tree, order)

Expand Down
3 changes: 1 addition & 2 deletions src/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ subtrees) will return the number of subtrees. ManyTrees types will return a
Dict of counts of the number of roots for each tree in the set.
"""
function nroots end
nroots(::AbstractTree{OneTree, Unrooted}) = 0
nroots(tree::AbstractTree{OneTree, <: Rooted}) = _nroots(tree)
nroots(tree::AbstractTree{OneTree}) = _nroots(tree)
nroots(trees::AbstractTree{ManyTrees}, name) = nroots(gettree(trees, name))
nroots(trees::AbstractTree{ManyTrees}) =
Dict(name => nroots(gettree(trees, name)) for name in _gettreenames(trees))
Expand Down
15 changes: 4 additions & 11 deletions src/RecursiveTree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ RecursiveNode{RT, NL, NodeData, BranchData, BT, LenUnits}(name::NL, data::NodeDa
data, missing)

"""
struct RecoursiveTree <: AbstractTree
struct RecursiveTree <: AbstractTree

A phylogenetic tree type containing RecursiveElts as both nodes and branches,
allowing navigation of the tree using only the node and branch elements.
allowing navigation of the tree using only the node and branch elements.
"""
mutable struct RecursiveTree{RT, NL, NodeData, BranchData, BT <: BranchingType, LenUnits, TD} <:
AbstractTree{OneTree, RT, NL,
Expand All @@ -67,8 +67,7 @@ mutable struct RecursiveTree{RT, NL, NodeData, BranchData, BT <: BranchingType,
BT, LenUnits, TD}(tipnames::AbstractVector{NL} = NL[];
name::String = TREENAME,
tipdata::TD = _emptydata(TD),
rootheight::Union{LenUnits, Missing} = missing,
validate::Bool = false) where
rootheight::Union{LenUnits, Missing} = missing) where
{RT, NL, NodeData, BranchData, BT, LenUnits, TD}
NT = RecursiveNode{RT, NL, NodeData, BranchData, BT, LenUnits}
BrT = RecursiveBranch{RT, NL, NodeData, BranchData, BT, LenUnits}
Expand All @@ -81,15 +80,9 @@ mutable struct RecursiveTree{RT, NL, NodeData, BranchData, BT <: BranchingType,

if !isempty(tipnames)
createnodes!(tree, tipnames)
elseif !isnothing(tree.tipdata) && !isempty(tree.tipdata)
createnodes!(tree, unique(keys(tree.tipdata)))
end

if validate
validate!(tree)
else
tree.isvalid = missing
end
tree.isvalid = missing

return tree
end
Expand Down
15 changes: 12 additions & 3 deletions test/test_API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ end
struct TestTree <: Phylo.AbstractTree{OneTree, OneRoot, String, TestNode, TestBranch}
end

import Phylo.API: _preferbranchobjects
_preferbranchobjects(::Type{<: TestTree}) = false

@testset "Check errors" begin
tt = TestTree();
tn = TestNode();
tb = TestBranch();

@test_throws ErrorException _getnodes(tt)
@test_throws MethodError _getnodes(tt, preorder)
@test_throws ErrorException _getnodenames(tt)
@test_throws ErrorException _getbranches(tb)
@test_throws ErrorException _getnodes(tt)
@test_throws MethodError _nnodes(tt)
@test_throws ErrorException _getbranches(tt)
@test_throws ErrorException _getbranchnames(tt)
@test_throws ErrorException _nbranches(tt)
@test_throws MethodError _hasnode(tt, tn)
@test_throws ErrorException _hasnode(tt, "test")
@test_throws MethodError _hasbranch(tt, tb)
@test_throws ErrorException _hasbranch(tt, 1)
@test_throws ErrorException _hasinbound(tt, tn)
@test_throws ErrorException _getinbound(tt, tn)
@test_throws ErrorException _getoutbounds(tt, tn)
Expand Down