Main.cpp
/*
* Copyright (C) 2010 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 "SamFile.h"
#include "Pileup.h"
#include "PileupElementBaseQual.h"
void newAnalyze(PileupElementBaseQual& element)
{
std::cout << "newAnalyze: ";
element.analyze();
}
class AnalyzeClass
{
public:
AnalyzeClass()
{
myCounter = 33;
}
bool operator() (PileupElementBaseQual& element)
{
std::cout << "Class Analyze: Counter = " << myCounter << ": ";
element.analyze();
++myCounter;
return(true);
}
int myCounter;
private:
};
int main(int argc, char ** argv)
{
const char* fileName = "../../test/testFiles/sortedBam.bam";
const char* indexName = "../../test/testFiles/sortedBam.bam.bai";
printf("\nPileup<PileupElementBaseQual> on entire file: %s\n", fileName);
Pileup<PileupElementBaseQual> pileup(1024);
pileup.processFile(fileName);
printf("\nPileup<PileupElement> on entire file: %s\n", fileName);
Pileup<PileupElement> pileup1(1024);
pileup1.processFile(fileName);
printf("\nPileup<PileupElementBaseQual> on a section of file: %s\n", fileName);
// Read a sorted & indexed BAM file.
Pileup<PileupElementBaseQual> pileup2(100);
SamFile samIn;
SamFileHeader header;
SamRecord record;
if(!samIn.OpenForRead(fileName))
{
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
return(samIn.GetStatus());
}
// Open the bam index file for reading.
if(!samIn.ReadBamIndex(indexName))
{
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
return(samIn.GetStatus());
}
if(!samIn.ReadHeader(header))
{
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
return(samIn.GetStatus());
}
const char* refName = "1";
int start = 1000;
int end = 1500;
if(!samIn.SetReadSection(refName, start, end))
{
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
return(samIn.GetStatus());
}
// Iterate over all records
while (samIn.ReadRecord(header, record))
{
pileup2.processAlignment(record);
}
pileup2.flushPileup();
int returnValue = 0;
if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
{
// Failed to read a record.
fprintf(stderr, "%s\n", samIn.GetStatusMessage());
returnValue = samIn.GetStatus();
}
printf("\nPileup<PileupElementBaseQual> on entire file, newAnalyze: %s\n", fileName);
void (*fnPtr)(PileupElementBaseQual&) = newAnalyze;
Pileup<PileupElementBaseQual, void (*)(PileupElementBaseQual&)> pileup3(1024, fnPtr);
pileup3.processFile(fileName);
printf("\nPileup<PileupElementBaseQual> on entire file, newAnalyze: %s\n", fileName);
AnalyzeClass myAnalyzeClass;
myAnalyzeClass.myCounter = 2;
Pileup<PileupElementBaseQual, AnalyzeClass> pileup4(1024, myAnalyzeClass);
pileup4.processFile(fileName);
return(0);
}
AnalyzeClass
Definition: Main.cpp:30
PileupElementBaseQual
This class inherits from the base class and stores base and qualities.
Definition: PileupElementBaseQual.h:26
PileupElementBaseQual::analyze
virtual void analyze()
Perform the analysis associated with this class.
Definition: PileupElementBaseQual.cpp:144
Pileup
Class to perform a pileup of all reads by position, assuming the reads are coordinate sorted.
Definition: Pileup.h:59
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::GetStatusMessage
const char * GetStatusMessage()
Get the Status Message of the last call that sets status.
Definition: SamFile.h:218
SamFile::SetReadSection
bool SetReadSection(int32_t refID)
Sets which reference id (index into the BAM list of reference information) of the BAM file should be ...
Definition: SamFile.cpp:696
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::GetStatus
SamStatus::Status GetStatus()
Get the Status of the last call that sets status.
Definition: SamFile.h:212
SamFile::ReadBamIndex
bool ReadBamIndex(const char *filename)
Read the specified bam index file.
Definition: SamFile.cpp:300
SamRecord
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition: SamRecord.h:52
StatGenStatus::NO_MORE_RECS
@ NO_MORE_RECS
NO_MORE_RECS: failed to read a record since there are no more to read either in the file or section i...
Definition: StatGenStatus.h:36