struct group *groupTracks(char *db, struct trackDb *tracks)
/* Make up groups and assign tracks to groups. */
{
struct trackDb *track;
struct trackRef *tr;
struct group *group, *groups = NULL;
struct grp *grp;
struct grp *grps = hLoadGrps(db);
struct hash *groupHash = newHash(8);

/* Sort groups by priority */
slSort(&grps, cmpGroupPri);

/* Create hash and list of groups */
for (grp = grps; grp != NULL; grp = grp->next)
    {
    AllocVar(group);
    group->name = cloneString(grp->name);
    group->label = cloneString(grp->label);
    slAddTail(&groups, group);
    hashAdd(groupHash, grp->name, group);
    }

/* Add tracks to group */
for (track = tracks; track != NULL; track = track->next)
    {
    AllocVar(tr);
    tr->track = track;
    group = hashFindVal(groupHash, track->grp);
    slAddHead(&group->tracks, tr);
    }

/* order tracks within groups by priority */
for (group = groups; group != NULL; group = group->next)
    slSort(&group->tracks, cmpTrackPri);
hashFree(&groupHash);
return groups;
}
예제 #2
0
static struct grp *makeGroupList(char *db, struct trackDb *trackList, struct grp **pHubGrpList,
                                 boolean allTablesOk)
/* Get list of groups that actually have something in them. */
{
struct grp *groupsAll, *groupList = NULL, *group;
struct hash *groupsInTrackList = newHash(0);
struct hash *groupsInDatabase = newHash(0);
struct trackDb *track;

/* Stream through track list building up hash of active groups. */
for (track = trackList; track != NULL; track = track->next)
    {
    if (!hashLookup(groupsInTrackList,track->grp))
        hashAdd(groupsInTrackList, track->grp, NULL);
    }

/* Scan through group table, putting in ones where we have data. */
groupsAll = hLoadGrps(db);
for (group = slPopHead(&groupsAll); group != NULL; group = slPopHead(&groupsAll))
    {
    if (hashLookup(groupsInTrackList, group->name))
	{
	slAddTail(&groupList, group);
	hashAdd(groupsInDatabase, group->name, group);
	}
    else
        grpFree(&group);
    }

/* if we have custom tracks, we want to add the track hubs
 * after that group */
struct grp *addAfter = NULL;
if ((groupList != NULL) && sameString(groupList->name, "user"))
    addAfter = groupList;

/* Add in groups from hubs. */
for (group = slPopHead(pHubGrpList); group != NULL; group = slPopHead(pHubGrpList))
    {
    // if the group isn't represented in any track, don't add it to list
    if (!hashLookup(groupsInTrackList,group->name))
	continue;
    /* check to see if we're inserting hubs rather than
     * adding them to the front of the list */
    struct grp *newGrp = grpDup(group);
    if (addAfter != NULL)
	{
	newGrp->next = addAfter->next;
	addAfter->next = newGrp;
	}
    else
	slAddHead(&groupList, newGrp);
    hashAdd(groupsInDatabase, newGrp->name, newGrp);
    }

/* Do some error checking for tracks with group names that are
 * not in database.  Just warn about them. */
if (!trackHubDatabase(db))
    for (track = trackList; track != NULL; track = track->next)
    {
    if (!hashLookup(groupsInDatabase, track->grp))
         warn("Track %s has group %s, which isn't in grp table",
	 	track->table, track->grp);
    }

/* Create dummy group for all tracks. */
AllocVar(group);
group->name = cloneString("allTracks");
group->label = cloneString("All Tracks");
slAddTail(&groupList, group);

/* Create another dummy group for all tables. */
if (allTablesOk)
    {
    AllocVar(group);
    group->name = cloneString("allTables");
    group->label = cloneString("All Tables");
    slAddTail(&groupList, group);
    }

hashFree(&groupsInTrackList);
hashFree(&groupsInDatabase);
return groupList;
}
예제 #3
0
static void doFileSearch(char *db,char *organism,struct cart *cart,struct trackDb *tdbList)
{
struct sqlConnection *conn = hAllocConn(db);
boolean metaDbExists = sqlTableExists(conn, "metaDb");
if (!sqlTableExists(conn, "metaDb"))
    {
    warn("Assembly %s %s does not support Downloadable Files search.", organism, hFreezeFromDb(db));
    hFreeConn(&conn);
    return;
    }
char *nameSearch = cartOptionalString(cart, TRACK_SEARCH_ON_NAME);
char *descSearch=NULL;
char *fileTypeSearch = cartOptionalString(cart, FILE_SEARCH_ON_FILETYPE);
boolean doSearch = sameWord(cartUsualString(cart, FILE_SEARCH,"no"), "search");
#ifdef ONE_FUNC
struct hash *parents = newHash(4);
#endif///def ONE_FUNC
boolean searchTermsExist = FALSE;  // FIXME: Why is this needed?
int cols;

#ifdef USE_TABS
enum searchTab selectedTab = simpleTab;
char *currentTab = cartUsualString(cart, FILE_SEARCH_CURRENT_TAB, "simpleTab");
if (sameString(currentTab, "simpleTab"))
    {
    selectedTab = simpleTab;
    descSearch = cartOptionalString(cart, TRACK_SEARCH_SIMPLE);
    freez(&nameSearch);
    }
else if (sameString(currentTab, "filesTab"))
    {
    selectedTab = filesTab;
    descSearch = cartOptionalString(cart, TRACK_SEARCH_ON_DESCR);
    }
#else///ifndef USE_TABS
enum searchTab selectedTab = filesTab;
descSearch = cartOptionalString(cart, TRACK_SEARCH_ON_DESCR);
#endif///ndef USE_TABS

#ifdef USE_TABS
struct trix *trix;
char trixFile[HDB_MAX_PATH_STRING];
getSearchTrixFile(db, trixFile, sizeof(trixFile));
trix = trixOpen(trixFile);
#endif///def USE_TABS

printf("<div style='max-width:1080px;'>");
// FIXME: Do we need a form at all?
printf("<form action='../cgi-bin/hgFileSearch' name='%s' id='%s' method='get'>\n\n", 
       FILE_SEARCH_FORM,FILE_SEARCH_FORM);
cartSaveSession(cart);  // Creates hidden var of hgsid to avoid bad voodoo

printf("<input type='hidden' name='db' value='%s'>\n", db);
printf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_DEL_ROW);
printf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_ADD_ROW);

