2fa680cd690905a0010a020adfcf88d09c6aac18
kate
  Sun Oct 4 14:57:32 2015 -0700
Add log transform option to display config. refs #15645

diff --git src/hg/hgTracks/gtexTracks.c src/hg/hgTracks/gtexTracks.c
index 9cabf3a..390c029 100644
--- src/hg/hgTracks/gtexTracks.c
+++ src/hg/hgTracks/gtexTracks.c
@@ -148,39 +148,43 @@
 
 static int gtexGraphWidth(struct gtexGeneInfo *geneInfo)
 /* Width of GTEx graph in pixels */
 {
 int barWidth = gtexBarWidth();
 int padding = gtexGraphPadding();
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 int count = geneBed->expCount;
 // TODO: save labels in extras
 int labelWidth = geneInfo->medians2 ? 5 : 0;
 return (barWidth * count) + (padding * (count-1)) + labelWidth + 2;
 ;
 }
 
 
-static int valToHeight(double val, double maxVal, int maxHeight)
+static int valToHeight(double val, double maxVal, int maxHeight, boolean doLogTransform)
 /* Log-scale and Convert a value from 0 to maxVal to 0 to maxHeight-1 */
 // TODO: support linear or log scale
 {
 if (val == 0.0)
     return 0;
 // smallest counts are 1x10e-3, translate to counter negativity
 //double scaled = (log10(val) + 3.001)/(log10(maxVal) + 3.001);
-double scaled = log10(val+1.0) / log10(maxVal+1.0);
+double scaled = 0.0;
+if (doLogTransform)
+    scaled = log10(val+1.0) / log10(maxVal+1.0);
+else
+    scaled = val/maxVal;
 if (scaled < 0)
     warn("scaled=%f\n", scaled);
 //uglyf("%.2f -> %.2f height %d", val, scaled, (int)scaled * (maxHeight-1));
 return (scaled * (maxHeight-1));
 }
 
 // TODO: whack this
 static int valToY(double val, double maxVal, int maxHeight)
 /* Convert a value from 0 to maxVal to 0 to height-1 */
 {
 if (val == 0.0)
     return 0;
 //double scaled = (log10(val)+3.001)/(log10(maxVal)+3.001);
 double scaled = log10(val+1.0) / log10(maxVal+1.0);
 if (scaled < 0)
@@ -409,47 +413,46 @@
     geneInfo->geneBed = geneBed;
     geneInfo->geneModel = hashFindVal(modelHash, geneBed->geneId);
     slAddHead(&list, geneInfo);
     geneBed = geneBed->next;
     geneInfo->geneBed->next = NULL;
     }
 slReverse(&list);
 tg->items = list;
 }
 
 static void gtexGeneDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, 
                 double scale, MgFont *font, Color color, enum trackVisibility vis)
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
+boolean doLogTransform = cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, GTEX_LOG_TRANSFORM, 
+                                                GTEX_LOG_TRANSFORM_DEFAULT);
 
 // Color in dense mode using transcriptClass
 Color statusColor = getTranscriptStatusColor(hvg, geneBed);
 if (vis != tvFull && vis != tvPack)
     {
     bedDrawSimpleAt(tg, geneBed, hvg, xOff, y, scale, font, statusColor, vis);
     return;
     }
 
 struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
-if ((extras->isComparison) &&
-        (tg->visibility == tvFull || tg->visibility == tvPack))
+if (extras->isComparison && (tg->visibility == tvFull || tg->visibility == tvPack))
         //&& gtexGraphHeight() != MIN_GRAPH_HEIGHT)
-    {
     // compute medians based on configuration (comparisons, and later, filters)
     loadComputedMedians(geneInfo, extras);
-    }
 int heightPer = tg->heightPer;
 
 int graphX = gtexGraphX(geneBed);
 if (graphX < 0)
     return;
 
 // yZero is at bottom of graph
 int yZero = gtexGraphHeight() + y - 1;
 
 // draw faint line under graph to delineate extent when bars are missing (tissue w/ 0 expression)
 // TODO: skip missing bars -- then we can lose the gray line (at least for non-comparison mode)
 
 //uglyf("DRAW: xOff=%d, x1=%d, y=%d, yZero=%d<br>", xOff, x1, y, yZero);
 
 #ifndef MULTI_REGION
