Skip to content

Commit

Permalink
hybridlambda format: set gammas to 0.5 if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
cecileane committed Jun 11, 2022
1 parent 0ffba5b commit 1f78b2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/graph_components.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""
biconnectedComponents(network, ignoreTrivial=false)
Calculate biconnected components (aka "blobs") using Tarjan's algorithm:
the output is an array of arrays of edges.
Calculate biconnected components (aka "blobs") using Tarjan's algorithm.
Output: array of arrays of edges.
- the length of the array is the number of blobs
- each element is an array of all the edges inside a given blob.
These blobs are returned in post-order, but within a blob,
edges are *not* necessarily sorted in topological order.
If `ignoreTrivial` is true, trivial components (of a single edge)
Expand Down Expand Up @@ -137,6 +141,9 @@ If `ignoreTrivial` is true, trivial components are ignored.
keyword argument: `checkPreorder`, true by default. If false,
the `isChild1` edge field and the `net.nodes_changed` network field
are supposed to be correct.
**warning**: see [`biconnectedComponents`](@ref) for node
attributes modified during the algorithm.
"""
function blobInfo(net, ignoreTrivial=true::Bool;
checkPreorder=true::Bool)
Expand Down Expand Up @@ -197,7 +204,15 @@ the number of the blob's root is given to the newly created leaf.
The first (bang) version modifies the network and returns
the array of blob roots. The second version copies the network
then returns a tuple: the forest and the blob roots.
then returns a tuple: the forest and the array of blob roots.
Warnings:
- the forest is represented by a single HybridNetwork object,
on which most functions don't work (like `writeTopology`, plotting etc.)
because the network is disconnected (to make the forest).
Revert back to low-level functions, e.g. `printEdges` and `printNodes`.
- see [`biconnectedComponents`](@ref) for node
attributes modified during the algorithm.
"""
function blobDecomposition(net)
net2 = deepcopy(net)
Expand Down
6 changes: 6 additions & 0 deletions src/readwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,12 @@ function hybridlambdaformat(net::HybridNetwork; prefix="I")
leafnames = tipLabels(net)
length(Set(leafnames)) == length(leafnames) || error("taxon names must be unique: $(sort(leafnames))")
net = deepcopy(net) # binding to new object
for e in net.edge
if e.hybrid && e.isMajor && e.gamma == -1.0
@error("edge number $(e.number) is missing gamma: will use 0.5")
setGamma!(e, 0.5)
end
end
for no in net.node
(no.leaf || no.hybrid) && continue # skip leaves & hybrid nodes
no.name = "" # erase any exisiting name: especially bootstrap values
Expand Down
2 changes: 2 additions & 0 deletions test/test_relaxed_reading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ end
@test hybridlambdaformat(net) == "((((B)H1#0.7,D)I1:4.0,(H1#0.7,E)I2:6.2)I3:2.0,O)I4;"
net = readTopology("((((D)#H1:::0.7,D)1:4,(#H1:::0.3,E)1:6.2):2,O);") # 2 tips named D
@test_throws Exception hybridlambdaformat(net)
net = readTopology("((((B)#H1,D)1:4,(#H1,E)1:6.2):2,O);") # missing gamma
@test_logs (:error, r"^edge.*0.5$") (@test hybridlambdaformat(net) == "((((B)H1#0.5,D)I1:4.0,(H1#0.5,E)I2:6.2)I3:2.0,O)I4;")
end
end

0 comments on commit 1f78b2a

Please sign in to comment.