void doSummaryStatsWikiTrack(struct sqlConnection *conn) /* Put up page showing summary stats for wikiTrack. */ { struct sqlConnection *wikiConn = wikiConnect(); doSummaryStatsBed(wikiConn); wikiDisconnect(&wikiConn); }
struct bed *wikiTrackGetBedRange(char *table, char *chromName, int start, int end) /* fetch wiki track items as simple bed 3 list in given range */ { struct bed *bed, *bedList = NULL; struct sqlConnection *wikiConn = wikiConnect(); struct sqlResult *sr; char **row; char where[256]; int rowOffset; safef(where, ArraySize(where), "db='%s'", database); sr = hRangeQuery(wikiConn, table, chromName, start, end, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { struct wikiTrack *item = wikiTrackLoad(row); AllocVar(bed); bed->chrom = cloneString(item->chrom); bed->chromStart = item->chromStart; bed->chromEnd = item->chromEnd; slAddHead(&bedList, bed); wikiTrackFree(&item); } sqlFreeResult(&sr); wikiDisconnect(&wikiConn); return bedList; }
void addWikiTrack(struct track **pGroupList) /* Add wiki track and append to group list. */ { if (wikiTrackEnabled(database, NULL)) { struct track *tg = trackNew(); static char longLabel[80]; struct trackDb *tdb; struct sqlConnection *wikiConn = wikiConnect(); if (! sqlTableExists(wikiConn,WIKI_TRACK_TABLE)) errAbort("loadWikiTrack configuration error, set wikiTrack.URL in hg.conf"); linkedFeaturesMethods(tg); AllocVar(tdb); tg->track = WIKI_TRACK_TABLE; tg->table = WIKI_TRACK_TABLE; tg->canPack = TRUE; tg->visibility = tvHide; tg->hasUi = TRUE; tg->shortLabel = cloneString(WIKI_TRACK_LABEL); safef(longLabel, sizeof(longLabel), WIKI_TRACK_LONGLABEL); tg->longLabel = longLabel; tg->loadItems = wikiTrackLoadItems; tg->itemName = linkedFeaturesName; tg->mapItemName = wikiTrackMapItemName; tg->mapItem = wikiTrackMapItem; tg->priority = WIKI_TRACK_PRIORITY; tg->defaultPriority = WIKI_TRACK_PRIORITY; tg->groupName = cloneString("map"); tg->defaultGroupName = cloneString("map"); tg->exonArrows = TRUE; tg->nextItemButtonable = TRUE; tdb->track = cloneString(tg->track); tdb->canPack = tg->canPack; tdb->table = cloneString(tg->table); tdb->shortLabel = cloneString(tg->shortLabel); tdb->longLabel = cloneString(tg->longLabel); tdb->useScore = 1; tdb->grp = cloneString(tg->groupName); tdb->priority = tg->priority; trackDbPolish(tdb); tg->tdb = tdb; slAddHead(pGroupList, tg); wikiDisconnect(&wikiConn); } }
static void wikiTrackFilteredBedOnRegion( struct region *region, /* Region to get data from. */ struct hash *idHash, /* Hash of identifiers or NULL */ struct bedFilter *bf, /* Filter or NULL */ struct lm *lm, /* Local memory pool. */ struct bed **pBedList /* Output get's appended to this list */ ) /* Get the wikiTrack items passing filter on a single region. */ { struct bed *bed; int fieldCount = 6; char query[512]; int rowOffset; char **row; struct sqlConnection *wikiConn = wikiConnect(); struct sqlResult *sr = NULL; char where[512]; char *filter = filterClause(wikiDbName(), WIKI_TRACK_TABLE, region->chrom, NULL); if (filter) sqlSafefFrag(where, sizeof(where), "db='%s' AND %-s", database, filter); else sqlSafefFrag(where, sizeof(where), "db='%s'", database); sqlSafef(query, sizeof(query), "select * from %s", WIKI_TRACK_TABLE); sr = hRangeQuery(wikiConn, WIKI_TRACK_TABLE, region->chrom, region->start, region->end, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { bed = bedLoadN(row+rowOffset, fieldCount); if ((idHash == NULL || hashLookup(idHash, bed->name)) && (bf == NULL || bedFilterOne(bf, bed))) { struct bed *copy = lmCloneBed(bed, lm); slAddHead(pBedList, copy); } } sqlFreeResult(&sr); wikiDisconnect(&wikiConn); }
void doPasteIdentifiers(struct sqlConnection *conn) /* Respond to paste identifiers button. */ { struct sqlConnection *alternateConn = conn; char *actualDb = database; if (sameWord(curTable, WIKI_TRACK_TABLE)) { alternateConn = wikiConnect(); actualDb = wikiDbName(); } char *oldPasted = forCurTable() ? cartUsualString(cart, hgtaPastedIdentifiers, "") : ""; struct hTableInfo *hti = maybeGetHti(actualDb, curTable, conn); char *idField = getIdField(actualDb, curTrack, curTable, hti); htmlOpen("Paste In Identifiers for %s", curTableLabel()); if (idField == NULL) errAbort("Sorry, I can't tell which field of table %s to treat as the " "identifier field.", curTable); hPrintf("<FORM ACTION=\"%s\" METHOD=%s>\n", getScriptName(), cartUsualString(cart, "formMethod", "POST")); cartSaveSession(cart); hPrintf("Please paste in the identifiers you want to include.\n"); if (sqlDatabaseExists("hgTemp")) explainIdentifiers(actualDb, alternateConn, idField); else warn("No hgTemp database found for temporary tables.<br>Please src/product/README.mysql.setup for more information."); hPrintf("<BR>\n"); cgiMakeTextArea(hgtaPastedIdentifiers, oldPasted, 10, 70); hPrintf("<BR>\n"); cgiMakeButton(hgtaDoPastedIdentifiers, "submit"); hPrintf(" "); cgiMakeButton(hgtaDoClearPasteIdentifierText, "clear"); hPrintf(" "); cgiMakeButton(hgtaDoMainPage, "cancel"); hPrintf("</FORM>"); cgiDown(0.9); htmlClose(); if (sameWord(curTable, WIKI_TRACK_TABLE)) wikiDisconnect(&alternateConn); }
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 wikiTrackLoadItems(struct track *tg) /* Load the items from the wikiTrack table */ { struct bed *bed; struct sqlConnection *wikiConn = wikiConnect(); struct sqlResult *sr; char **row; int rowOffset; char where[256]; struct linkedFeatures *lfList = NULL, *lf; int scoreMin = 0; int scoreMax = 99999; safef(where, ArraySize(where), "db='%s'", database); sr = hRangeQuery(wikiConn, tg->table, chromName, winStart, winEnd, where, &rowOffset); while ((row = sqlNextRow(sr)) != NULL) { struct wikiTrack *item = wikiTrackLoad(row); AllocVar(bed); bed->chrom = cloneString(item->chrom); bed->chromStart = item->chromStart; bed->chromEnd = item->chromEnd; bed->name = cloneString(item->name); bed->score = item->score; safecpy(bed->strand, sizeof(bed->strand), item->strand); bed->thickStart = item->chromStart; bed->thickEnd = item->chromEnd; bed->itemRgb = hexToDecimal(item->color); bed8To12(bed); lf = lfFromBedExtra(bed, scoreMin, scoreMax); lf->extra = (void *)USE_ITEM_RGB; /* signal for coloring */ lf->filterColor=bed->itemRgb; /* overload itemAttr fields to be able to pass id to hgc click box */ struct itemAttr *id; AllocVar(id); id->chromStart = item->id; lf->itemAttr = id; slAddHead(&lfList, lf); wikiTrackFree(&item); } sqlFreeResult(&sr); wikiDisconnect(&wikiConn); slSort(&lfList, linkedFeaturesCmp); /* read-only option 2012-06-25 */ if ((! wikiTrackReadOnly()) && wikiTrackEnabled(database, NULL)) { // add special item to allow creation of new entries AllocVar(bed); bed->chrom = chromName; bed->chromStart = winStart; bed->chromEnd = winEnd; bed->name = cloneString("Make new entry"); bed->score = 100; bed->strand[0] = ' '; /* no barbs when strand is unknown */ bed->thickStart = winStart; bed->thickEnd = winEnd; bed->itemRgb = 0xcc0000; bed8To12(bed); lf = lfFromBedExtra(bed, scoreMin, scoreMax); lf->extra = (void *)USE_ITEM_RGB; /* signal for coloring */ lf->filterColor=bed->itemRgb; slAddHead(&lfList, lf); } tg->items = lfList; } /* static void wikiTrackLoadItems(struct track *tg) */