Browse Source

allow underscore; fix distance calculation

remotes/georgeg/no_streams
lomereiter 9 years ago
parent
commit
4758c0595c
  1. 8
      bio/newick/parser.d
  2. 3
      bio/newick/tree.d

8
bio/newick/parser.d

@ -20,6 +20,10 @@ NewickNode* parse(string s) {
private {
bool isValidCharacter(dchar c) {
return isAlphaNum(c) || c == '_';
}
void skipWhiteSpace(ref string s) {
while (true) {
if (s.empty)
@ -59,7 +63,7 @@ private {
return new NewickNode;
default:
enforce(isAlphaNum(ch), "Node name contains invalid character");
enforce(isValidCharacter(ch), "Node name contains invalid character");
return parseLeafNode(s);
}
}
@ -72,7 +76,7 @@ private {
auto node = nd is null ? (new NewickNode) : nd;
size_t i = 0;
while (isAlphaNum(s[i])) {
while (isValidCharacter(s[i])) {
++i;
}

3
bio/newick/tree.d

@ -38,9 +38,10 @@ class NewickTree {
/** Distance between two nodes */
double distance(NewickNode* n1, NewickNode* n2) {
if (n1 is null || n2 is null) return double.nan;
if (n1 == n2) return 0;
if (n1 == root) return distance(root, n2.parent) + n2.distance_to_parent;
if (n2 == root) return distance(n1, root) + n1.distance_to_parent;
if (n2 == root) return distance(n1.parent, root) + n1.distance_to_parent;
assert(n1.parent !is null);
assert(n2.parent !is null);
return distance(n1.parent, n2.parent) + n1.distance_to_parent

Loading…
Cancel
Save