965d1048e8671fb3a5630fe75deb88f24df386d7
kate
  Wed Aug 13 15:01:59 2014 -0700
Expand schema for GTex.  Create tissue short names and use these in sample and data tables. refs #13504
diff --git src/hg/lib/gtexSample.c src/hg/lib/gtexSample.c
index 9c94afd..66d4e16 100644
--- src/hg/lib/gtexSample.c
+++ src/hg/lib/gtexSample.c
@@ -1,155 +1,149 @@
 /* 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";
+char *gtexSampleCommaSepFieldNames = "name,tissue,donor";
 
 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->name = 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->name = cloneString(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];
+char *row[3];
 
 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];
+char *row[3];
 
 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->name = sqlStringComma(&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->name);
 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);
+fprintf(f, "%s", el->name);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
-fprintf(f, "%s", el->donor);
+fprintf(f, "%s", el->tissue);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
-fprintf(f, "%s", el->name);
+fprintf(f, "%s", el->donor);
 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"
+"    name varchar(255) not null,       # GTEx sample identifier\n"
+"    tissue varchar(255) not null,     # Tissue name\n"
+"    donor varchar(255) not null,      # GTEx subject identifier\n"
 "              #Indices\n"
-"    PRIMARY KEY(id)\n"
+"    PRIMARY KEY(name)\n"
 ")\n",   table);
 sqlRemakeTable(conn, table, query);
 }