src/hg/instinct/lib/hgHeatmapCustomDb.c 1.2
1.2 2009/06/04 03:42:49 jsanborn
added copyright notices, removed cluster library
Index: src/hg/instinct/lib/hgHeatmapCustomDb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/lib/hgHeatmapCustomDb.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -B -U 1000000 -r1.1 -r1.2
--- src/hg/instinct/lib/hgHeatmapCustomDb.c 5 May 2009 22:43:38 -0000 1.1
+++ src/hg/instinct/lib/hgHeatmapCustomDb.c 4 Jun 2009 03:42:49 -0000 1.2
@@ -1,574 +1,578 @@
+/********************************************************************************/
+/* Copyright 2007-2009 -- The Regents of the University of California */
+/********************************************************************************/
+
/* hgHeatmapCustomDb.c was originally generated by the autoSql program, which also
* generated hgHeatmapCustomDb.h and hgHeatmapCustomDb.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 "hgHeatmapCustomDb.h"
static char const rcsid[] = "$Id$";
void featuresStaticLoad(char **row, struct features *ret)
/* Load a row from features 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[1];
ret->shortLabel = row[2];
ret->longLabel = row[3];
ret->filterType = row[4];
ret->priority = sqlDouble(row[5]);
ret->visibility = row[6];
}
struct features *featuresLoad(char **row)
/* Load a features from row fetched with select * from features
* from database. Dispose of this with featuresFree(). */
{
struct features *ret;
AllocVar(ret);
ret->id = sqlUnsigned(row[0]);
ret->name = cloneString(row[1]);
ret->shortLabel = cloneString(row[2]);
ret->longLabel = cloneString(row[3]);
ret->filterType = cloneString(row[4]);
ret->priority = sqlDouble(row[5]);
ret->visibility = cloneString(row[6]);
return ret;
}
struct features *featuresLoadAll(char *fileName)
/* Load all features from a whitespace-separated file.
* Dispose of this with featuresFreeList(). */
{
struct features *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];
while (lineFileRow(lf, row))
{
el = featuresLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct features *featuresLoadAllByChar(char *fileName, char chopper)
/* Load all features from a chopper separated file.
* Dispose of this with featuresFreeList(). */
{
struct features *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = featuresLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct features *featuresLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all features 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 featuresFreeList(). */
{
struct features *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = featuresLoad(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void featuresSaveToDb(struct sqlConnection *conn, struct features *el, char *tableName, int updateSize)
/* Save features 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 featuresSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s','%s',%g,'%s')",
tableName, el->id, el->name, el->shortLabel, el->longLabel, el->filterType, el->priority, el->visibility);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void featuresSaveToDbEscaped(struct sqlConnection *conn, struct features *el, char *tableName, int updateSize)
/* Save features 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 featuresSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *name, *shortLabel, *longLabel, *filterType, *visibility;
name = sqlEscapeString(el->name);
shortLabel = sqlEscapeString(el->shortLabel);
longLabel = sqlEscapeString(el->longLabel);
filterType = sqlEscapeString(el->filterType);
visibility = sqlEscapeString(el->visibility);
dyStringPrintf(update, "insert into %s values ( %u,'%s','%s','%s','%s',%g,'%s')",
tableName, el->id, name, shortLabel, longLabel, filterType, el->priority, visibility);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&name);
freez(&shortLabel);
freez(&longLabel);
freez(&filterType);
freez(&visibility);
}
struct features *featuresCommaIn(char **pS, struct features *ret)
/* Create a features out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new features */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->id = sqlUnsignedComma(&s);
ret->name = sqlStringComma(&s);
ret->shortLabel = sqlStringComma(&s);
ret->longLabel = sqlStringComma(&s);
ret->filterType = sqlStringComma(&s);
ret->priority = sqlDoubleComma(&s);
ret->visibility = sqlStringComma(&s);
*pS = s;
return ret;
}
void featuresFree(struct features **pEl)
/* Free a single dynamically allocated features such as created
* with featuresLoad(). */
{
struct features *el;
if ((el = *pEl) == NULL) return;
freeMem(el->name);
freeMem(el->shortLabel);
freeMem(el->longLabel);
freeMem(el->filterType);
freeMem(el->visibility);
freez(pEl);
}
void featuresFreeList(struct features **pList)
/* Free a list of dynamically allocated features's */
{
struct features *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
featuresFree(&el);
}
*pList = NULL;
}
void featuresOutput(struct features *el, FILE *f, char sep, char lastSep)
/* Print out features. 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->name);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->shortLabel);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->longLabel);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->filterType);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%g", el->priority);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->visibility);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void clinicalDataStaticLoad(char **row, struct clinicalData *ret)
/* Load a row from clinicalData table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->patientId = row[0];
ret->feature_id = sqlUnsigned(row[1]);
ret->val = sqlDouble(row[2]);
ret->code = row[3];
}
struct clinicalData *clinicalDataLoad(char **row)
/* Load a clinicalData from row fetched with select * from clinicalData
* from database. Dispose of this with clinicalDataFree(). */
{
struct clinicalData *ret;
AllocVar(ret);
ret->patientId = cloneString(row[0]);
ret->feature_id = sqlUnsigned(row[1]);
ret->val = sqlDouble(row[2]);
ret->code = cloneString(row[3]);
return ret;
}
struct clinicalData *clinicalDataLoadAll(char *fileName)
/* Load all clinicalData from a whitespace-separated file.
* Dispose of this with clinicalDataFreeList(). */
{
struct clinicalData *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[4];
while (lineFileRow(lf, row))
{
el = clinicalDataLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct clinicalData *clinicalDataLoadAllByChar(char *fileName, char chopper)
/* Load all clinicalData from a chopper separated file.
* Dispose of this with clinicalDataFreeList(). */
{
struct clinicalData *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[4];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = clinicalDataLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct clinicalData *clinicalDataLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all clinicalData 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 clinicalDataFreeList(). */
{
struct clinicalData *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = clinicalDataLoad(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void clinicalDataSaveToDb(struct sqlConnection *conn, struct clinicalData *el, char *tableName, int updateSize)
/* Save clinicalData 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 clinicalDataSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s',%u,%g,'%s')",
tableName, el->patientId, el->feature_id, el->val, el->code);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void clinicalDataSaveToDbEscaped(struct sqlConnection *conn, struct clinicalData *el, char *tableName, int updateSize)
/* Save clinicalData 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 clinicalDataSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *patientId, *code;
patientId = sqlEscapeString(el->patientId);
code = sqlEscapeString(el->code);
dyStringPrintf(update, "insert into %s values ( '%s',%u,%g,'%s')",
tableName, patientId, el->feature_id, el->val, code);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&patientId);
freez(&code);
}
struct clinicalData *clinicalDataCommaIn(char **pS, struct clinicalData *ret)
/* Create a clinicalData out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new clinicalData */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->patientId = sqlStringComma(&s);
ret->feature_id = sqlUnsignedComma(&s);
ret->val = sqlDoubleComma(&s);
ret->code = sqlStringComma(&s);
*pS = s;
return ret;
}
void clinicalDataFree(struct clinicalData **pEl)
/* Free a single dynamically allocated clinicalData such as created
* with clinicalDataLoad(). */
{
struct clinicalData *el;
if ((el = *pEl) == NULL) return;
freeMem(el->patientId);
freeMem(el->code);
freez(pEl);
}
void clinicalDataFreeList(struct clinicalData **pList)
/* Free a list of dynamically allocated clinicalData's */
{
struct clinicalData *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
clinicalDataFree(&el);
}
*pList = NULL;
}
void clinicalDataOutput(struct clinicalData *el, FILE *f, char sep, char lastSep)
/* Print out clinicalData. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->patientId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%u", el->feature_id);
fputc(sep,f);
fprintf(f, "%g", el->val);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->code);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void labTrackStaticLoad(char **row, struct labTrack *ret)
/* Load a row from labTrack table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->patientId = row[0];
ret->trackId = row[1];
}
struct labTrack *labTrackLoad(char **row)
/* Load a labTrack from row fetched with select * from labTrack
* from database. Dispose of this with labTrackFree(). */
{
struct labTrack *ret;
AllocVar(ret);
ret->patientId = cloneString(row[0]);
ret->trackId = cloneString(row[1]);
return ret;
}
struct labTrack *labTrackLoadAll(char *fileName)
/* Load all labTrack from a whitespace-separated file.
* Dispose of this with labTrackFreeList(). */
{
struct labTrack *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[2];
while (lineFileRow(lf, row))
{
el = labTrackLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct labTrack *labTrackLoadAllByChar(char *fileName, char chopper)
/* Load all labTrack from a chopper separated file.
* Dispose of this with labTrackFreeList(). */
{
struct labTrack *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[2];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = labTrackLoad(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct labTrack *labTrackLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all labTrack 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 labTrackFreeList(). */
{
struct labTrack *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = labTrackLoad(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void labTrackSaveToDb(struct sqlConnection *conn, struct labTrack *el, char *tableName, int updateSize)
/* Save labTrack 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 labTrackSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s')",
tableName, el->patientId, el->trackId);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void labTrackSaveToDbEscaped(struct sqlConnection *conn, struct labTrack *el, char *tableName, int updateSize)
/* Save labTrack 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 labTrackSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *patientId, *trackId;
patientId = sqlEscapeString(el->patientId);
trackId = sqlEscapeString(el->trackId);
dyStringPrintf(update, "insert into %s values ( '%s','%s')",
tableName, patientId, trackId);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&patientId);
freez(&trackId);
}
struct labTrack *labTrackCommaIn(char **pS, struct labTrack *ret)
/* Create a labTrack out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new labTrack */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->patientId = sqlStringComma(&s);
ret->trackId = sqlStringComma(&s);
*pS = s;
return ret;
}
void labTrackFree(struct labTrack **pEl)
/* Free a single dynamically allocated labTrack such as created
* with labTrackLoad(). */
{
struct labTrack *el;
if ((el = *pEl) == NULL) return;
freeMem(el->patientId);
freeMem(el->trackId);
freez(pEl);
}
void labTrackFreeList(struct labTrack **pList)
/* Free a list of dynamically allocated labTrack's */
{
struct labTrack *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
labTrackFree(&el);
}
*pList = NULL;
}
void labTrackOutput(struct labTrack *el, FILE *f, char sep, char lastSep)
/* Print out labTrack. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->patientId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->trackId);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
/* -------------------------------- End autoSql Generated Code -------------------------------- */