| 1 |
#include <pbcopper/data/Read.h> |
| 2 |
|
| 3 |
#include <algorithm> |
| 4 |
|
| 5 |
#include <gtest/gtest.h> |
| 6 |
|
| 7 |
#include <pbcopper/data/Clipping.h> |
| 8 |
#include <pbcopper/data/MappedRead.h> |
| 9 |
#include <pbcopper/data/internal/ClippingImpl.h> |
| 10 |
|
| 11 |
using namespace PacBio::Data; |
| 12 |
|
| 13 |
TEST(Data_Read, ClipRead) |
| 14 |
{ |
| 15 |
const std::string seq{"AACCGTTAGC"}; |
| 16 |
const QualityValues quals = QualityValues::FromFastq("0123456789"); |
| 17 |
const SNR snr{0.9, 0.9, 0.9, 0.9}; |
| 18 |
const Position qStart = 500; |
| 19 |
const Position qEnd = 510; |
| 20 |
const std::vector<uint16_t> pw{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; |
| 21 |
const std::vector<uint16_t> ipd{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; |
| 22 |
|
| 23 |
// ClipToQuery(read, 502, 509); |
| 24 |
const size_t clipStart = 502; |
| 25 |
const size_t clipEnd = 509; |
| 26 |
const ClipResult clipResult{2, 502, 509}; |
| 27 |
|
| 28 |
Read read{"name/0/500_510", seq, quals, snr, qStart, qEnd, pw, ipd}; |
| 29 |
internal::ClipRead(read, clipResult, clipStart, clipEnd); |
| 30 |
|
| 31 |
const std::string expectedSeq{"CCGTTAG"}; |
| 32 |
const QualityValues expectedQuals = QualityValues::FromFastq("2345678"); |
| 33 |
const SNR expectedSnr{0.9, 0.9, 0.9, 0.9}; |
| 34 |
const Position expectedQStart = 502; |
| 35 |
const Position expectedQEnd = 509; |
| 36 |
const std::vector<uint16_t> expectedPw{30, 40, 50, 60, 70, 80, 90}; |
| 37 |
const std::vector<uint16_t> expectedIpd{30, 40, 50, 60, 70, 80, 90}; |
| 38 |
|
| 39 |
EXPECT_EQ("name/0/500_510", read.FullName()); |
| 40 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 41 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 42 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 43 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 44 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 45 |
EXPECT_TRUE(read.PulseWidth); |
| 46 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 47 |
EXPECT_TRUE(read.IPD); |
| 48 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 49 |
} |
| 50 |
|
| 51 |
TEST(Data_Read, ClipMappedRead) |
| 52 |
{ |
| 53 |
const std::string seq{"AACCGTTAGC"}; |
| 54 |
const QualityValues quals = QualityValues::FromFastq("0123456789"); |
| 55 |
const SNR snr{0.9, 0.9, 0.9, 0.9}; |
| 56 |
const Position qStart = 500; |
| 57 |
const Position qEnd = 510; |
| 58 |
const std::vector<uint16_t> pw{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; |
| 59 |
const std::vector<uint16_t> ipd{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; |
| 60 |
const Strand strand = Strand::FORWARD; |
| 61 |
const Position tStart = 100; |
| 62 |
const Position tEnd = 111; |
| 63 |
const Cigar cigar{"4=1D2I2D4="}; |
| 64 |
const uint8_t mapQV = 80; |
| 65 |
|
| 66 |
// ClipToReference(read, 102, 107); |
| 67 |
const ClipResult clipResult{2, 502, 507, 102, Cigar{"2=1D2I2D"}}; |
| 68 |
|
| 69 |
MappedRead read{Read{"name/0/500_510", seq, quals, snr, qStart, qEnd, pw, ipd}, |
| 70 |
strand, |
| 71 |
tStart, |
| 72 |
tEnd, |
| 73 |
cigar, |
| 74 |
mapQV}; |
| 75 |
internal::ClipMappedRead(read, clipResult); |
| 76 |
|
| 77 |
const std::string expectedSeq{"CCGTT"}; |
| 78 |
const QualityValues expectedQuals = QualityValues::FromFastq("23456"); |
| 79 |
const SNR expectedSnr{0.9, 0.9, 0.9, 0.9}; |
| 80 |
const Position expectedQStart = 502; |
| 81 |
const Position expectedQEnd = 507; |
| 82 |
const std::vector<uint16_t> expectedPw{30, 40, 50, 60, 70}; |
| 83 |
const std::vector<uint16_t> expectedIpd{30, 40, 50, 60, 70}; |
| 84 |
const Strand expectedStrand = Strand::FORWARD; |
| 85 |
const Position expectedTStart = 102; |
| 86 |
const Position expectedTEnd = 107; |
| 87 |
const Cigar expectedCigar{"2=1D2I2D"}; |
| 88 |
const uint8_t expectedMapQV = 80; |
| 89 |
|
| 90 |
EXPECT_EQ("name/0/500_510", read.FullName()); |
| 91 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 92 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 93 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 94 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 95 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 96 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 97 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 98 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 99 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 100 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 101 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 102 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 103 |
} |
| 104 |
|
| 105 |
TEST(Data_Read, ClipToReferenceOutsideAlignedRegion) |
| 106 |
{ |
| 107 |
const std::string seq{"GATTACA"}; |
| 108 |
const QualityValues quals{"ZZZZZZZ"}; |
| 109 |
const SNR snr{0.9, 0.9, 0.9, 0.9}; |
| 110 |
const Position qStart = 500; |
| 111 |
const Position qEnd = 507; |
| 112 |
const std::vector<uint16_t> pw{10, 20, 30, 40, 50, 60, 70}; |
| 113 |
const std::vector<uint16_t> ipd{10, 20, 30, 40, 50, 60, 70}; |
| 114 |
const Strand strand = Strand::FORWARD; |
| 115 |
const Position tStart = 200; |
| 116 |
const Position tEnd = 207; |
| 117 |
const Cigar cigar{"7="}; |
| 118 |
const uint8_t mapQV = 99; |
| 119 |
|
| 120 |
const std::string expectedSeq; |
| 121 |
const QualityValues expectedQuals{""}; |
| 122 |
const SNR expectedSnr{0.9, 0.9, 0.9, 0.9}; |
| 123 |
const Position expectedQStart = -1; |
| 124 |
const Position expectedQEnd = -1; |
| 125 |
const std::vector<uint16_t> expectedPw{}; |
| 126 |
const std::vector<uint16_t> expectedIpd{}; |
| 127 |
const Strand expectedStrand = Strand::FORWARD; |
| 128 |
const Position expectedTStart = -1; |
| 129 |
const Position expectedTEnd = -1; |
| 130 |
const Cigar expectedCigar{""}; |
| 131 |
const uint8_t expectedMapQV = 255; |
| 132 |
|
| 133 |
auto shouldClipToEmptyRead = [&](Position start, Position end) { |
| 134 |
MappedRead read{Read{"name/0/500_507", seq, quals, snr, qStart, qEnd, pw, ipd}, |
| 135 |
strand, |
| 136 |
tStart, |
| 137 |
tEnd, |
| 138 |
cigar, |
| 139 |
mapQV}; |
| 140 |
|
| 141 |
ClipToReference(read, start, end, true); |
| 142 |
|
| 143 |
EXPECT_EQ("name/0/500_507", read.FullName()); |
| 144 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 145 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 146 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 147 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 148 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 149 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 150 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 151 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 152 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 153 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 154 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 155 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 156 |
}; |
| 157 |
|
| 158 |
{ |
| 159 |
SCOPED_TRACE("clip region is well before alignment start"); |
| 160 |
shouldClipToEmptyRead(0, 50); |
| 161 |
} |
| 162 |
{ |
| 163 |
SCOPED_TRACE("clip region ends at alignment start"); |
| 164 |
shouldClipToEmptyRead(150, 200); |
| 165 |
} |
| 166 |
{ |
| 167 |
SCOPED_TRACE("clip region starts at alignment end"); |
| 168 |
shouldClipToEmptyRead(207, 250); |
| 169 |
} |
| 170 |
{ |
| 171 |
SCOPED_TRACE("clip region starts well after alignment end"); |
| 172 |
shouldClipToEmptyRead(500, 600); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
TEST(Data_Read, MultipleClipsToReference) |
| 177 |
{ |
| 178 |
const std::string seq(1200, 'A'); |
| 179 |
const QualityValues quals{std::string(1200, 'Z')}; |
| 180 |
const SNR snr{0.9, 0.9, 0.9, 0.9}; |
| 181 |
const Position qStart = 0; |
| 182 |
const Position qEnd = 1200; |
| 183 |
const std::vector<uint16_t> pw(1200, 20); |
| 184 |
const std::vector<uint16_t> ipd(1200, 20); |
| 185 |
const Strand strand = Strand::FORWARD; |
| 186 |
const Position tStart = 0; |
| 187 |
const Position tEnd = 1200; |
| 188 |
const Cigar cigar{"1200="}; |
| 189 |
const uint8_t mapQV = 99; |
| 190 |
|
| 191 |
// intial read, aligned to reference: [0, 1200) |
| 192 |
MappedRead read{Read{"name/0/0_1200", seq, quals, snr, qStart, qEnd, pw, ipd}, |
| 193 |
strand, |
| 194 |
tStart, |
| 195 |
tEnd, |
| 196 |
cigar, |
| 197 |
mapQV}; |
| 198 |
|
| 199 |
// clip to reference: [0, 1000) - shrinking from right |
| 200 |
ClipToReference(read, 0, 1000, true); |
| 201 |
|
| 202 |
std::string expectedSeq(1000, 'A'); |
| 203 |
QualityValues expectedQuals{std::string(1000, 'Z')}; |
| 204 |
const SNR expectedSnr{0.9, 0.9, 0.9, 0.9}; |
| 205 |
Position expectedQStart = 0; |
| 206 |
Position expectedQEnd = 1000; |
| 207 |
std::vector<uint16_t> expectedPw(1000, 20); |
| 208 |
std::vector<uint16_t> expectedIpd(1000, 20); |
| 209 |
const Strand expectedStrand = Strand::FORWARD; |
| 210 |
Position expectedTStart = 0; |
| 211 |
Position expectedTEnd = 1000; |
| 212 |
Cigar expectedCigar{"1000="}; |
| 213 |
const uint8_t expectedMapQV = 99; |
| 214 |
|
| 215 |
EXPECT_EQ("name/0/0_1200", read.FullName()); |
| 216 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 217 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 218 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 219 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 220 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 221 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 222 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 223 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 224 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 225 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 226 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 227 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 228 |
|
| 229 |
// clip again, to reference: [100, 1000) - shrinking from left |
| 230 |
ClipToReference(read, 100, 1000, true); |
| 231 |
|
| 232 |
expectedSeq = std::string(900, 'A'); |
| 233 |
expectedQuals = QualityValues{std::string(900, 'Z')}; |
| 234 |
expectedQStart = 100; |
| 235 |
expectedQEnd = 1000; |
| 236 |
expectedPw = std::vector<uint16_t>(900, 20); |
| 237 |
expectedIpd = std::vector<uint16_t>(900, 20); |
| 238 |
expectedTStart = 100; |
| 239 |
expectedTEnd = 1000; |
| 240 |
expectedCigar = Cigar{"900="}; |
| 241 |
|
| 242 |
EXPECT_EQ("name/0/0_1200", read.FullName()); |
| 243 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 244 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 245 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 246 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 247 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 248 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 249 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 250 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 251 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 252 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 253 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 254 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 255 |
|
| 256 |
// clip again, to reference: [200, 800) - shrinking both sides |
| 257 |
ClipToReference(read, 200, 800, true); |
| 258 |
|
| 259 |
expectedSeq = std::string(600, 'A'); |
| 260 |
expectedQuals = QualityValues{std::string(600, 'Z')}; |
| 261 |
expectedQStart = 200; |
| 262 |
expectedQEnd = 800; |
| 263 |
expectedPw = std::vector<uint16_t>(600, 20); |
| 264 |
expectedIpd = std::vector<uint16_t>(600, 20); |
| 265 |
expectedTStart = 200; |
| 266 |
expectedTEnd = 800; |
| 267 |
expectedCigar = Cigar{"600="}; |
| 268 |
|
| 269 |
EXPECT_EQ("name/0/0_1200", read.FullName()); |
| 270 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 271 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 272 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 273 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 274 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 275 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 276 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 277 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 278 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 279 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 280 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 281 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 282 |
} |
| 283 |
|
| 284 |
TEST(Data_Read, MultipleClipsToReference_WithLargeDeletion) |
| 285 |
{ |
| 286 |
const std::string seq(1000, 'A'); |
| 287 |
const QualityValues quals{std::string(1000, 'Z')}; |
| 288 |
const SNR snr{0.9, 0.9, 0.9, 0.9}; |
| 289 |
const Position qStart = 0; |
| 290 |
const Position qEnd = 1000; |
| 291 |
const std::vector<uint16_t> pw(1200, 20); |
| 292 |
const std::vector<uint16_t> ipd(1200, 20); |
| 293 |
const Strand strand = Strand::FORWARD; |
| 294 |
const Position tStart = 0; |
| 295 |
const Position tEnd = 1200; |
| 296 |
const Cigar cigar{"400=200D600="}; |
| 297 |
const uint8_t mapQV = 99; |
| 298 |
|
| 299 |
// intial read, aligned to reference: [0, 1200) |
| 300 |
MappedRead read{Read{"name/0/0_1000", seq, quals, snr, qStart, qEnd, pw, ipd}, |
| 301 |
strand, |
| 302 |
tStart, |
| 303 |
tEnd, |
| 304 |
cigar, |
| 305 |
mapQV}; |
| 306 |
|
| 307 |
// clip to reference: [0, 1000) - shrinking from right |
| 308 |
ClipToReference(read, 0, 1000, true); |
| 309 |
|
| 310 |
std::string expectedSeq(800, 'A'); |
| 311 |
QualityValues expectedQuals{std::string(800, 'Z')}; |
| 312 |
const SNR expectedSnr{0.9, 0.9, 0.9, 0.9}; |
| 313 |
Position expectedQStart = 0; |
| 314 |
Position expectedQEnd = 800; |
| 315 |
std::vector<uint16_t> expectedPw(800, 20); |
| 316 |
std::vector<uint16_t> expectedIpd(800, 20); |
| 317 |
const Strand expectedStrand = Strand::FORWARD; |
| 318 |
Position expectedTStart = 0; |
| 319 |
Position expectedTEnd = 1000; |
| 320 |
Cigar expectedCigar{"400=200D400="}; |
| 321 |
const uint8_t expectedMapQV = 99; |
| 322 |
|
| 323 |
EXPECT_EQ("name/0/0_1000", read.FullName()); |
| 324 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 325 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 326 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 327 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 328 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 329 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 330 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 331 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 332 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 333 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 334 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 335 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 336 |
|
| 337 |
// clip again, to reference: [100, 1000) - shrinking from left |
| 338 |
ClipToReference(read, 100, 1000, true); |
| 339 |
|
| 340 |
expectedSeq = std::string(700, 'A'); |
| 341 |
expectedQuals = QualityValues{std::string(700, 'Z')}; |
| 342 |
expectedQStart = 100; |
| 343 |
expectedQEnd = 800; |
| 344 |
expectedPw = std::vector<uint16_t>(700, 20); |
| 345 |
expectedIpd = std::vector<uint16_t>(700, 20); |
| 346 |
expectedTStart = 100; |
| 347 |
expectedTEnd = 1000; |
| 348 |
expectedCigar = Cigar{"300=200D400="}; |
| 349 |
|
| 350 |
EXPECT_EQ("name/0/0_1000", read.FullName()); |
| 351 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 352 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 353 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 354 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 355 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 356 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 357 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 358 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 359 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 360 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 361 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 362 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 363 |
|
| 364 |
// clip again, to reference: [200, 800) - shrinking both sides |
| 365 |
ClipToReference(read, 200, 800, true); |
| 366 |
|
| 367 |
expectedSeq = std::string(400, 'A'); |
| 368 |
expectedQuals = QualityValues{std::string(400, 'Z')}; |
| 369 |
expectedQStart = 200; |
| 370 |
expectedQEnd = 600; |
| 371 |
expectedPw = std::vector<uint16_t>(400, 20); |
| 372 |
expectedIpd = std::vector<uint16_t>(400, 20); |
| 373 |
expectedTStart = 200; |
| 374 |
expectedTEnd = 800; |
| 375 |
expectedCigar = Cigar{"200=200D200="}; |
| 376 |
|
| 377 |
EXPECT_EQ("name/0/0_1000", read.FullName()); |
| 378 |
EXPECT_EQ(expectedSeq, read.Seq); |
| 379 |
EXPECT_EQ(expectedQuals, read.Qualities); |
| 380 |
EXPECT_EQ(expectedQStart, read.QueryStart); |
| 381 |
EXPECT_EQ(expectedQEnd, read.QueryEnd); |
| 382 |
EXPECT_EQ(expectedSnr, read.SignalToNoise); |
| 383 |
EXPECT_TRUE(std::equal(expectedPw.cbegin(), expectedPw.cend(), read.PulseWidth->begin())); |
| 384 |
EXPECT_TRUE(std::equal(expectedIpd.cbegin(), expectedIpd.cend(), read.IPD->begin())); |
| 385 |
EXPECT_EQ(expectedStrand, read.Strand); |
| 386 |
EXPECT_EQ(expectedTStart, read.TemplateStart); |
| 387 |
EXPECT_EQ(expectedTEnd, read.TemplateEnd); |
| 388 |
EXPECT_EQ(expectedCigar, read.Cigar); |
| 389 |
EXPECT_EQ(expectedMapQV, read.MapQuality); |
| 390 |
} |
| 391 |
|
| 392 |
TEST(Data_Read, BamRecordFunctions) |
| 393 |
{ |
| 394 |
const Position qStart = 500; |
| 395 |
const Position qEnd = 510; |
| 396 |
const std::string seq{"AACCGTTAGC"}; |
| 397 |
const std::string quals{"?]?]?]?]?*"}; |
| 398 |
const std::vector<uint8_t> frames = {10, 10, 20, 20, 30, 40, 40, 10, 30, 20}; |
| 399 |
|
| 400 |
const std::string seq_rev{"GCTAACGGTT"}; |
| 401 |
const std::string quals_rev{"*?]?]?]?]?"}; |
| 402 |
const std::vector<uint8_t> frames_rev = {20, 30, 10, 40, 40, 30, 20, 20, 10, 10}; |
| 403 |
|
| 404 |
const std::string s1_cigar{"10="}; |
| 405 |
const std::string s2_cigar{"5=3D5="}; |
| 406 |
const std::string s3_cigar{"4=1D2I2D4="}; |
| 407 |
|
| 408 |
{ |
| 409 |
// s1 - FORWARD |
| 410 |
const MappedRead s1{ |
| 411 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 412 |
Strand::FORWARD, 100, Cigar::FromStdString(s1_cigar), 60}; |
| 413 |
|
| 414 |
EXPECT_EQ(Strand::FORWARD, s1.AlignedStrand()); |
| 415 |
EXPECT_EQ(qStart, s1.QueryStart); |
| 416 |
EXPECT_EQ(qEnd, s1.QueryEnd); |
| 417 |
EXPECT_EQ(500, s1.AlignedStart()); |
| 418 |
EXPECT_EQ(510, s1.AlignedEnd()); // 500 + 10= |
| 419 |
EXPECT_EQ(100, s1.ReferenceStart()); |
| 420 |
EXPECT_EQ(110, s1.ReferenceEnd()); // 100 + 10= |
| 421 |
} |
| 422 |
|
| 423 |
{ |
| 424 |
// s1 - REVERSE |
| 425 |
const MappedRead s1_rev{ |
| 426 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 427 |
Strand::REVERSE, 100, Cigar::FromStdString(s1_cigar), 60}; |
| 428 |
|
| 429 |
EXPECT_EQ(Strand::REVERSE, s1_rev.AlignedStrand()); |
| 430 |
EXPECT_EQ(qStart, s1_rev.QueryStart); |
| 431 |
EXPECT_EQ(qEnd, s1_rev.QueryEnd); |
| 432 |
EXPECT_EQ(500, s1_rev.AlignedStart()); |
| 433 |
EXPECT_EQ(510, s1_rev.AlignedEnd()); // 500 + 10= |
| 434 |
EXPECT_EQ(100, s1_rev.ReferenceStart()); |
| 435 |
EXPECT_EQ(110, s1_rev.ReferenceEnd()); // 100 + 10= |
| 436 |
} |
| 437 |
|
| 438 |
{ |
| 439 |
// s2 - FORWARD |
| 440 |
const MappedRead s2{ |
| 441 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 442 |
Strand::FORWARD, 100, Cigar::FromStdString(s2_cigar), 60}; |
| 443 |
|
| 444 |
EXPECT_EQ(Strand::FORWARD, s2.AlignedStrand()); |
| 445 |
EXPECT_EQ(qStart, s2.QueryStart); |
| 446 |
EXPECT_EQ(qEnd, s2.QueryEnd); |
| 447 |
EXPECT_EQ(500, s2.AlignedStart()); |
| 448 |
EXPECT_EQ(510, s2.AlignedEnd()); // 500 + 10= |
| 449 |
EXPECT_EQ(100, s2.ReferenceStart()); |
| 450 |
EXPECT_EQ(113, s2.ReferenceEnd()); // 100 + 10= |
| 451 |
} |
| 452 |
|
| 453 |
{ |
| 454 |
// s2 - REVERSE |
| 455 |
const MappedRead s2_rev{ |
| 456 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 457 |
Strand::REVERSE, 100, Cigar::FromStdString(s2_cigar), 60}; |
| 458 |
|
| 459 |
EXPECT_EQ(Strand::REVERSE, s2_rev.AlignedStrand()); |
| 460 |
EXPECT_EQ(qStart, s2_rev.QueryStart); |
| 461 |
EXPECT_EQ(qEnd, s2_rev.QueryEnd); |
| 462 |
EXPECT_EQ(500, s2_rev.AlignedStart()); |
| 463 |
EXPECT_EQ(510, s2_rev.AlignedEnd()); // 500 + 10= |
| 464 |
EXPECT_EQ(100, s2_rev.ReferenceStart()); |
| 465 |
EXPECT_EQ(113, s2_rev.ReferenceEnd()); // 100 + 10= |
| 466 |
} |
| 467 |
|
| 468 |
{ |
| 469 |
// s3 - FORWARD |
| 470 |
const MappedRead s3{ |
| 471 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 472 |
Strand::FORWARD, 100, Cigar::FromStdString(s3_cigar), 60}; |
| 473 |
|
| 474 |
EXPECT_EQ(Strand::FORWARD, s3.AlignedStrand()); |
| 475 |
EXPECT_EQ(qStart, s3.QueryStart); |
| 476 |
EXPECT_EQ(qEnd, s3.QueryEnd); |
| 477 |
EXPECT_EQ(500, s3.AlignedStart()); |
| 478 |
EXPECT_EQ(510, s3.AlignedEnd()); // 500 + 10= |
| 479 |
EXPECT_EQ(100, s3.ReferenceStart()); |
| 480 |
EXPECT_EQ(111, s3.ReferenceEnd()); // 100 + 10= |
| 481 |
} |
| 482 |
|
| 483 |
{ |
| 484 |
// s3 - REVERSE |
| 485 |
const MappedRead s3_rev{ |
| 486 |
Read{"name/0/500_510", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 487 |
Strand::REVERSE, 100, Cigar::FromStdString(s3_cigar), 60}; |
| 488 |
|
| 489 |
EXPECT_EQ(Strand::REVERSE, s3_rev.AlignedStrand()); |
| 490 |
EXPECT_EQ(qStart, s3_rev.QueryStart); |
| 491 |
EXPECT_EQ(qEnd, s3_rev.QueryEnd); |
| 492 |
EXPECT_EQ(500, s3_rev.AlignedStart()); |
| 493 |
EXPECT_EQ(510, s3_rev.AlignedEnd()); // 500 + 10= |
| 494 |
EXPECT_EQ(100, s3_rev.ReferenceStart()); |
| 495 |
EXPECT_EQ(111, s3_rev.ReferenceEnd()); // 100 + 10= |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
TEST(Data_Read, BamRecordFunctions_Clip) |
| 500 |
{ |
| 501 |
const Position qStart = 500; |
| 502 |
const Position qEnd = 515; |
| 503 |
const std::string seq{"TTAACCGTTAGCAAA"}; |
| 504 |
const std::string quals{"--?]?]?]?]?*+++"}; |
| 505 |
const std::vector<uint8_t> frames = {40, 40, 10, 10, 20, 20, 30, 40, |
| 506 |
40, 10, 30, 20, 10, 10, 10}; |
| 507 |
|
| 508 |
const std::string seq_rev{"TTTGCTAACGGTTAA"}; |
| 509 |
const std::string quals_rev{"+++*?]?]?]?]?--"}; |
| 510 |
const std::vector<uint8_t> frames_rev = {10, 10, 10, 20, 30, 10, 40, 40, |
| 511 |
30, 20, 20, 10, 10, 40, 40}; |
| 512 |
|
| 513 |
const std::string s1_cigar{"2S10=3S"}; |
| 514 |
const std::string s2_cigar{"2S5=3D5=3S"}; |
| 515 |
const std::string s3_cigar{"2S4=1D2I2D4=3S"}; |
| 516 |
|
| 517 |
{ |
| 518 |
// s1 - FORWARD |
| 519 |
const MappedRead s1{ |
| 520 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 521 |
Strand::FORWARD, 100, Cigar::FromStdString(s1_cigar), 60}; |
| 522 |
|
| 523 |
EXPECT_EQ(Strand::FORWARD, s1.AlignedStrand()); |
| 524 |
EXPECT_EQ(qStart, s1.QueryStart); // 500 |
| 525 |
EXPECT_EQ(qEnd, s1.QueryEnd); // QStart + seqLength |
| 526 |
EXPECT_EQ(502, s1.AlignedStart()); // QStart + 2S |
| 527 |
EXPECT_EQ(512, s1.AlignedEnd()); // AStart + 10= |
| 528 |
EXPECT_EQ(100, s1.ReferenceStart()); // 100 |
| 529 |
EXPECT_EQ(110, s1.ReferenceEnd()); // RefStart + 10= |
| 530 |
} |
| 531 |
|
| 532 |
{ |
| 533 |
// s1 - REVERSE |
| 534 |
const MappedRead s1_rev{ |
| 535 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 536 |
Strand::REVERSE, 100, Cigar::FromStdString(s1_cigar), 60}; |
| 537 |
|
| 538 |
EXPECT_EQ(Strand::REVERSE, s1_rev.AlignedStrand()); |
| 539 |
EXPECT_EQ(qStart, s1_rev.QueryStart); // 500 |
| 540 |
EXPECT_EQ(qEnd, s1_rev.QueryEnd); // QStart + seqLength |
| 541 |
EXPECT_EQ(503, s1_rev.AlignedStart()); // QStart + 3S |
| 542 |
EXPECT_EQ(513, s1_rev.AlignedEnd()); // AStart + 10= |
| 543 |
EXPECT_EQ(100, s1_rev.ReferenceStart()); // 100 |
| 544 |
EXPECT_EQ(110, s1_rev.ReferenceEnd()); // RefStart + 10= |
| 545 |
} |
| 546 |
|
| 547 |
{ |
| 548 |
// s2 - FORWARD |
| 549 |
const MappedRead s2{ |
| 550 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 551 |
Strand::FORWARD, 100, Cigar::FromStdString(s2_cigar), 60}; |
| 552 |
|
| 553 |
EXPECT_EQ(Strand::FORWARD, s2.AlignedStrand()); |
| 554 |
EXPECT_EQ(qStart, s2.QueryStart); // 500 |
| 555 |
EXPECT_EQ(qEnd, s2.QueryEnd); // QStart + seqLength |
| 556 |
EXPECT_EQ(502, s2.AlignedStart()); // QStart + 2S |
| 557 |
EXPECT_EQ(512, s2.AlignedEnd()); // AStart + 10= |
| 558 |
EXPECT_EQ(100, s2.ReferenceStart()); // 100 |
| 559 |
EXPECT_EQ(113, s2.ReferenceEnd()); // RefStart + 10= + 3D |
| 560 |
} |
| 561 |
|
| 562 |
{ |
| 563 |
// s2 - REVERSE |
| 564 |
const MappedRead s2_rev{ |
| 565 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 566 |
Strand::REVERSE, 100, Cigar::FromStdString(s2_cigar), 60}; |
| 567 |
|
| 568 |
EXPECT_EQ(Strand::REVERSE, s2_rev.AlignedStrand()); |
| 569 |
EXPECT_EQ(qStart, s2_rev.QueryStart); // 500 |
| 570 |
EXPECT_EQ(qEnd, s2_rev.QueryEnd); // QStart + seqLength |
| 571 |
EXPECT_EQ(503, s2_rev.AlignedStart()); // QStart + 3S |
| 572 |
EXPECT_EQ(513, s2_rev.AlignedEnd()); // AStart + 10= |
| 573 |
EXPECT_EQ(100, s2_rev.ReferenceStart()); // 100 |
| 574 |
EXPECT_EQ(113, s2_rev.ReferenceEnd()); // RefStart + 10= + 3D |
| 575 |
} |
| 576 |
|
| 577 |
{ |
| 578 |
// s3 - FORWARD |
| 579 |
const MappedRead s3{ |
| 580 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 581 |
Strand::FORWARD, 100, Cigar::FromStdString(s3_cigar), 60}; |
| 582 |
|
| 583 |
EXPECT_EQ(Strand::FORWARD, s3.AlignedStrand()); |
| 584 |
EXPECT_EQ(qStart, s3.QueryStart); // 500 |
| 585 |
EXPECT_EQ(qEnd, s3.QueryEnd); // QStart + seqLength |
| 586 |
EXPECT_EQ(502, s3.AlignedStart()); // QStart + 2S |
| 587 |
EXPECT_EQ(512, s3.AlignedEnd()); // AStart + 8= + 2I |
| 588 |
EXPECT_EQ(100, s3.ReferenceStart()); // 100 |
| 589 |
EXPECT_EQ(111, s3.ReferenceEnd()); // RefStart + 8= + 3D |
| 590 |
} |
| 591 |
|
| 592 |
{ |
| 593 |
// s3 - REVERSE |
| 594 |
const MappedRead s3_rev{ |
| 595 |
Read{"name/0/500_515", seq, QualityValues{quals}, SNR{1, 2, 3, 4}, qStart, qEnd}, |
| 596 |
Strand::REVERSE, 100, Cigar::FromStdString(s3_cigar), 60}; |
| 597 |
|
| 598 |
EXPECT_EQ(Strand::REVERSE, s3_rev.AlignedStrand()); |
| 599 |
EXPECT_EQ(qStart, s3_rev.QueryStart); // 500 |
| 600 |
EXPECT_EQ(qEnd, s3_rev.QueryEnd); // QStart + seqLength |
| 601 |
EXPECT_EQ(503, s3_rev.AlignedStart()); // QStart + 3S |
| 602 |
EXPECT_EQ(513, s3_rev.AlignedEnd()); // AStart + 8= + 2I |
| 603 |
EXPECT_EQ(100, s3_rev.ReferenceStart()); // 100 |
| 604 |
EXPECT_EQ(111, s3_rev.ReferenceEnd()); // RefStart + 8= + 3D |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
// clang-format off |
| 609 |
TEST(Data_Read, can_set_query_start_and_end_from_id) |
| 610 |
{ |
| 611 |
const int32_t holeNumber = 77; |
| 612 |
const PacBio::Data::Position qStart = 1000; |
| 613 |
const PacBio::Data::Position qEnd = 1010; |
| 614 |
const PacBio::Data::LocalContextFlags ctxtFlags = |
| 615 |
PacBio::Data::LocalContextFlags::ADAPTER_BEFORE | |
| 616 |
PacBio::Data::LocalContextFlags::ADAPTER_AFTER; |
| 617 |
const PacBio::Data::Accuracy acc = 0.95F; |
| 618 |
const PacBio::Data::SNR snr{0.4, 0.4, 0.4, 0.4}; |
| 619 |
const std::string seq{"GGTTAACCAA"}; |
| 620 |
const PacBio::Data::Frames pw{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; |
| 621 |
const PacBio::Data::Frames ipd{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; |
| 622 |
const std::string movie{"movie"}; |
| 623 |
const std::string chemistry{"chemistry"}; |
| 624 |
|
| 625 |
const PacBio::Data::Read read{ |
| 626 |
PacBio::Data::ReadId{movie, holeNumber, {qStart, qEnd}}, |
| 627 |
seq, pw, ipd, ctxtFlags, acc, snr, chemistry}; |
| 628 |
EXPECT_EQ(qStart, read.QueryStart); |
| 629 |
EXPECT_EQ(qEnd, read.QueryEnd); |
| 630 |
} |
| 631 |
|
| 632 |
TEST(Data_ReadId, can_create_from_subread_name) |
| 633 |
{ |
| 634 |
const PacBio::Data::ReadId id{"m54001_160623_195125/553/3100_11230"}; |
| 635 |
EXPECT_EQ("m54001_160623_195125", id.MovieName); |
| 636 |
EXPECT_EQ(553, id.HoleNumber); |
| 637 |
EXPECT_EQ(PacBio::Data::Interval(3100, 11230), *id.ZmwInterval); |
| 638 |
} |
| 639 |
|
| 640 |
TEST(Data_ReadId, can_create_from_ccs_read_name) |
| 641 |
{ |
| 642 |
const PacBio::Data::ReadId id{"m54001_160623_195125/553/ccs"}; |
| 643 |
EXPECT_EQ("m54001_160623_195125", id.MovieName); |
| 644 |
EXPECT_EQ(553, id.HoleNumber); |
| 645 |
EXPECT_FALSE(id.ZmwInterval); |
| 646 |
} |
| 647 |
|
| 648 |
// clang-format on |