src/hg/instinct/lib/featuresLib.c 1.32

1.32 2010/05/06 18:42:07 jsanborn
added new way of accessing clinical features
Index: src/hg/instinct/lib/featuresLib.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/lib/featuresLib.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -b -B -U 4 -r1.31 -r1.32
--- src/hg/instinct/lib/featuresLib.c	12 Apr 2010 17:16:10 -0000	1.31
+++ src/hg/instinct/lib/featuresLib.c	6 May 2010 18:42:07 -0000	1.32
@@ -207,8 +207,13 @@
 {
 return cloneString("n/a");
 }
 
+struct slName *noValList(struct column *col, struct slName *id, struct sqlConnection *conn)
+{
+return NULL;
+}
+
 static char *noColVal(struct column *col, struct sqlConnection *conn)
 /* Return not-available value. */
 {
 return cloneString("n/a");
@@ -224,8 +229,9 @@
 /* Set up default methods. */
 {
 col->exists = alwaysExists;
 col->cellVal = noVal;
+col->cellValList = noValList;
 col->cellMinVal = noColVal;
 col->cellMaxVal = noColVal;
 col->cellAvgVal = noColVal;
 col->cellPrint = cellSimplePrint;
@@ -300,8 +306,41 @@
 
 return sqlQuickString(conn, query);
 }
 
+struct slName *cellLookupValList(struct column *col, struct slName *idList, 
+				 struct sqlConnection *conn)
+/* Get all values in field in a table defined by col->table, col->keyField, 
+ * col->valField.  If an xrefLookup is specified in col->settings,
+ * use that to look up an alternate name for the result. */
+{
+struct slName *id;
+
+char query[512];
+safef(query, sizeof(query), "select %s, %s from %s;",
+	       col->keyField, col->valField, col->table);
+ 
+struct sqlResult *sr = sqlGetResult(conn, query);
+char **row;
+
+struct hash *hash = hashNew(0);
+while ((row = sqlNextRow(sr)) != NULL)
+    hashAdd(hash, row[0], cloneString(row[1]));
+
+struct hashEl *el;
+struct slName *retList = NULL;
+for (id = idList; id; id = id->next)
+    {
+    if ((el = hashLookup(hash, id->name)) == NULL)
+	slNameAddHead(&retList, NULL);
+    else
+	slNameAddHead(&retList, el->val);
+    }
+slReverse(&retList);
+
+return retList;
+}
+
 boolean cellLookupCoded(struct column *col, struct sqlConnection *conn)
 {
 if (!sqlTableExists(conn, CODES_TABLE))
     return FALSE;
@@ -464,8 +503,9 @@
 if (col->valField == NULL)
     errAbort("Not enough fields in type lookup for %s", col->name);
 col->exists = simpleTableExists;
 col->cellVal = cellLookupVal;
+col->cellValList = cellLookupValList;
 col->cellAvgVal = cellLookupAvgVal;
 col->cellMinVal = cellLookupMinVal;
 col->cellMaxVal = cellLookupMaxVal;
 col->cellMinCutVal= cellLookupMinCutVal;