void testCap_segmentCoordinatesReverseStrand(CuTest* testCase) { /* * Tests the coordinates of an segment and its 5 and 3 prime caps. */ cactusCapTestSetup(); Block *block = block_construct(3, flower); Segment *segment = segment_construct2(block, 2, 0, sequence); Cap *_5Cap = segment_get5Cap(segment); Cap *_3Cap = segment_get3Cap(segment); CuAssertTrue(testCase, cap_getSide(_5Cap)); CuAssertTrue(testCase, !cap_getSide(_3Cap)); CuAssertTrue(testCase, !cap_getStrand(_5Cap)); CuAssertTrue(testCase, !cap_getStrand(_3Cap)); CuAssertIntEquals(testCase, 4, cap_getCoordinate(_5Cap)); CuAssertIntEquals(testCase, 2, cap_getCoordinate(_3Cap)); CuAssertTrue(testCase, !segment_getStrand(segment)); CuAssertIntEquals(testCase, 4, segment_getStart(segment)); CuAssertIntEquals(testCase, 3, segment_getLength(segment)); CuAssertTrue(testCase, !cap_getSide(cap_getReverse(_5Cap))); CuAssertTrue(testCase, cap_getSide(cap_getReverse(_3Cap))); CuAssertTrue(testCase, cap_getStrand(cap_getReverse(_5Cap))); CuAssertTrue(testCase, cap_getStrand(cap_getReverse(_3Cap))); CuAssertIntEquals(testCase, 4, cap_getCoordinate(cap_getReverse(_5Cap))); CuAssertIntEquals(testCase, 2, cap_getCoordinate(cap_getReverse(_3Cap))); CuAssertTrue(testCase, segment_getStrand(segment_getReverse(segment))); CuAssertIntEquals(testCase, 2, segment_getStart(segment_getReverse(segment))); CuAssertIntEquals(testCase, 3, segment_getLength(segment_getReverse(segment))); cactusCapTestTeardown(); }
static void debugScaffoldPaths(stList *haplotypePaths, stHash *haplotypePathToScaffoldPathHash, stHash *haplotypeToMaximalHaplotypeLengthHash, stList *haplotypeEventStrings, stList *contaminationEventStrings, CapCodeParameters *capCodeParameters) { stHash *segmentToMaximalHaplotypePathHash = buildSegmentToContigPathHash(haplotypePaths); for (int64_t i = 0; i < stList_length(haplotypePaths); i++) { stList *haplotypePath = stList_get(haplotypePaths, i); assert(stList_length(haplotypePath) > 0); //Traversing from 5' end.. Segment *_5Segment = stList_get(haplotypePath, 0); Segment *_3Segment = stList_get(haplotypePath, stList_length(haplotypePath) - 1); assert(segment_getStrand(_5Segment) == segment_getStrand(_3Segment)); if (!segment_getStrand(_5Segment)) { Segment *j = _5Segment; _5Segment = segment_getReverse(_3Segment); _3Segment = segment_getReverse(j); } assert(segment_getStrand(_5Segment)); assert(segment_getStrand(_3Segment)); Cap *_5Cap = segment_get5Cap(_5Segment); Cap *_3Cap = segment_get3Cap(_3Segment); if (getAdjacentCapsSegment(_5Cap) != NULL) { assert(!trueAdjacency(_5Cap, haplotypeEventStrings)); } if (getAdjacentCapsSegment(_3Cap) != NULL) { assert(!trueAdjacency(_3Cap, haplotypeEventStrings)); } debugScaffoldPathsP(_5Cap, haplotypePath, haplotypePathToScaffoldPathHash, haplotypeToMaximalHaplotypeLengthHash, segmentToMaximalHaplotypePathHash, haplotypeEventStrings, contaminationEventStrings, capCodeParameters, 1); debugScaffoldPathsP(_3Cap, haplotypePath, haplotypePathToScaffoldPathHash, haplotypeToMaximalHaplotypeLengthHash, segmentToMaximalHaplotypePathHash, haplotypeEventStrings, contaminationEventStrings, capCodeParameters, 0); } stHash_destruct(segmentToMaximalHaplotypePathHash); }
static void getMaximalHaplotypePathsP2(Segment *segment, stList *maximalHaplotypePath, stSortedSet *segmentSet, stList *eventStrings) { /* * Iterate all the way to one end of the contig then start the traversal to define the maximal * haplotype path. */ Cap *_5Cap = segment_get5Cap(segment); assert(hasCapInEvents(cap_getEnd(segment_get3Cap(segment)), eventStrings)); //isHaplotypeEnd(cap_getEnd(segment_get3Cap(segment)))); if (trueAdjacency(_5Cap, eventStrings)) { //Check that the adjacency is supported by a haplotype path Segment *otherSegment = getAdjacentCapsSegment(_5Cap); assert(segment != otherSegment); assert(segment_getReverse(segment) != otherSegment); if (otherSegment != NULL) { assert(stSortedSet_search(segmentSet, otherSegment) == NULL); assert(stSortedSet_search(segmentSet, segment_getReverse( otherSegment)) == NULL); assert(hasCapInEvents(cap_getEnd(segment_get3Cap(otherSegment)), eventStrings)); //isHaplotypeEnd(cap_getEnd(segment_get3Cap(otherSegment)))); getMaximalHaplotypePathsP2(otherSegment, maximalHaplotypePath, segmentSet, eventStrings); } else { //We need to start the maximal haplotype recursion getMaximalHaplotypePathsP3(segment, maximalHaplotypePath, segmentSet, eventStrings); } } else { getMaximalHaplotypePathsP3(segment, maximalHaplotypePath, segmentSet, eventStrings); } }
static stList *getSubstringsForFlowerSegments(stList *flowers) { /* * Get the set of substrings representing the strings in the segments of the given flowers. */ stList *substrings = stList_construct3(0, (void (*)(void *)) substring_destruct); for (int64_t i = 0; i < stList_length(flowers); i++) { Flower *flower = stList_get(flowers, i); Flower_EndIterator *blockIt = flower_getBlockIterator(flower); Block *block; while ((block = flower_getNextBlock(blockIt)) != NULL) { Block_InstanceIterator *instanceIt = block_getInstanceIterator(block); Segment *segment; while ((segment = block_getNext(instanceIt)) != NULL) { Sequence *sequence; if ((sequence = segment_getSequence(segment)) != NULL) { segment = segment_getStrand(segment) ? segment : segment_getReverse(segment); assert(segment_getLength(segment) > 0); stList_append(substrings, substring_construct(sequence_getMetaSequence(sequence)->stringName, segment_getStart(segment) - sequence_getStart(sequence), segment_getLength(segment))); } } block_destructInstanceIterator(instanceIt); } flower_destructBlockIterator(blockIt); } return substrings; }
static void debugScaffoldPathsP(Cap *cap, stList *haplotypePath, stHash *haplotypePathToScaffoldPathHash, stHash *haplotypeToMaximalHaplotypeLengthHash, stHash *segmentToMaximalHaplotypePathHash, stList *haplotypeEventStrings, stList *contaminationEventStrings, CapCodeParameters *capCodeParameters, bool capDir) { int64_t insertLength; int64_t deleteLength; Cap *otherCap; enum CapCode capCode = getCapCode(cap, &otherCap, haplotypeEventStrings, contaminationEventStrings, &insertLength, &deleteLength, capCodeParameters); if (capCode == SCAFFOLD_GAP || capCode == AMBIGUITY_GAP) { Segment *adjacentSegment = getAdjacentCapsSegment(cap); assert(adjacentSegment != NULL); while (!hasCapInEvents(cap_getEnd(capDir ? segment_get5Cap(adjacentSegment) : segment_get3Cap(adjacentSegment)), haplotypeEventStrings)) { adjacentSegment = getAdjacentCapsSegment(capDir ? segment_get5Cap(adjacentSegment) : segment_get3Cap(adjacentSegment)); assert(adjacentSegment != NULL); } assert(adjacentSegment != NULL); assert(hasCapInEvents(cap_getEnd(segment_get5Cap(adjacentSegment)), haplotypeEventStrings)); //isHaplotypeEnd(cap_getEnd(segment_get5Cap(adjacentSegment)))); stIntTuple *j = stHash_search(haplotypeToMaximalHaplotypeLengthHash, haplotypePath); (void)j; assert(j != NULL); stList *adjacentHaplotypePath = stHash_search(segmentToMaximalHaplotypePathHash, adjacentSegment); if (adjacentHaplotypePath == NULL) { adjacentHaplotypePath = stHash_search(segmentToMaximalHaplotypePathHash, segment_getReverse(adjacentSegment)); } assert(adjacentHaplotypePath != NULL); assert(adjacentHaplotypePath != haplotypePath); stIntTuple *k = stHash_search(haplotypeToMaximalHaplotypeLengthHash, adjacentHaplotypePath); (void)k; assert(k != NULL); assert(stIntTuple_get(j, 0) == stIntTuple_get(k, 0)); assert(stHash_search(haplotypePathToScaffoldPathHash, haplotypePath) == stHash_search(haplotypePathToScaffoldPathHash, adjacentHaplotypePath)); } }
static void getMaximalHaplotypePathsCheck(Flower *flower, stSortedSet *segmentSet, const char *eventString, stList *eventStrings) { /* * Do debug checks that the haplotypes paths are well formed. */ Flower_SegmentIterator *segmentIt = flower_getSegmentIterator(flower); Segment *segment; while ((segment = flower_getNextSegment(segmentIt)) != NULL) { if (strcmp(event_getHeader(segment_getEvent(segment)), eventString) == 0) { if (hasCapInEvents(cap_getEnd(segment_get5Cap(segment)), eventStrings)) { //isHaplotypeEnd(cap_getEnd(segment_get5Cap(segment)))) { assert(stSortedSet_search(segmentSet, segment) != NULL || stSortedSet_search(segmentSet, segment_getReverse( segment)) != NULL); } } } flower_destructSegmentIterator(segmentIt); Flower_GroupIterator *groupIt = flower_getGroupIterator(flower); Group *group; while ((group = flower_getNextGroup(groupIt)) != NULL) { if (group_getNestedFlower(group) != NULL) { getMaximalHaplotypePathsCheck(group_getNestedFlower(group), segmentSet, eventString, eventStrings); } } flower_destructGroupIterator(groupIt); }
void block_check(Block *block) { //Check is connected to flower properly cactusCheck(flower_getBlock(block_getFlower(block), block_getName(block)) == block_getPositiveOrientation(block)); //Check we have actually set built blocks for the flower.. cactusCheck(flower_builtBlocks(block_getFlower(block))); //Checks the two ends are block ends. End *_5End = block_get5End(block); End *_3End = block_get3End(block); cactusCheck(end_isBlockEnd(_5End)); cactusCheck(end_isBlockEnd(_3End)); cactusCheck(end_getOrientation(_5End) == block_getOrientation(block)); cactusCheck(end_getOrientation(_3End) == block_getOrientation(block)); cactusCheck(end_getBlock(_5End) == block); cactusCheck(end_getBlock(_3End) == block); cactusCheck(end_getSide(_5End)); //Check the sides of the ends are consistent. cactusCheck(!end_getSide(_3End)); cactusCheck(block_getLength(block) > 0); //check block has non-zero length //Check reverse Block *rBlock = block_getReverse(block); cactusCheck(rBlock != NULL); cactusCheck(block_getReverse(block) == rBlock); cactusCheck(block_getOrientation(block) == !block_getOrientation(rBlock)); cactusCheck(block_getLength(block) == block_getLength(rBlock)); cactusCheck(block_get5End(block) == end_getReverse(block_get3End(rBlock))); cactusCheck(block_get3End(block) == end_getReverse(block_get5End(rBlock))); cactusCheck(block_getInstanceNumber(block) == block_getInstanceNumber(rBlock)); if(block_getInstanceNumber(block) > 0) { cactusCheck(block_getFirst(block) == segment_getReverse(block_getFirst(rBlock))); if(block_getRootInstance(block) == NULL) { cactusCheck(block_getRootInstance(rBlock) == NULL); } else { cactusCheck(block_getRootInstance(block) == segment_getReverse(block_getRootInstance(rBlock))); } } //For each segment calls segment_check. Block_InstanceIterator *iterator = block_getInstanceIterator(block); Segment *segment; while((segment = block_getNext(iterator)) != NULL) { segment_check(segment); } block_destructInstanceIterator(iterator); }
void testBlock_getFirst(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getFirst(block) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getFirst(block_getReverse(block)) == rootSegment); Block *block2 = block_construct(1, flower); CuAssertTrue(testCase, block_getFirst(block2) == NULL); CuAssertTrue(testCase, block_getFirst(block_getReverse(block2)) == NULL); cactusBlockTestTeardown(); }
void testBlock_getSegmentForEvent(CuTest* testCase) { cactusBlockTestSetup(); CuAssertPtrEquals(testCase, block_getSegmentForEvent(block_getReverse(block), event_getName(rootEvent)), rootSegment); Segment *segment = block_getSegmentForEvent(block, event_getName(leafEvent)); CuAssertTrue(testCase, segment == leaf1Segment || segment == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getSegmentForEvent(block, NULL_NAME) == NULL); cactusBlockTestTeardown(); }
void testBlock_getSetRootInstance(CuTest *testCase) { cactusBlockTestSetup(); Block *block2 = block_construct(1, flower); CuAssertTrue(testCase, block_getRootInstance(block2) == NULL); block_destruct(block2); //block_setRootInstance(block, segment_getReverse(rootSegment)); //set in the constructor code of the test. CuAssertTrue(testCase, block_getRootInstance(block) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, end_getRootInstance(block_get5End(block)) == segment_get5Cap(segment_getReverse(rootSegment))); CuAssertTrue(testCase, end_getRootInstance(block_get3End(block)) == segment_get3Cap(segment_getReverse(rootSegment))); cactusBlockTestTeardown(); }
void testBlock_serialisation(CuTest* testCase) { cactusBlockTestSetup(); Name rootInstanceName = segment_getName(rootSegment); Name leaf1InstanceName = segment_getName(leaf1Segment); Name leaf2InstanceName = segment_getName(leaf2Segment); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(block, (void(*)(void *, void(*)(const void *, size_t, size_t))) block_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); block_destruct(block); void *vA2 = vA; block = block_loadFromBinaryRepresentation(&vA2, flower); rootSegment = segment_getReverse(block_getInstance(block, rootInstanceName)); leaf1Segment = block_getInstance(block, leaf1InstanceName); leaf2Segment = segment_getReverse(block_getInstance(block, leaf2InstanceName)); free(vA); nestedTest = 1; testBlock_getName(testCase); testBlock_getOrientation(testCase); testBlock_getReverse(testCase); testBlock_getLength(testCase); testBlock_getFlower(testCase); testBlock_getLeftEnd(testCase); testBlock_getRightEnd(testCase); testBlock_getSetRootInstance(testCase); testBlock_getInstanceNumber(testCase); testBlock_getInstance(testCase); testBlock_getFirst(testCase); testBlock_instanceIterator(testCase); testBlock_makeNewickString(testCase); testBlock_getChain(testCase); testBlock_getSegmentForEvent(testCase); nestedTest = 0; cactusBlockTestTeardown(); }
void testBlock_getInstance(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getInstance(block, segment_getName(rootSegment)) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf1Segment)) == leaf1Segment); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf2Segment)) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(rootSegment)) == rootSegment); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf1Segment)) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf2Segment)) == leaf2Segment); cactusBlockTestTeardown(); }
void testBlock_instanceIterator(CuTest* testCase) { cactusBlockTestSetup(); Block_InstanceIterator *iterator; iterator = block_getInstanceIterator(block); CuAssertTrue(testCase, iterator != NULL); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getNext(iterator) == leaf1Segment); Block_InstanceIterator *iterator2 = block_copyInstanceIterator(iterator); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getNext(iterator) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getPrevious(iterator) == leaf1Segment); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getPrevious(iterator) == NULL); CuAssertTrue(testCase, block_getNext(iterator2) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getNext(iterator2) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator2) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getPrevious(iterator2) == leaf1Segment); CuAssertTrue(testCase, block_getPrevious(iterator2) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getPrevious(iterator2) == NULL); block_destructInstanceIterator(iterator); block_destructInstanceIterator(iterator2); iterator = block_getInstanceIterator(block_getReverse(block)); CuAssertTrue(testCase, block_getNext(iterator) == rootSegment); CuAssertTrue(testCase, block_getNext(iterator) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getNext(iterator) == leaf2Segment); CuAssertTrue(testCase, block_getNext(iterator) == NULL); CuAssertTrue(testCase, block_getPrevious(iterator) == leaf2Segment); CuAssertTrue(testCase, block_getPrevious(iterator) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getPrevious(iterator) == rootSegment); CuAssertTrue(testCase, block_getPrevious(iterator) == NULL); block_destructInstanceIterator(iterator); cactusBlockTestTeardown(); }
static void getMaximalHaplotypePathsP3(Segment *segment, stList *maximalHaplotypePath, stSortedSet *segmentSet, stList *eventStrings) { stList_append(maximalHaplotypePath, segment); assert(stSortedSet_search(segmentSet, segment) == NULL); assert(stSortedSet_search(segmentSet, segment_getReverse(segment)) == NULL); stSortedSet_insert(segmentSet, segment); Cap *_3Cap = segment_get3Cap(segment); if (trueAdjacency(_3Cap, eventStrings)) { //Continue on.. Segment *otherSegment = getAdjacentCapsSegment(_3Cap); if (otherSegment != NULL) { getMaximalHaplotypePathsP3(otherSegment, maximalHaplotypePath, segmentSet, eventStrings); } } }
stHash *buildSegmentToContigPathHash(stList *maximalHaplotypePaths) { stHash *segmentToMaximalHaplotypePathHash = stHash_construct(); for (int64_t i = 0; i < stList_length(maximalHaplotypePaths); i++) { stList *maximalHaplotypePath = stList_get(maximalHaplotypePaths, i); assert(stList_length(maximalHaplotypePath) > 0); for (int64_t j = 0; j < stList_length(maximalHaplotypePath); j++) { Segment *segment = stList_get(maximalHaplotypePath, j); assert(stHash_search(segmentToMaximalHaplotypePathHash, segment) == NULL); assert(stHash_search(segmentToMaximalHaplotypePathHash, segment_getReverse(segment)) == NULL); stHash_insert(segmentToMaximalHaplotypePathHash, segment, maximalHaplotypePath); } } return segmentToMaximalHaplotypePathHash; }
static int64_t getBoundingNs(Cap *cap) { assert(cap != NULL); Segment *segment = getCapsSegment(cap); if (segment == NULL) { return 0; } Cap *_5TerminalCap = getTerminalCap(segment_get5Cap(segment)); Cap *_3TerminalCap = getTerminalCap(segment_get3Cap(segment)); (void)_3TerminalCap; assert(_5TerminalCap != NULL); assert(_3TerminalCap != NULL); //return 0; if (cap_getName(_5TerminalCap) == cap_getName(cap)) { return getBoundingNsP(segment); } else { assert(cap_getName(_3TerminalCap) == cap_getName(cap)); return getBoundingNsP(segment_getReverse(segment)); } }
static bool duplicated(Segment *segment) { Sequence *sequence = segment_getSequence(segment); assert(sequence != NULL); MetaSequence *metaSequence = sequence_getMetaSequence(sequence); Block *block = segment_getBlock(segment); Block_InstanceIterator *it = block_getInstanceIterator(block); Segment *segment2; while((segment2 = block_getNext(it)) != NULL) { if(segment != segment2) { assert(segment != segment_getReverse(segment2)); Sequence *sequence2 = segment_getSequence(segment2); if(sequence2 != NULL && sequence_getMetaSequence(sequence2) == metaSequence) { block_destructInstanceIterator(it); return 1; } } } block_destructInstanceIterator(it); return 0; }
static void getMaximalHaplotypePathsP(Flower *flower, stList *maximalHaplotypePaths, stSortedSet *segmentSet, const char *eventString, stList *eventStrings) { /* * Iterate through the segments in this flower. */ Flower_SegmentIterator *segmentIt = flower_getSegmentIterator(flower); Segment *segment; while ((segment = flower_getNextSegment(segmentIt)) != NULL) { if (stSortedSet_search(segmentSet, segment) == NULL && stSortedSet_search(segmentSet, segment_getReverse(segment)) == NULL) { //Check we haven't yet seen this segment if (strcmp(event_getHeader(segment_getEvent(segment)), eventString) == 0) { //Check if the segment is in the assembly if (hasCapInEvents(cap_getEnd(segment_get5Cap(segment)), eventStrings)) { //Is a block in a haplotype segment assert(hasCapInEvents(cap_getEnd(segment_get3Cap(segment)), eventStrings)); //isHaplotypeEnd(cap_getEnd(segment_get3Cap(segment)))); stList *maximalHaplotypePath = stList_construct(); stList_append(maximalHaplotypePaths, maximalHaplotypePath); getMaximalHaplotypePathsP2(segment, maximalHaplotypePath, segmentSet, eventStrings); } else { assert(!hasCapInEvents(cap_getEnd(segment_get3Cap(segment)), eventStrings));//assert(!isHaplotypeEnd(cap_getEnd(segment_get3Cap(segment)))); } } } } flower_destructSegmentIterator(segmentIt); /* * Now recurse on the contained flowers. */ Flower_GroupIterator *groupIt = flower_getGroupIterator(flower); Group *group; while ((group = flower_getNextGroup(groupIt)) != NULL) { if (group_getNestedFlower(group) != NULL) { getMaximalHaplotypePathsP(group_getNestedFlower(group), maximalHaplotypePaths, segmentSet, eventString, eventStrings); } } flower_destructGroupIterator(groupIt); }
static void getOrderedSegmentsP(Flower *flower, stSortedSet *segments) { Flower_SegmentIterator *segmentIt = flower_getSegmentIterator(flower); Segment *segment; while ((segment = flower_getNextSegment(segmentIt)) != NULL) { if (!segment_getStrand(segment)) { segment = segment_getReverse(segment); } assert(stSortedSet_search(segments, segment) == NULL); stSortedSet_insert(segments, segment); } flower_destructSegmentIterator(segmentIt); //Recurse over the flowers Flower_GroupIterator *groupIt = flower_getGroupIterator(flower); Group *group; while ((group = flower_getNextGroup(groupIt)) != NULL) { if (group_getNestedFlower(group) != NULL) { getOrderedSegmentsP(group_getNestedFlower(group), segments); } } flower_destructGroupIterator(groupIt); }
Segment *block_getInstanceP(Block *block, Segment *connectedSegment) { return block_getOrientation(block) || connectedSegment == NULL ? connectedSegment : segment_getReverse(connectedSegment); }
void testCap_getSegment(CuTest* testCase) { cactusCapTestSetup(); Block *block = block_construct(2, flower); Segment *segment = segment_construct(block, rootEvent); CuAssertTrue(testCase, cap_getSegment(segment_get5Cap(segment)) == segment); CuAssertTrue(testCase, cap_getSegment(segment_get3Cap(segment)) == segment); CuAssertTrue(testCase, cap_getOrientation(segment_get5Cap(segment)) == segment_getOrientation(segment)); CuAssertTrue(testCase, cap_getOrientation(segment_get3Cap(segment)) == segment_getOrientation(segment)); CuAssertTrue(testCase, cap_getSegment(cap_getReverse(segment_get5Cap(segment))) == segment_getReverse(segment)); CuAssertTrue(testCase, cap_getSegment(cap_getReverse(segment_get3Cap(segment))) == segment_getReverse(segment)); cactusCapTestTeardown(); }
static stHash *getScaffoldPathsP(stList *haplotypePaths, stHash *haplotypePathToScaffoldPathHash, stList *haplotypeEventStrings, stList *contaminationEventStrings, CapCodeParameters *capCodeParameters) { stHash *haplotypeToMaximalHaplotypeLengthHash = buildContigPathToContigPathLengthHash(haplotypePaths); stHash *segmentToMaximalHaplotypePathHash = buildSegmentToContigPathHash(haplotypePaths); for (int64_t i = 0; i < stList_length(haplotypePaths); i++) { stSortedSet *bucket = stSortedSet_construct(); stHash_insert(haplotypePathToScaffoldPathHash, stList_get(haplotypePaths, i), bucket); stSortedSet_insert(bucket, stList_get(haplotypePaths, i)); } for (int64_t i = 0; i < stList_length(haplotypePaths); i++) { stList *haplotypePath = stList_get(haplotypePaths, i); assert(stList_length(haplotypePath) > 0); Segment *_5Segment = stList_get(haplotypePath, 0); if (!segment_getStrand(_5Segment)) { _5Segment = segment_getReverse(stList_get(haplotypePath, stList_length(haplotypePath) - 1)); } assert(segment_getStrand(_5Segment)); if (getAdjacentCapsSegment(segment_get5Cap(_5Segment)) != NULL) { assert(!trueAdjacency(segment_get5Cap(_5Segment), haplotypeEventStrings)); } int64_t insertLength; int64_t deleteLength; Cap *otherCap; enum CapCode _5CapCode = getCapCode(segment_get5Cap(_5Segment), &otherCap, haplotypeEventStrings, contaminationEventStrings, &insertLength, &deleteLength, capCodeParameters); if (_5CapCode == SCAFFOLD_GAP || _5CapCode == AMBIGUITY_GAP) { assert(stHash_search(haplotypeToMaximalHaplotypeLengthHash, haplotypePath) != NULL); int64_t j = stIntTuple_get(stHash_search(haplotypeToMaximalHaplotypeLengthHash, haplotypePath), 0); Segment *adjacentSegment = getAdjacentCapsSegment(segment_get5Cap(_5Segment)); assert(adjacentSegment != NULL); while (!hasCapInEvents(cap_getEnd(segment_get5Cap(adjacentSegment)), haplotypeEventStrings)) { //is not a haplotype end adjacentSegment = getAdjacentCapsSegment(segment_get5Cap(adjacentSegment)); assert(adjacentSegment != NULL); } assert(adjacentSegment != NULL); assert(hasCapInEvents(cap_getEnd(segment_get5Cap(adjacentSegment)), haplotypeEventStrings)); //is a haplotype end stList *adjacentHaplotypePath = stHash_search(segmentToMaximalHaplotypePathHash, adjacentSegment); if (adjacentHaplotypePath == NULL) { adjacentHaplotypePath = stHash_search(segmentToMaximalHaplotypePathHash, segment_getReverse( adjacentSegment)); } assert(adjacentHaplotypePath != NULL); assert(adjacentHaplotypePath != haplotypePath); assert(stHash_search(haplotypeToMaximalHaplotypeLengthHash, adjacentHaplotypePath) != NULL); int64_t k = stIntTuple_get(stHash_search(haplotypeToMaximalHaplotypeLengthHash, adjacentHaplotypePath), 0); //Now merge the buckets and make new int tuples.. stSortedSet *bucket1 = stHash_search(haplotypePathToScaffoldPathHash, haplotypePath); stSortedSet *bucket2 = stHash_search(haplotypePathToScaffoldPathHash, adjacentHaplotypePath); assert(bucket1 != NULL); assert(bucket2 != NULL); assert(bucket1 != bucket2); stSortedSet *bucket3 = stSortedSet_getUnion(bucket1, bucket2); stSortedSetIterator *bucketIt = stSortedSet_getIterator(bucket3); stList *l; while ((l = stSortedSet_getNext(bucketIt)) != NULL) { //Do the bucket first assert(stHash_search(haplotypePathToScaffoldPathHash, l) == bucket1 || stHash_search(haplotypePathToScaffoldPathHash, l) == bucket2); stHash_remove(haplotypePathToScaffoldPathHash, l); stHash_insert(haplotypePathToScaffoldPathHash, l, bucket3); //Now the length stIntTuple *m = stHash_remove(haplotypeToMaximalHaplotypeLengthHash, l); assert(m != NULL); assert(stIntTuple_get(m, 0) == j || stIntTuple_get(m, 0) == k); stHash_insert(haplotypeToMaximalHaplotypeLengthHash, l, stIntTuple_construct1( j + k)); stIntTuple_destruct(m); } assert(stHash_search(haplotypePathToScaffoldPathHash, haplotypePath) == bucket3); assert(stHash_search(haplotypePathToScaffoldPathHash, adjacentHaplotypePath) == bucket3); stSortedSet_destructIterator(bucketIt); } } stHash_destruct(segmentToMaximalHaplotypePathHash); return haplotypeToMaximalHaplotypeLengthHash; }