a003e77ab083122c7fc7cf562387af864a2c24cb max Thu Mar 21 15:36:22 2013 -0700 added link to image page on yif server, after email from mate diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c index 3c53c8f..e9d5388 100644 --- src/hg/hgc/pubs.c +++ src/hg/hgc/pubs.c @@ -1,40 +1,43 @@ /* pubs.c - display details of publiations literature track (pubsxxx tables) */ #include "common.h" #include "jksql.h" #include "hdb.h" #include "hgc.h" #include "hgColors.h" #include "trackDb.h" #include "web.h" #include "hash.h" +#include "net.h" #include "obscure.h" #include "common.h" #include "string.h" //include "hgTrackUi.h" // 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 bool pubsHasSupp = TRUE; // global var for printArticleInfo to indicate if article is elsevier 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 +static char* extId = NULL; // internal section types in mysql table 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, @@ -117,33 +120,38 @@ //static void web2StartTbody() { web2Start("tbody"); } static void web2EndTbody() { web2End("tbody"); } //static void web2StartTable() { web2Start("table"); } static void web2EndTable() { web2EndTbody(); web2End("table"); } static void web2StartDivCI (char *class, char *id) { web2StartCI(class, id, "div"); } static void web2StartDivC (char *class) { web2StartC(class, "div"); } static void web2EndDiv(char *comment) { printf("</div> <!-- %s -->\n", comment); } -static void web2Img(char *url, char *alt, int width, int hspace, int vspace) +//static void web2Img(char *url, char *alt, int width, int hspace, int vspace) +//{ +//printf("<img src=\"%s\" alt=\"%s\" width=\"%d\" hspace=\"%d\" vspace=\"%d\">\n", url, alt, width, hspace, vspace); +//} + +static void web2ImgLink(char *url, char *imgUrl, char *alt, int width, int hspace, int vspace) { -printf("<img src=\"%s\" alt=\"%s\" width=\"%d\" hspace=\"%d\" vspace=\"%d\">\n", url, alt, width, hspace, vspace); +printf("<a href=\"%s\"><img src=\"%s\" alt=\"%s\" width=\"%d\" hspace=\"%d\" vspace=\"%d\"></a>\n", url, imgUrl, alt, width, hspace, vspace); } static void web2PrintHeaderCell(char *label, int width) /* Print th heading cell with given width in percent */ { printf("<th width=\"%d%%\">", width); printf("%s</th>", label); } static void web2PrintCellF(char *format, ...) /* print a td with format */ { va_list args; va_start(args, format); @@ -254,31 +262,32 @@ 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 query[4000]; /* Mysql specific setting to make the group_concat function return longer strings */ sqlUpdate(conn, "SET SESSION group_concat_max_len = 100000"); -safef(query, sizeof(query), "SELECT distinct %s.articleId, url, title, authors, citation, pmid, " +safef(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) " "GROUP by articleId " "ORDER BY year DESC " "LIMIT %d", markerTable, markerTable, articleTable, item, sectionList, itemLimit); if (pubsDebug) printf("%s", query); struct sqlResult *sr = sqlGetResult(conn, query); return sr; } @@ -351,31 +360,31 @@ char *sectionList = makeSqlMarkerList(); printLimitWarning(conn, markerTable, item, itemLimit, sectionList); printf("<H3>Snippets from Publications:</H3>"); struct sqlResult *sr = queryMarkerRows(conn, markerTable, articleTable, item, itemLimit, sectionList); 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[6]; + char *snippets = row[7]; url = mangleUrl(url); printf("<A HREF=\"%s\">%s</A> ", 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("<HR>"); } freeMem(sectionList); sqlFreeResult(&sr); @@ -388,51 +397,53 @@ char url[1024]; memcpy(url, urlOrig, sizeof(url)); char *urlParts[20]; int partCount = chopString(url, ".", urlParts, ArraySize(urlParts)); // construct path char *logoUrl = needMem(sizeof(url)); safef(logoUrl, sizeof(url), "../images/pubs_%s.png", urlParts[partCount-2]); return logoUrl; } static char *printArticleInfo(struct sqlConnection *conn, char *item, char *pubsArticleTable) /* Header with information about paper, return documentId */ { char query[512]; -safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid, source FROM %s WHERE articleId='%s'", pubsArticleTable, item); +safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid, " + "source, extId FROM %s WHERE articleId='%s'", pubsArticleTable, item); struct sqlResult *sr = sqlGetResult(conn, query); char **row; char *articleId=NULL; if ((row = sqlNextRow(sr)) == NULL) { printf("Could not resolve articleId %s, this is an internal error.\n", item); printf("Please send an email to max@soe.ucsc.edu\n"); sqlFreeResult(&sr); return NULL; } articleId = cloneString(row[0]); char *url = row[1]; char *title = row[2]; char *authors = row[3]; char *cit = row[4]; char *abstract = row[5]; char *pmid = row[6]; 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.)"; if (stringIn("sciencedirect.com", url)) { pubsHasSupp = FALSE; pubsIsElsevier = TRUE; } // logo of publisher char *logoUrl = urlToLogoUrl(url); printf("<a href=\"%s\"><img align=\"right\" hspace=\"20\" src=\"%s\"></a>\n", url, logoUrl); @@ -582,30 +593,64 @@ } void removeFlank (char *snippet) /* keep only the parts inside <b> to </b> of a string, modifies the string in place */ { char* startPtr = stringIn("<B>", snippet); char* endPtr = stringIn("</B>", snippet); if (startPtr!=0 && endPtr!=0 && startPtr<endPtr) { char* buf = stringBetween("<B>", "</B>", snippet); memcpy(snippet, buf, strlen(buf)+1); freeMem(buf); } } +static void printYifSection(char *clickedFileUrl) +/* print section with the image on yif and a link to it */ +{ + +// parse out yif file Id from yif url to generate link to yif page +struct netParsedUrl npu; +netParseUrl(clickedFileUrl, &npu); +struct hash *params = NULL; +struct cgiVar* paramList = NULL; +char *paramStr = strchr(npu.file, '?'); +cgiParseInput(paramStr, ¶ms, ¶mList); +struct cgiVar *var = hashFindVal(params, "file"); +char *figId = NULL; +if (var!=NULL && var->val!=NULL) + figId = var->val; + +char yifPageUrl[4096]; +if (figId) + { + safef(yifPageUrl, sizeof(yifPageUrl), "http://krauthammerlab.med.yale.edu/imagefinder/Figure.external?sp=S%s%%2F%s", extId, figId); + } + +if (!yifPageUrl) + return; + +web2StartSection("section", + "<A href=\"%s\">Yale Image Finder</a>: figure where sequences were found", + yifPageUrl); + +web2ImgLink(yifPageUrl, clickedFileUrl, "Image from YIF", 600, 10, 10); + +web2EndSection(); +} + static bool printSeqSection(char *articleId, char *title, bool showDesc, struct sqlConnection *conn, struct hash* clickedSeqs, bool isClickedSection, bool fasta, char *pslTable, char *articleTable) /* print a section with a table of sequences, show only sequences with IDs in hash, * There are two sections, respective sequences are shown depending on isClickedSection and clickedSeqs * - seqs that were clicked on (isClickedSection=True) -> show only seqs in clickedSeqs * - other seqs (isClickedSection=False) -> show all other seqs * * */ { // get data from mysql char query[4096]; safef(query, sizeof(query), "SELECT fileDesc, snippet, locations, articleId, fileId, seqId, sequence, fileUrl " "FROM %s WHERE articleId='%s';", pubsSequenceTable, articleId); if (pubsDebug) puts(query); @@ -723,36 +768,33 @@ printGbLinks(locs); printf("<br>"); slFreeList(&locs); } web2EndCell(); } web2EndRow(); } } if (!fasta) web2EndTable(); web2EndSection(); /* Yale Image finder files contain links to the image itself */ -if (stringIn("yif", articleSource) && (clickedFileUrl!=NULL) && isClickedSection) { - char* imgTitle = "<A href=\"http://krauthammerlab.med.yale.edu/imagefinder/\">Yale Image Finder</a>: figure where sequences were found"; - web2StartSection("section", "%s", imgTitle); - web2Img(clickedFileUrl, "Image from YIF", 600, 10, 10); - web2EndSection(); -} +if (stringIn("yif", articleSource) && (clickedFileUrl!=NULL) && isClickedSection) + printYifSection(clickedFileUrl); + freeMem(clickedFileUrl); sqlFreeResult(&sr); return foundSkippedRows; } static void printSeqInfo(struct sqlConnection *conn, char *trackTable, char *pslTable, char *articleId, char *item, char *seqName, int start, bool fileDesc, bool fasta, char *articleTable) /* print sequences, split into two sections * two sections: one for sequences that were clicked, one for all others*/ { struct hash *clickedSeqs = getSeqIdHash(conn, trackTable, articleId, item, seqName, start); bool skippedRows;