b50394c8b9d62283c6731ac2db96403169b532ee
max
Mon Apr 16 17:34:24 2012 -0700
html changed according to gregs corrections, suppress copyright notice for non-elsevier papers, suppress document type for publishers that have only one type (main text) (comment from larrym), many many indentation corrections to better comply to jim kent source style (larrym comments)
diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c
index 5d346af..43329f8 100644
--- src/hg/hgc/pubs.c
+++ src/hg/hgc/pubs.c
@@ -4,30 +4,36 @@
#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 "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;
+
// 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 };
@@ -35,39 +41,46 @@
static char* pubsSequenceTable;
static char* mangleUrl(char* url)
/* add publisher specific parameters to url and return new url*/
{
if (!stringIn("sciencedirect.com", url))
return url;
// cgi param to add the "UCSC matches" sciverse application to elsevier's sciencedirect
char* sdAddParam = "?svAppaddApp=298535";
char* longUrl = catTwoStrings(url, sdAddParam);
char* newUrl = replaceChars(longUrl, "article", "svapps");
return newUrl;
}
-static void printFilterLink(char* pslTrack, char* articleId)
+static void printFilterLink(char* pslTrack, char* articleId, char* articleTable)
/* print a link to hgTracks with an additional cgi param to activate the single article filter */
{
int start = cgiInt("o");
int end = cgiInt("t");
- printf("
",
- hgTracksPathAndSettings(), database, seqName, start+1, end, articleId, pslTrack);
+ char qBuf[1024];
+ struct sqlConnection *conn = hAllocConn(database);
+ safef(qBuf, sizeof(qBuf), "SELECT CONCAT(firstAuthor, year) FROM %s WHERE articleId='%s';", articleTable, articleId);
+ char* dispId = sqlQuickString(conn, qBuf);
+
+ printf("",
+ hgTracksPathAndSettings(), database, seqName, start+1, end, articleId, pslTrack, dispId);
printf("Show these sequence matches individually on genome browser (activates track \""
"Individual matches for article\")
");
+ hFreeConn(&conn);
+
}
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%s
\n", authors);
printf("%s\n", url, title);
printf("%s", cit);
if (strlen(pmid)!=0 && strcmp(pmid, "0"))
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 */
@@ -272,71 +291,71 @@
// split comma-sep list into parts
char* seqIdCoordString = sqlQuickString(conn, query);
char* seqIdCoords[1024];
int partCount = chopString(seqIdCoordString, ",", seqIdCoords, ArraySize(seqIdCoords));
int i;
struct hash *seqIdHash = NULL;
seqIdHash = newHash(0);
for (i=0; i\n", HG_COL_BORDER);
- printf("\n", HG_COL_TABLE_LABEL);
+printf("\n");
+printf("\n");
if (showDesc)
puts(" Article file | \n");
puts(" One row per sequence, with flanking text, sequence in bold | \n");
if (pubsDebug)
puts(" Identifiers | \n");
if (!isClickedSection && !pubsDebug)
puts(" Chained matches with this sequence | \n");
- 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) {
+while (*c != 0)
{
if ((*c=='&') || (*c=='<'))
doNotBreak = TRUE;
if (*c==';' || (*c =='>'))
doNotBreak = FALSE;
printf("%c", *c);
if (i % distance == 0 && ! doNotBreak)
printf("");
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)
@@ -356,31 +375,31 @@
char* chrom = cloneNextWordByDelimiter(&locString, ':');
char* startStr = cloneNextWordByDelimiter(&locString, '-');
char* endStr = cloneString(locString);
int start = atoi(startStr);
int end = atoi(endStr);
printHgTracksLink(db, chrom, start, end, NULL, NULL);
printf("
");
freeMem(endStr); //XX why can't I free these?
freeMem(chrom);
freeMem(startStr);
freeMem(db);
}
}
-static bool printSeqSection(char* articleId, char* title, bool showDesc, struct sqlConnection* conn, struct hash* clickedSeqs, bool isClickedSection, bool fasta, char* pslTable)
+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 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);
@@ -390,31 +409,31 @@
if (fasta)
otherFormat = "table";
else
otherFormat = "fasta";
char fullTitle[5000];
safef(fullTitle, sizeof(fullTitle),
"%s (%s format)",
title, cartSidUrlString(cart), cgiString("o"), cgiString("t"), cgiString("g"), cgiString("i"),
!fasta, otherFormat);
webNewSection("%s", fullTitle);
if (isClickedSection)
{
- printFilterLink(pslTable, articleId);
+ printFilterLink(pslTable, articleId, articleTable);
printf("");
}
else
printf("");
if (!fasta)
printSeqHeaders(showDesc, isClickedSection);
char **row;
bool foundSkippedRows = FALSE;
while ((row = sqlNextRow(sr)) != NULL)
{
char* fileDesc = row[0];
char* snippet = row[1];
char* locString= row[2];
@@ -424,103 +443,101 @@
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));
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;
}
+ printf(" |
");
+
if (fasta)
- {
printf(">%s %s
|
", annotId, seq);
- }
else
{
printf("
\n", HG_COL_LOCAL_TABLE);
if (showDesc)
printf("%s\n", fileDesc);
- //printf(" | %s | \n", snippet);
- printf("");
+ //printf(" | %s | \n", snippet);
+ printf("");
printAddWbr(snippet, 40);
printf(" | \n");
if (pubsDebug)
- {
printf("article %s, file %s, seq %s, annotId %s", artId, fileId, seqId, annotId);
- }
// print links to locations
- if (!isClickedSection && !pubsDebug) {
+ if (!isClickedSection && !pubsDebug)
+ {
// format: hg19/chr1:300-400,mm9/chr1:60006-23234
// split on "," then split on "/"
//locs = charSepToSlNames(locString, ',');
char* locArr[1024];
int partCount = chopString(locString, ",", locArr, ArraySize(locArr));
printf(" | ");
if (partCount==0)
printf("No matches");
-
else
{
struct slName *locs;
locs = slNameListFromStringArray(locArr, partCount);
slUniqify(&locs, slNameCmp, slNameFree);
printGbLinks(locs);
printf(" ");
printf(" | \n");
slFreeList(&locs);
}
}
printf("
\n");
}
}
- printf("\n"); // finish section
+printf("\n"); // finish section
webEndSectionTables();
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)
+ 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);
+ fileDesc, conn, clickedSeqs, 1, fasta, pslTable, articleTable);
else
skippedRows=1;
if (skippedRows)
printSeqSection(articleId, "Other Sequences in this article", \
- fileDesc, conn, clickedSeqs, 0, fasta, pslTable);
+ fileDesc, conn, clickedSeqs, 0, fasta, pslTable, articleTable);
+if (pubsIsElsevier)
printf("Copyright 2012 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 "
@@ -663,44 +680,40 @@
if (aliTable!=NULL)
{
pubsSequenceTable = trackDbRequiredSetting(tdb, "pubsSequenceTable");
pubsAli(conn, trackTable, pubsSequenceTable, item);
return;
}
else
{
genericHeader(tdb, item);
struct psl *psl = getAlignments(conn, trackTable, item);
printf("
Genomic Alignment with sequence found in publication fulltext
");
printAlignmentsSimple(psl, start, trackTable, trackTable, item);
}
}
-
else
{
printTrackVersion(tdb, conn, item);
if (stringIn("Marker", trackTable))
{
char* markerTable = trackDbRequiredSetting(tdb, "pubsMarkerTable");
printPositionAndSize(start, end, 0);
printMarkerSnippets(conn, articleTable, markerTable, item);
}
else
{
printPositionAndSize(start, end, 1);
pubsSequenceTable = trackDbRequiredSetting(tdb, "pubsSequenceTable");
char* articleId = printArticleInfo(conn, item, articleTable);
if (articleId!=NULL)
{
- bool showDesc;
- showDesc = (! endsWith(trackTable, "Elsevier"));
- // avoid clutter: Elsevier has only main text
char *pslTable = trackDbRequiredSetting(tdb, "pubsPslTrack");
- printSeqInfo(conn, trackTable, pslTable, articleId, item, seqName, start, showDesc, fasta);
+ printSeqInfo(conn, trackTable, pslTable, articleId, item, seqName, start, pubsHasSupp, fasta, articleTable);
}
}
}
printTrackHtml(tdb);
hFreeConn(&conn);
}