void constExons(struct txGraph *graph, FILE *f) /* Write out constituitive exons. */ { /* Create a tree with all introns. */ struct rbTree *tree = rangeTreeNew(); struct txEdge *edge; for (edge = graph->edgeList; edge != NULL; edge = edge->next) { if (edge->type == ggIntron) { rangeTreeAdd(tree, graph->vertices[edge->startIx].position, graph->vertices[edge->endIx].position); } } /* Scan through all exons looking for ones that don't intersect * introns. */ int eId = 0; for (edge = graph->edgeList; edge != NULL; edge = edge->next) { if (edge->type == ggExon) { struct txVertex *s = &graph->vertices[edge->startIx]; struct txVertex *e = &graph->vertices[edge->endIx]; if (s->type == ggHardStart && e->type == ggHardEnd) { int start = s->position; int end = e->position; if (!rangeTreeOverlaps(tree, start, end)) { char *refSource = refSourceAcc(graph, edge); if (refSource != NULL && edge->evCount >= 10) { /* Do one more scan making sure that it doesn't * intersect any exons except for us. */ boolean anyOtherExon = FALSE; struct txEdge *ed; for (ed = graph->edgeList; ed != NULL; ed = ed->next) { if (ed != edge) { int edStart = graph->vertices[ed->startIx].position; int edEnd = graph->vertices[ed->endIx].position; if (rangeIntersection(edStart, edEnd, start, end) > 0) { anyOtherExon = TRUE; break; } } } if (!anyOtherExon) fprintf(f, "%s\t%d\t%d\t%s.%d\t0\t%s\n", graph->tName, start, end, refSource, ++eId, graph->strand); } } } } } rangeTreeFree(&tree); }
static struct bed* subset_beds(char* sectionString, struct bed** pRegions, struct hash* chromHash) /* in the situation where both a regions bed file is given AND the filename specifies subsections, */ /* intersect the two. For simplictity sake, */ { struct bed* fname_ranges = parseSectionString(sectionString, chromHash); struct bed* bed; struct bed* subset = NULL; struct bed* regions = *pRegions; slSort(&fname_ranges, bedCmp); bed = fname_ranges; while (bed != NULL) { /* each iteration of the loop should be a separate chrom */ struct bed* region; struct rbTree* tree = rangeTreeNew(); while ((bed != NULL) && (bed->next != NULL) && (sameString(bed->chrom, bed->next->chrom))) { rangeTreeAdd(tree, bed->chromStart, bed->chromEnd); bed = bed->next; } rangeTreeAdd(tree, bed->chromStart, bed->chromEnd); /* now we're at a point that we're dealing only with one chromosome. */ for (region = regions; region != NULL; region = region->next) { if (sameString(region->chrom, bed->chrom) && rangeTreeOverlaps(tree, region->chromStart, region->chromEnd) && rangeTreeFindEnclosing(tree, region->chromStart, region->chromEnd)) { struct bed* clone = cloneBed(region); slAddHead(&subset, clone); } else if (sameString(region->chrom, bed->chrom) && rangeTreeOverlaps(tree, region->chromStart, region->chromEnd)) errAbort("range specified in file overlaps but is not contained by range specified on command-line"); } rangeTreeFree(&tree); bed = bed->next; } if (subset == NULL) { errAbort("no ranges specified in file were contained in ranges specified on command-line"); } slReverse(&subset); bedFreeList(&fname_ranges); bedFreeList(pRegions); return subset; }
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); }