e8405a958dae40b261b2eadcd59a20edc64761f1 angie Wed May 13 15:25:04 2020 -0700 VCF details and track controls: use "sample" instead of "haplotype" when displaying SARS-CoV-2 data because viruses are not diploid. refs #25409 Also don't display "leaf cluster" shape option, which applies only to the center-weighted haplotype clustering, unless that method is selected. diff --git src/hg/lib/vcfUi.c src/hg/lib/vcfUi.c index 7cfd5e8..045f92c 100644 --- src/hg/lib/vcfUi.c +++ src/hg/lib/vcfUi.c @@ -28,61 +28,89 @@ static void vcfCfgHaplotypeCenterHiddens(char *track, char *ctrName, char *ctrChrom, int ctrPos) /* Make hidden form inputs and button for setting the center variant for haplotype * clustering/sorting in hgTracks. */ { char cartVar[1024]; safef(cartVar, sizeof(cartVar), "%s.centerVariantChrom", track); cgiMakeHiddenVar(cartVar, ctrChrom); 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); } +char *vcfHaplotypeOrSample(struct cart *cart) +/* Return "Sample" if the current organism is uniploid (like SARS-CoV-2), "Haplotype" otherwise. */ +{ +// We should make a better way of determining whether the organism is diploid, +// but for now this will prevent David from being bothered by diploid terminology +// when viewing SARS-CoV-2 variants: +return sameOk(cartOptionalString(cart, "db"), "wuhCor1") ? "Sample" : "Haplotype"; +} + void vcfCfgHaplotypeCenter(struct cart *cart, struct trackDb *tdb, char *track, boolean parentLevel, 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) { printf("using "); char *centerChrom = cartOptionalStringClosestToHome(cart, tdb, parentLevel, "centerVariantChrom"); if (isEmpty(centerChrom)) { // Unspecified in cart -- describe the default action printf(VCF_HAPLOSORT_DEFAULT_DESC " as anchor.\n"); if (isNotEmpty(thisChrom)) { // but we do have a candidate, so offer to make it the center: puts(""); vcfCfgHaplotypeCenterHiddens(track, thisName, thisChrom, thisPos); char label[256]; safef(label, sizeof(label), "Use %s", nameOrDefault(thisName, "this variant")); cgiMakeButton("setCenterSubmit", label); printf(" as anchor\n"); } else - printf("To anchor the sorting to a particular variant, " + { + printf(""); + char *hapOrSample = vcfHaplotypeOrSample(cart); + if (sameString(hapOrSample, "Sample")) + { + puts("Samples are clustered by similarity around a central variant. " + "Samples are reordered for display using the clustering tree, which is " + "drawn in the left label area."); + } + else + { + puts("If this mode is selected and genotypes are phased or homozygous, " + "then each genotype is split into two independent haplotypes. " + "These local haplotypes are clustered by similarity around a central variant. " + "Haplotypes are reordered for display using the clustering tree, which is " + "drawn in the left label area. " + "Local haplotype blocks can often be identified using this display."); + } + printf("
To anchor the sorting to a particular variant, " "click on the variant in the genome browser, " "and then click on the 'Use this variant' button on the next page." "\n"); } + } else { // Describe the one specified in cart. int centerPos = cartUsualIntClosestToHome(cart, tdb, parentLevel, "centerVariantPos", -1); char *centerName = cartStringClosestToHome(cart, tdb, parentLevel, "centerVariantName"); if (isNotEmpty(thisChrom)) { // These form inputs are for either "use me" or clear: vcfCfgHaplotypeCenterHiddens(track, thisName, thisChrom, thisPos); // Is this variant the same as the center variant specified in cart? if (sameString(thisChrom, centerChrom) && sameString(thisName, centerName) && thisPos == centerPos) printf("this variant as anchor.\n"); else @@ -116,52 +144,60 @@ cgiMakeButtonWithOnClick("clearCenterSubmit", "Clear selection", NULL, onClick->string); printf(" (use " VCF_HAPLOSORT_DEFAULT_DESC ")\n"); } } } static void vcfCfgHaplotypeMethod(struct cart *cart, struct trackDb *tdb, char *track, boolean parentLevel, struct vcfFile *vcff) /* If vcff has genotype data, offer the option of whether to cluster or just use the order * of genotypes in the VCF file. For clustering, show status and controls for choosing the * center variant for haplotype clustering/sorting in hgTracks. */ { if (vcff != NULL && vcff->genotypeCount > 1) { printf("\n", vcfHaplotypeOrSample(cart)); + // If trackDb specifies a treeFile, offer that as an option char *hapMethod = cartOrTdbString(cart, tdb, VCF_HAP_METHOD_VAR, VCF_DEFAULT_HAP_METHOD); + char *hapMethodTdb = trackDbSetting(tdb, VCF_HAP_METHOD_VAR); char varName[1024]; safef(varName, sizeof(varName), "%s." VCF_HAP_METHOD_VAR, track); + if (hapMethodTdb && startsWithWord("treeFile", hapMethodTdb)) + { + puts(""); + } + printf("
" - "Haplotype sorting order:
\n"); + "%s sorting order:
"); + cgiMakeRadioButton(varName, VCF_HAP_METHOD_TREE_FILE, + startsWithWord(VCF_HAP_METHOD_TREE_FILE, hapMethod)); + printf("using the tree specified in file associated with track
"); cgiMakeRadioButton(varName, VCF_HAP_METHOD_CENTER_WEIGHTED, sameString(hapMethod, VCF_HAP_METHOD_CENTER_WEIGHTED)); printf(""); vcfCfgHaplotypeCenter(cart, tdb, track, parentLevel, vcff, NULL, NULL, 0, "mainForm"); puts("
"); cgiMakeRadioButton(varName, VCF_HAP_METHOD_FILE_ORDER, sameString(hapMethod, VCF_HAP_METHOD_FILE_ORDER)); - puts("using the order in which samples appear in the underlying VCF file"); - // If trackDb specifies a treeFile, offer that as an option - char *hapMethodTdb = trackDbSetting(tdb, VCF_HAP_METHOD_VAR); - if (hapMethodTdb && startsWithWord("treeFile", hapMethodTdb)) - { - puts("
"); - cgiMakeRadioButton(varName, VCF_HAP_METHOD_TREE_FILE, - startsWithWord(VCF_HAP_METHOD_TREE_FILE, hapMethod)); - printf("using the tree specified in file associated with track"); - } - puts("
"); + puts("using the order in which samples appear in the underlying VCF file"); + puts(""); + jsInlineF("$('input[type=radio][name=\"%s\"]').change(function() { " + "if (this.value == '"VCF_HAP_METHOD_CENTER_WEIGHTED"') {" + " $('#leafShapeContainer').show();" + "} else {" + " $('#leafShapeContainer').hide();" + "}});\n", + varName); } } //TODO: share this code w/hgTracks, hgc in hg/lib/vcfFile.c static struct vcfFile *vcfHopefullyOpenHeader(struct cart *cart, struct trackDb *tdb) /* Defend against network errors and return the vcfFile object with header data, or NULL. */ { knetUdcInstall(); if (udcCacheTimeout() < 300) udcSetCacheTimeout(300); char *fileOrUrl = trackDbSetting(tdb, "bigDataUrl"); if (isEmpty(fileOrUrl)) { char *db = cartString(cart, "db"); char *table = tdb->table; @@ -200,89 +236,97 @@ if (isNotEmpty(errCatch->message->string)) warn("unable to open %s: %s", fileOrUrl, errCatch->message->string); } errCatchFree(&errCatch); return vcff; } static void vcfCfgHapClusterEnable(struct cart *cart, struct trackDb *tdb, char *name, boolean parentLevel) /* Let the user enable/disable haplotype sorting display. */ { boolean hapClustEnabled = cartOrTdbBoolean(cart, tdb, VCF_HAP_ENABLED_VAR, TRUE); char cartVar[1024]; safef(cartVar, sizeof(cartVar), "%s." VCF_HAP_ENABLED_VAR, name); cgiMakeCheckBox(cartVar, hapClustEnabled); -printf("Enable Haplotype sorting display
\n"); +printf("Enable %s sorting display
\n", vcfHaplotypeOrSample(cart)); } static void vcfCfgHapClusterColor(struct cart *cart, struct trackDb *tdb, char *name, boolean parentLevel) /* Let the user choose how to color the sorted haplotypes. */ { -printf("Haplotype coloring scheme:
\n"); +printf("Allele coloring scheme:
\n"); char *colorBy = cartOrTdbString(cart, tdb, VCF_HAP_COLORBY_VAR, VCF_DEFAULT_HAP_COLORBY); char varName[1024]; safef(varName, sizeof(varName), "%s." VCF_HAP_COLORBY_VAR, name); cgiMakeRadioButton(varName, VCF_HAP_COLORBY_ALTONLY, sameString(colorBy, VCF_HAP_COLORBY_ALTONLY)); printf("reference alleles invisible, alternate alleles in black
\n"); cgiMakeRadioButton(varName, VCF_HAP_COLORBY_REFALT, sameString(colorBy, VCF_HAP_COLORBY_REFALT)); printf("reference alleles in blue, alternate alleles in red
\n"); cgiMakeRadioButton(varName, VCF_HAP_COLORBY_BASE, sameString(colorBy, VCF_HAP_COLORBY_BASE)); printf("first base of allele (A = red, C = blue, G = green, T = magenta)
\n"); } static void vcfCfgHapClusterTreeAngle(struct cart *cart, struct trackDb *tdb, char *name, boolean parentLevel) /* Let the user choose branch shape. */ { -printf("Haplotype clustering tree leaf shape:
\n"); +// This option applies only to center-weighted clustering; don't show option when some other +// method is selected. +char *hapMethod = cartOrTdbString(cart, tdb, VCF_HAP_METHOD_VAR, VCF_DEFAULT_HAP_METHOD); +printf("
\n", + differentString(hapMethod, VCF_HAP_METHOD_CENTER_WEIGHTED) ? " style='display: none;'" : ""); +printf("%s clustering tree leaf shape:
\n", vcfHaplotypeOrSample(cart)); char *treeAngle = cartOrTdbString(cart, tdb, VCF_HAP_TREEANGLE_VAR, VCF_DEFAULT_HAP_TREEANGLE); char varName[1024]; safef(varName, sizeof(varName), "%s." VCF_HAP_TREEANGLE_VAR, name); cgiMakeRadioButton(varName, VCF_HAP_TREEANGLE_TRIANGLE, sameString(treeAngle, VCF_HAP_TREEANGLE_TRIANGLE)); -printf("draw leaf clusters as <
\n"); +printf("draw branches whose samples are all identical as <
\n"); cgiMakeRadioButton(varName, VCF_HAP_TREEANGLE_RECTANGLE, sameString(treeAngle, VCF_HAP_TREEANGLE_RECTANGLE)); -printf("draw leaf clusters as [
\n"); +printf("draw branches whose samples are all identical as [
\n"); +puts("
"); } static void vcfCfgHapClusterHeight(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff, char *name, boolean parentLevel) /* Let the user specify a height for the track. */ { if (vcff != NULL && vcff->genotypeCount > 1) { - printf("Haplotype sorting display height: \n"); + printf("%s sorting display height: \n", vcfHaplotypeOrSample(cart)); int cartHeight = cartOrTdbInt(cart, tdb, 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, "4", "2500"); puts("
"); } } static void vcfCfgHapCluster(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff, char *name, boolean parentLevel) /* Show controls for haplotype-sorting display, which only makes sense to do when * the VCF file describes multiple genotypes. */ { +char *hapOrSample = vcfHaplotypeOrSample(cart); +printf("

%s sorting display

\n", hapOrSample); vcfCfgHapClusterEnable(cart, tdb, name, parentLevel); vcfCfgHaplotypeMethod(cart, tdb, name, parentLevel, vcff); -vcfCfgHapClusterColor(cart, tdb, name, parentLevel); vcfCfgHapClusterTreeAngle(cart, tdb, name, parentLevel); +vcfCfgHapClusterColor(cart, tdb, name, parentLevel); vcfCfgHapClusterHeight(cart, tdb, vcff, name, parentLevel); } static void vcfCfgMinQual(struct cart *cart, struct trackDb *tdb, struct vcfFile *vcff, char *name, boolean parentLevel) /* If checkbox is checked, apply minimum value filter to QUAL column. */ { char cartVar[1024]; safef(cartVar, sizeof(cartVar), "%s." VCF_APPLY_MIN_QUAL_VAR, name); boolean applyFilter = cartOrTdbBoolean(cart, tdb, VCF_APPLY_MIN_QUAL_VAR, VCF_DEFAULT_APPLY_MIN_QUAL); cgiMakeCheckBox(cartVar, applyFilter); printf("Exclude variants with Quality/confidence score (QUAL) score less than\n"); double minQual = cartOrTdbDouble(cart, tdb, VCF_MIN_QUAL_VAR, VCF_DEFAULT_MIN_QUAL); safef(cartVar, sizeof(cartVar), "%s." VCF_MIN_QUAL_VAR, name); @@ -339,37 +383,30 @@ "0.0", "0.5"); puts("
"); } 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("", boxed ? " width='100%'" : ""); struct vcfFile *vcff = vcfHopefullyOpenHeader(cart, tdb); if (vcff != NULL) { boolean parentLevel = isNameAtParentLevel(tdb, name); if (vcff->genotypeCount > 1) { - puts("

Haplotype sorting display

"); - puts("

When this display mode is enabled and genotypes are phased or homozygous, " - "each genotype is split into two independent haplotypes. " - "These local haplotypes are clustered by similarity around a central variant. " - "Haplotypes are reordered for display using the clustering tree, which is " - "drawn in the left label area. " - "Local haplotype blocks can often be identified using this display.

"); vcfCfgHapCluster(cart, tdb, vcff, name, parentLevel); } if (differentString(tdb->track,"evsEsp6500")) { puts("

Filters

"); vcfCfgMinQual(cart, tdb, vcff, name, parentLevel); vcfCfgFilterColumn(cart, tdb, vcff, name, parentLevel); } vcfCfgMinAlleleFreq(cart, tdb, vcff, name, parentLevel); } else { printf("Sorry, couldn't access VCF file.
\n"); }