@@ -478,47 +481,56 @@
 Color labelColor = MG_GRAY;
 
 // TODO: generalize
 if (geneInfo->medians2)
     {
     // add labels to comparison graphs
     //FIXME: compute these
     int charHeight = 5;
     int labelWidth = 5;
     hvGfxText(hvg, x1, yZero-charHeight, labelColor, font, "F");
     hvGfxText(hvg, x1, yZero + gtexGeneHeight() + gtexGeneMargin(), labelColor, font, "M");
     startX = startX + labelWidth + 2;
     x1 = startX;
     }
 
+/* TODO:  Remove DEBUG code here */
+struct gtexTissue *tissues = getTissues();
+struct gtexTissue *tissue = tissues;
+/* DEBUG */
+
 for (i=0; i<expCount; i++)
     {
     struct rgbColor fillColor = extras->colors[i];
     if (barWidth == 1 && sameString(colorScheme, GTEX_COLORS_GTEX))
         {
         // brighten colors a bit so they'll be more visible at this scale
         fillColor = gtexTissueBrightenColor(fillColor);
         }
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
 
     double expScore = (geneInfo->medians1 ? geneInfo->medians1[i] : geneBed->expScores[i]);
     //double expScore = geneBed->expScores[i];
     /*
     if (expScore < 1)
         expScore = 0.0;
         */
-    int height = valToHeight(expScore, maxMedian, gtexGraphHeight());
+    // DEBUG code here
+    //uglyf("%s: score=%.2f<br>", tissue->description, expScore);
+    tissue = tissue->next;
+    // END DEBUG
+    int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform);
     // TODO: adjust yGene to get gene track distance as desired
     //if (i ==0) uglyf("DRAW: expScore=%.2f, maxMedian=%.2f, graphHeight=%d, y=%d<br>", expScore, maxMedian, gtexGraphHeight(), y);
     //if (i ==0) uglyf("DRAW: yZero=%d, yMedian=%d, height=%d<br>", yZero, yMedian, height);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero-height, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero-height, barWidth, height, fillColorIx, lineColorIx);
     x1 = x1 + barWidth + graphPadding;
     }
 #endif
 
 // mark gene extent
 int yGene = yZero + gtexGeneMargin() - 1;
 
 // draw gene model
@@ -540,31 +552,31 @@
 for (i=0; i<expCount; i++)
     {
     struct rgbColor fillColor = extras->colors[i];
     if (barWidth == 1 && sameString(colorScheme, GTEX_COLORS_GTEX))
         {
         // brighten colors a bit so they'll be more visible at this scale
         struct hslColor hsl = mgRgbToHsl(fillColor);
         hsl.s = min(1000, hsl.s + 300);
         fillColor = mgHslToRgb(hsl);
         }
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
     //double expScore = geneBed->expScores[i];
     double expScore = geneInfo->medians2[i];
     //if (expScore < 1)
         //expScore = 0.0;
-    int height = valToHeight(expScore, maxMedian, gtexGraphHeight());
+    int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform);
     // TODO: adjust yGene instead of yMedian+1 to get gene track distance as desired
     //if (i ==0) uglyf("DRAW2: expScore=%.2f, maxMedian=%.2f, graphHeight=%d, y=%d<br>", expScore, maxMedian, gtexGraphHeight(), y);
     //if (i ==0) uglyf("DRAW2: yZero=%d, height=%d<br>", yZero, height);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero, barWidth, height, fillColorIx, lineColorIx);
     x1 = x1 + barWidth + graphPadding;
     }
 #endif
 }
 
 #ifdef MULTI_REGION
 static int gtexGeneNonPropPixelWidth(struct track *tg, void *item)
 /* Return end chromosome coordinate of item, including graph */
