Exemplo n.º 1
0
static stList *getRandomPairwiseAlignments() {
    stList *pairwiseAlignments = stList_construct3(0, (void(*)(void *)) destructPairwiseAlignment);
    int64_t randomAlignmentNumber = st_randomInt(0, 10);
    for (int64_t i = 0; i < randomAlignmentNumber; i++) {
        char *contig1 = stString_print("%" PRIi64 "", i);
        char *contig2 = stString_print("%" PRIi64 "", i * 10);
        int64_t start1 = st_randomInt(100000, 1000000);
        int64_t start2 = st_randomInt(100000, 1000000);
        int64_t strand1 = st_random() > 0.5;
        int64_t strand2 = st_random() > 0.5;
        int64_t end1 = start1;
        int64_t end2 = start2;
        struct List *operationList = constructEmptyList(0, NULL);
        while (st_random() > 0.1) {
            int64_t length = st_randomInt(0, 10);
            int64_t type = st_randomInt(0, 3);
            assert(type < 3);
            listAppend(operationList, constructAlignmentOperation(type, length, 0));
            if (type != PAIRWISE_INDEL_Y) {
                end1 += strand1 ? length : -length;
            }
            if (type != PAIRWISE_INDEL_X) {
                end2 += strand2 ? length : -length;
            }
        }
        stList_append(pairwiseAlignments,
                      constructPairwiseAlignment(contig1, start1, end1, strand1, contig2, start2, end2, strand2, 0.0, operationList));
        free(contig1);
        free(contig2);
    }
    return pairwiseAlignments;
}
Exemplo n.º 2
0
// copied from cPecanRealign
struct PairwiseAlignment *convertAlignedPairsToPairwiseAlignment(char *seqName1, char *seqName2, double score,
        int64_t length1, int64_t length2, stList *alignedPairs) {
    //Make pairwise alignment
    int64_t pX = -1, pY = -1, mL = 0;
    //Create an end matched pair, which is used to ensure the alignment has the correct end indels.
    struct List *opList = constructEmptyList(0, (void (*)(void *)) destructAlignmentOperation);
    stList_append(alignedPairs, stIntTuple_construct2(length1, length2));
    for (int64_t i = 0; i < stList_length(alignedPairs); i++) {
        stIntTuple *alignedPair = stList_get(alignedPairs, i);
        int64_t x = stIntTuple_get(alignedPair, 0);
        int64_t y = stIntTuple_get(alignedPair, 1);
        assert(x - pX > 0);
        assert(y - pY > 0);
        if (x - pX > 0 && y - pY > 0) { //This is a hack for filtering
            if (x - pX > 1) { //There is an indel.
                if (mL > 0) {
                    listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                    mL = 0;
                }
                listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_X, x - pX - 1, 0));
            }
            if (y - pY > 1) {
                if (mL > 0) {
                    listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                    mL = 0;
                }
                listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_Y, y - pY - 1, 0));
            }
            mL++;
            pX = x;
            pY = y;
        }
    }
    //Deal with a trailing match, but exclude the final match
    if (mL > 1) {
        listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL - 1, 0));
    }
    stIntTuple_destruct(stList_pop(alignedPairs));
    //Construct the alignment
    struct PairwiseAlignment *pA = constructPairwiseAlignment(seqName1, 0, length1, 1, seqName2, 0, length2, 1, score,
            opList);
    return pA;
}