libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2011 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "TestCigarHelper.h" 00019 #include "TestValidate.h" 00020 #include "CigarHelper.h" 00021 #include <assert.h> 00022 00023 void testCigarHelper() 00024 { 00025 // Call generic test. 00026 CigarHelperTest::testCigarHelper(); 00027 } 00028 00029 00030 void CigarHelperTest::testCigarHelper() 00031 { 00032 testSoftClipBeginByRefPos(); 00033 testSoftClipEndByRefPos(); 00034 } 00035 00036 00037 void CigarHelperTest::testSoftClipBeginByRefPos() 00038 { 00039 SamRecord record; 00040 CigarRoller newCigar; 00041 std::string newCigarString; 00042 int32_t newPos = 0; 00043 00044 // Setup the current Cigar. 00045 // Cigar: HHHSSSMMMDDDMMMIIIMMMPPPMMMDDDMMMSSSHHH 00046 // ReadPos: 000000 000011111 111 112222 00047 // ReadPos: 012345 678901234 567 890123 00048 // RefPos: 111111111 122 222222223 00049 // RefPos: 012345678 901 234567890 00050 const char* origCigar = "3H3S3M3D3M3I3M3P3M3D3M3S3H"; 00051 record.setCigar(origCigar); 00052 record.set0BasedPosition(10); 00053 record.setSequence("gggAAATTTCCCTTTGGGAAAggg"); 00054 00055 //////////////////////////////////////////////////////// 00056 // Clip outside of the range (after). Everything should be clipped. 00057 assert(CigarHelper::softClipBeginByRefPos(record, 10000, newCigar, newPos) == 23); 00058 newCigar.getCigarString(newCigarString); 00059 assert(strcmp(newCigarString.c_str(), "3H24S3H") == 0); 00060 00061 //////////////////////////////////////////////////////// 00062 // Clip outside of the range (before). Nothing should change. 00063 assert(CigarHelper::softClipBeginByRefPos(record, 1, newCigar, newPos) == 00064 CigarHelper::NO_CLIP); 00065 newCigar.getCigarString(newCigarString); 00066 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00067 00068 00069 //////////////////////////////////////////////////////// 00070 //////////////////////////////////////////////////////// 00071 // Test clipping at every position of the read. 00072 00073 //////////////////////////////////////////////////////// 00074 // Clip at the first position. 00075 assert(CigarHelper::softClipBeginByRefPos(record, 10, newCigar, newPos) == 3); 00076 assert(newPos == 11); 00077 newCigar.getCigarString(newCigarString); 00078 //std::cout << newCigarString.c_str() << std::endl; 00079 assert(strcmp(newCigarString.c_str(), "3H4S2M3D3M3I3M3P3M3D3M3S3H") == 0); 00080 00081 //////////////////////////////////////////////////////// 00082 // Clip in the middle of the first Match. 00083 assert(CigarHelper::softClipBeginByRefPos(record, 11, newCigar, newPos) == 4); 00084 assert(newPos == 12); 00085 newCigar.getCigarString(newCigarString); 00086 //std::cout << newCigarString.c_str() << std::endl; 00087 assert(strcmp(newCigarString.c_str(), "3H5S1M3D3M3I3M3P3M3D3M3S3H") == 0); 00088 00089 //////////////////////////////////////////////////////// 00090 assert(CigarHelper::softClipBeginByRefPos(record, 12, newCigar, newPos) == 5); 00091 assert(newPos == 16); 00092 newCigar.getCigarString(newCigarString); 00093 //std::cout << newCigarString.c_str() << std::endl; 00094 assert(strcmp(newCigarString.c_str(), "3H6S3M3I3M3P3M3D3M3S3H") == 0); 00095 00096 //////////////////////////////////////////////////////// 00097 assert(CigarHelper::softClipBeginByRefPos(record, 13, newCigar, newPos) == 5); 00098 assert(newPos == 16); 00099 newCigar.getCigarString(newCigarString); 00100 //std::cout << newCigarString.c_str() << std::endl; 00101 assert(strcmp(newCigarString.c_str(), "3H6S3M3I3M3P3M3D3M3S3H") == 0); 00102 00103 //////////////////////////////////////////////////////// 00104 assert(CigarHelper::softClipBeginByRefPos(record, 14, newCigar, newPos) == 5); 00105 assert(newPos == 16); 00106 newCigar.getCigarString(newCigarString); 00107 //std::cout << newCigarString.c_str() << std::endl; 00108 assert(strcmp(newCigarString.c_str(), "3H6S3M3I3M3P3M3D3M3S3H") == 0); 00109 00110 //////////////////////////////////////////////////////// 00111 assert(CigarHelper::softClipBeginByRefPos(record, 15, newCigar, newPos) == 5); 00112 assert(newPos == 16); 00113 newCigar.getCigarString(newCigarString); 00114 //std::cout << newCigarString.c_str() << std::endl; 00115 assert(strcmp(newCigarString.c_str(), "3H6S3M3I3M3P3M3D3M3S3H") == 0); 00116 00117 //////////////////////////////////////////////////////// 00118 assert(CigarHelper::softClipBeginByRefPos(record, 16, newCigar, newPos) == 6); 00119 assert(newPos == 17); 00120 newCigar.getCigarString(newCigarString); 00121 //std::cout << newCigarString.c_str() << std::endl; 00122 assert(strcmp(newCigarString.c_str(), "3H7S2M3I3M3P3M3D3M3S3H") == 0); 00123 00124 //////////////////////////////////////////////////////// 00125 assert(CigarHelper::softClipBeginByRefPos(record, 17, newCigar, newPos) == 7); 00126 assert(newPos == 18); 00127 newCigar.getCigarString(newCigarString); 00128 //std::cout << newCigarString.c_str() << std::endl; 00129 assert(strcmp(newCigarString.c_str(), "3H8S1M3I3M3P3M3D3M3S3H") == 0); 00130 00131 //////////////////////////////////////////////////////// 00132 assert(CigarHelper::softClipBeginByRefPos(record, 18, newCigar, newPos) == 11); 00133 assert(newPos == 19); 00134 newCigar.getCigarString(newCigarString); 00135 //std::cout << newCigarString.c_str() << std::endl; 00136 assert(strcmp(newCigarString.c_str(), "3H12S3M3P3M3D3M3S3H") == 0); 00137 00138 //////////////////////////////////////////////////////// 00139 assert(CigarHelper::softClipBeginByRefPos(record, 19, newCigar, newPos) == 12); 00140 assert(newPos == 20); 00141 newCigar.getCigarString(newCigarString); 00142 //std::cout << newCigarString.c_str() << std::endl; 00143 assert(strcmp(newCigarString.c_str(), "3H13S2M3P3M3D3M3S3H") == 0); 00144 00145 //////////////////////////////////////////////////////// 00146 assert(CigarHelper::softClipBeginByRefPos(record, 20, newCigar, newPos) == 13); 00147 assert(newPos == 21); 00148 newCigar.getCigarString(newCigarString); 00149 //std::cout << newCigarString.c_str() << std::endl; 00150 assert(strcmp(newCigarString.c_str(), "3H14S1M3P3M3D3M3S3H") == 0); 00151 00152 //////////////////////////////////////////////////////// 00153 assert(CigarHelper::softClipBeginByRefPos(record, 21, newCigar, newPos) == 14); 00154 assert(newPos == 22); 00155 newCigar.getCigarString(newCigarString); 00156 //std::cout << newCigarString.c_str() << std::endl; 00157 assert(strcmp(newCigarString.c_str(), "3H15S3M3D3M3S3H") == 0); 00158 00159 //////////////////////////////////////////////////////// 00160 assert(CigarHelper::softClipBeginByRefPos(record, 22, newCigar, newPos) == 15); 00161 assert(newPos == 23); 00162 newCigar.getCigarString(newCigarString); 00163 //std::cout << newCigarString.c_str() << std::endl; 00164 assert(strcmp(newCigarString.c_str(), "3H16S2M3D3M3S3H") == 0); 00165 00166 //////////////////////////////////////////////////////// 00167 assert(CigarHelper::softClipBeginByRefPos(record, 23, newCigar, newPos) == 16); 00168 assert(newPos == 24); 00169 newCigar.getCigarString(newCigarString); 00170 //std::cout << newCigarString.c_str() << std::endl; 00171 assert(strcmp(newCigarString.c_str(), "3H17S1M3D3M3S3H") == 0); 00172 00173 //////////////////////////////////////////////////////// 00174 assert(CigarHelper::softClipBeginByRefPos(record, 24, newCigar, newPos) == 17); 00175 assert(newPos == 28); 00176 newCigar.getCigarString(newCigarString); 00177 //std::cout << newCigarString.c_str() << std::endl; 00178 assert(strcmp(newCigarString.c_str(), "3H18S3M3S3H") == 0); 00179 00180 //////////////////////////////////////////////////////// 00181 assert(CigarHelper::softClipBeginByRefPos(record, 25, newCigar, newPos) == 17); 00182 assert(newPos == 28); 00183 newCigar.getCigarString(newCigarString); 00184 //std::cout << newCigarString.c_str() << std::endl; 00185 assert(strcmp(newCigarString.c_str(), "3H18S3M3S3H") == 0); 00186 00187 //////////////////////////////////////////////////////// 00188 assert(CigarHelper::softClipBeginByRefPos(record, 26, newCigar, newPos) == 17); 00189 assert(newPos == 28); 00190 newCigar.getCigarString(newCigarString); 00191 //std::cout << newCigarString.c_str() << std::endl; 00192 assert(strcmp(newCigarString.c_str(), "3H18S3M3S3H") == 0); 00193 00194 //////////////////////////////////////////////////////// 00195 assert(CigarHelper::softClipBeginByRefPos(record, 27, newCigar, newPos) == 17); 00196 assert(newPos == 28); 00197 newCigar.getCigarString(newCigarString); 00198 //std::cout << newCigarString.c_str() << std::endl; 00199 assert(strcmp(newCigarString.c_str(), "3H18S3M3S3H") == 0); 00200 00201 //////////////////////////////////////////////////////// 00202 assert(CigarHelper::softClipBeginByRefPos(record, 28, newCigar, newPos) == 18); 00203 assert(newPos == 29); 00204 newCigar.getCigarString(newCigarString); 00205 //std::cout << newCigarString.c_str() << std::endl; 00206 assert(strcmp(newCigarString.c_str(), "3H19S2M3S3H") == 0); 00207 00208 //////////////////////////////////////////////////////// 00209 assert(CigarHelper::softClipBeginByRefPos(record, 29, newCigar, newPos) == 19); 00210 assert(newPos == 30); 00211 newCigar.getCigarString(newCigarString); 00212 //std::cout << newCigarString.c_str() << std::endl; 00213 assert(strcmp(newCigarString.c_str(), "3H20S1M3S3H") == 0); 00214 00215 //////////////////////////////////////////////////////// 00216 assert(CigarHelper::softClipBeginByRefPos(record, 30, newCigar, newPos) == 23); 00217 assert(newPos == 10); 00218 newCigar.getCigarString(newCigarString); 00219 //std::cout << newCigarString.c_str() << std::endl; 00220 assert(strcmp(newCigarString.c_str(), "3H24S3H") == 0); 00221 00222 //////////////////////////////////////////////////////// 00223 assert(CigarHelper::softClipBeginByRefPos(record, 31, newCigar, newPos) == 23); 00224 assert(newPos == 10); 00225 newCigar.getCigarString(newCigarString); 00226 //std::cout << newCigarString.c_str() << std::endl; 00227 assert(strcmp(newCigarString.c_str(), "3H24S3H") == 0); 00228 00229 //////////////////////////////////////////////////////// 00230 //////////////////////////////////////////////////////// 00231 // Test clipping at every position when insertions & deletions 00232 // are next to each other. 00233 origCigar = "3M3D3I3M"; 00234 record.setCigar(origCigar); 00235 record.setSequence("GGGAAAGGG"); 00236 // Cigar: MMMDDDIIIMMM 00237 // ReadPos: 000 000000 00238 // ReadPos: 012 345678 00239 // RefPos: 111111 111 00240 // RefPos: 012345 678 00241 record.setCigar(origCigar); 00242 assert(CigarHelper::softClipBeginByRefPos(record, 9, newCigar, newPos) == 00243 CigarHelper::NO_CLIP); 00244 assert(newPos == 10); 00245 newCigar.getCigarString(newCigarString); 00246 //std::cout << newCigarString.c_str() << std::endl; 00247 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00248 00249 record.setCigar(origCigar); 00250 assert(CigarHelper::softClipBeginByRefPos(record, 10, newCigar, newPos) == 0); 00251 assert(newPos == 11); 00252 newCigar.getCigarString(newCigarString); 00253 //std::cout << newCigarString.c_str() << std::endl; 00254 assert(strcmp(newCigarString.c_str(), "1S2M3D3I3M") == 0); 00255 00256 record.setCigar(origCigar); 00257 assert(CigarHelper::softClipBeginByRefPos(record, 11, newCigar, newPos) == 1); 00258 assert(newPos == 12); 00259 newCigar.getCigarString(newCigarString); 00260 //std::cout << newCigarString.c_str() << std::endl; 00261 assert(strcmp(newCigarString.c_str(), "2S1M3D3I3M") == 0); 00262 00263 record.setCigar(origCigar); 00264 assert(CigarHelper::softClipBeginByRefPos(record, 12, newCigar, newPos) == 5); 00265 assert(newPos == 16); 00266 newCigar.getCigarString(newCigarString); 00267 //std::cout << newCigarString.c_str() << std::endl; 00268 assert(strcmp(newCigarString.c_str(), "6S3M") == 0); 00269 00270 record.setCigar(origCigar); 00271 assert(CigarHelper::softClipBeginByRefPos(record, 13, newCigar, newPos) == 5); 00272 assert(newPos == 16); 00273 newCigar.getCigarString(newCigarString); 00274 //std::cout << newCigarString.c_str() << std::endl; 00275 assert(strcmp(newCigarString.c_str(), "6S3M") == 0); 00276 00277 record.setCigar(origCigar); 00278 assert(CigarHelper::softClipBeginByRefPos(record, 14, newCigar, newPos) == 5); 00279 assert(newPos == 16); 00280 newCigar.getCigarString(newCigarString); 00281 //std::cout << newCigarString.c_str() << std::endl; 00282 assert(strcmp(newCigarString.c_str(), "6S3M") == 0); 00283 00284 record.setCigar(origCigar); 00285 assert(CigarHelper::softClipBeginByRefPos(record, 15, newCigar, newPos) == 5); 00286 assert(newPos == 16); 00287 newCigar.getCigarString(newCigarString); 00288 //std::cout << newCigarString.c_str() << std::endl; 00289 assert(strcmp(newCigarString.c_str(), "6S3M") == 0); 00290 00291 record.setCigar(origCigar); 00292 assert(CigarHelper::softClipBeginByRefPos(record, 16, newCigar, newPos) == 6); 00293 assert(newPos == 17); 00294 newCigar.getCigarString(newCigarString); 00295 //std::cout << newCigarString.c_str() << std::endl; 00296 assert(strcmp(newCigarString.c_str(), "7S2M") == 0); 00297 00298 record.setCigar(origCigar); 00299 assert(CigarHelper::softClipBeginByRefPos(record, 17, newCigar, newPos) == 7); 00300 assert(newPos == 18); 00301 newCigar.getCigarString(newCigarString); 00302 //std::cout << newCigarString.c_str() << std::endl; 00303 assert(strcmp(newCigarString.c_str(), "8S1M") == 0); 00304 00305 record.setCigar(origCigar); 00306 assert(CigarHelper::softClipBeginByRefPos(record, 18, newCigar, newPos) == 8); 00307 assert(newPos == 10); 00308 newCigar.getCigarString(newCigarString); 00309 //std::cout << newCigarString.c_str() << std::endl; 00310 assert(strcmp(newCigarString.c_str(), "9S") == 0); 00311 00312 record.setCigar(origCigar); 00313 assert(CigarHelper::softClipBeginByRefPos(record, 19, newCigar, newPos) == 8); 00314 assert(newPos == 10); 00315 newCigar.getCigarString(newCigarString); 00316 //std::cout << newCigarString.c_str() << std::endl; 00317 assert(strcmp(newCigarString.c_str(), "9S") == 0); 00318 00319 //////////////////////////////////////////////////////// 00320 //////////////////////////////////////////////////////// 00321 // Test clipping at every position when first non-clip instruction is delete. 00322 origCigar = "3H3S3D3M3S3H"; 00323 record.setCigar(origCigar); 00324 record.setSequence("gggAAAggg"); 00325 // Cigar: HHHSSSDDDMMMSSSHHH 00326 // ReadPos: 000 000000 00327 // ReadPos: 012 345678 00328 // RefPos: 111111 00329 // RefPos: 012345 00330 record.setCigar(origCigar); 00331 assert(CigarHelper::softClipBeginByRefPos(record, 9, newCigar, newPos) == 00332 CigarHelper::NO_CLIP); 00333 assert(newPos == 10); 00334 newCigar.getCigarString(newCigarString); 00335 //std::cout << newCigarString.c_str() << std::endl; 00336 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00337 00338 record.setCigar(origCigar); 00339 assert(CigarHelper::softClipBeginByRefPos(record, 10, newCigar, newPos) == 2); 00340 assert(newPos == 13); 00341 newCigar.getCigarString(newCigarString); 00342 //std::cout << newCigarString.c_str() << std::endl; 00343 assert(strcmp(newCigarString.c_str(), "3H3S3M3S3H") == 0); 00344 00345 record.setCigar(origCigar); 00346 assert(CigarHelper::softClipBeginByRefPos(record, 11, newCigar, newPos) == 2); 00347 assert(newPos == 13); 00348 newCigar.getCigarString(newCigarString); 00349 //std::cout << newCigarString.c_str() << std::endl; 00350 assert(strcmp(newCigarString.c_str(), "3H3S3M3S3H") == 0); 00351 00352 record.setCigar(origCigar); 00353 assert(CigarHelper::softClipBeginByRefPos(record, 12, newCigar, newPos) == 2); 00354 assert(newPos == 13); 00355 newCigar.getCigarString(newCigarString); 00356 //std::cout << newCigarString.c_str() << std::endl; 00357 assert(strcmp(newCigarString.c_str(), "3H3S3M3S3H") == 0); 00358 00359 record.setCigar(origCigar); 00360 assert(CigarHelper::softClipBeginByRefPos(record, 13, newCigar, newPos) == 3); 00361 assert(newPos == 14); 00362 newCigar.getCigarString(newCigarString); 00363 //std::cout << newCigarString.c_str() << std::endl; 00364 assert(strcmp(newCigarString.c_str(), "3H4S2M3S3H") == 0); 00365 00366 record.setCigar(origCigar); 00367 assert(CigarHelper::softClipBeginByRefPos(record, 14, newCigar, newPos) == 4); 00368 assert(newPos == 15); 00369 newCigar.getCigarString(newCigarString); 00370 //std::cout << newCigarString.c_str() << std::endl; 00371 assert(strcmp(newCigarString.c_str(), "3H5S1M3S3H") == 0); 00372 00373 record.setCigar(origCigar); 00374 assert(CigarHelper::softClipBeginByRefPos(record, 15, newCigar, newPos) == 8); 00375 assert(newPos == 10); 00376 newCigar.getCigarString(newCigarString); 00377 //std::cout << newCigarString.c_str() << std::endl; 00378 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00379 00380 record.setCigar(origCigar); 00381 assert(CigarHelper::softClipBeginByRefPos(record, 16, newCigar, newPos) == 8); 00382 assert(newPos == 10); 00383 newCigar.getCigarString(newCigarString); 00384 //std::cout << newCigarString.c_str() << std::endl; 00385 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00386 00387 //////////////////////////////////////////////////////// 00388 //////////////////////////////////////////////////////// 00389 // Test clipping at every position when first non-clip instruction is insert. 00390 origCigar = "3H3S3I3M3S3H"; 00391 record.setCigar(origCigar); 00392 record.setSequence("gggAAATTTggg"); 00393 // Cigar: HHHSSSIIIMMMSSSHHH 00394 // ReadPos: 000000000011 00395 // ReadPos: 012345678901 00396 // RefPos: 111 00397 // RefPos: 012 00398 record.setCigar(origCigar); 00399 assert(CigarHelper::softClipBeginByRefPos(record, 9, newCigar, newPos) == 00400 CigarHelper::NO_CLIP); 00401 assert(newPos == 10); 00402 newCigar.getCigarString(newCigarString); 00403 //std::cout << newCigarString.c_str() << std::endl; 00404 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00405 00406 record.setCigar(origCigar); 00407 assert(CigarHelper::softClipBeginByRefPos(record, 10, newCigar, newPos) == 6); 00408 assert(newPos == 11); 00409 newCigar.getCigarString(newCigarString); 00410 //std::cout << newCigarString.c_str() << std::endl; 00411 assert(strcmp(newCigarString.c_str(), "3H7S2M3S3H") == 0); 00412 00413 record.setCigar(origCigar); 00414 assert(CigarHelper::softClipBeginByRefPos(record, 11, newCigar, newPos) == 7); 00415 assert(newPos == 12); 00416 newCigar.getCigarString(newCigarString); 00417 //std::cout << newCigarString.c_str() << std::endl; 00418 assert(strcmp(newCigarString.c_str(), "3H8S1M3S3H") == 0); 00419 00420 record.setCigar(origCigar); 00421 assert(CigarHelper::softClipBeginByRefPos(record, 12, newCigar, newPos) == 11); 00422 assert(newPos == 10); 00423 newCigar.getCigarString(newCigarString); 00424 //std::cout << newCigarString.c_str() << std::endl; 00425 assert(strcmp(newCigarString.c_str(), "3H12S3H") == 0); 00426 00427 record.setCigar(origCigar); 00428 assert(CigarHelper::softClipBeginByRefPos(record, 13, newCigar, newPos) == 11); 00429 assert(newPos == 10); 00430 newCigar.getCigarString(newCigarString); 00431 //std::cout << newCigarString.c_str() << std::endl; 00432 assert(strcmp(newCigarString.c_str(), "3H12S3H") == 0); 00433 } 00434 00435 00436 void CigarHelperTest::testSoftClipEndByRefPos() 00437 { 00438 SamRecord record; 00439 CigarRoller newCigar; 00440 std::string newCigarString; 00441 00442 // Setup the current Cigar. 00443 // Cigar: HHHSSSMMMDDDMMMIIIMMMPPPMMMDDDMMMSSSHHH 00444 // ReadPos: 000000 000011111 111 112222 00445 // ReadPos: 012345 678901234 567 890123 00446 // RefPos: 111111111 122 222222223 00447 // RefPos: 012345678 901 234567890 00448 const char* origCigar = "3H3S3M3D3M3I3M3P3M3D3M3S3H"; 00449 record.setCigar(origCigar); 00450 record.set0BasedPosition(10); 00451 record.setSequence("gggAAATTTCCCTTTGGGAAAggg"); 00452 00453 //////////////////////////////////////////////////////// 00454 // Clip outside of the range (after). Nothing should change. 00455 assert(CigarHelper::softClipEndByRefPos(record, 10000, newCigar) == 00456 CigarHelper::NO_CLIP); 00457 newCigar.getCigarString(newCigarString); 00458 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00459 00460 //////////////////////////////////////////////////////// 00461 // Clip outside of the range (before). Everything should be clipped. 00462 assert(CigarHelper::softClipEndByRefPos(record, 1, newCigar) == 0); 00463 newCigar.getCigarString(newCigarString); 00464 //std::cout << newCigarString.c_str() << std::endl; 00465 assert(strcmp(newCigarString.c_str(), "3H24S3H") == 0); 00466 00467 00468 //////////////////////////////////////////////////////// 00469 //////////////////////////////////////////////////////// 00470 // Test clipping at every position of the read. 00471 00472 //////////////////////////////////////////////////////// 00473 // Clip at the first position. 00474 assert(CigarHelper::softClipEndByRefPos(record, 10, newCigar) == 0); 00475 newCigar.getCigarString(newCigarString); 00476 //std::cout << newCigarString.c_str() << std::endl; 00477 assert(strcmp(newCigarString.c_str(), "3H24S3H") == 0); 00478 00479 //////////////////////////////////////////////////////// 00480 // Clip in the middle of the first Match. 00481 assert(CigarHelper::softClipEndByRefPos(record, 11, newCigar) == 4); 00482 newCigar.getCigarString(newCigarString); 00483 //std::cout << newCigarString.c_str() << std::endl; 00484 assert(strcmp(newCigarString.c_str(), "3H3S1M20S3H") == 0); 00485 00486 //////////////////////////////////////////////////////// 00487 // Clip just before the first deletion. 00488 assert(CigarHelper::softClipEndByRefPos(record, 12, newCigar) == 5); 00489 newCigar.getCigarString(newCigarString); 00490 //std::cout << newCigarString.c_str() << std::endl; 00491 assert(strcmp(newCigarString.c_str(), "3H3S2M19S3H") == 0); 00492 00493 //////////////////////////////////////////////////////// 00494 // Clip at the first deletion. 00495 assert(CigarHelper::softClipEndByRefPos(record, 13, newCigar) == 6); 00496 newCigar.getCigarString(newCigarString); 00497 //std::cout << newCigarString.c_str() << std::endl; 00498 assert(strcmp(newCigarString.c_str(), "3H3S3M18S3H") == 0); 00499 00500 //////////////////////////////////////////////////////// 00501 // Clip in the middle of the first deletion. 00502 assert(CigarHelper::softClipEndByRefPos(record, 14, newCigar) == 6); 00503 newCigar.getCigarString(newCigarString); 00504 //std::cout << newCigarString.c_str() << std::endl; 00505 assert(strcmp(newCigarString.c_str(), "3H3S3M18S3H") == 0); 00506 00507 //////////////////////////////////////////////////////// 00508 // Clip in the end of the first deletion. 00509 assert(CigarHelper::softClipEndByRefPos(record, 15, newCigar) == 6); 00510 newCigar.getCigarString(newCigarString); 00511 //std::cout << newCigarString.c_str() << std::endl; 00512 assert(strcmp(newCigarString.c_str(), "3H3S3M18S3H") == 0); 00513 00514 //////////////////////////////////////////////////////// 00515 // Clip just after the first deletion (should remove the deletion). 00516 assert(CigarHelper::softClipEndByRefPos(record, 16, newCigar) == 6); 00517 newCigar.getCigarString(newCigarString); 00518 //std::cout << newCigarString.c_str() << std::endl; 00519 assert(strcmp(newCigarString.c_str(), "3H3S3M18S3H") == 0); 00520 00521 //////////////////////////////////////////////////////// 00522 // Clip in middle of read after 1st deletion. 00523 assert(CigarHelper::softClipEndByRefPos(record, 17, newCigar) == 7); 00524 newCigar.getCigarString(newCigarString); 00525 //std::cout << newCigarString.c_str() << std::endl; 00526 assert(strcmp(newCigarString.c_str(), "3H3S3M3D1M17S3H") == 0); 00527 00528 //////////////////////////////////////////////////////// 00529 // Clip in middle of read after 1st deletion. 00530 assert(CigarHelper::softClipEndByRefPos(record, 18, newCigar) == 8); 00531 newCigar.getCigarString(newCigarString); 00532 //std::cout << newCigarString.c_str() << std::endl; 00533 assert(strcmp(newCigarString.c_str(), "3H3S3M3D2M16S3H") == 0); 00534 00535 //////////////////////////////////////////////////////// 00536 // Clip just after the 1st insertion. 00537 assert(CigarHelper::softClipEndByRefPos(record, 19, newCigar) == 12); 00538 newCigar.getCigarString(newCigarString); 00539 //std::cout << newCigarString.c_str() << std::endl; 00540 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I12S3H") == 0); 00541 00542 //////////////////////////////////////////////////////// 00543 // Clip in middle of the match after 1st insertion. 00544 assert(CigarHelper::softClipEndByRefPos(record, 20, newCigar) == 13); 00545 newCigar.getCigarString(newCigarString); 00546 //std::cout << newCigarString.c_str() << std::endl; 00547 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I1M11S3H") == 0); 00548 00549 //////////////////////////////////////////////////////// 00550 // Clip in middle of the match after 1st insertion. 00551 assert(CigarHelper::softClipEndByRefPos(record, 21, newCigar) == 14); 00552 newCigar.getCigarString(newCigarString); 00553 //std::cout << newCigarString.c_str() << std::endl; 00554 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I2M10S3H") == 0); 00555 00556 //////////////////////////////////////////////////////// 00557 // Clip right after the pad 00558 assert(CigarHelper::softClipEndByRefPos(record, 22, newCigar) == 15); 00559 newCigar.getCigarString(newCigarString); 00560 //std::cout << newCigarString.c_str() << std::endl; 00561 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M9S3H") == 0); 00562 00563 //////////////////////////////////////////////////////// 00564 // Clip middle of read after the pad 00565 assert(CigarHelper::softClipEndByRefPos(record, 23, newCigar) == 16); 00566 newCigar.getCigarString(newCigarString); 00567 //std::cout << newCigarString.c_str() << std::endl; 00568 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P1M8S3H") == 0); 00569 00570 //////////////////////////////////////////////////////// 00571 // Clip end of read after the pad before deletion 00572 assert(CigarHelper::softClipEndByRefPos(record, 24, newCigar) == 17); 00573 newCigar.getCigarString(newCigarString); 00574 //std::cout << newCigarString.c_str() << std::endl; 00575 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P2M7S3H") == 0); 00576 00577 //////////////////////////////////////////////////////// 00578 // Clip at start of 2nd deletion. 00579 assert(CigarHelper::softClipEndByRefPos(record, 25, newCigar) == 18); 00580 newCigar.getCigarString(newCigarString); 00581 //std::cout << newCigarString.c_str() << std::endl; 00582 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M6S3H") == 0); 00583 00584 //////////////////////////////////////////////////////// 00585 // Clip in 2nd deletion. 00586 assert(CigarHelper::softClipEndByRefPos(record, 26, newCigar) == 18); 00587 newCigar.getCigarString(newCigarString); 00588 //std::cout << newCigarString.c_str() << std::endl; 00589 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M6S3H") == 0); 00590 00591 //////////////////////////////////////////////////////// 00592 // Clip in 2nd deletion. 00593 assert(CigarHelper::softClipEndByRefPos(record, 27, newCigar) == 18); 00594 newCigar.getCigarString(newCigarString); 00595 //std::cout << newCigarString.c_str() << std::endl; 00596 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M6S3H") == 0); 00597 00598 //////////////////////////////////////////////////////// 00599 // Clip right after 2nd deletion. 00600 assert(CigarHelper::softClipEndByRefPos(record, 28, newCigar) == 18); 00601 newCigar.getCigarString(newCigarString); 00602 //std::cout << newCigarString.c_str() << std::endl; 00603 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M6S3H") == 0); 00604 00605 //////////////////////////////////////////////////////// 00606 // Clip in middle of last match. 00607 assert(CigarHelper::softClipEndByRefPos(record, 29, newCigar) == 19); 00608 newCigar.getCigarString(newCigarString); 00609 //std::cout << newCigarString.c_str() << std::endl; 00610 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M3D1M5S3H") == 0); 00611 00612 //////////////////////////////////////////////////////// 00613 // Clip in middle of last match. 00614 assert(CigarHelper::softClipEndByRefPos(record, 30, newCigar) == 20); 00615 newCigar.getCigarString(newCigarString); 00616 //std::cout << newCigarString.c_str() << std::endl; 00617 assert(strcmp(newCigarString.c_str(), "3H3S3M3D3M3I3M3P3M3D2M4S3H") == 0); 00618 00619 //////////////////////////////////////////////////////// 00620 // Clip right after the read (no change). 00621 assert(CigarHelper::softClipEndByRefPos(record, 31, newCigar) == 00622 CigarHelper::NO_CLIP); 00623 newCigar.getCigarString(newCigarString); 00624 //std::cout << newCigarString.c_str() << std::endl; 00625 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00626 00627 //////////////////////////////////////////////////////// 00628 //////////////////////////////////////////////////////// 00629 // Test clipping at every position when insertions & deletions 00630 // are next to each other. 00631 origCigar = "3M3D3I3M"; 00632 record.setCigar(origCigar); 00633 record.setSequence("GGGAAAGGG"); 00634 // Cigar: MMMDDDIIIMMM 00635 // ReadPos: 000 000000 00636 // ReadPos: 012 345678 00637 // RefPos: 111111 111 00638 // RefPos: 012345 678 00639 record.setCigar(origCigar); 00640 assert(CigarHelper::softClipEndByRefPos(record, 9, newCigar) == 0); 00641 newCigar.getCigarString(newCigarString); 00642 //std::cout << newCigarString.c_str() << std::endl; 00643 assert(strcmp(newCigarString.c_str(), "9S") == 0); 00644 00645 record.setCigar(origCigar); 00646 assert(CigarHelper::softClipEndByRefPos(record, 10, newCigar) == 0); 00647 newCigar.getCigarString(newCigarString); 00648 //std::cout << newCigarString.c_str() << std::endl; 00649 assert(strcmp(newCigarString.c_str(), "9S") == 0); 00650 00651 record.setCigar(origCigar); 00652 assert(CigarHelper::softClipEndByRefPos(record, 11, newCigar) == 1); 00653 newCigar.getCigarString(newCigarString); 00654 //std::cout << newCigarString.c_str() << std::endl; 00655 assert(strcmp(newCigarString.c_str(), "1M8S") == 0); 00656 00657 record.setCigar(origCigar); 00658 assert(CigarHelper::softClipEndByRefPos(record, 12, newCigar) == 2); 00659 newCigar.getCigarString(newCigarString); 00660 //std::cout << newCigarString.c_str() << std::endl; 00661 assert(strcmp(newCigarString.c_str(), "2M7S") == 0); 00662 00663 record.setCigar(origCigar); 00664 assert(CigarHelper::softClipEndByRefPos(record, 13, newCigar) == 3); 00665 newCigar.getCigarString(newCigarString); 00666 //std::cout << newCigarString.c_str() << std::endl; 00667 assert(strcmp(newCigarString.c_str(), "3M6S") == 0); 00668 00669 record.setCigar(origCigar); 00670 assert(CigarHelper::softClipEndByRefPos(record, 14, newCigar) == 3); 00671 newCigar.getCigarString(newCigarString); 00672 //std::cout << newCigarString.c_str() << std::endl; 00673 assert(strcmp(newCigarString.c_str(), "3M6S") == 0); 00674 00675 record.setCigar(origCigar); 00676 assert(CigarHelper::softClipEndByRefPos(record, 15, newCigar) == 3); 00677 newCigar.getCigarString(newCigarString); 00678 //std::cout << newCigarString.c_str() << std::endl; 00679 assert(strcmp(newCigarString.c_str(), "3M6S") == 0); 00680 00681 record.setCigar(origCigar); 00682 assert(CigarHelper::softClipEndByRefPos(record, 16, newCigar) == 6); 00683 newCigar.getCigarString(newCigarString); 00684 //std::cout << newCigarString.c_str() << std::endl; 00685 assert(strcmp(newCigarString.c_str(), "3M3D3I3S") == 0); 00686 00687 record.setCigar(origCigar); 00688 assert(CigarHelper::softClipEndByRefPos(record, 17, newCigar) == 7); 00689 newCigar.getCigarString(newCigarString); 00690 //std::cout << newCigarString.c_str() << std::endl; 00691 assert(strcmp(newCigarString.c_str(), "3M3D3I1M2S") == 0); 00692 00693 record.setCigar(origCigar); 00694 assert(CigarHelper::softClipEndByRefPos(record, 18, newCigar) == 8); 00695 newCigar.getCigarString(newCigarString); 00696 //std::cout << newCigarString.c_str() << std::endl; 00697 assert(strcmp(newCigarString.c_str(), "3M3D3I2M1S") == 0); 00698 00699 record.setCigar(origCigar); 00700 assert(CigarHelper::softClipEndByRefPos(record, 19, newCigar) == 00701 CigarHelper::NO_CLIP); 00702 newCigar.getCigarString(newCigarString); 00703 //std::cout << newCigarString.c_str() << std::endl; 00704 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00705 00706 //////////////////////////////////////////////////////// 00707 //////////////////////////////////////////////////////// 00708 // Test clipping at every position when first non-clip instruction is delete. 00709 origCigar = "3H3S3D3M3S3H"; 00710 record.setCigar(origCigar); 00711 record.setSequence("gggAAAggg"); 00712 // Cigar: HHHSSSDDDMMMSSSHHH 00713 // ReadPos: 000 000000 00714 // ReadPos: 012 345678 00715 // RefPos: 111111 00716 // RefPos: 012345 00717 record.setCigar(origCigar); 00718 assert(CigarHelper::softClipEndByRefPos(record, 9, newCigar) == 0); 00719 newCigar.getCigarString(newCigarString); 00720 //std::cout << newCigarString.c_str() << std::endl; 00721 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00722 00723 record.setCigar(origCigar); 00724 assert(CigarHelper::softClipEndByRefPos(record, 10, newCigar) == 0); 00725 newCigar.getCigarString(newCigarString); 00726 //std::cout << newCigarString.c_str() << std::endl; 00727 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00728 00729 record.setCigar(origCigar); 00730 assert(CigarHelper::softClipEndByRefPos(record, 11, newCigar) == 0); 00731 newCigar.getCigarString(newCigarString); 00732 //std::cout << newCigarString.c_str() << std::endl; 00733 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00734 00735 record.setCigar(origCigar); 00736 assert(CigarHelper::softClipEndByRefPos(record, 12, newCigar) == 0); 00737 newCigar.getCigarString(newCigarString); 00738 //std::cout << newCigarString.c_str() << std::endl; 00739 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00740 00741 record.setCigar(origCigar); 00742 assert(CigarHelper::softClipEndByRefPos(record, 13, newCigar) == 0); 00743 newCigar.getCigarString(newCigarString); 00744 //std::cout << newCigarString.c_str() << std::endl; 00745 assert(strcmp(newCigarString.c_str(), "3H9S3H") == 0); 00746 00747 record.setCigar(origCigar); 00748 assert(CigarHelper::softClipEndByRefPos(record, 14, newCigar) == 4); 00749 newCigar.getCigarString(newCigarString); 00750 //std::cout << newCigarString.c_str() << std::endl; 00751 assert(strcmp(newCigarString.c_str(), "3H3S3D1M5S3H") == 0); 00752 00753 record.setCigar(origCigar); 00754 assert(CigarHelper::softClipEndByRefPos(record, 15, newCigar) == 5); 00755 newCigar.getCigarString(newCigarString); 00756 //std::cout << newCigarString.c_str() << std::endl; 00757 assert(strcmp(newCigarString.c_str(), "3H3S3D2M4S3H") == 0); 00758 00759 record.setCigar(origCigar); 00760 assert(CigarHelper::softClipEndByRefPos(record, 16, newCigar) == 00761 CigarHelper::NO_CLIP); 00762 newCigar.getCigarString(newCigarString); 00763 //std::cout << newCigarString.c_str() << std::endl; 00764 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00765 00766 //////////////////////////////////////////////////////// 00767 //////////////////////////////////////////////////////// 00768 // Test clipping at every position when first non-clip instruction is insert. 00769 origCigar = "3H3S3I3M3S3H"; 00770 record.setCigar(origCigar); 00771 record.setSequence("gggAAATTTggg"); 00772 // Cigar: HHHSSSIIIMMMSSSHHH 00773 // ReadPos: 000000000011 00774 // ReadPos: 012345678901 00775 // RefPos: 111 00776 // RefPos: 012 00777 record.setCigar(origCigar); 00778 assert(CigarHelper::softClipEndByRefPos(record, 9, newCigar) == 0); 00779 newCigar.getCigarString(newCigarString); 00780 //std::cout << newCigarString.c_str() << std::endl; 00781 assert(strcmp(newCigarString.c_str(), "3H12S3H") == 0); 00782 00783 record.setCigar(origCigar); 00784 assert(CigarHelper::softClipEndByRefPos(record, 10, newCigar) == 6); 00785 newCigar.getCigarString(newCigarString); 00786 //std::cout << newCigarString.c_str() << std::endl; 00787 assert(strcmp(newCigarString.c_str(), "3H3S3I6S3H") == 0); 00788 00789 record.setCigar(origCigar); 00790 assert(CigarHelper::softClipEndByRefPos(record, 11, newCigar) == 7); 00791 newCigar.getCigarString(newCigarString); 00792 //std::cout << newCigarString.c_str() << std::endl; 00793 assert(strcmp(newCigarString.c_str(), "3H3S3I1M5S3H") == 0); 00794 00795 record.setCigar(origCigar); 00796 assert(CigarHelper::softClipEndByRefPos(record, 12, newCigar) == 8); 00797 newCigar.getCigarString(newCigarString); 00798 //std::cout << newCigarString.c_str() << std::endl; 00799 assert(strcmp(newCigarString.c_str(), "3H3S3I2M4S3H") == 0); 00800 00801 record.setCigar(origCigar); 00802 assert(CigarHelper::softClipEndByRefPos(record, 13, newCigar) == 00803 CigarHelper::NO_CLIP); 00804 newCigar.getCigarString(newCigarString); 00805 //std::cout << newCigarString.c_str() << std::endl; 00806 assert(strcmp(newCigarString.c_str(), origCigar) == 0); 00807 }