95efc27edf24bba8d0c7e53d2ef4aead59982826 braney Mon Jun 15 18:29:39 2020 -0700 Merging in our gencode merge code to master branch diff --git src/hg/lib/gencodeToEntrezGene.c src/hg/lib/gencodeToEntrezGene.c new file mode 100644 index 0000000..c55fc37 --- /dev/null +++ src/hg/lib/gencodeToEntrezGene.c @@ -0,0 +1,123 @@ +/* gencodeToEntrezGene.c was originally generated by the autoSql program, which also + * generated gencodeToEntrezGene.h and gencodeToEntrezGene.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 "gencodeToEntrezGene.h" + + + +char *gencodeToEntrezGeneCommaSepFieldNames = "transcriptId,entrezGeneId"; + +void gencodeToEntrezGeneStaticLoad(char **row, struct gencodeToEntrezGene *ret) +/* Load a row from gencodeToEntrezGene table into ret. The contents of ret will + * be replaced at the next call to this function. */ +{ + +ret->transcriptId = row[0]; +ret->entrezGeneId = sqlSigned(row[1]); +} + +struct gencodeToEntrezGene *gencodeToEntrezGeneLoad(char **row) +/* Load a gencodeToEntrezGene from row fetched with select * from gencodeToEntrezGene + * from database. Dispose of this with gencodeToEntrezGeneFree(). */ +{ +struct gencodeToEntrezGene *ret; + +AllocVar(ret); +ret->transcriptId = cloneString(row[0]); +ret->entrezGeneId = sqlSigned(row[1]); +return ret; +} + +struct gencodeToEntrezGene *gencodeToEntrezGeneLoadAll(char *fileName) +/* Load all gencodeToEntrezGene from a whitespace-separated file. + * Dispose of this with gencodeToEntrezGeneFreeList(). */ +{ +struct gencodeToEntrezGene *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[2]; + +while (lineFileRow(lf, row)) + { + el = gencodeToEntrezGeneLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct gencodeToEntrezGene *gencodeToEntrezGeneLoadAllByChar(char *fileName, char chopper) +/* Load all gencodeToEntrezGene from a chopper separated file. + * Dispose of this with gencodeToEntrezGeneFreeList(). */ +{ +struct gencodeToEntrezGene *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[2]; + +while (lineFileNextCharRow(lf, chopper, row, ArraySize(row))) + { + el = gencodeToEntrezGeneLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct gencodeToEntrezGene *gencodeToEntrezGeneCommaIn(char **pS, struct gencodeToEntrezGene *ret) +/* Create a gencodeToEntrezGene out of a comma separated string. + * This will fill in ret if non-null, otherwise will + * return a new gencodeToEntrezGene */ +{ +char *s = *pS; + +if (ret == NULL) + AllocVar(ret); +ret->transcriptId = sqlStringComma(&s); +ret->entrezGeneId = sqlSignedComma(&s); +*pS = s; +return ret; +} + +void gencodeToEntrezGeneFree(struct gencodeToEntrezGene **pEl) +/* Free a single dynamically allocated gencodeToEntrezGene such as created + * with gencodeToEntrezGeneLoad(). */ +{ +struct gencodeToEntrezGene *el; + +if ((el = *pEl) == NULL) return; +freeMem(el->transcriptId); +freez(pEl); +} + +void gencodeToEntrezGeneFreeList(struct gencodeToEntrezGene **pList) +/* Free a list of dynamically allocated gencodeToEntrezGene's */ +{ +struct gencodeToEntrezGene *el, *next; + +for (el = *pList; el != NULL; el = next) + { + next = el->next; + gencodeToEntrezGeneFree(&el); + } +*pList = NULL; +} + +void gencodeToEntrezGeneOutput(struct gencodeToEntrezGene *el, FILE *f, char sep, char lastSep) +/* Print out gencodeToEntrezGene. Separate fields with sep. Follow last field with lastSep. */ +{ +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->transcriptId); +if (sep == ',') fputc('"',f); +fputc(sep,f); +fprintf(f, "%d", el->entrezGeneId); +fputc(lastSep,f); +} + +/* -------------------------------- End autoSql Generated Code -------------------------------- */ +