src/hg/lib/makeItemsItem.c 1.3

1.3 2010/04/10 01:13:58 kent
Taking a few more steps towards making the makeItems type custom track. It actually seems to be storing ranges in the customTrash database and displaying them now based on your javascript selections!
Index: src/hg/lib/makeItemsItem.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/makeItemsItem.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 1000000 -r1.2 -r1.3
--- src/hg/lib/makeItemsItem.c	9 Apr 2010 17:45:57 -0000	1.2
+++ src/hg/lib/makeItemsItem.c	10 Apr 2010 01:13:58 -0000	1.3
@@ -1,233 +1,238 @@
 /* makeItemsItem.c was originally generated by the autoSql program, which also 
  * generated makeItemsItem.h and makeItemsItem.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 "makeItemsItem.h"
 
 static char const rcsid[] = "$Id$";
 
 void makeItemsItemStaticLoad(char **row, struct makeItemsItem *ret)
 /* Load a row from makeItemsItem table into ret.  The contents of ret will
  * be replaced at the next call to this function. */
 {
 
 ret->bin = sqlUnsigned(row[0]);
 ret->chrom = row[1];
 ret->chromStart = sqlUnsigned(row[2]);
 ret->chromEnd = sqlUnsigned(row[3]);
 ret->name = row[4];
-safecpy(ret->strand, sizeof(ret->strand), row[5]);
-ret->score = sqlUnsigned(row[6]);
-ret->color = row[7];
-ret->description = row[8];
+ret->score = sqlUnsigned(row[5]);
+safecpy(ret->strand, sizeof(ret->strand), row[6]);
+ret->thickStart = sqlUnsigned(row[7]);
+ret->thickEnd = sqlUnsigned(row[8]);
+ret->itemRgb = sqlUnsigned(row[9]);
+ret->description = row[10];
 }
 
 struct makeItemsItem *makeItemsItemLoadByQuery(struct sqlConnection *conn, char *query)
 /* Load all makeItemsItem from table that satisfy the query given.  
  * Where query is of the form 'select * from example where something=something'
  * or 'select example.* from example, anotherTable where example.something = 
  * anotherTable.something'.
  * Dispose of this with makeItemsItemFreeList(). */
 {
 struct makeItemsItem *list = NULL, *el;
 struct sqlResult *sr;
 char **row;
 
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     el = makeItemsItemLoad(row);
     slAddHead(&list, el);
     }
 slReverse(&list);
 sqlFreeResult(&sr);
 return list;
 }
 
 void makeItemsItemSaveToDb(struct sqlConnection *conn, struct makeItemsItem *el, char *tableName, int updateSize)
 /* Save makeItemsItem as a row to the table specified by tableName. 
  * As blob fields may be arbitrary size updateSize specifies the approx size
  * of a string that would contain the entire query. Arrays of native types are
  * converted to comma separated strings and loaded as such, User defined types are
  * inserted as NULL. Note that strings must be escaped to allow insertion into the database.
  * For example "autosql's features include" --> "autosql\'s features include" 
  * If worried about this use makeItemsItemSaveToDbEscaped() */
 {
 struct dyString *update = newDyString(updateSize);
-dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s','%s',%u,'%s',%s)", 
-	tableName,  el->bin,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->strand,  el->score,  el->color,  el->description);
+dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s',%u,'%s',%u,%u,%u,%s)", 
+	tableName,  el->bin,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->thickStart,  el->thickEnd,  el->itemRgb,  el->description);
 sqlUpdate(conn, update->string);
 freeDyString(&update);
 }
 
 void makeItemsItemSaveToDbEscaped(struct sqlConnection *conn, struct makeItemsItem *el, char *tableName, int updateSize)
 /* Save makeItemsItem as a row to the table specified by tableName. 
  * As blob fields may be arbitrary size updateSize specifies the approx size.
  * of a string that would contain the entire query. Automatically 
  * escapes all simple strings (not arrays of string) but may be slower than makeItemsItemSaveToDb().
  * For example automatically copies and converts: 
  * "autosql's features include" --> "autosql\'s features include" 
  * before inserting into database. */ 
 {
 struct dyString *update = newDyString(updateSize);
-char  *chrom, *name, *strand, *color, *description;
+char  *chrom, *name, *strand, *description;
 chrom = sqlEscapeString(el->chrom);
 name = sqlEscapeString(el->name);
 strand = sqlEscapeString(el->strand);
-color = sqlEscapeString(el->color);
 description = sqlEscapeString(el->description);
 
-dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s','%s',%u,'%s','%s')", 
-	tableName,  el->bin,  chrom,  el->chromStart,  el->chromEnd,  name,  strand,  el->score,  color,  description);
+dyStringPrintf(update, "insert into %s values ( %u,'%s',%u,%u,'%s',%u,'%s',%u,%u,%u,'%s')", 
+	tableName,  el->bin,  chrom,  el->chromStart,  el->chromEnd,  name,  el->score,  strand,  el->thickStart,  el->thickEnd,  el->itemRgb,  description);
 sqlUpdate(conn, update->string);
 freeDyString(&update);
 freez(&chrom);
 freez(&name);
 freez(&strand);
