bb85cad5b5a52f6a5e96f72cbfe681c5c4b863f8
max
  Wed Aug 21 22:25:39 2013 -0700
fixing a layout bug, adding cgi param for ensembl to linkout to hgc
diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c
index d78f418..dbbeb44 100644
--- src/hg/hgc/pubs.c
+++ src/hg/hgc/pubs.c
@@ -16,42 +16,43 @@
 
 // cgi var to activate debug output
 static int pubsDebug = 0;
 
 // global var for printArticleInfo to indicate if article has suppl info 
 // Most publishers have supp data.
 // If they don't have it, we can skip the fileType column in the table
 bool pubsHasSupp = TRUE; 
 
 // global var for printArticleInfo to indicate if article is elsevier
 // If it's elsevier, we print the copyright line
 bool pubsIsElsevier = FALSE; 
 
 // the article source is used to modify other parts of the page
 static char *articleSource;
-// we need the external article PMC Id for yif links
+
+// we need the external article PMC Id for YIF links
 static char *extId = NULL;
 
 // section types in mysql table, for all annotations tables
 // we note where the hit is located in the document
 static char *pubsSecNames[] ={
       "header", "abstract",
       "intro", "methods",
       "results", "discussion",
       "conclusions", "ack",
       "refs", "unknown" };
-//
+
 // whether a checkbox is checked by default, have to correspond to pubsSecNames
 static int pubsSecChecked[] ={
       1, 1,
       1, 1,
       1, 1,
       1, 0,
       0, 1 };
 
 static char *pubsSequenceTable;
 
 
 /* ------ functions to replace HTML4 tables with HTML5 constructs */
 /* Web wrappers incorporating tag, id, and class HTML attributes, to support
  * styling and test */
 
