libStatGen Software 1
Loading...
Searching...
No Matches
PileupElementBaseQual Class Reference

This class inherits from the base class and stores base and qualities. More...

#include <PileupElementBaseQual.h>

Inheritance diagram for PileupElementBaseQual:
Collaboration diagram for PileupElementBaseQual:

Public Member Functions

 PileupElementBaseQual (const PileupElementBaseQual &q)
virtual void addEntry (SamRecord &record)
 Add an entry to this pileup element.
virtual void analyze ()
 Perform the analysis associated with this class.
virtual void reset (int32_t refPosition)
 Resets the entry, setting the new position associated with this element.
Public Member Functions inherited from PileupElement
 PileupElement ()
 Pileup element constructor.
 PileupElement (const PileupElement &q)
 Constructor that resets the pileup element, does not copy, just resets.
virtual ~PileupElement ()
 Pileup element destructor.
const char * getChromosome () const
 Get the chromosome name stored in this element.
int32_t getRefPosition () const
 Get the reference position stored in this element.
char getRefBase ()
 Returns the reference base for this pileup element.

Additional Inherited Members

Static Public Member Functions inherited from PileupElement
static void setReference (GenomeSequence *reference)
 Set the reference to use for all pilepElements.
Static Public Attributes inherited from PileupElement
static const int32_t UNSET_POSITION = -1
Static Protected Member Functions inherited from PileupElement
static GenomeSequencegetReference ()
 Get a pointer to the reference.

Detailed Description

This class inherits from the base class and stores base and qualities.

Definition at line 25 of file PileupElementBaseQual.h.

Constructor & Destructor Documentation

◆ PileupElementBaseQual() [1/2]

PileupElementBaseQual::PileupElementBaseQual ( )

Definition at line 22 of file PileupElementBaseQual.cpp.

23 : PileupElement(),
24 myBases(NULL),
25 myQualities(NULL),
26 myAllocatedSize(0),
27 myIndex(-1),
28 myAddDelAsBase(false)
29{
30 myAllocatedSize = 1024;
31 myBases = (char*)malloc(myAllocatedSize + 1);
32 myQualities = (char*)malloc(myAllocatedSize + 1);
33 if((myBases == NULL ) || (myQualities == NULL))
34 {
35 // TODO, check for malloc failures.
36 std::cerr << "Failed Memory Allocation\n";
37 }
38}
PileupElement()
Pileup element constructor.

◆ PileupElementBaseQual() [2/2]

PileupElementBaseQual::PileupElementBaseQual ( const PileupElementBaseQual & q)

Definition at line 41 of file PileupElementBaseQual.cpp.

42 : PileupElement(),
43 myBases(NULL),
44 myQualities(NULL),
45 myAllocatedSize(0),
46 myIndex(-1)
47{
48 myAllocatedSize = 1024;
49 myBases = (char*)malloc(myAllocatedSize + 1);
50 myQualities = (char*)malloc(myAllocatedSize + 1);
51 myAddDelAsBase = q.myAddDelAsBase;
52 if((myBases == NULL ) || (myQualities == NULL))
53 {
54 // TODO, check for malloc failures.
55 std::cerr << "Failed Memory Allocation\n";
56 }
57}

◆ ~PileupElementBaseQual()

PileupElementBaseQual::~PileupElementBaseQual ( )
virtual

Definition at line 60 of file PileupElementBaseQual.cpp.

61{
62 if(myBases != NULL)
63 {
64 free(myBases);
65 myBases = NULL;
66 }
67 if(myQualities != NULL)
68 {
69 free(myQualities);
70 myQualities = NULL;
71 }
72}

Member Function Documentation

◆ addEntry()

void PileupElementBaseQual::addEntry ( SamRecord & record)
virtual

Add an entry to this pileup element.

Reimplemented from PileupElement.

Definition at line 76 of file PileupElementBaseQual.cpp.

