1084bf14211e7e4ace072d7a213672f3a8f98be1
kate
  Fri Jul 24 17:30:21 2015 -0700
Scale wrt all genes, not just those in window.  We now save the max tissue median score in the gtexInfo table. refs #15645

diff --git src/hg/lib/gtexInfo.c src/hg/lib/gtexInfo.c
new file mode 100644
index 0000000..d056958
--- /dev/null
+++ src/hg/lib/gtexInfo.c
@@ -0,0 +1,162 @@
+/* gtexInfo.c was originally generated by the autoSql program, which also 
+ * generated gtexInfo.h and gtexInfo.sql.  This module links the database and
+ * the RAM representation of objects. */
+
+#include "common.h"
+#include "linefile.h"
+#include "dystring.h"
+#include "jksql.h"
+#include "hdb.h"
+#include "gtexInfo.h"
+
+
+
+char *gtexInfoCommaSepFieldNames = "version,releaseDate,maxMedianScore";
+
+void gtexInfoStaticLoad(char **row, struct gtexInfo *ret)
+/* Load a row from gtexInfo table into ret.  The contents of ret will
+ * be replaced at the next call to this function. */
+{
+
+ret->version = row[0];
+ret->releaseDate = row[1];
+ret->maxMedianScore = sqlDouble(row[2]);
+}
+
+struct gtexInfo *gtexInfoLoad(char **row)
+/* Load a gtexInfo from row fetched with select * from gtexInfo
+ * from database.  Dispose of this with gtexInfoFree(). */
+{
+struct gtexInfo *ret;
+
+AllocVar(ret);
+ret->version = cloneString(row[0]);
+ret->releaseDate = cloneString(row[1]);
+ret->maxMedianScore = sqlDouble(row[2]);
+return ret;
+}
+
+struct gtexInfo *gtexInfoLoadAll(char *fileName) 
+/* Load all gtexInfo from a whitespace-separated file.
+ * Dispose of this with gtexInfoFreeList(). */
+{
+struct gtexInfo *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[3];
+
+while (lineFileRow(lf, row))
+    {
+    el = gtexInfoLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexInfo *gtexInfoLoadAllByChar(char *fileName, char chopper) 
+/* Load all gtexInfo from a chopper separated file.
+ * Dispose of this with gtexInfoFreeList(). */
+{
+struct gtexInfo *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[3];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = gtexInfoLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexInfo *gtexInfoCommaIn(char **pS, struct gtexInfo *ret)
+/* Create a gtexInfo out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new gtexInfo */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->version = sqlStringComma(&s);
+ret->releaseDate = sqlStringComma(&s);
+ret->maxMedianScore = sqlDoubleComma(&s);
+*pS = s;
+return ret;
+}
+
+void gtexInfoFree(struct gtexInfo **pEl)
+/* Free a single dynamically allocated gtexInfo such as created
+ * with gtexInfoLoad(). */
+{
+struct gtexInfo *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->version);
+freeMem(el->releaseDate);
+freez(pEl);
+}
+
+void gtexInfoFreeList(struct gtexInfo **pList)
+/* Free a list of dynamically allocated gtexInfo's */
+{
+struct gtexInfo *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    gtexInfoFree(&el);
+    }
+*pList = NULL;
+}
+
+void gtexInfoOutput(struct gtexInfo *el, FILE *f, char sep, char lastSep) 
+/* Print out gtexInfo.  Separate fields with sep. Follow last field with lastSep. */
+{
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->version);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->releaseDate);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%g", el->maxMedianScore);
+fputc(lastSep,f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+
+void gtexInfoCreateTable(struct sqlConnection *conn, char *table)
+/* Create GTEx info table */
+{
+char query[1024];
+
+sqlSafef(query, sizeof(query),
+"CREATE TABLE %s (\n"
+"    version varchar(255) not null,	# GTEX data release (e.g. V4, V6)\n"
+"    releaseDate varchar(255) not null,	# Release date\n"
+"    maxMedianScore double not null,	# Maximum score observed for a tissue median (use to scale display)\n"
+"        #Indices\n"
+"    PRIMARY KEY(version)\n"
+")\n",   table);
+sqlRemakeTable(conn, table, query);
+}
+
+double gtexMaxMedianScore(char *version)
+/* Retrieve max median score for latest (or named) version */
+{
+char query[1024];
+struct sqlConnection *conn = hAllocConn("hgFixed");
+if (!conn)
+    return 0;
+// TODO: trackDB setting for this
+if (!version)
+    version = "V4";
+sqlSafef(query, sizeof query, "select maxMedianScore from gtexInfo where version='%s'", version);
+return sqlQuickDouble(conn, query);
+}
+