@@ -262,47 +263,55 @@
         safef(nameBuf, sizeof(nameBuf), "'%s'", secName);
         slAddHead(&names, slNameNew(nameBuf));
     }
 }
 
 if (names==0)
     errAbort("You need to specify at least one article section.");
 
 char *nameListString = slNameListToString(names, ',');
 slNameFree(names);
 return nameListString;
 }
 
 
 static struct sqlResult *queryMarkerRows(struct sqlConnection *conn, char *markerTable, \
-    char *articleTable, char *item, int itemLimit, char *sectionList)
-/* query marker rows from mysql, based on http parameters  */
+    char *articleTable, char *item, int itemLimit, char *sectionList, char *artExtIdFilter)
+/* query marker rows from mysql, based on http parameters  
+ * optionally filter on sections or just a single article
+ * */
 {
 char query[4000];
 /* Mysql specific setting to make the group_concat function return longer strings */
 sqlUpdate(conn, "NOSQLINJ SET SESSION group_concat_max_len = 100000");
  
+char artFilterSql[4000];
+artFilterSql[0] = 0;
+if (isNotEmpty(artExtIdFilter))
+    safef(artFilterSql, sizeof(artFilterSql), " AND extId='%s' ", artExtIdFilter);
+
 // no need to check for illegal characters in sectionList
 sqlSafef(query, sizeof(query), "SELECT distinct %s.articleId, url, title, authors, citation, "  
     "pmid, extId, "
     "group_concat(snippet, concat(\" (section: \", section, \")\") SEPARATOR ' (...) ') FROM %s "
     "JOIN %s USING (articleId) "
     "WHERE markerId='%s' AND section in (%-s) "
+    "%-s"
     "GROUP by articleId "
     "ORDER BY year DESC "
     "LIMIT %d",
-    markerTable, markerTable, articleTable, item, sectionList, itemLimit);
+    markerTable, markerTable, articleTable, item, sectionList, artFilterSql, itemLimit);
 
 if (pubsDebug)
     printf("%s", query);
 
 struct sqlResult *sr = sqlGetResult(conn, query);
 
 return sr;
 }
 
 
 static void printSectionCheckboxes()
 /* show a little form with checkboxes where user can select sections they want to show */
 {
 // labels to show to user, have to correspond to pubsSecNames
 char *secLabels[] ={
@@ -347,66 +356,100 @@
 
 static void printLimitWarning(struct sqlConnection *conn, char *markerTable, 
     char *item, int itemLimit, char *sectionList)
 {
 char query[4000];
 // no need to check for illegal characters in sectionList
 sqlSafef(query, sizeof(query), "SELECT COUNT(*) from %s WHERE markerId='%s' AND section in (%-s) ", markerTable, item, sectionList);
 if (sqlNeedQuickNum(conn, query) > itemLimit) 
     {
     printf("<b>This marker is mentioned more than %d times</b><BR>\n", itemLimit);
     printf("The results would take too long to load in your browser and are "
     "therefore limited to %d articles.<P>\n", itemLimit);
     }
 }
 
+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) 
+    {
+    if ((*c=='&') || (*c=='<'))
+       doNotBreak = TRUE;
+    if (*c==';' || (*c =='>'))
+       doNotBreak = FALSE;
+
+    printf("%c", *c);
+    if (i % distance == 0 && ! doNotBreak) 
+        printf("<wbr>");
+    c++;
+    i++;
+    }
+}
+
 static void printMarkerSnippets(struct sqlConnection *conn, char *articleTable, char *markerTable, char *item)
 {
 
 /* do not show more snippets than this limit */
 int itemLimit=100;
 
-printSectionCheckboxes();
+char *artExtIdFilter = cgiOptionalString("pubsFilterExtId");
+
 char *sectionList = makeSqlMarkerList();
+if (artExtIdFilter==NULL)
+    {
+    printSectionCheckboxes();
     printLimitWarning(conn, markerTable, item, itemLimit, sectionList);
-
     printf("<H3>Snippets from Publications:</H3>");
-struct sqlResult *sr = queryMarkerRows(conn, markerTable, articleTable, item, itemLimit, sectionList);
+    }
 
+struct sqlResult *sr = queryMarkerRows(conn, markerTable, articleTable, item, itemLimit, sectionList, artExtIdFilter);
+
+printf("<DIV style=\"width:1024px; font-size:100%%\">\n");
 char **row;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     char *articleId = row[0];
     char *url       = row[1];
     char *title     = row[2];
     char *authors   = row[3];
     char *citation  = row[4];
     char *pmid      = row[5];
     char *snippets  = row[7];
     url = mangleUrl(url);
-    printf("<A HREF=\"%s\">%s</A> ", url, title);
+    printf("<A HREF=\"%s\">%s</A><BR> ", url, title);
     printf("<SMALL>%s</SMALL>; ", authors);
     printf("<SMALL>%s ", citation);
     if (!isEmpty(pmid) && strcmp(pmid, "0")!=0 )
         printf(", <A HREF=\"http://www.ncbi.nlm.nih.gov/pubmed/%s\">PMID%s</A>\n", pmid, pmid);
     printf("</SMALL><BR>\n");
     if (pubsDebug)
         printf("articleId=%s", articleId);
-    printf("<I>%s</I><P>", snippets);
+    printf("<I>\n");
+    printAddWbr(snippets, 40);
+    printf("</I><P>");
     printf("<HR>");
     }
 
+printf("</DIV>\n");
 freeMem(sectionList);
 sqlFreeResult(&sr);
 }
 
 static char *urlToLogoUrl(char *pubsArticleTable, char *articleId, char *urlOrig)
 /* return a string with relative path of logo for publisher given the url of
  * fulltext or a table/articleId, has to be freed 
 */
 {
 struct sqlConnection *conn = hAllocConn(database);
 char *pubCode = NULL;
 if (hHasField("hgFixed", pubsArticleTable, "publisher"))
     {
     char query[4000];
     sqlSafef(query, sizeof(query), "SELECT publisher from %s where articleId=%s", 
@@ -558,55 +601,30 @@
 // 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("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) 
-    {
-    if ((*c=='&') || (*c=='<'))
-       doNotBreak = TRUE;
-    if (*c==';' || (*c =='>'))
-       doNotBreak = FALSE;
-
-    printf("%c", *c);
-    if (i % distance == 0 && ! doNotBreak) 
-        printf("<wbr>");
-    c++;
-    i++;
-    }
-}
-
 void printHgTracksLink(char *db, char *chrom, int start, int end, char *linkText, char *optUrlStr)
 /* print link to hgTracks for db at pos */
 {
 char buf[1024];
 if (linkText==NULL) 
     {
     char startBuf[64], endBuf[64];
     sprintLongWithCommas(startBuf, start + 1);
     sprintLongWithCommas(endBuf, end);
     safef(buf, sizeof(buf), "%s:%s-%s (%s)", chrom, startBuf, endBuf, db);
     linkText = buf;
     }
 
 if (optUrlStr==NULL)
     optUrlStr = "";