3b6b332ae9f729a5cbc146116f56b9840dbe2af8
jcasper
  Fri Mar 11 10:59:51 2016 -0800
Updated OMIM display, more linkouts, resolving merge conflict, refs #16796

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 196c95b..0766f49 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -295,30 +295,32 @@
 
 /* See this NCBI web doc for more info about entrezFormat:
  * http://www.ncbi.nlm.nih.gov/entrez/query/static/linking.html */
 char *entrezFormat = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Search&db=%s&term=%s&doptcmdl=%s&tool=genome.ucsc.edu";
 char *entrezPureSearchFormat = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=PureSearch&db=%s&details_term=%s[%s] ";
 char *ncbiGeneFormat = "http://www.ncbi.nlm.nih.gov/gene/%s";
 char *entrezUidFormat = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=%s&list_uids=%d&dopt=%s&tool=genome.ucsc.edu";
 /* db=unists is not mentioned in NCBI's doc... so stick with this usage: */
 char *unistsnameScript = "http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?db=unists";
 char *unistsScript = "http://www.ncbi.nlm.nih.gov/genome/sts/sts.cgi?uid=";
 char *gdbScript = "http://www.gdb.org/gdb-bin/genera/accno?accessionNum=";
 char *cloneDbScript = "http://www.ncbi.nlm.nih.gov/clone?term=";
 char *traceScript = "http://www.ncbi.nlm.nih.gov/Traces/trace.cgi?cmd=retrieve&val=";
 char *genMapDbScript = "http://genomics.med.upenn.edu/perl/genmapdb/byclonesearch.pl?clone=";
 char *uniprotFormat = "http://www.uniprot.org/uniprot/%s";
+char *dbSnpFormat = "http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=%s";
+char *clinVarFormat = "http://www.ncbi.nlm.nih.gov/clinvar/?term=%s[clv_acc]";
 
 /* variables for gv tables */
 char *gvPrevCat = NULL;
 char *gvPrevType = NULL;
 
 /* initialized by getCtList() if necessary: */
 struct customTrack *theCtList = NULL;
 
 /* getDNA stuff actually works when the database doesn't exist! */
 boolean dbIsFound = FALSE;
 
 /* forwards */
 char *getPredMRnaProtSeq(struct genePred *gp);
 void doAltGraphXDetails(struct trackDb *tdb, char *item);
 
@@ -10489,81 +10491,82 @@
     printf("<BR><B>OMIM: ");
     printf("<A HREF=\"%s%s\" target=_blank>", url, itemName);
     printf("%s</A></B>", itemName);
     if (title1 != NULL) printf(": %s", title1);
     if (title2 != NULL) printf(" %s ", title2);
 
     // disable NCBI link until they work it out with OMIM
     /*
     printf("<BR>\n");
     printf("<B>OMIM page at NCBI: ");
     printf("<A HREF=\"%s%s\" target=_blank>", ncbiOmimUrl, itemName);
     printf("%s</A></B><BR>", itemName);
     */
 
     sqlSafef(query, sizeof(query),
-          "select replStr from omimAvRepl where avId=%s;", avId);
+          "select repl2 from omimAv where avId=%s;", avId);
     sr = sqlMustGetResult(conn, query);
     row = sqlNextRow(sr);
     if (row != NULL)
         {
       	if (row[0] != NULL)
-	    {
-            char *replStr;
-            char *chp;
-            replStr= cloneString(row[0]);
-
-            // just take the first AA replacement if there are multiple
-            chp = strstr(replStr, ",");
-            if (chp != NULL) *chp = '\0';
-
-	    printf("<BR><B>Amino Acid Replacement:</B> %s\n", replStr);
-	    }
+	          printf("<BR><B>Amino Acid Replacement:</B> %s\n", row[0]);
 	      }
     sqlFreeResult(&sr);
 
-    dbSnpId = cloneString("-");
     printf("<BR>\n");
-    sqlSafef(query, sizeof(query),
-          "select dbSnpId from omimAvRepl where avId='%s'", avId);
 
+    sqlSafef(query, sizeof(query),
+          "select dbSnpId from omimAv where avId='%s'", avId);
     sr = sqlMustGetResult(conn, query);
     row = sqlNextRow(sr);
+    dbSnpId = cloneString("-");
     if (row != NULL)
