8ba40a5b6b71e2cbd67b60b75d1cb3a7f50a930f max Thu Feb 9 14:53:26 2012 -0800 sectioning selectors added diff --git src/hg/hgc/t2g.c src/hg/hgc/t2g.c index 9161313..7b96717 100644 --- src/hg/hgc/t2g.c +++ src/hg/hgc/t2g.c @@ -2,73 +2,176 @@ #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 "obscure.h" //include "hgTrackUi.h" // cgi var to activate debug output int t2gDebug = 0; +// internal section types in mysql table +char* t2gSecNames[] ={ + "header", "abstract", + "intro", "methods", + "results", "discussion", + "conclusions", "ack", + "refs", "unknown" }; +// +// whether a checkbox is checked by default, have to correspond to t2gSecNames +int t2gSecChecked[] ={ + 1, 1, + 1, 1, + 1, 1, + 1, 0, + 0, 1 }; + char* sequenceTable; char* articleTable; -/* splits string with | and returns part index (is there no easier way to do this?) -char *splitPart(char* string, int index) +char* makeSqlMarkerList(void) +/* return list of sections from cgi vars, format like "'abstract','header'" */ +{ +int secCount = sizeof(t2gSecNames)/sizeof(char *); +struct slName* names = NULL; +int i; +for (i=0; i<secCount; i++) { - char* name2; - name2 = cloneString(string); - char **parts = NULL; - AllocArray(parts, 2); - chopString(name2, "|", parts, 2); - return (char *)parts[index]; -}*/ + // add ' around name and add to list + char* secName = t2gSecNames[i]; + if (cgiOptionalInt(secName, t2gSecChecked[i])) + { + char nameBuf[100]; + sprintf(nameBuf, "'%s'", secName); + slAddHead(&names, slNameNew(nameBuf)); + } +} -void printMarkerSnippets(struct sqlConnection *conn, char* item) +if (names==0) + errAbort("You need to specify at least one article section."); + +char* nameListString = slNameListToString(names, ','); +slNameFree(names); +return nameListString; +} + +struct sqlResult* queryMarkerRows(struct sqlConnection* conn, char* item, int itemLimit) +/* query marker rows from mysql, based on http parameters */ { -printf("<H3>Snippets from Publications:</H3>"); +char query[4000]; +sqlUpdate(conn, "SET SESSION group_concat_max_len = 40000"); + +char* sectionList = makeSqlMarkerList(); + +safef(query, sizeof(query), "SELECT distinct t2gElsevierMarker.articleId, url, title, authors, citation, group_concat(snippet, section SEPARATOR ' (...) ') FROM t2gElsevierMarker JOIN t2gElsevierArticle USING (articleId) WHERE markerId='%s' GROUP by articleId LIMIT %d", item, itemLimit); +//safef(query, sizeof(query), "SELECT distinct t2gElsevierMarker.articleId, url, title, authors, citation, group_concat(snippet SEPARATOR ' (...) ') FROM t2gElsevierMarker JOIN t2gElsevierArticle USING (articleId) WHERE markerId='%s' AND section IN (%s) GROUP by articleId LIMIT %d", item, sectionList, itemLimit); + +printf(sectionList); +freeMem(sectionList); + +struct sqlResult *sr = sqlGetResult(conn, query); + +return sr; +} + + +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 t2gSecNames +char *secLabels[] ={ + "Title", "Abstract", + "Introduction", "Methods", + "Results", "Discussion", + "Conclusions", "Acknowledgements", + "References", "Not determined" }; + +int labelCount = sizeof(secLabels)/sizeof(char *); + +int i; +printf("<P>\n"); +printf("<B>Sections of article shown:</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 = t2gSecNames[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", t2gSecNames[i]); + printf("<INPUT TYPE=\"checkbox\" name=\"%s\" ", name); + + int isChecked = cgiOptionalInt(name, t2gSecChecked[i]); + if (isChecked) + printf("value=\"1\" checked=\"yes\">%s</INPUT>\n", secLabels[i]); + else + printf("value=\"1\">%s</INPUT>\n", secLabels[i]); +} + +printf("<INPUT TYPE=\"hidden\" name=\"o\" value=\"%s\" />\n", cgiString("o")); +printf("<INPUT TYPE=\"hidden\" name=\"g\" value=\"%s\" />\n", cgiString("g")); +printf("<INPUT TYPE=\"hidden\" name=\"t\" value=\"%s\" />\n", cgiString("t")); +printf("<INPUT TYPE=\"hidden\" name=\"i\" value=\"%s\" />\n", cgiString("i")); +printf("<INPUT TYPE=\"hidden\" name=\"hgsid\" value=\"%s\" />\n", cgiString("hgsid")); +printf("<BR>"); +printf("<INPUT TYPE=\"submit\" VALUE=\"Submit\" />\n"); +printf("</FORM><P>\n"); +} +void printLimitWarning(struct sqlConnection *conn, char* item, int itemLimit) +{ char query[4000]; safef(query, sizeof(query), "SELECT COUNT(*) from t2gElsevierMarker WHERE markerId='%s'", item); -if (sqlNeedQuickNum(conn, query) > 4000) { - printf("Sorry, this marker is mentioned in more than 4000 times<BR>"); - printf("The results would take too long to load in your browser and are therefore not shown.<P>"); - return; +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); +} } -sqlUpdate(conn, "SET SESSION group_concat_max_len = 10000"); +void printMarkerSnippets(struct sqlConnection *conn, char* item) +{ + +/* do not show more snippets than this limit */ +int itemLimit=4000; -safef(query, sizeof(query), "SELECT distinct t2gElsevierMarker.articleId, url, title, authors, citation, group_concat(snippet SEPARATOR ' (...) ') FROM t2gElsevierMarker JOIN t2gElsevierArticle USING (articleId) WHERE markerId='%s' GROUP by articleId", item); +printSectionCheckboxes(); +printLimitWarning(conn, item, itemLimit); + +printf("<H3>Snippets from Publications:</H3>"); + +struct sqlResult* sr = queryMarkerRows(conn, item, itemLimit); -struct sqlResult *sr = sqlGetResult(conn, query); 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* snippets = row[5]; - printf("<SMALL>%s</SMALL><BR>", authors); - printf("<A HREF=\"%s\">%s</A><BR>", url, title); - printf("<SMALL>%s</SMALL><P>", citation); + printf("<A HREF=\"%s\">%s</A> ", url, title); + printf("<SMALL>%s</SMALL>; ", authors); + printf("<SMALL>%s</SMALL><BR>", citation); if (t2gDebug) printf("articleId=%s", articleId); printf("<I>%s</I><P>", snippets); printf("<HR>"); } } char* printArticleInfo(struct sqlConnection *conn, char* item) /* Header with information about paper, return documentId */ { char query[512]; safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract FROM %s WHERE displayId='%s'", articleTable, item); struct sqlResult *sr = sqlGetResult(conn, query); @@ -310,65 +413,67 @@ } else { versionString[0] = 0; dateReference[0] = 0; } if (versionString[0]) safef(headerTitle, sizeof(headerTitle), "%s - %s", item, versionString); else safef(headerTitle, sizeof(headerTitle), "%s", item); genericHeader(tdb, headerTitle); } -void printPositionAndSize(int start, int end) +void printPositionAndSize(int start, int end, bool showSize) { printf("<B>Position:</B> " "<A HREF=\"%s&db=%s&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> %s<BR>\n", startBuf); } void doT2gDetails(struct trackDb *tdb, char *item) /* text2genome.org custom display */ { int start = cgiInt("o"); int end = cgiInt("t"); char* trackTable = cgiString("g"); int fasta = cgiOptionalInt("fasta", 0); t2gDebug = cgiOptionalInt("debug", 0); struct sqlConnection *conn = hAllocConn(database); printTrackVersion(tdb, conn, item); -printPositionAndSize(start, end); if (startsWith("t2gMarker", trackTable)) { + printPositionAndSize(start, end, 0); printMarkerSnippets(conn, item); } else { + printPositionAndSize(start, end, 1); sequenceTable = hashMustFindVal(tdb->settingsHash, "sequenceTable"); articleTable = hashMustFindVal(tdb->settingsHash, "articleTable"); char* docId = printArticleInfo(conn, item); if (docId!=0) { bool showDesc; showDesc = (! endsWith(trackTable, "Elsevier")); // avoid clutter: Elsevier has only main text printSeqInfo(conn, trackTable, docId, item, seqName, start, showDesc, fasta); } } printTrackHtml(tdb); hFreeConn(&conn); }