ShiftIndels.cpp
/*
* Copyright (C) 2011 Regents of the University of Michigan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ShiftIndels.h"
#include "SamFile.h"
void testShiftIndels()
{
ShiftIndelsTest::testShift("testFiles/testShift.sam", "results/testShift.sam");
#ifdef __ZLIB_AVAILABLE__
ShiftIndelsTest::testShift("testFiles/testShift.bam", "results/testShift.bam");
ShiftIndelsTest::testShift("testFiles/testShift.bam", "results/testShiftFromBam.sam");
#endif
ShiftIndelsTest::testShift("testFiles/testShift.sam", "results/testShiftFromSam.bam");
}
void ShiftIndelsTest::testShift(const char* input, const char* output)
{
SamFile inSam, outSam;
assert(inSam.OpenForRead(input));
assert(outSam.OpenForWrite(output));
// Read the SAM Header.
SamFileHeader samHeader;
assert(inSam.ReadHeader(samHeader));
assert(outSam.WriteHeader(samHeader));
SamRecord samRecord;
int readNum = 1;
bool shiftResult = true;
while(inSam.ReadRecord(samHeader, samRecord))
{
if((readNum == 3)|| (readNum == 5))
{
shiftResult = false;
}
else
{
shiftResult = true;
}
++readNum;
assert(samRecord.shiftIndelsLeft() == shiftResult);
assert(outSam.WriteRecord(samHeader, samRecord));
}
}
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::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
SamFile::OpenForWrite
bool OpenForWrite(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for writing with the specified filename, determining SAM/BAM from the extension (...
Definition: SamFile.cpp:223
SamFile::WriteHeader
bool WriteHeader(SamFileHeader &header)
Writes the specified header into the file.
Definition: SamFile.cpp:480
SamFile::WriteRecord
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
Definition: SamFile.cpp:632
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::shiftIndelsLeft
bool shiftIndelsLeft()
Shift the indels (if any) to the left by updating the CIGAR.
Definition: SamRecord.cpp:368