77{
78 // Call the base class:
80
81 // Increment the index
82 ++myIndex;
83
84 // if the index has gone beyond the allocated space, double the size.
85 if(myIndex >= myAllocatedSize)
86 {
87 char* tempBuffer = (char*)realloc(myBases, myAllocatedSize * 2);
88 if(tempBuffer == NULL)
89 {
90 std::cerr << "Memory Allocation Failure\n";
91 // TODO
92 return;
93 }
94 myBases = tempBuffer;
95 tempBuffer = (char*)realloc(myQualities, myAllocatedSize * 2);
96 if(tempBuffer == NULL)
97 {
98 std::cerr << "Memory Allocation Failure\n";
99 // TODO
100 return;
101 }
102 myQualities = tempBuffer;
103 myAllocatedSize = myAllocatedSize * 2;
104 }
105
106 Cigar* cigar = record.getCigarInfo();
107
108 if(cigar == NULL)
109 {
110 throw std::runtime_error("Failed to retrieve cigar info from the record.");
111 }
112
113
114 int32_t readIndex =
116
117 // If the readPosition is N/A, this is a deletion.
118 if(readIndex != CigarRoller::INDEX_NA)
119 {
120 char base = record.getSequence(readIndex);
121 char qual = record.getQuality(readIndex);
122 if(qual == UNSET_QUAL)
123 {
124 qual = ' ';
125 }
126 myBases[myIndex] = base;
127 myQualities[myIndex] = qual;
128 }
129 else if(myAddDelAsBase)
130 {
131 // This version adds deletions as bases.
132 myBases[myIndex] = '-';
133 myQualities[myIndex] = '0';
134 }
135 else
136 {
137 // Do not add a deletion.
138 // Did not add any entries, so decrement the index counter since the
139 // index was not used.
140 --myIndex;
141 }
142}
static const int32_t INDEX_NA
Value associated with an index that is not applicable/does not exist, used for converting between que...
Definition Cigar.h:492
int32_t getQueryIndex(int32_t refOffset)
Return the query index associated with the specified reference offset or INDEX_NA based on this cigar...
Definition Cigar.cpp:202
int32_t getRefPosition() const
Get the reference position stored in this element.
virtual void addEntry(SamRecord &record)
Add an entry to this pileup element.
Cigar * getCigarInfo()
Returns a pointer to the Cigar object associated with this record.
int32_t get0BasedPosition()
Get the 0-based(BAM) leftmost position of the record.
const char * getQuality()
Returns the SAM formatted quality string (QUAL).
const char * getSequence()
Returns the SAM formatted sequence string (SEQ), translating the base as specified by setSequenceTran...

References PileupElement::addEntry(), SamRecord::get0BasedPosition(), SamRecord::getCigarInfo(), SamRecord::getQuality(), Cigar::getQueryIndex(), PileupElement::getRefPosition(), SamRecord::getSequence(), and Cigar::INDEX_NA.

◆ analyze()

void PileupElementBaseQual::analyze ( )
virtual

Perform the analysis associated with this class.

Reimplemented from PileupElement.

Reimplemented in TestPileupElement.

Definition at line 144 of file PileupElementBaseQual.cpp.

145{
146 if(getRefPosition() != UNSET_POSITION)
147 {
148 myBases[myIndex+1] = '\0';
149 myQualities[myIndex+1] = '\0';
150 std::cout << getChromosome() << "\t" << getRefPosition() << "\tN\t" << myIndex+1 << "\t";
151 std::cout << myBases << "\t";
152 std::cout << myQualities;
153 std::cout << "\n";
154 }
155}
const char * getChromosome() const
Get the chromosome name stored in this element.

References PileupElement::getChromosome(), and PileupElement::getRefPosition().

◆ reset()

void PileupElementBaseQual::reset ( int32_t refPosition)
virtual

Resets the entry, setting the new position associated with this element.

Reimplemented from PileupElement.

Definition at line 157 of file PileupElementBaseQual.cpp.

158{
159 // Call the base class.
160 PileupElement::reset(refPosition);
161
162 myIndex = -1;
163}
virtual void reset(int32_t refPosition)
Resets the entry, setting the new position associated with this element.

References PileupElement::reset().


The documentation for this class was generated from the following files: