95efc27edf24bba8d0c7e53d2ef4aead59982826 braney Mon Jun 15 18:29:39 2020 -0700 Merging in our gencode merge code to master branch diff --git src/hg/lib/gencodeAttrs.c src/hg/lib/gencodeAttrs.c new file mode 100644 index 0000000..151e687 --- /dev/null +++ src/hg/lib/gencodeAttrs.c @@ -0,0 +1,187 @@ +/* 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,transcriptId,transcriptName,transcriptType,ccdsId,level,proteinId,transcriptClass"; + +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->transcriptId = row[3]; +ret->transcriptName = row[4]; +ret->transcriptType = row[5]; +ret->ccdsId = row[6]; +ret->level = sqlSigned(row[7]); +ret->proteinId = row[8]; +ret->transcriptClass = row[9]; +} + +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->transcriptId = cloneString(row[3]); +ret->transcriptName = cloneString(row[4]); +ret->transcriptType = cloneString(row[5]); +ret->ccdsId = cloneString(row[6]); +ret->level = sqlSigned(row[7]); +ret->proteinId = cloneString(row[8]); +ret->transcriptClass = cloneString(row[9]); +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[10]; + +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[10]; + +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->transcriptId = sqlStringComma(&s); +ret->transcriptName = sqlStringComma(&s); +ret->transcriptType = sqlStringComma(&s); +ret->ccdsId = sqlStringComma(&s); +ret->level = sqlSignedComma(&s); +ret->proteinId = sqlStringComma(&s); +ret->transcriptClass = 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->transcriptId); +freeMem(el->transcriptName); +freeMem(el->transcriptType); +freeMem(el->ccdsId); +freeMem(el->proteinId); +freeMem(el->transcriptClass); +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->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->ccdsId); +if (sep == ',') fputc('"',f); +fputc(sep,f); +fprintf(f, "%d", el->level); +fputc(sep,f); +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->proteinId); +if (sep == ',') fputc('"',f); +fputc(sep,f); +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->transcriptClass); +if (sep == ',') fputc('"',f); +fputc(lastSep,f); +} + +/* -------------------------------- End autoSql Generated Code -------------------------------- */ +