b7cb97d2942575d92f6385055e172dcbd979ee05 angie Tue Oct 1 13:09:29 2019 -0700 Adding new data type bigDbSnp.as with associated dbSnpDetails.as, for a track based on the new "dbSNP 2.0" schema and JSON downloads. refs #23283 diff --git src/hg/lib/dbSnpDetails.c src/hg/lib/dbSnpDetails.c new file mode 100644 index 0000000..bbe8a1a --- /dev/null +++ src/hg/lib/dbSnpDetails.c @@ -0,0 +1,346 @@ +/* dbSnpDetails.c was originally generated by the autoSql program, which also + * generated dbSnpDetails.h and dbSnpDetails.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 "dbSnpDetails.h" + + + +char *dbSnpDetailsCommaSepFieldNames = "name,freqSourceCount,alleleCounts,alleleTotals,soTermCount,soTerms,clinVarCount,clinVarAccs,clinVarSigs,submitterCount,submitters,pubMedIdCount,pubMedIds"; + +struct dbSnpDetails *dbSnpDetailsLoad(char **row) +/* Load a dbSnpDetails from row fetched with select * from dbSnpDetails + * from database. Dispose of this with dbSnpDetailsFree(). */ +{ +struct dbSnpDetails *ret; + +AllocVar(ret); +ret->freqSourceCount = sqlSigned(row[1]); +ret->soTermCount = sqlSigned(row[4]); +ret->clinVarCount = sqlSigned(row[6]); +ret->submitterCount = sqlSigned(row[9]); +ret->pubMedIdCount = sqlSigned(row[11]); +ret->name = cloneString(row[0]); +{ +int sizeOne; +sqlStringDynamicArray(row[2], &ret->alleleCounts, &sizeOne); +assert(sizeOne == ret->freqSourceCount); +} +{ +int sizeOne; +sqlSignedDynamicArray(row[3], &ret->alleleTotals, &sizeOne); +assert(sizeOne == ret->freqSourceCount); +} +{ +int sizeOne; +sqlSignedDynamicArray(row[5], &ret->soTerms, &sizeOne); +assert(sizeOne == ret->soTermCount); +} +{ +int sizeOne; +sqlStringDynamicArray(row[7], &ret->clinVarAccs, &sizeOne); +assert(sizeOne == ret->clinVarCount); +} +{ +int sizeOne; +sqlStringDynamicArray(row[8], &ret->clinVarSigs, &sizeOne); +assert(sizeOne == ret->clinVarCount); +} +{ +int sizeOne; +sqlStringDynamicArray(row[10], &ret->submitters, &sizeOne); +assert(sizeOne == ret->submitterCount); +} +{ +int sizeOne; +sqlSignedDynamicArray(row[12], &ret->pubMedIds, &sizeOne); +assert(sizeOne == ret->pubMedIdCount); +} +return ret; +} + +struct dbSnpDetails *dbSnpDetailsLoadAll(char *fileName) +/* Load all dbSnpDetails from a whitespace-separated file. + * Dispose of this with dbSnpDetailsFreeList(). */ +{ +struct dbSnpDetails *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[13]; + +while (lineFileRow(lf, row)) + { + el = dbSnpDetailsLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct dbSnpDetails *dbSnpDetailsLoadAllByChar(char *fileName, char chopper) +/* Load all dbSnpDetails from a chopper separated file. + * Dispose of this with dbSnpDetailsFreeList(). */ +{ +struct dbSnpDetails *list = NULL, *el; +struct lineFile *lf = lineFileOpen(fileName, TRUE); +char *row[13]; + +while (lineFileNextCharRow(lf, chopper, row, ArraySize(row))) + { + el = dbSnpDetailsLoad(row); + slAddHead(&list, el); + } +lineFileClose(&lf); +slReverse(&list); +return list; +} + +struct dbSnpDetails *dbSnpDetailsCommaIn(char **pS, struct dbSnpDetails *ret) +/* Create a dbSnpDetails out of a comma separated string. + * This will fill in ret if non-null, otherwise will + * return a new dbSnpDetails */ +{ +char *s = *pS; + +if (ret == NULL) + AllocVar(ret); +ret->name = sqlStringComma(&s); +ret->freqSourceCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->alleleCounts, ret->freqSourceCount); +for (i=0; ifreqSourceCount; ++i) + { + ret->alleleCounts[i] = sqlStringComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->alleleTotals, ret->freqSourceCount); +for (i=0; ifreqSourceCount; ++i) + { + ret->alleleTotals[i] = sqlSignedComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +ret->soTermCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->soTerms, ret->soTermCount); +for (i=0; isoTermCount; ++i) + { + ret->soTerms[i] = sqlSignedComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +ret->clinVarCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->clinVarAccs, ret->clinVarCount); +for (i=0; iclinVarCount; ++i) + { + ret->clinVarAccs[i] = sqlStringComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->clinVarSigs, ret->clinVarCount); +for (i=0; iclinVarCount; ++i) + { + ret->clinVarSigs[i] = sqlStringComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +ret->submitterCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->submitters, ret->submitterCount); +for (i=0; isubmitterCount; ++i) + { + ret->submitters[i] = sqlStringComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +ret->pubMedIdCount = sqlSignedComma(&s); +{ +int i; +s = sqlEatChar(s, '{'); +AllocArray(ret->pubMedIds, ret->pubMedIdCount); +for (i=0; ipubMedIdCount; ++i) + { + ret->pubMedIds[i] = sqlSignedComma(&s); + } +s = sqlEatChar(s, '}'); +s = sqlEatChar(s, ','); +} +*pS = s; +return ret; +} + +void dbSnpDetailsFree(struct dbSnpDetails **pEl) +/* Free a single dynamically allocated dbSnpDetails such as created + * with dbSnpDetailsLoad(). */ +{ +struct dbSnpDetails *el; + +if ((el = *pEl) == NULL) return; +freeMem(el->name); +/* All strings in alleleCounts are allocated at once, so only need to free first. */ +if (el->alleleCounts != NULL) + freeMem(el->alleleCounts[0]); +freeMem(el->alleleCounts); +freeMem(el->alleleTotals); +freeMem(el->soTerms); +/* All strings in clinVarAccs are allocated at once, so only need to free first. */ +if (el->clinVarAccs != NULL) + freeMem(el->clinVarAccs[0]); +freeMem(el->clinVarAccs); +/* All strings in clinVarSigs are allocated at once, so only need to free first. */ +if (el->clinVarSigs != NULL) + freeMem(el->clinVarSigs[0]); +freeMem(el->clinVarSigs); +/* All strings in submitters are allocated at once, so only need to free first. */ +if (el->submitters != NULL) + freeMem(el->submitters[0]); +freeMem(el->submitters); +freeMem(el->pubMedIds); +freez(pEl); +} + +void dbSnpDetailsFreeList(struct dbSnpDetails **pList) +/* Free a list of dynamically allocated dbSnpDetails's */ +{ +struct dbSnpDetails *el, *next; + +for (el = *pList; el != NULL; el = next) + { + next = el->next; + dbSnpDetailsFree(&el); + } +*pList = NULL; +} + +void dbSnpDetailsOutput(struct dbSnpDetails *el, FILE *f, char sep, char lastSep) +/* Print out dbSnpDetails. Separate fields with sep. Follow last field with lastSep. */ +{ +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->name); +if (sep == ',') fputc('"',f); +fputc(sep,f); +fprintf(f, "%d", el->freqSourceCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; ifreqSourceCount; ++i) + { + if (sep == ',') fputc('"',f); + fprintf(f, "%s", el->alleleCounts[i]); + if (sep == ',') fputc('"',f); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; ifreqSourceCount; ++i) + { + fprintf(f, "%d", el->alleleTotals[i]); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +fprintf(f, "%d", el->soTermCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; isoTermCount; ++i) + { + fprintf(f, "%d", el->soTerms[i]); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +fprintf(f, "%d", el->clinVarCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; iclinVarCount; ++i) + { + if (sep == ',') fputc('"',f); + fprintf(f, "%s", el->clinVarAccs[i]); + if (sep == ',') fputc('"',f); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; iclinVarCount; ++i) + { + if (sep == ',') fputc('"',f); + fprintf(f, "%s", el->clinVarSigs[i]); + if (sep == ',') fputc('"',f); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +fprintf(f, "%d", el->submitterCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; isubmitterCount; ++i) + { + if (sep == ',') fputc('"',f); + fprintf(f, "%s", el->submitters[i]); + if (sep == ',') fputc('"',f); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(sep,f); +fprintf(f, "%d", el->pubMedIdCount); +fputc(sep,f); +{ +int i; +if (sep == ',') fputc('{',f); +for (i=0; ipubMedIdCount; ++i) + { + fprintf(f, "%d", el->pubMedIds[i]); + fputc(',', f); + } +if (sep == ',') fputc('}',f); +} +fputc(lastSep,f); +} + +/* -------------------------------- End autoSql Generated Code -------------------------------- */ +