Ejemplo n.º 1
0
void TopSegmentSimpleIteratorTest::createCallBack(Alignment *alignment) {
    Genome *ancGenome = alignment->addRootGenome("Anc0", 0);
    size_t numChildren = 9;
    for (size_t i = 0; i < numChildren; ++i) {
        alignment->addLeafGenome("Leaf" + std::to_string(i), "Anc0", 0.1);
    }
    vector<Sequence::Info> seqVec(1);
    seqVec[0] = Sequence::Info("Sequence", 1000000, 5000, 10000);
    ancGenome->setDimensions(seqVec);

    CuAssertTrue(_testCase, ancGenome->getNumChildren() == numChildren);

    _topSegments.clear();
    for (size_t i = 0; i < ancGenome->getNumTopSegments(); ++i) {
        TopSegmentStruct topSeg;
        topSeg.setRandom();
        topSeg._length = ancGenome->getSequenceLength() / ancGenome->getNumTopSegments();
        topSeg._startPosition = i * topSeg._length;
        _topSegments.push_back(topSeg);
    }

    TopSegmentIteratorPtr tsIt = ancGenome->getTopSegmentIterator(0);
    for (size_t i = 0; not tsIt->atEnd(); tsIt->toRight(), ++i) {
        CuAssertTrue(_testCase, (size_t)tsIt->getTopSegment()->getArrayIndex() == i);
        _topSegments[i].applyTo(tsIt);
    }
}
Ejemplo n.º 2
0
void TopSegmentIsGapTest::createCallBack(Alignment *alignment) {
    size_t numSequences = 3;
    vector<Sequence::Info> seqVec(numSequences);

    BottomSegmentIteratorPtr bi;
    BottomSegmentStruct bs;
    TopSegmentIteratorPtr ti;
    TopSegmentStruct ts;

    Genome *parent1 = alignment->addRootGenome("parent1");
    Genome *child1 = alignment->addLeafGenome("child1", "parent1", 1);

    // set up two genomes.  each with three sequences.  each sequence
    // with 5 segments of length two.  start with segment i in parent
    // aligned with segment i in child.
    for (size_t i = 0; i < numSequences; ++i) {
        string name = "Sequence" + std::to_string(i);
        seqVec[i] = Sequence::Info(name, 10, 5, 5);
    }
    parent1->setDimensions(seqVec);
    child1->setDimensions(seqVec);

    for (bi = parent1->getBottomSegmentIterator(); not bi->atEnd(); bi->toRight()) {
        bs.set(bi->getBottomSegment()->getArrayIndex() * 2, 2);
        bs._children.clear();
        bs._children.push_back(pair<hal_size_t, bool>(bi->getBottomSegment()->getArrayIndex(), false));
        bs.applyTo(bi);
    }

    for (ti = child1->getTopSegmentIterator(); not ti->atEnd(); ti->toRight()) {
        ts.set(ti->getTopSegment()->getArrayIndex() * 2, 2, ti->getTopSegment()->getArrayIndex());
        ts.applyTo(ti);
    }

    // insertion in middle (8th top segment)

    bi = parent1->getBottomSegmentIterator(8);
    ti = child1->getTopSegmentIterator(8);
    assert(bi->getBottomSegment()->getChildIndex(0) == 8 && ti->getTopSegment()->getParentIndex() == 8);
    bi->getBottomSegment()->setChildIndex(0, 9);
    ti->getTopSegment()->setParentIndex(NULL_INDEX);
    ti->toRight();
    ti->getTopSegment()->setParentIndex(8);

    // insertion at begining (10th top segment)

    bi = parent1->getBottomSegmentIterator(10);
    ti = child1->getTopSegmentIterator(10);
    assert(bi->getBottomSegment()->getChildIndex(0) == 10 && ti->getTopSegment()->getParentIndex() == 10);
    bi->getBottomSegment()->setChildIndex(0, 11);
    ti->getTopSegment()->setParentIndex(NULL_INDEX);
    ti->toRight();
    ti->getTopSegment()->setParentIndex(10);

    // just having a null parent is not enough for an insertion
    bi = parent1->getBottomSegmentIterator(2);
    ti = child1->getTopSegmentIterator(2);
    assert(bi->getBottomSegment()->getChildIndex(0) == 2 && ti->getTopSegment()->getParentIndex() == 2);
    ti->getTopSegment()->setParentIndex(NULL_INDEX);
}