struct hash *allChainsHash(char *fileName) /* Hash all the chains in a given file by their ids. */ { struct hash *chainHash = newHash(18); struct lineFile *lf = lineFileOpen(fileName, TRUE); struct chain *chain; char chainId[20]; struct lm *lm = chainHash->lm; struct rbTreeNode **stack; lmAllocArray(lm, stack, 128); while ((chain = chainRead(lf)) != NULL) { struct indexedChain *ixc; lmAllocVar(lm, ixc); ixc->chain = chain; #ifdef SOON #endif /* SOON */ ixc->blockTree = rangeTreeNewDetailed(lm, stack); struct cBlock *block; for (block = chain->blockList; block != NULL; block = block->next) { struct range *r = rangeTreeAdd(ixc->blockTree, block->tStart, block->tEnd); r->val = block; } safef(chainId, sizeof(chainId), "%x", chain->id); hashAddUnique(chainHash, chainId, ixc); } lineFileClose(&lf); return chainHash; }
void peakClusterMakerAddFromSource(struct peakClusterMaker *maker, struct peakSource *source) /* Read through data source and add items to it to rangeTrees in maker */ { struct hash *chromHash = maker->chromHash; struct lineFile *lf = lineFileOpen(source->dataSource, TRUE); struct lm *lm = chromHash->lm; /* Local memory pool - share with hash */ char *row[source->minColCount]; struct peakItem *item; char *line; while (lineFileNextReal(lf, &line)) { char *asciiLine = lmCloneString(lm, line); int wordCount = chopByWhite(line, row, source->minColCount); lineFileExpectAtLeast(lf, source->minColCount, wordCount); char *chrom = row[source->chromColIx]; struct hashEl *hel = hashLookup(chromHash, chrom); if (hel == NULL) { struct rbTree *tree = rangeTreeNewDetailed(lm, maker->stack); hel = hashAdd(chromHash, chrom, tree); } struct rbTree *tree = hel->val; lmAllocVar(lm, item); item->chrom = hel->name; item->chromStart = sqlUnsigned(row[source->startColIx]); item->chromEnd = sqlUnsigned(row[source->endColIx]); item->score = sqlDouble(row[source->scoreColIx]) * source->normFactor; if (item->score > 1000) item->score = 1000; item->source = source; item->asciiLine = asciiLine; rangeTreeAddValList(tree, item->chromStart, item->chromEnd, item); } lineFileClose(&lf); }
struct rbTree *genomeRangeTreeFindOrAddRangeTree(struct genomeRangeTree *tree, char *chrom) /* Find the rangeTree for this chromosome, or add new chrom and empty rangeTree if not found. */ { struct hashEl *hel; hel = hashStore(tree->hash, chrom); if (hel->val == NULL) /* need to add a new rangeTree */ hel->val = rangeTreeNewDetailed(tree->lm, tree->stack); return hel->val; }
void refSeparateButJoined(struct txGraph *graph, FILE *f) /* Flag graphs that have two non-overlapping refSeqs. */ { int sourceIx; boolean foundIt = FALSE; struct lm *lm = lmInit(0); struct rbTreeNode **stack; lmAllocArray(lm, stack, 128); /* Loop through sources looking for reference type. */ for (sourceIx=0; sourceIx<graph->sourceCount; ++sourceIx) { struct txSource *source = &graph->sources[sourceIx]; if (sameString(source->type, refType)) { /* Create a rangeTree including all exons of source. */ struct rbTree *tree = rangeTreeNewDetailed(lm, stack); struct txEdge *edge; for (edge = graph->edgeList; edge != NULL; edge = edge->next) { if (edge->type == ggExon && evOfSourceOnList(edge->evList, sourceIx)) rangeTreeAdd(tree, graph->vertices[edge->startIx].position, graph->vertices[edge->endIx].position); } /* Go through remaining reference sources looking for no overlap. */ int i; for (i=0; i<graph->sourceCount; ++i) { if (i == sourceIx) continue; struct txSource *s = &graph->sources[i]; if (sameString(s->type, refType)) { boolean gotOverlap = FALSE; for (edge = graph->edgeList; edge != NULL; edge = edge->next) { if (edge->type == ggExon && evOfSourceOnList(edge->evList, i)) { if (rangeTreeOverlaps(tree, graph->vertices[edge->startIx].position, graph->vertices[edge->endIx].position)) { gotOverlap = TRUE; break; } } } if (!gotOverlap) { foundIt = TRUE; break; } } } freez(&tree); } if (foundIt) break; } if (foundIt) { fprintf(f, "%s\t%d\t%d\t%s\t0\t%s\n", graph->tName, graph->tStart, graph->tEnd, "refJoined", graph->strand); } lmCleanup(&lm); }