a9a29995abe1e134d84bb80bdae1c0318060feff
kate
  Wed Aug 6 00:41:21 2014 -0700
Tool to load GTEx (NIH Common Fund Gene Tissue Expression).  Quite similar to microarray table organization.
diff --git src/hg/lib/gtexData.c src/hg/lib/gtexData.c
new file mode 100644
index 0000000..16c5459
--- /dev/null
+++ src/hg/lib/gtexData.c
@@ -0,0 +1,156 @@
+/* gtexData.c was originally generated by the autoSql program, which also 
+ * generated gtexData.h and gtexData.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 "gtexData.h"
+
+
+
+char *gtexDataCommaSepFieldNames = "geneId,sampleCount,sampleLevels";
+
+struct gtexData *gtexDataLoad(char **row)
+/* Load a gtexData from row fetched with select * from gtexData
+ * from database.  Dispose of this with gtexDataFree(). */
+{
+struct gtexData *ret;
+
+AllocVar(ret);
+ret->sampleCount = sqlUnsigned(row[1]);
+ret->geneId = cloneString(row[0]);
+{
+int sizeOne;
+sqlFloatDynamicArray(row[2], &ret->sampleLevels, &sizeOne);
+assert(sizeOne == ret->sampleCount);
+}
+return ret;
+}
+
+struct gtexData *gtexDataLoadAll(char *fileName) 
+/* Load all gtexData from a whitespace-separated file.
+ * Dispose of this with gtexDataFreeList(). */
+{
+struct gtexData *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[3];
+
+while (lineFileRow(lf, row))
+    {
+    el = gtexDataLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexData *gtexDataLoadAllByChar(char *fileName, char chopper) 
+/* Load all gtexData from a chopper separated file.
+ * Dispose of this with gtexDataFreeList(). */
+{
+struct gtexData *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[3];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = gtexDataLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexData *gtexDataCommaIn(char **pS, struct gtexData *ret)
+/* Create a gtexData out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new gtexData */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->geneId = sqlStringComma(&s);
+ret->sampleCount = sqlUnsignedComma(&s);
+{
+int i;
+s = sqlEatChar(s, '{');
+AllocArray(ret->sampleLevels, ret->sampleCount);
+for (i=0; i<ret->sampleCount; ++i)
+    {
+    ret->sampleLevels[i] = sqlFloatComma(&s);
+    }
+s = sqlEatChar(s, '}');
+s = sqlEatChar(s, ',');
+}
+*pS = s;
+return ret;
+}
+
+void gtexDataFree(struct gtexData **pEl)
+/* Free a single dynamically allocated gtexData such as created
+ * with gtexDataLoad(). */
+{
+struct gtexData *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->geneId);
+freeMem(el->sampleLevels);
+freez(pEl);
+}
+
+void gtexDataFreeList(struct gtexData **pList)
+/* Free a list of dynamically allocated gtexData's */
+{
+struct gtexData *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    gtexDataFree(&el);
+    }
+*pList = NULL;
+}
+
+void gtexDataOutput(struct gtexData *el, FILE *f, char sep, char lastSep) 
+/* Print out gtexData.  Separate fields with sep. Follow last field with lastSep. */
+{
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->geneId);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->sampleCount);
+fputc(sep,f);
+{
+int i;
+if (sep == ',') fputc('{',f);
+for (i=0; i<el->sampleCount; ++i)
+    {
+    fprintf(f, "%g", el->sampleLevels[i]);
+    fputc(',', f);
+    }
+if (sep == ',') fputc('}',f);
+}
+fputc(lastSep,f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+
+void gtexDataCreateTable(struct sqlConnection *conn, char *table)
+/* Create table with given name. */
+{
+char query[512];
+
+sqlSafef(query, sizeof(query),
+"CREATE TABLE %s (\n"
+"    geneId varchar(255) not null,\n"
+"    sampleCount int unsigned not null,\n"
+"    sampleLevels longblob not null,\n"
+"    INDEX(geneId(10))\n"
+")\n",   table);
+sqlRemakeTable(conn, table, query);
+}