b3afed1479ffa80ba9615108abb29836b8dd1fdc
kate
  Mon Mar 28 18:06:42 2016 -0700
Add total expression to details page.  Correct map box size problem. refs #15645

diff --git src/hg/hgTracks/gtexTracks.c src/hg/hgTracks/gtexTracks.c
index 7b61a93..1345168 100644
--- src/hg/hgTracks/gtexTracks.c
+++ src/hg/hgTracks/gtexTracks.c
@@ -472,35 +472,34 @@
     return MED_BAR_WIDTH;
 else
     return MIN_BAR_WIDTH;
 }
 
 static enum trackVisibility gtexGeneModelVis(struct gtexGeneExtras *extras)
 {
 long winSize = virtWinBaseCount;
 if (winSize < WIN_MED_GRAPH && !extras->isComparison)
     return tvPack;
 return tvSquish;
 }
 
 static int gtexGeneModelHeight(struct gtexGeneExtras *extras)
 {
-long winSize = virtWinBaseCount;
-if (winSize < WIN_MED_GRAPH && !extras->isComparison)
+enum trackVisibility vis = gtexGeneModelVis(extras);
+if (vis == tvSquish)
+    return trunc(tl.fontHeight/2) + 1;
 return tl.fontHeight;
-// too busy to show exon arrows if zoomed out or have double graphs
-return 8;
 }
 
 static int gtexGraphPadding()
 {
 long winSize = virtWinBaseCount;
 
 if (winSize < WIN_MAX_GRAPH)
     return MAX_GRAPH_PADDING;
 else if (winSize < WIN_MED_GRAPH)
     return MED_GRAPH_PADDING;
 else
     return MIN_GRAPH_PADDING;
 }
 
 static int gtexMaxGraphHeight()
@@ -742,31 +741,38 @@
                                         extras->doLogTransform);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero, barWidth, height, fillColorIx, lineColorIx);
     // mark clipped bar with magenta tip
     if (!extras->doLogTransform && expScore > viewMax)
         hvGfxBox(hvg, x1, yZero + height, barWidth, 1, clipColor);
     x1 = x1 + barWidth + graphPadding;
     }
 }
 
 static int gtexGeneItemHeightOptionalMax(struct track *tg, void *item, boolean isMax)
 {
 if (tg->visibility == tvSquish || tg->visibility == tvDense)
+    {
+    if (tg->visibility == tvSquish)
+        {
+        tg->lineHeight = trunc(tl.fontHeight/2) + 1;
+        tg->heightPer = tg->lineHeight;
+        }
     return tgFixedItemHeight(tg, item);
+    }
 struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
 if (isMax)
     {
     int extra = 0;
     if (((struct gtexGeneExtras *)tg->extraUiData)->isComparison)
         extra = gtexMaxGraphHeight() + 2;
     return gtexMaxGraphHeight() + gtexGeneMargin() + gtexGeneModelHeight(extras) + extra;
     }
 if (item == NULL)
     return 0;
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 
 if (geneInfo->height != 0)
     return geneInfo->height;
 int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, TRUE);
@@ -795,52 +801,67 @@
 }
 
 static char *tissueExpressionText(struct gtexTissue *tissue, double expScore, 
                                         boolean doLogTransform, char *qualifier)
 /* Construct mouseover text for tissue graph */
 {
 static char buf[128];
 safef(buf, sizeof(buf), "%s (%.1f %s%s%sRPKM)", tissue->description, 
                                 doLogTransform ? log10(expScore+1.0) : expScore,
                                 qualifier != NULL ? qualifier : "",
                                 qualifier != NULL ? " " : "",
                                 doLogTransform ? "log " : "");
 return buf;
 }
 
