forked from JuliaPhylo/PhyloNetworks.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_relaxed_reading.jl
56 lines (53 loc) · 2.79 KB
/
test_relaxed_reading.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@testset "test: newick parsing" begin
global net
@testset "readTopology White Symbol Tests" begin
global n1, n2, n3
#Test newlines, spaces, tabs, and carriage returns
n1 = readTopology("(A,((B,#H1),(C,(D)#H1)));")
n2 = readTopology("(A\n,\t (\n\r (B , #H1 ),( C ,(D )#H1 ) \n\n\n\n\n) );")
@test writeTopology(n1) == writeTopology(n2)
#Test spaces in troublesome locations
n3 = readTopology("( A, ( ( B , #H 1 ) ,( C , ( D )#H1 ) ) ) ;")
@test writeTopology(n1) == writeTopology(n3)
#Test spaces in names
resultant = readTopology("('Homo sapiens', ((B,#H1),(C,(D)#H1)));")
expected = readTopology("('Homosapiens',((B,#H1),(C,(D)#H1)));")
@test writeTopology(resultant) == writeTopology(expected)
#Test other white symbols in names
resultant = readTopology("('H\tom\ro\nsa p \n\n\n\n\n\n\n\ni\t\t\t\t\t\t\t\ten s ', ((B,#H1),(C,(D)#H1)));")
expected = readTopology("('Homosapiens',((B,#H1),(C,(D)#H1)));")
@test writeTopology(resultant) == writeTopology(expected)
end
@testset "isMajor and gamma consistency" begin
net = readTopology("((((B)#H1)#H2,((D,C,#H2:::0.8),(#H1,A))));");
@test writeTopology(net, round=true, digits=8) == "(#H2:::0.2,((D,C,((B)#H1)#H2:::0.8),(#H1,A)));"
net = readTopologyLevel1("(E,((B)#H1:::.5,((D,C),(#H1:::.5,A))));");
@test writeTopology(net) == "(D:1.0,C:1.0,((#H1:1.0::0.5,A:1.0):1.0,((B:1.0)#H1:1.0::0.5,E:1.0):1.0):1.0);"
originalstdout = stdout
redirect_stdout(open("/dev/null", "w")) # not portable to Windows
@test_logs PhyloNetworks.printEverything(net)
redirect_stdout(originalstdout)
end
@testset "internal nodes, writemulti" begin
@test writeTopology(readTopology("(a,b):0.5;")) == "(a,b);"
@test writeTopology(readTopology("((a,(b)#H1)i1,(#H1,c))r;")) == "((a,(b)#H1)i1,(#H1,c))r;"
@test writeTopology(readTopology("((a,(b)#H1)i1,(#H1,c))r;"), internallabel=false) == "((a,(b)#H1),(#H1,c));"
n11 = (@test_logs readTopology("((a,(b)#H1)i1,(#H1,c)i2)root:0.5;"));
n12 = (@test_logs readTopology("(((a,(b)#H2)i1,(#H2,c)i2)root:0.5);")); # root edge was deleted
# writeTopology(net) == "((a,(b)#H1)i1,(#H1,c)i2);"
# readTopology("((((a,(b)#H1)i1,(#H1,c)i2)root:0.5));"); still has 1 (of the 2) root edges
# writeMultiTopology([n1,n2], stdout)
n11.root = 2 # below the hybrid node: will trigger RootMismatch and message below
originalstdout = stdout
redirect_stdout(open("/dev/null", "w"))
writeMultiTopology([n11,n12], "test_relaxedreading.net")
rm("test_relaxedreading.net")
redirect_stdout(originalstdout)
end
@testset "write for hybrid-lambda" begin
net = readTopology("((a:1,(bH:1)#H1:1::0.8)H2:5,(#H1:0::0.2,c:1):1);");
@test hybridlambdaformat(net) == "((a:1.0,(bH:1.0)H1#0.8:1.0)H2:5.0,(H1#0.8:0.0,c:1.0)I1:1.0)I2;"
net = readTopology("((#H1:::0.2,c),(I3,(b)#H1:::0.8):5);")
@test hybridlambdaformat(net) == "((H1#0.2,c)I4,(I3,(b)H1#0.2)I5:5.0)I6;"
end
end