80a8dbcfd43490512f126712ee37dcaf249aa0bc
max
  Wed May 1 16:32:24 2013 -0700
making it possible to link to hgc without t and o parameters (europmc)
diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c
index 90c0571..906e3c0 100644
--- src/hg/hgc/pubs.c
+++ src/hg/hgc/pubs.c
@@ -205,31 +205,33 @@
            "<A HREF=\"%s&amp;db=%s&amp;position=%s%%3A%d-%d\">",
                   hgTracksPathAndSettings(), database, seqName, start+1, end);
 char startBuf[64], endBuf[64];
 sprintLongWithCommas(startBuf, start + 1);
 sprintLongWithCommas(endBuf, end);
 printf("%s:%s-%s</A><BR>\n", seqName, startBuf, endBuf);
 long size = end - start;
 sprintLongWithCommas(startBuf, size);
 if (showSize)
     printf("<B>Genomic Size:</B>&nbsp;%s<BR>\n", startBuf);
 }
 
 static void printFilterLink(char *pslTrack, char *articleId, char *articleTable)
 /* print a link to hgTracks with an additional cgi param to activate the single article filter */
 {
-    int start = cgiInt("o");
+    int start = cgiOptionalInt("o", -1);
+    if (start==-1)
+        return;
     int end = cgiInt("t");
     char qBuf[1024];
     struct sqlConnection *conn = hAllocConn(database);
     safef(qBuf, sizeof(qBuf), "SELECT CONCAT(firstAuthor, year) FROM %s WHERE articleId='%s';", articleTable, articleId);
     char *dispId = sqlQuickString(conn, qBuf);
 
     printf(
         "      <div class=\"subsection\">");
     printf(
         "      <P><A HREF=\"%s&amp;db=%s&amp;position=%s%%3A%d-%d&amp;pubsFilterArticleId=%s&amp;%s=pack&amp;hgFind.matches=%s\">",
         hgTracksPathAndSettings(), database, seqName, start+1, end, articleId, pslTrack, dispId);
 
     printf("Show these sequence matches individually on genome browser</A> (activates track \""
         "Individual matches for article\")</P>");
 
@@ -458,58 +460,64 @@
 articleSource  = row[7];
 extId          = row[8];
 
 url = mangleUrl(url);
 if (strlen(abstract)==0) 
         abstract = "(No abstract available for this article. "
             "Please follow the link to the fulltext above by clicking on the titel or the fulltext image.)";
 
 if (stringIn("sciencedirect.com", url)) 
     {
     pubsHasSupp = FALSE;
     pubsIsElsevier = TRUE;
     }
 
 // authors  title
-printf("<DIV style=\"width:800px; font-size:100%%\">\n");
+printf("<DIV style=\"width:1024px; font-size:100%%\">\n");
 printf("<P>%s</P>\n", authors);
-printf("<A TARGET=\"_blank\" HREF=\"%s\"><B>%s</B></A>\n", url, title);
-
+//
 // logo of publisher
 char *logoUrl = urlToLogoUrl(conn, pubsArticleTable, articleId, url);
 if (logoUrl)
     printf("<a href=\"%s\"><img align=\"right\" hspace=\"20\" src=\"%s\"></a>\n", url, logoUrl);
 freeMem(logoUrl);
+
+printf("<div style=\"width:800px\">");
+printf("<A TARGET=\"_blank\" HREF=\"%s\"><B>%s</B></A></div>\n", url, title);
+printf("</DIV>\n");
 printf("</DIV>\n");
 
-printf("<P style=\"width:800px; font-size:80%%\">%s", cit);
+
+printf("<P style=\"width:1024px; font-size:80%%\">%s", cit);
 if (strlen(pmid)!=0 && strcmp(pmid, "0"))
     printf(", <A HREF=\"http://www.ncbi.nlm.nih.gov/pubmed/%s\">PMID%s</A>\n", pmid, pmid);
 printf("</P>\n");
-printf("<P style=\"width:800px; font-size:100%%\">%s</P>\n", abstract);
+printf("<P style=\"width:1024px; font-size:100%%\">%s</P>\n", abstract);
 
 if (pubsIsElsevier)
     printf("<P><SMALL>Copyright 2012 Elsevier B.V. All rights reserved.</SMALL></P>");
 
 sqlFreeResult(&sr);
 return articleId;
 }
 
 static struct hash *getSeqIdHash(struct sqlConnection *conn, char *trackTable, \
     char *articleId, char *item, char *seqName, int start)
 /* return a hash with the sequence IDs for a given chain of BLAT matches */
 {
+if (start==-1)
+    return NULL;
 char query[512];
 /* check first if the column exists (some debugging tables on hgwdev don't have seqIds) */
 safef(query, sizeof(query), "SHOW COLUMNS FROM %s LIKE 'seqIds';", trackTable);
 char *seqIdPresent = sqlQuickString(conn, query);
 if (!seqIdPresent) {
     return NULL;
 }
 
 /* get sequence-Ids for feature that was clicked (item&startPos are unique) and return as hash*/
 safef(query, sizeof(query), "SELECT seqIds,'' FROM %s WHERE name='%s' "
     "and chrom='%s' and chromStart=%d;", trackTable, item, seqName, start);
 if (pubsDebug)
     printf("%s<br>", query);
 
 // split comma-sep list into parts
@@ -537,31 +545,31 @@
 web2StartTableC("stdTbl centeredStdTbl");
 web2StartTheadC("stdTblHead");
 if (showDesc)
     web2PrintHeaderCell("Article file", 10);
 
 // yif sequences have no flanking text at M. Krauthammer's request
 if (stringIn("yif", articleSource))
     web2PrintHeaderCell("Matching sequences", 60);
 else
     web2PrintHeaderCell("One row per sequence, with flanking text, sequence in bold", 60);
 
 if (pubsDebug)
     web2PrintHeaderCell("Identifiers", 30);
 
 if (!isClickedSection && !pubsDebug)
-    web2PrintHeaderCell("Chained matches with this sequence", 20);
+    web2PrintHeaderCell("Link to matching genomic location", 20);
 web2EndThead();
 web2StartTbodyS("font-family: Arial, Helvetica, sans-serif; line-height: 1.5em; font-size: 0.9em;");
 }
 
 static void printAddWbr(char *text, int distance) 
 /* a crazy hack for firefox/mozilla that is unable to break long words in tables
  * We need to add a <wbr> tag every x characters in the text to make text breakable.
  */
 {
 int i;
 i = 0;
 char *c;
 c = text;
 bool doNotBreak = FALSE;
 while (*c != 0) 
@@ -683,31 +691,31 @@
 "FROM %s WHERE articleId='%s';", pubsSequenceTable, articleId);
 if (pubsDebug)
     puts(query);
 struct sqlResult *sr = sqlGetResult(conn, query);
 
 // construct title for section
 char *otherFormat = NULL;
 if (fasta)
     otherFormat = "table";
 else
     otherFormat = "fasta";
 
 char fullTitle[5000];
 safef(fullTitle, sizeof(fullTitle), 
 "%s&nbsp;<A HREF=\"../cgi-bin/hgc?%s&o=%s&t=%s&g=%s&i=%s&fasta=%d\"><SMALL>(%s format)</SMALL></A>\n", 
-title, cartSidUrlString(cart), cgiString("o"), cgiString("t"), cgiString("g"), cgiString("i"), 
+title, cartSidUrlString(cart), cgiOptionalString("o"), cgiOptionalString("t"), cgiString("g"), cgiString("i"), 
 !fasta, otherFormat);
 
 web2StartSection("pubsSection", "%s", fullTitle);
 
 // print filtering link at start of table & table headers
 if (isClickedSection) {
     printFilterLink(pslTable, articleId, articleTable);
     }
 
 if (!fasta) 
     printSeqHeaders(showDesc, isClickedSection);
 
 // output rows
 char **row;
 
