libMems/gnRAWSequence.h

Go to the documentation of this file.
00001 
00002 // File:            gnRAWSequence.h
00003 // Purpose:         Optimized Sequence class for RAW sequence files
00004 // Description:     Provides a high level sequence interface to all types of
00005 //                                      sequence data.
00006 // Changes:        
00007 // Version:         libGenome 0.5.1 
00008 // Author:          Aaron Darling 
00009 // Modified by:     
00010 // Copyright:       (c) Aaron Darling 
00011 // Licenses:        See COPYING file for details 
00013 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #ifndef _gnRAWSequence_h_
00019 #define _gnRAWSequence_h_
00020 
00021 #include "libGenome/gnDefs.h"
00022 
00023 #include <string>
00024 #include <iostream>
00025 #include <list>
00026 #include "libGenome/gnSequence.h"
00027 
00028 namespace genome {
00029 
00030 
00035 class GNDLLEXPORT gnRAWSequence : public gnSequence
00036 {
00037 public:
00041         gnRAWSequence();
00045         gnRAWSequence( const std::string& filename )
00046         {
00047                 this->filename = filename;
00048                 data.open( filename );
00049         }
00050 
00051         gnRAWSequence* Clone() const {return new gnRAWSequence(*this);}
00052 
00053         gnSeqI contigListSize() const {return 1;}
00054         gnSeqI contigListLength() const {return 1;}
00055         uint32 contigIndexByBase( const gnSeqI baseI) const {
00056                 if(baseI >= data.size()) Throw_gnEx(SeqIndexOutOfBounds());
00057                 return 0;
00058         }
00059         gnRAWSequence contig( const uint32 contigI) const { 
00060                 if(contigI>0) Throw_gnEx(FragmentIndexOutOfBounds()); 
00061                 return *this;
00062         }
00063         gnRAWSequence contigByBase( const gnSeqI baseI) const {
00064                 if(baseI >= data.size()) Throw_gnEx(SeqIndexOutOfBounds());
00065                 return *this;
00066         }
00067         virtual gnSeqI contigStart( const uint32 contigI) const {
00068                 if(contigI>0) Throw_gnEx(FragmentIndexOutOfBounds()); 
00069                 return 0;
00070         }
00071         virtual gnSeqI contigLength( const uint32 contigI) const {
00072                 if(contigI>0) Throw_gnEx(FragmentIndexOutOfBounds()); 
00073                 return data.size();
00074         }
00075         virtual uint32 contigIndexByName( std::string& contigName) const {
00076                 return 0;
00077         }
00078         virtual std::string contigName( const uint32 contigI) const {
00079                 if(contigI>0) Throw_gnEx(FragmentIndexOutOfBounds()); 
00080                 return "";
00081         }
00082         virtual gnSequence contigByName( std::string& contigName) const {
00083                 Throw_gnEx(FragmentIndexOutOfBounds());
00084         }
00085         virtual void merge(const gnSeqI startI, const gnSeqI endI){ throw; }
00086         virtual void mergeContigs(const uint32 startC, const uint32 endC){ throw; }
00087         virtual void splitContig(const gnSeqI splitI, const uint32 contigI=ALL_CONTIGS) { throw; }
00088 
00089         virtual void setContigName( const uint32 contigI, const std::string& contig_name) { throw; }
00090 
00091         virtual uint32 getFeatureListLength() const {
00092                 return 0;
00093         }
00094         virtual gnBaseFeature* getFeature(const uint32 featureI) const{ Throw_gnEx(FeatureIndexOutOfBounds()); }
00095         virtual void getContainedFeatures(const gnLocation& lt, std::vector<gnBaseFeature*>& feature_vector, std::vector<uint32>& index_vector) const {}
00096         virtual void getIntersectingFeatures(const gnLocation& lt, std::vector<gnBaseFeature*>& feature_vector, std::vector<uint32>& index_vector) const {}
00097         virtual uint32 addFeature(gnBaseFeature* feature) { throw; }
00098         virtual void removeFeature(const uint32 featureI){ Throw_gnEx(FeatureIndexOutOfBounds()); }
00099         virtual void getBrokenFeatures(const gnLocation& lt, std::vector<gnBaseFeature*>& feature_vector) const{};
00100         virtual uint32 getHeaderListLength(const uint32 contigI) const{ return 0; }
00101         virtual gnBaseHeader* getHeader(const uint32 contigI, const uint32 headerI) const{Throw_gnEx(HeaderIndexOutOfBounds());};
00102         virtual void addHeader(const uint32 contigI, gnBaseHeader* header, const uint32 headerI){Throw_gnEx(FragmentIndexOutOfBounds());}
00103         virtual void removeHeader(const uint32 contigI, const uint32 headerI){ Throw_gnEx(HeaderIndexOutOfBounds()); }
00104         virtual void setReverseComplement( const boolean revComp, const uint32 contigI=ALL_CONTIGS){Throw_gnEx(FragmentIndexOutOfBounds());};
00105         virtual boolean isReverseComplement( const uint32 contigI=ALL_CONTIGS ){return false;}
00106         virtual boolean isCircular() const{ return false; }
00107         virtual void setCircular( const boolean value ) {}
00108         
00109         virtual void globalToLocal(uint32& contigI, gnSeqI& baseI) const{};
00110         virtual void localToGlobal(const uint32 contigI, gnSeqI& baseI) const {};
00111         virtual void globalToSource(uint32& contigI, gnSeqI& baseI) const{};
00112         virtual void localToSource(uint32& contigI, gnSeqI& baseI) const{};
00113         virtual bool LoadSource(const std::string sourcename){
00114                 data.open( sourcename );
00115                 filename = sourcename;
00116                 return true;
00117         }
00118 
00122         gnRAWSequence& operator+=(const gnRAWSequence& seq);
00123 
00130 /*      virtual int compare(const gnRAWSequence& seq) const;
00131         virtual int compare(const std::string& str) const;
00132 
00133         virtual void append( const gnRAWSequence& seq);
00134         virtual void insert( const gnSeqI offset, const gnSeqC *bases, const gnSeqI length);
00135         virtual void insert( const gnSeqI offset, const gnRAWSequence& seq);
00136         virtual void insert( const gnSeqI offset, const gnGenomeSpec& gnbs);
00137         gnRAWSequence const operator+(const gnRAWSequence& seq) const;
00138         virtual void erase( const gnSeqI offset=0, const gnSeqI length=GNSEQI_END );
00139 */
00140         gnRAWSequence subseq(const gnSeqI offset, const gnSeqI length) const
00141         {
00142                 gnRAWSequence gnrs;
00143                 gnrs.data.open(filename, length, offset - 1);
00144                 return gnrs;
00145         }
00146 //      friend std::istream& operator>>(std::istream& is, gnRAWSequence& gns);  //read from source.
00150 //      friend std::ostream& operator<<(std::ostream& os, const gnRAWSequence& gns); //write to source.
00151 
00152         virtual gnSeqI length() const { return data.size(); }
00153         virtual gnSeqI size() const { return data.size(); }
00154 
00155         virtual std::string ToString( const gnSeqI length=GNSEQI_END, const gnSeqI offset=1 ) const
00156         {
00157                 gnSeqI len = length == GNSEQI_END ?  data.size() - offset - 1 : length;
00158                 std::string asdf(data.data()+offset-1, len);
00159                 return asdf;
00160         }
00161 
00162         virtual boolean ToString( std::string& str, const gnSeqI length=GNSEQI_END, const gnSeqI offset=1 ) const
00163         {
00164                 gnSeqI len = length == GNSEQI_END ? data.size() - offset - 1 : length;
00165                 str.assign(data.data()+offset-1,len);
00166                 return true;
00167         }
00168         virtual boolean ToArray( gnSeqC* pSeqC, gnSeqI length, const gnSeqI offset=1 ) const
00169         {
00170                 gnSeqI len = length == GNSEQI_END ? data.size() - offset - 1 : length;
00171                 memcpy(pSeqC, data.data()+offset-1, len);
00172                 return true;
00173         }
00174         virtual gnSeqC GetSeqC( const gnSeqI offset ) const
00175         {
00176                 return *(data.data()+(offset-1));
00177         }
00178         gnSeqC operator[]( const gnSeqI offset ) const
00179         {
00180                 return *(data.data()+(offset-1));
00181         }
00182 
00183         virtual gnSeqI find(const gnRAWSequence& search, const gnSeqI offset=0) const {return GNSEQI_ERROR;}
00184         
00185 private:
00186         boost::iostreams::mapped_file_source data;
00187         std::string filename;
00188 }; // class gnRAWSequence
00189 
00190 /*
00191 GNDLLEXPORT
00192 std::istream& operator>>(std::istream& is, gnRAWSequence& gns); //read from source.
00193 GNDLLEXPORT
00194 std::ostream& operator<<(std::ostream& os, const gnRAWSequence& gns); //write to source.
00195 */
00196 
00197 
00198 
00199 }       // end namespace genome
00200 
00201 #endif
00202         // _gnRAWSequence_h_

Generated on Fri Mar 14 06:01:03 2008 for libMems by doxygen 1.3.6