libStatGen Software  1
TestSamRecordHelper.cpp
1 /*
2  * Copyright (C) 2012 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 "TestSamRecordHelper.h"
19 #include "TestValidate.h"
20 #include "SamRecordHelper.h"
21 #include <assert.h>
22 
23 void testSamRecordHelper()
24 {
25  // Call generic test.
26  SamRecordHelperTest::testSamRecordHelper("testFiles/testSam.sam");
27  // SamRecordHelperTest::testSamRecordHelper("testFiles/testBam.bam");
28 }
29 
30 
31 void SamRecordHelperTest::testSamRecordHelper(const char* fileName)
32 {
33  SamFile inSam;
34  assert(inSam.OpenForRead(fileName));
35  SamFileHeader samHeader;
36  assert(inSam.ReadHeader(samHeader));
37  validateHeader(samHeader);
38 
39  SamRecord samRecord;
40  assert(inSam.ReadRecord(samHeader, samRecord) == true);
41  validateRead1(samRecord);
42 
43  // Validate the entire sequence matches.
44  assert(SamRecordHelper::checkSequence(samRecord,
45  TestValidate::READ1_POS,
46  TestValidate::READ1_SEQ.c_str()) == 0);
47 
48  // The read start position is 1010.
49  // The sequence is CCGAA.
50  assert(SamRecordHelper::checkSequence(samRecord, 1010, "CCGAA") == 0);
51 
52  // Test not matching.
53  assert(SamRecordHelper::checkSequence(samRecord, 1010, "NNNNN") == -1);
54 
55  // Test match, but not at the start.
56  assert(SamRecordHelper::checkSequence(samRecord, 1011, "CGA") == 1);
57 
58  // Test match not at the start, but to the end.
59  assert(SamRecordHelper::checkSequence(samRecord, 1011, "CGAA") == 1);
60 
61  // Test run over the end.
62  assert(SamRecordHelper::checkSequence(samRecord, 1011, "CGAAC") == -1);
63 
64 }
65 
66 
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:501
SamRecordHelper::checkSequence
static int checkSequence(SamRecord &record, int32_t pos0Based, const char *sequence)
Helper method that checks if the record's read sequence starting at the specified 0-based reference p...
Definition: SamRecordHelper.cpp:21
SamFileHeader
This class allows a user to get/set the fields in a SAM/BAM Header.
Definition: SamFileHeader.h:35
SamRecord
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition: SamRecord.h:52
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::ReadHeader
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
Definition: SamFile.cpp:437
SamFile
Allows the user to easily read/write a SAM/BAM file.
Definition: SamFile.h:36