e67106d5cf1204021cada70c1ca43a92bd3b346d
chmalee
  Wed Aug 21 16:54:25 2019 -0700
Adding links to dbSnp hgc pages if the position is supported over at MuPIT, refs #24020

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 167fb73..ef89bc2 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -18499,30 +18499,54 @@
 	struct trackDb *gcTdb = hashFindVal(trackHash, gcTable);
 	if (gcTdb != NULL)
 	    {
 	    printf("<TR><TD colspan=2>><B><A HREF=\"%s", hgTracksPathAndSettings());
 	    // If gcTable is hidden, make it dense; otherwise, leave it alone.
 	    if (sameString("hide",
 			   cartUsualString(cart, gcTable,
 					   trackDbSettingOrDefault(gcTdb, "visibility", "hide"))))
 		printf("&%s=dense", gcTable);
 	    printf("\">%s SNP</A> </B></TD></TR>\n", gcTdb->shortLabel);
 	    }
 	}
     }
 }
 
+static void checkForMupit(struct sqlConnection *conn, struct trackDb *tdb, int start)
+/* Print a link to MuPIT if the item is in the mupitRanges table */
+{
+if (sqlTableExists(conn, "mupitRanges"))
+    {
+    char *doLink = NULL;
+    char query[512];
+    sqlSafef(query, sizeof(query),
+        "select * from mupitRanges where chrom='%s' and chromStart <= %d and chromEnd >= %d",
+        seqName, start, start);
+    doLink = sqlQuickString(conn, query);
+    if (doLink != NULL)
+        {
+        int mupitPosition = start + 1; // mupit uses 1-based coords
+        printf("<TR><TD colspan=2><B>");
+        if (sameString(database, "hg19"))
+            printf("<A HREF=\"http://hg19.cravat.us/MuPIT_Interactive/?gm=%s:%d\">", seqName, mupitPosition);
+        else if (sameString(database, "hg38"))
+            printf("<A HREF=\"http://mupit.icm.jhu.edu/MuPIT_Interactive/?gm=%s:%d\">", seqName, mupitPosition);
+        printf("MuPIT Structure</A></B></TD></TR>\n");
+        }
+    }
+}
+
 void printOtherSnpMappings(char *table, char *name, int start,
 			   struct sqlConnection *conn, int rowOffset)
 /* If this SNP (from any bed4+ table) is not uniquely mapped, print the other mappings. */
 {
 char query[512];
 sqlSafef(query, sizeof(query), "select * from %s where name='%s'",
       table, name);
 struct sqlResult *sr = sqlGetResult(conn, query);
 int snpCount = 0;
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     struct bed *snp = bedLoad3(row + rowOffset);
     if (snp->chromStart != start || differentString(snp->chrom, seqName))
 	{
@@ -18566,30 +18590,31 @@
     printf("<BR>\n");
     printSnp125Info(tdb, snp, version);
     doSnpEntrezGeneLink(tdb, itemName);
     }
 else
     errAbort("SNP %s not found at %s base %d", itemName, seqName, start);
 sqlFreeResult(&sr);
 
 printOtherSnpMappings(table, itemName, start, conn, rowOffset);
 puts("<BR>");
 // Make table for collapsible sections:
 puts("<TABLE>");
 checkForGwasCatalog(conn, tdb, itemName);
 checkForHgdpGeo(conn, tdb, itemName, start);
 checkForHapmap(conn, tdb, itemName);
+checkForMupit(conn, tdb, start);
 printSnpAlignment(tdb, snpAlign, version);
 puts("</TABLE>");
 printTrackHtml(tdb);
 hFreeConn(&conn);
 }
 
 
 void doTigrGeneIndex(struct trackDb *tdb, char *item)
 /* Put up info on tigr gene index item. */
 {
 char *animal = cloneString(item);
 char *id = strchr(animal, '_');
 char buf[128];
 
 if (id == NULL)