#ifdef USE_TABS
printf("<input type='hidden' name='%s' id='currentTab' value='%s'>\n", 
       FILE_SEARCH_CURRENT_TAB, currentTab);
printf("<div id='tabs' style='display:none; %s'>\n"
       "<ul>\n"
       "<li><a href='#simpleTab'><B style='font-size:.9em;font-family: arial, Geneva, "
       "Helvetica, san-serif;'>Search</B></a></li>\n"
       "<li><a href='#filesTab'><B style='font-size:.9em;font-family: arial, Geneva, "
       "Helvetica, san-serif;'>Files</B></a></li>\n"
       "</ul>\n",cgiBrowser()==btIE?"width:1060px;":"max-width:inherit;");

// Files tab
printf("<div id='simpleTab' style='max-width:inherit;'>\n");

printf("<table id='simpleTable' style='width:100%%; font-size:.9em;'><tr><td colspan='2'>");
printf("<input type='text' name='%s' id='simpleSearch' class='submitOnEnter' value='%s' "
       "style='max-width:1000px; width:100%%;' onkeyup='findTracks.searchButtonsEnable(true);'>\n",
       TRACK_SEARCH_SIMPLE,descSearch == NULL ? "" : descSearch);
if (selectedTab==simpleTab && descSearch)
    searchTermsExist = TRUE;

