e652094011770a202bcffd9c504b8b5e25bd59a4 kate Wed Oct 7 11:24:48 2015 -0700 1. Graph aesthetics (colors, etc.). 2. Change ordering to median descending. refs #15645 diff --git src/hg/hgc/gtexClick.c src/hg/hgc/gtexClick.c index 12a1109..1f0d8ec 100644 --- src/hg/hgc/gtexClick.c +++ src/hg/hgc/gtexClick.c @@ -10,31 +10,31 @@ #include "hgc.h" #include "rainbow.h" #include "hvGfx.h" #include "gtexUi.h" #include "gtexGeneBed.h" #include "gtexTissue.h" #include "gtexSampleData.h" /* Dimensions of image parts */ int pad = 2; int margin = 1; //int graphHeight = 400; int graphHeight = 325; //int barWidth = 3; -int barWidth = 9; +int barWidth = 12; /* Dimensions of image overall and our portion within it. */ int imageWidth, imageHeight, innerWidth, innerHeight, innerXoff, innerYoff; void setImageDims(int expCount) /* Set up image according to count */ { innerHeight = graphHeight + 2*pad; innerWidth = pad + expCount*(pad + barWidth); imageWidth = innerWidth + 2*margin; imageHeight = innerHeight + 2*margin; innerXoff = margin; innerYoff = margin; } @@ -76,36 +76,49 @@ int yMax = valToY(midClipMin, maxExp, height); for (i=0; i<size; ++i) { double exp = vals[i]; int y = valToY(exp, maxExp, height); if (y < yMin || y > yMax) { y += yOff; hvGfxDot(hvg, xOff-1, y, colorIx); hvGfxDot(hvg, xOff+1, y, colorIx); hvGfxDot(hvg, xOff, y-1, colorIx); hvGfxDot(hvg, xOff, y+1, colorIx); } } } -void drawBoxAndWhiskers(struct hvGfx *hvg, int fillColorIx, int lineColorIx, int x, int y, + +int cmpTissueSampleValsMedianScore(const void *va, const void *vb) +/* Compare RPKM scores */ +{ +const struct tissueSampleVals *a = *((struct tissueSampleVals **)va); +const struct tissueSampleVals *b = *((struct tissueSampleVals **)vb); +if (a->median == b->median) + return 0; +return (a->median > b->median ? 1: -1); +} + +void drawBoxAndWhiskers(struct hvGfx *hvg, int fillColorIx, int x, int y, struct tissueSampleVals *tsv, double maxExp) /* Draw a Tukey-type box plot. JK */ { -int medianColorIx = lineColorIx; -int whiskColorIx = lineColorIx; +struct rgbColor lineColor = {.r=128, .g=128, .b=128}; +int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b); +int medianColorIx = hvGfxFindColorIx(hvg,0,0,0); +int whiskColorIx = hvGfxFindColorIx(hvg,192,192,192); double xCen = x + barWidth/2; if (tsv->count > 1) { /* Cache a few fields from tsv in local variables */ double q1 = tsv->q1, q3 = tsv->q3, median = tsv->median; /* Figure out position of first quarter, median, and third quarter in screen Y coordinates */ int yQ1 = valToY(q1, maxExp, graphHeight) + y; int yQ3 = valToY(q3, maxExp, graphHeight) + y; int yMedian = valToY(median, maxExp, graphHeight); /* Draw a filled box that covers the middle two quarters */ int qHeight = yQ1 - yQ3 + 1; hvGfxOutlinedBox(hvg, x, yQ3, barWidth, qHeight, fillColorIx, lineColorIx); @@ -226,52 +239,50 @@ int count = tsv->count = slCount(tsv->valList); double *vals = AllocArray(tsv->vals, count); for (i=0; i<count; i++) { val = slPopHead(&tsv->valList); if (doLogTransform) vals[i] = log10(val->val+1.0); else vals[i] = val->val; } doubleBoxWhiskerCalc(tsv->count, tsv->vals, &tsv->min, &tsv->q1, &tsv->median, &tsv->q3, &tsv->max); slAddHead(&tsList, tsv); } -slReverse(&tsList); // Tissue list is now sorted by GTEx tissue ordering. // TODO: Option to sort by score descending. +slSort(&tsList, cmpTissueSampleValsMedianScore); +slReverse(&tsList); // Initialize graphics for Box-and-whiskers plot setImageDims(slCount(tsList)); struct tempName pngTn; trashDirFile(&pngTn, "hgc", "gtexGene", ".png"); //uglyf("Trash file: %s\n", pngTn.forCgi); struct hvGfx *hvg = hvGfxOpenPng(imageWidth, imageHeight, pngTn.forCgi, FALSE); //hvGfxSetClip(hvg, 0, 0, imageWidth, imageHeight); // needed ? -struct rgbColor lineColor = {.r=0}; -int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b); - int x=innerXoff + pad, y = innerYoff + pad; for (tsv = tsList; tsv != NULL; tsv = tsv->next) { struct rgbColor fillColor = rgbFromIntColor(tsv->color); int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b); - drawBoxAndWhiskers(hvg, fillColorIx, lineColorIx, x, y, tsv, maxVal); + drawBoxAndWhiskers(hvg, fillColorIx, x, y, tsv, maxVal); x += barWidth + pad; } //hvGfxUnclip(hvg); hvGfxClose(&hvg); printf("<IMG SRC = \"%s\" BORDER=1><BR>\n", pngTn.forHtml); /*printf("<IMG SRC = \"%s\" BORDER=1 WIDTH=%d HEIGHT=%d><BR>\n", pngTn.forHtml, imageWidth, imageHeight); */ //cloneString(gifTn.forHtml); // Track description printTrackHtml(tdb); // Print out tissue table with color assignments