GlfRecord.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 __GLF_RECORD_H__
00019 #define __GLF_RECORD_H__
00020 
00021 #include <map>
00022 #include <stdint.h>
00023 
00024 #include "InputFile.h" 
00025 #include "CharBuffer.h"
00026 
00027 class GlfRecord
00028 {
00029 public:
00030     GlfRecord();
00031     ~GlfRecord();
00032 
00033 //     // Copy Constructor   
00034 //     GlfRecord(const GlfRecord& record);
00035 
00036 //     // Overload operator = to copy the passed in record into this record.
00037 //     GlfRecord & operator = (const GlfRecord& record);
00038 
00039 //     // Overload operator = to copy the passed in record into this record.
00040 //     bool copy(const GlfRecord& record);
00041 
00042     void reset();
00043    
00044     // Read the record from the specified file.  Assumes the file is in
00045     // the correct position for reading the record.
00046     bool read(IFILE filePtr);
00047 
00048     // Write the record to the specified file.
00049     bool write(IFILE filePtr) const;
00050 
00051     void print() const;
00052 
00053     // Accessors to set the generic values.
00054     bool setRtypeRef(uint8_t rtypeRef);
00055     bool setRecordType(uint8_t recType);
00056     bool setRefBaseInt(uint8_t refBase);
00057     // TODO   bool setRefBaseChar(char refBase);
00058     bool setOffset(uint32_t offset);
00059     bool setMinDepth(uint32_t minDepth);
00060     bool setMinLk(uint8_t minLk);
00061     bool setReadDepth(uint32_t readDepth);
00062     bool setRmsMapQ(uint8_t rmsMapQ);
00063     
00064     // Accessors for setting record type 1;
00065     //bool setType1(all fields for type 1);
00066     bool setLk(int index, uint8_t value);
00067 
00068     // Accessors for setting record type 2
00069 //     bool setType2(all fields for type 2);
00070     bool setLkHom1(uint8_t lk);
00071     bool setLkHom2(uint8_t lk);
00072     bool setLkHet(uint8_t lk);
00073     bool setInsertionIndel1(const std::string& indelSeq);
00074     bool setDeletionIndel1(const std::string& indelSeq);
00075     bool setInsertionIndel2(const std::string& indelSeq);
00076     bool setDeletionIndel2(const std::string& indelSeq);
00077 
00078     // Accessors to get the generic values.
00079     inline int getRecordType() const
00080     {
00081         return(myRecTypeRefBase >> REC_TYPE_SHIFT);
00082     }
00083     inline int getRefBase() const
00084     {
00085         return(myRecTypeRefBase & REF_BASE_MASK);
00086     }
00087 
00088     char getRefBaseChar() const;
00089     uint32_t getOffset();
00090     uint8_t getMinDepth();
00091     uint8_t getMinLk();
00092     uint32_t getReadDepth();
00093     uint8_t getRmsMapQ();
00094     
00095     // Accessors for getting record type 1;
00096     //bool getType1(all fields for type 1);
00097     uint8_t getLk(int index);
00098     
00099     //     // Accessors for setting record type 1;
00100     //     bool setType2(all fields for type 2);
00101     uint8_t getLkHom1();
00102     uint8_t getLkHom2();
00103     uint8_t getLkHet();
00104     int16_t getIndel1(std::string& indelSeq);
00105     int16_t getIndel2(std::string& indelSeq);
00106     
00107 
00108 private:
00109     // Read a record of record type 1.
00110     void readType1(IFILE filePtr);
00111 
00112     // Read a record of record type 2.
00113     void readType2(IFILE filePtr);
00114 
00115 
00116     // Write the rtyperef field.
00117     void writeRtypeRef(IFILE filePtr) const;
00118 
00119 
00120     // Write a record of record type 1.
00121     void writeType1(IFILE filePtr) const;
00122 
00123     // Write a record of record type 2.
00124     void writeType2(IFILE filePtr) const;
00125 
00126     // Contains record_type and ref_base.
00127     uint8_t myRecTypeRefBase;
00128 
00129     static const uint8_t REC_TYPE_SHIFT = 4;
00130     static const uint8_t REF_BASE_MASK = 0xF;
00131     static const uint8_t REC_TYPE_MASK = 0xF0;
00132 
00133     static const uint32_t MIN_LK_SHIFT = 24;
00134     static const uint32_t READ_DEPTH_MASK = 0xFFFFFF;
00135     static const uint32_t MIN_LK_MASK = 0xFF000000;
00136 
00137     static const char REF_BASE_MAX = 15;
00138     static std::string REF_BASE_CHAR;
00139 
00140     static const int NUM_REC1_LIKELIHOOD = 10;
00141 
00142     struct
00143     {
00144         uint32_t offset;
00145         uint32_t min_depth;
00146         uint8_t rmsMapQ;
00147         uint8_t lk[NUM_REC1_LIKELIHOOD];
00148     } myRec1Base;
00149 
00150     static const int REC1_BASE_SIZE = 19;
00151 
00152     struct
00153     {
00154         uint32_t offset;
00155         uint32_t min_depth;
00156         uint8_t rmsMapQ;
00157         uint8_t lkHom1;
00158         uint8_t lkHom2;
00159         uint8_t lkHet;
00160         int16_t indelLen1;
00161         int16_t indelLen2;
00162     } myRec2Base;
00163 
00164     // TODO rest of rec 2.
00165     CharBuffer myIndelSeq1;
00166     CharBuffer myIndelSeq2;
00167 
00168     static const int REC2_BASE_SIZE = 16;
00169 
00170 };
00171 
00172 #endif
Generated on Tue Nov 9 16:11:49 2010 for StatGen Software by  doxygen 1.6.3