⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seq_vector_ci.hpp

📁 ncbi源码
💻 HPP
字号:
/* * =========================================================================== * PRODUCTION $Log: seq_vector_ci.hpp,v $ * PRODUCTION Revision 1000.3  2004/06/01 19:21:44  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * PRODUCTION * =========================================================================== */#ifndef SEQ_VECTOR_CI__HPP#define SEQ_VECTOR_CI__HPP/*  $Id: seq_vector_ci.hpp,v 1000.3 2004/06/01 19:21:44 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Author: Aleksey Grichenko, Michael Kimelman, Eugene Vasilchenko** File Description:*   Seq-vector iterator**/#include <objmgr/seq_map_ci.hpp>#include <objects/seq/Seq_data.hpp>BEGIN_NCBI_SCOPEclass CRandom;BEGIN_SCOPE(objects)class CSeqVector;class CNcbi2naRandomizer;class NCBI_XOBJMGR_EXPORT CSeqVector_CI{public:    typedef unsigned char TResidue;    typedef TResidue value_type;    typedef CSeq_data::E_Choice   TCoding;    CSeqVector_CI(void);    ~CSeqVector_CI(void);    CSeqVector_CI(const CSeqVector& seq_vector, TSeqPos pos = 0);    CSeqVector_CI(const CSeqVector_CI& sv_it);    CSeqVector_CI& operator=(const CSeqVector_CI& sv_it);    bool operator==(const CSeqVector_CI& iter) const;    bool operator!=(const CSeqVector_CI& iter) const;    bool operator<(const CSeqVector_CI& iter) const;    bool operator>(const CSeqVector_CI& iter) const;    bool operator>=(const CSeqVector_CI& iter) const;    bool operator<=(const CSeqVector_CI& iter) const;    // Fill the buffer string with the sequence data for the interval    // [start, stop).    void GetSeqData(TSeqPos start, TSeqPos stop, string& buffer);    // Fill the buffer string with the count bytes of sequence data    // starting with current iterator position    void GetSeqData(string& buffer, TSeqPos count);    CSeqVector_CI& operator++(void);    CSeqVector_CI& operator--(void);    TSeqPos GetPos(void) const;    CSeqVector_CI& SetPos(TSeqPos pos);    TCoding GetCoding(void) const;    void SetCoding(TCoding coding);    void SetRandomizeAmbiguities(void);    void SetRandomizeAmbiguities(Uint4 seed);    void SetRandomizeAmbiguities(CRandom& random_gen);    void SetNoAmbiguities(void);    TResidue operator*(void) const;    operator bool(void) const;    CSeqVector_CI& operator+=(TSeqPos value);    CSeqVector_CI& operator-=(TSeqPos value);private:    TSeqPos x_GetSize(void) const;    TCoding x_GetCoding(TCoding cacheCoding, TCoding dataCoding) const;    void x_SetPos(TSeqPos pos);    void x_InitializeCache(void);    void x_DestroyCache(void);    void x_ClearCache(void);    void x_ResizeCache(size_t size);    void x_SwapCache(void);    void x_UpdateCacheUp(TSeqPos pos);    void x_UpdateCacheDown(TSeqPos pos);    void x_FillCache(TSeqPos start, TSeqPos count);    void x_UpdateSeg(TSeqPos pos);    void x_InitSeg(TSeqPos pos);    void x_InitRandomizer(CRandom& random_gen);    void x_NextCacheSeg(void);    void x_PrevCacheSeg(void);    TSeqPos x_CachePos(void) const;    TSeqPos x_CacheSize(void) const;    TSeqPos x_CacheEndPos(void) const;    TSeqPos x_BackupPos(void) const;    TSeqPos x_BackupSize(void) const;    TSeqPos x_BackupEndPos(void) const;    TSeqPos x_CacheOffset(void) const;    void x_ResetCache(void);    void x_ResetBackup(void);    friend class CSeqVector;    void x_SetVector(CSeqVector& seq_vector);    typedef char* TCacheData;    typedef char* TCache_I;    CConstRef<CSeqMap>       m_SeqMap;    CHeapScope               m_Scope;    ENa_strand               m_Strand;    TCoding                  m_Coding;    // Current CSeqMap segment    CSeqMap_CI               m_Seg;    // Current cache pointer    TCache_I                 m_Cache;    // Current cache    TSeqPos                  m_CachePos;    TCacheData               m_CacheData;    TCache_I                 m_CacheEnd;    // Backup cache    TSeqPos                  m_BackupPos;    TCacheData               m_BackupData;    TCache_I                 m_BackupEnd;    CRef<CNcbi2naRandomizer> m_Randomizer;};/////////////////////////////////////////////////////////////////////////  Inline methods///////////////////////////////////////////////////////////////////////inlineCSeqVector_CI::TCoding CSeqVector_CI::GetCoding(void) const{    return m_Coding;}inlineTSeqPos CSeqVector_CI::x_CachePos(void) const{    return m_CachePos;}inlineTSeqPos CSeqVector_CI::x_CacheSize(void) const{    return m_CacheEnd - m_CacheData;}inlineTSeqPos CSeqVector_CI::x_CacheEndPos(void) const{    return x_CachePos() + x_CacheSize();}inlineTSeqPos CSeqVector_CI::x_BackupPos(void) const{    return m_BackupPos;}inlineTSeqPos CSeqVector_CI::x_BackupSize(void) const{    return m_BackupEnd - m_BackupData;}inlineTSeqPos CSeqVector_CI::x_BackupEndPos(void) const{    return x_BackupPos() + x_BackupSize();}inlineTSeqPos CSeqVector_CI::x_CacheOffset(void) const{    return m_Cache - m_CacheData;}inlineTSeqPos CSeqVector_CI::GetPos(void) const{    return x_CachePos() + x_CacheOffset();}inlinevoid CSeqVector_CI::x_ResetBackup(void){    m_BackupEnd = m_BackupData;}inlinevoid CSeqVector_CI::x_ResetCache(void){    m_Cache = m_CacheEnd = m_CacheData;}inlinevoid CSeqVector_CI::x_SwapCache(void){    swap(m_CacheData, m_BackupData);    swap(m_CacheEnd, m_BackupEnd);    swap(m_CachePos, m_BackupPos);    m_Cache = m_CacheData;}inlineCSeqVector_CI& CSeqVector_CI::SetPos(TSeqPos pos){    TCache_I cache = m_CacheData;    TSeqPos offset = pos - m_CachePos;    TSeqPos size = m_CacheEnd - cache;    if ( offset >= size ) {        x_SetPos(pos);    }    else {        m_Cache = cache + offset;    }    return *this;}inlineCSeqVector_CI::operator bool(void) const{    return m_Cache < m_CacheEnd;}inlinebool CSeqVector_CI::operator==(const CSeqVector_CI& iter) const{    return GetPos() == iter.GetPos();}inlinebool CSeqVector_CI::operator!=(const CSeqVector_CI& iter) const{    return GetPos() != iter.GetPos();}inlinebool CSeqVector_CI::operator<(const CSeqVector_CI& iter) const{    return GetPos() < iter.GetPos();}inlinebool CSeqVector_CI::operator>(const CSeqVector_CI& iter) const{    return GetPos() > iter.GetPos();}inlinebool CSeqVector_CI::operator<=(const CSeqVector_CI& iter) const{    return GetPos() <= iter.GetPos();}inlinebool CSeqVector_CI::operator>=(const CSeqVector_CI& iter) const{    return GetPos() >= iter.GetPos();}inlineCSeqVector_CI::TResidue CSeqVector_CI::operator*(void) const{    _ASSERT(*this);    return *m_Cache;}inlineCSeqVector_CI& CSeqVector_CI::operator++(void){    _ASSERT(*this);    if ( ++m_Cache >= m_CacheEnd ) {        x_NextCacheSeg();    }    return *this;}inlineCSeqVector_CI& CSeqVector_CI::operator--(void){    TCache_I cache = m_Cache;    if ( cache == m_CacheData ) {        x_PrevCacheSeg();    }    else {        m_Cache = cache - 1;    }    return *this;}inlinevoid CSeqVector_CI::GetSeqData(TSeqPos start, TSeqPos stop, string& buffer){    SetPos(start);    if (start > stop) {        buffer.erase();        return;    }    GetSeqData(buffer, stop - start);}inlineCSeqVector_CI& CSeqVector_CI::operator+=(TSeqPos value){    SetPos(GetPos() + value);    return *this;}inlineCSeqVector_CI& CSeqVector_CI::operator-=(TSeqPos value){    SetPos(GetPos() - value);    return *this;}inlineCSeqVector_CI operator+(const CSeqVector_CI& iter, TSeqPos value){    CSeqVector_CI ret(iter);    ret += value;    return ret;}inlineCSeqVector_CI operator-(const CSeqVector_CI& iter, TSeqPos value){    CSeqVector_CI ret(iter);    ret -= value;    return ret;}inlineCSeqVector_CI operator+(const CSeqVector_CI& iter, TSignedSeqPos value){    CSeqVector_CI ret(iter);    ret.SetPos(iter.GetPos() + value);    return ret;}inlineCSeqVector_CI operator-(const CSeqVector_CI& iter, TSignedSeqPos value){    CSeqVector_CI ret(iter);    ret.SetPos(iter.GetPos() - value);    return ret;}inlineTSignedSeqPos operator-(const CSeqVector_CI& iter1,                        const CSeqVector_CI& iter2){    return iter1.GetPos() - iter2.GetPos();}inlineCSeqVector_CI::TCoding CSeqVector_CI::x_GetCoding(TCoding cacheCoding,                                                  TCoding dataCoding) const{    return cacheCoding != CSeq_data::e_not_set? cacheCoding: dataCoding;}END_SCOPE(objects)END_NCBI_SCOPE/** ---------------------------------------------------------------------------* $Log: seq_vector_ci.hpp,v $* Revision 1000.3  2004/06/01 19:21:44  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19** Revision 1.19  2004/04/26 14:15:00  grichenk* Added standard container methods** Revision 1.18  2004/04/22 18:34:18  grichenk* Added optional ambiguity randomizer for ncbi2na coding** Revision 1.17  2004/03/16 15:47:26  vasilche* Added CBioseq_set_Handle and set of EditHandles** Revision 1.16  2003/12/02 16:42:50  grichenk* Fixed GetSeqData to return empty string if start > stop.* Added GetSeqData(const_iterator, const_iterator, string).** Revision 1.15  2003/10/08 14:16:55  vasilche* Removed circular reference CSeqVector <-> CSeqVector_CI.** Revision 1.14  2003/08/29 13:34:47  vasilche* Rewrote CSeqVector/CSeqVector_CI code to allow better inlining.* CSeqVector::operator[] made significantly faster.* Added possibility to have platform dependent byte unpacking functions.** Revision 1.13  2003/08/21 13:32:04  vasilche* Optimized CSeqVector iteration.* Set some CSeqVector values (mol type, coding) in constructor instead of detecting them while iteration.* Remove unsafe bit manipulations with coding.** Revision 1.12  2003/08/19 18:34:11  vasilche* Buffer length constant moved to *.cpp file for easier modification.** Revision 1.11  2003/08/14 20:05:18  vasilche* Simple SNP features are stored as table internally.* They are recreated when needed using CFeat_CI.** Revision 1.10  2003/07/18 19:42:42  vasilche* Added x_DestroyCache() method.** Revision 1.9  2003/06/24 19:46:41  grichenk* Changed cache from vector<char> to char*. Made* CSeqVector::operator[] inline.** Revision 1.8  2003/06/17 22:03:37  dicuccio* Added missing export specifier** Revision 1.7  2003/06/05 20:20:21  grichenk* Fixed bugs in assignment functions,* fixed minor problems with coordinates.** Revision 1.6  2003/06/04 13:48:53  grichenk* Improved double-caching, fixed problem with strands.** Revision 1.5  2003/06/02 16:01:36  dicuccio* Rearranged include/objects/ subtree.  This includes the following shifts:*     - include/objects/alnmgr --> include/objtools/alnmgr*     - include/objects/cddalignview --> include/objtools/cddalignview*     - include/objects/flat --> include/objtools/flat*     - include/objects/objmgr/ --> include/objmgr/*     - include/objects/util/ --> include/objmgr/util/*     - include/objects/validator --> include/objtools/validator** Revision 1.4  2003/05/30 20:43:54  vasilche* Fixed CSeqVector_CI::operator--().** Revision 1.3  2003/05/30 19:30:08  vasilche* Fixed compilation on GCC 3.** Revision 1.2  2003/05/30 18:00:26  grichenk* Fixed caching bugs in CSeqVector_CI** Revision 1.1  2003/05/27 19:42:23  grichenk* Initial revision*** ===========================================================================*/#endif  // SEQ_VECTOR_CI__HPP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -