src/hg/instinct/hgGeneset/hgGenesets.c 1.11
1.11 2010/01/29 23:47:20 jsanborn
updated json return
Index: src/hg/instinct/hgGeneset/hgGenesets.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgGeneset/hgGenesets.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -b -B -U 4 -r1.10 -r1.11
--- src/hg/instinct/hgGeneset/hgGenesets.c 29 Jan 2010 22:27:36 -0000 1.10
+++ src/hg/instinct/hgGeneset/hgGenesets.c 29 Jan 2010 23:47:20 -0000 1.11
@@ -894,9 +894,90 @@
}
}
+void jsonSettings(struct json *js, struct mapSettings *settings)
+{
+struct json *c, *map = jsonAddContainer(js, "imageMap");
+
+/* Main heatmap */
+c = jsonAddContainer(map, "main");
+jsonAddInt(c, "x", settings->hm_x);
+jsonAddInt(c, "y", settings->hm_y);
+jsonAddInt(c, "width", settings->hm_width);
+jsonAddInt(c, "height", settings->hm_height);
+
+/* Thumbnail */
+c = jsonAddContainer(map, "thumbnail");
+jsonAddInt(c, "x", 0);
+jsonAddInt(c, "y", 0);
+jsonAddInt(c, "width", settings->hm_x);
+jsonAddInt(c, "height", settings->hm_y);
+
+/* Sample Label */
+c = jsonAddContainer(map, "sampleLabels");
+jsonAddInt(c, "x", settings->hm_x);
+jsonAddInt(c, "y", 0);
+jsonAddInt(c, "width", settings->hm_width);
+jsonAddInt(c, "height", settings->hm_y);
+
+
+/* Feature Label */
+c = jsonAddContainer(map, "featureLabels");
+jsonAddInt(c, "x", 0);
+jsonAddInt(c, "y", settings->hm_y);
+jsonAddInt(c, "width", settings->hm_x);
+jsonAddInt(c, "height", settings->hm_height);
+
+
+
+struct json *new, *list = jsonAddContainerList(js, "samples");
+new = list;
+
+struct hashEl *el;
+struct hashCookie cookie = hashFirst(settings->sampleHash);
+while ((el = hashNext(&cookie)) != NULL)
+ {
+ if (!new)
+ new = jsonAddContainerToList(&list);
+
+ char *name = el->val;
+ int i = hashIntValDefault(settings->x_index, el->name, -1);
+ if (i < 0)
+ continue;
+ int start = ceil(((double) i) * settings->hm_x_scale) + settings->hm_x;
+ int stop = ceil(((double) i + 1) * settings->hm_x_scale) + settings->hm_x;
+
+ jsonAddString(new, "name", name);
+ jsonAddInt(new, "start", start);
+ jsonAddInt(new, "stop", stop);
+
+ new = NULL;
+ }
+list = jsonAddContainerList(js, "features");
+new = list;
+
+cookie = hashFirst(settings->featureHash);
+while ((el = hashNext(&cookie)) != NULL)
+ {
+ if (!new)
+ new = jsonAddContainerToList(&list);
+
+ char *name = el->val;
+ int i = hashIntValDefault(settings->y_index, el->name, -1);
+ if (i < 0)
+ continue;
+ int start = round(((double) i) * settings->hm_y_scale) + settings->hm_y;
+ int stop = round(((double) i + 1) * settings->hm_y_scale) + settings->hm_y;
+
+ jsonAddString(new, "name", name);
+ jsonAddInt(new, "start", start);
+ jsonAddInt(new, "stop", stop);
+
+ new = NULL;
+ }
+}
void drawHeatmap()
{
struct sqlConnection *conn = hAllocConnProfile(localDb, db);
@@ -951,10 +1032,13 @@
if (metric && method)
clusterRawData(rdList, settings, metric, method);
char *filename = heatmapGif(conn, rdList, settings);
+
struct json *js = newJson();
jsonAddString(js, "image", filename);
+
+jsonSettings(js, settings);
if (js)
hPrintf("%s\n", js->print(js));
}