@@ -832,31 +840,36 @@
 
 bool skippedRows;
 if (clickedSeqs) 
     skippedRows = printSeqSection(articleId, "Sequences matching here", \
         fileDesc, conn, clickedSeqs, 1, fasta, pslTable, articleTable);
 else 
     skippedRows=1;
 
 if (skippedRows) 
     {
     // the section title should change if the data comes from the yale image finder = a figure
     char* docType = "article";
     if (stringIn("yif", articleSource))
         docType = "figure";
     char title[1024];
+    if (clickedSeqs)
     safef(title, sizeof(title), "Other Sequences in this %s", docType);
+    // NO clicked seqs can happen if the hgc was called with no o or t parameters
+    // from somewhere outside the browser, like elsevier or europmc
+    else
+        safef(title, sizeof(title), "Sequences in this %s", docType);
 
     printSeqSection(articleId, title, \
         fileDesc, conn, clickedSeqs, 0, fasta, pslTable, articleTable);
     }
 freeHash(&clickedSeqs);
 }
 
 static void printTrackVersion(struct trackDb *tdb, struct sqlConnection *conn, char *item) 
 {
 char versionString[256];
 char dateReference[256];
 char headerTitle[512];
 /* see if hgFixed.trackVersion exists */
 boolean trackVersionExists = hTableExists("hgFixed", "trackVersion");
 
@@ -961,32 +974,32 @@
         }
         psl->blockSizes[i] = bs/3; 
         }
 
     }
 else
     qt = gftDna;
 
 showSomeAlignment(psl, oSeq, qt, 0, oSeq->size, NULL, 0, 0);
 }
 
 void doPubsDetails(struct trackDb *tdb, char *item)
 /* publications custom display */
 {
 
-int start        = cgiInt("o");
-int end          = cgiOptionalInt("t", 0);
+int start        = cgiOptionalInt("o", -1);
+int end          = cgiOptionalInt("t", -1);
 char *trackTable = cgiString("g");
 char *aliTable   = cgiOptionalString("aliTable");
 int fasta        = cgiOptionalInt("fasta", 0);
 pubsDebug        = cgiOptionalInt("debug", 0);
 
 struct sqlConnection *conn = hAllocConn(database);
 
 char *articleTable = trackDbRequiredSetting(tdb, "pubsArticleTable");
 
 if (stringIn("Psl", trackTable))
     { 
     if (aliTable!=NULL)
         {
         pubsSequenceTable = trackDbRequiredSetting(tdb, "pubsSequenceTable");
         pubsAli(conn, trackTable, pubsSequenceTable, item);
@@ -995,33 +1008,35 @@
 
     else
         {
         genericHeader(tdb, item);
         struct psl *psl = getAlignments(conn, trackTable, item);
         printf("<H3>Genomic Alignment with sequence found in publication fulltext</H3>");
         printAlignmentsSimple(psl, start, trackTable, trackTable, item);
         }
     }
 else
     {
     printTrackVersion(tdb, conn, item);
     if (stringIn("Marker", trackTable))
         {
         char *markerTable = trackDbRequiredSetting(tdb, "pubsMarkerTable");
+        if (start!=-1)
         printPositionAndSize(start, end, 0);
         printMarkerSnippets(conn, articleTable, markerTable, item);
         }
     else
         {
         pubsSequenceTable = trackDbRequiredSetting(tdb, "pubsSequenceTable");
         char *articleId = printArticleInfo(conn, item, articleTable);
         if (articleId!=NULL) 
             {
             char *pslTable = trackDbRequiredSetting(tdb, "pubsPslTrack");
-            printSeqInfo(conn, trackTable, pslTable, articleId, item, seqName, start, pubsHasSupp, fasta, articleTable);
+            printSeqInfo(conn, trackTable, pslTable, articleId, item, \
+                seqName, start, pubsHasSupp, fasta, articleTable);
             }
     }
 }
 
 printTrackHtml(tdb);
 hFreeConn(&conn);
 }