7a0635be123f35cc0b5063af03911a70ecbc9841 angie Fri Jun 1 17:30:41 2012 -0700 Track #7964 (1000 Genomes Phase 1 Variant Calls): adding trackDb entryand code support for database table that has per-chromosome fileNames because 1000 Genomes provides enormous per-chromosome files. This is very similar to code support for per-chromosome BAM. To-do: refactor out bam-specific code and trackDbCustom.c's tdbBigFileName to use bbiNameFromSettingOrTable(Chrom). diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index 81196bc..0f99ec1 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -5079,29 +5079,66 @@ { char *tdbType = findTypeForTable(database, parent, table, ctLookupName); return (tdbType && startsWithWord(type, tdbType)); } boolean hIsBigBed(char *database, char *table, struct trackDb *parent, struct customTrack *(*ctLookupName)(char *table)) /* Return TRUE if table corresponds to a bigBed file. * if table has no parent trackDb pass NULL for parent * If this is a custom track, pass in function ctLookupName(table) which looks up a * custom track by name, otherwise pass NULL */ { return trackIsType(database, table, parent, "bigBed", ctLookupName); } -char *bbiNameFromSettingOrTable(struct trackDb *tdb, struct sqlConnection *conn, char *table) -/* Return file name from bigDataUrl or little table. */ -{ -char *fileName = cloneString(trackDbSetting(tdb, "bigDataUrl")); -if (fileName == NULL) - { - char query[256]; +static char *bbiNameFromTableChrom(struct sqlConnection *conn, char *table, char *seqName) +/* Return file name from table. If table has a seqName column, then grab the + * row associated with chrom (which can be e.g. '1' not 'chr1' if that is the + * case in the big remote file). */ +{ +boolean checkSeqName = (sqlFieldIndex(conn, table, "seqName") >= 0); +if (checkSeqName && seqName == NULL) + errAbort("bamFileNameFromTable: table %s has seqName column, but NULL seqName passed in", + table); +char query[512]; +if (checkSeqName) + safef(query, sizeof(query), "select fileName from %s where seqName = '%s'", + table, seqName); +else safef(query, sizeof(query), "select fileName from %s", table); +char *fileName = sqlQuickString(conn, query); +if (fileName == NULL && checkSeqName) + { + if (startsWith("chr", seqName)) + safef(query, sizeof(query), "select fileName from %s where seqName = '%s'", + table, seqName+strlen("chr")); + else + safef(query, sizeof(query), "select fileName from %s where seqName = 'chr%s'", + table, seqName); fileName = sqlQuickString(conn, query); + } if (fileName == NULL) + { + if (checkSeqName) + errAbort("Missing fileName for seqName '%s' in %s table", seqName, table); + else errAbort("Missing fileName in %s table", table); } return fileName; } + +char *bbiNameFromSettingOrTableChrom(struct trackDb *tdb, struct sqlConnection *conn, char *table, + char *seqName) +/* Return file name from bigDataUrl or little table (which might have a seqName column). */ +{ +char *fileName = cloneString(trackDbSetting(tdb, "bigDataUrl")); +if (fileName == NULL) + fileName = bbiNameFromTableChrom(conn, table, seqName); +return fileName; +} + +char *bbiNameFromSettingOrTable(struct trackDb *tdb, struct sqlConnection *conn, char *table) +/* Return file name from bigDataUrl or little table. */ +{ +return bbiNameFromSettingOrTableChrom(tdb, conn, table, NULL); +}