a127c65d3afd590532ba58c503bc08d29cb90ac5 max Wed Mar 5 03:05:44 2014 -0800 Fixing RNAplot problem with newer versions, refs #11957, note 178 andrefs #6382 diff --git src/hg/hgGene/rnaStructure.c src/hg/hgGene/rnaStructure.c index cf0a295..239d403 100644 --- src/hg/hgGene/rnaStructure.c +++ src/hg/hgGene/rnaStructure.c @@ -1,26 +1,27 @@ /* rnaStructure - do section on 3' and 5' UTR structure. */ #include "common.h" #include "hash.h" #include "linefile.h" #include "jksql.h" #include "rnaFold.h" #include "hui.h" #include "web.h" #include "portable.h" #include "hgGene.h" +#include "hgConfig.h" static void rnaTrashDirsInit(char **tables, int count) /* create trash directories if necessary */ { for ( count--; count > -1; count--) mkdirTrashDirectory(tables[count]); } static boolean rnaStructureExists(struct section *section, struct sqlConnection *conn, char *geneId) /* Return TRUE if tables exists and have our gene. */ { if (sqlTableExists(conn, "foldUtr3") && sqlRowExists(conn, "foldUtr3", "name", geneId)) @@ -41,90 +42,113 @@ static char *tables[2] = {"foldUtr5", "foldUtr3"}; int side; if (firstTime) { rnaTrashDirsInit(tables, ArraySize(tables)); firstTime = FALSE; } webPrintLinkTableStart(); webPrintLabelCell("Region"); webPrintLabelCell("Fold Energy"); webPrintLabelCell("Bases"); webPrintLabelCell("Energy/Base"); webPrintWideCenteredLabelCell("Display As", 3); + +char *rnaPlotPath = cfgOptionDefault("rnaPlotPath", "../cgi-bin/RNAplot"); + for (side = 0; side < ArraySize(names); ++side) { char *table = tables[side]; struct sqlResult *sr; char query[256], **row; sqlSafef(query, sizeof(query), "select * from %s where name = '%s'", table, geneId); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { struct rnaFold fold; int bases; char psName[128]; /* Load fold and save it as postScript. */ rnaFoldStaticLoad(row, &fold); safef(psName, sizeof(psName), "../trash/%s/%s_%s.ps", table, table, geneId); - if (!fileExists(psName)) + bool plotDone = FALSE; + if (fileExists(psName)) + plotDone = TRUE; + else { FILE *f; - f = popen("../cgi-bin/RNAplot", "w"); + + if (!fileExists(rnaPlotPath)) + { + plotDone = FALSE; + fprintf(stderr, "Could not find %s", rnaPlotPath); + } + else + { + f = popen(rnaPlotPath, "w"); if (f != NULL) { fprintf(f, ">%s\n", psName); /* This tells where to put file. */ fprintf(f, "%s\n%s\n", fold.seq, fold.fold); pclose(f); + plotDone = TRUE; + } } } + // newer versions of RNAplot add _ss.ps to the file name + if (!fileExists(psName)) + safef(psName, sizeof(psName), "../trash/%s/%s_%s.ps_ss.ps", table, table, geneId); + /* Print row of table, starting with energy terms . */ hPrintf("</TR><TR>"); bases = strlen(fold.seq); webPrintLinkCell(names[side]); webPrintLinkCellStart(); hPrintf("%1.2f", fold.energy); webPrintLinkCellEnd(); webPrintLinkCellStart(); hPrintf("%d", bases); webPrintLinkCellEnd(); webPrintLinkCellStart(); hPrintf("%1.3f", fold.energy/bases); webPrintLinkCellEnd(); + if (plotDone) + { /* Print link to png image. */ webPrintLinkCellStart(); hPrintf("<A HREF=\"%s?%s&%s=%s&%s=%s&%s=%s\" class=\"toc\" TARGET=_blank>", geneCgi, cartSidUrlString(cart), hggMrnaFoldRegion, table, hggMrnaFoldPs, psName, hggDoRnaFoldDisplay, "picture"); hPrintf(" Picture "); hPrintf("</A>"); webPrintLinkCellEnd(); /* Print link to PostScript. */ webPrintLinkCellStart(); hPrintf("<A HREF=\"%s\" class=\"toc\">", psName); hPrintf(" PostScript "); hPrintf("</A>"); webPrintLinkCellEnd(); + } /* Print link to text. */ webPrintLinkCellStart(); hPrintf("<A HREF=\"%s?%s&%s=%s&%s=%s\" class=\"toc\" TARGET=_blank>", geneCgi, cartSidUrlString(cart), hggMrnaFoldRegion, table, hggDoRnaFoldDisplay, "text"); hPrintf(" Text "); hPrintf("</A>"); webPrintLinkCellEnd(); } sqlFreeResult(&sr); } webPrintLinkTableEnd(); hPrintf("<BR>The RNAfold program from the ");