Skip to content

Commit

Permalink
fix use of isdescendant
Browse files Browse the repository at this point in the history
  • Loading branch information
cecileane committed Oct 11, 2020
1 parent becb19e commit a1a4c2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/moves_semidirected.jl
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,15 @@ function fliphybrid!(net::HybridNetwork, hybridnode::Node, minor=true::Bool,
#! 3. in hybrid ladder case: chooses leaf edges as newhybridedge
# CAS note: I added additional leaf check to prevent this.
@debug "$(e !== edgetoflip), $(PhyloNetworks.isdescendant_undirected(p2, newhybridnode, e)), $(!any(n.leaf for n in e.node))"
if e !== edgetoflip && PhyloNetworks.isdescendant_undirected(p2, newhybridnode, e) && !any(n.leaf for n in e.node)
push!(isdesc, true)
else
push!(isdesc, false)
isp2desc = false
if e !== edgetoflip
neibr = getOtherNode(e, newhybridnode) # neighbor of new hybrid node via e
if !neibr.leaf && (p2 === neibr ||
PhyloNetworks.isdescendant_undirected(p2, neibr, e))
isp2desc = true
end
end
push!(isdesc, isp2desc)
end
@debug "isdesc has $(length(isdesc))"
if sum(isdesc) != 1 # if >1 one edge is an ancestor, flipping would create a cycle
Expand Down
4 changes: 2 additions & 2 deletions test/test_moves_semidirected.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ end # of testset on checknetwork functions for species constraints

end # of constrained NNI moves

@testset "test fliphybrid! inner function" begin
@testset "test fliphybrid!" begin
# simple network
n6h1 = readTopology("((((1:0.2,2:0.2):2.4,((3:0.4,4:0.4):1.1)#H1:1.1):2.0,(#H1:0.0::0.3,5:1.5):3.1):1.0,6:5.6);")
@test n6h1.hybrid[1].number == 5
# @test n6h1.hybrid[1].number == 5
#! currently, rejects an allowable newhybridedge in the following call
@test !isnothing(PhyloNetworks.fliphybrid!(n6h1, n6h1.hybrid[1])) # flips minor by default
@test n6h1.hybrid[1].number == -8
Expand Down

0 comments on commit a1a4c2d

Please sign in to comment.