ebcbc767842df436441e62e1d90f0038b85583b5 galt Tue Aug 25 14:02:57 2015 -0700 fix phyloGif to accept more special chars. fixes #15919 diff --git src/hg/phyloGif/phyloGif.c src/hg/phyloGif/phyloGif.c index 360aaff..9c7b6ed 100644 --- src/hg/phyloGif/phyloGif.c +++ src/hg/phyloGif/phyloGif.c @@ -68,35 +68,36 @@ #include "errAbort.h" #include "errCatch.h" struct cart *cart=NULL; /* The user's ui state. */ struct hash *oldVars = NULL; boolean onWeb = FALSE; int width=240,height=512; boolean branchLengths = FALSE; /* branch lengths */ boolean lengthLegend = FALSE; /* length ruler*/ boolean branchLabels = FALSE; /* labelled branch lengths */ boolean htmlPageWrapper = FALSE; /* wrap output in an html page */ -boolean preserveUnderscores = FALSE; /* preserve underscores in input as spaces in output */ +boolean stripUnderscoreSuff = FALSE; /* strip underscore suffixes from labels in input */ +boolean dashToSpace = FALSE; /* convert dash to space */ +boolean underToSpace = FALSE; /* convert underscore to space */ boolean monospace = FALSE; /* use monospace font */ int branchDecimals = 2; /* show branch label length to two decimals by default */ int branchMultiplier = 1; /* multiply branch length by factor */ -char *escapePattern = NULL; /* use to escape dash '-' char in input */ char layoutErrMsg[1024] = ""; /* Null terminated list of CGI Variables we don't want to save * permanently. */ char *excludeVars[] = {"Submit", "submit", "phyloGif_submit", "phyloGif_restore", NULL}; void usage(char *msg) /* Explain usage and exit. */ { errAbort( "%s\n\n" "phyloGif - parse and display phyloGenetic tree\n" "\n" "Command-line Usage Examples:\n" " phyloGif -phyloGif_tree=tree.nh [options] > phylo.gif \n" @@ -208,37 +209,48 @@ else if (phyloTree->numEdges == 0) /* leaf */ { int w=0; double factor=0.0; this->depth=0; this->vPos=*pNumLeafs; (*pNumLeafs)++; if(!phyloTree->ident->name) { safef(layoutErrMsg,sizeof(layoutErrMsg), "leaf is missing label\n"); return; } - /* de-escape name if needed */ - if(stringIn(escapePattern,phyloTree->ident->name)) + if(dashToSpace) { char *temp = phyloTree->ident->name; - phyloTree->ident->name = replaceChars(temp,escapePattern," "); + phyloTree->ident->name = replaceChars(temp,"-"," "); freez(&temp); } + + if(underToSpace) + { + char *temp = phyloTree->ident->name; + phyloTree->ident->name = replaceChars(temp,"_"," "); + freez(&temp); + } + + /* strip underscore suffixes option */ + if (stripUnderscoreSuff) + stripUnderscoreSuffixes(phyloTree->ident->name); + w=mgFontStringWidth(font,phyloTree->ident->name); if (w > *pMaxLabelWidth) *pMaxLabelWidth = w; factor = (width - 3*MARGIN - w) / this->hPos; if (*pMinMaxFactor == 0.0 || factor < *pMinMaxFactor) *pMinMaxFactor = factor; } else { safef(layoutErrMsg,sizeof(layoutErrMsg), "Expected tree nodes to have 0 or 2 edges, found %d.\n" "Check for missing commas or missing data.\n" ,phyloTree->numEdges); } @@ -378,70 +390,76 @@ printf("Content-type: image/gif\r\n"); printf("\r\n"); return 0; } if (useCart) { width = cartUsualInt(cart,"phyloGif_width",width); height = cartUsualInt(cart,"phyloGif_height",height); phyloData = cloneString(cartOptionalString(cart,"phyloGif_tree")); branchLengths = cartVarExists(cart,"phyloGif_branchLengths"); lengthLegend = cartVarExists(cart,"phyloGif_lengthLegend"); branchLabels = cartVarExists(cart,"phyloGif_branchLabels"); branchDecimals = cartUsualInt(cart,"phyloGif_branchDecimals", branchDecimals); branchMultiplier = cartUsualInt(cart,"phyloGif_branchMultiplier", branchMultiplier); - preserveUnderscores = cartVarExists(cart,"phyloGif_underscores"); + stripUnderscoreSuff = cartVarExists(cart,"phyloGif_undersuff_strip"); + dashToSpace = cartVarExists(cart,"phyloGif_dash_to_space"); + underToSpace = cartVarExists(cart,"phyloGif_under_to_space"); monospace = cartVarExists(cart, "phyloGif_monospace"); } else { width = cgiUsualInt("phyloGif_width",width); height = cgiUsualInt("phyloGif_height",height); phyloData = cloneString(cgiOptionalString("phyloGif_tree")); branchLengths = cgiVarExists("phyloGif_branchLengths"); lengthLegend = cgiVarExists("phyloGif_lengthLegend"); branchLabels = cgiVarExists("phyloGif_branchLabels"); branchDecimals = cgiUsualInt("phyloGif_branchDecimals", branchDecimals); branchMultiplier = cgiUsualInt("phyloGif_branchMultiplier", branchMultiplier); - preserveUnderscores = cgiVarExists("phyloGif_underscores"); + stripUnderscoreSuff = cgiVarExists("phyloGif_undersuff_strip"); + dashToSpace = cgiVarExists("phyloGif_dash_to_space"); + underToSpace = cgiVarExists("phyloGif_under_to_space"); monospace = cgiVarExists("phyloGif_monospace"); } if (useCart) { if (onWeb) { printf("Content-type: text/html\r\n"); printf("\r\n"); cartWebStart(cart, NULL, "%s", "phyloGif Interactive Phylogenetic Tree Gif Maker"); if (isMSIE) /* cannot handle long urls */ puts("
"); webNewSection("Notes"); puts( "\n" "1. Length-ruler and length-values cannot be shown unless use-branch-lengths is also checked.\n" "((A:0.1,B:0.1):0.2,C:0.15);\n" " | \n"
" |
\n" "((A:0.1,B:0.1)D:0.2,C:0.15)E;\n" " | \n"
" (internal or ancestral node labels)\n" " |
\n" " ((((\n" " (\n" " ((mouse,rat),human),\n" " (dog,cow)\n" " ),\n" " opossum),\n" " chicken),\n" " xenopus),\n" " (tetraodon,zebrafish));\n" " | \n"
" |
\n"
+"We have extended the Newick format to allow spaces \n" +"and other non-alphanumeric characters in node labels. \n" +"If you need a backslash, comma, semi-colon, colon, or parenthesis, \n" +"it must be escaped with a back-slash character. \n" +" \n" +"((Brandt's myotis \\(bat\\):0.1,\n" +" White-tailed eagle:0.1):0.2,\n" +" S. purpuratus:0.15);\n" +" | \n"
+" |