7ffce0e9718d585fa11cddf6ae4fa2be764e6795
angie
  Fri Jul 24 17:19:51 2020 -0700
Added phyloCountInternalNodes.  Allow Newick format tree node names to begin with '_'.  refs #25943

diff --git src/lib/phyloTree.c src/lib/phyloTree.c
index cf25448..ea3c5ad 100644
--- src/lib/phyloTree.c
+++ src/lib/phyloTree.c
@@ -179,31 +179,31 @@
 
     do
 	{
 	struct phyloTree *child = parseSubTree(&ptr);
 	if (!child)
 	    errAbort("missing child/subTree at (%s)",ptr-1);
 	edge = newEdge(node,child);
 	edge->parent = node;
 	} while (*ptr++ == ',');
     --ptr;
     if (*ptr++ != ')') 
 	errAbort("unbalanced parenthesis at (%s)",ptr-1);
     node->ident = parseIdent(&ptr);
     }
 else 
-    if ((*ptr == ':') || (isalpha(*ptr))|| (isdigit(*ptr)) 
+    if ((*ptr == ':') || (isalpha(*ptr))|| (isdigit(*ptr)) || (*ptr == '_')
 	 || (*ptr == '\'') || (*ptr == '.')) 
 	node->ident = parseIdent(&ptr);
 else
     errAbort("illegal char '%c' in phyloString",*ptr);
 
 if (*ptr == '[')
     {
     if (startsWith("[&&NHX:D=Y]",ptr))
 	node->isDup = TRUE;
 
     while(*ptr != ']')
 	ptr++;
 
     ptr++;
 
@@ -484,15 +484,29 @@
 errAbort("tried to delete non-existant edge");
 }
 
 int phyloCountLeaves(struct phyloTree *tree)
 {
 int ii, count = 0;
 
 if (tree->numEdges == 0)
     return 1;
 
 for (ii=0; ii < tree->numEdges; ii++)
     count += phyloCountLeaves(tree->edges[ii]);
 
 return count;
 }
+
+int phyloCountInternalNodes(struct phyloTree *node)
+/* Return the number of internal nodes (not leaf nodes) in tree. */
+{
+int count = 0;
+if (node->numEdges > 0)
+    {
+    count = 1;
+    int ii;
+    for (ii = 0;  ii < node->numEdges;  ii++)
+        count += phyloCountInternalNodes(node->edges[ii]);
+    }
+return count;
+}