@@ -579,37 +591,35 @@
 static void gtexGeneNonPropDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y,
                 double scale, MgFont *font, Color color, enum trackVisibility vis)
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 
 // Color in dense mode using transcriptClass
 // GALT REMOVE Color statusColor = getTranscriptStatusColor(hvg, geneBed);
 if (vis != tvFull && vis != tvPack)
     {
     //GALT bedDrawSimpleAt(tg, geneBed, hvg, xOff, y, scale, font, statusColor, vis);
     return;
     }
 
 struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
-if ((extras->isComparison) &&
-        (tg->visibility == tvFull || tg->visibility == tvPack))
+if (extras->isComparison && (tg->visibility == tvFull || tg->visibility == tvPack))
         //&& gtexGraphHeight() != MIN_GRAPH_HEIGHT)
-    {
     // compute medians based on configuration (comparisons, and later, filters)
     loadComputedMedians(geneInfo, extras);
-    }
+
 int i;
 int expCount = geneBed->expCount;
 double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian;
 struct rgbColor lineColor = {.r=0};
 int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b);
 // GALT REMOVE int heightPer = tg->heightPer;
 
 int graphX = gtexGraphX(geneBed);
 if (graphX < 0)
     return;
 // x1 is at left of graph
 int x1 = xOff + graphX;
 int startX = x1;
 
 // yZero is at bottom of graph
@@ -649,31 +659,31 @@
     {
     struct rgbColor fillColor = extras->colors[i];
     if (barWidth == 1 && sameString(colorScheme, GTEX_COLORS_GTEX))
         {
         // brighten colors a bit so they'll be more visible at this scale
         fillColor = gtexTissueBrightenColor(fillColor);
         }
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
 
     double expScore = (geneInfo->medians1 ? geneInfo->medians1[i] : geneBed->expScores[i]);
     //double expScore = geneBed->expScores[i];
     /*
     if (expScore < 1)
         expScore = 0.0;
         */
-    int height = valToHeight(expScore, maxMedian, gtexGraphHeight());
+    int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform);
     // TODO: adjust yGene to get gene track distance as desired
     //if (i ==0) uglyf("DRAW: expScore=%.2f, maxMedian=%.2f, graphHeight=%d, y=%d<br>", expScore, maxMedian, gtexGraphHeight(), y);
     //if (i ==0) uglyf("DRAW: yZero=%d, yMedian=%d, height=%d<br>", yZero, yMedian, height);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero-height, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero-height, barWidth, height, fillColorIx, lineColorIx);
     x1 = x1 + barWidth + graphPadding;
     }
 
 // mark gene extent
 int yGene = yZero + gtexGeneMargin() - 1;
 
 /* GALT NOT DONE HERE NOW
 // draw gene model
@@ -695,31 +705,31 @@
 for (i=0; i<expCount; i++)
     {
     struct rgbColor fillColor = extras->colors[i];
     if (barWidth == 1 && sameString(colorScheme, GTEX_COLORS_GTEX))
         {
         // brighten colors a bit so they'll be more visible at this scale
         struct hslColor hsl = mgRgbToHsl(fillColor);
         hsl.s = min(1000, hsl.s + 300);
         fillColor = mgHslToRgb(hsl);
         }
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
     //double expScore = geneBed->expScores[i];
     double expScore = geneInfo->medians2[i];
     //if (expScore < 1)
         //expScore = 0.0;
-    int height = valToHeight(expScore, maxMedian, gtexGraphHeight());
+    int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform);
     // TODO: adjust yGene instead of yMedian+1 to get gene track distance as desired
     //if (i ==0) uglyf("DRAW2: expScore=%.2f, maxMedian=%.2f, graphHeight=%d, y=%d<br>", expScore, maxMedian, gtexGraphHeight(), y);
     //if (i ==0) uglyf("DRAW2: yZero=%d, height=%d<br>", yZero, height);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero, barWidth, height, fillColorIx);
     else
         hvGfxOutlinedBox(hvg, x1, yZero, barWidth, height, fillColorIx, lineColorIx);
     x1 = x1 + barWidth + graphPadding;
     }
 
 }
 #endif