src/hg/instinct/hgGeneset/drawingCode.c 1.1
1.1 2010/01/21 23:51:13 jsanborn
added initial drawing code
Index: src/hg/instinct/hgGeneset/drawingCode.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgGeneset/drawingCode.c,v
retrieving revision 1.2
retrieving revision 1.1
diff -b -B -U 4 -r1.2 -r1.1
--- src/hg/instinct/hgGeneset/drawingCode.c 22 Jan 2010 05:11:28 -0000 1.2
+++ src/hg/instinct/hgGeneset/drawingCode.c 21 Jan 2010 23:51:13 -0000 1.1
@@ -108,25 +108,28 @@
int i = -1, j = -1;
int prevSampleId = -1;
int prevFeatureId = -1;
char id[128];
-char pixelStr[128];
-struct hmPixel *hm, *hmList = NULL;
-struct hashEl *el;
-struct hash *pixelHash = hashNew(0);
-
-int w = round(settings->x_scale);
-if (w < 1)
- w = 1;
-int h = round(settings->y_scale);
-if (h < 1)
- h = 1;
struct rawData *rd;
for (rd = rdList; rd; rd = rd->next)
{
val = rd->val;
+ 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];
+
// Attempt to reduce number of hash calls by checking if we *just* searched
// for sample or feature id.
if (rd->feature_id != prevFeatureId)
{
@@ -144,51 +147,12 @@
if (i < 0 || j < 0)
continue;
- int x1 = round((double) i * settings->x_scale);
- int y1 = round((double) j * settings->y_scale);
- int x2 = round((double) (i + 1) * settings->x_scale);
- int y2 = round((double) (j + 1) * settings->y_scale);
-
- safef(pixelStr, sizeof(pixelStr), "%d,%d", x1, y1);
- if ((el = hashLookup(pixelHash, pixelStr)) == NULL)
- {
- hm = AllocA(struct hmPixel);
- hm->x = x1;
- hm->y = y1;
- hm->w = ((x2 - x1) > 0) ? (x2 - x1) : 1;
- hm->h = ((y2 - y1) > 0) ? (y2 - y1) : 1;
- hm->val = 0.0;
- hm->count = 0;
- slAddHead(&hmList, hm);
- hashAdd(pixelHash, pixelStr, hm);
- }
- else
- hm = el->val;
-
- hm->val += val;
- hm->count += 1.0;
- }
-
-for (hm = hmList; hm ; hm = hm->next)
- {
- val = hm->val / (double) 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 x = i * settings->x_scale;
+ int y = j * settings->y_scale;
- vgBox(vg, hm->x, hm->y, hm->w, hm->h, valCol);
+ vgBox(vg, x, y, settings->x_scale, settings->y_scale, valCol);
}
vgUnclip(vg);
}
@@ -225,21 +189,21 @@
settings->missing = missing;
}
struct mapSettings *initMapSettings(struct slName *samples, struct slName *features,
- int width, int height)
+ int x_scale, int y_scale)
{
if (!samples || !features)
return NULL;
struct mapSettings *settings = AllocA(struct mapSettings);
-settings->width = width;
-settings->height = height;
+settings->x_scale = x_scale;
+settings->y_scale = y_scale;
mapSettingsDefaultColor(settings);
settings->max_deviation = DEFAULT_MAX_DEVIATION;
-settings->gain = 1.0;
+settings->gain = 10.0;
settings->x_index = hashNew(0);
settings->y_index = hashNew(0);
@@ -262,10 +226,10 @@
hashAddInt(settings->y_index, sl->name, numSamples);
numSamples += 1;
}
-settings->x_scale = (double) width / (double) numFeatures;
-settings->y_scale = (double) height / (double) numSamples;
+settings->width = numFeatures * settings->x_scale;
+settings->height = numSamples * settings->y_scale;
return settings;
}
@@ -280,10 +244,10 @@
return NULL;
struct hvGfx *vg;
struct tempName md5Tn;
-char *strToHash = cartSettingsString(hghPrefix, "heatmapGif");
-trashDirMD5File(&md5Tn, "hgg", ".gif", strToHash);
+char *strToHash = cartSettingsString(hgh3Prefix, "heatmapGif");
+trashDirMD5File(&md5Tn, "hgh3", ".gif", strToHash);
off_t size = fileSize(md5Tn.forCgi);
if (!fileExists(md5Tn.forCgi) || (size == 0) || DEBUG)
{