16ec9357014d6670ffe6464487e962a4e3ed9332
braney
  Thu Apr 16 16:41:19 2020 -0700
add secondary structure picture

diff --git src/hg/hgc/rnaFoldClick.c src/hg/hgc/rnaFoldClick.c
index 36e514b..3c1c30f 100644
--- src/hg/hgc/rnaFoldClick.c
+++ src/hg/hgc/rnaFoldClick.c
@@ -5,30 +5,31 @@
 
 #include "common.h"
 #include "jksql.h"
 #include "hgMaf.h"
 #include "maf.h"
 #include "cart.h"
 #include "hgc.h"
 #include "hCommon.h"
 #include "hgColors.h"
 #include "obscure.h"
 #include "customTrack.h"
 #include "htmshell.h"
 #include "rnautil.h"
 #include "rnaSecStr.h"
 #include "memalloc.h"
+#include "hgConfig.h"
 
 
 /* Taken from hgc.c (should probably be in hgc.h)*/
 #define RED 0xFF0000
 #define GREEN 0x00FF00
 #define BLUE 0x0000FF
 #define BLACK 0x000000
 #define CYAN 0x00FFFF
 #define GRAY 0xcccccc
 #define LTGRAY 0x999999
 #define ORANGE 0xDD6600
 #define MAGENTA 0xFF00FF
 
 #define LTPURPLE 0x9966CC
 #define SCORE_SHADES_COUNT 10
@@ -356,30 +357,70 @@
     if ((mcThis = mafMayFindCompSpecies(maf, species[i], '.')) == NULL)
 	continue;
     newOrder[mcCount++] = mcThis;
   }
 
 maf->components = NULL;
 for (i = 0; i < mcCount; i++)
   {
     newOrder[i]->next = 0;
     slAddHead(&maf->components, newOrder[i]);
   }
 
 slReverse(&maf->components);
 }
 
+void htmlPrintSecStr(FILE *f, char *table, struct rnaSecStr *item)
+/* Print out the details for an rnaStruct* table. */
+{
+// grab the sequence
+struct dnaSeq *seq = hChromSeq(database, item->chrom, item->chromStart, item->chromEnd);
+touppers(seq->dna);
+if (item->strand[0] == '-')
+    reverseComplement(seq->dna, seq->size);
+toRna(seq->dna);
+
+// make sure the dna is not longer than the paren string
+seq->dna[strlen(item->secStr)] = 0;
+
+char *rnaPlotPath = cfgOptionDefault("rnaPlotPath", "../cgi-bin/RNAplot");
+mkdirTrashDirectory(table);
+
+char command[512];
+char psName[512];
+safef(psName, sizeof(psName), "../trash/%s/%s_%s.ps", table, table, item->name);
+FILE *of = popen(rnaPlotPath, "w");
+if (of != NULL)
+    {
+    fprintf(of, ">%s\n", psName);        /* This tells where to put file. */
+    fprintf(of, "%s\n%s\n", seq->dna, item->secStr);
+    pclose(of);
+    }
+
+char pngName[256];
+char *rootName = cloneString(psName);
+ 
+chopSuffix(rootName);
+safef(pngName, sizeof(pngName), "%s.png", rootName);
+
+safef(command, sizeof(command),
+    "gs -g768x768 -sDEVICE=png16m -sOutputFile=%s -dBATCH -dNOPAUSE -q %s" , pngName, psName);
+mustSystem(command);
+
+printf("<IMG SRC='%s' border = '2'>", pngName);
+}
+
 void htmlPrintSecStrEvofoldDrawing(FILE *f, struct rnaSecStr *item)
 {
 char fileName[512];
 struct dnaSeq *seq;
 seq = hChromSeq(database, item->chrom, item->chromStart, item->chromEnd);
 touppers(seq->dna);
 if (item->strand[0] == '-')
     reverseComplement(seq->dna, seq->size);
 memSwapChar(seq->dna, seq->size, 'T', 'U');
 
 safef(fileName, sizeof(fileName), "/gbdb/%s/evoFold/%s/%s.png",
        database, item->chrom, item->name);
 if (fileExists(fileName))
     {
     fprintf(f, "<center><h2> RNA secondary structure drawing </h2></center>");
@@ -439,63 +480,71 @@
 printf("\" TARGET=_blank>%s</A>.", "click here to go to genome-mirror.moma.ki.au.dk");
 fprintf(f," <B><FONT COLOR = RED>NOTE:</FONT> some operating system/browser combinations require ");
 fprintf(f," the latest version of Java for this to work properly.</FONT></B></P>");
 }
 
 void doRnaSecStr(struct trackDb *tdb, char *itemName)
 /* Handle click on rnaSecStr type elements. */
 {
 char *table = tdb->table;
 struct sqlConnection *conn = hAllocConn(database);
 struct sqlResult *sr;
 struct rnaSecStr *item;
 char extraWhere[256];
 char **row;
 int  rowOffset = 0;
-char *mafTrack = trackDbRequiredSetting(tdb, "mafTrack");
+char *mafTrack = trackDbSetting(tdb, "mafTrack");
 int start = cartInt(cart, "o");
 struct mafAli *maf;
 char option[128];
 char *speciesOrder = NULL;
 
 /* print header */
 genericHeader(tdb, itemName);
 /* printRfamUrl(itemName); */
 genericBedClick(conn, tdb, itemName, start, 6);
 htmlHorizontalLine();
 
 /* get the rnaSecStr and maf from db */
 sprintf(extraWhere, "chromStart = %d and name = '%s'", start, itemName);
 sr   = hExtendedChromQuery(conn, table, seqName, extraWhere,  FALSE, NULL, &rowOffset);
 row  = sqlNextRow(sr);
 item = rnaSecStrLoad(row + rowOffset);
+if (mafTrack)
+    {
     maf  = mafFromRnaSecStrItem(mafTrack, item);
 
     /* order maf by species */
     safef(option, sizeof(option), "%s.speciesOrder", tdb->track);
     speciesOrder = cartUsualString(cart, option, NULL);
     if (speciesOrder == NULL)
       speciesOrder = trackDbSetting(tdb, "speciesOrder");
     if (speciesOrder)
       mafSortBySpeciesOrder(maf, speciesOrder);
 
     mafAndFoldHeader(stdout);
     htmlPrintMafAndFold(stdout, maf, item->secStr, item->conf, 100);
 
     mafAndFoldLegend(stdout);
+    }
 
-/* Draw structure for evoFold */
+/* Draw structure for rnaStruct* table */
+if (startsWith("rnaStruct", tdb->table))
+    {
+    htmlHorizontalLine();
+    htmlPrintSecStr(stdout, tdb->table, item);
+    }
 if (sameWord(tdb->table, "evofold"))
     {
     htmlHorizontalLine();
     htmlPrintSecStrEvofoldDrawing(stdout, item);
     }
 
 /* Draw structure for evoFoldV2 */
 if (sameWord(tdb->table, "evofoldV2"))
     {
     htmlHorizontalLine();
     htmlPrintSecStrEvofoldV2Drawing(stdout, item);
     }
 
 /* track specific html */
 printTrackHtml(tdb);