Pileup< PILEUP_TYPE, FUNC_CLASS > Class Template Reference

Class to perform a pileup of all reads by position, assuming the reads are coordinate sorted. More...

#include <Pileup.h>

Collaboration diagram for Pileup< PILEUP_TYPE, FUNC_CLASS >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Pileup (const FUNC_CLASS &fp=FUNC_CLASS())
 Constructor using the default maximum number of bases a read spans.
 Pileup (int window, const FUNC_CLASS &fp=FUNC_CLASS())
 Constructor that sets the maximum number of bases a read spans.
 Pileup (const std::string &refSeqFileName, const FUNC_CLASS &fp=FUNC_CLASS())
 Perform pileup with a reference.
 Pileup (int window, const std::string &refSeqFileName, const FUNC_CLASS &fp=FUNC_CLASS())
 Perform pileup with a reference and a specified window size.
virtual ~Pileup ()
 Destructor.
virtual int processFile (const std::string &fileName, uint16_t excludeFlag=0x0704, uint16_t includeFlag=0)
 Performs a pileup on the specified file.
virtual void processAlignment (SamRecord &record)
 Add an alignment to the pileup.
virtual void processAlignmentRegion (SamRecord &record, int startPos, int endPos, PosList *excludeList=NULL)
 Add only positions that fall within the specified region of the alignment to the pileup and outside of the specified excluded positions.
void flushPileup ()
 Done processing, flush every position that is currently being stored in the pileup.

Protected Member Functions

void addAlignmentPosition (int refPosition, SamRecord &record)
virtual void flushPileup (int refID, int refPosition)
void flushPileup (int refPosition)
int pileupPosition (int refPosition)
virtual void resetElement (PILEUP_TYPE &element, int position)
virtual void addElement (PILEUP_TYPE &element, SamRecord &record)
virtual void analyzeElement (PILEUP_TYPE &element)
virtual void analyzeHead ()

Protected Attributes

FUNC_CLASS myAnalyzeFuncPtr
std::vector< PILEUP_TYPE > myElements
int pileupStart
int pileupHead
int pileupTail
int pileupWindow
int myCurrentRefID
GenomeSequencemyRefPtr

Detailed Description

template<class PILEUP_TYPE, class FUNC_CLASS = defaultPileup<PILEUP_TYPE>>
class Pileup< PILEUP_TYPE, FUNC_CLASS >

Class to perform a pileup of all reads by position, assuming the reads are coordinate sorted.

Definition at line 58 of file Pileup.h.


Constructor & Destructor Documentation

template<class PILEUP_TYPE , class FUNC_CLASS>
Pileup< PILEUP_TYPE, FUNC_CLASS >::Pileup ( int  window,
const FUNC_CLASS &  fp = FUNC_CLASS() 
) [inline]

Constructor that sets the maximum number of bases a read spans.

This is the "window" the length of the buffer that holds the pileups for each position until the read start has moved past the position.

Definition at line 168 of file Pileup.h.

00169     : myAnalyzeFuncPtr(fp),
00170       myElements(),
00171       pileupStart(0),
00172       pileupHead(0),
00173       pileupTail(-1),
00174       pileupWindow(window),
00175       myCurrentRefID(-2),
00176       myRefPtr(NULL)
00177 {
00178     // Not using pointers since this is templated.
00179     myElements.resize(window);
00180 }


Member Function Documentation

template<class PILEUP_TYPE , class FUNC_CLASS >
void Pileup< PILEUP_TYPE, FUNC_CLASS >::flushPileup (  )  [inline]

Done processing, flush every position that is currently being stored in the pileup.

Definition at line 368 of file Pileup.h.

