static void showTableFieldsDb(char *db, char *rootTable, boolean withGetButton) /* Put up a little html table with a check box, name, and hopefully * a description for each field in SQL rootTable. */ { struct sqlConnection *conn = NULL; if (!trackHubDatabase(database)) conn = hAllocConn(db); struct trackDb *tdb = findTdbForTable(db, curTrack, rootTable, ctLookupName); struct asObject *asObj = asForTable(conn, rootTable); boolean showItemRgb = FALSE; showItemRgb=bedItemRgb(tdb); /* should we expect itemRgb instead of "reserved" */ struct slName *fieldList; if (isBigBed(database, rootTable, curTrack, ctLookupName)) fieldList = bigBedGetFields(rootTable, conn); else if (isBamTable(rootTable)) fieldList = bamGetFields(); else if (isVcfTable(rootTable, NULL)) fieldList = vcfGetFields(); else { char *table = chromTable(conn, rootTable); fieldList = sqlListFields(conn, table); freez(&table); } showTableFieldsOnList(db, rootTable, asObj, fieldList, showItemRgb, withGetButton); hFreeConn(&conn); }
struct bed *getFilteredBeds(struct sqlConnection *conn, char *table, struct region *region, struct lm *lm, int *retFieldCount) /* Get list of beds on single region that pass filtering. */ { boolean isTabix = FALSE; /* region may be part of a list, and the routines we call work on lists of * regions. Temporarily force region->next to NULL and restore at end. */ struct region *oldNext = region->next; struct bed *bedList = NULL; region->next = NULL; if (isBigBed(database, table, curTrack, ctLookupName)) bedList = bigBedGetFilteredBedsOnRegions(conn, database, table, region, lm, retFieldCount); else if (isBamTable(table)) bedList = bamGetFilteredBedsOnRegions(conn, database, table, region, lm, retFieldCount); else if (isVcfTable(table, &isTabix)) bedList = vcfGetFilteredBedsOnRegions(conn, database, table, region, lm, retFieldCount, isTabix); else if (isCustomTrack(table)) bedList = customTrackGetFilteredBeds(database, table, region, lm, retFieldCount); else if (sameWord(table, WIKI_TRACK_TABLE)) bedList = wikiTrackGetFilteredBeds(table, region, lm, retFieldCount); else bedList = dbGetFilteredBedsOnRegions(conn, database, database, table, table, region, lm, retFieldCount); region->next = oldNext; return bedList; }
static struct slName *getExamples(char *db, struct sqlConnection *conn, char *table, char *field, int count) /* Return a list of several example values of table.field. */ { boolean isTabix = FALSE; if (isBamTable(table)) { assert(sameString(field, "qName")); return randomBamIds(table, conn, count); } else if (isBigBed(db, table, curTrack, ctLookupName)) { assert(sameString(field, "name")); return randomBigBedIds(table, conn, count); } else if (isVcfTable(table, &isTabix)) { assert(sameString(field, "id")); return randomVcfIds(table, conn, count, isTabix); } else { char fullTable[HDB_MAX_TABLE_STRING]; char *c = strchr(table, '.'); if (c || ! hFindSplitTable(database, NULL, table, fullTable, NULL)) safecpy(fullTable, sizeof(fullTable), table); return sqlRandomSampleConn(conn, fullTable, field, count); } }
boolean canIntersect(char *db, char *table) /* Return true if table exists and is positional. */ { if (isCustomTrack(table) && ctLookupName(table) != NULL) return TRUE; if (isBamTable(table)) return TRUE; if (isBigWigTable(table)) return TRUE; if (isBigBed(database, table, curTrack, ctLookupName)) return TRUE; if (isVcfTable(table, NULL)) return TRUE; if (isHubTrack(table)) return TRUE; if (sameWord(table, WIKI_TRACK_TABLE)) return TRUE; if (hTableOrSplitExists(db, table)) return isPositional(db, table); return FALSE; }
static struct hash *getAllPossibleIds(struct sqlConnection *conn, struct lm *lm, char *idField, char *extraWhere) /* If curTable is a custom track or bigFile, return NULL. Otherwise, * make a hash of all identifiers in curTable (and alias tables if specified) * so that we can check the validity of pasted/uploaded identifiers. */ { if (isCustomTrack(curTable) || isBamTable(curTable) || isVcfTable(curTable, NULL) || isBigBed(database, curTable, curTrack, ctLookupName)) return NULL; struct hash *matchHash = hashNew(20); struct slName *tableList; char *xrefTable = NULL, *xrefIdField = NULL, *aliasField = NULL; struct sqlConnection *alternateConn = conn; if (sameWord(curTable, WIKI_TRACK_TABLE)) alternateConn = wikiConnect(); if (sameWord(curTable, WIKI_TRACK_TABLE)) tableList = slNameNew(WIKI_TRACK_TABLE); else if (strchr(curTable, '.')) tableList = slNameNew(curTable); else tableList = hSplitTableNames(database, curTable); if (idField != NULL) addPrimaryIdsToHash(alternateConn, matchHash, idField, tableList, lm, extraWhere); getXrefInfo(alternateConn, &xrefTable, &xrefIdField, &aliasField); if (xrefTable != NULL) { addXrefIdsToHash(alternateConn, matchHash, idField, xrefTable, xrefIdField, aliasField, lm, extraWhere); } if (sameWord(curTable, WIKI_TRACK_TABLE)) wikiDisconnect(&alternateConn); return matchHash; }
static void filterControlsForTableDb(char *db, char *rootTable) /* Put up filter controls for a single database table. */ { struct sqlConnection *conn = NULL; if (!trackHubDatabase(db)) conn = hAllocConn(db); char *table = chromTable(conn, rootTable); struct trackDb *tdb = findTdbForTable(db, curTrack, rootTable, ctLookupName); boolean isSmallWig = isWiggle(db, table); boolean isBigWig = tdb ? tdbIsBigWig(tdb) : isBigWigTable(table); boolean isWig = isSmallWig || isBigWig; boolean isBedGr = tdb ? tdbIsBedGraph(tdb) : isBedGraph(rootTable); boolean isBb = tdb ? tdbIsBigBed(tdb) : isBigBed(database, table, curTrack, ctLookupName); boolean isBam = tdb ? tdbIsBam(tdb) : isBamTable(rootTable); boolean isVcf = tdb ? tdbIsVcf(tdb) : isVcfTable(rootTable, NULL); int bedGraphColumn = 5; /* default score column */ if (isBedGr) { int wordCount; char *words[8]; char *typeLine = cloneString(tdb->type); wordCount = chopLine(typeLine,words); if (wordCount > 1) bedGraphColumn = sqlUnsigned(words[1]); freez(&typeLine); } if (isWig) { hPrintf("<TABLE BORDER=0>\n"); if ((tdb != NULL) && (tdb->type != NULL)) { double min, max; wiggleMinMax(tdb,&min,&max); numericFilterWithLimits(db, rootTable, filterDataValueVar,filterDataValueVar,min,max,""); hPrintf("<TR><TD COLSPAN=3 ALIGN=RIGHT> (dataValue range: [%g:%g]) " "</TD></TR></TABLE>\n", min, max); } else { numericFilter(db, rootTable, filterDataValueVar,filterDataValueVar, ""); hPrintf("</TABLE>\n"); } } else { struct sqlFieldType *ftList; if (isBb) ftList = bigBedListFieldsAndTypes(tdb, conn); else if (isBam) ftList = bamListFieldsAndTypes(); else if (isVcf) ftList = vcfListFieldsAndTypes(); else ftList = sqlListFieldsAndTypes(conn, table); printSqlFieldListAsControlTable(ftList, db, rootTable, tdb, isBedGr); } /* Printf free-form query row. */ if (!(isWig||isBedGr||isBam||isVcf)) { char *name; hPrintf("<TABLE BORDER=0><TR><TD>\n"); name = filterFieldVarName(db, rootTable, "", filterRawLogicVar); cgiMakeDropList(name, logOpMenu, logOpMenuSize, cartUsualString(cart, name, logOpMenu[0])); hPrintf(" Free-form query: "); name = filterFieldVarName(db, rootTable, "", filterRawQueryVar); char *val = cartUsualString(cart, name, ""); // escape double quotes to avoid HTML parse trouble in the text input. val = htmlEncodeText(val, FALSE); cgiMakeTextVar(name, val, 50); hPrintf("</TD></TR></TABLE>\n"); } if (isWig||isBedGr||isBam||isVcf) { char *name; hPrintf("<TABLE BORDER=0><TR><TD> Limit data output to: \n"); name = filterFieldVarName(db, rootTable, "_", filterMaxOutputVar); cgiMakeDropList(name, maxOutMenu, maxOutMenuSize, cartUsualString(cart, name, maxOutMenu[0])); hPrintf(" lines</TD></TR></TABLE>\n"); } freez(&table); hFreeConn(&conn); hPrintf("<BR>\n"); cgiMakeButton(hgtaDoFilterSubmit, "submit"); hPrintf(" "); cgiMakeButton(hgtaDoMainPage, "cancel"); }
static void filterControlsForTableCt(char *db, char *table) /* Put up filter controls for a custom track. */ { struct customTrack *ct = ctLookupName(table); char *type = ct->dbTrackType; puts("<TABLE BORDER=0>"); if (type != NULL && startsWithWord("maf", type)) { stringFilterOption(db, table, "chrom", " AND "); integerFilter(db, table, "chromStart", "chromStart", " AND "); integerFilter(db, table, "chromEnd", "chromEnd", " AND "); } else if (type != NULL && (startsWithWord("makeItems", type) || sameWord("bedDetail", type) || sameWord("pgSnp", type))) { struct sqlConnection *conn = hAllocConn(CUSTOM_TRASH); struct sqlFieldType *ftList = sqlListFieldsAndTypes(conn, ct->dbTableName); printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE); hFreeConn(&conn); } else if (ct->wiggle || isBigWigTable(table)) { if ((ct->tdb != NULL) && (ct->tdb != NULL)) { double min, max; wiggleMinMax(ct->tdb,&min,&max); numericFilterWithLimits("ct", table, filterDataValueVar, filterDataValueVar,min,max,""); hPrintf("<TR><TD COLSPAN=3 ALIGN=RIGHT> (dataValue range: [%g,%g]) " "</TD></TR>\n", min, max); } else { numericFilter("ct", table, filterDataValueVar, filterDataValueVar,""); } } else if (isBigBed(db, table, curTrack, ctLookupName)) { struct sqlFieldType *ftList = bigBedListFieldsAndTypes(ct->tdb, NULL); printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE); } else if (isBamTable(table)) { struct sqlFieldType *ftList = bamListFieldsAndTypes(); printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE); } else if (isVcfTable(table, NULL)) { struct sqlFieldType *ftList = vcfListFieldsAndTypes(); printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE); } else { if (ct->fieldCount >= 3) { stringFilterOption(db, table, "chrom", " AND "); integerFilter(db, table, "chromStart", "chromStart", " AND "); integerFilter(db, table, "chromEnd", "chromEnd", " AND "); } if (ct->fieldCount >= 4) { stringFilterOption(db, table, "name", " AND "); } if (ct->fieldCount >= 5) { numericFilter(db, table, "score", "score", " AND "); } if (ct->fieldCount >= 6) { stringFilterOption(db, table, "strand", " AND "); } if (ct->fieldCount >= 8) { integerFilter(db, table, "thickStart", "thickStart", " AND "); integerFilter(db, table, "thickEnd", "thickEnd", " AND "); } if (ct->fieldCount >= 12) { integerFilter(db, table, "blockCount", "blockCount", " AND "); } /* These are not bed fields, just extra constraints that we offer: */ if (ct->fieldCount >= 3) { integerFilter(db, table, "chromLength", "(chromEnd - chromStart)", (ct->fieldCount >= 8) ? " AND " : ""); } if (ct->fieldCount >= 8) { integerFilter( db, table, "thickLength", "(thickEnd - thickStart)", " AND "); eqFilterOption(db, table, "compareStarts","chromStart","thickStart", " AND "); eqFilterOption(db, table, "compareEnds", "chromEnd", "thickEnd", ""); } } puts("</TABLE>"); if (ct->wiggle || isBigWigTable(table) || isBamTable(table) || isVcfTable(table, NULL)) { char *name; hPrintf("<TABLE BORDER=0><TR><TD> Limit data output to: \n"); name = filterFieldVarName("ct", table, "_", filterMaxOutputVar); cgiMakeDropList(name, maxOutMenu, maxOutMenuSize, cartUsualString(cart, name, maxOutMenu[0])); hPrintf(" lines</TD></TR></TABLE>\n"); } hPrintf("<BR>\n"); cgiMakeButton(hgtaDoFilterSubmit, "submit"); hPrintf(" "); cgiMakeButton(hgtaDoMainPage, "cancel"); }