8a0946dd6870f10cde056ba243f1fb4ec1fd16b4 angie Thu Feb 27 11:58:33 2014 -0800 Adding support for plain VCF custom tracks (as opposed to VCF+tabix),since users seem to want to upload VCF, and as long as the file is not too big it will work OK. This means adding a new track type vcf (as opposed to vcfTabix) and supporting it in hgTracks, hgTrackUi, hgc, hgTables and hgVai. (and others I've forgotten?) refs #12416 diff --git src/hg/hgc/vcfClick.c src/hg/hgc/vcfClick.c index 123941d..80b82c8 100644 --- src/hg/hgc/vcfClick.c +++ src/hg/hgc/vcfClick.c @@ -1,31 +1,25 @@ /* vcfTrack -- handlers for Variant Call Format data. */ -#ifdef USE_TABIX - #include "common.h" #include "dystring.h" #include "errCatch.h" #include "hCommon.h" #include "hdb.h" #include "hgc.h" #include "htmshell.h" #include "jsHelper.h" -#if (defined USE_TABIX && defined KNETFILE_HOOKS) -#include "knetUdc.h" -#include "udc.h" -#endif//def USE_TABIX && KNETFILE_HOOKS #include "pgSnp.h" #include "regexHelper.h" #include "trashDir.h" #include "vcf.h" #include "vcfUi.h" #define NA "n/a" static void printKeysWithDescriptions(struct vcfFile *vcff, int wordCount, char **words, struct vcfInfoDef *infoDefs) /* Given an array of keys, print out a list of values with * descriptions if descriptions are available. */ { int i; for (i = 0; i < wordCount; i++) @@ -367,38 +361,45 @@ unsigned int vcfStart = vcfRecordTrimIndelLeftBase(rec); boolean showLeftBase = (rec->chromStart == vcfStart+1); char *displayAls[rec->alleleCount]; makeDisplayAlleles(rec, showLeftBase, leftBase, 20, TRUE, FALSE, displayAls); printPosOnChrom(seqName, rec->chromStart, rec->chromEnd, NULL, FALSE, rec->name); printf("Reference allele: %s
\n", displayAls[0]); vcfAltAlleleDetails(rec, displayAls); vcfQualDetails(rec); vcfFilterDetails(rec); vcfInfoDetails(rec); pgSnpCodingDetail(rec); makeDisplayAlleles(rec, showLeftBase, leftBase, 5, FALSE, TRUE, displayAls); vcfGenotypesDetails(rec, tdb->track, displayAls); } +#ifdef USE_TABIX + +#if (defined KNETFILE_HOOKS) +#include "knetUdc.h" +#include "udc.h" +#endif//def KNETFILE_HOOKS + void doVcfTabixDetails(struct trackDb *tdb, char *item) /* Show details of an alignment from a VCF file compressed and indexed by tabix. */ { -#if (defined USE_TABIX && defined KNETFILE_HOOKS) +#if (defined KNETFILE_HOOKS) knetUdcInstall(); if (udcCacheTimeout() < 300) udcSetCacheTimeout(300); -#endif//def USE_TABIX && KNETFILE_HOOKS +#endif//def KNETFILE_HOOKS int start = cartInt(cart, "o"); int end = cartInt(cart, "t"); struct sqlConnection *conn = hAllocConnTrack(database, tdb); char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, tdb->table, seqName); hFreeConn(&conn); int vcfMaxErr = -1; struct vcfFile *vcff = NULL; /* protect against temporary network error */ struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { vcff = vcfTabixFileMayOpen(fileOrUrl, seqName, start, end, vcfMaxErr, -1); } errCatchEnd(errCatch); if (errCatch->gotError) @@ -408,15 +409,59 @@ } errCatchFree(&errCatch); if (vcff != NULL) { struct vcfRecord *rec; for (rec = vcff->records; rec != NULL; rec = rec->next) if (rec->chromStart == start && rec->chromEnd == end) // in pgSnp mode, don't get name vcfRecordDetails(tdb, rec); } else printf("Sorry, unable to open %s
\n", fileOrUrl); } #endif // no USE_TABIX + + +void doVcfDetails(struct trackDb *tdb, char *item) +/* Show details of an alignment from an uncompressed VCF file. */ +{ +int start = cartInt(cart, "o"); +int end = cartInt(cart, "t"); +struct customTrack *ct = lookupCt(tdb->track); +struct sqlConnection *conn = NULL; +char *table = tdb->table; +if (ct) + { + conn = hAllocConn(CUSTOM_TRASH); + table = ct->dbTableName; + } +else + conn = hAllocConnTrack(database, tdb); +char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, table, seqName); +hFreeConn(&conn); +int vcfMaxErr = -1; +struct vcfFile *vcff = NULL; +/* protect against parsing error */ +struct errCatch *errCatch = errCatchNew(); +if (errCatchStart(errCatch)) + { + vcff = vcfFileMayOpen(fileOrUrl, seqName, start, end, vcfMaxErr, -1, TRUE); + } +errCatchEnd(errCatch); +if (errCatch->gotError) + { + if (isNotEmpty(errCatch->message->string)) + warn("%s", errCatch->message->string); + } +errCatchFree(&errCatch); +if (vcff != NULL) + { + struct vcfRecord *rec; + for (rec = vcff->records; rec != NULL; rec = rec->next) + if (rec->chromStart == start && rec->chromEnd == end) // in pgSnp mode, don't get name + vcfRecordDetails(tdb, rec); + } +else + printf("Sorry, unable to open %s
\n", fileOrUrl); +}