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/gtexSample.c src/hg/lib/gtexSample.c
new file mode 100644
index 0000000..9c94afd
--- /dev/null
+++ src/hg/lib/gtexSample.c
@@ -0,0 +1,155 @@
+/* gtexSample.c was originally generated by the autoSql program, which also 
+ * generated gtexSample.h and gtexSample.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 "gtexSample.h"
+
+
+
+char *gtexSampleCommaSepFieldNames = "id,tissue,donor,name";
+
+void gtexSampleStaticLoad(char **row, struct gtexSample *ret)
+/* Load a row from gtexSample table into ret.  The contents of ret will
+ * be replaced at the next call to this function. */
+{
+
+ret->id = sqlUnsigned(row[0]);
+ret->tissue = row[1];
+ret->donor = row[2];
+ret->name = row[3];
+}
+
+struct gtexSample *gtexSampleLoad(char **row)
+/* Load a gtexSample from row fetched with select * from gtexSample
+ * from database.  Dispose of this with gtexSampleFree(). */
+{
+struct gtexSample *ret;
+
+AllocVar(ret);
+ret->id = sqlUnsigned(row[0]);
+ret->tissue = cloneString(row[1]);
+ret->donor = cloneString(row[2]);
+ret->name = cloneString(row[3]);
+return ret;
+}
+
+struct gtexSample *gtexSampleLoadAll(char *fileName) 
+/* Load all gtexSample from a whitespace-separated file.
+ * Dispose of this with gtexSampleFreeList(). */
+{
+struct gtexSample *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[4];
+
+while (lineFileRow(lf, row))
+    {
+    el = gtexSampleLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexSample *gtexSampleLoadAllByChar(char *fileName, char chopper) 
+/* Load all gtexSample from a chopper separated file.
+ * Dispose of this with gtexSampleFreeList(). */
+{
+struct gtexSample *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[4];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = gtexSampleLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct gtexSample *gtexSampleCommaIn(char **pS, struct gtexSample *ret)
+/* Create a gtexSample out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new gtexSample */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->id = sqlUnsignedComma(&s);
+ret->tissue = sqlStringComma(&s);
+ret->donor = sqlStringComma(&s);
+ret->name = sqlStringComma(&s);
+*pS = s;
+return ret;
+}
+
+void gtexSampleFree(struct gtexSample **pEl)
+/* Free a single dynamically allocated gtexSample such as created
+ * with gtexSampleLoad(). */
+{
+struct gtexSample *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->tissue);
+freeMem(el->donor);
+freeMem(el->name);
+freez(pEl);
+}
+
+void gtexSampleFreeList(struct gtexSample **pList)
+/* Free a list of dynamically allocated gtexSample's */
+{
+struct gtexSample *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    gtexSampleFree(&el);
+    }
+*pList = NULL;
+}
+
+void gtexSampleOutput(struct gtexSample *el, FILE *f, char sep, char lastSep) 
+/* Print out gtexSample.  Separate fields with sep. Follow last field with lastSep. */
+{
+fprintf(f, "%u", el->id);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->tissue);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->donor);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->name);
+if (sep == ',') fputc('"',f);
+fputc(lastSep,f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+
+void gtexSampleCreateTable(struct sqlConnection *conn, char *table)
+/* Create expression record format table of given name. */
+{
+char query[1024];
+
+sqlSafef(query, sizeof(query),
+"CREATE TABLE %s (\n"
+"    id int unsigned not null,	# internal id\n"
+"    tissue varchar(255) not null,	# GTEx tissue\n"
+"    donor varchar(255) not null,	# GTEx donor name\n"
+"    name varchar(255) not null,        # GTEx sample name\n"
+"              #Indices\n"
+"    PRIMARY KEY(id)\n"
+")\n",   table);
+sqlRemakeTable(conn, table, query);
+}