1882a226292f155a88d6980e252225d5f25c57f9
markd
  Sun Feb 16 10:51:30 2014 -0800
Imported Mouse GENCODE M2.
diff --git src/hg/hgc/gencodeClick.c src/hg/hgc/gencodeClick.c
index 5ca84c2..e7be9b6 100644
--- src/hg/hgc/gencodeClick.c
+++ src/hg/hgc/gencodeClick.c
@@ -24,34 +24,35 @@
 /*
  * General notes:
  *  - this will be integrated into hgGene at some point, however this was
  *    done as part of hgc for timing reasons and to allow more time to design
  *    the hgGene part.
  *  - Tables below will output at least one row even if no data is available.
  *    
  */
 
 /* Various URLs and URL templates.  At one time, these were in the ra file,
  * but that didn't prove that helpful and end up requiring updated the ra
  * files for every GENCODE version if a URL was added or changed. */
 //FIXME: clean up RA files when CGIs no longer need them
 static char *gencodeBiotypesUrl = "http://www.gencodegenes.org/gencode_biotypes.html";
 static char *gencodeTagsUrl = "http://www.gencodegenes.org/gencode_tags.html";
-static char *ensemblTranscriptIdUrl = "http://www.ensembl.org/Homo_sapiens/Transcript/Summary?db=core;t=%s";
-static char *ensemblGeneIdUrl = "http://www.ensembl.org/Homo_sapiens/Gene/Summary?db=core;t=%s";
-static char *vegaTranscriptIdUrl = "http://vega.sanger.ac.uk/Homo_sapiens/Transcript/Summary?db=core;t=%s";
-static char *vegaGeneIdUrl = "http://vega.sanger.ac.uk/Homo_sapiens/Gene/Summary?db=core;g=%s";
+static char *ensemblTranscriptIdUrl = "http://www.ensembl.org/%s/Transcript/Summary?db=core;t=%s";
+static char *ensemblGeneIdUrl = "http://www.ensembl.org/%s/Gene/Summary?db=core;t=%s";
+static char *ensemblSupportingEvidUrl = "http://www.ensembl.org/%s/Transcript/SupportingEvidence?db=core;t=%s";
+static char *vegaTranscriptIdUrl = "http://vega.sanger.ac.uk/%s/Transcript/Summary?db=core;t=%s";
+static char *vegaGeneIdUrl = "http://vega.sanger.ac.uk/%s/Gene/Summary?db=core;g=%s";
 static char *yalePseudoUrl = "http://tables.pseudogene.org/%s";
 static char *hgncUrl = "http://www.genenames.org/data/hgnc_data.php?match=%s";
 static char *geneCardsUrl = "http://www.genecards.org/cgi-bin/carddisp.pl?gene=%s";
 static char *apprisHomeUrl = "http://appris.bioinfo.cnio.es/";
 static char *apprisGeneUrl = "http://appris.bioinfo.cnio.es/report.html?id=%s&namespace=Ensembl_Gene_Id&specie=%s";
 static char *apprisTranscriptUrl = "http://appris.bioinfo.cnio.es/report.html?id=%s&namespace=Ensembl_Transcript_Id&specie=%s";
 
 static char *getBaseAcc(char *acc, char *accBuf, int accBufSize)
 /* get the accession with version number dropped. */
 {
 safecpy(accBuf, accBufSize, acc);
 char *dot = strchr(accBuf, '.');
 if (dot != NULL)
     *dot = '\0';
 return accBuf;
@@ -167,53 +168,87 @@
 }
 
 static char *getSupportLevelDesc(struct wgEncodeGencodeTranscriptionSupportLevel *tsl)
 /* return description for level */
 {
 static char buf[32];
 if ((tsl == NULL) || (tsl->level <= 0))
     return "tslNA";
 else
     {
     safef(buf, sizeof(buf), "tsl%d", tsl->level);
     return buf;
     }
 }
 
+static char* getScientificNameSym(void)
+/* get the scientific name of an organism in the form "Homo_sapiens"
+ *  WARNING: static return */
+{
+static char sciNameSym[128];
+char *sciName = hScientificName(database);
+if (sciName == NULL)
+    errAbort("can't get scientific name for %s", database);
+safecpy(sciNameSym, sizeof(sciNameSym), sciName);
+freeMem(sciName);
+subChar(sciNameSym, ' ', '_');
+return sciNameSym;
+}
+
 static void prExtIdAnchor(char *id, char *urlTemplate)
 /* if an id to an external database is not empty, print an HTML anchor to it */
 {
 if (!isEmpty(id))
     {
     char urlBuf[512];
     safef(urlBuf, sizeof(urlBuf), urlTemplate, id);
     printf("<a href=\"%s\" target=_blank>%s</a>", urlBuf, id);
     }
 }
 
