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

feat: handle plus sign in scientific notation floats #223

Merged
merged 4 commits into from
Mar 10, 2025
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
8 changes: 4 additions & 4 deletions docs/src/man/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ gene flow/hybridization or gene tree estimation error,
and can be hard to interpret biologically.

```@raw html
<img src="../assets/implicit.png" width="50%" alt="implicit split network" class="center"/>
<img src="assets/implicit.png" width="50%" alt="implicit split network" class="center"/>
```

In PhyloNetworks, we consider **explicit** phylogenetic networks exclusively.
Expand All @@ -130,14 +130,14 @@ In parenthetical format, internal nodes can have a name, like node `C` below,
in a tree written as `(A,B)C` in newick format:

```@raw html
<img src="../assets/intNode.png" width="45%" alt="internal tree node C" class="center"/>
<img src="assets/intNode.png" width="45%" alt="internal tree node C" class="center"/>
```

To represent networks in parenthetical format, the extended newick format splits
each hybrid node into two nodes with the same name:

```@raw html
<img src="../assets/netNewick.png" width="70%" alt="a hybrid node is split into 2 nodes with the same name, to represent a network as a tree" class="center"/>
<img src="assets/netNewick.png" width="70%" alt="a hybrid node is split into 2 nodes with the same name, to represent a network as a tree" class="center"/>
```

By convention, the hybrid tag is `# + H,LGT,R + number`, and the minor
Expand Down Expand Up @@ -174,4 +174,4 @@ the edge was a tree edge:
setgamma!(net.edge[4], 0.7)
# should return this:
# ERROR: cannot change gamma in a tree edge
```
```
4 changes: 2 additions & 2 deletions src/readwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ end

# aux function to read floats like length or gamma values, to be read after a colon
function readnewick_float(s::IO, c::Char)
if !(isdigit(c) || c in ['.','e','-','E'])
if !(isdigit(c) || c in ['.','e','-','E', '+'])
a = read(s, String);
error("Expected float digit after ':' but found $(c). remaining is $(a).");
end
num = ""
while isdigit(c) || c in ['.','e','-', 'E']
while isdigit(c) || c in ['.','e','-', 'E', '+']
d = read(s, Char) # reads c and advances IO
num = string(num,d);
c = peekskip(s);
Expand Down
5 changes: 5 additions & 0 deletions test/test_relaxed_reading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ global net
@test_throws Exception readnewick("(E,((B)#H1") # doesn't end with ;
@test_throws Exception readnewick(IOBuffer("E;")) # Expected beginning of tree with (
end
@testset "edge parameters" begin
net = readnewick("(A:2e-03,((B:1.2e1,#H1:1e+1):2.2E-02,(D:1.1E+2)#H1:4.4E+2::5.5E-10));")
@test [e.length for e in net.edge] == [0.002,12,10,0.022,110,440,-1]
@test [e.gamma for e in net.edge if e.hybrid] == [0.99999999945, 5.5e-10]
end
@testset "ismajor & gamma consistency, and miscellaneous" begin
net = readnewick("((((B)#H1)#H2,((D,C,#H2:::0.8),(#H1,A))));");
@test writenewick(net, round=true, digits=8) == "(#H2:::0.2,((D,C,((B)#H1)#H2:::0.8),(#H1,A)));"
Expand Down
Loading