753b4d5d57c43a7b33312ed2c4f88de877baea91 kate Thu Dec 17 14:16:23 2015 -0800 Make gene model more vivid (and useful) when it's not too busy (<500K window and single graph), by using pack instead of squish. refs #15645 diff --git src/hg/hgTracks/gtexTracks.c src/hg/hgTracks/gtexTracks.c index 667c78f..6e635f8 100644 --- src/hg/hgTracks/gtexTracks.c +++ src/hg/hgTracks/gtexTracks.c @@ -363,30 +363,47 @@ #define MIN_GRAPH_PADDING 0 #define MARGIN_WIDTH 1 static int gtexBarWidth() { long winSize = virtWinBaseCount; if (winSize < WIN_MAX_GRAPH) return MAX_BAR_WIDTH; else if (winSize < WIN_MED_GRAPH) 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) + 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() { long winSize = virtWinBaseCount; @@ -405,35 +422,30 @@ int padding = gtexGraphPadding(); int count = filteredTissueCount(tg); 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. */ { int start = max(gtex->chromStart, winStart); double scale = scaleForWindow(insideWidth, winStart, winEnd); int x1 = round((start - winStart) * scale); return x1; } -static int gtexGeneModelHeight() -{ - 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 */ { if (val == 0.0) return 0; double scaled = 0.0; if (doLogTransform) scaled = log10(val+1.0) / log10(maxVal+1.0); else scaled = val/maxVal; @@ -482,140 +494,143 @@ else expScore = geneInfo->medians2[i]; maxExp = max(maxExp, expScore); } double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, GTEX_MAX_LIMIT, GTEX_MAX_LIMIT_DEFAULT); double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian; return valToClippedHeight(maxExp, maxMedian, viewMax, gtexMaxGraphHeight(), extras->doLogTransform); } static void gtexGeneDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis) /* Draw tissue expression bar graph over gene model. Optionally, draw a second graph under gene, to compare sample sets */ { +struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData; struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item; struct gtexGeneBed *geneBed = geneInfo->geneBed; // 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; } int heightPer = tg->heightPer; int graphX = gtexGraphX(geneBed); if (graphX < 0) return; // draw gene model int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, TRUE); topGraphHeight = max(topGraphHeight, tl.fontHeight); int yZero = topGraphHeight + y - 1; // yZero is bottom of graph int yGene = yZero + gtexGeneMargin() - 1; -tg->heightPer = gtexGeneModelHeight() + 1; +tg->heightPer = gtexGeneModelHeight(extras) + 1; if (geneInfo->geneModel) // some BEDs do not have a corresponding geneModel record { struct linkedFeatures *lf = linkedFeaturesFromGenePred(tg, geneInfo->geneModel, FALSE); lf->filterColor = statusColor; - linkedFeaturesDrawAt(tg, lf, hvg, xOff, yGene, scale, font, color, tvSquish); + linkedFeaturesDrawAt(tg, lf, hvg, xOff, yGene, scale, font, color, + gtexGeneModelVis(extras)); } tg->heightPer = heightPer; } 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(tg, geneInfo); return graphWidth; } 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 gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData; struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item; struct gtexGeneBed *geneBed = geneInfo->geneBed; int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, TRUE); topGraphHeight = max(topGraphHeight, tl.fontHeight); int yZero = topGraphHeight + y - 1; // yZero is bottom of graph int yGene = yZero + gtexGeneMargin()-1; int graphX = gtexGraphX(geneBed); int x1 = xOff + graphX; // x1 is at left of graph int keepX = x1; drawGraphBase(tg, geneInfo, hvg, keepX, yZero+1); int startX = x1; 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; // add labels to comparison graphs if (geneInfo->medians2) { hvGfxText(hvg, x1, yZero - tl.fontHeight + 1, labelColor, font, "F"); - hvGfxText(hvg, x1, yZero + gtexGeneModelHeight() + gtexGeneMargin() + 1, labelColor, font, "M"); + hvGfxText(hvg, x1, yZero + gtexGeneModelHeight(extras) + gtexGeneMargin() + 1, + labelColor, font, "M"); startX = startX + tl.mWidth+2; x1 = startX; } // draw bar graph double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, GTEX_MAX_LIMIT, GTEX_MAX_LIMIT_DEFAULT); double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian; int i; int expCount = geneBed->expCount; -struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData; struct gtexTissue *tis; for (i=0, tis=extras->tissues; i<expCount; i++, tis=tis->next) { if (!filterTissue(tg, tis->name)) continue; 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 = valToClippedHeight(expScore, maxMedian, viewMax, gtexMaxGraphHeight(), extras->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); // mark clipped bar with magenta tip if (!extras->doLogTransform && expScore > viewMax) hvGfxBox(hvg, x1, yZero-height+1, barWidth, 1, clipColor); x1 = x1 + barWidth + graphPadding; } if (!geneInfo->medians2) return; // draw comparison bar graph (upside down) x1 = startX; -yZero = yGene + gtexGeneModelHeight() + 1; // yZero is at top of graph +yZero = yGene + gtexGeneModelHeight(extras) + 1; // yZero is at top of graph drawGraphBase(tg, geneInfo, hvg, keepX, yZero-1); for (i=0, tis=extras->tissues; i<expCount; i++, tis=tis->next) { if (!filterTissue(tg, tis->name)) continue; 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); @@ -624,53 +639,55 @@ 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); 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) return 0; +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() + extra; + 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); topGraphHeight = max(topGraphHeight, tl.fontHeight); int bottomGraphHeight = 0; boolean isComparison = ((struct gtexGeneExtras *)tg->extraUiData)->isComparison; if (isComparison) { bottomGraphHeight = max(gtexGeneGraphHeight(tg, geneInfo, FALSE), tl.fontHeight) + gtexGeneMargin(); } -int height = topGraphHeight + bottomGraphHeight + gtexGeneMargin() + gtexGeneModelHeight(); +int height = topGraphHeight + bottomGraphHeight + gtexGeneMargin() + + gtexGeneModelHeight(extras); return height; } static int gtexGeneMaxHeight(struct track *tg) /* Maximum height in pixels of a gene graph */ { return gtexGeneItemHeightOptionalMax(tg, NULL, TRUE); } static int gtexGeneItemHeight(struct track *tg, void *item) { return gtexGeneItemHeightOptionalMax(tg, item, FALSE); } static char *tissueExpressionText(struct gtexTissue *tissue, double expScore, @@ -706,31 +723,31 @@ int yGene = yZero + gtexGeneMargin() - 1; if (!geneInfo->geneModel) return; int geneStart = max(geneInfo->geneModel->txStart, winStart); int geneEnd = min(geneInfo->geneModel->txEnd, winEnd); double scale = scaleForWindow(insideWidth, winStart, winEnd); int x1 = round((double)((int)geneStart-winStart)*scale) + x; int x2 = round((double)((int)geneEnd-winStart)*scale) + x; int w = x2-x1; char query[256]; sqlSafef(query, sizeof(query), "select kgXref.description from kgXref, knownToEnsembl where knownToEnsembl.value='%s' and knownToEnsembl.name=kgXref.kgID", geneBed->transcriptId); struct sqlConnection *conn = hAllocConn(database); char *desc = sqlQuickString(conn, query); hFreeConn(&conn); -mapBoxHc(hvg, start, end, x, yGene, w, gtexGeneModelHeight()-1, tg->track, mapItemName, desc); +mapBoxHc(hvg, start, end, x, yGene, w, gtexGeneModelHeight(extras)-1, tg->track, mapItemName, desc); // add maps to tissue bars in expresion graph struct gtexTissue *tissues = getTissues(); struct gtexTissue *tissue = NULL; int barWidth = gtexBarWidth(); int padding = gtexGraphPadding(); double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian; int graphX = gtexGraphX(geneBed); if (graphX < 0) return; // x1 is at left of graph x1 = insideX + graphX; @@ -749,31 +766,31 @@ continue; double expScore = (geneInfo->medians1 ? geneInfo->medians1[i] : geneBed->expScores[i]); int height = valToClippedHeight(expScore, maxMedian, viewMax, gtexMaxGraphHeight(), extras->doLogTransform); char *qualifier = NULL; if (extras->isComparison && extras->isDifference) qualifier = "F-M"; mapBoxHc(hvg, start, end, x1, yZero-height, barWidth, height, tg->track, mapItemName, tissueExpressionText(tissue, expScore, extras->doLogTransform, qualifier)); // add map box to comparison graph if (geneInfo->medians2) { double expScore = geneInfo->medians2[i]; int height = valToClippedHeight(expScore, maxMedian, viewMax, gtexMaxGraphHeight(), extras->doLogTransform); - int y = yZero + gtexGeneModelHeight() + gtexGeneMargin(); // y is top of bottom graph + 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; } } 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;