Referenced by Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignment(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignmentRegion(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processFile(), and Pileup< PILEUP_TYPE, FUNC_CLASS >::~Pileup().

00369 {
00370     // while there are still entries between the head and tail, flush,
00371     // but no need to flush if pileupTail == -1 because in that case 
00372     // no entries have been added
00373     while ((pileupHead <= pileupTail) && (pileupTail != -1))
00374     {
00375         flushPileup(pileupHead+1);
00376     }
00377     pileupStart = pileupHead = 0;
00378     pileupTail = -1;
00379 }

template<class PILEUP_TYPE , class FUNC_CLASS >
void Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignmentRegion ( SamRecord record,
int  startPos,
int  endPos,
PosList excludeList = NULL 
) [inline, virtual]

Add only positions that fall within the specified region of the alignment to the pileup and outside of the specified excluded positions.

Parameters:
record alignment to be added to the pileup.
startPos 0-based start position of the bases that should be added to the pileup.
endPos 0-based end position of the bases that should be added to the pileup (this position is not added). Set to -1 if there is no end position to the region.
excludeList list of refID/positions to exclude from processing.

Definition at line 316 of file Pileup.h.

References Pileup< PILEUP_TYPE, FUNC_CLASS >::flushPileup(), SamRecord::get0BasedAlignmentEnd(), SamRecord::get0BasedPosition(), SamRecord::getReferenceID(), and PosList::hasPosition().

00320 {
00321     int refPosition = record.get0BasedPosition();
00322     int refID = record.getReferenceID();
00323 
00324     // Flush any elements from the pileup that are prior to this record
00325     // since the file is sorted, we are done with those positions.
00326     flushPileup(refID, refPosition);
00327     
00328     // Check if the region starts after this reference starts.  If so,
00329     // we only want to start adding at the region start position.
00330     if(startPos > refPosition)
00331     {
00332         refPosition = startPos;
00333     }
00334 
00335     // Loop through for each reference position covered by the record.
00336     // It is up to the PILEUP_TYPE to handle insertions/deletions, etc
00337     // that are related with the given reference position.
00338     for(; refPosition <= record.get0BasedAlignmentEnd(); ++refPosition)
00339     {
00340         // Check to see if we have gone past the end of the region, in which
00341         // case we can stop processing this record.  Check >= since the
00342         // end position is not in the region.
00343         if((endPos != -1) && (refPosition >= endPos))
00344         {
00345             break;
00346         }
00347 
00348         // Check to see if this position is in the exclude list.
00349         bool addPos = true;
00350         if(excludeList != NULL)
00351         {
00352             // There is an exclude list, so lookup the position.
00353             if(excludeList->hasPosition(refID, refPosition))
00354             {
00355                 // This position is in the exclude list, so don't add it.
00356                 addPos = false;
00357             }
00358         }
00359         if(addPos)
00360         {
00361             addAlignmentPosition(refPosition, record);
00362         }
00363     }
00364 }

template<class PILEUP_TYPE , class FUNC_CLASS >
int Pileup< PILEUP_TYPE, FUNC_CLASS >::processFile ( const std::string &  fileName,
uint16_t  excludeFlag = 0x0704,
uint16_t  includeFlag = 0 
) [inline, virtual]

Performs a pileup on the specified file.

Parameters:
excludeFlag if specified, if any bit set in the exclude flag is set in the record's flag, it will be dropped. Defaulted to exclude: unmapped, not primary alignment failed platform/vendor quality check PCR or optical duplicate
includeFlag if specified, every bit must be set in the record's flag for it to be included - defaulted to 0, no bits are required to be set.
Returns:
0 for success and non-zero for failure.

Definition at line 235 of file Pileup.h.

References SamFile::COORDINATE, Pileup< PILEUP_TYPE, FUNC_CLASS >::flushPileup(), SamRecord::getFlag(), SamFile::GetStatus(), SamFile::GetStatusMessage(), StatGenStatus::NO_MORE_RECS, SamFile::OpenForRead(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignment(), SamFile::ReadHeader(), SamFile::ReadRecord(), SamFile::SetReference(), and SamFile::setSortedValidation().

00238 {
00239     SamFile samIn;
00240     SamFileHeader header;
00241     SamRecord record;
00242     
00243     if(myRefPtr != NULL)
00244     {
00245         samIn.SetReference(myRefPtr);
00246     }
00247 
00248     if(!samIn.OpenForRead(fileName.c_str()))
00249     {
00250         fprintf(stderr, "%s\n", samIn.GetStatusMessage());
00251         return(samIn.GetStatus());
00252     }
00253     
00254     if(!samIn.ReadHeader(header))
00255     {
00256         fprintf(stderr, "%s\n", samIn.GetStatusMessage());
00257         return(samIn.GetStatus());
00258     }
00259 
00260     // The file needs to be sorted by coordinate.
00261     samIn.setSortedValidation(SamFile::COORDINATE);
00262 
00263     // Iterate over all records
00264     while (samIn.ReadRecord(header, record))
00265     {
00266         uint16_t flag = record.getFlag();
00267         if(flag & excludeFlag)
00268         {
00269             // This record has an excluded flag set, 
00270             // so continue to the next one.
00271             continue;
00272         }
00273         if((flag & includeFlag) != includeFlag)
00274         {
00275             // This record does not have all required flags set, 
00276             // so continue to the next one.
00277             continue;
00278         }
00279         processAlignment(record);
00280     }
00281 
00282     flushPileup();
00283 
00284     int returnValue = 0;
00285     if(samIn.GetStatus() != SamStatus::NO_MORE_RECS)
00286     {
00287         // Failed to read a record.
00288         fprintf(stderr, "%s\n", samIn.GetStatusMessage());
00289         returnValue = samIn.GetStatus();
00290     }
00291     return(returnValue);  
00292 }


The documentation for this class was generated from the following file:
Generated on Mon Feb 11 13:45:25 2013 for libStatGen Software by  doxygen 1.6.3