printf("</td></tr><td style='max-height:4px;'></td></tr></table>");
printf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n",
       FILE_SEARCH);
printf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' "
       "onclick='findTracks.clear();'>\n");
printf("<input type='submit' name='submit' value='cancel' class='cancel' "
       "style='font-size:.8em;'>\n");
printf("</div>\n");
#endif///def USE_TABS

// Files tab
printf("<div id='filesTab' style='width:inherit;'>\n"
        "<table id='filesTable' cellSpacing=0 style='width:inherit; font-size:.9em;'>\n");
cols = 8;

// Track Name contains
printf("<tr><td colspan=3></td>");
printf("<td nowrap><b style='max-width:100px;'>Track&nbsp;Name:</b></td>");
printf("<td align='right'>contains</td>\n");
printf("<td colspan='%d'>", cols - 4);
printf("<input type='text' name='%s' id='nameSearch' class='submitOnEnter' value='%s' "
       "onkeyup='findTracks.searchButtonsEnable(true);' style='min-width:326px; font-size:.9em;'>",
       TRACK_SEARCH_ON_NAME, nameSearch == NULL ? "" : nameSearch);
printf("</td></tr>\n");

// Description contains
printf("<tr><td colspan=2></td><td align='right'>and&nbsp;</td>");
printf("<td><b style='max-width:100px;'>Description:</b></td>");
printf("<td align='right'>contains</td>\n");
printf("<td colspan='%d'>", cols - 4);
printf("<input type='text' name='%s' id='descSearch' value='%s' class='submitOnEnter' "
       "onkeyup='findTracks.searchButtonsEnable(true);' style='max-width:536px; "
       "width:536px; font-size:.9em;'>",
       TRACK_SEARCH_ON_DESCR, descSearch == NULL ? "" : descSearch);
printf("</td></tr>\n");
if (selectedTab==filesTab && descSearch)
    searchTermsExist = TRUE;

// Set up Group dropdown
struct grp *grps = hLoadGrps(db);
grps = groupsFilterForTdbList(&grps,tdbList);
int numGroups = slCount(grps) + 1; // Add Any
char **groups = needMem(sizeof(char *) * numGroups);
char **labels = needMem(sizeof(char *) * numGroups);
groups[0] = ANYLABEL;
labels[0] = ANYLABEL;
int ix=1;
struct grp *grp = grps;
for (; grp != NULL; grp = grp->next,ix++)
    {
    groups[ix] = cloneString(grp->name);
    labels[ix] = cloneString(grp->label);
    }

printf("<tr><td colspan=2></td><td align='right'>and&nbsp;</td>\n");
printf("<td><b style='max-width:100px;'>Group:</b></td>");
printf("<td align='right'>is</td>\n");
printf("<td colspan='%d'>", cols - 4);
char *groupSearch = cartOptionalString(cart, TRACK_SEARCH_ON_GROUP);
cgiMakeDropListFull(TRACK_SEARCH_ON_GROUP, labels, groups, numGroups, groupSearch, 
                    "class='groupSearch' style='min-width:40%; font-size:.9em;'");
printf("</td></tr>\n");
if (selectedTab==filesTab && groupSearch)
    searchTermsExist = TRUE;

// Track Type is (drop down)
printf("<tr><td colspan=2></td><td align='right'>and&nbsp;</td>\n");
printf("<td nowrap><b style='max-width:100px;'>Data Format:</b></td>");
printf("<td align='right'>is</td>\n");
printf("<td colspan='%d'>", cols - 4);
char *dropDownHtml = fileFormatSelectHtml(FILE_SEARCH_ON_FILETYPE,fileTypeSearch,
                                          "style='min-width:40%; font-size:.9em;'");
if (dropDownHtml)
    {
    puts(dropDownHtml);
    freeMem(dropDownHtml);
    }
printf("</td></tr>\n");
if (selectedTab==filesTab && fileTypeSearch)
    searchTermsExist = TRUE;

