src/hg/instinct/hgBamBam/hgBamBam.c 1.3

1.3 2010/05/26 08:02:55 jsanborn
updated
Index: src/hg/instinct/hgBamBam/hgBamBam.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgBamBam/hgBamBam.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 4 -r1.2 -r1.3
--- src/hg/instinct/hgBamBam/hgBamBam.c	26 May 2010 05:20:33 -0000	1.2
+++ src/hg/instinct/hgBamBam/hgBamBam.c	26 May 2010 08:02:55 -0000	1.3
@@ -235,14 +235,60 @@
 
 jsonAddString(js, "scale", filename);
 }
 
+char *getPosition(struct genoLayChrom *glList)
+{
+char *pos = cartUsualString(cart, bbPos, NULL);
+
+if (!pos)
+    return NULL;
+
+char *chrom;
+int start = -1, stop = -1;
+if (!hgParseChromRange(NULL, pos, &chrom, &start, &stop))
+    return NULL;
+
+struct genoLayChrom *gl;
+for (gl = glList; gl; gl = gl->next)
+    {
+    if (!sameString(gl->fullName, chrom))
+	continue;
+    break;
+    }
+if (!gl)
+    return NULL;
+
+if (start <= 0 && stop <= 0)
+    {
+    start = 1;
+    stop  = gl->size - 1;
+    }
+
+if (start <= 0)
+    start = 1;
+else if (start > gl->size - 1)
+    start = gl->size - 1;
+
+if (stop <= 0)
+    stop = 1;
+else if (stop > gl->size - 1)
+    stop = gl->size - 1;
+
+char newPos[256];
+safef(newPos, sizeof(newPos), "%s:%d-%d", chrom, start, stop);
+
+return cloneString(newPos);
+}
 
 void draw()
 {
 struct sqlConnection *conn = hAllocConnProfile(localDb, db);
 
-char *pos = cartUsualString(cart, bbPos, NULL);
+struct genoLayChrom *glList = genoLayDbChroms(conn, FALSE);
+
+char *pos = getPosition(glList);
+
 int width  = cartUsualInt(cart, bbWidth, DEFAULT_PLOT_WIDTH);
 int height = cartUsualInt(cart, bbHeight, DEFAULT_PLOT_HEIGHT);
 
 char *name = "TCGA_13_0751";
@@ -257,12 +303,39 @@
 drawIdeo(conn, js, pos, width);
 drawGenes(conn, js, pos, width);
 drawScale(conn, js, pos, width);
 
-hFreeConn(&conn);
+if (pos)
+    jsonAddString(js, "pos", pos);
+else
+    jsonAddString(js, "pos", "");
 
+struct settings *settings = initSettings(conn, pos, width, height, 0, 0);
+
+if (settings)
+    {
+    struct json *new, *list = jsonAddContainerList(js, "chroms");
+    new = list;
+    
+    struct chromLay *cl;
+    for (cl = settings->layoutList; cl; cl = cl->next)
+	{
+	jsonAddString(new, "name", cl->chrom);
+	jsonAddDouble(new, "baseStart", cl->baseStart);
+	jsonAddDouble(new, "baseEnd", cl->baseEnd);
+	jsonAddDouble(new, "baseWidth", cl->baseWidth);
+	jsonAddInt(new, "pxStart", cl->pxStart);
+	jsonAddInt(new, "pxStop", cl->pxStart + cl->pxWidth);
+	jsonAddInt(new, "pxWidth", cl->pxWidth);
+	
+	if (cl->next)
+	    new = jsonAddContainerToList(&list);
+	}
+    }
 if (js)
     hPrintf("%s\n", js->print(js));
+
+hFreeConn(&conn);
 }
 
 void dispatchRoutines()
 /* Look at command variables in cart and figure out which