static struct slName *getGenomeDbs(struct gbConf *conf) /* get list of genome databases from variable names */ { // build hash of dbs struct hash *dbSet = hashNew(20); struct hashCookie cookie = hashFirst(conf->hash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) { char *prefix = parsePrefix(hel->name); if (isGenomeDb(prefix)) hashStore(dbSet, prefix); } // convert to a list of dbs struct slName *dbs = NULL; cookie = hashFirst(dbSet); while ((hel = hashNext(&cookie)) != NULL) slSafeAddHead(&dbs, slNameNew(hel->name)); #ifdef DUMP_HASH_STATS hashPrintStats(dbSet, "gbConfDbSet", stderr); #endif hashFree(&dbSet); slSort(&dbs, slNameCmp); return dbs; }
static void fillInFastaOffsets(struct brokenRefPepTbl *brpTbl, struct sqlConnection *conn, struct extFileTbl* extFileTbl) /* get offsets of proteins in fasta files */ { struct hashCookie cookie = hashFirst(brpTbl->protFaHash); struct hashEl *hel; /* fill in */ while ((hel = hashNext(&cookie)) != NULL) getFastaOffsets(brpTbl, conn, extFileTbl, hel->name); /* check if any missing */ cookie = hashFirst(brpTbl->protAccHash); while ((hel = hashNext(&cookie)) != NULL) { struct brokenRefPep *brp = hel->val; if (strlen(brp->mrnaAcc) && (brp->newFaOff < 0)) { /* in one case, this was a pseudoGene mistakenly left in as an * mRNA, so make it a warning */ fprintf(stderr, "Warning: %s: refPep %s (for %s) not found in %s\n", sqlGetDatabase(conn), brp->protAcc, brp->mrnaAcc, brp->newFaPath); } } }
/* Dump the file upload details. Don't actually do anything with the uploaded file. */ static void uploadTest(Webs *wp, char *path, char *query) { WebsKey *s; WebsUpload *up; char *upfile; websSetStatus(wp, 200); websWriteHeaders(wp, -1, 0); websWriteHeader(wp, "Content-Type", "text/plain"); websWriteEndHeaders(wp); if (scaselessmatch(wp->method, "POST")) { for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) { up = s->content.value.symbol; websWrite(wp, "FILE: %s\r\n", s->name.value.string); websWrite(wp, "FILENAME=%s\r\n", up->filename); websWrite(wp, "CLIENT=%s\r\n", up->clientFilename); websWrite(wp, "TYPE=%s\r\n", up->contentType); websWrite(wp, "SIZE=%d\r\n", up->size); upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename); rename(up->filename, upfile); wfree(upfile); } websWrite(wp, "\r\nVARS:\r\n"); for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) { websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string); } } websDone(wp); }
void getSnps(char *tableName) { char query[512]; struct sqlConnection *conn = hAllocConn(); struct sqlResult *sr; char **row; struct hashCookie cookie; struct hashEl *hel = NULL; sqlSafef(query, sizeof(query), "select chrom, chromStart, chromEnd, name, strand from %s", tableName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { hel = hashLookup(chromHash, row[0]); if (hel == NULL) verbose(1, "%s not found\n", row[0]); else fprintf(hel->val, "%s\t%s\t%s\t%s\t0\t%s\t%s\t%s\n", row[0], row[1], row[2], row[3], row[4], row[5], row[6]); } sqlFreeResult(&sr); cookie = hashFirst(chromHash); while ((hel = hashNext(&cookie))) fclose(hel->val); }
static void computeUserAbilities(WebsUser *user) { char *ability, *roles, *tok; assure(user); if ((user->abilities = hashCreate(-1)) == 0) { return; } roles = sclone(user->roles); for (ability = stok(roles, " \t,", &tok); ability; ability = stok(NULL, " \t,", &tok)) { computeAbilities(user->abilities, ability, 0); } #if BIT_DEBUG { WebsKey *key; trace(5, "User \"%s\" has abilities: ", user->name); for (key = hashFirst(user->abilities); key; key = hashNext(user->abilities, key)) { trace(5, "%s ", key->name.value.string); ability = key->name.value.string; } trace(5, "\n"); } #endif wfree(roles); }
void refPepList(char *db, FILE* outFh) /* list of sequences needing repair */ { struct sqlConnection *conn = sqlConnect(db); struct brokenRefPepTbl *brpTbl; struct hashCookie cookie; struct hashEl *hel; struct extFileTbl* extFileTbl = NULL; if (!checkForRefLink(conn)) { sqlDisconnect(&conn); return; } extFileTbl = extFileTblLoad(conn); brpTbl = brokenRefPepTblNew(conn, NULL); brokenRefPepGetSeqScan(conn, extFileTbl, brpTbl); brokenRefPepGetMrnas(conn, brpTbl); extFileTblFree(&extFileTbl); cookie = hashFirst(brpTbl->protAccHash); while ((hel = hashNext(&cookie)) != NULL) { struct brokenRefPep *brp = hel->val; fprintf(outFh, "%s\t%s\t%s\n", sqlGetDatabase(conn), brp->protAcc, (brp->mrnaAcc != NULL)? "repair" : "drop"); } gbVerbMsg(1, "%s: need to repair %d refseq protein gbExtFile entries", sqlGetDatabase(conn), brpTbl->numToRepair); gbVerbMsg(1, "%s: need to drop %d refseq protein gbExtFile entries", sqlGetDatabase(conn), brpTbl->numToDrop); }
static void writeTdbSimple(struct jsonWrite *jw, struct trackDb *tdb, struct hash *fieldHash) /* Write JSON for the non-parent/child fields of tdb */ { if (fieldOk("track", fieldHash)) jsonWriteString(jw, "track", tdb->track); if (fieldOk("table", fieldHash)) jsonWriteString(jw, "table", tdb->table); if (fieldOk("shortLabel", fieldHash)) jsonWriteString(jw, "shortLabel", tdb->shortLabel); if (fieldOk("longLabel", fieldHash)) jsonWriteString(jw, "longLabel", tdb->longLabel); if (fieldOk("type", fieldHash)) jsonWriteString(jw, "type", tdb->type); if (fieldOk("priority", fieldHash)) jsonWriteDouble(jw, "priority", tdb->priority); if (fieldOk("grp", fieldHash)) jsonWriteString(jw, "grp", tdb->grp); // NOTE: if you add a new field here, then also add it to nameIsTdbField above. if (tdb->settingsHash) { struct hashEl *hel; struct hashCookie cookie = hashFirst(tdb->settingsHash); while ((hel = hashNext(&cookie)) != NULL) { if (! nameIsTdbField(hel->name) && fieldOk(hel->name, fieldHash)) { //#*** TODO: move jsonStringEscape inside jsonWriteString char *encoded = jsonStringEscape((char *)hel->val); jsonWriteString(jw, hel->name, encoded); } } } }
void cartJsonExecute(struct cartJson *cj) /* Get commands from cgi, print Content-type, execute commands, print results as JSON. */ { cartJsonPushErrHandlers(); puts("Content-Type:text/javascript\n"); // Initialize response JSON object: jsonWriteObjectStart(cj->jw, NULL); // Always send back hgsid: jsonWriteString(cj->jw, cartSessionVarName(), cartSessionId(cj->cart)); char *commandJson = cgiOptionalString(CARTJSON_COMMAND); if (commandJson) { struct jsonElement *commandObj = jsonParse(commandJson); struct hash *commandHash = jsonObjectVal(commandObj, "commandObj"); // change* commands need to go first! Really we need an ordered map type here... // for now, just make a list and sort to put change commands at the front. struct slPair *commandList = NULL, *cmd; struct hashCookie cookie = hashFirst(commandHash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) slAddHead(&commandList, slPairNew(hel->name, hel->val)); slSort(&commandList, commandCmp); for (cmd = commandList; cmd != NULL; cmd = cmd->next) doOneCommand(cj, cmd->name, (struct jsonElement *)cmd->val); } cartJsonPrintWarnings(cj->jw); jsonWriteObjectEnd(cj->jw); puts(cj->jw->dy->string); cartJsonPopErrHandlers(); }
void checkMrnaPartition(struct gbSelect* select) /* Check an mRNA partition. For genbank, check all ESTs against * this mRNA partation. */ { struct hashCookie cookie; struct hashEl* hel; gbReleaseLoadProcessed(select); struct gbSelect* prevSelect = gbProcessedGetPrevRel(select); if (prevSelect != NULL) gbReleaseLoadProcessed(prevSelect); gbVerbEnter(2, "checking %s", gbSelectDesc(select)); cookie = hashFirst(select->release->entryTbl); while ((hel = hashNext(&cookie)) != NULL) checkOrgCat(hel->val, prevSelect); gbVerbLeave(2, "checking %s", gbSelectDesc(select)); if (select->release->srcDb == GB_GENBANK) checkEstPartitions(select->release); gbReleaseUnload(select->release); if (prevSelect != NULL) { gbReleaseUnload(prevSelect->release); freeMem(prevSelect); } }
void bitmapToMaskArray(struct hash *bitmapHash, struct hash *tbHash) /* Translate each bitmap in bitmapHash into an array of mask coordinates * in the corresponding twoBit in tbHash. Assume tbHash's mask array is * empty at the start -- we allocate it here. Free bitmap when done. */ { struct hashCookie cookie = hashFirst(tbHash); struct hashEl *hel = NULL; while ((hel = hashNext(&cookie)) != NULL) { char *seqName = hel->name; struct twoBit *tb = (struct twoBit *)(hel->val); struct hashEl *bHel = hashLookup(bitmapHash, seqName); Bits *bits; unsigned start=0, end=0; assert(tb != NULL); assert(tb->maskBlockCount == 0); if (bHel == NULL) errAbort("Missing bitmap for seq \"%s\"", seqName); bits = (Bits *)bHel->val; if (bits != NULL) { struct lm *lm = lmInit(0); struct unsignedRange *rangeList = NULL, *range = NULL; int i; for (;;) { start = bitFindSet(bits, end, tb->size); if (start >= tb->size) break; end = bitFindClear(bits, start, tb->size); if (end > start) { lmAllocVar(lm, range); range->start = start; range->size = (end - start); slAddHead(&rangeList, range); } } slReverse(&rangeList); tb->maskBlockCount = slCount(rangeList); if (tb->maskBlockCount > 0) { AllocArray(tb->maskStarts, tb->maskBlockCount); AllocArray(tb->maskSizes, tb->maskBlockCount); for (i = 0, range = rangeList; range != NULL; i++, range = range->next) { tb->maskStarts[i] = range->start; tb->maskSizes[i] = range->size; } } lmCleanup(&lm); bitFree(&bits); bHel->val = NULL; } } }
static int writeAuthFile(char *path) { FILE *fp; WebsKey *kp, *ap; WebsRole *role; WebsUser *user; WebsHash roles, users; char *tempFile; assert(path && *path); tempFile = websTempFile(NULL, "gp"); if ((fp = fopen(tempFile, "w" FILE_TEXT)) == 0) { error("Can't open %s", tempFile); return -1; } fprintf(fp, "#\n# %s - Authorization data\n#\n\n", basename(path)); roles = websGetRoles(); if (roles >= 0) { for (kp = hashFirst(roles); kp; kp = hashNext(roles, kp)) { role = kp->content.value.symbol; fprintf(fp, "role name=%s abilities=", kp->name.value.string); for (ap = hashFirst(role->abilities); ap; ap = hashNext(role->abilities, ap)) { fprintf(fp, "%s,", ap->name.value.string); } fputc('\n', fp); } fputc('\n', fp); } users = websGetUsers(); if (users >= 0) { for (kp = hashFirst(users); kp; kp = hashNext(users, kp)) { user = kp->content.value.symbol; fprintf(fp, "user name=%s password=%s roles=%s", user->name, user->password, user->roles); fputc('\n', fp); } } fclose(fp); unlink(path); if (rename(tempFile, path) < 0) { error("Can't create new %s", path); return -1; } return 0; }
static void dumpIgnoreTbl(struct hash* ignoreTbl) /* print ignoreTbl for debugging purposes */ { struct hashCookie cookie = hashFirst(ignoreTbl); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) verbose(3, "ignore: %s: %s\n", hel->name, (char*)hel->val); }
static char *findType(struct hash *cvHash,char **requested,int requestCount, char **queryBy, char **org,boolean silent) /* returns the type that was requested or else the type associated with the term requested */ { struct hashCookie hc = hashFirst(cvHash); struct hashEl *hEl; struct hash *ra; char *type = typeOpt; if (requested != NULL) // if no type, find it from requested terms. Will validate terms match type { // NOTE: Enter here even if there is a type, to confirm the type while ((hEl = hashNext(&hc)) != NULL) // FIXME: This should be using mdbCv APIs to get hashes. { // One per "request[]" ra = (struct hash *)hEl->val; if (sameWord(hashMustFindVal(ra, CV_TYPE),CV_TOT)) // TOT = typeOfTerm continue; char *val = hashFindVal(ra, *queryBy); if (val != NULL) { int ix = stringArrayIx(val,requested,requestCount); if (ix != -1) // found { char *thisType = hashMustFindVal(ra, CV_TYPE); char *thisOrg = hashFindVal(ra, ORGANISM); if (type == NULL) { if (thisOrg != NULL) { *org = strLower(cloneString(thisOrg)); } type = thisType; } else if (differentWord(type,thisType)) { if (sameWord(CV_TERM_CONTROL,type)) type = thisType; else if (differentWord(CV_TERM_CONTROL,thisType)) errAbort("Error: Requested %s of type '%s'. But '%s' has type '%s'\n", *queryBy,type,requested[ix],thisType); } } } } } if (type == NULL && sameWord(*queryBy,CV_TERM)) // Special case of term becoming target { char *queryByTarget = CV_TARGET; type = findType(cvHash,requested,requestCount,&queryByTarget,org,TRUE); // silent here if (type != NULL) *queryBy = queryByTarget; } if (type == NULL && !silent) // Still not type? abort errAbort("Error: Required %s=%s ['%s', '%s', '%s', '%s' or '%s'] argument not found\n", *queryBy,(requested != NULL) ? *requested : "?", CV_TYPE, CV_TERM, CV_TAG, CV_TARGET, CV_LABEL); return normalizeType(type); }
static void brokenRefPepGetMrnas(struct sqlConnection *conn, struct brokenRefPepTbl *brpTbl) /* load mrna information for broken refPeps */ { struct hashCookie cookie = hashFirst(brpTbl->protAccHash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) brokenRefPepGetPath(conn, brpTbl, (struct brokenRefPep*)hel->val); }
void* hashNextVal(struct hashCookie *cookie) /* Return the next value in the hash table, or NULL if no more. Do not modify * hash table while this is being used. */ { struct hashEl *hel = hashNext(cookie); if (hel == NULL) return NULL; else return hel->val; }
char *hashNextName(struct hashCookie *cookie) /* Return the next name in the hash table, or NULL if no more. Do not modify * hash table while this is being used. */ { struct hashEl *hel = hashNext(cookie); if (hel == NULL) return NULL; else return hel->name; }
static void findNewEntries(struct gbSelect* select, struct gbStatusTbl* statusTbl) /* Traverse the gbIndex file to find entries that were not in the gbStatus * table when loaded. These are new entries. */ { struct hashCookie cookie; struct hashEl* hel; cookie = hashFirst(select->release->entryTbl); while ((hel = hashNext(&cookie)) != NULL) checkNewEntry(select, statusTbl, (struct gbEntry*)hel->val); }
static void gotCcdsCheckInfo(struct hash *infoCcds) /* check source databases added to ccdsInof table */ { int errCnt = 0; struct hashCookie cookie = hashFirst(infoCcds); struct hashEl* hel; while ((hel = hashNext(&cookie)) != NULL) errCnt += gotCcdsCheckSrcDb(hel); if (errCnt > 0) errAbort("Error: not all CCDSs have both NCBI and Hinxton genes in ccdsInfo table"); }
/* free slRef objects in the compRangeMap */ static void destructCompRangeMap(struct malnSet *malnSet) { struct hashCookie cookie = hashFirst(malnSet->compRangeMap->hash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) { struct rbTree *rangeTree = hel->val; for (struct range *rng = rangeTreeList(rangeTree); rng != NULL; rng = rng->next) { slFreeList(&rng->val); } } genomeRangeTreeFree(&malnSet->compRangeMap); }
static void alignStatsOutputUnaligned(FILE *fh, struct hash* querySizesTbl) /* output stats on unaligned */ { struct hashCookie cookie = hashFirst(querySizesTbl); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) { struct querySizeCnt *qs = hel->val; if (qs->alnCnt == 0) fprintf(fh, alnStatsFmt, hel->name, qs->qSize, "", 0, 0, 0.0, 0.0, 0.0, 0.0); } }
static struct chromSize *getAllChroms(char *db) /* get list of all chroms */ { struct chromSize *chroms = NULL; struct hash *chrTbl = hChromSizeHash(db); struct hashCookie ck = hashFirst(chrTbl); struct hashEl *hel; while ((hel = hashNext(&ck)) != NULL) slSafeAddHead(&chroms, chromSizeNew(hel->name, ptToInt(hel->val))); hashFree(&chrTbl); return chroms; }
static void getRnaSeqs(struct sqlConnection *conn, struct hash *refSeqVerInfoTbl, char *outFile) /* get request RNA sequences from database */ { FILE *fh = mustOpen(outFile, "w"); struct hashCookie cookie = hashFirst(refSeqVerInfoTbl); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) { processRnaSeq(fh, conn, hel->val); } carefulClose(&fh); }
PUBLIC void websComputeAllUserAbilities() { WebsUser *user; WebsKey *sym; if (users) { for (sym = hashFirst(users); sym; sym = hashNext(users, sym)) { user = (WebsUser*) sym->content.value.symbol; computeUserAbilities(user); } } }
boolean mafMayFindAllComponents(struct mafAli *maf, struct hash *cHash) /* Find component of given source that starts matches any string in the cHash. Return NULL if not found. */ { struct hashCookie cookie = hashFirst(cHash); struct hashEl *el; while ((el = hashNext(&cookie)) != NULL) if (mafMayFindComponent(maf, el->name) == NULL) return FALSE; return TRUE; }
static struct mgcStatus *sortTable(struct mgcStatusTbl *mst) /* Get a list of the entries, sorted by imageId */ { struct hashCookie cookie = hashFirst(mst->imageIdHash); struct hashEl *hel; struct mgcStatus *statusList = NULL; while ((hel = hashNext(&cookie)) != NULL) slAddHead(&statusList, ((struct mgcStatus*)hel->val)); slSort(&statusList, imageIdCmp); return statusList; }
int hubCheckTrack(struct trackHub *hub, struct trackHubGenome *genome, struct trackDb *tdb, struct trackHubCheckOptions *options, struct dyString *errors) /* Check track settings and optionally, files */ { int retVal = 0; if (options->checkSettings && options->settings) { //verbose(3, "Found %d settings to check to spec\n", slCount(settings)); verbose(3, "Checking track: %s\n", tdb->shortLabel); verbose(3, "Found %d settings to check to spec\n", hashNumEntries(tdb->settingsHash)); struct hashEl *hel; struct hashCookie cookie = hashFirst(tdb->settingsHash); while ((hel = hashNext(&cookie)) != NULL) retVal |= hubCheckTrackSetting(hub, tdb, hel->name, options, errors); /* TODO: ? also need to check settings not in this list (other tdb fields) */ } if (options->printMeta) { struct slPair *metaPairs = trackDbMetaPairs(tdb); if (metaPairs != NULL) { printf("%s\n", trackHubSkipHubName(tdb->track)); struct slPair *pair; for(pair = metaPairs; pair; pair = pair->next) { printf("\t%s : %s\n", pair->name, (char *)pair->val); } printf("\n"); } slPairFreeValsAndList(&metaPairs); } if (!options->checkFiles) return retVal; struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { hubCheckBigDataUrl(hub, genome, tdb); } errCatchEnd(errCatch); if (errCatch->gotError) { retVal = 1; dyStringPrintf(errors, "%s", errCatch->message->string); } errCatchFree(&errCatch); return retVal; }
void bestProbeOverlap(struct sqlConnection *conn, char *probeTable, struct genePred *gpList, struct hash *gpToProbeHash) /* Create hash of most overlapping probe if any for each gene. Require * at least 100 base overlap. */ { /* Create a hash of binKeepers filled with probes. */ struct hash *keeperHash = keepersForChroms(conn); struct hashCookie it = hashFirst(keeperHash); struct hashEl *hel; int pslCount = 0; while ((hel = hashNext(&it)) != NULL) { char *chrom = hel->name; struct binKeeper *bk = hel->val; int rowOffset; struct sqlResult *sr = hChromQuery(conn, probeTable, chrom, NULL, &rowOffset); char **row; while ((row = sqlNextRow(sr)) != NULL) { struct psl *psl = pslLoad(row+rowOffset); binKeeperAdd(bk, psl->tStart, psl->tEnd, psl); ++pslCount; } sqlFreeResult(&sr); } verbose(2, "Loaded %d psls from %s\n", pslCount, probeTable); /* Loop through gene list, finding best probe if any for each gene. */ struct genePred *gp; for (gp = gpList; gp != NULL; gp = gp->next) { struct rbTree *rangeTree = genePredToRangeTree(gp, FALSE); struct psl *bestPsl = NULL; int bestOverlap = 99; /* MinOverlap - 1 */ struct binKeeper *bk = hashMustFindVal(keeperHash, gp->chrom); struct binElement *bin, *binList = binKeeperFind(bk, gp->txStart, gp->txEnd); for (bin = binList; bin != NULL; bin = bin->next) { struct psl *psl = bin->val; if (psl->strand[0] == gp->strand[0]) { int overlap = pslRangeTreeOverlap(psl, rangeTree); if (overlap > bestOverlap) { bestOverlap = overlap; bestPsl = psl; } } } if (bestPsl != NULL) hashAdd(gpToProbeHash, gp->name, bestPsl->qName); } }
void spMapperPrintNoMapInfo(struct spMapper *sm, char *outFile) /* Print missed id table. First column is id, second column is R if it wasn't * found in uniref, or K if it couldn't be associated with a known gene */ { FILE *fh = mustOpen(outFile, "w"); struct hashCookie cookie = hashFirst(sm->noMapTbl); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) fprintf(fh, "%s\t%c\n", hel->name, ptToInt(hel->val)); carefulClose(&fh); }
PUBLIC void websCloseAuth() { WebsKey *key, *next; wfree(secret); if (users >= 0) { for (key = hashFirst(users); key; key = next) { next = hashNext(users, key); freeUser(key->content.value.symbol); } hashFree(users); users = -1; } if (roles >= 0) { for (key = hashFirst(roles); key; key = next) { next = hashNext(roles, key); freeRole(key->content.value.symbol); } hashFree(roles); roles = -1; } }
static void outputQueryStats(struct hash *queryStatsTbl, char *statsFile) /* output statistics on queries */ { struct hashCookie cookie = hashFirst(queryStatsTbl); FILE *fh = mustOpen(statsFile, "w"); struct hashEl *hel; fputs(queryStatsHdr, fh); while ((hel = hashNext(&cookie)) != NULL) queryStatsOutput(fh, hel->val); carefulClose(&fh); }