void verifyTerms(struct mdbObj *mdbObjs, struct slName *terms) { for(; mdbObjs; mdbObjs=mdbObjs->next) { struct slName *t; for(t=terms; t; t = t->next) { struct mdbVar *mdbVar = hashFindVal(mdbObjs->varHash, t->name); if (mdbVar == NULL) errAbort("obj %s doesn't have var %s\n", mdbObjs->obj, t->name); } } }
struct tracker *trackerForIp(char *ip) /* Find tracker for given IP address. Make it up if it * doesn't already exist. */ { struct tracker *tracker = hashFindVal(trackerHash, ip); if (tracker == NULL) { lmAllocVar(trackerHash->lm, tracker); hashAddSaveName(trackerHash, ip, tracker, &tracker->name); tracker->lastAccess = now; tracker->curDelay = -penalty; slAddHead(&trackerList, tracker); } return tracker; }
struct twoBitFile *twoBitOpenCached(char *path) /* Return open two bit file associated with path. */ { static struct hash *hash = NULL; struct twoBitFile *tbf; if (hash == NULL) hash = newHash(8); tbf = hashFindVal(hash, path); if (tbf == NULL) { tbf = twoBitOpen(path); hashAdd(hash, path, tbf); } return tbf; }
void assocGroupAdd(struct assocGroup *ag, char *key, char *val) /* Add key/val pair to assocGroup. */ { struct assocList *al = hashFindVal(ag->listHash, key); struct slRef *ref; if (al == NULL) { lmAllocVar(ag->lm, al); hashAdd(ag->listHash, key, al); } val = hashStoreName(ag->valStringHash, val); lmAllocVar(ag->lm, ref); ref->val = val; slAddHead(&al->list, ref); }
int termCmp(const void *va, const void *vb) /* Compare controlled vocab based on term value */ { const struct hash *a = *((struct hash **)va); const struct hash *b = *((struct hash **)vb); char *typeA = hashMustFindVal((struct hash *)a, CV_TYPE); char *typeB = hashMustFindVal((struct hash *)b, CV_TYPE); int ret = strcasecmp(typeA, typeB); if (ret != 0) return ret; char *targA = hashFindVal((struct hash *)a, CV_TARGET); char *targB = hashFindVal((struct hash *)b, CV_TARGET); if (targA != NULL && targB != NULL) { ret = strcasecmp(targA, targB); if (ret != 0) return ret; } char *termA = hashMustFindVal((struct hash *)a, CV_TERM); char *termB = hashMustFindVal((struct hash *)b, CV_TERM); return (strcasecmp(termA, termB)); }
static int gvfHierCmp(const void *va, const void *vb) /* Sort GVF so that children follow their parents, and children of the same parent * are sorted by var_type -- otherwise things are sorted by size,chromStart,name. */ { const struct bed8Attrs *a = *((struct bed8Attrs **)va); const struct bed8Attrs *b = *((struct bed8Attrs **)vb); char *aParentName = getAttributeVal(a, "Parent"); char *bParentName = getAttributeVal(b, "Parent"); if (bParentName != NULL && sameString(bParentName, a->name)) return -1; else if (aParentName != NULL && sameString(aParentName, b->name)) return 1; else if (aParentName != NULL && bParentName != NULL && sameString(aParentName, bParentName) && getAttributeVal(a, "var_type") != NULL && getAttributeVal(b, "var_type") != NULL) return strcmp(getAttributeVal(a, "var_type"), getAttributeVal(b, "var_type")); else { const struct bed8Attrs *bedCmpA = a, *bedCmpB = b; if (aParentName != NULL) bedCmpA = hashFindVal(nameHash, aParentName); if (bParentName != NULL) bedCmpB = hashFindVal(nameHash, bParentName); int diff = 0; if (bedCmpA != NULL && bedCmpB != NULL) { // no need to compare chrom here diff = ((bedCmpB->chromEnd - bedCmpB->chromStart) - (bedCmpA->chromEnd - bedCmpA->chromStart)); if (diff == 0) diff = bedCmpA->chromStart - bedCmpB->chromStart; } if (diff == 0) diff = strcmp(aParentName, bParentName); return diff; } }
struct dnaSeq *readCachedNib(struct hash *nibHash, char *nibDir, char *chrom, int start, int size) /* Return sequence using cache of nibs. */ { struct nibInfo *ni = hashFindVal(nibHash, chrom); if (ni == NULL) { char fileName[512]; sprintf(fileName, "%s/%s.nib", nibDir, chrom); AllocVar(ni); ni->fileName = cloneString(fileName); nibOpenVerify(fileName, &ni->f, &ni->size); } return nibLdPart(ni->fileName, ni->f, ni->size, start, size); }
static boolean inHapRegion(struct hapRegions *hr, char *chrom, int start, int end) /* determine if chrom range is in a haplotype region of a reference chromosome */ { struct refChrom *rc = hashFindVal(hr->refMap, chrom); if (rc != NULL) { struct hapChrom *hc; for (hc = rc->hapChroms; hc != NULL; hc = hc->next) { if ((end > hc->refStart) && (start < hc->refEnd)) return TRUE; } } return FALSE; }
struct table *elsIntoTables(struct elStat *elList, struct hash *dtdHash) /* Create table and field data structures from element/attribute * data structures. */ { struct elStat *el; struct attStat *att; struct table *tableList = NULL, *table; struct field *field = NULL; for (el = elList; el != NULL; el = el->next) { struct dtdElement *dtdElement = hashFindVal(dtdHash, el->name); int attCount = 0; if (dtdElement == NULL) errAbort("Element %s is in .stats but not in .dtd file", el->name); table = tableNew(dtdElement->mixedCaseName, el, dtdElement); for (att = el->attList; att != NULL; att = att->next) { char *name = att->name; char *mixedName = NULL; if (sameString(name, "<text>")) name = mixedName = textField; else { struct dtdAttribute *dtdAtt = findDtdAttribute(dtdElement, name); if (dtdAtt == NULL) errAbort("Element %s attribute %s is in .stats but not in .dtd file", el->name, name); mixedName = dtdAtt->mixedCaseName; } field = addFieldToTable(table, name, mixedName, att, FALSE, TRUE, attIsString(att), textField); attCount += 1; } /* If the table is real simple we'll just promote it */ if (attCount == 1 && sameString(field->name, textField) && (field->attStat->maxLen < maxPromoteSize || !field->isString)) { table->promoted = TRUE; table->primaryKey = field; } else makePrimaryKey(table); slAddHead(&tableList, table); } slReverse(&tableList); return tableList; }
struct axt *netFillToAxt(struct cnFill *fill, struct dnaSeq *tChrom , int tSize, struct hash *qChromHash, char *nibDir, struct chain *chain, boolean swap) /* Convert subset of chain as defined by fill to axt. swap query and target if swap is true*/ { struct dnaSeq *qSeq; boolean isRev = (chain->qStrand == '-'); struct chain *subChain, *chainToFree; int qOffset; struct axt *axtList = NULL , *axt; struct nibInfo *nib = hashFindVal(qChromHash, fill->qName); /* Get query sequence fragment. */ { if (nib == NULL) { char path[512]; AllocVar(nib); safef(path, sizeof(path), "%s/%s.nib", nibDir, fill->qName); nib->fileName = cloneString(path); nibOpenVerify(path, &nib->f, &nib->size); hashAdd(qChromHash, fill->qName, nib); } qSeq = nibLoadPartMasked(NIB_MASK_MIXED, nib->fileName, fill->qStart, fill->qSize); if (isRev) { reverseComplement(qSeq->dna, qSeq->size); qOffset = nib->size - (fill->qStart + fill->qSize); } else qOffset = fill->qStart; } chainSubsetOnT(chain, fill->tStart, fill->tStart + fill->tSize, &subChain, &chainToFree); if (subChain != NULL) { axtList = chainToAxt(subChain, qSeq, qOffset, tChrom, fill->tStart, 100, BIGNUM); if (swap) { for (axt = axtList ; axt != NULL ; axt = axt->next) axtSwap(axt, tSize, nib->size); } } chainFree(&chainToFree); freeDnaSeq(&qSeq); return axtList; }
void oneEnsFile(char *ensFile, struct hash *uniq, struct hash *pToT, FILE *f) /* Process one ensemble peptide prediction file into tab delimited * output f, using uniq hash to make sure no dupes. */ { struct lineFile *lf = lineFileOpen(ensFile, TRUE); char *line; int lineSize; boolean firstTime = TRUE; char *translation; /* Do cursory sanity check. */ if (!lineFileNext(lf, &line, &lineSize)) errAbort("%s is empty", ensFile); if (line[0] != '>') errAbort("%s is badly formatted, doesn't begin with '>'", ensFile); lineFileReuse(lf); while (lineFileNext(lf, &line, &lineSize)) { if (line[0] == '>') { char *upperCase; char *transcript; /* End last line. */ if (firstTime) firstTime = FALSE; else fputc('\n', f); translation = findEnsTrans(lf, line); if (hashLookupUpperCase(uniq, translation) != NULL) errAbort("Duplicate (case insensitive) '%s' line %d of %s", translation, lf->lineIx, lf->fileName); upperCase = cloneString(translation); touppers(upperCase); hashAdd(uniq, upperCase, NULL); freeMem(upperCase); transcript = hashFindVal(pToT, translation); if (transcript == NULL) errAbort("Can't find transcript for %s", translation); fprintf(f, "%s\t", transcript); } else { mustWrite(f, line, lineSize-1); } } fputc('\n', f); lineFileClose(&lf); }
void addSeqInfo(char *seqInfoName, struct hash *cloneHash) /* Add in information from sequence.info file. */ /* TSF - stage info now being derived from here - 4/7/2003 */ { struct lineFile *lf = lineFileOpen(seqInfoName, TRUE); char *line, *words[16]; int lineSize, wordCount; struct clonePos *clone; struct gsSeqInfo gs; int warnsLeft = maxWarn; /* Only show first maxWarn warnings about missing clones. */ static char stages[] = "PPDF"; printf("Processing %s\n", seqInfoName); while (lineFileNext(lf, &line, &lineSize)) { if (line[0] == '#') continue; wordCount = chopLine(line, words); if (wordCount == 0) continue; if (wordCount < 8) errAbort("Expecting 8 words line %d of %s", lf->lineIx, lf->fileName); gsSeqInfoStaticLoad(words, &gs); /* TSF - Phase 0 clones now included in contig_overlaps.agp 4/23/2003 */ /*if (gs.phase != 0) {*/ chopSuffix(gs.acc); if ((clone = hashFindVal(cloneHash, gs.acc)) == NULL) { if (warnsLeft > 0) { --warnsLeft; warn("%s is in %s but not in ooDir/*/*.gl", gs.acc, seqInfoName); } else if (warnsLeft == 0) { --warnsLeft; warn("(Truncating additional warnings)"); } continue; } clone->seqSize = gs.size; clone->phase = gs.phase; clone->stage[0] = stages[atoi(words[3])]; /* } */ } lineFileClose(&lf); }
void chainStats(char *chains) { int lastChainId = -1; struct lineFile *chainsLf = lineFileOpen(chains, TRUE); struct cseqPair *cspList = NULL, *csp; struct dyString *dy = newDyString(512); struct hash *chainHash = newHash(0); /* Hash keyed by qSeq<strand>tSeq */ struct chain *chain; struct cBlock *block; int count; count = 0; while ((chain = chainRead(chainsLf)) != NULL) { if (chain->id > lastChainId) lastChainId = chain->id; dyStringClear(dy); dyStringPrintf(dy, "%s%c%s", chain->qName, chain->qStrand, chain->tName); csp = hashFindVal(chainHash, dy->string); if (csp == NULL) { AllocVar(csp); slAddHead(&cspList, csp); hashAddSaveName(chainHash, dy->string, csp, &csp->name); csp->qName = cloneString(chain->qName); csp->tName = cloneString(chain->tName); csp->qStrand = chain->qStrand; } slAddHead(&csp->chain, chain); count++; } lineFileClose(&chainsLf); printf("read in %d chains\n",count); for(csp = cspList; csp; csp = csp->next) { slSort(&csp->chain, chainCmpTarget); gapChains(csp->chain); for(chain = csp->chain ; chain ; chain = chain->next) { for(block = chain->blockList; block; block = block->next) { } } } dyStringFree(&dy); }
void processSnps(char *chromName) /* read through chrN_snpTmp tables */ /* lookup into snpDataHash */ /* write to output file */ { char query[512]; struct sqlConnection *conn = hAllocConn(); struct sqlResult *sr; char **row; char tableName[64]; char fileName[64]; FILE *f; struct snpData *sel = NULL; safef(tableName, ArraySize(tableName), "%s_snpTmp", chromName); safef(fileName, ArraySize(fileName), "%s_snpTmp.tab", chromName); f = mustOpen(fileName, "w"); safef(query, sizeof(query), "select snp_id, chromStart, chromEnd, loc_type, class, orientation, fxn_class, " "allele, refUCSC, refUCSCReverseComp, observed, weight from %s ", tableName); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { sel = hashFindVal(snpDataHash, row[0]); if (sel == NULL) { fprintf(f, "%s\t%s\t%s\t%s\t", row[0], row[1], row[2], row[3]); fprintf(f, "%s\t%s\t%s\t", row[4], row[5], row[6]); fprintf(f, "0\t0.0\t0.0\t"); fprintf(f, "%s\t%s\t%s\t%s\t%s\n", row[7], row[8], row[9], row[10], row[11]); fprintf(errorFileHandle, "no match for snp_id %s\n", row[0]); continue; } /* check here for avHet < 0 */ /* check here for class = "single" and isBiallelic(observed) and avHet <= .5 */ /* check here for class = "single" and isTriallelic(observed) and avHet <= .3333 */ /* check here for class = "single" and isQuadallelic(observed) and avHet <= .25 */ fprintf(f, "%s\t%s\t%s\t%s\t", row[0], row[1], row[2], row[3]); fprintf(f, "%s\t%s\t%s\t", row[4], row[5], row[6]); fprintf(f, "%d\t%s\t%s\t", sel->validation_status, sel->avHet, sel->avHetSE); fprintf(f, "%s\t%s\t%s\t%s\t%s\n", row[7], row[8], row[9], row[10], row[11]); } sqlFreeResult(&sr); hFreeConn(&conn); carefulClose(&f); }
struct hashEl *wildHashLookup(struct hash *hash, char *name) /* If wildcards are in hash, then look up var in "wildCardHash" bin. */ { struct slPair *wild = hashFindVal(hash, WILD_CARD_HASH_BIN); if (wild == NULL) // Hasn't been made yet. wild = wildHashMakeList(hash); if (wild == NULL || (slCount(wild) == 1 && sameString(wild->name,WILD_CARD_HASH_EMPTY))) return NULL; // Empty list means hash contains no names with wildcards for ( ;wild != NULL; wild=wild->next) if (wildMatch(wild->name,name)) return wild->val; return NULL; }
int findLastIntronPos(struct hash *bedHash, char *name) /* Find last intron position in RNA coordinates if we have * a bed for this mRNA. Otherwise (or if it's single exon) * return 0. */ { struct bed *bed = hashFindVal(bedHash, name); if (bed == NULL) return 0; if (bed->blockCount < 2) return 0; int rnaSize = bedTotalBlockSize(bed); if (bed->strand[0] == '+') return rnaSize - bed->blockSizes[bed->blockCount-1]; else return rnaSize - bed->blockSizes[0]; }
static char *mdbLookupField(struct mdbObj *mdb, char *field) /* Lookup a field in a mdbObj. */ { if (sameString(field, "obj")) { return mdb->obj; } else { struct mdbVar *var = hashFindVal(mdb->varHash, field); if (var == NULL) return NULL; else return var->val; } }
static struct slRef *simpleSearchForTracksstruct(struct trix *trix,char **descWords,int descWordCount) // Performs the simple search and returns the found tracks. { struct slRef *tracks = NULL; struct trixSearchResult *tsList; for(tsList = trixSearch(trix, descWordCount, descWords, TRUE); tsList != NULL; tsList = tsList->next) { struct track *track = (struct track *) hashFindVal(trackHash, tsList->itemId); if (track != NULL) // It is expected that this is NULL (e.g. when the trix references trackDb tracks which have no tables) { refAdd(&tracks, track); } } return tracks; }
double weightOfEvidence(struct txGraph *txg, struct txEvidence *evList, struct hash *weightHash) /* Sum up weight of all evidence and return. */ { struct txEvidence *ev; double total = 0; for (ev = evList; ev != NULL; ev = ev->next) { struct txSource *source = &txg->sources[ev->sourceId]; struct weight *weight = hashFindVal(weightHash, source->type); if (weight == NULL) errAbort("No weight of type %s\n", source->type); else total += weight->value; } return total; }
struct gbIgnoreAcc* gbIgnoreGet(struct gbIgnore *ignore, char *acc, time_t modDate) /* Get he ignore entry for an accession and modedate, or NULL */ { if (ignore->accHash != NULL) { struct gbIgnoreAcc *igAcc = hashFindVal(ignore->accHash, acc); while (igAcc != NULL) { if (igAcc->modDate == modDate) return igAcc; igAcc = igAcc->next; } } return NULL; }
void transferExceptions(char *inName, char *inSource, struct hash *pepToRefHash, char *outName, FILE *f) /* Write out exceptions attatched to inName to file, this time * attached to outName. */ { if (sameString(inSource, "ccds") || startsWith("RefPep", inSource)) { char *refName = hashFindVal(pepToRefHash, inName); if (refName != NULL) inName = refName; } if (hashLookup(selenocysteineHash, inName)) fprintf(f, "%s\tselenocysteine\tyes\n", outName); if (hashLookup(altStartHash, inName)) fprintf(f, "%s\texception\talternative_start_codon\n", outName); }
struct dnaSeq *loadSomeSeq(struct hash *otherHash, char *chrom, int start, int end) /* Load sequence from chromosome file referenced in chromTable. */ { struct dnaSeq *seq = NULL; struct otherSeq *os = hashFindVal(otherHash, chrom); if (os != NULL) { seq = nibLdPart(os->nibFile, os->f, os->chromSize, start, end - start); } else { warn("Sequence %s isn't a chromsome", chrom); } return seq; }
void readMarkers(struct lineFile *mkf) /* Read in Sanger sts name, UniSTS ID and aliases */ /* All Sanger names in this file are found in the Clone marker file */ { struct bac *b = NULL; struct alias *a = NULL; char *words[6], *sanger[NUMSANGER], *stsIdandAliases[NUMALIASES], *extName = NULL; char *firstAlias = NULL, **aliases = NULL, *pr1 = NULL, *pr2 = NULL; int sangerCount = 0, nameCount = 0, i, j, k; char sep = '|'; boolean isId = TRUE; /* Read in all rows */ while (lineFileChopCharNext(mkf, sep, words, 6)) { sangerCount = chopByChar(words[1], ';', sanger, ArraySize(sanger)); nameCount = chopByChar(words[2], ';', stsIdandAliases, ArraySize(stsIdandAliases)); pr1 = cloneString(words[3]); pr2 = cloneString(words[4]); /* process each sanger name found */ for (i = 0; i < sangerCount; i++) { /* use sanger name to find alias struct in hash */ if ((a = hashFindVal(aliasHash, sanger[i])) != NULL) { /* if string is numeric, then it is an integer ID so do not add to array */ k = 0; for (j = 0; j < nameCount; j++) { isId = stringIsAnInteger(stsIdandAliases[j]); if (!isId) { a->aliases[k] = cloneString(stsIdandAliases[j]); k++; } } /* store primer sequences */ a->primer1 = cloneString(pr1); a->primer2 = cloneString(pr2); } else fprintf(stderr, "Can not find sanger name, %s, in aliasHash\n", sanger[i]); } } }
static void doOneCommand(struct cartJson *cj, char *command, struct jsonElement *paramObject) /* Dispatch command by name, checking for required parameters. */ { CartJsonHandler *handler = hashFindVal(cj->handlerHash, command); if (handler) { struct hash *paramHash = jsonObjectVal(paramObject, command); handler(cj, paramHash); } else { jsonWriteStringf(cj->jw, "error", "cartJson: unrecognized command '%s'\"", command); return; } }
struct genoLay *ggLayout(struct sqlConnection *conn, int graphRows, int graphCols) /* Figure out how to lay out image. */ { int i,j; struct genoLayChrom *chromList; int oneRowHeight; int minLeftLabelWidth = 0, minRightLabelWidth = 0; /* Figure out basic dimensions of image. */ trackLayoutInit(&tl, cart); tl.picWidth = cartUsualInt(cart, hggImageWidth, hgDefaultPixWidth); /* Refine all graphs actually used, and calculate label * widths if need be. */ for (i=0; i<graphRows; ++i) { for (j=0; j<graphCols; ++j) { char *source = graphSourceAt(i,j); if (source != NULL) { struct genoGraph *gg = hashFindVal(ggHash, source); if (gg != NULL) { ggRefineUsed(gg); if (withLabels) { int labelWidth; labelWidth = ggLabelWidth(gg, tl.font); if (j == 0 && labelWidth > minLeftLabelWidth) minLeftLabelWidth = labelWidth; if (j == 1 && labelWidth > minRightLabelWidth) minRightLabelWidth = labelWidth; } } } } } /* Get list of chromosomes and lay them out. */ chromList = genoLayDbChroms(conn, FALSE); oneRowHeight = graphHeight()+betweenRowPad; return genoLayNew(chromList, tl.font, tl.picWidth, graphRows*oneRowHeight, minLeftLabelWidth, minRightLabelWidth, chromLayout()); }
int hubCheckTrackSetting(struct trackHub *hub, struct trackDb *tdb, char *setting, struct trackHubCheckOptions *options, struct dyString *errors) /* Check trackDb setting to spec (by version and level). Returns non-zero if error, msg in errors */ { int retVal = 0; verbose(4, " Check setting '%s'\n", setting); /* skip internally added/used settings */ if (sameString(setting, "polished") || sameString(setting, "group")) return 0; /* check setting is in extra file of supported settings */ if (options->extra && hashLookup(options->extra, setting)) return 0; /* check setting is supported in this version */ struct trackHubSettingSpec *hubSetting = hashFindVal(options->settings, setting); if (hubSetting == NULL) { dyStringPrintf(errors, "Setting '%s' is unknown/unsupported", setting); char *suggest = suggestSetting(setting, options); if (suggest != NULL) dyStringPrintf(errors, " (did you mean '%s' ?)", suggest); dyStringPrintf(errors, "\n"); retVal = 1; } else if (sameString(hubSetting->level, "deprecated")) { dyStringPrintf(errors, "Setting '%s' is deprecated\n", setting); retVal = 1; } else { /* check level */ struct trackHubSettingSpec *checkLevel = NULL; AllocVar(checkLevel); checkLevel->level = options->level; if (trackHubSettingLevel(hubSetting) < trackHubSettingLevel(checkLevel)) { dyStringPrintf(errors, "Setting '%s' is level '%s'\n", setting, hubSetting->level); retVal = 1; } freez(&checkLevel); } return retVal; }
void outputAlignmentForStan(struct sqlConnection *conn, struct stanMad *sm, struct hash *iHash, FILE *out) { struct psl *pslList, *bestPsl = NULL; char buff[1024]; int i; struct imageClone *ic = NULL; sprintf(buff, "%d", sm->clid); printf("Looking for %s\n", buff); ic = hashFindVal(iHash, buff); if(ic != NULL) { /* first try looking for the image clones themselves... */ for(i=0; i<ic->numGenbank; i++) { char query[1024]; sqlSafef(query, sizeof query, "select * from all_est where qName='%s'", ic->genbankIds[i]); pslList = pslLoadByQuery(conn, buff); if(pslList != NULL) { slSort(&pslList, pslCmpScore); if(bestPsl == NULL || (pslScore(pslList) > pslScore(bestPsl))) pslFree(&bestPsl); bestPsl = copyPsl(pslList); } pslFreeList(&pslList); } if(bestPsl != NULL) { freez(&bestPsl->qName); sprintf(buff, "%d", sm->clid); bestPsl->qName = cloneString(buff); pslTabOut(bestPsl,out); } else { fprintf(out, "%d\talignment unknown\n", sm->clid); } } else { fprintf(out, "%d\tunknown\n", sm->clid); } }
static struct pslRef *getSetQueryPsls(struct pslSets *ps, int iSet, char *qName) /* get the pslRefs objects for a query from the given set */ { struct pslRef *psls = NULL; struct pslQuery *pq = hashFindVal(ps->sets[iSet]->queryHash, qName); if (pq != NULL) { struct psl *psl; for (psl = pq->psls; psl != NULL; psl = psl->next) { struct pslRef *pr = pslRefAlloc(ps); pr->psl = psl; slAddHead(&psls, pr); } } return psls; }
struct hash *getChromLimits(char *database) /* Get hash full of chromosome limits. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char **row; struct hash *hash = newHash(8); struct chromLimit *clList = NULL, *cl; double sum = 0; char *limitFile = optionVal("chromLimit", NULL); /* Read in chromosome info from database. */ sr = sqlGetResult(conn, "NOSQLINJ select chrom,size from chromInfo"); while ((row = sqlNextRow(sr)) != NULL) { AllocVar(cl); hashAddSaveName(hash, row[0], cl, &cl->name); cl->size = atoi(row[1]); sum += cl->size; slAddHead(&clList, cl); } sqlFreeResult(&sr); hFreeConn(&conn); /* Calculate max picks. */ for (cl = clList; cl != NULL; cl = cl->next) { cl->maxPicks = round(60.0*cl->size/sum); } /* Override max picks based on chromLimits file if any. */ if (limitFile != NULL) { struct lineFile *lf = lineFileOpen(limitFile, TRUE); char *row[2]; while (lineFileRow(lf, row)) { cl = hashFindVal(hash, row[0]); cl->maxPicks = lineFileNeedNum(lf, row, 1); } lineFileClose(&lf); } return hash; }
void cdwChangeAccess(char *chmodString, char *rqlWhere) /* cdwChangeAccess - Change access to files.. */ { char cWhere, cDir, cAccess; parseChmodString(chmodString, &cWhere, &cDir, &cAccess); /* Get list of all stanzas matching query */ struct sqlConnection *conn = cdwConnectReadWrite(); struct tagStorm *tags = cdwTagStorm(conn); struct dyString *rqlQuery = dyStringNew(0); dyStringPrintf(rqlQuery, "select accession from cdwFileTags where accession and %s", rqlWhere); struct slRef *ref, *matchRefList = tagStanzasMatchingQuery(tags, rqlQuery->string); /* Make one pass through mostly for early error reporting and building up * hash of cdwValidFiles keyed by accession */ struct hash *validHash = hashNew(0); for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = cdwValidFileFromLicensePlate(conn, acc); if (vf == NULL) errAbort("%s not found in cdwValidFile", acc); hashAdd(validHash, acc, vf); } } /* Second pass through matching list we call routine that actually adds * the group/file relationship. */ for (ref = matchRefList; ref != NULL; ref = ref->next) { struct tagStanza *stanza = ref->val; char *acc = tagFindVal(stanza, "accession"); if (acc != NULL) { struct cdwValidFile *vf = hashFindVal(validHash, acc); if (vf != NULL) { changeAccess(conn, vf->fileId, cWhere, cDir, cAccess); } } } }