+#if UNUSED
 static void prTdExtIdAnchor(char *id, char *urlTemplate)
 /* print a table data element with an anchor for a id */
 {
 printf("<td>");
 prExtIdAnchor(id, urlTemplate);
 }
+#endif
+
+static void prEnsIdAnchor(char *id, char *urlTemplate)
+/* if an id to an ensembl or vega database is not empty, print an HTML anchor to it */
+{
+if (!isEmpty(id))
+    {
+    char urlBuf[512];
+    safef(urlBuf, sizeof(urlBuf), urlTemplate, getScientificNameSym(), id);
+    printf("<a href=\"%s\" target=_blank>%s</a>", urlBuf, id);
+    }
+}
 
-static void prApprisTdAnchor(char *id, struct sqlConnection *conn, char *urlTemplate)
+static void prTdEnsIdAnchor(char *id, char *urlTemplate)
+/* print a table data element with an ensembl/vega anchor for a id */
+{
+printf("<td>");
+prEnsIdAnchor(id, urlTemplate);
+}
+
+static void prApprisTdAnchor(char *id, char *urlTemplate)
 /* print a gene or transcript link to APPRIS */
 {
 // under bar separated, lower case species name.
-char *speciesArg = hScientificName(sqlGetDatabase(conn));
+char *speciesArg = hScientificName(database);
 toLowerN(speciesArg, strlen(speciesArg));
 subChar(speciesArg, ' ', '_');
 
 char accBuf[64];
 printf("<td><a href=\"");
 printf(urlTemplate, getBaseAcc(id, accBuf, sizeof(accBuf)), speciesArg);
 printf("\" target=_blank>%s</a>", id);
 
 freeMem(speciesArg);
 }
 
 static void writePosLink(char *chrom, int chromStart, int chromEnd)
 /* write link to a genomic position */
 {
 printf("<a href=\"%s&db=%s&position=%s%%3A%d-%d\">%s:%d-%d</A>",
@@ -227,37 +262,37 @@
                                bool haveTsl, struct wgEncodeGencodeTranscriptionSupportLevel *tsl)
 /* write basic HTML info for all genes */
 {
 /*
  * notes:
  *   - According to Steve: `status' is not the same for ensembl and havana.  So either avoid displaying it
  *     or display it as `automatic status' or `manual status'.
  */
 
 // basic gene and transcript information
 printf("<table class=\"hgcCcds\" style=\"white-space: nowrap;\"><thead>\n");
 printf("<tr><th><th>Transcript<th>Gene</tr>\n");
 printf("</thead><tbody>\n");
 
 printf("<tr><th>Gencode id");
-prTdExtIdAnchor(transAttrs->transcriptId, ensemblTranscriptIdUrl);
-prTdExtIdAnchor(transAttrs->geneId, ensemblGeneIdUrl);
+prTdEnsIdAnchor(transAttrs->transcriptId, ensemblTranscriptIdUrl);
+prTdEnsIdAnchor(transAttrs->geneId, ensemblGeneIdUrl);
 printf("</tr>\n");
 
 printf("<tr><th>HAVANA manual id");
-prTdExtIdAnchor(transAttrs->havanaTranscriptId, vegaTranscriptIdUrl);
-prTdExtIdAnchor(transAttrs->havanaGeneId, vegaGeneIdUrl);
+prTdEnsIdAnchor(transAttrs->havanaTranscriptId, vegaTranscriptIdUrl);
+prTdEnsIdAnchor(transAttrs->havanaGeneId, vegaGeneIdUrl);
 printf("</tr>\n");
 
 printf("<tr><th>Position");
 printf("<td>");
 writePosLink(transAnno->chrom, transAnno->txStart, transAnno->txEnd);
 printf("<td>");
 writePosLink(transAnno->chrom, geneChromStart, geneChromEnd);
 printf("</tr>\n");
 
 printf("<tr><th>Strand<td>%s<td></tr>\n", transAnno->strand);
 
 printf("<tr><th><a href=\"%s\" target = _blank>Biotype</a><td>%s<td>%s</tr>\n", gencodeBiotypesUrl, transAttrs->transcriptType, transAttrs->geneType);
 
 printf("<tr><th>Status<td>%s<td>%s</tr>\n", transAttrs->transcriptStatus, transAttrs->geneStatus);
 
@@ -278,32 +313,32 @@
 if (!isEmpty(transAttrs->ccdsId))
     {
     printf("<a href=\"");
     printCcdsExtUrl(transAttrs->ccdsId);
     printf("\" target=_blank>%s</a>", transAttrs->ccdsId);
     }
 printf("<td></tr>\n");
 
 printf("<tr><th>GeneCards<td colspan=2>");
 prExtIdAnchor(transAttrs->geneName, geneCardsUrl);
 printf("</tr>\n");
 
 if (isProteinCodingTrans(transAttrs))
     {
     printf("<tr><th><a href=\"%s\" target=_blank>APPRIS</a>\n", apprisHomeUrl);
-    prApprisTdAnchor(transAttrs->transcriptId, conn, apprisTranscriptUrl);
-    prApprisTdAnchor(transAttrs->geneId, conn, apprisGeneUrl);
+    prApprisTdAnchor(transAttrs->transcriptId, apprisTranscriptUrl);
+    prApprisTdAnchor(transAttrs->geneId, apprisGeneUrl);
     printf("</tr>\n");
     }
 
 // FIXME: add sequence here??
 printf("</tbody></table>\n");
 }
 
 static void writeSequenceHtml(struct trackDb *tdb, char *gencodeId, struct genePred *transAnno)
 /* write links to get sequences */
 {
 printf("<table class=\"hgcCcds\"><thead>\n");
 printf("<tr><th colspan=\"2\">Sequences</tr>\n");
 printf("</thead><tbody>\n");
 if (transAnno->cdsStart < transAnno->cdsEnd)
     {
@@ -548,75 +583,60 @@
 slReverse(&supportEvids2);
 *supportEvids = supportEvids2;
 }
 
 static struct supportEvid *loadSupportEvid(struct wgEncodeGencodeTranscriptSupport *transcriptSupports,
                                            struct wgEncodeGencodeExonSupport *exonSupports)
 /* load transcript and supporting evidence into a common structure */
 {
 struct supportEvid *supportEvids = NULL;
 transcriptSupportToSupportEvid(&supportEvids, transcriptSupports);
 exonSupportToSupportEvid(&supportEvids, exonSupports);
 sortUniqSupportExidence(&supportEvids);
 return supportEvids;
 }
 
-static char *getSupportEvidEnsemblUrl(char *gencodeId)
-/* Generate a URL to the ensembl supporting evidence page.
- * WARNING: static return. */
-{
-static char url[256];
-// generate organism part of url in the form: Homo_sapiens
-char *sciName = hScientificName(database);
-if (sciName == NULL)
-    errAbort("can't get scientific name for %s", database);
-char *space = strchr(sciName, ' ');
-if (space != NULL)
-    *space = '_';
-safef(url, sizeof(url), "http://www.ensembl.org/%s/Transcript/SupportingEvidence?db=core;t=%s", sciName, gencodeId);
-freeMem(sciName);
-return url;
-}
-
-static void writeSupportExidenceEntry(struct supportEvid *supportEvid)
+static void writeSupportEvidenceEntry(struct supportEvid *supportEvid)
 /* write HTML table entry  for a supporting evidence */
 {
 // FIXME: should link to sources when possible
 printf("<td width=\"25%%\">%s", supportEvid->seqSrc);
 printf("<td width=\"25%%\">%s", supportEvid->seqId);
 }
 
 static void writeSupportingEvidenceLinkHtml(char *gencodeId, struct wgEncodeGencodeTranscriptSupport *transcriptSupports,
                                             struct wgEncodeGencodeExonSupport *exonSupports)
 /* write HTML links to supporting evidence */
 {
 struct supportEvid *supportEvids = loadSupportEvid(transcriptSupports, exonSupports);
 
 printf("<table class=\"hgcCcds\"><thead>\n");
-printf("<tr><th colspan=\"4\">Supporting Evidence (<a href=\"%s\" target=\"_blank\">view in Ensembl</a>)</tr>\n", getSupportEvidEnsemblUrl(gencodeId));
+printf("<tr><th colspan=\"4\">Supporting Evidence (");
+prEnsIdAnchor(gencodeId, ensemblSupportingEvidUrl);
+printf(")</tr>\n");
 printf("<tr class=\"hgcCcdsSub\"><th>Source<th>Sequence<th>Source<th>Sequence</tr>\n");
 printf("</thead><tbody>\n");
 struct supportEvid *supportEvid = supportEvids;
 int i, rowCnt = 0;
 while ((supportEvid != NULL) || (rowCnt == 0))
     {
     printf("<tr>");
     for (i = 0; i < 2; i++)
         {
         if (supportEvid != NULL)
             {
-            writeSupportExidenceEntry(supportEvid);
+            writeSupportEvidenceEntry(supportEvid);
             supportEvid = supportEvid->next;
             }
         else
             printf("<td colspan=\"2\" width=\"50%%\">");
         }
     printf("</tr>\n");
     rowCnt++;
     }
 printf("</tbody></table>\n");
 slFreeList(&supportEvids);
 }
 
 static void writeTagEntry(struct wgEncodeGencodeTag *tag)
 /* write HTML table entry for a Tag */
 {