");
itemPos = 1;
++rowIx;
}
webPrintLinkCellStart();
hPrintf("%s",
section->name, section->shortLabel);
webPrintLinkCellEnd();
}
webFinishPartialLinkTable(rowIx, itemPos, maxPerRow);
webPrintLinkTableEnd();
}
char *sectionCloseVar(char *section)
/* Get close variable for given section */
{
static char buf[128];
safef(buf, sizeof(buf), "%s%s_%s_%s", hggPrefix, "section", section, "close");
return buf;
}
boolean sectionIsOpen(struct section *section)
/* Check cart and ra to see if section is open(-) or closed(+) */
{
char *closeVarName = sectionCloseVar(section->name);
char *vis = sectionSetting(section, "visibility");
int defaultClosed = (vis && sameString(vis, "hide")) ? 1 : 0;
return !(cartUsualInt(cart, closeVarName, defaultClosed));
}
void printSections(struct section *sectionList, struct sqlConnection *conn,
char *geneId)
/* Print each section in turn. */
{
struct section *section;
for (section = sectionList; section != NULL; section = section->next)
{
boolean isOpen = sectionIsOpen(section);
char *indicator = (isOpen ? "-" : "+");
char *indicatorImg = (isOpen ? "../images/remove.gif" : "../images/add.gif");
struct dyString *header = dyStringNew(0);
//keep the following line for future debugging need
//printf("
printing %s section\n", section->name);fflush(stdout);
dyStringPrintf(header, "", section->name);
dyStringPrintf(header, "
",
section->name, indicatorImg, indicator);
dyStringAppend(header, section->longLabel);
if (isOpen)
webNewSection("%s",header->string);
else
webNewHiddenSection("%s",header->string);
long startTime = clock1000();
section->print(section, conn, geneId);
section->printTime = clock1000() - startTime;
dyStringFree(&header);
}
// add some simple javascript that can do the collapse/expand section buttons
// this code needs to be wrapped in an immediately executable function so that
// re-clicks don't complain about previously declared variables
jsInlineF(""
"(function() {\n"
"function collapseSection() {\n"
" let toCollapse = this.parentNode.nextElementSibling;\n"
" let isHidden = toCollapse.style.display === \"none\";\n"
" if (isHidden) {\n"
" toCollapse.style = \"display: \";\n"
" this.src = \"../images/remove.gif\";\n"
" this.alt = \"-\";\n"
" } else {\n"
" this.src = \"../images/add.gif\";\n"
" toCollapse.style = \"display: none\";\n"
" this.alt = \"+\";\n"
" }\n"
"}\n"
"\n"
"let btns = document.querySelectorAll(\"[id$=Btn]\");\n"
"let i;\n"
"for (i = 0; i < btns.length; i++) {\n"
" btn = btns[i];\n"
" btn.addEventListener('click', collapseSection);\n"
"}\n"
"})();\n"
);
}
void printTiming(struct section *sectionList)
/* Print timing for each section, if measureTiming is set */
{
if (!measureTiming)
return;
struct section *section;
int total = 0;
printf("section, check time, print time, total
\n");
for (section = sectionList; section != NULL; section = section->next)
{
boolean isOpen = sectionIsOpen(section);
int sectionTime = section->checkTime + section->printTime;
printf("%s, %d, %d, %d %s
\n", section->shortLabel, section->checkTime, section->printTime,
sectionTime, isOpen ? "" : "closed");
total += sectionTime;
}
printf("total = %d\n", total);
printf("
");
}
void webMain(struct sqlConnection *conn, struct trackDb *tdb)
/* Set up fancy web page with hotlinks bar and
* sections. */
{
struct section *sectionList = NULL;
printDescription(curGeneId, conn, tdb);
sectionList = loadSectionList(conn);
printIndex(sectionList);
printUpdateTime(database, tdb, NULL);
printSections(sectionList, conn, curGeneId);
printTiming(sectionList);
}
static char *findGeneId(struct sqlConnection *conn, char *name)
/* Given some sort of gene name, see if it is in our primary gene table, and if not
* look it up in alias table if we have one. */
{
/* Just check if it's in the main gene table, and if so return input name. */
char *mainTable = genomeSetting("knownGene");
char query[256];
sqlSafef(query, sizeof(query), "select count(*) from %s where name = '%s'", mainTable, name);
if (sqlQuickNum(conn, query) > 0)
return name;
else
{
/* check OMIM gene symbol table first */
if (sqlTableExists(conn, "omimGeneSymbol"))
{
sqlSafef(query, sizeof(query), "select geneSymbol from omimGeneSymbol where geneSymbol= '%s'", name);
char *symbol = sqlQuickString(conn, query);
if (symbol != NULL)
{
sqlSafef(query, sizeof(query), "select kgId from kgXref where geneSymbol = '%s'", symbol);
char *kgId = sqlQuickString(conn, query);
if (kgId != NULL)
{
/* The canonical gene is preferred */
sqlSafef(query, sizeof(query),
"select c.transcript from knownCanonical c,knownIsoforms i where i.transcript = '%s' and i.clusterId=c.clusterId", kgId);
char *canonicalKgId = sqlQuickString(conn, query);
if (canonicalKgId != NULL)
{
return canonicalKgId;
}
else
return(kgId);
}
}
}
}
char *alias = genomeOptionalSetting("kgAlias");
if (alias != NULL && sqlTableExists(conn, alias))
{
sqlSafef(query, sizeof(query), "select kgID from %s where alias = '%s'", alias, name);
char *id = sqlQuickString(conn, query);
if (id == NULL)
hUserAbort("Couldn't find %s in %s.%s or %s.%s", name, sqlGetDatabase(conn), mainTable, sqlGetDatabase(conn), alias);
return id;
}
else
hUserAbort("Couldn't find %s in %s.%s", name, sqlGetDatabase(conn), mainTable);
return NULL;
}
static void getGenePosition(struct sqlConnection *conn)
/* Get gene position from database. */
{
char *table = genomeSetting("knownGene");
char query[256];
struct sqlResult *sr;
char **row;
sqlSafef(query, sizeof(query),
"select chrom,txStart,txEnd from %s where name = '%s'"
, table, curGeneId);
sr = sqlGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
{
curGeneChrom = cloneString(row[0]);
curGeneStart = atoi(row[1]);
curGeneEnd = atoi(row[2]);
}
else
hUserAbort("Couldn't find %s in %s.%s", curGeneId, database, table);
sqlFreeResult(&sr);
}
static struct genePred *getCurGenePred(struct sqlConnection *conn)
/* Return current gene in genePred. */
{
char *track = genomeSetting("knownGene");
char table[HDB_MAX_TABLE_STRING];
boolean hasBin;
char query[256];
struct sqlResult *sr;
char **row;
struct genePred *gp = NULL;
if (!hFindSplitTable(sqlGetDatabase(conn), curGeneChrom, track, table, sizeof table, &hasBin))
errAbort("track %s not found", track);
bool hasAttrId = sqlColumnExists(conn, table, "alignId");
sqlSafef(query, sizeof(query),
"select * from %s where name = '%s' "
"and chrom = '%s' and txStart=%d and txEnd=%d"
, table, curGeneId, curGeneChrom, curGeneStart, curGeneEnd);
sr = sqlGetResult(conn, query);
if ((row = sqlNextRow(sr)) != NULL)
{
gp = genePredLoad(row + hasBin);
#define ALIGNIDFIELD 11 // Gencode Id
if (hasAttrId)
curAlignId = cloneString(row[ALIGNIDFIELD]);
else
curAlignId = gp->name;
}
sqlFreeResult(&sr);
if (gp == NULL)
errAbort("getCurGenePred: Can't find %s", query);
return gp;
}
void doKgMethod()
/* display knownGene.html content (UCSC Known Genes
* Method, Credits, and Data Use Restrictions) */
{
cartWebStart(cart, database, "Methods, Credits, and Use Restrictions");
char *tableName = cartUsualString(cart, hggType, NULL);
if (tableName == NULL)
tableName = "knownGene";
struct trackDb *tdb = hTrackDbForTrack(database, tableName);
-hPrintf("%s", tdb->html);
+// QuickLift: hub trackDb has no html; pull it from the source assembly's native track.
+char *liftDbSetting = (tdb != NULL) ? trackDbSetting(tdb, "quickLiftDb") : NULL;
+if (liftDbSetting != NULL && isEmpty(tdb->html))
+ {
+ struct trackDb *srcTdb = hTrackDbForTrack(liftDbSetting, trackHubSkipHubName(tableName));
+ if (srcTdb != NULL && isNotEmpty(srcTdb->html))
+ tdb = srcTdb;
+ }
+hPrintf("%s", emptyForNull(tdb->html));
cartWebEnd();
}
static void quickLiftGenePred(struct cart *cart, struct trackDb *tdb)
// map curGenePred to current db
{
char *chrom = cloneString(cartString(cart, hggChrom));
int start = atoi(cartString(cart, hggStart));
int end = atoi(cartString(cart, hggEnd));
char *quickLiftFile = cloneString(trackDbSetting(tdb, "quickLiftUrl"));
char *linkFileName = bigChainGetLinkFile(quickLiftFile);
struct hash *chainHash = newHash(8);
struct chain *chain, *chainList = chainLoadIdRangeHub(NULL, quickLiftFile, linkFileName, chrom, start, end, -1);
for(chain = chainList; chain; chain = chain->next)
{
chainSwap(chain);
liftOverAddChainHash(chainHash, chain);
}
calcLiftOverGenePreds( curGenePred, chainHash, 0.0, 1.0, TRUE, NULL, NULL, TRUE, FALSE);
curGeneChrom = curGenePred->chrom;
if (curGenePred->chrom == NULL)
errAbort("Failed to quickLift %s", curGenePred->name);
curGeneStart = curGenePred->txStart;
curGeneEnd = curGenePred->txEnd;
}
void cartMain(struct cart *theCart)
/* We got the persistent/CGI variable cart. Now
* set up the globals and make a web page. */
{
if (issueBotWarning)
{
char *ip = getenv("REMOTE_ADDR");
botDelayMessage(ip, botDelayMillis);
}
cart = theCart;
getDbAndGenome(cart, &database, &genome, oldVars);
initGenbankTableNames(database);
if (cartVarExists(cart, hggDoKgMethod))
doKgMethod();
else if (cartVarExists(cart, hggDoTxInfoDescription))
doTxInfoDescription();
else
{
struct sqlConnection *conn = NULL;
char *geneName = cartUsualString(cart, hggGene, NULL);
if (isEmpty(geneName))
{
// Silly googlebots.
hUserAbort("Error: the hgg_gene parameter is missing from the cart and the CGI params.");
}
/* if kgProtMap2 table exists, this means we are doing KG III */
if (hTableExists(database, "kgProtMap2")) kgVersion = KG_III;
char *tableName = cartUsualString(cart, hggType, NULL);
tableName = dupTrackSkipToSourceName(tableName);
char *knownDb = hdbDefaultKnownDb(database);
// if no table has been given to us, try knownGene
if (tableName == NULL)
tableName = "knownGene";
struct trackDb *tdb = hTrackDbForTrack(database, tableName);
if ((tdb == NULL) && sameString(tableName, "knownGene") && differentString(database, knownDb))
{
// if no table or knownGene has been given to us, and knownGene doesn't work, try the default gene track.
tableName = hdbGetMasterGeneTrack(knownDb);
tdb = hTrackDbForTrack(database, tableName);
}
if (tdb == NULL)
hUserAbort("Error: cannot open gene track %s.", tableName);
globalTdb = tdb;
char *externalDb = trackDbSetting(tdb, "externalDb");
liftDb = trackDbSetting(tdb, "quickLiftDb");
if (externalDb != NULL)
conn = hAllocConn(externalDb);
else
{
char *db = (liftDb != NULL) ? liftDb : database;
genome = hGenome(db);
conn = hAllocConn(db);
}
getGenomeSettings();
curGeneId = findGeneId(conn, geneName);
getGenePosition(conn);
curGenePred = getCurGenePred(conn);
// if we're quickLifting we need to map the liftDb genepred to the one in the quickLift hub
if (liftDb != NULL)
quickLiftGenePred(cart, tdb);
curGeneName = getGeneName(curGeneId, conn);
spConn = hAllocConn(UNIPROT_DB_NAME);
swissProtAcc = getSwissProtAcc(conn, spConn, curGeneId);
if (isRgdGene(conn)) swissProtAcc=getRgdGeneUniProtAcc(curGeneId, conn);
/* Check command variables, and do the ones that
* don't want to put up the hot link bar etc. */
if (cartVarExists(cart, hggDoGetMrnaSeq))
doGetMrnaSeq(conn, curGeneId, curGeneName);
else if (cartVarExists(cart, hggDoWikiTrack))
doWikiTrack(conn);
else if (cartVarExists(cart, hggDoGetProteinSeq))
doGetProteinSeq(conn, curGeneId, curGeneName);
else if (cartVarExists(cart, hggDoRnaFoldDisplay))
doRnaFoldDisplay(conn, curGeneId, curGeneName);
else if (cartVarExists(cart, hggDoOtherProteinSeq))
doOtherProteinSeq(conn, curGeneName);
else if (cartVarExists(cart, hggDoOtherProteinAli))
doOtherProteinAli(conn, curGeneId, curGeneName);
else
{
/* Default case - start fancy web page. */
measureTiming = isNotEmpty(cartOptionalString(cart, "measureTiming"));
isGencode = trackDbSettingOn(tdb, "isGencode");
isGencode2 = trackDbSettingOn(tdb, "isGencode2");
isGencode3 = trackDbSettingOn(tdb, "isGencode3");
if (isGencode2 || isGencode3)
cartWebStart(cart, database, "%s Gene %s (%s) from %s",
genome, curGeneName, curGeneId, tdb->longLabel);
else
cartWebStart(cart, database, "%s Gene %s (%s)",
genome, curGeneName, curAlignId);
webMain(conn, tdb);
cartWebEnd();
}
hFreeConn(&spConn);
hFreeConn(&conn);
}
cartRemovePrefix(cart, hggDoPrefix);
}
char *excludeVars[] = {"Submit", "submit", "ajax", hggAjaxSection, NULL};
int main(int argc, char *argv[])
/* Process command line. */
{
long enteredMainTime = clock1000();
/* 0, 0, == use default 10 second for warning, 20 second for immediate exit */
issueBotWarning = earlyBotCheck(enteredMainTime, "hgGene", delayFraction, 0, 0, "html");
cgiSpoof(&argc, argv);
htmlSetStyle(htmlStyleUndecoratedLink);
if (argc != 1)
usage();
oldVars = hashNew(10);
cartEmptyShell(cartMain, hUserCookie(), excludeVars, oldVars);
cgiExitTime("hgGene", enteredMainTime);
return 0;
}