/* codeBlastScore.c was originally generated by the autoSql program, which also 
 * generated codeBlastScore.h and codeBlastScore.sql.  This module links the database and
 * the RAM representation of objects. */

/* Copyright (C) 2014 The Regents of the University of California 
 * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */

#include "common.h"
#include "linefile.h"
#include "dystring.h"
#include "jksql.h"
#include "codeBlastScore.h"


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

ret->qName = row[0];
strcpy(ret->code, row[1]);
ret->evalue = row[2];
ret->GI = sqlUnsigned(row[3]);
ret->PI = atof(row[4]);
ret->length = sqlUnsigned(row[5]);
ret->gap = sqlUnsigned(row[6]);
ret->score = sqlUnsigned(row[7]);
ret->seqstart = sqlUnsigned(row[8]);
ret->seqend = sqlUnsigned(row[9]);
strcpy(ret->species, row[10]);
strcpy(ret->product, row[11]);
strcpy(ret->name, row[12]);
}

struct codeBlastScore *codeBlastScoreLoad(char **row)
/* Load a codeBlastScore from row fetched with select * from codeBlastScore
 * from database.  Dispose of this with codeBlastScoreFree(). */
{
struct codeBlastScore *ret;

AllocVar(ret);
ret->qName = cloneString(row[0]);
strcpy(ret->code, row[1]);
ret->evalue = cloneString(row[2]);
ret->GI = sqlUnsigned(row[3]);
ret->PI = atof(row[4]);
ret->length = sqlUnsigned(row[5]);
ret->gap = sqlUnsigned(row[6]);
ret->score = sqlUnsigned(row[7]);
ret->seqstart = sqlUnsigned(row[8]);
ret->seqend = sqlUnsigned(row[9]);
strcpy(ret->species, row[10]);
strcpy(ret->product, row[11]);
strcpy(ret->name, row[12]);
return ret;
}

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

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

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

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

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

if (ret == NULL)
    AllocVar(ret);
ret->qName = sqlStringComma(&s);
sqlFixedStringComma(&s, ret->code, sizeof(ret->code));
ret->evalue = sqlStringComma(&s);
ret->GI = sqlUnsignedComma(&s);
ret->PI = sqlFloatComma(&s);
ret->length = sqlUnsignedComma(&s);
ret->gap = sqlUnsignedComma(&s);
ret->score = sqlUnsignedComma(&s);
ret->seqstart = sqlUnsignedComma(&s);
ret->seqend = sqlUnsignedComma(&s);
sqlFixedStringComma(&s, ret->species, sizeof(ret->species));
sqlFixedStringComma(&s, ret->product, sizeof(ret->product));
sqlFixedStringComma(&s, ret->name, sizeof(ret->name));
*pS = s;
return ret;
}

void codeBlastScoreFree(struct codeBlastScore **pEl)
/* Free a single dynamically allocated codeBlastScore such as created
 * with codeBlastScoreLoad(). */
{
struct codeBlastScore *el;

if ((el = *pEl) == NULL) return;
freeMem(el->qName);
freeMem(el->evalue);
freez(pEl);
}

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

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

void codeBlastScoreOutput(struct codeBlastScore *el, FILE *f, char sep, char lastSep) 
/* Print out codeBlastScore.  Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->qName);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->code);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->evalue);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%u", el->GI);
fputc(sep,f);
fprintf(f, "%g", el->PI);
fputc(sep,f);
fprintf(f, "%u", el->length);
fputc(sep,f);
fprintf(f, "%u", el->gap);
fputc(sep,f);
fprintf(f, "%u", el->score);
fputc(sep,f);
fprintf(f, "%u", el->seqstart);
fputc(sep,f);
fprintf(f, "%u", el->seqend);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->species);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->product);
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 -------------------------------- */

