Skip to content

Commit

Permalink
bump compat for PhyloNetworks to 0.16, drop earlier versions (#25)
Browse files Browse the repository at this point in the history
fixes #24
cecileane authored Apr 4, 2023
1 parent b2f7137 commit aaf3069
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ CSV = "0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10"
DataFrames = "0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 1.0"
NLopt = "0.5.1, 0.6"
PhyloCoalSimulations = "0.1,1"
PhyloNetworks = "0.15.2"
PhyloNetworks = "0.16.0"
SpecialFunctions = "0.8, 0.9, 0.10, 1.0, 2"
StaticArrays = "0.9, 0.10, 0.11, 0.12, 1.0"
StatsFuns = "0.7, 0.8, 0.9, 1"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@

## overview

`QuartetNetworkGoodnessFit` is a Julia package, providing tools to measure the
`QuartetNetworkGoodnessFit` is a Julia package for phylogenetic networks analyses using four-taxon subsets.
It includes tools to measure the
goodness of fit of a phylogenetic network to data on subsets of 4 tips.
It depends on the [PhyloNetworks](https://github.com/crsl4/PhyloNetworks.jl)
package.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterMarkdown = "997ab1e6-3595-5248-9280-8efb232c3433"
PhyloCoalSimulations = "53f7b83a-06b5-4910-9a21-1896bf762ade"
PhyloNetworks = "33ad39ac-ed31-50eb-9b15-43d0656eaa72"
QuartetNetworkGoodnessFit = "1382f7fc-2744-4d9d-8ec6-1e3efdec0746"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ using QuartetNetworkGoodnessFit
DocMeta.setdocmeta!(QuartetNetworkGoodnessFit, :DocTestSetup, :(using QuartetNetworkGoodnessFit); recursive=true)

makedocs(
sitename = "QuartetNetwork GoF.jl",
sitename = "QGoF",
authors = "Cécile Ané and Ruoyi Cai",
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"), # easier local build
modules = [QuartetNetworkGoodnessFit],
9 changes: 5 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# QuartetNetworkGoodnessFit.jl
# Quarnet GoF --or simply QGoF


Julia
QuartetNetworkGoodnessFit.jl is a Julia
[package](https://github.com/cecileane/QuartetNetworkGoodnessFit.jl)
for phylogenetic networks analyses using four-taxon subsets.
It includes tools
to measure the goodness of fit
of a phylogenetic network to data on subsets of 4 tips.
of a candidate network to data on subsets of 4 tips.
It depends on the [PhyloNetworks](https://github.com/crsl4/PhyloNetworks.jl)
package.

20 changes: 10 additions & 10 deletions src/quarnetconcordancefactors.jl
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ function network_expectedCF_4taxa!(net::HybridNetwork, fourtaxa, inheritancecorr
function isexternal(ib) # is bcc[ib] of degree 2 and adjacent to an external edge?
# yes if: 1 single exit adjacent to a leaf
length(exitnodes[ib]) != 1 && return false
ch = PhyloNetworks.getChildren(exitnodes[ib][1])
ch = getchildren(exitnodes[ib][1])
return length(ch) == 1 && ch[1].leaf
end
for ib in reverse(bloborder)
@@ -203,19 +203,19 @@ function network_expectedCF_4taxa!(net::HybridNetwork, fourtaxa, inheritancecorr
preorder!(net)
# find a lowest hybrid node and # of taxa below it
hyb = net.nodes_changed[findlast(n -> n.hybrid, net.nodes_changed)]
funneledge = [e for e in hyb.edge if PhyloNetworks.getParent(e) === hyb]
funneledge = [e for e in hyb.edge if getparent(e) === hyb]
ispolytomy = length(funneledge) > 1
funneldescendants = union([PhyloNetworks.descendants(e) for e in funneledge]...)
ndes = length(funneldescendants)
n2 = (ispolytomy ? hyb : PhyloNetworks.getChild(funneledge[1]))
n2 = (ispolytomy ? hyb : getchild(funneledge[1]))
ndes > 2 && n2.leaf && error("2+ descendants below the lowest hybrid, yet n2 is a leaf. taxa: $(fourtaxa)")
end
if ndes > 2 # simple formula for qCF: find cut edge and its length
# inheritance correlation has no impact
# pool of cut edges below. contains NO external edge, bc n2 not leaf (if reticulation), nice tree ow
cutpool = (net.numHybrids == 0 ? net.edge :
[e for e in n2.edge if PhyloNetworks.getParent(e) === n2])
filter!(e -> !PhyloNetworks.getChild(e).leaf, cutpool)
[e for e in n2.edge if getparent(e) === n2])
filter!(e -> !getchild(e).leaf, cutpool)
net.numHybrids > 0 || length(cutpool) <= 1 ||
error("2+ cut edges, yet 4-taxon tree, degree-3 root and no degree-2 nodes. taxa: $(fourtaxa)")
sistertofirst = 2 # arbitrarily correct if 3-way polytomy (no cut edge)
@@ -235,7 +235,7 @@ function network_expectedCF_4taxa!(net::HybridNetwork, fourtaxa, inheritancecorr
ndes > 0 || error("weird: hybrid node has no descendant taxa")
# by now, there are 1 or 2 taxa below the lowest hybrid
qCF = MVector{3,Float64}(0.0,0.0,0.0) # mutated later
parenthedge = [e for e in hyb.edge if PhyloNetworks.getChild(e) === hyb]
parenthedge = [e for e in hyb.edge if getchild(e) === hyb]
all(h.hybrid for h in parenthedge) || error("hybrid $(hyb.number) has a parent edge that's a tree edge")
parenthnumber = [p.number for p in parenthedge]
nhe = length(parenthedge)
@@ -269,10 +269,10 @@ function network_expectedCF_4taxa!(net::HybridNetwork, fourtaxa, inheritancecorr
# no coalescence on cut-edge: delete it and extract parental networks
ispolytomy || PhyloNetworks.shrinkedge!(net, funneledge[1])
# shrinkedge! requires PhyloNetworks v0.15.2
childedge = [e for e in hyb.edge if PhyloNetworks.getParent(e) === hyb]
childedge = [e for e in hyb.edge if getparent(e) === hyb]
length(childedge) == 2 ||
error("2-taxon subtree, but not 2 child edges after shrinking the cut edge.")
all(PhyloNetworks.getChild(e).leaf for e in childedge) ||
all(getchild(e).leaf for e in childedge) ||
error("2-taxon subtree, cut-edge shrunk, but the 2 edges aren't both external")
childnumber = [e.number for e in childedge]
for i in 1:nhe
@@ -291,8 +291,8 @@ function network_expectedCF_4taxa!(net::HybridNetwork, fourtaxa, inheritancecorr
# detach childedge[2] from hyb and attach it to hyb's parent j
pej_index = findfirst(e -> e.number == parenthnumber[j], simplernet.edge)
pej = simplernet.edge[pej_index]
pn = PhyloNetworks.getParent(pej)
hn = PhyloNetworks.getChild(pej) # hyb node, but in simplernet
pn = getparent(pej)
hn = getchild(pej) # hyb node, but in simplernet
ce2_index = findfirst(e -> e.number == childnumber[2], simplernet.edge)
ce2 = simplernet.edge[ce2_index]
PhyloNetworks.removeEdge!(hn,ce2)
10 changes: 5 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@ function ultrametrize!(net::HybridNetwork, verbose::Bool)
dr[1] = 0.0 # root
for i in 2:length(net.nodes_changed) # pre-order
@inbounds n = net.nodes_changed[i]
e = PhyloNetworks.getMajorParentEdge(n)
p = PhyloNetworks.getParent(e)
e = getparentedge(n)
p = getparent(e)
pi = findfirst(x -> x===p, net.nodes_changed)
drmaj = dr[pi] # distance to root of major parent
if !n.hybrid # n is a tree node. only 1 parent edge: e
@@ -47,8 +47,8 @@ function ultrametrize!(net::HybridNetwork, verbose::Bool)
continue
end
# now: n is a hybrid node, with parent edges e and emin
emin = PhyloNetworks.getMinorParentEdge(n)
pmin = PhyloNetworks.getParent(emin)
emin = getparentedgeminor(n)
pmin = getparent(emin)
pmini = findfirst(x -> x===pmin, net.nodes_changed)
drmin = dr[pmini] # distance to root of minor parent
majmissing = e.length == -1.0
@@ -101,7 +101,7 @@ function ultrametrize!(net::HybridNetwork, verbose::Bool)
for i in 2:length(net.nodes_changed)
@inbounds n = net.nodes_changed[i]
n.leaf || continue
e = PhyloNetworks.getMajorParentEdge(n)
e = getparentedge(n)
if e.length == -1.0
e.length = height - dr[i]
elseif !isapprox(dr[i], height)

0 comments on commit aaf3069

Please sign in to comment.