seq_vector.cpp
来自「ncbi源码」· C++ 代码 · 共 571 行 · 第 1/2 页
CPP
571 行
/* * =========================================================================== * PRODUCTION $Log: seq_vector.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:24:24 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.68 * PRODUCTION * =========================================================================== *//* $Id: seq_vector.cpp,v 1000.3 2004/06/01 19:24:24 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, Eugene Vasilchenko** File Description:* Sequence data container for object manager**/#include <ncbi_pch.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/seq_vector_ci.hpp>#include <corelib/ncbimtx.hpp>#include <objmgr/impl/data_source.hpp>#include <objects/seq/seqport_util.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objmgr/seq_map.hpp>#include <objmgr/objmgr_exception.hpp>#include <algorithm>#include <map>#include <vector>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)//////////////////////////////////////////////////////////////////////// CSeqVector:://CSeqVector::CSeqVector(void) : m_Size(0){ m_Iterator.x_SetVector(*this);}CSeqVector::CSeqVector(const CSeqVector& vec) : m_SeqMap(vec.m_SeqMap), m_Scope(vec.m_Scope), m_Size(vec.m_Size), m_Mol(vec.m_Mol), m_Strand(vec.m_Strand), m_Coding(vec.m_Coding){ m_Iterator.x_SetVector(*this);}CSeqVector::CSeqVector(CConstRef<CSeqMap> seqMap, CScope& scope, EVectorCoding coding, ENa_strand strand) : m_SeqMap(seqMap), m_Scope(&scope), m_Size(seqMap->GetLength(&scope)), m_Mol(seqMap->GetMol()), m_Strand(strand), m_Coding(CSeq_data::e_not_set){ m_Iterator.x_SetVector(*this); SetCoding(coding);}CSeqVector::CSeqVector(const CSeqMap& seqMap, CScope& scope, EVectorCoding coding, ENa_strand strand) : m_SeqMap(&seqMap), m_Scope(&scope), m_Size(seqMap.GetLength(&scope)), m_Mol(seqMap.GetMol()), m_Strand(strand), m_Coding(CSeq_data::e_not_set){ m_Iterator.x_SetVector(*this); SetCoding(coding);}CSeqVector::CSeqVector(const CSeq_loc& loc, CScope& scope, EVectorCoding coding, ENa_strand strand) : m_SeqMap(CSeqMap::CreateSeqMapForSeq_loc(loc, &scope)), m_Scope(&scope), m_Size(m_SeqMap->GetLength(&scope)), m_Mol(m_SeqMap->GetMol()), m_Strand(strand), m_Coding(CSeq_data::e_not_set){ m_Iterator.x_SetVector(*this); SetCoding(coding);}CSeqVector::~CSeqVector(void){}CSeqVector& CSeqVector::operator= (const CSeqVector& vec){ if ( &vec != this ) { m_SeqMap = vec.m_SeqMap; m_Scope = vec.m_Scope; m_Size = vec.m_Size; m_Mol = vec.m_Mol; m_Strand = vec.m_Strand; m_Coding = vec.m_Coding; m_Iterator.x_SetVector(*this); } return *this;}bool CSeqVector::CanGetRange(TSeqPos from, TSeqPos to) const{ return m_SeqMap->CanResolveRange(m_Scope.GetScopeOrNull(), from, to, m_Strand);}CSeqVector::TResidue CSeqVector::x_GetGapChar(TCoding coding){ switch (coding) { case CSeq_data::e_Iupacna: // DNA - N return 'N'; case CSeq_data::e_Ncbi8na: // DNA - bit representation case CSeq_data::e_Ncbi4na: return 0x0f; // all bits set == any base case CSeq_data::e_Ncbieaa: // Proteins - X case CSeq_data::e_Iupacaa: return 'X'; case CSeq_data::e_Ncbi8aa: // Protein - numeric representation case CSeq_data::e_Ncbistdaa: return 21; case CSeq_data::e_not_set: return 0; // It's not good to throw an exception here case CSeq_data::e_Ncbi2na: // Codings without gap symbols case CSeq_data::e_Ncbipaa: //### Not sure about this case CSeq_data::e_Ncbipna: //### Not sure about this default: NCBI_THROW(CSeqVectorException, eCodingError, "Can not indicate gap using the selected coding"); }}DEFINE_STATIC_FAST_MUTEX(s_ConvertTableMutex2);const char* CSeqVector::sx_GetConvertTable(TCoding src, TCoding dst, bool reverse){ CFastMutexGuard guard(s_ConvertTableMutex2); typedef pair<pair<TCoding, TCoding>, bool> TKey; typedef map<TKey, vector<char> > TTables; static TTables tables; TKey key(pair<TCoding, TCoding>(src, dst), reverse); TTables::iterator it = tables.find(key); if ( it != tables.end() ) { // already created return it->second.empty()? 0: &it->second[0]; } it = tables.insert(TTables::value_type(key, vector<char>())).first; if ( !CSeqportUtil::IsCodeAvailable(src) || !CSeqportUtil::IsCodeAvailable(dst) ) { // invalid types return 0; } const size_t COUNT = kMax_UChar+1; const unsigned kInvalidCode = kMax_UChar; pair<unsigned, unsigned> srcIndex = CSeqportUtil::GetCodeIndexFromTo(src); if ( srcIndex.second >= COUNT ) { // too large range return 0; } if ( reverse ) { // check if src needs complement conversion try { CSeqportUtil::GetIndexComplement(src, srcIndex.first); } catch ( exception& /*noComplement*/ ) { reverse = false; } } if ( dst != src ) { pair<unsigned, unsigned> dstIndex = CSeqportUtil::GetCodeIndexFromTo(dst); if ( dstIndex.second >= COUNT ) { // too large range return 0; } try { // check for types compatibility CSeqportUtil::GetMapToIndex(src, dst, srcIndex.first); } catch ( exception& /*badType*/ ) { // incompatible types return 0; } } else if ( !reverse ) { // no need to convert at all return 0; } it->second.resize(COUNT, char(kInvalidCode)); for ( unsigned i = srcIndex.first; i <= srcIndex.second; ++i ) { try { unsigned code = i; if ( reverse ) { code = CSeqportUtil::GetIndexComplement(src, code); } if ( dst != src ) { code = CSeqportUtil::GetMapToIndex(src, dst, code); } code = min(kInvalidCode, code); it->second[i] = char(code); } catch ( exception& /*noConversion or noComplement*/ ) { } } return &it->second[0];}void CSeqVector::SetCoding(TCoding coding){ if (m_Coding != coding) { m_Coding = coding; } m_Iterator.SetCoding(coding);}void CSeqVector::SetIupacCoding(void){ SetCoding(IsProtein()? CSeq_data::e_Iupacaa: CSeq_data::e_Iupacna);}void CSeqVector::SetNcbiCoding(void){ SetCoding(IsProtein()? CSeq_data::e_Ncbistdaa: CSeq_data::e_Ncbi4na);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?