File: ProbabilityDistanceTest.cpp

package info (click to toggle)
snap-aligner 2.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,648 kB
  • sloc: cpp: 41,013; ansic: 5,239; python: 227; makefile: 85; sh: 27
file content (70 lines) | stat: -rw-r--r-- 2,357 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "stdafx.h"
#include "Compat.h"
#include "TestLib.h"
#include "ProbabilityDistance.h"

// Test fixture for all the ProbabilityDistance tests
struct ProbabilityDistanceTest {
    ProbabilityDistance dist;
    double prob;
    
    ProbabilityDistanceTest(): dist(0.1, 0.01, 0.2) {}
};


TEST_F(ProbabilityDistanceTest, "basic probabilities") {
    dist.compute("A", "A", "I", 1, 0, 0, &prob);
    ASSERT_NEAR(0.9, prob);

    dist.compute("A", "C", "I", 1, 0, 0, &prob);
    ASSERT_NEAR(0.1, prob);

    char quality10[2] = {43, 0};
    dist.compute("A", "C", quality10, 1, 0, 0, &prob);
    ASSERT_NEAR(0.19, prob);   // 1 - (1 - 0.9) * (1 - 0.9)

    // Check that allowing a shift at the start doesn't change it
    dist.compute("A", "A", "I", 1, 1, 2, &prob);
    ASSERT_NEAR(0.9, prob);

    dist.compute("A", "C", "I", 1, 1, 2, &prob);
    ASSERT_NEAR(0.1, prob);

    dist.compute("A", "C", quality10, 1, 1, 2, &prob);
    ASSERT_NEAR(0.19, prob);   // 1 - (1 - 0.9) * (1 - 0.9)

    dist.compute("AAAAA", "AAAAA", "IIIII", 5, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 5), prob);

    dist.compute("AAAAA", "AACAA", "IIIII", 5, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 4) * 0.1, prob);
}


TEST_F(ProbabilityDistanceTest, "indels") {
    dist.compute("ACGTA", "ACGGTA", "IIIIII", 6, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 5) * 0.01, prob);

    // Here it's better to count things as two substitutions than an indel and two mismatches
    dist.compute("ACGTA", "ACTA", "IIII", 4, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 2) * pow(0.1, 2), prob);

    dist.compute("ACGTACGT", "ACGTTACGT", "IIIIIIIII", 9, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 8) * 0.01, prob);

    dist.compute("ACGTACGT", "ACGACGT", "IIIIIII", 7, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 7) * 0.01, prob);

    dist.compute("ACGTACGT", "ACTACGT", "IIIIIII", 7, 0, 2, &prob);
    ASSERT_NEAR(pow(0.9, 7) * 0.01, prob);

    // Here we can start at shift 1 and get a better probability with substitutions than indels
    dist.compute("ACGTACGT", "ACTACGT", "IIIIIII", 7, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 5) * pow(0.1, 2), prob);

    dist.compute("ACGTACGT", "ACGTTTACGT", "IIIIIIIIII", 10, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 8) * 0.01 * 0.2, prob);

    dist.compute("ACGTTTACGT", "ACGTACGT", "IIIIIIII", 8, 1, 2, &prob);
    ASSERT_NEAR(pow(0.9, 8) * 0.01 * 0.2, prob);
}