libStatGen Software 1
Loading...
Searching...
No Matches
PileupElement.cpp
1/*
2 * Copyright (C) 2010 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 "PileupElement.h"
19
20
21GenomeSequence* PileupElement::myRefPtr = NULL;
22
23
25 : myRefPosition(UNSET_POSITION),
26 myChromosome("")
27{
28}
29
30
31// NOTE that this method does not actually copy, it just resets.
33 : myRefPosition(UNSET_POSITION),
34 myChromosome("")
35{
36}
37
41
42
43// Add an entry to this pileup element.
45{
46 if(myChromosome.empty())
47 {
48 // First entry, save chromosme name.
49 myChromosome = record.getReferenceName();
50 }
51}
52
53
54// Perform the alalysis associated with this class. May be a simple print,
55// a calculation, or something else. Typically performed when this element
56// has been fully populated by all records that cover the reference position.
58{
59 if(myRefPosition != UNSET_POSITION)
60 {
61 std::cout << myChromosome << "\t" << myRefPosition << "\n";
62 }
63}
64
65
66// Resets the entry, setting the new position associated with this element.
67void PileupElement::reset(int32_t refPosition)
68{
69 myChromosome.clear();
70 myRefPosition = refPosition;
71}
72
73
75{
76 if(myRefPtr != NULL)
77 {
78 // Add 1 to pos because getBase expects 1-based index.
79 return(myRefPtr->getBase(myChromosome.c_str(), myRefPosition+1));
80 }
81 return('N');
82}
83
84
85// Resets the entry, setting the new position associated with this element.
87{
88 myRefPtr = reference;
89}
Create/Access/Modify/Load Genome Sequences stored as binary mapped files.
char getBase(const char *chromosomeName, unsigned int chromosomeIndex) const
given a chromosome name and 1-based position, return the reference base.
This is a base class pileup component, representing the information for one reference position.
static void setReference(GenomeSequence *reference)
Set the reference to use for all pilepElements.
PileupElement()
Pileup element constructor.
virtual void addEntry(SamRecord &record)
Add an entry to this pileup element.
virtual void analyze()
Perform the analysis associated with this class.
virtual ~PileupElement()
Pileup element destructor.
virtual void reset(int32_t refPosition)
Resets the entry, setting the new position associated with this element.
char getRefBase()
Returns the reference base for this pileup element.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition SamRecord.h:52
const char * getReferenceName()
Get the reference sequence name (RNAME) of the record.