sections to the main table browser page for the tutorial. refs #35126
diff --git src/hg/hgTables/mainPage.c src/hg/hgTables/mainPage.c
index 0fa0f9cddda..4ea5fd10bc8 100644
--- src/hg/hgTables/mainPage.c
+++ src/hg/hgTables/mainPage.c
@@ -1,1179 +1,1194 @@
/* mainPage - stuff to put up the first table browser page. */
/* Copyright (C) 2014 The Regents of the University of California
* See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */
#include "common.h"
#include "linefile.h"
#include "hash.h"
#include "htmshell.h"
#include "cheapcgi.h"
#include "cart.h"
#include "cartTrackDb.h"
#include "textOut.h"
#include "jksql.h"
#include "hdb.h"
#include "web.h"
#include "jsHelper.h"
#include "hui.h"
#include "hgColors.h"
#include "trackDb.h"
#include "grp.h"
#include "hgTables.h"
#include "joiner.h"
#include "trackDb.h"
#include "hubConnect.h"
#include "trackHub.h"
#include "hgConfig.h"
static struct dyString *onChangeStart()
/* Start up a javascript onChange command */
{
struct dyString *dy = jsOnChangeStart();
jsDropDownCarryOver(dy, hgtaTrack);
jsDropDownCarryOver(dy, hgtaGroup);
jsTrackedVarCarryOver(dy, hgtaRegionType, "regionType");
jsTextCarryOver(dy, hgtaRange);
jsDropDownCarryOver(dy, hgtaOutputType);
jsTextCarryOver(dy, hgtaOutFileName);
return dy;
}
static char *onChangeClade()
/* Return javascript executed when they change clade. */
{
struct dyString *dy = onChangeStart();
jsDropDownCarryOver(dy, "clade");
jsDropDownCarryOver(dy, hgtaTable);
dyStringAppend(dy, " document.hiddenForm.org.value=0;");
dyStringAppend(dy, " document.hiddenForm.db.value=0;");
dyStringAppend(dy, " document.hiddenForm.position.value='';");
return jsOnChangeEnd(&dy);
}
static char *onChangeOrg()
/* Return javascript executed when they change organism. */
{
struct dyString *dy = onChangeStart();
jsDropDownCarryOver(dy, "clade");
jsDropDownCarryOver(dy, "org");
jsDropDownCarryOver(dy, hgtaTable);
dyStringAppend(dy, " document.hiddenForm.db.value=0;");
dyStringAppend(dy, " document.hiddenForm.position.value='';");
return jsOnChangeEnd(&dy);
}
static char *onChangeDb()
/* Return javascript executed when they change database. */
{
struct dyString *dy = onChangeStart();
jsDropDownCarryOver(dy, "clade");
jsDropDownCarryOver(dy, "db");
jsDropDownCarryOver(dy, hgtaTable);
dyStringAppend(dy, " document.hiddenForm.position.value='';");
return jsOnChangeEnd(&dy);
}
static char *onChangeGroupOrTrack()
/* Return javascript executed when they change group. */
{
struct dyString *dy = onChangeStart();
jsDropDownCarryOver(dy, "clade");
jsDropDownCarryOver(dy, "db");
jsDropDownCarryOver(dy, "org");
dyStringPrintf(dy, " document.hiddenForm.%s.value=0;", hgtaTable);
return jsOnChangeEnd(&dy);
}
static char *onChangeTable()
/* Return javascript executed when they change group. */
{
struct dyString *dy = onChangeStart();
jsDropDownCarryOver(dy, "clade");
jsDropDownCarryOver(dy, "db");
jsDropDownCarryOver(dy, "org");
jsDropDownCarryOver(dy, hgtaTable);
return jsOnChangeEnd(&dy);
}
void makeRegionButtonExtraHtml(char *val, char *selVal, char *extraHtml)
/* Make region radio button including a little Javascript to save selection state
* and optional extra html attributes. */
{
jsMakeTrackingRadioButtonExtraHtml(hgtaRegionType, "regionType", val, selVal, extraHtml);
}
void makeRegionButton(char *val, char *selVal)
/* Make region radio button including a little Javascript
* to save selection state. */
{
makeRegionButtonExtraHtml(val, selVal, NULL);
}
struct grp *showGroupField(char *groupVar, char *event, char *groupScript,
struct sqlConnection *conn, boolean allTablesOk)
/* Show group control. Returns selected group. */
{
struct grp *group, *groupList = fullGroupList;
struct grp *selGroup = findSelectedGroup(groupList, groupVar);
hPrintf("Group:\n");
hPrintf("\n");
return selGroup;
}
static void addIfExists(struct hash *hash, struct slName **pList, char *name)
/* Add name to tail of list if it exists in hash. */
{
if (hashLookup(hash, name))
slNameAddTail(pList, name);
}
struct slName *getDbListForGenome()
/* Get list of selectable databases. */
{
struct hash *hash = sqlHashOfDatabases();
struct slName *dbList = NULL;
addIfExists(hash, &dbList, database);
addIfExists(hash, &dbList, "uniProt");
addIfExists(hash, &dbList, "proteome");
addIfExists(hash, &dbList, "go");
addIfExists(hash, &dbList, "hgFixed");
addIfExists(hash, &dbList, "visiGene");
addIfExists(hash, &dbList, "ultra");
return dbList;
}
char *findSelDb()
/* Find user selected database (as opposed to genome database). */
{
struct slName *dbList = getDbListForGenome();
char *selDb = cartUsualString(cart, hgtaTrack, NULL);
if (!slNameInList(dbList, selDb))
selDb = cloneString(dbList->name);
slFreeList(&dbList);
return selDb;
}
struct trackDb *showTrackField(struct grp *selGroup, char *trackVar, char *event, char *trackScript,
boolean disableNoGenome)
/* Show track control. Returns selected track. */
{
struct trackDb *track, *selTrack = NULL;
if (trackScript == NULL)
trackScript = "";
if (sameString(selGroup->name, "allTables"))
{
char *selDb = findSelDb();
struct slName *dbList = getDbListForGenome(), *db;
hPrintf("database:\n");
hPrintf("\n");
}
else
{
boolean allTracks = sameString(selGroup->name, "allTracks");
hPrintf("Track:\n");
hPrintf("\n");
}
hPrintf("\n");
return selTrack;
}
char *unsplitTableName(char *table)
/* Convert chr*_name to name */
{
if (startsWith("chr", table))
{
char *s = strrchr(table, '_');
if (s != NULL)
{
table = s + 1;
}
}
return table;
}
struct slName *tablesForDb(char *db)
/* Find tables associated with database. */
{
boolean isGenomeDb = sameString(db, database);
struct sqlConnection *conn = hAllocConn(db);
struct slName *raw, *rawList = sqlListTables(conn);
struct slName *cooked, *cookedList = NULL;
struct hash *uniqHash = newHash(0);
hFreeConn(&conn);
for (raw = rawList; raw != NULL; raw = raw->next)
{
if (cartTrackDbIsAccessDenied(db, raw->name))
continue;
if (isGenomeDb)
{
/* Deal with tables split across chromosomes. */
char *root = unsplitTableName(raw->name);
if (cartTrackDbIsAccessDenied(db, root))
continue;
if (!hashLookup(uniqHash, root))
{
hashAdd(uniqHash, root, NULL);
cooked = slNameNew(root);
slAddHead(&cookedList, cooked);
}
}
else
{
char dbTable[256];
safef(dbTable, sizeof(dbTable), "%s.%s", db, raw->name);
cooked = slNameNew(dbTable);
slAddHead(&cookedList, cooked);
}
}
hashFree(&uniqHash);
slFreeList(&rawList);
slSort(&cookedList, slNameCmp);
return cookedList;
}
char *showTableField(struct trackDb *track, char *varName, boolean useJoiner)
/* Show table control and label. */
{
struct slName *name, *nameList = NULL;
char *selTable;
if (track == NULL)
nameList = tablesForDb(findSelDb());
else
nameList = cartTrackDbTablesForTrack(database, track, useJoiner);
/* Get currently selected table. If it isn't in our list
* then revert to first in list. */
selTable = cartUsualString(cart, varName, nameList->name);
if (!slNameInListUseCase(nameList, selTable))
selTable = nameList->name;
/* Print out label and drop-down list. */
hPrintf("Table: ");
hPrintf("\n");
if (!trackHubDatabase(database))
{
char *restrictDate = encodeRestrictionDateDisplay(database,selTdb);
if (restrictDate)
{
hPrintf("restricted until: %s",
ENCODE_DATA_RELEASE_POLICY, restrictDate);
freeMem(restrictDate);
}
}
return selTable;
}
struct outputType
/* Info on an output type. */
{
struct outputType *next;
char *name; /* Symbolic name of type. */
char *label; /* User visible label. */
};
static void showOutDropDown(struct outputType *otList, struct outputType *otDefault)
/* Display output drop-down. */
{
struct outputType *ot;
char *outputType = cartUsualString(cart, hgtaOutputType, otList->name);
if (otDefault != NULL && otDefault != otList)
{
boolean otInOtList = FALSE;
for (ot = otList; ot != NULL; ot = ot->next)
if (sameString(ot->name, outputType))
{
otInOtList = TRUE;
break;
}
if (! otInOtList)
outputType = otDefault->name;
}
hPrintf("\n");
hPrintf(" ");
hPrintf("
"
"Note: Table Browser GTF files contain transcripts, but no gene identifiers or symbols. "
"If you are looking for fully formatted "
"gene model files for use in genome analysis pipelines, check the "
"bigZips/genes "
"directory on our download server.
", trackHubSkipHubName(database));
hPrintf("
"
"Signal data points format: The Table Browser outputs signal track data in "
"wiggle format by default. You can also use the "
"Table Browser filter feature to designate a value threshold and then output that as BED format. The "
"Table Browser will then create a BED file with an entry for every value that passes the filter. Our command line tool "
"bigWigToBedGraph can also be used "
"to convert wig files directly. Contact us at genome@soe.ucsc.edu for help with data extraction or conversion.
");
hPrintf(" ");
// we should make an hgTables.js one day, this is ugly
jsInline("function checkOutputNotes(event) {\n"
"var outType=document.getElementById('outputTypeDropdown').value;\n"
"if (outType==='gff')\n"
" document.getElementById('gffNote').style.display='';\n"
"else if (outType==='wigData')\n"
" document.getElementById('wigNote').style.display='';\n"
"else\n"
" $('.outputNote').hide();\n" // a lot shorter with Jquery than without
"}\n"
"$(document).ready(checkOutputNotes);\n"
);
jsAddEventForId("change", "outputTypeDropdown", "checkOutputNotes");
jsInline("function checkSnpTablesNote(event) {\n"
"var trackName = document.getElementById('hgta_track').value;\n"
"if (trackName.startsWith('dbSnp') || trackName.startsWith('snp'))\n"
" document.getElementById('snpTablesNote').style.display='';\n"
"else\n"
" document.getElementById('snpTablesNote').style.display='none';\n"
"}\n"
"$(document).ready(checkSnpTablesNote);\n"
);
jsAddEventForId("change", "outputTypeDropdown", "checkSnpTablesNote");
jsInlineF("function checkForCsv(event) {\n"
"var outputType = document.getElementById('outputTypeDropdown').value;\n"
"if (outputType === 'primaryTable' || outputType === 'selectedFields') {\n"
" document.getElementById('%s').parentElement.style.display='';\n"
" document.getElementById('excelOutNote').style.display='';\n"
"} else {\n"
" document.getElementById('%s').parentElement.style.display='none';\n"
" document.getElementById('excelOutNote').style.display='none';\n"
"}\n"
"}\n"
"$(document).ready(checkForCsv);\n"
, hgtaOutSep, hgtaOutSep);
jsAddEventForId("change", "outputTypeDropdown", "checkForCsv");
+/*
+ * Code to add in the interactive tutorial*/
+if (cfgOptionBooleanDefault("showTutorial", TRUE))
+ {
+ puts("");
+ puts("");
+ jsIncludeFile("tableBrowserTutorial.js",NULL);
+ if (sameOk(cgiOptionalString("startTutorial"), "true"))
+ {
+ jsInline("tableBrowserTour.start();");
+ }
+ }
+
if (!cfgOptionBooleanDefault("hgta.disableSendOutput", FALSE))
{
hPrintf(" Send output to ");
struct dyString *dy = dyStringNew(256);
dyStringAppend(dy,
"document.getElementById('checkboxGreat').checked=false;");
if (isGenomeSpaceEnabled())
dyStringAppend(dy,
"document.getElementById('checkboxGenomeSpace').checked=false;");
dyStringAppend(dy,
"return true;");
cgiMakeCheckBoxWithId("sendToGalaxy", doGalaxy(), "checkboxGalaxy");
jsOnEventById("click", "checkboxGalaxy", dy->string);
hPrintf("Galaxy\n");
nbSpaces(2);
cgiMakeCheckBoxWithId("sendToGreat", doGreat(), "checkboxGreat");
jsOnEventById("click", "checkboxGreat", "return onSelectGreat();");
hPrintf(" GREAT");
if (isGenomeSpaceEnabled())
{
nbSpaces(2);
cgiMakeCheckBoxWithId("sendToGenomeSpace", doGenomeSpace(), "checkboxGenomeSpace");
jsOnEventById("click", "checkboxGenomeSpace",
"document.getElementById('checkboxGreat').checked=false;"
"document.getElementById('checkboxGalaxy').checked=false; return true;");
hPrintf(" GenomeSpace");
}
}
-hPrintf("\n");
+hPrintf("
");
}
void printNoGenomeWarning(struct trackDb *curTrack) {
/* print a message box that explains why a track is not downloadable */
hPrintf("
");
char *noGenomeNote = trackDbSettingClosestToHome(curTrack, "noGenomeReason");
hPrintf("Note: This track is unavailable for genome-wide download. ");
if (noGenomeNote)
hPrintf("Reason: %s", noGenomeNote);
else
hPrintf("Usually, this is due to distribution restrictions of the source database or the size of the track. Please see the track documentation for more details. Contact us if you are still unable to access the data. ");
hPrintf("
"
"Note: Most dbSNP tables are huge. Trying to download them through the Table Browser "
"usually leads to a timeout. "
"Please see our Data Access FAQ "
"on how to download dbSNP data.
");
/* Region line */
{
printStep(stepNumber++);
char *regionType;
if (cartVarExists(cart, "hgFind.matches")) // coming back from a search
regionType = cartUsualString(cart, hgtaRegionType, hgtaRegionTypeRange);
else
regionType = cartUsualString(cart, hgtaRegionType, hgtaRegionTypeGenome);
char *range = cartUsualString(cart, hgtaRange, "");
if (isPositional)
{
boolean doEncode = FALSE;
if (!trackHubDatabase(database))
doEncode = sqlTableExists(conn, "encodeRegions");
- hPrintf("
Region:\n");
+ hPrintf("
Region:\n");
/* If regionType not allowed force it to "genome". */
if ((sameString(regionType, hgtaRegionTypeUserRegions) &&
userRegionsFileName() == NULL) ||
(sameString(regionType, hgtaRegionTypeEncode) && !doEncode))
regionType = hgtaRegionTypeGenome;
// Is "genome" is not allowed because of tdb 'tableBrowser noGenome'?
boolean disableGenome = ((curTrack && cartTrackDbIsNoGenome(database, curTrack->table)) ||
(curTable && cartTrackDbIsNoGenome(database, curTable)));
// If "genome" is selected but not allowed, force it to "range":
if (sameString(regionType, hgtaRegionTypeGenome) && disableGenome)
regionType = hgtaRegionTypeRange;
jsTrackingVar("regionType", regionType);
if (disableGenome)
{
makeRegionButtonExtraHtml(hgtaRegionTypeGenome, regionType, "DISABLED");
hPrintf(" genome (unavailable for selected track)"
" ");
}
else
{
makeRegionButton(hgtaRegionTypeGenome, regionType);
hPrintf(" Genome ");
}
if (doEncode)
{
makeRegionButton(hgtaRegionTypeEncode, regionType);
hPrintf(" ENCODE Pilot regions ");
}
makeRegionButton(hgtaRegionTypeRange, regionType);
hPrintf(" Position ");
hPrintf("\n",
hgtaRange, hgtaRange, range);
jsOnEventById("focus", hgtaRange,
jsRadioUpdate(hgtaRegionType, "regionType", "range"));
cgiMakeButton(hgtaDoLookupPosition, "Lookup");
hPrintf(" ");
if (userRegionsFileName() != NULL)
{
makeRegionButton(hgtaRegionTypeUserRegions, regionType);
hPrintf(" Defined regions ");
cgiMakeButton(hgtaDoSetUserRegions, "Change");
hPrintf(" ");
cgiMakeButton(hgtaDoClearUserRegions, "Clear");
}
else
cgiMakeButton(hgtaDoSetUserRegions, "Define regions");
+ hPrintf("
");
hPrintf("
\n");
if (disableGenome) { // no need to check curTrack for NULL, disableGenome can only be set if curTable is set
hPrintf("
");
printNoGenomeWarning(curTrack);
hPrintf("
");
}
}
else
{
/* Need to put at least stubs of cgi variables in for JavaScript to work. */
jsTrackingVar("regionType", regionType);
cgiMakeHiddenVar(hgtaRange, range);
cgiMakeHiddenVar(hgtaRegionType, regionType);
}
/* Select identifiers line (if applicable). */
if (!isWig && getIdField(database, curTrack, curTable, hti) != NULL)
{
- hPrintf("
\n");
if (isWig || isBam || isVcf || isLongTabix || isHic)
{
char *name;
extern char *maxOutMenu[];
char *maxOutput = maxOutMenu[0];
if (isCustomTrack(curTable))
name=filterFieldVarName("ct", curTable, "_", filterMaxOutputVar);
else
name=filterFieldVarName(database,curTable, "_",filterMaxOutputVar);
maxOutput = cartUsualString(cart, name, maxOutMenu[0]);
if (isWig)
hPrintf(
"Note: to return more than %s lines, change the filter setting"
" (above). The entire data set may be available for download as"
" a very large file that contains the original data values (not"
" compressed into the wiggle format) -- see the Downloads page."
" ", maxOutput);
else if (isBam || isVcf || isLongTabix || isHic)
hPrintf(
"Note: to return more than %s lines, change the filter setting"
" (above). Please consider downloading the entire data from our Download pages."
" ", maxOutput);
}
else if (anySubtrackMerge(database, curTable) || anyIntersection())
{
hPrintf("Note: The all fields and selected fields output formats "
"are not available when a%s has been specified. ",
canSubtrackMerge ? " subtrack merge or intersection" : "n intersection");
}
cgiMakeButton(hgtaDoTopSubmit, "Get output");
hPrintf(" ");
if (isPositional || isWig)
{
cgiMakeButton(hgtaDoSummaryStats, "Summary/statistics");
hPrintf(" ");
}
+ hPrintf("
");
#ifdef SOMETIMES
hPrintf(" ");
cgiMakeButton(hgtaDoTest, "test");
#endif /* SOMETIMES */
}
hPrintf("");
}
static char *getGenomeSpaceText()
/* fetch GenomeSpace text if enabled */
{
if (isGenomeSpaceEnabled())
{
return
"Send data to "
"GenomeSpace for use with diverse computational tools. ";
}
else
{
return "";
}
}
void mainPageAfterOpen(struct sqlConnection *conn)
/* Put up main page assuming htmlOpen()/htmlClose()
* will happen in calling routine. */
{
hPrintf(
"Use this tool to retrieve and export data from the Genome Browser annotation track database. "
"You can limit retrieval based on data attributes and intersect or merge with data from "
"another track, or retrieve DNA sequence covered by a track."
);
hPrintf(" More...");
hPrintf(
""
"For a description of the controls below, "
"see Using the Table Browser (below). "
"General information and sample queries are available from the "
"Table Browser User's Guide. "
"For more complex queries, we recommend "
"Galaxy or "
"our public "
"MySQL server. "
"To examine the biological function of your set through annotation "
"enrichments, send the data to "
"GREAT. "
"%s"
"Refer to the "
"Credits page for the list of "
"contributors and usage restrictions associated with these data. "
"Bulk download of track data is available from the "
"Sequence and Annotation Downloads page."
, getGenomeSpaceText(), cgiAppendSForHttps()
);
hPrintf(" Less...");
// Show more or less intro text
char jsText[1024];
safef(jsText, sizeof jsText,
"$('#tbHelpMore').hide();"
"$('#tbHelp').show();"
"$('#tbHelpLess').show();"
);
jsOnEventById("click", "tbHelpMore", jsText);
safef(jsText, sizeof jsText,
"$('#tbHelpMore').show();"
"$('#tbHelp').hide();"
"$('#tbHelpLess').hide();"
);
jsOnEventById("click", "tbHelpLess", jsText);
// When GREAT is selected, disable the other checkboxes and force output to BED
jsInline(
"function onSelectGreat() {\n"
" document.getElementById('checkboxGalaxy').checked=false;\n");
if (isGenomeSpaceEnabled())
jsInline(
" document.getElementById('checkboxGenomeSpace').checked=false;\n");
jsInline(
" document.getElementById('outBed').selected=true;\n"
" return true;\n"
"}\n");
// Disable/enable noGenome tracks depending on whether region is genome.
jsInline(
"function maybeDisableNoGenome() {\n"
" var regionTypeSelected = $('input[name=\"hgta_regionType\"]:checked').val();\n"
" var regionIsGenome = (regionTypeSelected === 'genome');\n"
" var $noGenomeOptions = $('select[name=\"hgta_track\"] option.hgtaNoGenome,select[name=\"hgta_table\"] option.hgtaNoGenome');\n"
" $noGenomeOptions.attr('disabled', regionIsGenome)\n"
" .css('color', regionIsGenome ? '' : 'black');\n"
"}\n"
"$(document).ready(function() {\n"
// once when the page loads, and every time the user changes the region type:
" maybeDisableNoGenome();\n"
" $('input[name=\"hgta_regionType\"]').change(maybeDisableNoGenome);\n"
"});\n");
/* Main form. */
hPrintf("\n");
/* Hidden form - for benefit of javascript. */
{
static char *saveVars[] = {
"clade", "org", "db", hgtaGroup, hgtaTrack, hgtaTable, hgtaRegionType,
hgtaRange, hgtaOutputType, hgtaOutFileName};
jsCreateHiddenForm(cart, getScriptName(), saveVars, ArraySize(saveVars));
}
webNewSection("Using the Table Browser\n");
printMainHelp();
cartFlushHubWarnings();
}
void doMainPage(struct sqlConnection *conn)
/* Put up the first page user sees. */
{
htmlOpen("Table Browser");
//webIncludeResourceFile("jquery-ui.css");
mainPageAfterOpen(conn);
htmlClose();
}