351a4c4de3f732d59604a3b25444fed9b4452ab0 max Thu Feb 28 15:09:12 2013 -0800 changing hgc page diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c index d2bef58..267ff80 100644 --- src/hg/hgc/pubs.c +++ src/hg/hgc/pubs.c @@ -9,30 +9,32 @@ #include "web.h" #include "hash.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; // 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, @@ -115,30 +117,35 @@ //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) +{ +printf("<img src=\"%s\" alt=\"%s\" width=\"%d\" hspace=\"%d\" vspace=\"%d\">\n", url, 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); web2StartCell(); vprintf(format, args); @@ -257,37 +264,37 @@ 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[] ={ "Title", "Abstract", "Introduction", "Methods", "Results", "Discussion", "Conclusions", "Acknowledgements", - "References", "Not determined" }; + "References", "Undetermined section (e.g. for a brief communication)" }; int labelCount = sizeof(secLabels)/sizeof(char *); int i; printf("<P>\n"); -printf("<B>Sections of article shown:</B><BR>\n"); +printf("<B>Sections of article searched:</B><BR>\n"); printf("<FORM ACTION=\"hgc?%s&o=%s&t=%s&g=%s&i=%s\" METHOD=\"get\">\n", cartSidUrlString(cart), cgiString("o"), cgiString("t"), cgiString("g"), cgiString("i")); for (i=0; i<labelCount; i++) { char *name = pubsSecNames[i]; // checkboxes default to 0 unless checked, see // http://stackoverflow.com/questions/2520952/how-come-checkbox-state-is-not-always-passed-along-to-php-script printf("<INPUT TYPE=\"hidden\" name=\"%s\" value=\"0\" />\n", pubsSecNames[i]); printf("<INPUT TYPE=\"checkbox\" name=\"%s\" ", name); int isChecked = cgiOptionalInt(name, pubsSecChecked[i]); if (isChecked) printf("value=\"1\" checked=\"yes\">%s</INPUT>\n", secLabels[i]); else @@ -364,50 +371,51 @@ 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 FROM %s WHERE articleId='%s'", pubsArticleTable, item); +safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid, source 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]; 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); @@ -552,70 +560,72 @@ 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 " +"SELECT fileDesc, snippet, locations, articleId, fileId, seqId, sequence, fileUrl " "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 <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"), !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; +char *fileUrl = NULL; // we might need this after the loop for yif articles bool foundSkippedRows = FALSE; while ((row = sqlNextRow(sr)) != NULL) { char *fileDesc = row[0]; char *snippet = row[1]; char *locString= row[2]; char *artId = row[3]; char *fileId = row[4]; char *seqId = row[5]; char *seq = row[6]; + fileUrl = row[7]; // annotation (=sequence) ID is a 64 bit int with 10 digits for // article, 3 digits for file, 5 for annotation char annotId[100]; safef(annotId, 100, "%010d%03d%05d", atoi(artId), atoi(fileId), atoi(seqId)); if (pubsDebug) printf("%s", annotId); // only display this sequence if we're in the right section if (clickedSeqs!=NULL && ((hashLookup(clickedSeqs, annotId)!=NULL) != isClickedSection)) { foundSkippedRows = TRUE; continue; } if (fasta) @@ -656,52 +666,69 @@ slUniqify(&locs, slNameCmp, slNameFree); 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) && (fileUrl!=NULL) && isClickedSection) { + char* imgTitle = "Sequences were found in text obtained with optical character recognition from this figure:\n"; + web2StartSection("section", "%s", imgTitle); + web2Img(fileUrl, "Image from YIF", 600, 10, 10); + web2EndSection(); +} + 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; if (clickedSeqs) skippedRows = printSeqSection(articleId, "Sequences used to construct this feature", \ fileDesc, conn, clickedSeqs, 1, fasta, pslTable, articleTable); else skippedRows=1; if (skippedRows) - printSeqSection(articleId, "Other Sequences in this article", \ + { + // 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]; + safef(title, sizeof(title), "Other 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"); if (trackVersionExists) { char query[256]; safef(query, sizeof(query), \