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

/* Copyright (C) 2011 The Regents of the University of California 
 * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
#include "common.h"
#include "jksql.h"
#include "foo.h"


struct mrnaAli *mrnaAliLoad(char **row)
/* Load a mrnaAli from row fetched with select * from mrnaAli
 * from database.  Dispose of this with mrnaAliFree(). */
{
struct mrnaAli *ret;
int sizeOne,i;
char *s;

AllocVar(ret);
ret->blockCount = sqlUnsigned(row[15]);
ret->id = sqlUnsigned(row[0]);
ret->readDir = sqlSigned(row[1]);
ret->orientation = sqlSigned(row[2]);
ret->hasIntrons = sqlUnsigned(row[3]);
ret->isEst = sqlUnsigned(row[4]);
ret->score = sqlSigned(row[5]);
strcpy(ret->qAcc, row[6]);
ret->qId = sqlUnsigned(row[7]);
ret->qTotalSize = sqlUnsigned(row[8]);
ret->qStart = sqlUnsigned(row[9]);
ret->qEnd = sqlUnsigned(row[10]);
ret->tStartBac = sqlUnsigned(row[11]);
ret->tStartPos = sqlUnsigned(row[12]);
ret->tEndBac = sqlUnsigned(row[13]);
ret->tEndPos = sqlUnsigned(row[14]);
sqlUnsignedDynamicArray(row[16], &ret->blockSizes, &sizeOne);
assert(sizeOne == ret->blockCount);
sqlUnsignedDynamicArray(row[17], &ret->qBlockStarts, &sizeOne);
assert(sizeOne == ret->blockCount);
sqlUnsignedDynamicArray(row[18], &ret->tBlockBacs, &sizeOne);
assert(sizeOne == ret->blockCount);
sqlUnsignedDynamicArray(row[19], &ret->tBlockStarts, &sizeOne);
assert(sizeOne == ret->blockCount);
sqlUshortDynamicArray(row[20], &ret->startGoods, &sizeOne);
assert(sizeOne == ret->blockCount);
sqlUshortDynamicArray(row[21], &ret->endGoods, &sizeOne);
assert(sizeOne == ret->blockCount);
return ret;
}

struct mrnaAli *mrnaAliCommaIn(char **pS)
/* Create a mrnaAli out of a comma separated string. */
{
struct mrnaAli *ret;
char *s = *pS;
int i;

AllocVar(ret);
ret->id = sqlUnsignedComma(&s);
ret->readDir = sqlSignedComma(&s);
ret->orientation = sqlSignedComma(&s);
ret->hasIntrons = sqlUnsignedComma(&s);
ret->isEst = sqlUnsignedComma(&s);
ret->score = sqlSignedComma(&s);
ret->qAcc = sqlSignedComma(&s);
ret->qId = sqlUnsignedComma(&s);
ret->qTotalSize = sqlUnsignedComma(&s);
ret->qStart = sqlUnsignedComma(&s);
ret->qEnd = sqlUnsignedComma(&s);
ret->tStartBac = sqlUnsignedComma(&s);
ret->tStartPos = sqlUnsignedComma(&s);
ret->tEndBac = sqlUnsignedComma(&s);
ret->tEndPos = sqlUnsignedComma(&s);
ret->blockCount = sqlUnsignedComma(&s);
s = sqlEatChar(s, '{');
AllocArray(ret->blockSizes, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->blockSizes[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
s = sqlEatChar(s, '{');
AllocArray(ret->qBlockStarts, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->qBlockStarts[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
s = sqlEatChar(s, '{');
AllocArray(ret->tBlockBacs, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->tBlockBacs[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
s = sqlEatChar(s, '{');
AllocArray(ret->tBlockStarts, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->tBlockStarts[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
s = sqlEatChar(s, '{');
AllocArray(ret->startGoods, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->startGoods[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
s = sqlEatChar(s, '{');
AllocArray(ret->endGoods, ret->blockCount);
for (i=0; i<ret->blockCount; ++i)
    {
    ret->endGoods[i] = sqlUnsignedComma(&s);
    }
s = sqlEatChar(s, '}');
s = sqlEatChar(s, ',');
*pS = s;
return ret;
}

void mrnaAliFree(struct mrnaAli **pEl)
/* Free a single dynamically allocated mrnaAli such as created
 * with mrnaAliLoad(). */
{
struct mrnaAli *el;

if ((el = *pEl) == NULL) return;
freeMem(el->blockSizes);
freeMem(el->qBlockStarts);
freeMem(el->tBlockBacs);
freeMem(el->tBlockStarts);
freeMem(el->startGoods);
freeMem(el->endGoods);
freez(pEl);
}

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

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

void mrnaAliOutput(struct mrnaAli *el, FILE *f, char sep, char lastSep) 
/* Print out mrnaAli.  Separate fields with sep. Follow last field with lastSep. */
{
int i;
fprintf(f, "%u", el->id, sep);
fputc(sep,f);
fprintf(f, "%d", el->readDir, sep);
fputc(sep,f);
fprintf(f, "%d", el->orientation, sep);
fputc(sep,f);
fprintf(f, "%u", el->hasIntrons, sep);
fputc(sep,f);
fprintf(f, "%u", el->isEst, sep);
fputc(sep,f);
fprintf(f, "%d", el->score, sep);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->qAcc, sep);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%u", el->qId, sep);
fputc(sep,f);
fprintf(f, "%u", el->qTotalSize, sep);
fputc(sep,f);
fprintf(f, "%u", el->qStart, sep);
fputc(sep,f);
fprintf(f, "%u", el->qEnd, sep);
fputc(sep,f);
fprintf(f, "%u", el->tStartBac, sep);
fputc(sep,f);
fprintf(f, "%u", el->tStartPos, sep);
fputc(sep,f);
fprintf(f, "%u", el->tEndBac, sep);
fputc(sep,f);
fprintf(f, "%u", el->tEndPos, sep);
fputc(sep,f);
fprintf(f, "%u", el->blockCount, sep);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->blockSizes[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->qBlockStarts[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->tBlockBacs[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->tBlockStarts[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->startGoods[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(sep,f);
if (sep == ',') fputc('{',f);
for (i=0; i<el->blockCount; ++i)
    {
    fprintf(f, "%u", el->endGoods[i]);
    fputc(',', f);
    }
if (sep == ',') fputc('}',f);
fputc(lastSep,f);
}

