libStatGen Software 1
Loading...
Searching...
No Matches
ShiftIndels.cpp
1/*
2 * Copyright (C) 2011 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ShiftIndels.h"
19#include "SamFile.h"
20
21void testShiftIndels()
22{
23 ShiftIndelsTest::testShift("testFiles/testShift.sam", "results/testShift.sam");
24#ifdef __ZLIB_AVAILABLE__
25 ShiftIndelsTest::testShift("testFiles/testShift.bam", "results/testShift.bam");
26 ShiftIndelsTest::testShift("testFiles/testShift.bam", "results/testShiftFromBam.sam");
27#endif
28 ShiftIndelsTest::testShift("testFiles/testShift.sam", "results/testShiftFromSam.bam");
29}
30
31void ShiftIndelsTest::testShift(const char* input, const char* output)
32{
33 SamFile inSam, outSam;
34
35 assert(inSam.OpenForRead(input));
36 assert(outSam.OpenForWrite(output));
37
38
39 // Read the SAM Header.
40 SamFileHeader samHeader;
41 assert(inSam.ReadHeader(samHeader));
42 assert(outSam.WriteHeader(samHeader));
43
44
45 SamRecord samRecord;
46 int readNum = 1;
47 bool shiftResult = true;
48 while(inSam.ReadRecord(samHeader, samRecord))
49 {
50 if((readNum == 3)|| (readNum == 5))
51 {
52 shiftResult = false;
53 }
54 else
55 {
56 shiftResult = true;
57 }
58 ++readNum;
59
60 assert(samRecord.shiftIndelsLeft() == shiftResult);
61 assert(outSam.WriteRecord(samHeader, samRecord));
62 }
63
64}
This class allows a user to get/set the fields in a SAM/BAM Header.
Allows the user to easily read/write a SAM/BAM file.
Definition SamFile.h:36
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
Definition SamFile.cpp:450
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
Definition SamFile.cpp:514
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
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
bool WriteHeader(SamFileHeader &header)
Writes the specified header into the file.
Definition SamFile.cpp:480
bool WriteRecord(SamFileHeader &header, SamRecord &record)
Writes the specified record into the file.
Definition SamFile.cpp:632
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition SamRecord.h:52
bool shiftIndelsLeft()
Shift the indels (if any) to the left by updating the CIGAR.