bc5f960c316fcd863ff01af154b8bd67a4dc041a
angie
  Mon Aug 14 15:08:45 2017 -0700
hgVai: offer HGVS output options only when using RefSeq transcripts.  refs #19968 note-8

diff --git src/hg/hgVai/hgVai.c src/hg/hgVai/hgVai.c
index 4784225..41a6b31 100644
--- src/hg/hgVai/hgVai.c
+++ src/hg/hgVai/hgVai.c
@@ -547,31 +547,49 @@
 printf("<div class='sectionLiteHeader'>Select Genes</div>\n");
 if (gotGP)
     printf("The gene predictions selected here will be used ");
 else
     printf("Gene predictions are required in order ");
 printf("to determine the effect of "
        "each variant on genes, for example intronic, missense, splice site, intergenic etc.");
 if (!gotGP)
     printf(" Since this assembly has no gene prediction tracks, "
 	   "the VAI can't provide functional annotations. "
 	   "Please select a different genome.<BR>");
 printf("<BR>\n");
 if (! gotGP)
     return NULL;
 char *firstTrack = ((struct trackDb *)(trackRefList->val))->track;
-char *selected = cartUsualString(cart, "hgva_geneTrack", firstTrack);
+char *cartGeneTrack = cartOptionalString(cart, "hgva_geneTrack");
+if (isNotEmpty(cartGeneTrack))
+    {
+    // Make sure it's actually in trackRefList (might have been carried over from other db)
+    boolean exists = FALSE;
+    struct slRef *ref;
+    for (ref = trackRefList;  ref != NULL;  ref = ref->next)
+        {
+        struct trackDb *tdb = ref->val;
+        if (sameString(cartGeneTrack, tdb->track))
+            {
+            exists = TRUE;
+            break;
+            }
+        }
+    if (!exists)
+        cartGeneTrack = NULL;
+    }
+char *selected = isNotEmpty(cartGeneTrack) ? cartGeneTrack : firstTrack;
 //#*** should show more info about each track... button to pop up track desc?
 
 if (gotGP)
     {
     printf("<SELECT ID='hgva_geneTrack' NAME='hgva_geneTrack'>\n");
     jsOnEventById("change", "hgva_geneTrack", "hgva.changeGeneSource();");
     struct slRef *ref;
     for (ref = trackRefList;  ref != NULL;  ref = ref->next)
 	{
 	struct trackDb *tdb = ref->val;
     if (tdb->subtracks == NULL)
 	printOption(tdb->track, selected, tdb->longLabel);
 	}
     puts("</SELECT><BR>");
     }
@@ -968,54 +986,62 @@
            isVisible ? "block" : "none");
     cartMakeCheckBox(cart, "hgva_txStatus_refSeqStatus", FALSE);
     puts("Include the "
          "<A HREF=" REFSEQ_STATUS_DOC_URL " "
          "TARGET=_BLANK>RefSeq status</A> of each transcript.<BR>");
     puts("</div>");
     }
 printf("<div class=\"noTxStatus\" style=\"display: %s;\">",
        somethingIsVisible ? "none" : "block");
 puts("No transcript status data are available for the selected gene track.");
 puts("</div>");
 puts("<BR>");
 endCollapsibleSection();
 }
 