+static void getItemX(int start, int end, int *x1, int *x2)
+/* Return startX, endX based on item coordinates and current window */
+{
+int s = max(start, winStart);
+int e = min(end, winEnd);
+double scale = scaleForWindow(insideWidth, winStart, winEnd);
+assert(x1);
+*x1 = round((double)((int)s-winStart)*scale + insideX);
+assert(x2);
+*x2 = round((double)((int)e-winStart)*scale + insideX);
+}
+
 static void gtexGeneMapItem(struct track *tg, struct hvGfx *hvg, void *item, char *itemName, 
                         char *mapItemName, int start, int end, int x, int y, int width, int height)
 /* Create a map box on gene model and label, and one for each tissue (bar in the graph) in
  * pack or full mode.  Just single map for squish/dense modes */
 {
 if (tg->visibility == tvDense)
     {
     genericMapItem(tg, hvg, item, itemName, itemName, start, end, x, y, width, height);
     return;
     }
 struct gtexGeneInfo *geneInfo = item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
 if (tg->visibility == tvSquish)
     {
     int tisId = maxTissueForGene(geneBed);
     char *maxTissue = "";
     if (tisId > 1)
         maxTissue = getTissueDescription(tisId, extras->version);
     char buf[128];
-    safef(buf, sizeof buf, "%s %s%s", geneBed->name, tisId > 0 ? "+":"", maxTissue);
-    mapBoxHc(hvg, start, end, x, y, width, height, tg->track, mapItemName, buf);
+    safef(buf, sizeof buf, "%s %s%s", geneBed->name, tisId > 0 ? "^":"", maxTissue);
+    int x1, x2;
+    getItemX(start, end, &x1, &x2);
+    int width = x2-x1;
+    mapBoxHc(hvg, start, end, x1, y, width, height, tg->track, mapItemName, buf);
     return;
     }
 int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, TRUE);
 topGraphHeight = max(topGraphHeight, tl.fontHeight);        // label
 int yZero = topGraphHeight + y - 1;  // yZero is bottom of graph
 //int yGene = yZero + gtexGeneMargin() - 1;
 int x1 = insideX;
 
 
 // add maps to tissue bars in expresion graph
 struct gtexTissue *tissues = getTissues(extras->version);
 struct gtexTissue *tissue = NULL;
 int barWidth = gtexBarWidth();
 int padding = gtexGraphPadding();
 double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian;
@@ -880,40 +901,37 @@
         int height = valToClippedHeight(expScore, maxMedian, viewMax, 
                                         gtexMaxGraphHeight(), extras->doLogTransform);
         int y = yZero + gtexGeneModelHeight(extras) + gtexGeneMargin();  // y is top of bottom graph
         if (extras->isComparison && extras->isDifference)
             qualifier = "M-F";
         mapBoxHc(hvg, start, end, x1, y, barWidth, height, tg->track, mapItemName,
                 tissueExpressionText(tissue, expScore, extras->doLogTransform, qualifier));
         }
     x1 = x1 + barWidth + padding;
     }
 
 // add map box with description to gene model
 // NOTE: this is "under" the tissue map boxes
 if (geneInfo->geneModel && geneInfo->description)
     {
-    double scale = scaleForWindow(insideWidth, winStart, winEnd);
-    int geneStart = max(geneInfo->geneModel->txStart, winStart);
-    int geneEnd = min(geneInfo->geneModel->txEnd, winEnd);
-    int geneX = round((geneStart-winStart)*scale);
-    int w = round((geneEnd-winStart)*scale) - geneX;
-    x1 = insideX + geneX;
+    int x1, x2;
+    getItemX(geneInfo->geneModel->txStart, geneInfo->geneModel->txEnd, &x1, &x2);
+    int w = x2-x1;
     int labelWidth = mgFontStringWidth(tl.font, itemName);
     if (x1-labelWidth <= insideX)
         labelWidth = 0;
-    mapBoxHc(hvg, start, end, x1-labelWidth, y, w+labelWidth, geneInfo->height, tg->track, 
+    mapBoxHc(hvg, start, end, x1-labelWidth, y, w+labelWidth, geneInfo->height-3, tg->track, 
                     mapItemName, geneInfo->description);
     }
 }
 
 static char *gtexGeneItemName(struct track *tg, void *item)
 /* Return gene name */
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 return geneBed->name;
 }
 
 static int gtexGeneHeight(void *item)
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;