EqualsTest Class Reference

## Public Types

enum | FileType { SAM , BAM }

## Static Public Member Functions

static void | testEq (FileType inputType)

## Detailed Description

Definition at line 21 of file TestEquals.h.

## Member Enumeration Documentation

## FileType

enum EqualsTest::FileType

Definition at line 24 of file TestEquals.h.

{SAM, BAM};

## Member Function Documentation

## testEq()

void EqualsTest::testEq | ( | FileType | inputType | ) |

static

Definition at line 71 of file TestEquals.cpp.

{
reset();
SamFile inSam;
std::string outputBase = "results/out";
if(inputType == SAM)
{
assert(inSam.OpenForRead("testFiles/testEq.sam"));
outputBase += "SamEq";
}
else
{
assert(inSam.OpenForRead("testFiles/testEq.bam"));
outputBase += "BamEq";
}
// Read the SAM Header.
SamFileHeader samHeader;
assert(inSam.ReadHeader(samHeader));
std::string outputName = outputBase + "Bases.sam";
SamFile outBasesSam( outputName.c_str(), SamFile::WRITE);
outputName = outputBase + "Equals.sam";
SamFile outEqualsSam(outputName.c_str(), SamFile::WRITE);
outputName = outputBase + "Orig.sam";
SamFile outOrigSam( outputName.c_str(), SamFile::WRITE);
outputName = outputBase + "Bases.bam";
SamFile outBasesBam( outputName.c_str(), SamFile::WRITE);
outputName = outputBase + "Equals.bam";
SamFile outEqualsBam(outputName.c_str(), SamFile::WRITE);
outputName = outputBase + "Orig.bam";
SamFile outOrigBam( outputName.c_str(), SamFile::WRITE);
assert(outBasesSam.WriteHeader(samHeader));
assert(outEqualsSam.WriteHeader(samHeader));
assert(outOrigSam.WriteHeader(samHeader));
assert(outBasesBam.WriteHeader(samHeader));
assert(outEqualsBam.WriteHeader(samHeader));
assert(outOrigBam.WriteHeader(samHeader));
outBasesSam.SetWriteSequenceTranslation(SamRecord::BASES);
outEqualsSam.SetWriteSequenceTranslation(SamRecord::EQUAL);
outOrigSam.SetWriteSequenceTranslation(SamRecord::NONE);
outBasesBam.SetWriteSequenceTranslation(SamRecord::BASES);
outEqualsBam.SetWriteSequenceTranslation(SamRecord::EQUAL);
outOrigBam.SetWriteSequenceTranslation(SamRecord::NONE);
GenomeSequence reference("testFiles/chr1_partial.fa");
inSam.SetReference(&reference);
SamRecord samRecord;
// The set of 16 variations are repeated 3 times: once with all charcters
// 1) Matches have the actual bases in them.
// 2) Matches have '='
// 3) Matches are mixed between bases and '='
// Since Sequences are 4 characters long, there are 16 variations
// of match/mismatch.
for(int j = 0; j < 16; j++)
{
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, j, READ_SEQS_BASES[j]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
}
for(int j = 0; j < 16; j++)
{
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, j, READ_SEQS_EQUALS[j]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
}
for(int j = 0; j < 16; j++)
{
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, j, READ_SEQS_MIXED[j]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
}
expectedCigar = "2S4M";
expectedCigarHex.clear();
expectedCigarHex.push_back(0x24);
expectedCigarHex.push_back(0x40);
expected0BasedUnclippedStart = expectedRecord.myPosition-2;
expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1;
expectedRecord.myBlockSize = 70;
expectedRecord.myReadNameLength = 21;
expectedRecord.myCigarLength = 2;
expectedRecord.myReadLength = 6;
expectedQuality = "??I00?";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 16, READ_SEQS_MIXED[16]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
expectedCigar = "4M4H";
expectedCigarHex.clear();
expectedCigarHex.push_back(0x40);
expectedCigarHex.push_back(0x45);
expected0BasedUnclippedStart = expectedRecord.myPosition;
expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1;
expected0BasedUnclippedEnd = expectedRecord.myPosition + 7;
expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1;
expectedRecord.myBlockSize = 65;
expectedRecord.myReadNameLength = 19;
expectedRecord.myCigarLength = 2;
expectedRecord.myReadLength = 4;
expectedQuality = "I00?";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 17, READ_SEQS_MIXED[17]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
expectedCigar = "1M1P1M1I1M3D1M";
expectedCigarHex.clear();
expectedCigarHex.push_back(0x10);
expectedCigarHex.push_back(0x16);
expectedCigarHex.push_back(0x10);
expectedCigarHex.push_back(0x11);
expectedCigarHex.push_back(0x10);
expectedCigarHex.push_back(0x32);
expectedCigarHex.push_back(0x10);
expected0BasedAlignmentEnd = expectedRecord.myPosition + 6;
expected1BasedAlignmentEnd = expected0BasedAlignmentEnd + 1;
expectedAlignmentLength = 7;
expected0BasedUnclippedStart = expectedRecord.myPosition;
expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1;
expected0BasedUnclippedEnd = expected0BasedAlignmentEnd;
expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1;
expectedRecord.myBlockSize = 95;
expectedRecord.myReadNameLength = 27;
expectedRecord.myCigarLength = 7;
expectedRecord.myReadLength = 5;
expectedQuality = "I00??";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 18, READ_SEQS_MIXED[18]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
expectedCigar = "2M2N2M";
expectedCigarHex.clear();
expectedCigarHex.push_back(0x20);
expectedCigarHex.push_back(0x23);
expectedCigarHex.push_back(0x20);
expected0BasedAlignmentEnd = expectedRecord.myPosition + 5;
expected1BasedAlignmentEnd = expected0BasedAlignmentEnd + 1;
expectedAlignmentLength = 6;
expected0BasedUnclippedStart = expectedRecord.myPosition;
expected1BasedUnclippedStart = expected0BasedUnclippedStart + 1;
expected0BasedUnclippedEnd = expected0BasedAlignmentEnd;
expected1BasedUnclippedEnd = expected0BasedUnclippedEnd + 1;
expectedRecord.myBlockSize = 74;
expectedRecord.myReadNameLength = 24;
expectedRecord.myCigarLength = 3;
expectedRecord.myReadLength = 4;
expectedQuality = "I00?";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 19, READ_SEQS_MIXED[19]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
// Test getNextMatchMismatch.
SamSingleBaseMatchInfo matchTest;
SamQuerySeqWithRefIter queryIter(samRecord, reference, true);
assert(queryIter.getNextMatchMismatch(matchTest) == true);
assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH);
assert(matchTest.getQueryIndex() == 0);
assert(queryIter.getNextMatchMismatch(matchTest) == true);
assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH);
assert(matchTest.getQueryIndex() == 1);
assert(queryIter.getNextMatchMismatch(matchTest) == true);
assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH);
assert(matchTest.getQueryIndex() == 2);
assert(queryIter.getNextMatchMismatch(matchTest) == true);
assert(matchTest.getType() == SamSingleBaseMatchInfo::MATCH);
assert(matchTest.getQueryIndex() == 3);
assert(queryIter.getNextMatchMismatch(matchTest) == false);
// Check the read that is on a different chormosome not
// found in the reference.
reset();
expectedRecord.myBlockSize = 56;
expectedRecord.myReadNameLength = 14;
expectedRecord.myReferenceID = 1;
expectedReferenceName = "2";
expectedRecord.myMateReferenceID = 1;
expectedMateReferenceName = "2";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 20, READ_SEQS_MIXED[20]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
// Check the read that is on a different chormosome and
// has '=', but the chromosome is not found in the reference.
reset();
expectedRecord.myBlockSize = 57;
expectedRecord.myReadNameLength = 15;
expectedRecord.myReferenceID = 1;
expectedReferenceName = "2";
expectedRecord.myMateReferenceID = 1;
expectedMateReferenceName = "2";
assert(inSam.ReadRecord(samHeader, samRecord) == true);
validateEqRead(samRecord, 21, READ_SEQS_MIXED[21]);
assert(outBasesSam.WriteRecord(samHeader, samRecord));
assert(outEqualsSam.WriteRecord(samHeader, samRecord));
assert(outOrigSam.WriteRecord(samHeader, samRecord));
assert(outBasesBam.WriteRecord(samHeader, samRecord));
assert(outEqualsBam.WriteRecord(samHeader, samRecord));
assert(outOrigBam.WriteRecord(samHeader, samRecord));
SamQuerySeqWithRefIter queryIter2(samRecord, reference, true);
assert(queryIter2.getNextMatchMismatch(matchTest) == false);
}
GenomeSequence
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
Definition: GenomeSequence.h:100
SamFileHeader
This class allows a user to get/set the fields in a SAM/BAM Header.
Definition: SamFileHeader.h:35
SamFile
Allows the user to easily read/write a SAM/BAM file.
Definition: SamFile.h:36
SamFile::ReadHeader
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
Definition: SamFile.cpp:450
SamFile::ReadRecord
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
Definition: SamFile.cpp:514
SamFile::SetReference
void SetReference(GenomeSequence *reference)
Sets the reference to the specified genome sequence object.
Definition: SamFile.cpp:380
SamFile::WRITE
@ WRITE
open for writing.
Definition: SamFile.h:41
SamFile::OpenForRead
bool OpenForRead(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for reading with the specified filename, determing the type of file and SAM/BAM b...
Definition: SamFile.cpp:93
SamQuerySeqWithRefIter
Iterates through the query and compare with reference.
Definition: SamQuerySeqWithRefHelper.h:59
SamRecord
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition: SamRecord.h:52
SamRecord::NONE
@ NONE
Leave the sequence as is.
Definition: SamRecord.h:58
SamRecord::BASES
@ BASES
Translate '=' to the actual base.
Definition: SamRecord.h:60
SamRecord::EQUAL
@ EQUAL
Translate bases that match the reference to '='.
Definition: SamRecord.h:59
SamSingleBaseMatchInfo
This class contains the match/mismatch information between the reference and a read for a single base...
Definition: SamQuerySeqWithRefHelper.h:29
SamSingleBaseMatchInfo::getQueryIndex
int32_t getQueryIndex()
Get the query index for this object.
Definition: SamQuerySeqWithRefHelper.cpp:224
SamSingleBaseMatchInfo::getType
Type getType()
Get the type (match/mismatch/unknown) for this object.
Definition: SamQuerySeqWithRefHelper.cpp:218

The documentation for this class was generated from the following files:

- bam/test/TestEquals.h
- bam/test/TestEquals.cpp