src/hg/hgc/hgdpClick.c 1.5

1.5 2009/02/09 22:30:25 angie
Use hg.conf settings to determine GMT executable paths and enable/disable images, instead of hIsPrivateHost.
Index: src/hg/hgc/hgdpClick.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgc/hgdpClick.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/hg/hgc/hgdpClick.c	9 Feb 2009 18:52:35 -0000	1.4
+++ src/hg/hgc/hgdpClick.c	9 Feb 2009 22:30:25 -0000	1.5
@@ -2,8 +2,9 @@
 
 #include "common.h"
 #include "hgc.h"
 #include "hgdpGeo.h"
+#include "hgConfig.h"
 #include "trashDir.h"
 #include "pipeline.h"
 #include "obscure.h"
 #include "htmshell.h"
@@ -150,9 +151,8 @@
 
 // Parameters for running the Generic Mapping Tools psxy command to plot pie charts
 // on two maps in one image: Africa+EurAsia (AEA) and Central/South America (AM).
 // These are from scripts written by John Novembre, jnovembre at ucla.
-#define PSXY_PATH "/hive/data/outside/GMT4.3.1/bin/psxy"
 #define PSXY_PIX "-W0.5p"
 #define PSXY_CIRCLE "-Sc"
 #define PSXY_WEDGE "-Sw"
 #define PSXY_CONT_PLOT "-O"
@@ -165,37 +165,33 @@
 #define AM_PROJ "-JKs275.5/1.5i"
 #define AM_X "-X6.85i"
 #define AM_Y "-Y4.25i"
 static char *psxyOrangeAeaCmd[] = 
-    {PSXY_PATH, "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
+    {"", "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
      PSXY_CIRCLE, "-Gorange", AEA_X, AEA_Y, NULL};
 static char *psxyPieAeaCmd[] =
-    {PSXY_PATH, "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
+    {"", "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
      PSXY_WEDGE, "-Gblue", NULL};
 static char *psxyBlueAeaCmd[] =
-    {PSXY_PATH, "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
+    {"", "", AEA_REGION, AEA_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
      PSXY_CIRCLE, "-Gblue", NULL};
 static char *psxyOrangeAmCmd[] = 
-    {PSXY_PATH, "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
+    {"", "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
      PSXY_CIRCLE, "-Gorange", AM_X, AM_Y, NULL};
 static char *psxyPieAmCmd[] =
-    {PSXY_PATH, "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
+    {"", "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT, PSXY_CONT_PS,
      PSXY_WEDGE, "-Gblue", NULL};
 static char *psxyBlueAmCmd[] =
-    {PSXY_PATH, "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT,
+    {"", "", AM_REGION, AM_PROJ, PSXY_PIX, PSXY_CONT_PLOT,
      PSXY_CIRCLE, "-Gblue", NULL};
 
-// We use the Generic Mapping Tools ps2raster command to convert the generated
-// Encapsulated PostScript imange to PNG.
-#define PS2RASTER_PATH "/hive/data/outside/GMT4.3.1/bin/ps2raster"
-#define GHOSTSCRIPT_PATH "-G/usr/bin/ghostscript"
-
-static void runCommandAppend(char *cmd[], char *inFile, char *outFile)
+static void runCommandAppend(char *cmd[], char *program, char *inFile, char *outFile)
 /* Use the pipeline module to run a single command pipelineWrite|pipelineAppend. */
 {
 char **cmds[2];
 cmds[0] = cmd;
 cmds[1] = NULL;
+cmd[0] = program;
 cmd[1] = inFile;
 struct pipeline *pl = pipelineOpen(cmds, pipelineWrite|pipelineAppend, outFile, NULL);
 pipelineWait(pl);
 pipelineFree(&pl);
@@ -255,14 +251,17 @@
 fprintf(fEps, hgdpGeoLabelFormat, geo->name, geo->name,
 	geo->ancestralAllele, geo->ancestralAllele, geo->derivedAllele, geo->derivedAllele);
 fclose(fEps);
 //- run psxy on circle/pie spec trash files for AfrEurAsia and America
-runCommandAppend(psxyOrangeAeaCmd, pieFile, epsFile);
-runCommandAppend(psxyPieAeaCmd, pieFile, epsFile);
-runCommandAppend(psxyBlueAeaCmd, circleFile, epsFile);
-runCommandAppend(psxyOrangeAmCmd, pieFile, epsFile);
-runCommandAppend(psxyPieAmCmd, pieFile, epsFile);
-runCommandAppend(psxyBlueAmCmd, circleFile, epsFile);
+char *psxy = cfgOption("hgc.psxyPath");
+if (isEmpty(psxy))
+    errAbort("How did this get called?  hg.conf doesn't have hgc.psxyPath.");
+runCommandAppend(psxyOrangeAeaCmd, psxy, pieFile, epsFile);
+runCommandAppend(psxyPieAeaCmd, psxy, pieFile, epsFile);
+runCommandAppend(psxyBlueAeaCmd, psxy, circleFile, epsFile);
+runCommandAppend(psxyOrangeAmCmd, psxy, pieFile, epsFile);
+runCommandAppend(psxyPieAmCmd, psxy, pieFile, epsFile);
+runCommandAppend(psxyBlueAmCmd, psxy, circleFile, epsFile);
 
 // Make PDF and PNG:
 struct pipeline *pl;
 char pdfFile[FILENAME_LEN], pngFile[FILENAME_LEN];
@@ -273,10 +272,13 @@
 pl = pipelineOpen(cmdsPdf, pipelineWrite, "/dev/null", NULL);
 pipelineWait(pl);
 pipelineFree(&pl);
 
-char *ps2RasterPngCmd[] = {PS2RASTER_PATH, GHOSTSCRIPT_PATH, "-P", "-A", "-Tg", "-E150",
-			   epsFile, NULL};
+char *ps2raster = cfgOption("hgc.ps2rasterPath");
+char *ghostscript = cfgOption("hgc.ghostscriptPath");
+char gsOpt[PATH_LEN];
+safef(gsOpt, sizeof(gsOpt), "-G%s", ghostscript);
+char *ps2RasterPngCmd[] = {ps2raster, gsOpt, "-P", "-A", "-Tg", "-E150", epsFile, NULL};
 char **cmdsPng[] = {ps2RasterPngCmd, NULL};
 pl = pipelineOpen(cmdsPng, pipelineRead, "/dev/null", NULL);
 pipelineWait(pl);
 pipelineFree(&pl);
@@ -298,13 +300,26 @@
 mustRename(tmpPath, finalPngFile);
 }
 
 
+static boolean canMakeImages()
+/* Determine whether we have the necessary command line programs for
+ * creating images above. */
+{
+char *psxy = cfgOption("hgc.psxyPath");
+char *ps2raster = cfgOption("hgc.ps2rasterPath");
+char *ghostscript = cfgOption("hgc.ghostscriptPath");
+if (isEmpty(psxy) || isEmpty(ps2raster) || isEmpty(ghostscript))
+    return FALSE;
+if (!fileExists(psxy) || !fileExists(ps2raster) || !fileExists(ghostscript))
+    return FALSE;
+return TRUE;
+}
+
 void hgdpGeoImg(struct hgdpGeo *geo)
 /* Generate a PNG image: world map with pie charts for population allele frequencies. */
 {
-// Disable this past hgwdev until we fix the /hive paths...
-if (! hIsPrivateHost())
+if (! canMakeImages())
     return;
 struct tempName tn;
 trashDirFile(&tn, "hgc", "", "");
 char trashDir[FILENAME_LEN];