src/hg/instinct/hgHeatmap2/drawingCode.c 1.79
1.79 2010/03/17 01:29:36 jsanborn
added proportions summary view
Index: src/hg/instinct/hgHeatmap2/drawingCode.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgHeatmap2/drawingCode.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -b -B -U 4 -r1.78 -r1.79
--- src/hg/instinct/hgHeatmap2/drawingCode.c 10 Mar 2010 22:55:39 -0000 1.78
+++ src/hg/instinct/hgHeatmap2/drawingCode.c 17 Mar 2010 01:29:36 -0000 1.79
@@ -1,9 +1,9 @@
/********************************************************************************/
/* Copyright 2007-2009 -- The Regents of the University of California */
/********************************************************************************/
-/* mainPage - drs the main hgHeatmap page, including some controls
+/* mainPage - draws the main hgHeatmap page, including some controls
* on the top and the graphic. */
#define EXPR_DATA_SHADES 16
#define DEFAULT_MAX_DEVIATION 0.7
@@ -2036,8 +2036,68 @@
}
vgUnclip(vg);
}
+void drawProportionsPlot(struct vGfx *vg, struct heatmapLay *hl, struct genoHeatmap *gh,
+ struct hmPixel *hmList, int width, int height)
+{
+double val, absVal;
+struct hmPixel *hm;
+float gain = gh->gainFull;
+double md = maxDeviation(gh->name);
+double colorScale = COLOR_SCALE / md;
+
+Color valCol;
+Color upShades[EXPR_DATA_SHADES];
+Color downShades[EXPR_DATA_SHADES];
+
+// default, expression data color scheme:
+vgMakeColorGradient(vg, hl->zeroColor, hl->highColor, EXPR_DATA_SHADES, upShades);
+vgMakeColorGradient(vg, hl->zeroColor, hl->lowColor, EXPR_DATA_SHADES, downShades);
+
+vgSetClip(vg, 0, 0, width, height);
+for (hm = hmList; hm ; hm = hm->next)
+ {
+ if (!hm->valList)
+ continue;
+
+ float i = 0.0;
+ float numSamples = (float) slCount(hm->valList);
+ struct slDouble *sd;
+ slSort(&hm->valList, slDoubleCmp);
+ for (sd = hm->valList; sd ; sd = sd->next)
+ {
+ val = sd->val; // / hm->count;
+
+ absVal = fabs(val) * gain;
+
+ int colorIndex = (int)(absVal * (EXPR_DATA_SHADES-1.0) * colorScale);
+
+ /* Clip color index to fit inside of array, since we may have brightened it. */
+ if (colorIndex < 0) colorIndex = 0;
+ if (colorIndex >= EXPR_DATA_SHADES)
+ colorIndex = EXPR_DATA_SHADES-1;
+
+ if(val > 0)
+ valCol = upShades[colorIndex];
+ else
+ valCol = downShades[colorIndex];
+
+ int y = floor(i / numSamples * height);
+ if (y > height)
+ y = height;
+ int h = ceil(1.0 / numSamples * height);
+ if (h < 1)
+ h = 1;
+ /* Draw probe data */
+ vgBox(vg, hm->x, y, hm->w, h, valCol);
+
+ i += 1.0;
+ }
+ }
+vgUnclip(vg);
+}
+
void drawGenesetAverageLine(struct vGfx *vg, struct hmPixel *hmList,
double absMax, int height)
/* Draws a bargraph, specific for SNP data (for now) */
@@ -2263,9 +2323,10 @@
drawGenesetAverageLine(vg, hmGsList, hlList->maxVal, height);
}
void drawGeneSetGenomicSummary(struct vGfx *vg, struct genoHeatmap *gh,
- struct heatmapLay *hlList, struct slName *sampleList, int height)
+ struct heatmapLay *hlList, struct slName *sampleList,
+ char *summaryType, int height)
/* Draw chromosome graph on all chromosomes in layout at given
* y offset and height. */
{
if (!hlList)
@@ -2295,8 +2356,9 @@
slAddHead(&siList, si);
}
slReverse(&siList);
+int numSamples = slCount(siList);
int maxX = 0;
struct heatmapLay *hl;
for (hl = hlList; hl ; hl = hl->next)
@@ -2322,9 +2384,9 @@
if (!pixelEl)
{
hm = AllocA(struct hmPixel);
hm->x = x;
- hm->y = 0;
+ hm->y = numSamples;
hm->w = w;
hm->h = 0;
hm->val = 0.0;
hm->valList = NULL;
@@ -2345,13 +2407,17 @@
}
}
}
-drawTukeyBoxPlot(vg, hlList, gh, hmList, maxX, height);
+if (summaryType && sameString(summaryType, "proportions"))
+ drawProportionsPlot(vg, hlList, gh, hmList, maxX, height);
+else
+ drawTukeyBoxPlot(vg, hlList, gh, hmList, maxX, height);
}
void drawGeneSetSummary(struct vGfx *vg, char* database, char *chromHeatmap,
- struct heatmapLay *hlList, struct slName *sampleList, int height)
+ struct heatmapLay *hlList, struct slName *sampleList,
+ char *summaryType, int height)
/* Draw chromosome graph on all chromosomes in layout at given
* y offset and height. */
{
if (!hlList)
@@ -2366,9 +2432,9 @@
if (sameString(gh->platform, "SNP"))
drawGeneSetSNPSummary(vg, gh, hlList, sampleList, height);
else
- drawGeneSetGenomicSummary(vg, gh, hlList, sampleList, height);
+ drawGeneSetGenomicSummary(vg, gh, hlList, sampleList, summaryType, height);
}
void drawBedGraph(struct vGfx *vg, char* database,
@@ -2578,9 +2644,9 @@
drawBarGraphPlot(vg, hl, gh, hmList, hl->width, height);
}
void drawChromGenomicSummary(struct vGfx *vg, struct genoHeatmap *gh, struct heatmapLay *hl,
- struct slName *sampleList, int height)
+ struct slName *sampleList, char *summaryType, int height)
/* Draw chromosome graph on all chromosomes in layout at given
* y offset and height. */
{
struct bed *ghBed=NULL, *nb=NULL;
@@ -2604,8 +2670,10 @@
slAddHead(&siList, si);
}
slReverse(&siList);
+int numSamples = slCount(siList);
+
boolean useAccessTable = TRUE;
if (singleChromImage(hl))
useAccessTable = FALSE;
@@ -2622,9 +2690,9 @@
/* Window overlaps a probe */
if (start < hEl->baseStart)
start = hEl->baseStart;
- if ( end > hEl->baseEnd)
+ if (end > hEl->baseEnd)
end = hEl->baseEnd;
int x = pixelsPerBase * (start - hEl->baseStart) + chromX;
int w = pixelsPerBase * (end - start);
@@ -2636,9 +2704,9 @@
if (!el)
{
hm = AllocA(struct hmPixel);
hm->x = x;
- hm->y = 0;
+ hm->y = numSamples;
hm->w = w;
hm->h = 0;
hm->val = 0.0;
hm->count = 0;
@@ -2659,14 +2727,17 @@
}
}
bedFreeList(&ghBed);
}
-
-drawTukeyBoxPlot(vg, hl, gh, hmList, hl->width, height);
+if (summaryType && sameString(summaryType, "proportions"))
+ drawProportionsPlot(vg, hl, gh, hmList, hl->width, height);
+else
+ drawTukeyBoxPlot(vg, hl, gh, hmList, hl->width, height);
}
void drawChromSummary(struct vGfx *vg, char* database, struct heatmapLay *hl,
- char *chromHeatmap, struct slName *sampleList, int height)
+ char *chromHeatmap, struct slName *sampleList,
+ char *summaryType, int height)
/* Draw chromosome graph on all chromosomes in layout at given
* y offset and height. */
{
if (!hl)
@@ -2681,9 +2752,9 @@
if (sameString(gh->platform, "SNP"))
drawChromSNPSummary(vg, gh, hl, sampleList, height);
else
- drawChromGenomicSummary(vg, gh, hl, sampleList, height);
+ drawChromGenomicSummary(vg, gh, hl, sampleList, summaryType, height);
}
void drawBackgroundLines(struct vGfx *vg, int startX, int startY, int width, int height)
{
@@ -2895,9 +2966,9 @@
}
char *genomeSummaryGif(struct sqlConnection *conn, struct heatmapLay *hl,
struct genoHeatmap *gh, struct slName *sampleList,
- int totalH, int subset, int subsetNum)
+ char *summaryType, int totalH, int subset, int subsetNum)
/* Create genome GIF file and HT that includes it. */
{
if (!gh || !hl)
return NULL;
@@ -2925,9 +2996,9 @@
{
vg = hvGfxOpenGif(totalW, totalH, md5Tn.forCgi, FALSE);
if (sameWord(gh->dataType,"bed 15"))
- drawChromSummary(vg->vg, db, hl, gh->name, sampleList, totalH);
+ drawChromSummary(vg->vg, db, hl, gh->name, sampleList, summaryType, totalH);
else if (sameWord(gh->dataType, "bed 4") || sameWord(gh->dataType, "bed 5"))
drawBedGraph(vg->vg, db, hl, gh->name);
hvGfxClose(&vg);
@@ -3055,9 +3126,9 @@
}
char *genesetSummaryGif(struct sqlConnection *conn, struct heatmapLay *hl,
struct genoHeatmap *gh, struct slName *sampleList,
- int totalH, int subset, int subsetNum)
+ char *summaryType, int totalH, int subset, int subsetNum)
/* Create genome GIF file and HT that includes it. */
{
if (!gh || !hl)
return NULL;
@@ -3084,9 +3155,10 @@
drawLayoutLines(vg->vg, hl, totalW);
if (sameWord(gh->dataType,"bed 15"))
- drawGeneSetSummary(vg->vg, gh->database, gh->name, hl, sampleList, totalH);
+ drawGeneSetSummary(vg->vg, gh->database, gh->name, hl, sampleList,
+ summaryType, totalH);
hvGfxClose(&vg);
}
char *filename = replaceChars(md5Tn.forHtml, "..", "");