src/hg/instinct/lib/hgHeatmapLib.c 1.68

1.68 2010/04/12 17:16:10 jsanborn
added raDb functionality
Index: src/hg/instinct/lib/hgHeatmapLib.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/lib/hgHeatmapLib.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -b -B -U 4 -r1.67 -r1.68
--- src/hg/instinct/lib/hgHeatmapLib.c	11 Mar 2010 19:38:48 -0000	1.67
+++ src/hg/instinct/lib/hgHeatmapLib.c	12 Apr 2010 17:16:10 -0000	1.68
@@ -8,8 +8,9 @@
 #include "hash.h"
 #include "hCommon.h"
 #include "hdb.h"
 #include "hui.h"
+#include "hgConfig.h"
 #include "hgHeatmapLib.h"
 #include "microarray.h"
 #include "ra.h"
 #include "heatmapUtility.h"
@@ -28,8 +29,27 @@
 char *metaStatTest[4];
 
 static char *heatMapDbProfile = "localDb";  // database profile to use
 
+char *raDbPath()
+/* return the comma-separated list of the track database from the config
+ * file. Freez when done */
+{
+char *raDb = cfgOptionEnv("HGDB_TRACKDB", "db.raDb");
+if(raDb == NULL)
+    errAbort("Please set the db.raDb field in the hg.conf config file.");
+return cloneString(raDb);
+}
+
+struct raDb *raDbLoad(struct sqlConnection *conn)
+{
+char *raDb = raDbPath();
+char query[256];
+safef(query, sizeof(query), "select * from %s", raDb);
+
+return raDbLoadByQuery(conn, query);
+}
+
 struct microarrayGroups *maGroupings(char *database, char *table)
 /* Get the settings from the microarrayGrouop.ra files and put them in a convenient struct. */
 {
 struct microarrayGroups *ret;
@@ -260,8 +280,63 @@
 
 return gh;
 }
 
+struct genoHeatmap *getHeatmapRaDb(struct sqlConnection *localConn, 
+				   struct sqlConnection *publicConn, 
+				   char *database, struct raDb *ra)
+{
+struct sqlConnection *conn = localConn;
+if (!sqlTableExists(localConn, ra->name))
+    { /* check if table exists on public database */
+    if (publicConn && sqlTableExists(publicConn, ra->name))
+	conn = publicConn;
+    else
+	return NULL;
+    }
+
+/* Connect to database on local host */
+struct genoHeatmap *gh = AllocVar(gh);
+
+gh->database      = database;
+gh->sampleList    = NULL;
+gh->sampleOrder   = NULL;
+gh->expIdOrder    = NULL;
+gh->tDb           = hMaybeTrackInfo(conn, ra->name);
+gh->custom        = FALSE;
+gh->anaResult     = NULL;
+gh->anaResultHash = NULL;
+
+/* Setting on heatmap description from datasets.ra file*/
+gh->name        = cloneString(ra->name);
+gh->shortLabel  = cloneString(ra->shortLabel);
+gh->longLabel   = cloneString(ra->longLabel);
+gh->dataType    = cloneString(ra->dataType);
+gh->accessTable = cloneString(ra->accessTable);
+gh->local_url   = cloneString(ra->local_url);
+gh->group       = cloneString(ra->groupName);
+gh->raFile      = cloneString(ra->raFile);
+gh->patDb       = cloneString(ra->patDb);
+gh->patTable    = cloneString(ra->patTable);
+gh->patField    = cloneString(ra->patField);
+gh->sampleField = cloneString(ra->sampleField);
+gh->probeTable  = cloneString(ra->aliasTable);
+gh->displayNameTable = cloneString(ra->displayNameTable);
+gh->platform    = cloneString(ra->platform);
+gh->expScale    = *(ra->expScale);
+gh->gainFull    = *(ra->gainFull);
+gh->gainSet     = *(ra->gainSet);
+gh->height      = *(ra->height);
+gh->profile     = cloneString(ra->profile);
+gh->expCount    = *(ra->expCount);
+if (!ra->security)
+    gh->private = TRUE;  // default to private tracks.
+else
+    gh->private = !sameString(ra->security, "public");
+
+return gh;
+}
+
 /* Deep copy of gh, clean up memory after return pointer */
 struct genoHeatmap *cloneHeatmap(struct genoHeatmap *gh)
 {
 if (!gh)