Ejemplo n.º 1
0
static void setAdjacencyLengthsAndRecoverNewCapsAndBrokenAdjacencies(Cap *cap, stList *recoveredCaps) {
    /*
     * Sets the coordinates of the caps to be equal to the length of the adjacency sequence between them.
     * Used to build the reference sequence bottom up.
     *
     * One complexity is that a reference thread between the two caps
     * in each flower f may be broken into two in the children of f.
     * Therefore, for each flower f first identify attached stub ends present in the children of f that are
     * not present in f and copy them into f, reattaching the reference caps as needed.
     */
    while (1) {
        Cap *adjacentCap = cap_getAdjacency(cap);
        assert(adjacentCap != NULL);
        assert(cap_getCoordinate(cap) == INT64_MAX);
        assert(cap_getCoordinate(adjacentCap) == INT64_MAX);
        assert(cap_getStrand(cap) == cap_getStrand(adjacentCap));
        assert(cap_getSide(cap) != cap_getSide(adjacentCap));
        Group *group = end_getGroup(cap_getEnd(cap));
        assert(group != NULL);
        if (!group_isLeaf(group)) { //Adjacency is not terminal, so establish its sequence.
            Flower *nestedFlower = group_getNestedFlower(group);
            Cap *nestedCap = flower_getCap(nestedFlower, cap_getName(cap));
            assert(nestedCap != NULL);
            Cap *nestedAdjacentCap = flower_getCap(nestedFlower, cap_getName(adjacentCap));
            assert(nestedAdjacentCap != NULL);
            Cap *breakerCap;
            int64_t adjacencyLength = traceThreadLength(nestedCap, &breakerCap);
            assert(cap_getOrientation(nestedAdjacentCap));
            if (cap_getPositiveOrientation(breakerCap) != nestedAdjacentCap) { //The thread is broken at the lower level.
                //Copy cap into higher level graph.
                breakerCap = copyCapToParent(breakerCap, recoveredCaps);
                assert(cap_getSide(breakerCap));
                cap_makeAdjacent(cap, breakerCap);
                setAdjacencyLength(cap, breakerCap, adjacencyLength);
                adjacencyLength = traceThreadLength(nestedAdjacentCap, &breakerCap);
                assert(cap_getPositiveOrientation(breakerCap) != cap);
                breakerCap = copyCapToParent(breakerCap, recoveredCaps);
                assert(!cap_getSide(breakerCap));
                cap_makeAdjacent(breakerCap, adjacentCap);
                setAdjacencyLength(adjacentCap, breakerCap, adjacencyLength);
            } else { //The thread is not broken at the lower level
                setAdjacencyLength(cap, adjacentCap, adjacencyLength);
            }
        } else {
            //Set the coordinates of the caps to the adjacency size
            setAdjacencyLength(cap, adjacentCap, 0);
        }
        if ((cap = cap_getOtherSegmentCap(adjacentCap)) == NULL) {
            break;
        }
    }
}
Ejemplo n.º 2
0
void testCap_getTopCap(CuTest* testCase) {
    cactusCapTestSetup();
    End *end1 = end_construct(0, flower);
    End *end2 = end_construct(0, flower);
    End *end3 = end_construct(0, flower);
    Event *intermediateEvent = event_construct4(NULL, 0.0, rootEvent, leafEvent, eventTree);

    Cap *cap1T = cap_construct(end1, rootEvent);
    Cap *cap1I = cap_construct(end1, intermediateEvent);
    Cap *cap1L1 = cap_construct(end1, leafEvent);
    Cap *cap1L2 = cap_construct(end1, leafEvent);
    cap_makeParentAndChild(cap1I, cap1L1);
    cap_makeParentAndChild(cap1I, cap1L2);
    cap_makeParentAndChild(cap1T, cap1I);
    end_setRootInstance(end1, cap1T);
    assert(end_getRootInstance(end1) == cap1T);

    CuAssertTrue(testCase, cap_getTopCap(cap1L1) == NULL);
    CuAssertTrue(testCase, cap_getTopCap(cap_getReverse(cap1L1)) == NULL);
    CuAssertTrue(testCase, cap_getTopCap(cap1L2) == NULL);
    CuAssertTrue(testCase, cap_getTopCap(cap1I) == NULL);

    Cap *cap2T = cap_construct(end2, rootEvent);
    Cap *cap2L = cap_construct(end2, leafEvent);
    cap_makeParentAndChild(cap2T, cap2L);
    end_setRootInstance(end2, cap2T);
    cap_makeAdjacent(cap1L1, cap2L);

    CuAssertTrue(testCase, cap_getTopCap(cap1L1) == cap1T);
    CuAssertTrue(testCase, cap_getTopCap(cap_getReverse(cap1L1)) == cap_getReverse(cap1T));
    CuAssertTrue(testCase, cap_getTopCap(cap1I) == NULL);

    Cap *cap3T = cap_construct(end3, rootEvent);
    Cap *cap3I = cap_construct(end3, intermediateEvent);
    cap_makeParentAndChild(cap3T, cap3I);
    end_setRootInstance(end3, cap3T);
    cap_makeAdjacent(cap1I, cap3I);
    cap_makeAdjacent(cap1T, cap3T);

    CuAssertTrue(testCase, cap_getTopCap(cap1L1) == cap1I);
    CuAssertTrue(testCase, cap_getTopCap(cap_getReverse(cap1L1)) == cap_getReverse(cap1I));
    CuAssertTrue(testCase, cap_getTopCap(cap1I) == cap1T);
    CuAssertTrue(testCase, cap_getTopCap(cap_getReverse(cap1I)) == cap_getReverse(cap1T));

    CuAssertTrue(testCase, cap_getTopCap(cap1T) == NULL);

    cactusCapTestTeardown();
}
Ejemplo n.º 3
0
static void recoverBrokenAdjacencies(Flower *flower, stList *recoveredCaps, Name referenceEventName) {
    /*
     * Find reference intervals that are book-ended by stubs created in a child flower.
     */
    Flower_GroupIterator *groupIt = flower_getGroupIterator(flower);
    Group *group;
    while((group = flower_getNextGroup(groupIt)) != NULL) {
        Flower *nestedFlower;
        if((nestedFlower = group_getNestedFlower(group)) != NULL) {
            Flower_EndIterator *endIt = flower_getEndIterator(nestedFlower);
            End *childEnd;
            while((childEnd = flower_getNextEnd(endIt)) != NULL) {
                if(end_isStubEnd(childEnd) && flower_getEnd(flower, end_getName(childEnd)) == NULL) { //We have a thread we need to promote
                    Cap *childCap = getCapForReferenceEvent(childEnd, referenceEventName); //The cap in the reference
                    assert(childCap != NULL);
                    assert(!end_isAttached(childEnd));
                    childCap = cap_getStrand(childCap) ? childCap : cap_getReverse(childCap);
                    if (!cap_getSide(childCap)) {
                        Cap *adjacentChildCap = NULL;
                        int64_t adjacencyLength = traceThreadLength(childCap, &adjacentChildCap);
                        Cap *cap = copyCapToParent(childCap, recoveredCaps);
                        assert(adjacentChildCap != NULL);
                        assert(!end_isAttached(cap_getEnd(adjacentChildCap)));
                        assert(!cap_getSide(cap));
                        Cap *adjacentCap = copyCapToParent(adjacentChildCap, recoveredCaps);
                        cap_makeAdjacent(cap, adjacentCap);
                        setAdjacencyLength(cap, adjacentCap, adjacencyLength);
                    }
                }
            }
            flower_destructEndIterator(endIt);
        }
    }
    flower_destructGroupIterator(groupIt);
}
Ejemplo n.º 4
0
void stCaf_addAdjacencies(Flower *flower) {
    //Build a list of caps.
    stList *list = stList_construct();
    Flower_EndIterator *endIterator = flower_getEndIterator(flower);
    End *end;
    while ((end = flower_getNextEnd(endIterator)) != NULL) {
        End_InstanceIterator *instanceIterator = end_getInstanceIterator(end);
        Cap *cap;
        while ((cap = end_getNext(instanceIterator)) != NULL) {
            if (!cap_getStrand(cap)) {
                cap = cap_getReverse(cap);
            }
            stList_append(list, cap);
        }
        end_destructInstanceIterator(instanceIterator);
    }
    flower_destructEndIterator(endIterator);
    assert(stList_length(list) % 2 == 0);
    //Sort the list of caps.
    stList_sort(list, (int(*)(const void *, const void *)) addAdjacenciesPP);
    //Now make the adjacencies.
    for (int64_t i = 1; i < stList_length(list); i += 2) {
        Cap *cap = stList_get(list, i - 1);
        Cap *cap2 = stList_get(list, i);
        cap_makeAdjacent(cap, cap2);
    }
    //Clean up.
    stList_destruct(list);
}
Ejemplo n.º 5
0
void testCap_getBottomAndTopFaceEnd(CuTest* testCase) {
    cactusCapTestSetup();

    End *end1 = end_construct(0, flower);
    Cap *cap1T = cap_construct(end1, rootEvent);
    Cap *cap1L = cap_construct(end1, leafEvent);
    cap_makeParentAndChild(cap1T, cap1L);
    end_setRootInstance(end1, cap1T);

    End *end2 = end_construct(0, flower);
    Cap *cap2T = cap_construct(end2, rootEvent);
    Cap *cap2L = cap_construct(end2, leafEvent);
    cap_makeParentAndChild(cap2T, cap2L);
    end_setRootInstance(end2, cap2T);

    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap1T) == NULL);
    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap1L) == NULL);
    CuAssertTrue(testCase, cap_getTopFaceEnd(cap1T) == NULL);
    CuAssertTrue(testCase, cap_getTopFaceEnd(cap1L) == NULL);

    cap_makeAdjacent(cap1L, cap2L);
    cap_makeAdjacent(cap1T, cap2T);

    //Now make the face
    Face *face = face_construct(flower);
    face_allocateSpace(face, 2);
    face_setTopNode(face, 0, cap1T);
    face_setTopNode(face, 1, cap2T);
    face_setBottomNodeNumber(face, 0, 1);
    face_setBottomNodeNumber(face, 1, 1);
    face_addBottomNode(face, 0, cap1L);
    face_addBottomNode(face, 1, cap2L);

    CuAssertTrue(testCase, cap_getTopFaceEnd(cap1L) == NULL);
    CuAssertTrue(testCase, cap_getTopFaceEnd(cap2L) == NULL);
    FaceEnd *faceEnd1 = cap_getTopFaceEnd(cap1T);
    FaceEnd *faceEnd2 = cap_getTopFaceEnd(cap2T);
    CuAssertTrue(testCase, faceEnd_getTopNode(faceEnd1) == cap1T);
    CuAssertTrue(testCase, faceEnd_getTopNode(faceEnd2) == cap2T);

    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap1T) == NULL);
    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap2T) == NULL);
    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap1L) == faceEnd1);
    CuAssertTrue(testCase, cap_getBottomFaceEnd(cap2L) == faceEnd2);

    cactusCapTestTeardown();
}
Ejemplo n.º 6
0
void testCap_adjacent(CuTest* testCase) {
    cactusCapTestSetup();
    CuAssertTrue(testCase, cap_getAdjacency(leaf1Cap) == NULL);
    CuAssertTrue(testCase, cap_getAdjacency(leaf3Cap) == NULL);
    cap_makeAdjacent(leaf1Cap, leaf3Cap);
    CuAssertTrue(testCase, cap_getAdjacency(leaf1Cap) == cap_getReverse(leaf3Cap));
    CuAssertTrue(testCase, cap_getAdjacency(leaf3Cap) == cap_getReverse(leaf1Cap));
    CuAssertTrue(testCase, cap_getAdjacency(cap_getReverse(leaf1Cap)) == leaf3Cap);
    CuAssertTrue(testCase, cap_getAdjacency(cap_getReverse(leaf3Cap)) == leaf1Cap);
    cactusCapTestTeardown();
}
Ejemplo n.º 7
0
Segment *block_splitP(Segment *segment,
		Block *leftBlock, Block *rightBlock) {
	Segment *leftSegment = segment_getSequence(segment) != NULL
				? segment_construct2(leftBlock, segment_getStart(segment), segment_getStrand(segment), segment_getSequence(segment))
				: segment_construct(leftBlock, segment_getEvent(segment));
				Segment *rightSegment = segment_getSequence(segment) != NULL
				? segment_construct2(rightBlock, segment_getStart(segment) + block_getLength(leftBlock), segment_getStrand(segment), segment_getSequence(segment))
						: segment_construct(rightBlock, segment_getEvent(segment));
	//link together.
	cap_makeAdjacent(segment_get3Cap(leftSegment), segment_get5Cap(rightSegment));
	//update adjacencies.
	Cap *_5Cap = segment_get5Cap(segment);
	Cap *new5Cap = segment_get5Cap(leftSegment);
	Cap *_3Cap = segment_get3Cap(segment);
	Cap *new3Cap = segment_get3Cap(rightSegment);
	if(cap_getAdjacency(_5Cap) != NULL) {
		cap_makeAdjacent(cap_getAdjacency(_5Cap), new5Cap);
	}
	if(cap_getAdjacency(_3Cap) != NULL) {
		cap_makeAdjacent(cap_getAdjacency(_3Cap), new3Cap);
	}
	return leftSegment;
}
Ejemplo n.º 8
0
void processSequence(const char *fastaHeader, const char *string, int64_t length) {
    /*
     * Processes a sequence by adding it to the flower disk.
     */
    End *end1;
    End *end2;
    Cap *cap1;
    Cap *cap2;
    MetaSequence *metaSequence;
    Sequence *sequence;

    //Now put the details in a flower.
    metaSequence = metaSequence_construct(2, length, string, fastaHeader, event_getName(event), cactusDisk);
    sequence = sequence_construct(metaSequence, flower);

    end1 = end_construct2(0, isComplete, flower);
    end2 = end_construct2(1, isComplete, flower);
    cap1 = cap_construct2(end1, 1, 1, sequence);
    cap2 = cap_construct2(end2, length + 2, 1, sequence);
    cap_makeAdjacent(cap1, cap2);
    totalSequenceNumber++;
}