c295ff853919b7046caca525927f4856ff775622 chinhli Wed Dec 12 11:19:34 2012 -0800 Track #9269 ExonJunction Primers displayed as a bedDetail track. diff --git src/hg/lib/exonJunctionPrimers.c src/hg/lib/exonJunctionPrimers.c new file mode 100644 index 0000000..42d619a --- /dev/null +++ src/hg/lib/exonJunctionPrimers.c @@ -0,0 +1,218 @@ +/* exonJunctionPrimers.c was originally generated by the autoSql program, which also + * generated exonJunctionPrimers.h and exonJunctionPrimers.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 "exonJunctionPrimers.h" + + +struct exonJunctionPrimers *exonJunctionPrimersLoad(char **row) +/* Load a exonJunctionPrimers from row fetched with select * from exonJunctionPrimers + * from database. Dispose of this with exonJunctionPrimersFree(). */ +{ +struct exonJunctionPrimers *ret; + +AllocVar(ret); +ret->blockCount = sqlSigned(row[9]); +ret->chrom = cloneString(row[0]); +ret->chromStart = sqlUnsigned(row[1]); +ret->chromEnd = sqlUnsigned(row[2]); +ret->name = cloneString(row[3]); +ret->score = sqlUnsigned(row[4]); +safecpy(ret->strand, sizeof(ret->strand), row[5]); +ret->thickStart = sqlUnsigned(row[6]); +ret->thickEnd = sqlUnsigned(row[7]); +ret->reserved = sqlUnsigned(row[8]); +{ +int sizeOne; +sqlSignedDynamicArray(row[10], &ret->blockSizes, &sizeOne); +assert(sizeOne == ret->blockCount); +} +{ +int sizeOne; +sqlSignedDynamicArray(row[11], &ret->chromStarts, &sizeOne); +assert(sizeOne == ret->blockCount); +} +ret->id = cloneString(row[12]); +ret->description = cloneString(row[13]); +return ret; +} + +struct exonJunctionPrimers *exonJunctionPrimersLoadAll(char *fileName) +/* Load all exonJunctionPrimers from a whitespace-separated file. + * Dispose of this with exonJunctionPrimersFreeList(). */ +{ +struct exonJunctionPrimers *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[14]; + +while (lineFileRow(lf, row)) + { + el = exonJunctionPrimersLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct exonJunctionPrimers *exonJunctionPrimersLoadAllByChar(char *fileName, char chopper) +/* Load all exonJunctionPrimers from a chopper separated file. + * Dispose of this with exonJunctionPrimersFreeList(). */ +{ +struct exonJunctionPrimers *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[14]; + +while (lineFileNextCharRow(lf, chopper, row, ArraySize(row))) + { + el = exonJunctionPrimersLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct exonJunctionPrimers *exonJunctionPrimersCommaIn(char **pS, struct exonJunctionPrimers *ret) +/* Create a exonJunctionPrimers out of a comma separated string. + * This will fill in ret if non-null, otherwise will + * return a new exonJunctionPrimers */ +{ +char *s = *pS; + +if (ret == NULL) + AllocVar(ret); +ret->chrom = sqlStringComma(&s); +ret->chromStart = sqlUnsignedComma(&s); +ret->chromEnd = sqlUnsignedComma(&s); +ret->name = sqlStringComma(&s); +ret->score = sqlUnsignedComma(&s); +sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand)); +ret->thickStart = sqlUnsignedComma(&s); +ret->thickEnd = sqlUnsignedComma(&s); +ret->reserved = sqlUnsignedComma(&s); +ret->blockCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->blockSizes, ret->blockCount); +for (i=0; i<ret->blockCount; ++i) + { + ret->blockSizes[i] = sqlSignedComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->chromStarts, ret->blockCount); +for (i=0; i<ret->blockCount; ++i) + { + ret->chromStarts[i] = sqlSignedComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +ret->id = sqlStringComma(&s); +ret->description = sqlStringComma(&s); +*pS = s; +return ret; +} + +void exonJunctionPrimersFree(struct exonJunctionPrimers **pEl) +/* Free a single dynamically allocated exonJunctionPrimers such as created + * with exonJunctionPrimersLoad(). */ +{ +struct exonJunctionPrimers *el; + +if ((el = *pEl) == NULL) return; +freeMem(el->chrom); +freeMem(el->name); +freeMem(el->blockSizes); +freeMem(el->chromStarts); +freeMem(el->id); +freeMem(el->description); +freez(pEl); +} + +void exonJunctionPrimersFreeList(struct exonJunctionPrimers **pList) +/* Free a list of dynamically allocated exonJunctionPrimers's */ +{ +struct exonJunctionPrimers *el, *next; + +for (el = *pList; el != NULL; el = next) + { + next = el->next; + exonJunctionPrimersFree(&el); + } +*pList = NULL; +} + +void exonJunctionPrimersOutput(struct exonJunctionPrimers *el, FILE *f, char sep, char lastSep) +/* Print out exonJunctionPrimers. Separate fields with sep. Follow last field with lastSep. */ +{ +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->thickStart); +fputc(sep,f); +fprintf(f, "%u", el->thickEnd); +fputc(sep,f); +fprintf(f, "%u", el->reserved); +fputc(sep,f); +fprintf(f, "%d", el->blockCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; i<el->blockCount; ++i) + { + fprintf(f, "%d", el->blockSizes[i]); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; i<el->blockCount; ++i) + { + fprintf(f, "%d", el->chromStarts[i]); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->id); +if (sep == ',') fputc('"',f); +fputc(sep,f); +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->description); +if (sep == ',') fputc('"',f); +fputc(lastSep,f); +} + +/* -------------------------------- End autoSql Generated Code -------------------------------- */ +