Skip to content

Commit 336a82c

Browse files
cvigilvcecileane
andauthored
feature: handle '+' in scientific notation floats (#223)
to parse newick --------- Co-authored-by: Cecile Ane <[email protected]>
1 parent fc933b9 commit 336a82c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

docs/src/man/introduction.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ gene flow/hybridization or gene tree estimation error,
119119
and can be hard to interpret biologically.
120120

121121
```@raw html
122-
<img src="../assets/implicit.png" width="50%" alt="implicit split network" class="center"/>
122+
<img src="assets/implicit.png" width="50%" alt="implicit split network" class="center"/>
123123
```
124124

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

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

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

139139
```@raw html
140-
<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"/>
140+
<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"/>
141141
```
142142

143143
By convention, the hybrid tag is `# + H,LGT,R + number`, and the minor
@@ -174,4 +174,4 @@ the edge was a tree edge:
174174
setgamma!(net.edge[4], 0.7)
175175
# should return this:
176176
# ERROR: cannot change gamma in a tree edge
177-
```
177+
```

src/readwrite.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ end
113113

114114
# aux function to read floats like length or gamma values, to be read after a colon
115115
function readnewick_float(s::IO, c::Char)
116-
if !(isdigit(c) || c in ['.','e','-','E'])
116+
if !(isdigit(c) || c in ['.','e','-','E', '+'])
117117
a = read(s, String);
118118
error("Expected float digit after ':' but found $(c). remaining is $(a).");
119119
end
120120
num = ""
121-
while isdigit(c) || c in ['.','e','-', 'E']
121+
while isdigit(c) || c in ['.','e','-', 'E', '+']
122122
d = read(s, Char) # reads c and advances IO
123123
num = string(num,d);
124124
c = peekskip(s);

test/test_relaxed_reading.jl

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ global net
3535
@test_throws Exception readnewick("(E,((B)#H1") # doesn't end with ;
3636
@test_throws Exception readnewick(IOBuffer("E;")) # Expected beginning of tree with (
3737
end
38+
@testset "edge parameters" begin
39+
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));")
40+
@test [e.length for e in net.edge] == [0.002,12,10,0.022,110,440,-1]
41+
@test [e.gamma for e in net.edge if e.hybrid] == [0.99999999945, 5.5e-10]
42+
end
3843
@testset "ismajor & gamma consistency, and miscellaneous" begin
3944
net = readnewick("((((B)#H1)#H2,((D,C,#H2:::0.8),(#H1,A))));");
4045
@test writenewick(net, round=true, digits=8) == "(#H2:::0.2,((D,C,((B)#H1)#H2:::0.8),(#H1,A)));"

0 commit comments

Comments
 (0)