-static void selectHgvsOut()
-/* Offer HGVS output choices */
+static void selectHgvsOut(char *geneTrack)
+/* Offer HGVS output choices if RefSeq Genes are selected */
 {
 startCollapsibleSection("hgvsOut", "HGVS variant nomenclature", TRUE);
 printf("The <a href='http://www.hgvs.org/' target=_blank>Human Genome Variation Society (HGVS)</a> "
        "has established a "
        "<a href='http://varnomen.hgvs.org/' target=_blank>sequence variant nomenclature</a>, "
        "an international standard used to report variation in "
        "genomic, transcript and protein sequences.<br>\n");
+boolean refSeqSelected = sameString(geneTrack, "refGene") || startsWith("ncbiRefSeq", geneTrack);
+printf("<div id=\"hgvsOptions\" style=\"display: %s;\">", refSeqSelected ? "block" : "none");
 cartMakeCheckBox(cart, "hgva_hgvsG", FALSE);
 printf("Include HGVS genomic (g.) terms in output<br>\n");
 cartMakeCheckBox(cart, "hgva_hgvsCN", FALSE);
 printf("Include HGVS coding (c.) terms if applicable, otherwise noncoding (n.) terms, in output"
        "<br>\n");
 cartMakeCheckBox(cart, "hgva_hgvsP", FALSE);
 printf("Include HGVS protein (p.) terms (if applicable) in output<br>\n");
 cartMakeCheckBox(cart, "hgva_hgvsPAddParens", FALSE);
 printf("When including HGVS protein (p.) terms, add parentheses around changes to emphasize "
        "that they are predictions<br>\n");
 cartMakeCheckBox(cart, "hgva_hgvsBreakDelIns", FALSE);
 printf("For variants that involve both a deletion and insertion, "
        "including multi-nucleotide variants, "
        "include the deleted sequence (e.g. show \"delAGinsTT\" instead of only \"delinsTT\")"
        "<br>\n");
+puts("</div>");
+printf("<div id=\"noHgvs\" style=\"display: %s;\">",
+       refSeqSelected ? "none" : "block");
+printf("Select RefSeq Genes in the \"Select Genes\" section above "
+       "in order to make options appear.\n");
+puts("</div>");
 puts("<br>");
 endCollapsibleSection();
 }
 
 boolean isHg19RegulatoryTrack(struct trackDb *tdb, void *filterData)
 /* For now, just look for a couple specific tracks by tableName. */
 {
 //#*** NEED METADATA
 return (sameString("wgEncodeRegDnaseClusteredV3", tdb->table) ||
 	sameString("wgEncodeRegTfbsClusteredV3", tdb->table));
 }
 
 boolean isHg38RegulatoryTrack(struct trackDb *tdb, void *filterData)
 /* For now, just look for a couple specific tracks by tableName. */
 {
@@ -1145,31 +1171,31 @@
 struct slName *dbNsfpTables = findDbNsfpTables();
 boolean gotSnp = findSnpBed4("", NULL, NULL);
 struct slRef *elTrackRefList = NULL, *scoreTrackRefList = NULL;
 findCons(&elTrackRefList, &scoreTrackRefList);
 struct slRef *cosmicTrackRefList = findTrackRefByName("cosmic");
 boolean hasTxStat = hasTxStatus();
 if (dbNsfpTables == NULL && !gotSnp && elTrackRefList == NULL && scoreTrackRefList == NULL &&
     cosmicTrackRefList == NULL && !hasTxStat)
     return;
 puts("<BR>");
 printf("<div class='sectionLiteHeader'>Select More Annotations (optional)</div>\n");
 // Make wrapper table for collapsible sections:
 puts("<TABLE border=0 cellspacing=5 cellpadding=0 style='padding-left: 10px;'>");
 selectDbNsfp(dbNsfpTables);
 selectTxStatus(hasTxStat, geneTrack);
-selectHgvsOut();
+selectHgvsOut(geneTrack);
 selectDbSnp(gotSnp);
 trackCheckBoxSection("Cosmic", "COSMIC", cosmicTrackRefList);
 trackCheckBoxSection("ConsEl", "Conserved elements", elTrackRefList);
 trackCheckBoxSection("ConsScore", "Conservation scores", scoreTrackRefList);
 puts("</TABLE>");
 }
 
 void selectFiltersFunc()
 /* Options to restrict variants based on gene region/soTerm from gpFx */
 {
 startCollapsibleSection("filtersFunc", "Functional role", FALSE);
 printf("Include variants annotated as<BR>\n");
 jsMakeSetClearContainer();
 cartMakeCheckBox(cart, "hgva_include_intergenic", TRUE);
 printf("intergenic<BR>\n");