void addChainT(struct chrom *chrom, struct chrom *otherChrom, struct chain *chain) /* Add T side of chain to fill/gap tree of chromosome. * This is the easier case since there are no strand * issues to worry about. */ { struct slRef *spaceList; struct slRef *ref; struct cBlock *startBlock, *block, *nextBlock; struct gap *gap; spaceList = findSpaces(chrom->spaces,chain->tStart,chain->tEnd); startBlock = chain->blockList; for (ref = spaceList; ref != NULL; ref = ref->next) { struct space *space = ref->val; struct fill *fill; int gapStart, gapEnd; for (;;) { nextBlock = startBlock->next; if (nextBlock == NULL) break; gapEnd = nextBlock->tStart; if (gapEnd > space->start) break; startBlock = nextBlock; } if ((fill = fillSpace(chrom, space, chain, startBlock, FALSE)) != NULL) { for (block = startBlock; ; block = nextBlock) { nextBlock = block->next; if (nextBlock == NULL) break; gapStart = block->tEnd; gapEnd = nextBlock->tStart; if (strictlyInside(space->start, space->end, gapStart, gapEnd)) { int qs = block->qEnd; int qe = nextBlock->qStart; if (chain->qStrand == '-') reverseIntRange(&qs, &qe, chain->qSize); gap = gapNew(gapStart, gapEnd, qs, qe); addSpaceForGap(chrom, gap); slAddHead(&fill->gapList, gap); } } freez(&ref->val); /* aka space */ } } slFreeList(&spaceList); }
int main(int argc, char * argv[]) { if(argc < 2) { printf("Usage: %s <string>\n", argv[0]); return(EXIT_FAILURE); } int lengthOld = strlen(argv[1]); int lengthNew; char * newString; char * oldString; oldString = malloc(sizeof(char) * (lengthOld + 1)); strncpy(oldString, argv[1], lengthOld); oldString[lengthOld] = '\0'; lengthNew = lengthOld + (2 * findSpaces(oldString)); newString = malloc(sizeof(char) * (lengthNew + 1)); newString[lengthNew] = '\0'; printf("Old String: %s\n", oldString); replaceSpaces(oldString, newString, lengthOld, lengthNew); printf("New String: %s\n", newString); free(oldString); free(newString); return(EXIT_SUCCESS); }
void addChainQ(struct chrom *chrom, struct chrom *otherChrom, struct chain *chain) /* Add Q side of chain to fill/gap tree of chromosome. * For this side we have to cope with reverse strand * issues. */ { struct slRef *spaceList; struct slRef *ref; struct cBlock *startBlock, *block, *nextBlock; int gapStart, gapEnd; struct gap *gap; boolean isRev = (chain->qStrand == '-'); int qStart = chain->qStart, qEnd = chain->qEnd; if (isRev) { reverseIntRange(&qStart, &qEnd, chain->qSize); reverseBlocksQ(&chain->blockList, chain->qSize); } spaceList = findSpaces(chrom->spaces,qStart,qEnd); startBlock = chain->blockList; for (ref = spaceList; ref != NULL; ref = ref->next) { struct space *space = ref->val; struct fill *fill; for (;;) { nextBlock = startBlock->next; if (nextBlock == NULL) break; gapEnd = nextBlock->qStart; if (gapEnd > space->start) break; startBlock = nextBlock; } if ((fill = fillSpace(chrom, space, chain, startBlock, TRUE)) != NULL) { for (block = startBlock; ; block = nextBlock) { nextBlock = block->next; if (nextBlock == NULL) break; gapStart = block->qEnd; gapEnd = nextBlock->qStart; if (strictlyInside(space->start, space->end, gapStart, gapEnd)) { int ts, te; if (chain->qStrand == '+') { ts = block->tEnd; te = nextBlock->tStart; } else { ts = nextBlock->tStart; te = block->tEnd; } gap = gapNew(gapStart, gapEnd, ts, te); addSpaceForGap(chrom, gap); slAddHead(&fill->gapList, gap); } } freez(&ref->val); /* aka space */ } } slFreeList(&spaceList); if (isRev) reverseBlocksQ(&chain->blockList, chain->qSize); }