1becab6f1a87af952979239f1079e15ddd8ea74e
angie
  Wed Apr 16 16:54:48 2014 -0700
Matt and Tim noticed that the ESP6500 VCF track details had twoprintCustomTrackUrl invocations.  One was in genericClickHandlerPlus
and it used an incorrect name (known issue with using pgSnp display
code for VCF).  The second was inside doVcfTabixDetails, using
the correct name.  I moved doVcfTabixDetails and doVcfDetails out
of genericClickHandlerPlus; now doMiddle calls them, and they call
genericHeader and printTrackHtml in a shared function.
refs #9329

diff --git src/hg/hgc/vcfClick.c src/hg/hgc/vcfClick.c
index b563a7a..c61189f 100644
--- src/hg/hgc/vcfClick.c
+++ src/hg/hgc/vcfClick.c
@@ -364,100 +364,87 @@
 boolean showLeftBase = (rec->chromStart == vcfStart+1);
 (void)vcfRecordTrimAllelesRight(rec);
 char *displayAls[rec->alleleCount];
 makeDisplayAlleles(rec, showLeftBase, leftBase, 20, TRUE, FALSE, displayAls);
 printPosOnChrom(seqName, rec->chromStart, rec->chromEnd, NULL, FALSE, rec->name);
 printf("<B>Reference allele:</B> %s<BR>\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
-
-void doVcfTabixDetails(struct trackDb *tdb, char *item)
-/* Show details of an alignment from a VCF file compressed and indexed by tabix. */
+void doVcfDetailsCore(struct trackDb *tdb, char *fileOrUrl, boolean isTabix)
+/* Show item details using fileOrUrl. */
 {
-knetUdcInstall();
-if (udcCacheTimeout() < 300)
-    udcSetCacheTimeout(300);
+genericHeader(tdb, NULL);
 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 */
+/* protect against temporary network or parsing error */
 struct errCatch *errCatch = errCatchNew();
 if (errCatchStart(errCatch))
     {
+    if (isTabix)
 	vcff = vcfTabixFileMayOpen(fileOrUrl, seqName, start, end, vcfMaxErr, -1);
+    else
+	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<BR>\n", fileOrUrl);
+printTrackHtml(tdb);
+}
+
+
+#ifdef USE_TABIX
+
+void doVcfTabixDetails(struct trackDb *tdb, char *item)
+/* Show details of an alignment from a VCF file compressed and indexed by tabix. */
+{
+knetUdcInstall();
+if (udcCacheTimeout() < 300)
+    udcSetCacheTimeout(300);
+struct sqlConnection *conn = hAllocConnTrack(database, tdb);
+char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, tdb->table, seqName);
+hFreeConn(&conn);
+doVcfDetailsCore(tdb, fileOrUrl, TRUE);
 }
 
 
 #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<BR>\n", fileOrUrl);
+doVcfDetailsCore(tdb, fileOrUrl, FALSE);
 }