Skip to content
BitVecAlignmentScore

BitVecAlignmentScore

Description

Calculate alignment score between two bitvectors. Used in bioinformatics-style sequence alignment with match/mismatch scoring.

Parameters

Name Direction Description
bv1 in First bitvector
bv2 in Second bitvector
match in Score for matching bits
mismatch in Score for mismatching bits

Usage example (from documentation)

  int score = BitVecAlignmentScore(&seq1, &seq2, 2, -1);

Success

Returns the total alignment score computed as match * #matches + mismatch * #mismatches over the overlapping prefix of the two operands. Neither operand is modified.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    int BitVecAlignmentScore(BitVec *bv1, BitVec *bv2, int match, int mismatch) {
        ValidateBitVec(bv1);
        ValidateBitVec(bv2);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecAlignmentScore basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
    
        int score = BitVecAlignmentScore(&bv1, &bv2, 2, -1);
        result    = result && (score == 6); // 3 matches * 2
        BitVecPush(&bv2, false);
    
        score  = BitVecAlignmentScore(&bv1, &bv2, 2, -1);
        result = result && (score == -3); // 3 mismatches * -1
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecAlignmentScore edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test empty bitvectors
        int score = BitVecAlignmentScore(&bv1, &bv2, 1, -1);
        result    = result && (score == 0);
        BitVecPush(&bv2, false);
    
        score  = BitVecAlignmentScore(&bv1, &bv2, 1, -1);
        result = result && (score == 2); // 2 matches
        double correlation = BitVecCorrelation(&bv1, &bv2);
        double entropy1    = BitVecEntropy(&bv1);
        int    align_score = BitVecAlignmentScore(&bv1, &bv2, 1, -1);
        u64    best_align  = BitVecBestAlignment(&bv1, &bv2);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecAlignmentScore(NULL, bv2, 1, -1) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecAlignmentScore(NULL, &bv2, 1, -1);
        BitVecDeinit(&bv2);
        DefaultAllocatorDeinit(&alloc);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecAlignmentScore(bv1, NULL, 1, -1) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecAlignmentScore(&bv1, NULL, 1, -1);
        BitVecDeinit(&bv1);
        DefaultAllocatorDeinit(&alloc);
Last updated on