static void orderFieldsInTable(struct tableJoiner *tj) /* Rearrange order of fields in tj->fieldList so that * they are the same as the order in the database. */ { struct sqlConnection *conn = hAllocConn(tj->database); char *splitTable = chromTable(conn, tj->table); struct hash *fieldHash = hashNew(0); struct slName *field, *fieldList = sqlListFields(conn, splitTable); struct joinerDtf *dtf, *newList = NULL; /* Build up hash of field names. */ for (dtf = tj->fieldList; dtf != NULL; dtf = dtf->next) hashAdd(fieldHash, dtf->field, dtf); hFreeConn(&conn); /* Build up new list in correct order. */ for (field = fieldList; field != NULL; field = field->next) { dtf = hashFindVal(fieldHash, field->name); if (dtf != NULL) { slAddHead(&newList, dtf); } } slFreeList(&fieldList); slReverse(&newList); tj->fieldList = newList; freez(&splitTable); }
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); }
void makeDbOrderedCommaFieldList(struct sqlConnection *conn, char *table, struct joinerDtf *dtfList, struct dyString *dy) /* Assumes that dtfList all points to same table. This will return * a comma-separated field list in the same order as the fields are * in database. */ { char *split = chromTable(conn, table); struct slName *fieldList = sqlListFields(conn, split); makeOrderedCommaFieldList(fieldList, dtfList, dy); slFreeList(&fieldList); freez(&split); }
long long gapsInRegion(struct sqlConnection *conn, struct region *regionList, int limit) /* Return count of gaps in all regions to limit number of regions, * limit=0 == no limit, do them all */ { long long gapBases = 0; char *splitTable = chromTable(conn, "gap"); int regionCount = 0; if (sqlTableExists(conn, splitTable)) { struct region *region; for (region = regionList; (region != NULL) && (!(limit && (regionCount >= limit))); region = region->next, ++regionCount) { int rowOffset; char **row; struct agpGap gap; struct sqlResult *sr = hRangeQuery(conn, "gap", region->chrom, region->start, region->end, NULL, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { agpGapStaticLoad(row + rowOffset, &gap); if (gap.chromStart < region->start) gap.chromStart = region->start; if (gap.chromEnd > region->end) gap.chromEnd = region->end; gapBases += gap.chromEnd - gap.chromStart; } sqlFreeResult(&sr); } } freez(&splitTable); return gapBases; }
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"); }