-freez(&color);
 freez(&description);
 }
 
 struct makeItemsItem *makeItemsItemLoad(char **row)
 /* Load a makeItemsItem from row fetched with select * from makeItemsItem
  * from database.  Dispose of this with makeItemsItemFree(). */
 {
 struct makeItemsItem *ret;
 
 AllocVar(ret);
 ret->bin = sqlUnsigned(row[0]);
 ret->chrom = cloneString(row[1]);
 ret->chromStart = sqlUnsigned(row[2]);
 ret->chromEnd = sqlUnsigned(row[3]);
 ret->name = cloneString(row[4]);
-safecpy(ret->strand, sizeof(ret->strand), row[5]);
-ret->score = sqlUnsigned(row[6]);
-ret->color = cloneString(row[7]);
-ret->description = cloneString(row[8]);
+ret->score = sqlUnsigned(row[5]);
+safecpy(ret->strand, sizeof(ret->strand), row[6]);
+ret->thickStart = sqlUnsigned(row[7]);
+ret->thickEnd = sqlUnsigned(row[8]);
+ret->itemRgb = sqlUnsigned(row[9]);
+ret->description = cloneString(row[10]);
 return ret;
 }
 
 struct makeItemsItem *makeItemsItemLoadAll(char *fileName) 
 /* Load all makeItemsItem from a whitespace-separated file.
  * Dispose of this with makeItemsItemFreeList(). */
 {
 struct makeItemsItem *list = NULL, *el;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
-char *row[9];
+char *row[11];
 
 while (lineFileRow(lf, row))
     {
     el = makeItemsItemLoad(row);
     slAddHead(&list, el);
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
 struct makeItemsItem *makeItemsItemLoadAllByChar(char *fileName, char chopper) 
 /* Load all makeItemsItem from a chopper separated file.
  * Dispose of this with makeItemsItemFreeList(). */
 {
 struct makeItemsItem *list = NULL, *el;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
-char *row[9];
+char *row[11];
 
 while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
     {
     el = makeItemsItemLoad(row);
     slAddHead(&list, el);
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
 struct makeItemsItem *makeItemsItemCommaIn(char **pS, struct makeItemsItem *ret)
 /* Create a makeItemsItem out of a comma separated string. 
  * This will fill in ret if non-null, otherwise will
  * return a new makeItemsItem */
 {
 char *s = *pS;
 
 if (ret == NULL)
     AllocVar(ret);
 ret->bin = sqlUnsignedComma(&s);
 ret->chrom = sqlStringComma(&s);
 ret->chromStart = sqlUnsignedComma(&s);
 ret->chromEnd = sqlUnsignedComma(&s);
 ret->name = sqlStringComma(&s);
-sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand));
 ret->score = sqlUnsignedComma(&s);
-ret->color = sqlStringComma(&s);
+sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand));
+ret->thickStart = sqlUnsignedComma(&s);
+ret->thickEnd = sqlUnsignedComma(&s);
+ret->itemRgb = sqlUnsignedComma(&s);
 ret->description = sqlStringComma(&s);
 *pS = s;
 return ret;
 }
 
 void makeItemsItemFree(struct makeItemsItem **pEl)
 /* Free a single dynamically allocated makeItemsItem such as created
  * with makeItemsItemLoad(). */
 {
 struct makeItemsItem *el;
 
 if ((el = *pEl) == NULL) return;
 freeMem(el->chrom);
 freeMem(el->name);
-freeMem(el->color);
 freeMem(el->description);
 freez(pEl);
 }
 
 void makeItemsItemFreeList(struct makeItemsItem **pList)
 /* Free a list of dynamically allocated makeItemsItem's */
 {
 struct makeItemsItem *el, *next;
 
 for (el = *pList; el != NULL; el = next)
     {
     next = el->next;
     makeItemsItemFree(&el);
     }
 *pList = NULL;
 }
 
 void makeItemsItemOutput(struct makeItemsItem *el, FILE *f, char sep, char lastSep) 
 /* Print out makeItemsItem.  Separate fields with sep. Follow last field with lastSep. */
 {
 fprintf(f, "%u", el->bin);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->chrom);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%u", el->chromStart);
 fputc(sep,f);
 fprintf(f, "%u", el->chromEnd);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->name);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
+fprintf(f, "%u", el->score);
+fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->strand);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
-fprintf(f, "%u", el->score);
+fprintf(f, "%u", el->thickStart);
 fputc(sep,f);
-if (sep == ',') fputc('"',f);
-fprintf(f, "%s", el->color);
-if (sep == ',') fputc('"',f);
+fprintf(f, "%u", el->thickEnd);
+fputc(sep,f);
+fprintf(f, "%u", el->itemRgb);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->description);
 if (sep == ',') fputc('"',f);
 fputc(lastSep,f);
 }
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */