struct gene *geneFromCluster(struct txCluster *cluster, struct hash *bedHash, struct hash *infoHash) /* Create a coding gene from coding cluster. */ { struct gene *gene = geneNew(); gene->chrom = cloneString(cluster->chrom); gene->start = cluster->chromStart; gene->end = cluster->chromEnd; gene->strand = cluster->strand[0]; gene->isCoding = TRUE; int i; double bestScore = -BIGNUM; for (i=0; i<cluster->txCount; ++i) { /* Find and add bed. */ struct bed *bed = hashMustFindVal(bedHash, cluster->txArray[i]); geneAddBed(gene, bed); /* Recalc min/max of gene since cluster has CDS, not transcription bounds. */ gene->start = min(gene->start, bed->chromStart); gene->end = max(gene->end, bed->chromEnd); /* Figure out nicest gene in cluster to use as example. */ struct txInfo *info = hashMustFindVal(infoHash, bed->name); double score = txInfoCodingScore(info, TRUE); if (score > bestScore) { bestScore = score; gene->niceTx = bed; } } return gene; }
void testDb(struct htmlPage *orgPage, char *org, char *db) /* Test on one database. */ { struct hash *genomeRa = hgReadRa(org, db, dataDir, "genome.ra", NULL); char *canonicalTable = hashMustFindVal(genomeRa, "canonicalTable"); char *accColumn = hashMustFindVal(genomeRa, "idColumn"); struct slName *geneList = sqlRandomSampleWithSeed(db, canonicalTable, "transcript", clRepeat, seed); struct htmlPage *dbPage; struct slName *ptr; verbose(1, "genelist:\n"); for (ptr = geneList; ptr != NULL; ptr = ptr->next) verbose(1, "%s\n", ptr->name); htmlPageSetVar(orgPage, NULL, "db", db); htmlPageSetVar(orgPage, NULL, searchVarName, ""); dbPage = quickSubmit(orgPage, NULL, org, db, NULL, NULL, "dbEmptyPage", "submit", "go"); quickErrReport(); if (dbPage != NULL) { testDbColumns(dbPage, org, db, geneList); testDbSorts(dbPage, org, db, accColumn, geneList); testDbFilters(dbPage, org, db, accColumn, geneList); } htmlPageFree(&dbPage); hashFree(&genomeRa); slNameFreeList(&geneList); }
void readGbAcc(struct lineFile *gaf) /* Read in and record all genbank accessions that have sequences */ { struct gb *gb; char *acc[1]; struct sts *s; while (lineFileNextRow(gaf, acc, 1)) { if (!hashLookup(gbAccHash, acc[0])) { AllocVar(gb); gb->next = NULL; gb->acc = cloneString(acc[0]); gb->s = NULL; gb->gbSeq = TRUE; hashAdd(gbAccHash, acc[0], gb); if (hashLookup(nameHash, acc[0])) { s = hashMustFindVal(nameHash, acc[0]); addElement(acc[0], &s->si->genbank, &s->si->gbCount); removeElement(acc[0], &s->si->otherNames, &s->si->nameCount); } } else { gb = hashMustFindVal(gbAccHash, acc[0]); gb->gbSeq = TRUE; } } }
static boolean raRecLoad(struct raInfoTbl *rit, unsigned srcDb, struct lineFile *raLf, unsigned cdnaExtId, unsigned pepExtId) /* load next ra record */ { char *acc, *protAccVer, protAcc[GB_ACC_BUFSZ]; int ver; struct hash *raRec = raNextRecord(raLf); if (raRec == NULL) return FALSE; acc = hashMustFindVal(raRec, "acc"); ver = sqlSigned((char*)hashMustFindVal(raRec, "ver")); raInfoAdd(rit, raRec, acc, ver, "siz", "fao", "fas", cdnaExtId); if ((srcDb == GB_REFSEQ) && ((protAccVer = hashFindVal(raRec, "prt")) != NULL)) { if (pepExtId == 0) errAbort("%s has protein %s, but no pep.fa file", acc, protAccVer); ver = gbSplitAccVer(protAccVer, protAcc); raInfoAdd(rit, raRec, protAcc, ver, "prs", "pfo", "pfs", pepExtId); } #ifdef DUMP_HASH_STATS hashPrintStats(raRec, "raRec", stderr); #endif hashFree(&raRec); return TRUE; }
void readPslFile(struct lineFile *pf) /* Process all records in a psl file of mRNA alignments */ { int lineSize; char *line; char *words[32]; int wordCount; struct psl *psl; struct clone *clone; struct pslAli *pa = NULL; struct cloneName *cloneName; while (lineFileNext(pf, &line, &lineSize)) { wordCount = chopTabs(line, words); if (wordCount != 21) errAbort("Bad line %d of %s\n", pf->lineIx, pf->fileName); psl = pslLoad(words); if (hashLookup(leftNames, psl->qName)) cloneName = hashMustFindVal(leftNames, psl->qName); else if (hashLookup(rightNames, psl->qName)) cloneName = hashMustFindVal(rightNames, psl->qName); else continue; clone = hashMustFindVal(clones, cloneName->name); if ((psl->tBaseInsert < TINSERT) && ((!NORANDOM) || (strlen(psl->tName) < 7))) { pa = createPslAli(psl); if (hashLookup(leftNames, psl->qName)) slAddHead(&(clone->end1), pa); else slAddHead(&(clone->end2), pa); } } }
matrix * WEKApopulatePredictionsMatrix(struct hash * config) { //quick hack to get proper labes from trianing data. TODO: add a labeling scheme to WEKAwrapper for output char * trainingDir = hashMustFindVal(config, "trainingDir"); char * modelDir = hashMustFindVal(config, "modelDir"); char filename[1024]; safef(filename, sizeof(filename), "%s/data.arff", trainingDir); matrix * labelTemplate = WEKAtoMetadataMatrix(filename); safef(filename, sizeof(filename), "%s/weka.training.results", modelDir); FILE * fp = fopen(filename, "r"); if(fp == NULL) errAbort("Couldn't open %s for reading.", filename); //read the number of data lines by advancing the cursor to where data starts, then counting lines char * line; while( (line = readLine(fp)) && line != NULL) { if(strstr(line, "inst#") != NULL) break; } int samples = 0; while( (line = readLine(fp)) && line != NULL && !sameString(line, "")) samples++; if(samples == 0) return NULL;//catch where the model doesn't return values because of all null known vals rewind(fp); //advance the cursor again while( (line = readLine(fp)) && line != NULL) { if(strstr(line, "inst#") != NULL) break; } //create target for results matrix * result = init_matrix(1, samples); safef(result->rowLabels[0], MAX_LABEL, "prediction"); copy_matrix_labels(result, labelTemplate, 2,2); result->labels=1; free_matrix(labelTemplate); //read each result and save to results matrix int i; for(i = 0; i < result->cols && (line = readLine(fp)) != NULL; i++) { if(strstr(line, ":?") == NULL) { if(strstr(line, "subgroup 1:subgroup")) result->graph[0][i] = 0-atof(lastWordInLine(line)); else if(strstr(line, "subgroup 2:subgroup")) result->graph[0][i] = atof(lastWordInLine(line)); else errAbort("ERROR: Coudln't find a proper class assignment in your WEKA results file.\n"); } } fclose(fp); return result; }
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); }
struct libInfo *addEsts(char *database, struct hash *eiHash, struct hash *libHash, struct hash *authorHash, struct hash *liHash) /* Read in all ESTs from mRNA table in database and add them to * library they belong to. */ { struct libInfo *liList = NULL, *li; struct estOrientInfo *ei; struct sqlConnection *conn = sqlConnect(database); struct sqlResult *sr = NULL; char liId[256]; char **row; struct nameId *library, *author; sr = sqlGetResult(conn, "NOSQLINJ select acc,library,author,direction from mrna where type = 'EST'"); while ((row = sqlNextRow(sr)) != NULL) { library = hashMustFindVal(libHash, row[1]); author = hashMustFindVal(authorHash, row[2]); sprintf(liId, "%s.%s", library->id, author->id); if ((li = hashFindVal(liHash, liId)) == NULL) { AllocVar(li); li->libName = library->name; li->author = author->name; hashAdd(liHash, liId, li); slAddHead(&liList, li); } li->estCount += 1; if ((ei = hashFindVal(eiHash, row[0])) != NULL) { switch (row[3][0]) { case '5': slAddHead(&li->fivePrime, ei); break; case '3': slAddHead(&li->threePrime, ei); break; case '0': slAddHead(&li->unPrime, ei); break; default: errAbort("Unknown type '%s' for %s", row[3], row[0]); break; } } } sqlFreeResult(&sr); sqlDisconnect(&conn); slSort(&liList, libInfoCmp); return liList; }
struct chrom *getQChrom(char *qName, struct hash *qChromHash) /* Lift qName to chrom if necessary and dig up from qChromHash. */ { struct chrom *qChrom = NULL; if (liftHashQ != NULL) { struct liftSpec *lft = hashMustFindVal(liftHashQ, qName); qChrom = hashMustFindVal(qChromHash, lft->newName); } else qChrom = hashMustFindVal(qChromHash, qName); return(qChrom); }
void addMasking(struct hash *twoBitHash, struct hash *bitmapHash, char *seqName, unsigned start, unsigned end) /* Set bits in range. */ { if (end > start) { struct twoBit *tb = (struct twoBit *)hashMustFindVal(twoBitHash, seqName); if ((end > tb->size) || (start >= tb->size)) errAbort("bed range (%d - %d) is off the end of chromosome %s size %d", start, end, seqName, tb->size); Bits *bits = (Bits *)hashMustFindVal(bitmapHash, seqName); bitSetRange(bits, start, (end - start)); } }
void addName(struct sts *s, char *name) /* Add a name to a sts record */ { struct gb *gb; /* See if it is a genBank record */ if (checkGb(name)) { addElement(name, &s->si->genbank, &s->si->gbCount); if (hashLookup(gbAccHash, name)) { gb = hashMustFindVal(gbAccHash, name); gb->s = s; } else { AllocVar(gb); gb->next = NULL; gb->acc = cloneString(name); gb->s = s; } } else if (checkGdb(name)) { addElement(name, &s->si->gdb, &s->si->gdbCount); } else { addElement(name, &s->si->otherNames, &s->si->nameCount); } }
void pslRecalcMatch(char *inName, char *targetName, char *queryName, char *outName) /* pslRecalcMatch - Recalculate match,mismatch,repMatch columns in psl file. * This can be useful if the psl went through pslMap, or if you've added * lower-case repeat masking after the fact. */ { struct nibTwoCache *tCache = nibTwoCacheNew(targetName); struct dnaSeq *qSeqList = dnaLoadAll(queryName); struct hash *qHash = dnaSeqHash(qSeqList); struct psl *psl; struct lineFile *lf = pslFileOpen(inName); FILE *f = mustOpen(outName, "w"); while ((psl = pslNext(lf)) != NULL) { int tSize; struct dnaSeq *tSeqPart = nibTwoCacheSeqPart(tCache, psl->tName, psl->tStart, psl->tEnd - psl->tStart, &tSize); struct dnaSeq *qSeq = hashMustFindVal(qHash, getQName(psl->qName)); recalcMatches(psl, tSeqPart, psl->tStart, qSeq); pslTabOut(psl, f); dnaSeqFree(&tSeqPart); } carefulClose(&f); lineFileClose(&lf); }
void readAllSts(FILE *asf) /* Read in current sequences for sts markers */ { struct dnaSeq *ds; struct sts *s; char *words[8], *acc=NULL, *line; int wordCount; while (faReadMixedNext(asf, 0, "default", TRUE, &line, &ds)) { /* Determine the UCSC id */ wordCount = chopByWhite(line, words, ArraySize(words)); stripString(words[0], ">"); if (wordCount == 3) acc = cloneString(words[2]); else acc = NULL; /* Find the record and attach */ if (hashLookup(stsHash, ds->name)) { s = hashMustFindVal(stsHash, ds->name); s->fa = ds; s->faAcc = acc; s->si->sequence = 1; } else { dnaSeqFree(&ds); freez(&line); if (acc != NULL) freez(&acc); } } }
void separateStrand(struct bed *inList, struct hash *infoHash, struct rbTree *tree, struct rbTree *antitree, struct bed **retCoding, struct bed **retNearCoding, struct bed **retNearCodingJunk, struct bed **retAntisense, struct bed **retNoncoding) /* Separate list of beds from single strand into the 4 categories. * The tree covers the coding transcripts for this strand, and the * antitree for the opposite strand. */ { struct bed *bed, *nextBed; for (bed = inList; bed != NULL; bed = nextBed) { nextBed = bed->next; struct txInfo *info = hashMustFindVal(infoHash, bed->name); if (bed->thickStart < bed->thickEnd) { slAddHead(retCoding, bed); info->category = "coding"; if (info->retainedIntron || info->bleedIntoIntron >= 100 || info->nonsenseMediatedDecay) ++codingJunkCount; else ++codingCount; } else { if (startsWith("ab.ab", bed->name)) { slAddHead(retNoncoding, bed); info->category = "antibodyParts"; ++noncodingCount; } else if (bedOverlapWithRangeTree(tree, bed) >= minNearOverlap) { if (info->retainedIntron || info->bleedIntoIntron >= 100) { slAddHead(retNearCodingJunk, bed); info->category = "nearCodingJunk"; ++junkCount; } else { slAddHead(retNearCoding, bed); info->category = "nearCoding"; ++nearCodingCount; } } else if (bedOverlapWithRangeTree(antitree, bed) >= minNearOverlap) { slAddHead(retAntisense, bed); info->category = "antisense"; ++antisenseCount; } else { slAddHead(retNoncoding, bed); info->category = "noncoding"; ++noncodingCount; } } } }
struct chain *chainLookup(struct hash *hash, int id) /* Find chain in hash. */ { char nameBuf[16]; safef(nameBuf, sizeof(nameBuf), "%x", id); return hashMustFindVal(hash, nameBuf); }
static struct isxAddress *makeDirect(struct isx *isx, struct hash *labelHash) /* Isx is a conditional or unconditional jump instruction. * If it's target is an unconditional jump, then eliminate * the middle man or men, and jump straight to final destination */ { struct isxAddress *dest = isx->dest; char *name = dest->name; struct dlNode *node = hashMustFindVal(labelHash, name); for (; !dlEnd(node); node = node->next) { struct isx *isx = node->val; switch (isx->opType) { case poLabel: case poLoopStart: case poLoopEnd: case poCondCase: case poCondStart: case poCondEnd: break; case poJump: // uglyf("Short circuiting %s\n", name); return makeDirect(node->val, labelHash); default: return dest; } } return dest; }
struct sangRead *readReads(char *fileName, struct hash *pairHash) /* Read in read database file and hook it up to pairs in pairHash. */ { struct sangRead *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); char *words[4]; int wordCount; struct sangPair *pair; printf("Reading %s\n", fileName); while (lineFileNextRow(lf, words, 4)) { el = sangReadLoad(words); slAddHead(&list, el); pair = hashMustFindVal(pairHash, el->id); if (el->pq[0] == 'p') { if (pair->fRead) warn("%s - duplicate p read line %d of %s\n", el->id, lf->lineIx, lf->fileName); pair->fRead = el; } else { if (pair->rRead) warn("%s - duplicate q read line %d of %s\n", el->id, lf->lineIx, lf->fileName); pair->rRead = el; } } lineFileClose(&lf); slReverse(&list); return list; }
void polyInfo(char *pslFile, char *genoFile, char *estFile, char *outputFile) /* polyInfo - Collect info on polyAdenylation signals etc. */ { struct hash *pslHash = NULL; struct hash *genoHash = loadGeno(genoFile); static struct dnaSeq est; struct lineFile *lf = NULL; FILE *f = NULL; pslHash = pslIntoHash(pslFile); lf = lineFileOpen(estFile, TRUE); f = mustOpen(outputFile, "w"); while (faSpeedReadNext(lf, &est.dna, &est.size, &est.name)) { struct pslList *pl; struct psl *psl; struct estOrientInfo ei; if ((pl = hashFindVal(pslHash, est.name)) != NULL) { for (psl = pl->list; psl != NULL; psl = psl->next) { struct dnaSeq *geno = hashMustFindVal(genoHash, psl->tName); if (psl->tSize != geno->size) errAbort("psl generated on a different version of the genome"); ZeroVar(&ei); fillInEstInfo(&ei, &est, geno, psl); estOrientInfoTabOut(&ei, f); } } } }
char *bigWigFileName(char *table, struct sqlConnection *conn) /* Return file name associated with bigWig. This handles differences whether it's * a custom or built-in track. Do a freeMem on returned string when done. */ { struct trackDb *tdb = hashMustFindVal(fullTableToTdbHash, table); return tdbBigFileName(conn, tdb); }
void readEpcr(struct lineFile *ef) /* Read in and record epcr records */ { int wordCount; char *words[8]; char *pos[4]; struct epcr *epcr; struct sts *sts; while (lineFileChopNext(ef, words, 4)) { if (words[3]) { AllocVar(epcr); epcr->next = NULL; epcr->contig = cloneString(words[0]); epcr->bases = cloneString(words[1]); epcr->dbstsId = cloneString(words[2]); epcr->ucscId = cloneString(words[3]); wordCount = chopByChar(words[1], '.', pos, ArraySize(pos)); if (wordCount != 3) errAbort("Not parsing epcr as expeceted\n"); epcr->start = sqlUnsigned(pos[0]); epcr->end = sqlUnsigned(pos[2]); sts = hashMustFindVal(stsHash, epcr->dbstsId); if (!epcrInList(sts->epcr, epcr)) { slAddHead(&sts->epcr, epcr); sts->epcrCount++; } } } }
void *hashMustFindValFromInt(struct hash *hash, int key) /* Return hash value using an integer key */ { char buf[32]; safef(buf, sizeof(buf), "%d", key); return hashMustFindVal(hash, buf); }
void pslIntronsOnly(char *inPslName, char *genoFile, char *outPslName) /* pslIntronsOnly - Filter psl files to only include those with introns. */ { struct lineFile *lf = NULL; FILE *outFile = NULL; struct hash *genoHash = loadGeno(genoFile); struct psl *psl; int count = 0, intronCount = 0; lf = pslFileOpen(inPslName); outFile = mustOpen(outPslName, "w"); while ((psl = pslNext(lf)) != NULL) { struct dnaSeq *geno = hashMustFindVal(genoHash, psl->tName); if (pslHasIntron(psl, geno, 0)) { ++intronCount; pslTabOut(psl, outFile); } pslFree(&psl); ++count; } carefulClose(&outFile); lineFileClose(&lf); printf("%d of %d in %s have introns\n", intronCount, count, inPslName); }
void outputProt(struct protInfo *prot, struct hash *seedToScop, FILE *f, FILE *fKnownTo) /* Callapse together all features of same type that overlap and output */ { slSort(&prot->featureList, protFeatureCmpName); struct protFeature *startFeature, *endFeature; for (startFeature = prot->featureList; startFeature != NULL; startFeature = endFeature) { for (endFeature = startFeature->next; endFeature != NULL; endFeature = endFeature->next) if (!sameString(startFeature->name, endFeature->name)) break; struct rbTree *rangeTree = rangeTreeNew(); struct protFeature *feature; for (feature = startFeature; feature != endFeature; feature = feature->next) rangeTreeAdd(rangeTree, feature->start, feature->end); struct range *range, *rangeList = rangeTreeList(rangeTree); for (range = rangeList; range != NULL; range = range->next) { feature = highestScoringFeature(startFeature, endFeature, range->start, range->end); fprintf(f, "%s\t%d\t%d\t%s\n", prot->name, range->start, range->end, startFeature->name); fprintf(fKnownTo, "%s\t%s\t%d\t%d\t%g\n", prot->name, (char *)hashMustFindVal(seedToScop, startFeature->name), range->start, range->end, feature->eVal); } rangeTreeFree(&rangeTree); } }
int hashIntVal(struct hash *hash, char *name) /* Return integer value associated with name in a simple * hash of ints. */ { void *val = hashMustFindVal(hash, name); return ptToInt(val); }
void readCachedSeqPart(char *seqName, int start, int size, boolean getMasked, struct hash *hash, struct dlList *fileCache, struct dnaSeq **retSeq, int *retOffset, boolean *retIsNib) /* Read sequence hopefully using file cashe. If sequence is in a nib * file just read part of it. */ { struct seqFilePos *sfp = hashMustFindVal(hash, seqName); FILE *f = openFromCache(fileCache, sfp); if (sfp->isTwoBit) { *retSeq = twoBitReadSeqFrag((struct twoBitFile *)f, seqName, start, start + size); *retOffset = start; *retIsNib = TRUE; } else if (sfp->isNib) { *retSeq = nibLdPartMasked((getMasked ? NIB_MASK_MIXED : 0), sfp->file, f, sfp->pos, start, size); *retOffset = start; *retIsNib = TRUE; } else { if (getMasked) errAbort("masked sequences not supported with fasta files"); *retSeq = readSeqFromFaPos(sfp, f); *retOffset = 0; *retIsNib = FALSE; } }
void writeRelevantChains(char *ctgDir, struct hash *cloneHash) /* Read in geno.lst and write chains on relevant clones to * fragChains. */ { char inName[512]; char outName[512]; char *wordBuf, **faNames; int faCount; int i; char dir[256], cloneName[128], ext[64]; FILE *f; struct clone *clone; sprintf(inName, "%s/geno.lst", ctgDir); sprintf(outName, "%s/fragChains", ctgDir); readAllWords(inName, &faNames, &faCount, &wordBuf); f = mustOpen(outName, "w"); for (i=0; i<faCount; ++i) { splitPath(faNames[i], dir, cloneName, ext); if (!startsWith("NT_", cloneName)) { clone = hashMustFindVal(cloneHash, cloneName); writeChains(clone, f); } } freeMem(wordBuf); fclose(f); }
struct taggedFile *taggedFileForComposite(struct composite *composite, struct hash *metaHash) /* Return a taggedFile for every file in the composite. */ { struct slRef *manRefList = composite->manRefList; struct taggedFile *tf, *tfList = NULL; struct slRef *ref; for (ref = manRefList; ref != NULL; ref = ref->next) { /* Wrap up tags and manifest together, including a bonus tag or two from manifest. */ struct encode2Manifest *man = ref->val; struct meta *meta = hashMustFindVal(metaHash, man->experiment); AllocVar(tf); tf->manifest = man; slAddHead(&tfList, tf); struct metaTagVal *s, *d; for (s = meta->tagList; s != NULL; s = s->next) { d = metaTagValNew(s->tag, s->val); slAddHead(&tf->tagList, d); } d = metaTagValNew("replicate", man->replicate); slAddHead(&tf->tagList, d); } return tfList; }
struct hash *readChainToBinKeeper(char *sizeFileName, char *fileName) { struct binKeeper *bk; struct chain *chain; struct lineFile *lf = lineFileOpen(fileName, TRUE); struct lineFile *sf = lineFileOpen(sizeFileName, TRUE); struct hash *hash = newHash(0); char *chromRow[2]; while (lineFileRow(sf, chromRow)) { char *name = chromRow[0]; int size = lineFileNeedNum(sf, chromRow, 1); if (hashLookup(hash, name) != NULL) warn("Duplicate %s, ignoring all but first\n", name); else { bk = binKeeperNew(0, size); assert(size > 1); hashAdd(hash, name, bk); } } while ((chain = chainRead(lf)) != NULL) { bk = hashMustFindVal(hash, chain->tName); binKeeperAdd(bk, chain->tStart, chain->tEnd, chain); } lineFileClose(&lf); return hash; }
struct indexedChain *chainFromId(struct hash *chainHash, int id) /* Given chain ID and hash, return chain. */ { char chainId[20]; safef(chainId, sizeof(chainId), "%x", id); return hashMustFindVal(chainHash, chainId); }
boolean doTypeOfTermRow(struct hash *ra, char *org) // print one typeOfTerm row { char *term = (char *)hashMustFindVal(ra, CV_TERM); if (sameString(term,cvTypeNormalized(CV_TERM_CELL))) term = CV_TERM_CELL; else if (sameString(term,cvTypeNormalized(CV_TERM_ANTIBODY))) term = CV_TERM_ANTIBODY; puts("<TR>"); printf(" <TD><A HREF='hgEncodeVocab?type=%s' title='%s details' " "TARGET=ucscVocabChild>%s</a></TD>\n", term, term, term); printDescription(ra,NULL,2); printLabel(ra,term); puts("</TR>"); if (sameString(term,CV_TERM_CELL)) { puts("<TR>"); printf(" <TD><A HREF='hgEncodeVocab?type=%s&organism=Mouse' title='Mouse %s details' " "TARGET=ucscVocabChild>%s</a> <em>(for mouse)</em></TD>\n", term, term, term); char *s = getDescription(ra,NULL); printf(" <TD colspan=%d>%s <em>(for mouse)</em></TD>\n", TABLE_COLS_AVAILABLE(2), s?s:" "); freeMem(s); printLabel(ra,term); puts("</TR>"); } return TRUE; }