700758c7e3fabc5cd1f925d8da37c5ee4bee3bd0 max Sat Mar 17 13:56:32 2012 -0700 fixed wbr bug and added pmid output redmine #6833 diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c index c731e05..a722cbc 100644 --- src/hg/hgc/pubs.c +++ src/hg/hgc/pubs.c @@ -1,509 +1,521 @@ /* 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 "obscure.h" //include "hgTrackUi.h" // cgi var to activate debug output static int pubsDebug = 0; // 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, 0, 1 }; static char* pubsSequenceTable; static char* pubsArticleTable; static char* makeSqlMarkerList(void) /* return list of sections from cgi vars, format like "'abstract','header'" */ { int secCount = sizeof(pubsSecNames)/sizeof(char *); struct slName* names = NULL; int i; for (i=0; i\n"); printf("Sections of article shown:
\n"); printf("
\n", cartSidUrlString(cart), cgiString("o"), cgiString("t"), cgiString("g"), cgiString("i")); for (i=0; i\n", pubsSecNames[i]); printf("%s\n", secLabels[i]); else printf("value=\"1\">%s\n", secLabels[i]); } printf("\n", cgiString("o")); printf("\n", cgiString("g")); printf("\n", cgiString("t")); printf("\n", cgiString("i")); printf("\n", cart->sessionId); printf("
"); printf("\n"); printf("

\n"); } static void printLimitWarning(struct sqlConnection *conn, char* markerTable, char* item, int itemLimit, char* sectionList) { char query[4000]; safef(query, sizeof(query), "SELECT COUNT(*) from %s WHERE markerId='%s' AND section in (%s) ", markerTable, item, sectionList); if (sqlNeedQuickNum(conn, query) > itemLimit) { printf("This marker is mentioned more than %d times
\n", itemLimit); printf("The results would take too long to load in your browser and are " "therefore limited to %d articles.

\n", itemLimit); } } static void printMarkerSnippets(struct sqlConnection *conn, char* articleTable, char* markerTable, char* item) { /* do not show more snippets than this limit */ int itemLimit=1000; printSectionCheckboxes(); char* sectionList = makeSqlMarkerList(); printLimitWarning(conn, markerTable, item, itemLimit, sectionList); printf("

Snippets from Publications:

"); 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* snippets = row[5]; char* addParam = ""; if (strstrNoCase(url, "sciencedirect.com")) addParam = "?svAppaddApp=298535"; // add the "UCSC matches" sciverse application to article view printf("%s ", url, addParam, title); printf("%s; ", authors); printf("%s
", citation); if (pubsDebug) printf("articleId=%s", articleId); printf("%s

", snippets); printf("


"); } freeMem(sectionList); sqlFreeResult(&sr); } static 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'", pubsArticleTable, item); + safef(query, sizeof(query), "SELECT articleId, url, title, authors, citation, abstract, pmid FROM %s WHERE displayId='%s'", pubsArticleTable, item); struct sqlResult *sr = sqlGetResult(conn, query); char **row; char *articleId=NULL; if ((row = sqlNextRow(sr)) != NULL) { + char* cit = row[4]; char* abstract = row[5]; + char* pmid = row[6]; + if (strlen(abstract)==0) { abstract = "(No abstract found for this article. Please use the link to the fulltext above.)"; } articleId = cloneString(row[0]); printf("

%s

\n", row[3]); printf("%s\n", row[1], row[2]); - printf("

%s

\n", row[4]); + printf("

%s", cit); + if (nullIfAllSpace(pmid)!=NULL) + printf(", PMID%s\n", pmid, pmid); + printf("

\n"); printf("

%s

\n", abstract); } 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 */ { 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) puts(query); // split comma-sep list into parts char* seqIdCoordString = sqlQuickString(conn, query); char* seqIdCoords[1024]; int partCount = chopString(seqIdCoordString, ",", seqIdCoords, ArraySize(seqIdCoords)); int i; // format of part :-, e.g. 12312345:0-23 struct hash *seqIdHash = NULL; seqIdHash = newHash(0); for (i=0; i", annotIdHitCoord[0], annotIdHitCoord[1]); // put articleId and annotId together to create annotation(=sequence) Id char fullAnnotId[4096]; safef(fullAnnotId, sizeof(fullAnnotId), "%s%s", articleId, annotIdHitCoord[0]); hashAdd(seqIdHash, fullAnnotId, annotIdHitCoord[1]); } freeMem(seqIdCoordString); return seqIdHash; } static void printSeqHeaders(bool showDesc, bool isClickedSection) { printf("\n", HG_COL_BORDER); printf("\n", HG_COL_TABLE_LABEL); if (showDesc) puts(" \n"); puts(" \n"); if (pubsDebug) puts(" \n"); if (!isClickedSection && !pubsDebug) puts(" \n"); puts("\n"); } 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 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 (i % distance == 0) + if (*c=='&') + doNotBreak = TRUE; + if (*c==';') + doNotBreak = FALSE; + + if (i % distance == 0 && ! doNotBreak) printf(""); printf("%c", *c); c++; i++; } } } static bool printSeqSection(char* articleId, char* title, bool showDesc, struct sqlConnection* conn, struct hash* clickedSeqs, bool isClickedSection, bool fasta) /* print 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 " "FROM %s WHERE articleId='%s';", pubsSequenceTable, articleId); if (pubsDebug) puts(query); struct sqlResult *sr = sqlGetResult(conn, query); // construct title for section char fullTitle[5000]; safef(fullTitle, sizeof(fullTitle), "%s (switch fasta format)", title, cartSidUrlString(cart), cgiString("o"), cgiString("t"), cgiString("g"), cgiString("i"), !fasta); webNewSection(fullTitle); if (!fasta) printSeqHeaders(showDesc, isClickedSection); char **row; bool foundSkippedRows = FALSE; while ((row = sqlNextRow(sr)) != NULL) { char* fileDesc = row[0]; char* snippet = row[1]; char* locList = row[2]; char* artId = row[3]; char* fileId = row[4]; char* seqId = row[5]; char* seq = row[6]; // 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)); // only display this sequence if we're in the right section if (clickedSeqs!=NULL && ((hashLookup(clickedSeqs, annotId)!=NULL) != isClickedSection)) { foundSkippedRows = TRUE; continue; } if (fasta) { printf(">%s
%s
", annotId, seq); } else { printf("\n", HG_COL_LOCAL_TABLE); if (showDesc) printf("\n", snippet); printf("\n"); if (pubsDebug) { printf("\n"); } printf("\n"); } } printf("\n"); webEndSectionTables(); sqlFreeResult(&sr); return foundSkippedRows; } static void printSeqInfo(struct sqlConnection* conn, char* trackTable, char* articleId, char* item, char* seqName, int start, bool fileDesc, bool fasta) /* 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); else skippedRows=1; if (skippedRows) printSeqSection(articleId, "Other Sequences in this article", \ fileDesc, conn, clickedSeqs, 0, fasta); printf("

Copyright 2011 Elsevier B.V. All rights reserved.

"); 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), \ "SELECT version,dateReference FROM hgFixed.trackVersion " "WHERE db = '%s' AND name = 'pubs' ORDER BY updateTime DESC limit 1", database); struct sqlResult *sr = sqlGetResult(conn, query); char **row; /* in case of NULL result from the table */ versionString[0] = 0; while ((row = sqlNextRow(sr)) != NULL) { safef(versionString, sizeof(versionString), "version %s", row[0]); safef(dateReference, sizeof(dateReference), "%s", row[1]); } sqlFreeResult(&sr); } 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); } static void printPositionAndSize(int start, int end, bool showSize) { printf("Position: " "", hgTracksPathAndSettings(), database, seqName, start+1, end); char startBuf[64], endBuf[64]; sprintLongWithCommas(startBuf, start + 1); sprintLongWithCommas(endBuf, end); printf("%s:%s-%s
\n", seqName, startBuf, endBuf); long size = end - start; sprintLongWithCommas(startBuf, size); if (showSize) printf("Genomic Size: %s
\n", startBuf); } void doPubsDetails(struct trackDb *tdb, char *item) /* publications custom display */ { int start = cgiInt("o"); int end = cgiInt("t"); char* trackTable = cgiString("g"); int fasta = cgiOptionalInt("fasta", 0); pubsDebug = cgiOptionalInt("debug", 0); struct sqlConnection *conn = hAllocConn(database); printTrackVersion(tdb, conn, item); if (startsWith("pubsMarker", trackTable)) { char* markerTable = hashMustFindVal(tdb->settingsHash, "pubsMarkerTable"); char* articleTable = hashMustFindVal(tdb->settingsHash, "pubsArticleTable"); printPositionAndSize(start, end, 0); printMarkerSnippets(conn, articleTable, markerTable, item); } else { printPositionAndSize(start, end, 1); pubsSequenceTable = hashMustFindVal(tdb->settingsHash, "pubsSequenceTable"); pubsArticleTable = hashMustFindVal(tdb->settingsHash, "pubsArticleTable"); char* articleId = printArticleInfo(conn, item); if (articleId!=NULL) { bool showDesc; showDesc = (! endsWith(trackTable, "Elsevier")); // avoid clutter: Elsevier has only main text printSeqInfo(conn, trackTable, articleId, item, seqName, start, showDesc, fasta); } } printTrackHtml(tdb); hFreeConn(&conn); }

Article fileOne table row per sequence, with flanking text, sequence in boldIdentifiersFeature that includes this match
%s\n", fileDesc); //printf("%s"); printAddWbr(snippet, 40); printf("article %s, file %s, seq %s, annotId %s", artId, fileId, seqId, annotId); } // print links to locations if (!isClickedSection && !pubsDebug) { struct slName *locs; // format: hg19/chr1:300-400,mm9/chr1:60006-23234 // split on "," then split on "/" locs = charSepToSlNames(locList, ','); printf(""); if (locs==NULL) printf("No matches"); for ( ; locs!=NULL; locs = locs->next) { char* locString = locs->name; char* parts[2]; int partCount; partCount = chopString(locString, "/", parts, ArraySize(parts)); assert(partCount==2); char* db = parts[0]; char* pos = parts[1]; printf("%s (%s)", cartSidUrlString(cart), db, pos, pos, db); printf("
"); } printf("