libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 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 "TestEquals.h" 00019 #include "SamQuerySeqWithRefHelper.h" 00020 #include <assert.h> 00021 00022 00023 00024 void testSeqEquals() 00025 { 00026 // Call generic test which since the sam and bam are identical, should 00027 // contain the same results. 00028 EqualsTest::testEq(EqualsTest::SAM); 00029 #ifdef __ZLIB_AVAILABLE__ 00030 EqualsTest::testEq(EqualsTest::BAM); 00031 #endif 00032 } 00033 00034 00035 const char* EqualsTest::READ_NAMES[] = 00036 {"01:====", "02:===X", "03:==X=", "04:==XX", "05:=X==", "06:=X=X", 00037 "07:=XX=", "08:=XXX", "09:X===", "10:X==X", "11:X=X=", "12:X=XX", 00038 "13:XX==", "14:XX=X", "15:XXX=", "16:XXXX", "Read:GGCCTA;Ref:CCTA", 00039 "Read:CCTA;Ref:CCTA", "Read:CCGTxxxC;Ref:CCxTAACC", 00040 "Read:CCxxAC;Ref:CCTAACC", "chromNotInRef", "chromNotInRef1"}; 00041 00042 const char* EqualsTest::READ_SEQS_BASES[] = 00043 {"CCTA", "CCTT", "CCAA", "CCAT", "CTTA", "CTTT", "CTAA", "CTAT", "TCTA", "TCTT", "TCAA", "TCAT", "TTTA", "TTTT", "TTAA", "TTAT", "GGCCTA", 00044 "CCTA", "CCGTC", "CCAC", "CCTA", "CC=A"}; 00045 00046 const char* EqualsTest::READ_SEQS_EQUALS[] = 00047 {"====", "===T", "==A=", "==AT", "=T==", "=T=T", "=TA=", "=TAT", "T===", "T==T", "T=A=", "T=AT", "TT==", "TT=T", "TTA=", "TTAT", "GG====", 00048 "====", "==G==", "====", "CCTA", "CC=A"}; 00049 00050 const char* EqualsTest::READ_SEQS_MIXED[] = 00051 {"C===", "=C=T", "==AA", "==AT", "=TTA", "CT=T", "=TAA", "=TAT", "T=TA", "TC=T", "TCA=", "TCAT", "TT=A", "TT=T", "TTA=", "TTAT", "GGC=T=", 00052 "C=T=", "C=GT=", "C=A=", "CCTA", "CC=A"}; 00053 00054 const char* EqualsTest::expectedReferenceName; 00055 const char* EqualsTest::expectedMateReferenceName; 00056 const char* EqualsTest::expectedMateReferenceNameOrEqual; 00057 const char* EqualsTest::expectedCigar; 00058 const char* EqualsTest::expectedQuality; 00059 00060 std::vector<unsigned int> EqualsTest::expectedCigarHex; 00061 00062 int EqualsTest::expected0BasedAlignmentEnd; 00063 int EqualsTest::expected1BasedAlignmentEnd; 00064 int EqualsTest::expectedAlignmentLength; 00065 int EqualsTest::expected0BasedUnclippedStart; 00066 int EqualsTest::expected1BasedUnclippedStart; 00067 int EqualsTest::expected0BasedUnclippedEnd; 00068 int EqualsTest::expected1BasedUnclippedEnd; 00069 bamRecordStruct EqualsTest::expectedRecord; 00070 00071 void EqualsTest::testEq(FileType inputType) 00072 { 00073 reset(); 00074 SamFile inSam; 00075 00076 std::string outputBase = "results/out"; 00077 00078 if(inputType == SAM) 00079 { 00080 assert(inSam.OpenForRead("testFiles/testEq.sam")); 00081 outputBase += "SamEq"; 00082 } 00083 else 00084 { 00085 assert(inSam.OpenForRead("testFiles/testEq.bam")); 00086 outputBase += "BamEq"; 00087 } 00088 00089 // Read the SAM Header. 00090 SamFileHeader samHeader; 00091 assert(inSam.ReadHeader(samHeader)); 00092 00093 std::string outputName = outputBase + "Bases.sam"; 00094 SamFile outBasesSam( outputName.c_str(), SamFile::WRITE); 00095 outputName = outputBase + "Equals.sam"; 00096 SamFile outEqualsSam(outputName.c_str(), SamFile::WRITE); 00097 outputName = outputBase + "Orig.sam"; 00098 SamFile outOrigSam( outputName.c_str(), SamFile::WRITE); 00099 outputName = outputBase + "Bases.bam"; 00100 SamFile outBasesBam( outputName.c_str(), SamFile::WRITE); 00101 outputName = outputBase + "Equals.bam"; 00102 SamFile outEqualsBam(outputName.c_str(), SamFile::WRITE); 00103 outputName = outputBase + "Orig.bam"; 00104 SamFile outOrigBam( outputName.c_str(), SamFile::WRITE); 00105 assert(outBasesSam.WriteHeader(samHeader)); 00106 assert(outEqualsSam.WriteHeader(samHeader)); 00107 assert(outOrigSam.WriteHeader(samHeader)); 00108 assert(outBasesBam.WriteHeader(samHeader)); 00109 assert(outEqualsBam.WriteHeader(samHeader)); 00110 assert(outOrigBam.WriteHeader(samHeader)); 00111 00112 outBasesSam.SetWriteSequenceTranslation(SamRecord::BASES); 00113 outEqualsSam.SetWriteSequenceTranslation(SamRecord::EQUAL); 00114 outOrigSam.SetWriteSequenceTranslation(SamRecord::NONE); 00115 outBasesBam.SetWriteSequenceTranslation(SamRecord::BASES); 00116 outEqualsBam.SetWriteSequenceTranslation(SamRecord::EQUAL); 00117 outOrigBam.SetWriteSequenceTranslation(SamRecord::NONE); 00118 00119 GenomeSequence reference("testFiles/chr1_partial.fa"); 00120 00121 inSam.SetReference(&reference); 00122 00123 SamRecord samRecord; 00124 00125 // The set of 16 variations are repeated 3 times: once with all charcters 00126 // 1) Matches have the actual bases in them. 00127 // 2) Matches have '=' 00128 // 3) Matches are mixed between bases and '=' 00129 // Since Sequences are 4 characters long, there are 16 variations 00130 // of match/mismatch. 00131 for(int j = 0; j < 16; j++) 00132 { 00133 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00134 validateEqRead(samRecord, j, READ_SEQS_BASES[j]); 00135 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00136 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00137 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00138 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00139 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00140 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00141 } 00142 for(int j = 0; j < 16; j++) 00143 { 00144 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00145 validateEqRead(samRecord, j, READ_SEQS_EQUALS[j]); 00146 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00147 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00148 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00149 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00150 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00151 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00152 } 00153 for(int j = 0; j < 16; j++) 00154 { 00155 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00156 validateEqRead(samRecord, j, READ_SEQS_MIXED[j]); 00157 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00158 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00159 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00160 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00161 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00162 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00163 } 00164 00165 expectedCigar = "2S4M"; 00166 expectedCigarHex.clear(); 00167 expectedCigarHex.push_back(0x24); 00168 expectedCigarHex.push_back(0x40); 00169 expected0BasedUnclippedStart = expectedRecord.myPosition-2; 00170 expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1; 00171 expectedRecord.myBlockSize = 70; 00172 expectedRecord.myReadNameLength = 21; 00173 expectedRecord.myCigarLength = 2; 00174 expectedRecord.myReadLength = 6; 00175 expectedQuality = "??I00?"; 00176 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00177 validateEqRead(samRecord, 16, READ_SEQS_MIXED[16]); 00178 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00179 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00180 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00181 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00182 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00183 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00184 00185 expectedCigar = "4M4H"; 00186 expectedCigarHex.clear(); 00187 expectedCigarHex.push_back(0x40); 00188 expectedCigarHex.push_back(0x45); 00189 expected0BasedUnclippedStart = expectedRecord.myPosition; 00190 expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1; 00191 expected0BasedUnclippedEnd = expectedRecord.myPosition + 7; 00192 expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1; 00193 expectedRecord.myBlockSize = 65; 00194 expectedRecord.myReadNameLength = 19; 00195 expectedRecord.myCigarLength = 2; 00196 expectedRecord.myReadLength = 4; 00197 expectedQuality = "I00?"; 00198 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00199 validateEqRead(samRecord, 17, READ_SEQS_MIXED[17]); 00200 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00201 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00202 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00203 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00204 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00205 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00206 00207 expectedCigar = "1M1P1M1I1M3D1M"; 00208 expectedCigarHex.clear(); 00209 expectedCigarHex.push_back(0x10); 00210 expectedCigarHex.push_back(0x16); 00211 expectedCigarHex.push_back(0x10); 00212 expectedCigarHex.push_back(0x11); 00213 expectedCigarHex.push_back(0x10); 00214 expectedCigarHex.push_back(0x32); 00215 expectedCigarHex.push_back(0x10); 00216 expected0BasedAlignmentEnd = expectedRecord.myPosition + 6; 00217 expected1BasedAlignmentEnd = expected0BasedAlignmentEnd + 1; 00218 expectedAlignmentLength = 7; 00219 expected0BasedUnclippedStart = expectedRecord.myPosition; 00220 expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1; 00221 expected0BasedUnclippedEnd = expected0BasedAlignmentEnd; 00222 expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1; 00223 expectedRecord.myBlockSize = 95; 00224 expectedRecord.myReadNameLength = 27; 00225 expectedRecord.myCigarLength = 7; 00226 expectedRecord.myReadLength = 5; 00227 expectedQuality = "I00??"; 00228 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00229 validateEqRead(samRecord, 18, READ_SEQS_MIXED[18]); 00230 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00231 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00232 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00233 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00234 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00235 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00236 00237 expectedCigar = "2M2N2M"; 00238 expectedCigarHex.clear(); 00239 expectedCigarHex.push_back(0x20); 00240 expectedCigarHex.push_back(0x23); 00241 expectedCigarHex.push_back(0x20); 00242 expected0BasedAlignmentEnd = expectedRecord.myPosition + 5; 00243 expected1BasedAlignmentEnd = expected0BasedAlignmentEnd + 1; 00244 expectedAlignmentLength = 6; 00245 expected0BasedUnclippedStart = expectedRecord.myPosition; 00246 expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1; 00247 expected0BasedUnclippedEnd = expected0BasedAlignmentEnd; 00248 expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1; 00249 expectedRecord.myBlockSize = 74; 00250 expectedRecord.myReadNameLength = 24; 00251 expectedRecord.myCigarLength = 3; 00252 expectedRecord.myReadLength = 4; 00253 expectedQuality = "I00?"; 00254 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00255 validateEqRead(samRecord, 19, READ_SEQS_MIXED[19]); 00256 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00257 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00258 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00259 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00260 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00261 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00262 00263 // Test getNextMatchMismatch. 00264 SamSingleBaseMatchInfo matchTest; 00265 SamQuerySeqWithRefIter queryIter(samRecord, reference, true); 00266 assert(queryIter.getNextMatchMismatch(matchTest) == true); 00267 assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH); 00268 assert(matchTest.getQueryIndex() == 0); 00269 assert(queryIter.getNextMatchMismatch(matchTest) == true); 00270 assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH); 00271 assert(matchTest.getQueryIndex() == 1); 00272 assert(queryIter.getNextMatchMismatch(matchTest) == true); 00273 assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH); 00274 assert(matchTest.getQueryIndex() == 2); 00275 assert(queryIter.getNextMatchMismatch(matchTest) == true); 00276 assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH); 00277 assert(matchTest.getQueryIndex() == 3); 00278 assert(queryIter.getNextMatchMismatch(matchTest) == false); 00279 00280 // Check the read that is on a different chormosome not 00281 // found in the reference. 00282 reset(); 00283 expectedRecord.myBlockSize = 56; 00284 expectedRecord.myReadNameLength = 14; 00285 expectedRecord.myReferenceID = 1; 00286 expectedReferenceName = "2"; 00287 expectedRecord.myMateReferenceID = 1; 00288 expectedMateReferenceName = "2"; 00289 00290 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00291 validateEqRead(samRecord, 20, READ_SEQS_MIXED[20]); 00292 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00293 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00294 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00295 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00296 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00297 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00298 00299 // Check the read that is on a different chormosome and 00300 // has '=', but the chromosome is not found in the reference. 00301 reset(); 00302 expectedRecord.myBlockSize = 57; 00303 expectedRecord.myReadNameLength = 15; 00304 expectedRecord.myReferenceID = 1; 00305 expectedReferenceName = "2"; 00306 expectedRecord.myMateReferenceID = 1; 00307 expectedMateReferenceName = "2"; 00308 00309 assert(inSam.ReadRecord(samHeader, samRecord) == true); 00310 validateEqRead(samRecord, 21, READ_SEQS_MIXED[21]); 00311 assert(outBasesSam.WriteRecord(samHeader, samRecord)); 00312 assert(outEqualsSam.WriteRecord(samHeader, samRecord)); 00313 assert(outOrigSam.WriteRecord(samHeader, samRecord)); 00314 assert(outBasesBam.WriteRecord(samHeader, samRecord)); 00315 assert(outEqualsBam.WriteRecord(samHeader, samRecord)); 00316 assert(outOrigBam.WriteRecord(samHeader, samRecord)); 00317 00318 SamQuerySeqWithRefIter queryIter2(samRecord, reference, true); 00319 assert(queryIter2.getNextMatchMismatch(matchTest) == false); 00320 } 00321 00322 00323 void EqualsTest::reset() 00324 { 00325 expectedReferenceName = "1"; 00326 expectedMateReferenceName = "1"; 00327 expectedMateReferenceNameOrEqual = "="; 00328 expectedCigar = "4M"; 00329 expectedQuality = "I00?"; 00330 00331 // The First cigar is 4M which is 4 << 4 | 0 = 0x40 = 64 00332 expectedCigarHex.clear(); 00333 expectedCigarHex.push_back(0x40); 00334 00335 expectedRecord.myBlockSize = 50; 00336 expectedRecord.myReferenceID = 0; 00337 expectedRecord.myPosition = 10010; 00338 expectedRecord.myReadNameLength = 8; 00339 expectedRecord.myMapQuality = 0; 00340 expectedRecord.myBin = 4681; 00341 expectedRecord.myCigarLength = 1; 00342 expectedRecord.myFlag = 73; 00343 expectedRecord.myReadLength = 4; 00344 expectedRecord.myMateReferenceID = 0; 00345 expectedRecord.myMatePosition = 10008; 00346 expectedRecord.myInsertSize = 0; 00347 00348 expected0BasedAlignmentEnd = 10013; 00349 expected1BasedAlignmentEnd = expected0BasedAlignmentEnd + 1; 00350 expectedAlignmentLength = 4; 00351 expected0BasedUnclippedStart = expectedRecord.myPosition; 00352 expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1; 00353 expected0BasedUnclippedEnd = expected0BasedAlignmentEnd; 00354 expected1BasedUnclippedEnd = expected1BasedAlignmentEnd; 00355 } 00356 00357 void EqualsTest::validateEqRead(SamRecord& samRecord, 00358 int readIndex, 00359 const char* actualExpectedSequence) 00360 { 00361 char tag[3]; 00362 char type; 00363 void* value; 00364 00365 ////////////////////////////////////////// 00366 // Validate Record 1 00367 // Check the alignment end 00368 assert(samRecord.get0BasedAlignmentEnd() == expected0BasedAlignmentEnd); 00369 assert(samRecord.get1BasedAlignmentEnd() == expected1BasedAlignmentEnd); 00370 assert(samRecord.getAlignmentLength() == expectedAlignmentLength); 00371 assert(samRecord.get0BasedUnclippedStart() == expected0BasedUnclippedStart); 00372 assert(samRecord.get1BasedUnclippedStart() == expected1BasedUnclippedStart); 00373 assert(samRecord.get0BasedUnclippedEnd() == expected0BasedUnclippedEnd); 00374 assert(samRecord.get1BasedUnclippedEnd() == expected1BasedUnclippedEnd); 00375 00376 // Check the accessors. 00377 assert(samRecord.getBlockSize() == expectedRecord.myBlockSize); 00378 assert(samRecord.getReferenceID() == expectedRecord.myReferenceID); 00379 assert(strcmp(samRecord.getReferenceName(), expectedReferenceName) == 0); 00380 assert(samRecord.get1BasedPosition() == expectedRecord.myPosition + 1); 00381 assert(samRecord.get0BasedPosition() == expectedRecord.myPosition); 00382 assert(samRecord.getReadNameLength() == 00383 expectedRecord.myReadNameLength); 00384 assert(samRecord.getMapQuality() == expectedRecord.myMapQuality); 00385 assert(samRecord.getBin() == expectedRecord.myBin); 00386 assert(samRecord.getCigarLength() == expectedRecord.myCigarLength); 00387 assert(samRecord.getFlag() == expectedRecord.myFlag); 00388 assert(samRecord.getReadLength() == expectedRecord.myReadLength); 00389 assert(samRecord.getMateReferenceID() == 00390 expectedRecord.myMateReferenceID); 00391 assert(strcmp(samRecord.getMateReferenceName(), 00392 expectedMateReferenceName) == 0); 00393 assert(strcmp(samRecord.getMateReferenceNameOrEqual(), 00394 expectedMateReferenceNameOrEqual) == 0); 00395 assert(samRecord.get1BasedMatePosition() == 00396 expectedRecord.myMatePosition + 1); 00397 assert(samRecord.get0BasedMatePosition() == 00398 expectedRecord.myMatePosition); 00399 assert(samRecord.getInsertSize() == expectedRecord.myInsertSize); 00400 assert(strcmp(samRecord.getReadName(), READ_NAMES[readIndex]) == 0); 00401 assert(strcmp(samRecord.getCigar(), expectedCigar) == 0); 00402 samRecord.setSequenceTranslation(SamRecord::BASES); 00403 assert(strcmp(samRecord.getSequence(), READ_SEQS_BASES[readIndex]) == 0); 00404 assert(strcmp(samRecord.getQuality(), expectedQuality) == 0); 00405 00406 assert(samRecord.getSequence(0) == READ_SEQS_BASES[readIndex][0]); 00407 assert(samRecord.getQuality(0) == expectedQuality[0]); 00408 assert(samRecord.getSequence(1)== READ_SEQS_BASES[readIndex][1]); 00409 assert(samRecord.getQuality(1) == expectedQuality[1]); 00410 assert(samRecord.getSequence(2) == READ_SEQS_BASES[readIndex][2]); 00411 assert(samRecord.getQuality(2) == expectedQuality[2]); 00412 assert(samRecord.getSequence(3) == READ_SEQS_BASES[readIndex][3]); 00413 assert(samRecord.getQuality(3) == expectedQuality[3]); 00414 00415 assert(strcmp(samRecord.getSequence(SamRecord::EQUAL), 00416 READ_SEQS_EQUALS[readIndex]) == 0); 00417 assert(samRecord.getSequence(0, SamRecord::EQUAL) == 00418 READ_SEQS_EQUALS[readIndex][0]); 00419 assert(samRecord.getQuality(0) == expectedQuality[0]); 00420 assert(samRecord.getSequence(1, SamRecord::EQUAL) == 00421 READ_SEQS_EQUALS[readIndex][1]); 00422 assert(samRecord.getQuality(1) == expectedQuality[1]); 00423 assert(samRecord.getSequence(2, SamRecord::EQUAL) == 00424 READ_SEQS_EQUALS[readIndex][2]); 00425 assert(samRecord.getQuality(2) == expectedQuality[2]); 00426 assert(samRecord.getSequence(3, SamRecord::EQUAL) == 00427 READ_SEQS_EQUALS[readIndex][3]); 00428 assert(samRecord.getQuality(3) == expectedQuality[3]); 00429 00430 assert(strcmp(samRecord.getSequence(SamRecord::NONE), 00431 actualExpectedSequence) == 0); 00432 assert(samRecord.getSequence(0, SamRecord::NONE) == 00433 actualExpectedSequence[0]); 00434 assert(samRecord.getQuality(0) == expectedQuality[0]); 00435 assert(samRecord.getSequence(1, SamRecord::NONE) == 00436 actualExpectedSequence[1]); 00437 assert(samRecord.getQuality(1) == expectedQuality[1]); 00438 assert(samRecord.getSequence(2, SamRecord::NONE) == 00439 actualExpectedSequence[2]); 00440 assert(samRecord.getQuality(2) == expectedQuality[2]); 00441 assert(samRecord.getSequence(3, SamRecord::NONE) == 00442 actualExpectedSequence[3]); 00443 assert(samRecord.getQuality(3) == expectedQuality[3]); 00444 00445 samRecord.setSequenceTranslation(SamRecord::NONE); 00446 assert(strcmp(samRecord.getSequence(), 00447 actualExpectedSequence) == 0); 00448 assert(samRecord.getSequence(0) == 00449 actualExpectedSequence[0]); 00450 assert(samRecord.getQuality(0) == expectedQuality[0]); 00451 assert(samRecord.getSequence(1) == 00452 actualExpectedSequence[1]); 00453 assert(samRecord.getQuality(1) == expectedQuality[1]); 00454 assert(samRecord.getSequence(2) == 00455 actualExpectedSequence[2]); 00456 assert(samRecord.getQuality(2) == expectedQuality[2]); 00457 assert(samRecord.getSequence(3) == 00458 actualExpectedSequence[3]); 00459 assert(samRecord.getQuality(3) == expectedQuality[3]); 00460 00461 // No tags, should return false. 00462 00463 assert(samRecord.getNextSamTag(tag, type, &value) == false); 00464 00465 // Get the record ptr. 00466 samRecord.setSequenceTranslation(SamRecord::BASES); 00467 validateEqReadBuffer(samRecord, READ_SEQS_BASES[readIndex]); 00468 samRecord.setSequenceTranslation(SamRecord::NONE); 00469 validateEqReadBuffer(samRecord, actualExpectedSequence); 00470 samRecord.setSequenceTranslation(SamRecord::EQUAL); 00471 validateEqReadBuffer(samRecord, READ_SEQS_EQUALS[readIndex]); 00472 } 00473 00474 00475 void EqualsTest::validateEqReadBuffer(SamRecord& samRecord, 00476 const char* expectedSequence) 00477 { 00478 const bamRecordStruct* bufferPtr; 00479 unsigned char* varPtr; 00480 00481 bufferPtr = (const bamRecordStruct*)samRecord.getRecordBuffer(); 00482 // Validate the buffers match. 00483 assert(bufferPtr->myBlockSize == expectedRecord.myBlockSize); 00484 assert(bufferPtr->myReferenceID == expectedRecord.myReferenceID); 00485 assert(bufferPtr->myPosition == expectedRecord.myPosition); 00486 assert(bufferPtr->myReadNameLength == expectedRecord.myReadNameLength); 00487 assert(bufferPtr->myMapQuality == expectedRecord.myMapQuality); 00488 assert(bufferPtr->myBin == expectedRecord.myBin); 00489 assert(bufferPtr->myCigarLength == expectedRecord.myCigarLength); 00490 assert(bufferPtr->myFlag == expectedRecord.myFlag); 00491 assert(bufferPtr->myReadLength == expectedRecord.myReadLength); 00492 assert(bufferPtr->myMateReferenceID == 00493 expectedRecord.myMateReferenceID); 00494 assert(bufferPtr->myMatePosition == expectedRecord.myMatePosition); 00495 assert(bufferPtr->myInsertSize == expectedRecord.myInsertSize); 00496 00497 // Validate the variable length fields in the buffer. 00498 // Set the pointer to the start of the variable fields. 00499 varPtr = (unsigned char*)(&(bufferPtr->myData[0])); 00500 00501 // Validate the readname. 00502 for(int i = 0; i < expectedRecord.myReadNameLength; i++) 00503 { 00504 assert(*varPtr == samRecord.getReadName()[i]); 00505 varPtr++; 00506 } 00507 00508 // Validate the cigar. 00509 for(int i = 0; i < expectedRecord.myCigarLength; i++) 00510 { 00511 assert(*(unsigned int*)varPtr == expectedCigarHex[i]); 00512 // Increment the varptr the size of an int. 00513 varPtr += 4; 00514 } 00515 00516 // Validate the sequence. 00517 int expectedSeqHex = 0; 00518 for(int i = 0; i < expectedRecord.myReadLength; i++) 00519 { 00520 int hexChar = 0x0; 00521 switch(expectedSequence[i]) 00522 { 00523 case '=': 00524 hexChar = 0x0; 00525 break; 00526 case 'A': 00527 case 'a': 00528 hexChar = 0x1; 00529 break; 00530 case 'C': 00531 case 'c': 00532 hexChar = 0x2; 00533 break; 00534 case 'G': 00535 case 'g': 00536 hexChar = 0x4; 00537 break; 00538 case 'T': 00539 case 't': 00540 hexChar = 0x8; 00541 break; 00542 case 'N': 00543 case 'n': 00544 hexChar = 0xF; 00545 break; 00546 } 00547 if(i%2 == 0) 00548 { 00549 expectedSeqHex = hexChar << 4; 00550 } 00551 else 00552 { 00553 expectedSeqHex |= hexChar; 00554 assert(*varPtr == expectedSeqHex); 00555 varPtr++; 00556 } 00557 } 00558 if((expectedRecord.myReadLength%2) != 0) 00559 { 00560 // Odd number of sequences, so need to check the last one. 00561 assert(*varPtr == expectedSeqHex); 00562 varPtr++; 00563 } 00564 00565 // Validate the Quality 00566 for(int i = 0; i < expectedRecord.myReadLength; i++) 00567 { 00568 assert(*varPtr == samRecord.getQuality()[i] - 33); 00569 varPtr++; 00570 } 00571 00572 } 00573 00574