Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Apr 14, 2022
2 parents 240bf58 + 22b095d commit 4c19ab4
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 100 deletions.
2 changes: 1 addition & 1 deletion cmd/compareedges.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If the compared tree file contains several trees, it will take the first one onl

edges1 := refTree.Edges()

fmt.Printf("tree\tbrid\tlength\tsupport\tterminal\tdepth\ttopodepth\trightname\tfound")
fmt.Printf("tree\tbrid\tlength\tsupport\tterminal\tdepth\ttopodepth\trootdepth\trightname\tfound")
fmt.Printf("\ttransfer\ttaxatomove\tcomparednodename\tcomparedlength\tcomparedsupport\tcomparedtopodepth\tcomparedid")

fmt.Printf("\n")
Expand Down
2 changes: 1 addition & 1 deletion cmd/edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ gotree stats edges -i t.nw
}
defer closeWriteFile(f, outtreefile)

f.WriteString("tree\tbrid\tlength\tsupport\tterminal\tdepth\ttopodepth\trightname\tcomments\tleftname\trightcomment\tleftcomment")
f.WriteString("tree\tbrid\tlength\tsupport\tterminal\tdepth\ttopodepth\trootdepth\trightname\tcomments\tleftname\trightcomment\tleftcomment")
f.WriteString("\n")
if treefile, treechan, err = readTrees(intreefile); err != nil {
io.LogError(err)
Expand Down
68 changes: 49 additions & 19 deletions docs/commands/stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,55 @@ Should give

and

|tree | brid | length | support | terminal | depth | topodepth | rightname |
|------|--------|------------------------|-----------|------------|---------|-------------|-------------|
|0 | 0 | 0.0912341925030609 | N/A | false | 1 | 3 | |
|0 | 1 | 0.020616211789029896 | N/A | true | 0 | 1 | Tip4 |
|0 | 2 | 0.12939642466438622 | N/A | false | 1 | 2 | |
|0 | 3 | 0.09740195047110385 | N/A | true | 0 | 1 | Tip7 |
|0 | 4 | 0.015450672710905129 | N/A | true | 0 | 1 | Tip2 |
|0 | 5 | 0.12959932895259058 | N/A | true | 0 | 1 | Tip0 |
|0 | 6 | 0.022969404523534506 | N/A | false | 1 | 4 | |
|0 | 7 | 0.09604804621401375 | N/A | false | 1 | 3 | |
|0 | 8 | 0.027845992087631298 | N/A | true | 0 | 1 | Tip8 |
|0 | 9 | 0.005132906169455565 | N/A | false | 1 | 2 | |
|0 | 10 | 0.13492605122032592 | N/A | true | 0 | 1 | Tip9 |
|0 | 11 | 0.10309294031874587 | N/A | true | 0 | 1 | Tip3 |
|0 | 12 | 0.15075207292513051 | N/A | false | 1 | 3 | |
|0 | 13 | 0.029087690784364996 | N/A | false | 1 | 2 | |
|0 | 14 | 0.3779897840448691 | N/A | true | 0 | 1 | Tip6 |
|0 | 15 | 0.1120177846434196 | N/A | true | 0 | 1 | Tip5 |
|0 | 16 | 0.239082088939295 | N/A | true | 0 | 1 | Tip1 |
|tree | brid | length | support | terminal | depth | topodepth | rootdepth | rightname |
|------|--------|------------------------|-----------|------------|---------|-------------|-------------|-------------|
|0 | 0 | 0.0912341925030609 | N/A | false | 1 | 3 | -1 | |
|0 | 1 | 0.020616211789029896 | N/A | true | 0 | 1 | -1 | Tip4 |
|0 | 2 | 0.12939642466438622 | N/A | false | 1 | 2 | -1 | |
|0 | 3 | 0.09740195047110385 | N/A | true | 0 | 1 | -1 | Tip7 |
|0 | 4 | 0.015450672710905129 | N/A | true | 0 | 1 | -1 | Tip2 |
|0 | 5 | 0.12959932895259058 | N/A | true | 0 | 1 | -1 | Tip0 |
|0 | 6 | 0.022969404523534506 | N/A | false | 1 | 4 | -1 | |
|0 | 7 | 0.09604804621401375 | N/A | false | 1 | 3 | -1 | |
|0 | 8 | 0.027845992087631298 | N/A | true | 0 | 1 | -1 | Tip8 |
|0 | 9 | 0.005132906169455565 | N/A | false | 1 | 2 | -1 | |
|0 | 10 | 0.13492605122032592 | N/A | true | 0 | 1 | -1 | Tip9 |
|0 | 11 | 0.10309294031874587 | N/A | true | 0 | 1 | -1 | Tip3 |
|0 | 12 | 0.15075207292513051 | N/A | false | 1 | 3 | -1 | |
|0 | 13 | 0.029087690784364996 | N/A | false | 1 | 2 | -1 | |
|0 | 14 | 0.3779897840448691 | N/A | true | 0 | 1 | -1 | Tip6 |
|0 | 15 | 0.1120177846434196 | N/A | true | 0 | 1 | -1 | Tip5 |
|0 | 16 | 0.239082088939295 | N/A | true | 0 | 1 | -1 | Tip1 |

As the tree is unrooted, `rootdepth` is set to -1. However, with a rooted tree:

```
gotree generate yuletree -r --seed 10 | gotree stats edges
```

|tree | brid | length | support | terminal | depth | topodepth | rootdepth | rightname | comments | leftname | rightcomment | leftcomment |
|-----|------|-----------------------|---------|----------|-------|-----------|-----------|-----------|----------|----------|--------------|-------------|
|0 | 0 | 0.054743875470795914 | N/A | false | 2 | 2 | 1 | | [] | | [] | [] |
|0 | 1 | 0.13492605122032592 | N/A | false | 1 | 2 | 2 | | [] | | [] | [] |
|0 | 2 | 0.10309294031874587 | N/A | true | 0 | 1 | 3 | Tip9 | [] | | [] | [] |
|0 | 3 | 0.03707446096764306 | N/A | true | 0 | 1 | 3 | Tip2 | [] | | [] | [] |
|0 | 4 | 0.13604994737755394 | N/A | false | 1 | 4 | 2 | | [] | | [] | [] |
|0 | 5 | 0.19852695409349608 | N/A | true | 0 | 1 | 3 | Tip3 | [] | | [] | [] |
|0 | 6 | 0.020616211789029896 | N/A | false | 1 | 5 | 3 | | [] | | [] | [] |
|0 | 7 | 0.08184535681853511 | N/A | false | 1 | 4 | 4 | | [] | | [] | [] |
|0 | 8 | 0.3779897840448691 | N/A | false | 1 | 3 | 5 | | [] | | [] | [] |
|0 | 9 | 0.027845992087631298 | N/A | false | 1 | 2 | 6 | | [] | | [] | [] |
|0 | 10 | 0.0440885662122905 | N/A | true | 0 | 1 | 7 | Tip8 | [] | | [] | [] |
|0 | 11 | 0.14809735366802398 | N/A | true | 0 | 1 | 7 | Tip6 | [] | | [] | [] |
|0 | 12 | 0.18347097513974125 | N/A | true | 0 | 1 | 6 | Tip5 | [] | | [] | [] |
|0 | 13 | 0.03199874235185574 | N/A | true | 0 | 1 | 5 | Tip4 | [] | | [] | [] |
|0 | 14 | 0.10033210749794116 | N/A | true | 0 | 1 | 4 | Tip1 | [] | | [] | [] |
|0 | 15 | 0.09740195047110385 | N/A | false | 1 | 2 | 1 | | [] | | [] | [] |
|0 | 16 | 0.015450672710905129 | N/A | true | 0 | 1 | 2 | Tip7 | [] | | [] | [] |
|0 | 17 | 0.17182241382980687 | N/A | true | 0 | 1 | 2 | Tip0 | [] | | [] | [] |


Here `rootdepth` gives the number of branches from the current branch (included) to the root.

* Check wether a set of tips form a monophyletic clade

Expand Down
123 changes: 69 additions & 54 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,24 @@ rm -f expected result
# gotree compare edges
echo "->gotree compare edges"
cat > expected <<EOF
tree brid length support terminal depth topodepth rightname found transfer taxatomove comparednodename comparedlength comparedsupport comparedtopodepth comparedid
0 0 0.1824683850061218 N/A false 1 3 false 2 +Tip4,+Tip2 Tip7 0.2281203179753742 N/A 1 14
0 1 0.020616211789029896 N/A true 0 1 Tip4 true 0 Tip4 0.32980883896257585 N/A 1 2
0 2 0.25879284932877245 N/A false 1 2 false 1 +Tip2 Tip7 0.2281203179753742 N/A 1 14
0 3 0.09740195047110385 N/A true 0 1 Tip7 true 0 Tip7 0.2281203179753742 N/A 1 14
0 4 0.015450672710905129 N/A true 0 1 Tip2 true 0 Tip2 0.037584651176611125 N/A 1 11
0 5 0.25919865790518115 N/A true 0 1 Tip0 true 0 Tip0 0.11291296397843323 N/A 1 3
0 6 0.04593880904706901 N/A false 1 4 false 3 +Tip2,+Tip7,-Tip6 0.05806229063227526 N/A 3 4
0 7 0.1920960924280275 N/A false 1 3 false 1 +Tip3 0.005131510752894519 N/A 2 8
0 8 0.027845992087631298 N/A true 0 1 Tip8 true 0 Tip8 0.060367242116658816 N/A 1 10
0 9 0.01026581233891113 N/A false 1 2 false 1 +Tip3 Tip9 0.16045157517594316 N/A 1 9
0 10 0.13492605122032592 N/A true 0 1 Tip9 true 0 Tip9 0.16045157517594316 N/A 1 9
0 11 0.10309294031874587 N/A true 0 1 Tip3 true 0 Tip3 0.35163191615522493 N/A 1 5
0 12 0.30150414585026103 N/A false 1 3 false 2 +Tip6,-Tip7 0.12937482578337411 N/A 3 12
0 13 0.05817538156872999 N/A false 1 2 false 1 +Tip6 Tip5 0.054439044275040135 N/A 1 15
0 14 0.3779897840448691 N/A true 0 1 Tip6 true 0 Tip6 0.05325654013915672 N/A 1 1
0 15 0.1120177846434196 N/A true 0 1 Tip5 true 0 Tip5 0.054439044275040135 N/A 1 15
0 16 0.239082088939295 N/A true 0 1 Tip1 true 0 Tip1 0.013105562909283169 N/A 1 16
tree brid length support terminal depth topodepth rootdepth rightname found transfer taxatomove comparednodename comparedlength comparedsupport comparedtopodepth comparedid
0 0 0.1824683850061218 N/A false 1 3 -1 false 2 +Tip4,+Tip2 Tip7 0.2281203179753742 N/A 1 14
0 1 0.020616211789029896 N/A true 0 1 -1 Tip4 true 0 Tip4 0.32980883896257585 N/A 1 2
0 2 0.25879284932877245 N/A false 1 2 -1 false 1 +Tip2 Tip7 0.2281203179753742 N/A 1 14
0 3 0.09740195047110385 N/A true 0 1 -1 Tip7 true 0 Tip7 0.2281203179753742 N/A 1 14
0 4 0.015450672710905129 N/A true 0 1 -1 Tip2 true 0 Tip2 0.037584651176611125 N/A 1 11
0 5 0.25919865790518115 N/A true 0 1 -1 Tip0 true 0 Tip0 0.11291296397843323 N/A 1 3
0 6 0.04593880904706901 N/A false 1 4 -1 false 3 +Tip2,+Tip7,-Tip6 0.05806229063227526 N/A 3 4
0 7 0.1920960924280275 N/A false 1 3 -1 false 1 +Tip3 0.005131510752894519 N/A 2 8
0 8 0.027845992087631298 N/A true 0 1 -1 Tip8 true 0 Tip8 0.060367242116658816 N/A 1 10
0 9 0.01026581233891113 N/A false 1 2 -1 false 1 +Tip3 Tip9 0.16045157517594316 N/A 1 9
0 10 0.13492605122032592 N/A true 0 1 -1 Tip9 true 0 Tip9 0.16045157517594316 N/A 1 9
0 11 0.10309294031874587 N/A true 0 1 -1 Tip3 true 0 Tip3 0.35163191615522493 N/A 1 5
0 12 0.30150414585026103 N/A false 1 3 -1 false 2 +Tip6,-Tip7 0.12937482578337411 N/A 3 12
0 13 0.05817538156872999 N/A false 1 2 -1 false 1 +Tip6 Tip5 0.054439044275040135 N/A 1 15
0 14 0.3779897840448691 N/A true 0 1 -1 Tip6 true 0 Tip6 0.05325654013915672 N/A 1 1
0 15 0.1120177846434196 N/A true 0 1 -1 Tip5 true 0 Tip5 0.054439044275040135 N/A 1 15
0 16 0.239082088939295 N/A true 0 1 -1 Tip1 true 0 Tip1 0.013105562909283169 N/A 1 16
EOF
${GOTREE} compare edges -i <(${GOTREE} generate yuletree --seed 10) -c <(${GOTREE} generate yuletree --seed 12 -n 1) -m --moved-taxa > result 2>/dev/null
diff -q -b expected result
Expand All @@ -343,24 +343,24 @@ rm -f expected result
# gotree compare edges
echo "->gotree compare edges /2 (same tree)"
cat > expected <<EOF
tree brid length support terminal depth topodepth rightname found transfer taxatomove comparednodename comparedlength comparedsupport comparedtopodepth comparedid
0 0 0.1824683850061218 N/A false 1 3 true 0 0.1824683850061218 N/A 3 0
0 1 0.020616211789029896 N/A true 0 1 Tip4 true 0 Tip4 0.020616211789029896 N/A 1 1
0 2 0.25879284932877245 N/A false 1 2 true 0 0.25879284932877245 N/A 2 2
0 3 0.09740195047110385 N/A true 0 1 Tip7 true 0 Tip7 0.09740195047110385 N/A 1 3
0 4 0.015450672710905129 N/A true 0 1 Tip2 true 0 Tip2 0.015450672710905129 N/A 1 4
0 5 0.25919865790518115 N/A true 0 1 Tip0 true 0 Tip0 0.25919865790518115 N/A 1 5
0 6 0.04593880904706901 N/A false 1 4 true 0 0.04593880904706901 N/A 4 6
0 7 0.1920960924280275 N/A false 1 3 true 0 0.1920960924280275 N/A 3 7
0 8 0.027845992087631298 N/A true 0 1 Tip8 true 0 Tip8 0.027845992087631298 N/A 1 8
0 9 0.01026581233891113 N/A false 1 2 true 0 0.01026581233891113 N/A 2 9
0 10 0.13492605122032592 N/A true 0 1 Tip9 true 0 Tip9 0.13492605122032592 N/A 1 10
0 11 0.10309294031874587 N/A true 0 1 Tip3 true 0 Tip3 0.10309294031874587 N/A 1 11
0 12 0.30150414585026103 N/A false 1 3 true 0 0.30150414585026103 N/A 3 12
0 13 0.05817538156872999 N/A false 1 2 true 0 0.05817538156872999 N/A 2 13
0 14 0.3779897840448691 N/A true 0 1 Tip6 true 0 Tip6 0.3779897840448691 N/A 1 14
0 15 0.1120177846434196 N/A true 0 1 Tip5 true 0 Tip5 0.1120177846434196 N/A 1 15
0 16 0.239082088939295 N/A true 0 1 Tip1 true 0 Tip1 0.239082088939295 N/A 1 16
tree brid length support terminal depth topodepth rootdepth rightname found transfer taxatomove comparednodename comparedlength comparedsupport comparedtopodepth comparedid
0 0 0.1824683850061218 N/A false 1 3 -1 true 0 0.1824683850061218 N/A 3 0
0 1 0.020616211789029896 N/A true 0 1 -1 Tip4 true 0 Tip4 0.020616211789029896 N/A 1 1
0 2 0.25879284932877245 N/A false 1 2 -1 true 0 0.25879284932877245 N/A 2 2
0 3 0.09740195047110385 N/A true 0 1 -1 Tip7 true 0 Tip7 0.09740195047110385 N/A 1 3
0 4 0.015450672710905129 N/A true 0 1 -1 Tip2 true 0 Tip2 0.015450672710905129 N/A 1 4
0 5 0.25919865790518115 N/A true 0 1 -1 Tip0 true 0 Tip0 0.25919865790518115 N/A 1 5
0 6 0.04593880904706901 N/A false 1 4 -1 true 0 0.04593880904706901 N/A 4 6
0 7 0.1920960924280275 N/A false 1 3 -1 true 0 0.1920960924280275 N/A 3 7
0 8 0.027845992087631298 N/A true 0 1 -1 Tip8 true 0 Tip8 0.027845992087631298 N/A 1 8
0 9 0.01026581233891113 N/A false 1 2 -1 true 0 0.01026581233891113 N/A 2 9
0 10 0.13492605122032592 N/A true 0 1 -1 Tip9 true 0 Tip9 0.13492605122032592 N/A 1 10
0 11 0.10309294031874587 N/A true 0 1 -1 Tip3 true 0 Tip3 0.10309294031874587 N/A 1 11
0 12 0.30150414585026103 N/A false 1 3 -1 true 0 0.30150414585026103 N/A 3 12
0 13 0.05817538156872999 N/A false 1 2 -1 true 0 0.05817538156872999 N/A 2 13
0 14 0.3779897840448691 N/A true 0 1 -1 Tip6 true 0 Tip6 0.3779897840448691 N/A 1 14
0 15 0.1120177846434196 N/A true 0 1 -1 Tip5 true 0 Tip5 0.1120177846434196 N/A 1 15
0 16 0.239082088939295 N/A true 0 1 -1 Tip1 true 0 Tip1 0.239082088939295 N/A 1 16
EOF
${GOTREE} compare edges -i <(${GOTREE} generate yuletree --seed 10) -c <(${GOTREE} generate yuletree --seed 10 -n 1) -m --moved-taxa > result 2>/dev/null
diff -q -b expected result
Expand Down Expand Up @@ -835,29 +835,44 @@ rm -f expected expected2 result

echo "->gotree stats edges"
cat > expected <<EOF
tree brid length support terminal depth topodepth rightname comments leftname rightcomment leftcomment
0 0 0.1824683850061218 N/A false 1 3 [] [] []
0 1 0.020616211789029896 N/A true 0 1 Tip4 [] [] []
0 2 0.25879284932877245 N/A false 1 2 [] [] []
0 3 0.09740195047110385 N/A true 0 1 Tip7 [] [] []
0 4 0.015450672710905129 N/A true 0 1 Tip2 [] [] []
0 5 0.25919865790518115 N/A true 0 1 Tip0 [] [] []
0 6 0.04593880904706901 N/A false 1 4 [] [] []
0 7 0.1920960924280275 N/A false 1 3 [] [] []
0 8 0.027845992087631298 N/A true 0 1 Tip8 [] [] []
0 9 0.01026581233891113 N/A false 1 2 [] [] []
0 10 0.13492605122032592 N/A true 0 1 Tip9 [] [] []
0 11 0.10309294031874587 N/A true 0 1 Tip3 [] [] []
0 12 0.30150414585026103 N/A false 1 3 [] [] []
0 13 0.05817538156872999 N/A false 1 2 [] [] []
0 14 0.3779897840448691 N/A true 0 1 Tip6 [] [] []
0 15 0.1120177846434196 N/A true 0 1 Tip5 [] [] []
0 16 0.239082088939295 N/A true 0 1 Tip1 [] [] []
tree brid length support terminal depth topodepth rootdepth rightname comments leftname rightcomment leftcomment
0 0 0.1824683850061218 N/A false 1 3 -1 [] [] []
0 1 0.020616211789029896 N/A true 0 1 -1 Tip4 [] [] []
0 2 0.25879284932877245 N/A false 1 2 -1 [] [] []
0 3 0.09740195047110385 N/A true 0 1 -1 Tip7 [] [] []
0 4 0.015450672710905129 N/A true 0 1 -1 Tip2 [] [] []
0 5 0.25919865790518115 N/A true 0 1 -1 Tip0 [] [] []
0 6 0.04593880904706901 N/A false 1 4 -1 [] [] []
0 7 0.1920960924280275 N/A false 1 3 -1 [] [] []
0 8 0.027845992087631298 N/A true 0 1 -1 Tip8 [] [] []
0 9 0.01026581233891113 N/A false 1 2 -1 [] [] []
0 10 0.13492605122032592 N/A true 0 1 -1 Tip9 [] [] []
0 11 0.10309294031874587 N/A true 0 1 -1 Tip3 [] [] []
0 12 0.30150414585026103 N/A false 1 3 -1 [] [] []
0 13 0.05817538156872999 N/A false 1 2 -1 [] [] []
0 14 0.3779897840448691 N/A true 0 1 -1 Tip6 [] [] []
0 15 0.1120177846434196 N/A true 0 1 -1 Tip5 [] [] []
0 16 0.239082088939295 N/A true 0 1 -1 Tip1 [] [] []
EOF
${GOTREE} generate yuletree --seed 10 | ${GOTREE} stats edges > result
diff -q -b expected result
rm -f expected result

echo "->gotree stats edges /2 rooted"
cat > expected <<EOF
tree brid length support terminal depth topodepth rootdepth rightname comments leftname rightcomment leftcomment
0 0 N/A N/A false 1 2 1 [] [] []
0 1 N/A N/A true 0 1 2 1 [] [] []
0 2 N/A N/A true 0 1 2 2 [] [] []
0 3 N/A N/A false 1 2 1 [] [] []
0 4 N/A N/A true 0 1 2 3 [] [] []
0 5 N/A N/A false 1 2 2 [] [] []
0 6 N/A N/A true 0 1 3 4 [] [] []
0 7 N/A N/A true 0 1 3 5 [] [] []
EOF
echo "((1,2),(3,(4,5)));" | ${GOTREE} stats edges > result
diff -q -b expected result
rm -f expected result

echo "->gotree stats nodes"
cat > expected <<EOF
Expand Down
16 changes: 9 additions & 7 deletions tree/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,19 @@ Tab delimited:
3 - istip?
4 - depth
5 - topo depth
6 - root depth
6 - name of right node if any
7 - comments associated to the edge
8 - name of left node if any
9 - comment of right node if any
10 - comment of left node if any
7 - comments associated to the edge
8 - name of left node if any
9 - comment of right node if any
10 - comment of left node if any
*/
func (e *Edge) ToStatsString(withedgecomments bool) string {
var err error
length := e.LengthString()
support := e.SupportString()

var depth, leftdepth, rightdepth int
var depth, leftdepth, rightdepth, rootdepth int

if leftdepth, err = e.Left().Depth(); err != nil {
io.ExitWithMessage(err)
Expand All @@ -221,6 +222,7 @@ func (e *Edge) ToStatsString(withedgecomments bool) string {
io.ExitWithMessage(err)
}
depth = mutils.Min(leftdepth, rightdepth)
rootdepth = e.Right().rootdepth
var topodepth int
topodepth, err = e.TopoDepth()
if err != nil {
Expand All @@ -237,9 +239,9 @@ func (e *Edge) ToStatsString(withedgecomments bool) string {
comment = "\t" + e.CommentsString() + "\t" + leftname + "\t" + rightcomment + "\t" + leftcomment
}

return fmt.Sprintf("%s\t%s\t%t\t%d\t%d\t%s%s",
return fmt.Sprintf("%s\t%s\t%t\t%d\t%d\t%d\t%s%s",
length, support, e.Right().Tip(),
depth, topodepth, rightname, comment)
depth, topodepth, rootdepth, rightname, comment)
}

// Returns true if this edge defines the same biparition of the tips
Expand Down
Loading

0 comments on commit 4c19ab4

Please sign in to comment.