// mdb selects
struct slPair *mdbSelects = NULL;
if (metaDbExists)
    {
    struct slPair *mdbVars = mdbVarsSearchable(conn,FALSE,TRUE); // Not tables, just files
    mdbSelects = mdbSelectPairs(cart, mdbVars);
    char *output = mdbSelectsHtmlRows(conn,mdbSelects,mdbVars,cols,TRUE); // just for fileSearch
    if (output)
        {
        puts(output);
        freeMem(output);
        }
    slPairFreeList(&mdbVars);
    }

printf("</table>\n");
printf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", 
       FILE_SEARCH);
printf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' "
       "onclick='findTracks.clear();'>\n");
printf("<input type='submit' name='submit' value='cancel' class='cancel' "
       "style='font-size:.8em;'>\n");
printf("</div>\n");

#ifdef USE_TABS
printf("</div>\n"); // End tabs div
#endif///def USE_TABS

if (nameSearch != NULL && !strlen(nameSearch))
    nameSearch = NULL;
if (descSearch != NULL && !strlen(descSearch))
    descSearch = NULL;
if (groupSearch != NULL && sameString(groupSearch, ANYLABEL))
    groupSearch = NULL;

printf("</form>\n");
printf("</div>"); // Restricts to max-width:1000px;
cgiDown(0.8);

if (measureTiming)
    uglyTime("Generated search controls");


#ifdef USE_TABS
if (doSearch && selectedTab==simpleTab && isEmpty(descSearch))
    doSearch = FALSE;
#endif///def USE_TABS

if (doSearch)
    {
    // Now search
#ifdef USE_TABS
    struct slRef *foundTdbs = NULL;
    if (selectedTab==simpleTab)
        {
        foundTdbs = simpleSearchForTdbs(trix,descWords,descWordCount);
        // What to do now?
        if (measureTiming)
            uglyTime("Searched for tracks");

        // Sort and Print results
        if (selectedTab!=filesTab)
            {
            enum sortBy sortBy = cartUsualInt(cart,TRACK_SEARCH_SORT,sbRelevance);
            int tracksFound = slCount(foundTdbs);
            if (tracksFound > 1)
                findTracksSort(&tracks,sortBy);

            displayFoundTracks(cart,tracks,tracksFound,sortBy);

            if (measureTiming)
                uglyTime("Displayed found files");
            }
        }
    else if (selectedTab==filesTab && mdbPairs != NULL)
#endif ///def USE_TABS
        {
        if (nameSearch || descSearch || groupSearch)
            {  // Use nameSearch, descSearch and groupSearch to narrow down the list of composites.

            if (isNotEmpty(nameSearch) || isNotEmpty(descSearch) || isNotEmpty(groupSearch))
                {
                struct trackDb *tdbList = hTrackDb(db);
                struct trackDb *tdbsMatch = tdbFilterBy(&tdbList, nameSearch, descSearch, 
                                                        groupSearch);

                // Now we have a list of tracks, so we need a unique list of composites to add
                doSearch = mdbSelectsAddFoundComposites(&mdbSelects,tdbsMatch);
                }
            }

        if (doSearch && mdbSelects != NULL && isNotEmpty(fileTypeSearch))
            fileSearchResults(db, conn, cart, mdbSelects, fileTypeSearch);
        else
            printf("<DIV id='filesFound'><BR>No files found.<BR></DIV><BR>\n");

        if (measureTiming)
            uglyTime("Searched for files");
        }

    slPairFreeList(&mdbSelects);
    }
hFreeConn(&conn);

webNewSection("About " FILE_SEARCH_NAME);
printf("Search for downloadable ENCODE files by entering search terms in "
       "the Track name or Description fields and/or by making selections with "
       "the group, data format, and/or ENCODE metadata drop-downs.");
printf("<BR><a target='_blank' href='../goldenPath/help/fileSearch.html'>more help</a>\n");
}