6894b3e9c5590a37147afd1485f21f07285c7ed1
galt
Mon Sep 19 17:10:21 2016 -0700
Renamed phyloGif to phloPng for greater accuracy in the name. Because when we switched to PNG, only 16-bit color palettes are supported now. We lost the ability to do 8-bit color palette which is needed by GIF.
diff --git src/hg/phyloPng/phyloPng.c src/hg/phyloPng/phyloPng.c
new file mode 100644
index 0000000..e1c48ad
--- /dev/null
+++ src/hg/phyloPng/phyloPng.c
@@ -0,0 +1,770 @@
+/* Copyright (C) 2012 The Regents of the University of California
+ * See README in this or parent directory for licensing information. */
+
+/* phyloPng.c for parsing phylo tree and outputting a png.
+ *
+ * Author: Galt Barber 2006
+ *
+ * Designed to be run either as a cgi or as a command-line utility.
+ * The input file spec matches the .nh tree format e.g. (cat:0.5,dog:0.6):1.2;
+ * The output png layout was originally designed to ignore branch lengths.
+ * However, options have now been added to allow it to use branchlengths,
+ * and to label the length of the branches.
+ * Any _suffix is stripped from labels both because pyloTree.c
+ * can't tolerate underscores and because we don't want suffixes anyway.
+ * A semi-colon is automatically appended to the input if left off.
+ * Because phyloTree.c does errAbort on bad input, this causes cgi err 500
+ * if the input data has incorrect syntax. See the apache error_log.
+ * Added another option to place form output in a static html page
+ * so that we can prevent IE6 save-as bug, and FF auto-shrunk output.
+ * Added an option to display a length-scale legend or ruler at the bottom.
+ * Added an option to preserve underscores in input as spaces in output.
+ *
+ *
+ * One may use as a cgi in html GET:
+ *
+ *
+ * Or as cgi in html POST:
+
\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"
+" |
"); + /* we dont think the specific error message coming back are correct or useful + * so supply a generic err msg */ + htmlPrintf("Original input tree:\n[%s]\n\n",cgiString("phyloPng_tree")); + htmlPrintf("Input tree as passed to parser:\n[%s]\n\n",phyloData); + printf("Parser syntax error:\n%s",errMsg); + puts(""); + } + else + { + warn("%s", errMsg); + } + freez(&errMsg); + freez(&phyloData); + return 0; + } +} + + + +MgFont *font = NULL; +if (monospace) + font = mgMenloMediumFont(); +else + font = mgMediumBoldFont(); + + +if (phyloTree) + { + mg = mgNew(width,height); + mgClearPixels(mg); + + lengthLegend = lengthLegend && branchLengths; /* moot without lengths */ + if (lengthLegend) + { + int fHeight = mgFontPixelHeight(font); + height -= (MARGIN+2*fHeight); + } + + phyloTreeLayoutBL(phyloTree, &maxDepth, &numLeafs, 0, font, &maxLabelWidth, width, &minMaxFactor, 0.0); + + if (layoutErrMsg[0] != 0) + { + if (onWeb) + { + printf("Content-type: text/html\r\n"); + printf("\r\n"); + puts("
"); + printf("input tree: [%s]\n\n%s",cgiString("phyloPng_tree"),layoutErrMsg); + puts(""); + } + else + { + warn("%s", layoutErrMsg); + } + freez(&phyloData); + mgFree(&mg); + return 0; + } + + if (branchLengths) + phyloTreePngBL(phyloTree, maxDepth, numLeafs, maxLabelWidth, width, height, + mg, font, minMaxFactor, FALSE); + else + phyloTreePng(phyloTree, maxDepth, numLeafs, maxLabelWidth, width, height, mg, font); + + if (lengthLegend) + { + int i = 0; + char out[256]; + double scaleEnd = (width - 2*MARGIN); + int fHeight = mgFontPixelHeight(font); + int x=0; + int dh=0; + + mgDrawLine(mg, MARGIN, height+fHeight/2, + width-MARGIN, height+fHeight/2, MG_BLACK); + while(TRUE) + { + x=((minMaxFactor*i)/10); + if (x >= scaleEnd) + break; + if ((i % 5) == 0) + { + int y = mgFontCharWidth(font,'0'); + y += 0.5*mgFontCharWidth(font,'.'); + safef(out,sizeof(out),"%3.2f",branchMultiplier*i/10.0); + if (branchMultiplier > 10) + safef(out,sizeof(out),"%3.0f",branchMultiplier*i/10.0); + mgText(mg, MARGIN+x-y, height+fHeight, MG_BLACK, font, out); + dh=fHeight/2; + } + else + { + dh = fHeight / 4; + } + mgDrawLine(mg, MARGIN+x, height+fHeight/2-dh, + MARGIN+x, height+fHeight/2+dh, MG_BLACK); + ++i; + } + + + } + + } + +if (onWeb) + { + printf("Content-type: image/png\r\n"); + printf("\r\n"); + } + +if (!mgSaveToPng(stdout, mg, FALSE)) + { + errAbort("Couldn't save png to stdout"); + } + +if (cgiOptionalString("phyloPng_submit")) + cartCheckout(&cart); + +/* there's no code for freeing the phyloTree yet in phyloTree.c */ + +mgFree(&mg); +freez(&phyloData); + + +return 0; +} +