-        {
       	dbSnpId = cloneString(row[0]);
-	}
     sqlFreeResult(&sr);
 
     if (!sameWord(dbSnpId, "-"))
         {
-        char *snpTable = hFindLatestSnpTable(database, NULL);
-        if (snpTable != NULL)
-            // NOTE: dbSnpId is not guaranteed to be found in snpTable and it might be
-            // a better idea to always link directly to dbSNP.
-            printf("<B>dbSNP:</B> \n"
-                   "<A HREF=\"../cgi-bin/hgc?hgsid=%s&g=%s&i=%s\">%s</A>",
-                   cartSessionId(cart), snpTable, dbSnpId, dbSnpId);
-        else
+        struct slName *snpIdList, *thisSnpId;
+
+        printf("<b>dbSNP/ClinVar:</b> \n");
+
+        /* for each variant, print name and build a link for it if possible */
+        snpIdList = slNameListFromComma(dbSnpId);
+        while ((thisSnpId = slPopHead(&snpIdList)) != NULL)
             {
-            puts("<B>dbSNP:</B> ");
-            printDbSnpRsUrl(dbSnpId, "%s", dbSnpId);
+            if (strncmp(thisSnpId->name, "rs", 2) == 0) /* dbSnp ID */
+                printDbSnpRsUrl (thisSnpId->name, "%s", thisSnpId->name);
+            else if (strncmp(thisSnpId->name, "SCV", 3) == 0) /* ClinVar ID */
+                {
+                char clinVarUrl[2048];
+                safef (clinVarUrl, sizeof(clinVarUrl), clinVarFormat, thisSnpId->name);
+                printf ("<a href=\"%s\" target=\"_blank\">%s</a>", clinVarUrl, thisSnpId->name);
                 }
+            else
+                printf ("%s", thisSnpId->name);
+
+            slNameFree(&thisSnpId);
+
+            if (snpIdList != NULL)
+                printf (",");
+            }
+        printf("<br>\n");
         }
     }
 
-printf("<HR>");
+printf("<hr>\n");
 printPosOnChrom(chrom, atoi(chromStart), atoi(chromEnd), NULL, FALSE, itemName);
 }
 
 void doOmimAvSnp(struct trackDb *tdb, char *item)
 /* Put up OmimGene track info. */
 {
 genericHeader(tdb, item);
 printOmimAvSnpDetails(tdb, item, FALSE);
 printTrackHtml(tdb);
 }
 
 void doOmimGene2(struct trackDb *tdb, char *item)
 /* Put up OmimGene track info. */
 {
 genericHeader(tdb, item);
@@ -15312,37 +15315,39 @@
 	}
     printf("<A HREF=\"%s&o=%d&g=getDna&i=%s&c=%s&l=%d&r=%d&strand=%s&table=%s\">"
 	   "View DNA for this feature</A><BR>\n",  hgcPathAndSettings(),
 	   el.chromStart, cgiEncode(el.name),
 	   el.chrom, el.chromStart, el.chromEnd, el.strand, tbl);
     freez(&elname);
     }
 printTrackHtml(tdb);
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 }
 
 void printDbSnpRsUrl(char *rsId, char *labelFormat, ...)
 /* Print a link to dbSNP's report page for an rs[0-9]+ ID. */
 {
-printf("<A HREF=\"http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=%s\" "
-       "TARGET=_BLANK>", rsId);
+char dbSnpUrl[2048];
+safef (dbSnpUrl, sizeof(dbSnpUrl), dbSnpFormat, rsId);
+printf ("<a href=\"%s\" target=\"_blank\">", dbSnpUrl);
+
 va_list args;
 va_start(args, labelFormat);
 vprintf(labelFormat, args);
 va_end(args);
-printf("</A>");
+printf("</a>");
 }
 
 char *validateOrGetRsId(char *name, struct sqlConnection *conn)
 /* If necessary, get the rsId from the affy120K or affy10K table,
    given the affyId.  rsId is more common, affy120K is next, affy10K least.
  * returns "valid" if name is already a valid rsId,
            new rsId if it is found in the affy tables, or
            0 if no valid rsId is found */
 {
 char  *rsId = cloneString(name);
 struct affy120KDetails *a120K = NULL;
 struct affy10KDetails *a10K = NULL;
 char   query[512];
 
 if (strncmp(rsId,"rs",2)) /* is not a valid rsId, so it must be an affyId */