/* gencodeAttrs.c was originally generated by the autoSql program, which also 
 * generated gencodeAttrs.h and gencodeAttrs.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 "gencodeAttrs.h"



char *gencodeAttrsCommaSepFieldNames = "geneId,geneName,geneType,unused1,transcriptId,transcriptName,transcriptType,unused2,unused3,unused4,ccdsId,level,transcriptClass,proteinId";

void gencodeAttrsStaticLoad(char **row, struct gencodeAttrs *ret)
/* Load a row from gencodeAttrs table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

ret->geneId = row[0];
ret->geneName = row[1];
ret->geneType = row[2];
ret->unused1 = row[3];
ret->transcriptId = row[4];
ret->transcriptName = row[5];
ret->transcriptType = row[6];
ret->unused2 = row[7];
ret->unused3 = row[8];
ret->unused4 = row[9];
ret->ccdsId = row[10];
ret->level = sqlSigned(row[11]);
ret->transcriptClass = row[12];
ret->proteinId = row[13];
}

struct gencodeAttrs *gencodeAttrsLoad(char **row)
/* Load a gencodeAttrs from row fetched with select * from gencodeAttrs
 * from database.  Dispose of this with gencodeAttrsFree(). */
{
struct gencodeAttrs *ret;

AllocVar(ret);
ret->geneId = cloneString(row[0]);
ret->geneName = cloneString(row[1]);
ret->geneType = cloneString(row[2]);
ret->unused1 = cloneString(row[3]);
ret->transcriptId = cloneString(row[4]);
ret->transcriptName = cloneString(row[5]);
ret->transcriptType = cloneString(row[6]);
ret->unused2 = cloneString(row[7]);
ret->unused3 = cloneString(row[8]);
ret->unused4 = cloneString(row[9]);
ret->ccdsId = cloneString(row[10]);
ret->level = sqlSigned(row[11]);
ret->transcriptClass = cloneString(row[12]);
ret->proteinId = cloneString(row[13]);
return ret;
}

struct gencodeAttrs *gencodeAttrsLoadAll(char *fileName) 
/* Load all gencodeAttrs from a whitespace-separated file.
 * Dispose of this with gencodeAttrsFreeList(). */
{
struct gencodeAttrs *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[14];

while (lineFileRow(lf, row))
    {
    el = gencodeAttrsLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

struct gencodeAttrs *gencodeAttrsLoadAllByChar(char *fileName, char chopper) 
/* Load all gencodeAttrs from a chopper separated file.
 * Dispose of this with gencodeAttrsFreeList(). */
{
struct gencodeAttrs *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[14];

while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
    {
    el = gencodeAttrsLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

struct gencodeAttrs *gencodeAttrsCommaIn(char **pS, struct gencodeAttrs *ret)
/* Create a gencodeAttrs out of a comma separated string. 
 * This will fill in ret if non-null, otherwise will
 * return a new gencodeAttrs */
{
char *s = *pS;

if (ret == NULL)
    AllocVar(ret);
ret->geneId = sqlStringComma(&s);
ret->geneName = sqlStringComma(&s);
ret->geneType = sqlStringComma(&s);
ret->unused1 = sqlStringComma(&s);
ret->transcriptId = sqlStringComma(&s);
ret->transcriptName = sqlStringComma(&s);
ret->transcriptType = sqlStringComma(&s);
ret->unused2 = sqlStringComma(&s);
ret->unused3 = sqlStringComma(&s);
ret->unused4 = sqlStringComma(&s);
ret->ccdsId = sqlStringComma(&s);
ret->level = sqlSignedComma(&s);
ret->transcriptClass = sqlStringComma(&s);
ret->proteinId = sqlStringComma(&s);
*pS = s;
return ret;
}

void gencodeAttrsFree(struct gencodeAttrs **pEl)
/* Free a single dynamically allocated gencodeAttrs such as created
 * with gencodeAttrsLoad(). */
{
struct gencodeAttrs *el;

if ((el = *pEl) == NULL) return;
freeMem(el->geneId);
freeMem(el->geneName);
freeMem(el->geneType);
freeMem(el->unused1);
freeMem(el->transcriptId);
freeMem(el->transcriptName);
freeMem(el->transcriptType);
freeMem(el->unused2);
freeMem(el->unused3);
freeMem(el->unused4);
freeMem(el->ccdsId);
freeMem(el->transcriptClass);
freeMem(el->proteinId);
freez(pEl);
}

void gencodeAttrsFreeList(struct gencodeAttrs **pList)
/* Free a list of dynamically allocated gencodeAttrs's */
{
struct gencodeAttrs *el, *next;

for (el = *pList; el != NULL; el = next)
    {
    next = el->next;
    gencodeAttrsFree(&el);
    }
*pList = NULL;
}

void gencodeAttrsOutput(struct gencodeAttrs *el, FILE *f, char sep, char lastSep) 
/* Print out gencodeAttrs.  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);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->geneName);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->geneType);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->unused1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->transcriptId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->transcriptName);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->transcriptType);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->unused2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->unused3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->unused4);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ccdsId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", el->level);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->transcriptClass);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->proteinId);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

/* -------------------------------- End autoSql Generated Code -------------------------------- */

