libStatGen Software  1
PileupElement.cpp
00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include "PileupElement.h"
00019 
00020 
00021 GenomeSequence* PileupElement::myRefPtr = NULL;
00022 
00023 
00024 PileupElement::PileupElement()
00025     : myRefPosition(UNSET_POSITION),
00026       myChromosome("")
00027 {
00028 }
00029 
00030 
00031 // NOTE that this method does not actually copy, it just resets.
00032 PileupElement::PileupElement(const PileupElement& q)
00033     : myRefPosition(UNSET_POSITION),
00034       myChromosome("")
00035 {
00036 }
00037 
00038 PileupElement::~PileupElement()
00039 {
00040 }
00041 
00042 
00043 // Add an entry to this pileup element.  
00044 void PileupElement::addEntry(SamRecord& record)
00045 {
00046     if(myChromosome.empty())
00047     {
00048         // First entry, save chromosme name.
00049         myChromosome = record.getReferenceName();
00050     }
00051 }
00052 
00053 
00054 // Perform the alalysis associated with this class.  May be a simple print, 
00055 // a calculation, or something else.  Typically performed when this element
00056 // has been fully populated by all records that cover the reference position.
00057 void PileupElement::analyze()
00058 {
00059     if(myRefPosition != UNSET_POSITION)
00060     {
00061         std::cout << myChromosome << "\t" << myRefPosition << "\n";
00062     }
00063 }
00064 
00065 
00066 // Resets the entry, setting the new position associated with this element.
00067 void PileupElement::reset(int32_t refPosition)
00068 {
00069     myChromosome.clear();
00070     myRefPosition = refPosition;
00071 }
00072 
00073 
00074 char PileupElement::getRefBase()
00075 {
00076     if(myRefPtr != NULL)
00077     {
00078         // Add 1 to pos because getBase expects 1-based index.
00079         return(myRefPtr->getBase(myChromosome.c_str(), myRefPosition+1));
00080     }
00081     return('N');
00082 }
00083 
00084 
00085 // Resets the entry, setting the new position associated with this element.
00086 void PileupElement::setReference(GenomeSequence* reference)
00087 {
00088     myRefPtr = reference;
00089 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends