File: LibraryTypeTests.cpp

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (166 lines) | stat: -rw-r--r-- 9,612 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
SCENARIO("Library types are encoded/decoded properly") {

    GIVEN("A collection of library formats") {
        std::unordered_map<std::string, LibraryFormat> fm =
        {{"U", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::U)},
            {"SF", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::S)},
            {"SR", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::A)},
            {"IU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::U)},
            {"ISF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::S)},
            {"ISR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::A)},
            {"OU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::U)},
            {"OSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::S)},
            {"OSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::A)},
            {"MU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::U)},
            {"MSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::S)},
            {"MSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::A)}};

        for (auto& kv : fm) {
            WHEN("type is " + kv.first) {
                uint8_t id = kv.second.formatID();
                THEN("decodes as " + kv.first) {
                    REQUIRE(kv.second == LibraryFormat::formatFromID(id));
                }
            }
        }
    }
}


SCENARIO("Paired-end library types have proper compatibility") {

    using salmon::utils::compatibleHit;
    GIVEN("A series of observed [paired-end] library formats") {
        std::unordered_map<std::string, LibraryFormat> refFM =
        {{"U", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::U)},
            {"SF", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::S)},
            {"SR", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::A)},
            {"IU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::U)},
            {"ISF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::S)},
            {"ISR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::A)},
            {"OU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::U)},
            {"OSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::S)},
            {"OSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::A)},
            {"MU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::U)},
            {"MSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::S)},
            {"MSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::A)}};

        std::vector<std::string> testFormats{"ISF", "ISR",
                                             "OSF", "OSR", "MSF", "MSR"};

        for (auto kv : refFM) {
            auto& expectedName = kv.first;
            LibraryFormat expected(kv.second);
            for (auto ok : testFormats) {
                auto& observedName = ok;
                auto it = refFM.find(observedName);
                LibraryFormat observed(it->second);
                WHEN("expected is " + expectedName + " and observed is " + observedName) {
                    THEN("compatibilty should be") {
                        if (expectedName == observedName) {
                            REQUIRE(compatibleHit(expected, observed));
                        } else if (expectedName == "IU" and
                                (observedName == "ISF" or observedName == "ISR")) {
                            REQUIRE(compatibleHit(expected, observed));
                        } else if (expectedName == "OU" and
                                (observedName == "OSF" or observedName == "OSR")) {
                            REQUIRE(compatibleHit(expected, observed));
                        } else if (expectedName == "MU" and
                                (observedName == "MSF" or observedName == "MSR")) {
                            REQUIRE(compatibleHit(expected, observed));
                        } else {
                            REQUIRE(!compatibleHit(expected, observed));
                        }
                    }
                }
            }
        }
    }
}



SCENARIO("Single-end library types have proper compatibility") {

    using salmon::utils::compatibleHit;
    using rapmap::utils::MateStatus;

    GIVEN("A series of observed [single-end] library formats") {
        std::unordered_map<std::string, LibraryFormat> refFM =
        {{"U", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::U)},
            {"SF", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::S)},
            {"SR", LibraryFormat(ReadType::SINGLE_END, ReadOrientation::NONE, ReadStrandedness::A)},
            {"IU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::U)},
            {"ISF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::S)},
            {"ISR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::TOWARD, ReadStrandedness::A)},
            {"OU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::U)},
            {"OSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::S)},
            {"OSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::AWAY, ReadStrandedness::A)},
            {"MU", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::U)},
            {"MSF", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::S)},
            {"MSR", LibraryFormat(ReadType::PAIRED_END, ReadOrientation::SAME, ReadStrandedness::A)}};

        std::vector<std::string> testFormats{"SF", "SR"};

        int32_t start{0};
        std::vector<bool> isFwd({true, false});
        std::vector<MateStatus> ms({MateStatus::PAIRED_END_LEFT,
                                    MateStatus::PAIRED_END_RIGHT,
                                    //MateStatus::PAIRED_END_PAIRED,
                                    MateStatus::SINGLE_END});

        for (auto kv : refFM) {
            auto& expectedName = kv.first;
            LibraryFormat expected(kv.second);

            for (auto fwd : isFwd) {
                for (auto s : ms) {
                    std::string observedName = ((fwd) ? "SF" : "SR");
                    if (s == MateStatus::PAIRED_END_LEFT) {
                        observedName += " left orphan";
                    } else if (s == MateStatus::PAIRED_END_RIGHT) {
                        observedName += " right orphan";
                    } else if (s == MateStatus::SINGLE_END) {
                        observedName += " single end";
                    } else {
                        observedName += " should not happen!";
                    }

                    WHEN("expected is " + expectedName + " and observed is " + observedName) {
                        THEN("compatibility should be") {
                            /*
                            if ((expected.type == ReadType::PAIRED_END) and
                                (s == MateStatus::SINGLE_END)) {
                                REQUIRE(!compatibleHit(expected, start, fwd, s));
                            } else
                            */
                            if (expected.strandedness == ReadStrandedness::U) {
                                REQUIRE(compatibleHit(expected, start, fwd, s));
                            } else if ((expected.strandedness == ReadStrandedness::S and
                                        expected.orientation != ReadOrientation::SAME) and
                                    ((fwd and s == MateStatus::SINGLE_END) or
                                     (fwd and s == MateStatus::PAIRED_END_LEFT) or
                                     (!fwd and s == MateStatus::PAIRED_END_RIGHT))) {
                                REQUIRE(compatibleHit(expected, start, fwd, s));
                            } else if ((expected.strandedness == ReadStrandedness::A and
                                        expected.orientation != ReadOrientation::SAME) and
                                    ((!fwd and s == MateStatus::SINGLE_END) or
                                     (!fwd and s == MateStatus::PAIRED_END_LEFT) or
                                     (fwd and s == MateStatus::PAIRED_END_RIGHT))) {
                                REQUIRE(compatibleHit(expected, start, fwd, s));
                            } else if (expected.orientation  == ReadOrientation::SAME and
                                      ((expected.strandedness == ReadStrandedness::S and fwd) or
                                       (expected.strandedness == ReadStrandedness::A and !fwd))) {
                                REQUIRE(compatibleHit(expected, start, fwd, s));
                            } else {
                                REQUIRE(!compatibleHit(expected, start, fwd, s));
                            }
                        }
                    }
                }
            }
        }
    }
}