5c5df1a7446ad3368896deba413360935c334188 kate Wed Feb 10 13:12:47 2016 -0800 Support for multiple GTEx releases/versions (to add V6 track). refs #15645 diff --git src/hg/lib/gtexGeneBed.c src/hg/lib/gtexGeneBed.c index d1e4557..267bab4 100644 --- src/hg/lib/gtexGeneBed.c +++ src/hg/lib/gtexGeneBed.c @@ -1,212 +1,221 @@ /* gtexGeneBed.c was originally generated by the autoSql program, which also * generated gtexGeneBed.h and gtexGeneBed.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 "gtexGeneBed.h" char *gtexGeneBedCommaSepFieldNames = "chrom,chromStart,chromEnd,name,score,strand,geneId,transcriptId,transcriptClass,expCount,expScores"; struct gtexGeneBed *gtexGeneBedLoad(char **row) /* Load a gtexGeneBed from row fetched with select * from gtexGeneBed * from database. Dispose of this with gtexGeneBedFree(). */ { struct gtexGeneBed *ret; AllocVar(ret); ret->expCount = sqlUnsigned(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->geneId = cloneString(row[6]); ret->transcriptId = cloneString(row[7]); ret->transcriptClass = cloneString(row[8]); { int sizeOne; sqlFloatDynamicArray(row[10], &ret->expScores, &sizeOne); assert(sizeOne == ret->expCount); } return ret; } struct gtexGeneBed *gtexGeneBedLoadAll(char *fileName) /* Load all gtexGeneBed from a whitespace-separated file. * Dispose of this with gtexGeneBedFreeList(). */ { struct gtexGeneBed *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); char *row[11]; while (lineFileRow(lf, row)) { el = gtexGeneBedLoad(row); slAddHead(&list, el); } lineFileClose(&lf); slReverse(&list); return list; } struct gtexGeneBed *gtexGeneBedLoadAllByChar(char *fileName, char chopper) /* Load all gtexGeneBed from a chopper separated file. * Dispose of this with gtexGeneBedFreeList(). */ { struct gtexGeneBed *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); char *row[11]; while (lineFileNextCharRow(lf, chopper, row, ArraySize(row))) { el = gtexGeneBedLoad(row); slAddHead(&list, el); } lineFileClose(&lf); slReverse(&list); return list; } struct gtexGeneBed *gtexGeneBedCommaIn(char **pS, struct gtexGeneBed *ret) /* Create a gtexGeneBed out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new gtexGeneBed */ { 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->geneId = sqlStringComma(&s); ret->transcriptId = sqlStringComma(&s); ret->transcriptClass = sqlStringComma(&s); ret->expCount = sqlUnsignedComma(&s); { int i; s = sqlEatChar(s, '{'); AllocArray(ret->expScores, ret->expCount); for (i=0; i<ret->expCount; ++i) { ret->expScores[i] = sqlFloatComma(&s); } s = sqlEatChar(s, '}'); s = sqlEatChar(s, ','); } *pS = s; return ret; } void gtexGeneBedFree(struct gtexGeneBed **pEl) /* Free a single dynamically allocated gtexGeneBed such as created * with gtexGeneBedLoad(). */ { struct gtexGeneBed *el; if ((el = *pEl) == NULL) return; freeMem(el->chrom); freeMem(el->name); freeMem(el->geneId); freeMem(el->transcriptId); freeMem(el->transcriptClass); freeMem(el->expScores); freez(pEl); } void gtexGeneBedFreeList(struct gtexGeneBed **pList) /* Free a list of dynamically allocated gtexGeneBed's */ { struct gtexGeneBed *el, *next; for (el = *pList; el != NULL; el = next) { next = el->next; gtexGeneBedFree(&el); } *pList = NULL; } void gtexGeneBedOutput(struct gtexGeneBed *el, FILE *f, char sep, char lastSep) /* Print out gtexGeneBed. 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); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->geneId); 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->transcriptClass); if (sep == ',') fputc('"',f); fputc(sep,f); fprintf(f, "%u", el->expCount); fputc(sep,f); { int i; if (sep == ',') fputc('{',f); for (i=0; i<el->expCount; ++i) { fprintf(f, "%g", el->expScores[i]); fputc(',', f); } if (sep == ',') fputc('}',f); } fputc(lastSep,f); } /* -------------------------------- End autoSql Generated Code -------------------------------- */ void gtexGeneBedCreateTable(struct sqlConnection *conn, char *table) /* Create expression record format table of given name. */ { char query[1024]; sqlSafef(query, sizeof(query), "CREATE TABLE %s (\n" " chrom varchar(255) not null, # Reference sequence chromosome or scaffold\n" " chromStart int unsigned not null, # Start position in chromosome\n" " chromEnd int unsigned not null, # End position in chromosome\n" " name varchar(255) not null, # Gene symbol\n" " score int unsigned not null, # Score from 0-1000\n" " strand char(1) not null, # + or - for strand\n" " geneId varchar(255) not null, # Ensembl gene ID, referenced in GTEx data tables\n" " transcriptId varchar(255) not null, # Ensembl ID of Canonical transcript; determines genomic position\n" " transcriptClass varchar(255) not null, # GENCODE transcript class (coding, nonCoding, pseudo)\n" " expCount int unsigned not null, # Number of experiment values\n" " expScores longblob not null, # Comma separated list of experiment scores\n" "#Indices\n" " PRIMARY KEY(geneId)\n" ")\n", table); sqlRemakeTable(conn, table, query); } + +char *gtexVersionSuffix(char *table) +/* Return version string for a GTEx track table. For now, just supporting V4 (no suffix) and V6 */ +{ +if (endsWith(table, "V6")) + return("V6"); +return(""); +} +