halapi hierarchichalalignmentformatapi

- Main Page
- Namespaces
- Classes
- Files

- File List

hdf5_impl/hdf5DNAIterator.h

    00001 /*
    00002  * Copyright (C) 2012 by Glenn Hickey (hickey@soe.ucsc.edu)
    00003  *
    00004  * Released under the MIT license, see LICENSE.txt
    00005  */
    00006
    00007 #ifndef _HDF5DNAITERATOR_H
    00008 #define _HDF5DNAITERATOR_H
    00009
    00010 #include <cassert>
    00011 #include <H5Cpp.h>
    00012 #include "halDNAIterator.h"
    00013 #include "halCommon.h"
    00014 #include "hdf5ExternalArray.h"
    00015 #include "hdf5Genome.h"
    00016 #include "hdf5DNA.h"
    00017
    00018 namespace hal {
    00019
    00020 class HDF5DNAIterator : public DNAIterator
    00021 {
    00022 public:
    00023
    00024    HDF5DNAIterator(HDF5Genome* genome, hal_index_t index);
    00025    ~HDF5DNAIterator();
    00026
    00027    hal_dna_t getChar() const;
    00028    hal_dna_t getCompChar() const;
    00029    void setChar(hal_dna_t c);
    00030    void toLeft() const;
    00031    void toRight() const;
    00032    void jumpTo(hal_size_t index) const;
    00033    const Genome* getGenome() const;
    00034    Genome* getGenome();
    00035    hal_index_t getArrayIndex() const;
    00036
    00037    void readString(std::string& outString, hal_size_t length,
    00038                    hal_bool_t reversed = false) const;
    00039
    00040    void writeString(const std::string& inString, hal_size_t length,
    00041                     hal_bool_t reversed = false);
    00042
    00043    inline bool inRange() const;
    00044
    00045 protected:
    00046    mutable hal_index_t _index;
    00047    mutable HDF5Genome* _genome;
    00048 };
    00049
    00050 inline bool HDF5DNAIterator::inRange() const
    00051 {
    00052   return _index >= 0 &&
    00053      _index < (hal_index_t)_genome->_dnaArray.getSize();
    00054 }
    00055
    00056 inline hal_dna_t HDF5DNAIterator::getChar() const
    00057 {
    00058   assert(inRange() == true);
    00059   return _genome->_dnaArray.getValue<hal_dna_t>(_index, 0);
    00060 }
    00061
    00062 inline hal_dna_t  HDF5DNAIterator::getCompChar() const
    00063 {
    00064   assert(inRange() == true);
    00065   return reverseComplement(getChar());
    00066 }
    00067
    00068 inline void HDF5DNAIterator::setChar(hal_dna_t c)
    00069 {
    00070   if (inRange() == false)
    00071   {
    00072     throw hal_exception("Trying to set character out of range");
    00073   }
    00074   _genome->_dnaArray.setValue(_index, 0, c);
    00075 }
    00076
    00077 inline void HDF5DNAIterator::toLeft() const
    00078 {
    00079   --_index;
    00080 }
    00081
    00082 inline void HDF5DNAIterator::toRight() const
    00083 {
    00084   ++_index;
    00085 }
    00086
    00087 inline void HDF5DNAIterator::jumpTo(hal_size_t index) const
    00088 {
    00089   _index = static_cast<hal_index_t>(index);
    00090 }
    00091
    00092 inline const Genome* HDF5DNAIterator::getGenome() const
    00093 {
    00094   return _genome;
    00095 }
    00096
    00097 inline Genome* HDF5DNAIterator::getGenome()
    00098 {
    00099   return _genome;
    00100 }
    00101
    00102 inline hal_index_t HDF5DNAIterator::getArrayIndex() const
    00103 {
    00104   return _index;
    00105 }
    00106
    00107 inline void HDF5DNAIterator::readString(std::string& outString,
    00108                                         hal_size_t length,
    00109                                         hal_bool_t reversed) const
    00110 {
    00111   assert(inRange() == true);
    00112   outString.resize(length);
    00113   if (reversed == false)
    00114   {
    00115     for (hal_size_t i = 0; i < length; ++i)
    00116     {
    00117       outString[i] = getChar();
    00118       toRight();
    00119     }
    00120   }
    00121   else
    00122   {
    00123     for (hal_index_t i = length - 1; i >= 0; --i)
    00124     {
    00125       outString[i] = getCompChar();
    00126       toRight();
    00127     }
    00128   }
    00129 }
    00130
    00131 inline void HDF5DNAIterator::writeString(const std::string& inString,
    00132                                          hal_size_t length,
    00133                                          hal_bool_t reversed)
    00134 {
    00135   assert(inRange() == true);
    00136   if (reversed == false)
    00137   {
    00138     for (hal_size_t i = 0; i < length; ++i)
    00139     {
    00140       setChar(inString[i]);
    00141       toRight();
    00142     }
    00143   }
    00144   else
    00145   {
    00146     for (hal_index_t i = length - 1; i >= 0; --i)
    00147     {
    00148       setChar(reverseComplement(inString[i]));
    00149       toRight();
    00150     }
    00151   }
    00152 }
    00153
    00154 }
    00155 #endif

All Classes Namespaces Functions Variables Friends