ab076cf0a98938e33c5e76b251f8ed1110c4923c kate Thu Oct 22 16:51:00 2015 -0700 Improve display for non-log transformed by adding max view limit. refs #15645 diff --git src/hg/hgTracks/gtexTracks.c src/hg/hgTracks/gtexTracks.c index 02fe007..d481cc7 100644 --- src/hg/hgTracks/gtexTracks.c +++ src/hg/hgTracks/gtexTracks.c @@ -2,31 +2,32 @@ /* Copyright (C) 2015 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "hgTracks.h" #include "hvGfx.h" #include "rainbow.h" #include "gtexInfo.h" #include "gtexGeneBed.h" #include "gtexTissue.h" #include "gtexTissueData.h" #include "gtexUi.h" // NOTE: Sections to change for multi-region (vertical slice) display -// are marked with #ifdef MULTI_REGION +// are marked with #ifdef MULTI_REGION. WARNING: These sections +// are a bit out-of-date (refer to #ifndef MULTI code when integrating) struct gtexGeneExtras /* Track info */ { double maxMedian; /* Maximum median rpkm for all tissues */ boolean isComparison; /* Comparison of two sample sets (e.g. male/female). Displayed as two graphs, one oriented downward */ char *graphType; /* Additional info about graph (e.g. type of comparison graph */ struct rgbColor *colors; /* Color palette for tissues */ }; struct gtexGeneInfo /* GTEx gene model, names, and expression medians */ { struct gtexGeneInfo *next; /* Next in singly linked list */ @@ -345,39 +346,32 @@ 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; int labelWidth = geneInfo->medians2 ? tl.mWidth : 0; return (barWidth * count) + (padding * (count-1)) + labelWidth + 2; } static int gtexGraphX(struct gtexGeneBed *gtex) /* Locate graph on X, relative to viewport. Return -1 if it won't fit */ { int start = max(gtex->chromStart, winStart); -//int end = min(gtex->chromEnd, winEnd); -//if (start > end) - //return -1; double scale = scaleForWindow(insideWidth, winStart, winEnd); int x1 = round((start - winStart) * scale); -//int x2 = round((end - winStart) * scale); -//int width = gtexGraphWidth(gtex); -//if (x1 + width > x2) - //return -1; return x1; } static int gtexGeneHeight() { return 8; } static int gtexGeneMargin() { return 1; } 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 */ @@ -420,109 +414,134 @@ } struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData; 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; int yZero = gtexGraphHeight() + y-1; // yZero is bottom of graph #ifndef MULTI_REGION int x1 = xOff + graphX; // x1 is at left of graph - -int keepX = x1; +int keepX = x1; // FIXME: Too many X's! drawGraphBase(hvg, keepX, yZero+1, geneInfo); int startX = x1; 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); int barWidth = gtexBarWidth(); int graphPadding = gtexGraphPadding(); char *colorScheme = cartUsualStringClosestToHome(cart, tg->tdb, FALSE, GTEX_COLORS, GTEX_COLORS_DEFAULT); Color labelColor = MG_GRAY; +Color clipColor = MG_MAGENTA; + +double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, GTEX_MAX_LIMIT, GTEX_MAX_LIMIT_DEFAULT); // add labels to comparison graphs // TODO: generalize if (geneInfo->medians2) { hvGfxText(hvg, x1, yZero - tl.fontHeight, labelColor, font, "F"); hvGfxText(hvg, x1, yZero + gtexGeneHeight() + gtexGeneMargin(), labelColor, font, "M"); startX = startX + tl.mWidth+2; x1 = startX; } + +// draw bar graph +// TODO: share this code with other graph 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]); - int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform); + double useScore = expScore; + double useMax = maxMedian; + if (!doLogTransform) + { + useMax = viewMax; + if (expScore > viewMax) + useScore = viewMax; + } + int height = valToHeight(useScore, useMax, gtexGraphHeight(), doLogTransform); if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX)) hvGfxBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx); else hvGfxOutlinedBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx, lineColorIx); + if (useScore != expScore) + hvGfxBox(hvg, x1, yZero-height+1, barWidth, 1, clipColor); x1 = x1 + barWidth + graphPadding; } #endif // draw gene model int yGene = yZero + gtexGeneMargin()-1; tg->heightPer = gtexGeneHeight()+1; struct linkedFeatures *lf = linkedFeaturesFromGenePred(tg, geneInfo->geneModel, FALSE); lf->filterColor = statusColor; linkedFeaturesDrawAt(tg, lf, hvg, xOff, yGene, scale, font, color, tvSquish); tg->heightPer = heightPer; if (!geneInfo->medians2) return; #ifndef MULTI_REGION -// draw comparison graph (upside down) +// draw comparison bar graph (upside down) x1 = startX; yZero = yGene + gtexGeneHeight() + 1; // yZero is at top of graph drawGraphBase(hvg, keepX, yZero-1, geneInfo); 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 = geneInfo->medians2[i]; - int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform); + double useScore = expScore; + double useMax = maxMedian; + if (!doLogTransform) + { + useMax = viewMax; + if (expScore > viewMax) + useScore = viewMax; + } + int height = valToHeight(useScore, useMax, gtexGraphHeight(), 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); + if (useScore != expScore) + hvGfxBox(hvg, x1, yZero + height, barWidth, 1, clipColor); x1 = x1 + barWidth + graphPadding; } #endif } #ifdef MULTI_REGION static int gtexGeneNonPropPixelWidth(struct track *tg, void *item) /* Return end chromosome coordinate of item, including graph */ { struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item; int graphWidth = gtexGraphWidth(geneInfo); return graphWidth; } #endif @@ -663,74 +682,73 @@ if (geneInfo->medians2) { // skip over labels in comparison graphs x1 = x1 + tl.mWidth+ 2; } int i = 0; int yZero = gtexGraphHeight() + y - 1; boolean doLogTransform = cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, GTEX_LOG_TRANSFORM, GTEX_LOG_TRANSFORM_DEFAULT); for (tissue = tissues; tissue != NULL; tissue = tissue->next, i++) { double expScore = geneBed->expScores[i]; int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform); int yMedian = yZero - height; +// FIXME: need proper scaling for clipped (non-log) display mapBoxHc(hvg, start, end, x1, yMedian+1, barWidth, height, tg->track, mapItemName, tissue->description); // add map box to comparison graph if (geneInfo->medians2) { double expScore = geneInfo->medians2[i]; int height = valToHeight(expScore, maxMedian, gtexGraphHeight(), doLogTransform); int y = yZero + gtexGeneHeight() + gtexGeneMargin(); mapBoxHc(hvg, start, end, x1, y, barWidth, height, tg->track, mapItemName, tissue->description); } x1 = x1 + barWidth + padding; } } 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 gtexGeneItemHeight(struct track *tg, void *item) { if ((item == NULL) || (tg->visibility == tvSquish) || (tg->visibility == tvDense)) return 0; int extra = 0; if (((struct gtexGeneExtras *)tg->extraUiData)->isComparison) extra = gtexGraphHeight() + 2; -//uglyf("GTEX itemHeight extra = %d<br>", extra); return gtexGraphHeight() + gtexGeneMargin() + gtexGeneHeight() + extra; } static int gtexTotalHeight(struct track *tg, enum trackVisibility vis) /* Figure out total height of track */ { int height; int extra = 0; if (((struct gtexGeneExtras *)tg->extraUiData)->isComparison) extra = gtexGraphHeight() + 2; if (tg->visibility == tvSquish || tg->visibility == tvDense) height = 10; else height = gtexGraphHeight() + gtexGeneMargin() + gtexGeneHeight() + extra; -//uglyf("GTEX totalHeight = %d<br>", height); return tgFixedTotalHeightOptionalOverflow(tg, vis, height, height, FALSE); } static int gtexGeneItemStart(struct track *tg, void *item) /* Return end chromosome coordinate of item, including graph */ { struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item; struct gtexGeneBed *geneBed = geneInfo->geneBed; return geneBed->chromStart; } static int gtexGeneItemEnd(struct track *tg, void *item) /* Return end chromosome coordinate of item, including graph */ { struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;