6819e624cfe2476aa5e10be99ebaf8c96e319278
angie
  Tue Aug 9 15:40:00 2011 -0700
Feature #3710 (vcfTabix UI options): added checkbox to enable/disable haplotype sorting display.
diff --git src/hg/lib/vcfUi.c src/hg/lib/vcfUi.c
index 7e603fa..7e5a371 100644
--- src/hg/lib/vcfUi.c
+++ src/hg/lib/vcfUi.c
@@ -33,39 +33,32 @@
 safef(cartVar, sizeof(cartVar), "%s.centerVariantPos", track);
 char ctrPosStr[16];
 safef(ctrPosStr, sizeof(ctrPosStr), "%d", ctrPos);
 cgiMakeHiddenVar(cartVar, ctrPosStr);
 safef(cartVar, sizeof(cartVar), "%s.centerVariantName", track);
 cgiMakeHiddenVar(cartVar, ctrName);
 }
 
 void vcfCfgHaplotypeCenter(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff,
 			   char *thisName, char *thisChrom, int thisPos, char *formName)
 /* If vcff has genotype data, show status and controls for choosing the center variant
  * for haplotype clustering/sorting in hgTracks. */
 {
 if (vcff != NULL && vcff->genotypeCount > 1)
     {
-// cluster haplotypes or just show allele summary?
-//   if clustering haplotypes:
-//      track height?
-//      thicken lines?
-//      outline center variant?
-//      choose center variant?  [hgc option to make this variant's coords the center of viewed region?]
-//      color haplotypes by red/blue or allele bases?
     printf("<TABLE cellpadding=0><TR><TD>"
-	   "<B>Haplotype sorting:</B> using ");
+	   "<B>Haplotype sorting order:</B> using ");
     char cartVar[1024];
     safef(cartVar, sizeof(cartVar), "%s.centerVariantChrom", tdb->track);
     char *centerChrom = cartOptionalString(cart, cartVar);
     if (isEmpty(centerChrom))
 	{
 	// Unspecified in cart -- describe the default action
 	printf(VCF_HAPLOSORT_DEFAULT_DESC " as anchor.</TD></TR>\n");
 	if (isNotEmpty(thisChrom))
 	    {
 	    // but we do have a candidate, so offer to make it the center:
 	    puts("<TR><TD>");
 	    vcfCfgHaplotypeCenterHiddens(tdb->track, thisName, thisChrom, thisPos);
 	    char label[256];
 	    safef(label, sizeof(label), "Use %s", nameOrDefault(thisName, "this variant"));
 	    cgiMakeButton("submit", label);
@@ -147,56 +140,75 @@
 struct errCatch *errCatch = errCatchNew();
 if (errCatchStart(errCatch))
     {
     vcff = vcfTabixFileMayOpen(fileOrUrl, NULL, 0, 0, vcfMaxErr);
     }
 errCatchEnd(errCatch);
 if (errCatch->gotError)
     {
     if (isNotEmpty(errCatch->message->string))
 	warn("unable to open %s: %s", fileOrUrl, errCatch->message->string);
     }
 errCatchFree(&errCatch);
 return vcff;
 }
 
-void vcfCfgHapClusterHeight(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff,
-			    char *name)
+static void vcfCfgHapClusterHeight(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff,
+				   char *name, boolean compositeLevel)
 /* Let the user specify a height for the track. */
 {
 if (vcff != NULL && vcff->genotypeCount > 1)
     {
     printf("<B>Haplotype sorting display height:</B> \n");
-    boolean compositeLevel = isNameAtCompositeLevel(tdb, name);
     int cartHeight = cartUsualIntClosestToHome(cart, tdb, compositeLevel,
 					       VCF_HAP_HEIGHT_VAR, VCF_DEFAULT_HAP_HEIGHT);
     char varName[1024];
     safef(varName, sizeof(varName), "%s." VCF_HAP_HEIGHT_VAR, name);
     cgiMakeIntVarInRange(varName, cartHeight, "Height (in pixels) of track", 5, "10", "2500");
     }
 }
 
+static void vcfCfgHapCluster(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff,
+			     char *name)
+/* Show controls for haplotype-sorting display, which only makes sense to do when
+ * the VCF file describes multiple genotypes. */
+{
+boolean compositeLevel = isNameAtCompositeLevel(tdb, name);
+printf("<B>Enable Haplotype sorting display: </B>");
+boolean hapClustEnabled = cartUsualBooleanClosestToHome(cart, tdb, compositeLevel,
+							VCF_HAP_ENABLED_VAR, TRUE);
+char varName[1024];
+safef(varName, sizeof(varName), "%s." VCF_HAP_ENABLED_VAR, name);
+cgiMakeCheckBox(varName, hapClustEnabled);
+printf("<BR>\n");
+vcfCfgHaplotypeCenter(cart, tdb, vcff, NULL, NULL, 0, "mainForm");
+vcfCfgHapClusterHeight(cart, tdb, vcff, name, compositeLevel);
+//      thicken lines?
+//      outline center variant?
+//      color haplotypes by red/blue or allele bases?
+}
+
 void vcfCfgUi(struct cart *cart, struct trackDb *tdb, char *name, char *title, boolean boxed)
 /* VCF: Variant Call Format.  redmine #3710 */
 {
 boxed = cfgBeginBoxAndTitle(tdb, boxed, title);
 printf("<TABLE%s><TR><TD>", boxed ? " width='100%'" : "");
 struct vcfFile *vcff = vcfHopefullyOpenHeader(cart, tdb);
 if (vcff != NULL)
     {
-    vcfCfgHaplotypeCenter(cart, tdb, vcff, NULL, NULL, 0, "mainForm");
-    vcfCfgHapClusterHeight(cart, tdb, vcff, name);
+    if (vcff->genotypeCount > 1)
+	vcfCfgHapCluster(cart, tdb, vcff, name);
     }
 else
     {
     printf("Sorry, couldn't access VCF file.<BR>\n");
     }
 
 // filter:
 //   by qual column
 //   by filter column
 // color bases like pgSnp or some better palette?
 
 
 printf("</TD></TR></TABLE>");
 
 if (!boxed && fileExists(hHelpFile("hgVcfTrackHelp")))