PileupReader.h

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 #ifndef _PILEUP_READER_H
00019 #define _PILEUP_READER_H
00020 
00021 #include <list>
00022 #include <stdint.h>
00023 #include <string>
00024 #include <queue>
00025 
00026 #include "SamFile.h"
00027 
00072 
00081 class ReadBase {
00082     SamRecord   *_samRecord;
00083     int         _deletedBaseCount;   // how many bases, including this one, are deleted
00084     int         _insertedBasesOverlapping;
00085     bool        _InsertionFollowing;        // THIS read contains an insertion immediately after this base
00086 
00087     // More private state is needed - e.g. offset and length into read.
00088     // But also cigar string parsing state information - probably need
00089     // a small common state class used here and in ReadInsertion
00090 public:
00091     ReadBase() : _deletedBaseCount(0), _insertedBasesOverlapping(0), _InsertionFollowing(false) {;}
00092 
00093     bool set(SamRecord &, int basePosition);
00094 
00095     char getBase();
00096     char getPhredQualityChar();
00097     int  getPhredQualityScore();
00098 
00099     int  getDeletedBaseCount();
00100     int  getInsertedBasesOverlapping();
00101 
00102     bool hasInsertionFollowing();
00103 };
00104 
00109 class ReadInsertion {
00110     SamRecord *_samRecord;
00111     // More private state is needed - e.g. offset and length into read.
00112     // But also cigar string parsing state information - probably need
00113     // a small common state class used here and in ReadBase
00114 public:
00115     bool set(SamRecord &r);
00116 
00118     bool        getQualities(std::string &phredQualities);
00119     bool        getBases(std::string &bases);
00120 
00122     int         getQualities(char *phredQualities, int maxLength);
00123     int         getBases(char *bases, int maxLength);
00124 
00125     uint8_t     getMapQuality();
00126     uint16_t    getSAMFlag();
00127     SamRecord & getSamRecord();
00128 };
00129 
00142 class SequenceCoverageReader {
00143 
00144 private:
00145     SamFile&    _samFile;
00146     int         _referenceID;
00147     uint32_t    _position;
00148     bool        _useIndex;
00149     std::list<SamRecord *>    _samRecords;    // list of ptrs to records that overlap the last read pileup position
00150     std::queue<SamRecord *> _unused;         // fifo to recliam pre-allocated records from
00151 
00152 public:
00153 
00154     SequenceCoverageReader(SamFile &samFile) :
00155         _samFile(samFile),
00156         _referenceID(0),
00157         _position(0),
00158         _useIndex(true)
00159         { ; }
00160 
00161     void useIndex(bool u=true) { _useIndex = u; }
00162 
00185     bool getBases(int32_t referenceID, uint32_t position, std::vector<ReadBase> &readBases, bool &basesInserted);
00186 
00187     bool getInsertedBases(int referenceID, uint32_t position, std::vector<ReadInsertion> &readInsertions);
00188 
00189 };
00190 
00191 
00192 #endif
Generated on Tue Nov 9 16:11:48 2010 for StatGen Software by  doxygen 1.6.3