seq_map_ci.cpp
来自「ncbi源码」· C++ 代码 · 共 663 行 · 第 1/2 页
CPP
663 行
/* * =========================================================================== * PRODUCTION $Log: seq_map_ci.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:24:19 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.23 * PRODUCTION * =========================================================================== *//* $Id: seq_map_ci.cpp,v 1000.3 2004/06/01 19:24:19 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.** ===========================================================================** Authors:* Eugene Vasilchenko** File Description:* Sequence map for the Object Manager. Describes sequence as a set of* segments of different types (data, reference, gap or end).**/#include <ncbi_pch.hpp>#include <objmgr/seq_map_ci.hpp>#include <objmgr/seq_map.hpp>#include <objmgr/seq_entry_handle.hpp>#include <objmgr/impl/scope_impl.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)/////////////////////////////////////////////////////////////////////////////// SSeqMapSelector/////////////////////////////////////////////////////////////////////////////SSeqMapSelector& SSeqMapSelector::SetLimitTSE(const CSeq_entry* tse){ m_TSE.Reset(tse); m_TSE_Info.Reset(); return *this;}SSeqMapSelector& SSeqMapSelector::SetLimitTSE(const CSeq_entry_Handle& tse){ if ( tse ) { m_TSE_Info = tse.GetTSE_Info(); m_TSE = tse.GetSeq_entryCore(); } else { m_TSE_Info.Reset(); m_TSE.Reset(); } return *this;}////////////////////////////////////////////////////////////////////// CSeqMap_CI_SegmentInfobool CSeqMap_CI_SegmentInfo::x_Move(bool minusStrand, CScope* scope){ const CSeqMap& seqMap = *m_SeqMap; size_t index = m_Index; const CSeqMap::CSegment& old_seg = seqMap.x_GetSegment(index); if ( !minusStrand ) { if ( old_seg.m_Position > m_LevelRangeEnd || index == seqMap.x_GetSegmentsCount() ) return false; m_Index = ++index; seqMap.x_GetSegmentLength(index, scope); // Update length of segment return seqMap.x_GetSegmentPosition(index, scope) < m_LevelRangeEnd; } else { if ( old_seg.m_Position + old_seg.m_Length < m_LevelRangePos || index == 0 ) return false; m_Index = --index; return old_seg.m_Position > m_LevelRangePos; }}////////////////////////////////////////////////////////////////////// CSeqMap_CIinlinebool CSeqMap_CI::x_Push(TSeqPos pos){ return x_Push(pos, m_Selector.CanResolve());}CSeqMap_CI::CSeqMap_CI(void){ m_Selector.SetPosition(kInvalidSeqPos) .SetResolveCount(0) .SetFlags(CSeqMap::fDefaultFlags);}CSeqMap_CI::CSeqMap_CI(const CConstRef<CSeqMap>& seqMap, CScope* scope, TSeqPos pos, size_t maxResolveCount, TFlags flags) : m_Scope(scope){ m_Selector .SetResolveCount(maxResolveCount) .SetFlags(flags); if (pos >= seqMap->GetLength(scope)) { // Special case - end of seq map m_Selector.SetRange(seqMap->GetLength(scope), 0); TSegmentInfo push; push.m_SeqMap = seqMap; push.m_LevelRangePos = 0; push.m_LevelRangeEnd = GetPosition(); push.m_MinusStrand = false; push.m_Index = seqMap->x_GetSegmentsCount(); m_Stack.push_back(push); return; } x_Push(seqMap, 0, seqMap->GetLength(scope), false, pos); while ( !x_Found() ) { if ( !x_Push(pos - GetPosition()) ) { x_SettleNext(); break; } }}CSeqMap_CI::CSeqMap_CI(const CConstRef<CSeqMap>& seqMap, CScope* scope, TSeqPos pos, ENa_strand strand, size_t maxResolveCount, TFlags flags) : m_Scope(scope){ m_Selector .SetResolveCount(maxResolveCount) .SetFlags(flags); if (pos >= seqMap->GetLength(scope)) { // Special case - end of seq map m_Selector.SetRange(seqMap->GetLength(scope), 0); TSegmentInfo push; push.m_SeqMap = seqMap; push.m_LevelRangePos = 0; push.m_LevelRangeEnd = GetPosition(); push.m_MinusStrand = false; push.m_Index = seqMap->x_GetSegmentsCount(); m_Stack.push_back(push); return; } x_Push(seqMap, 0, seqMap->GetLength(scope), IsReverse(strand), pos); while ( !x_Found() ) { if ( !x_Push(pos - GetPosition()) ) { x_SettleNext(); break; } }}CSeqMap_CI::CSeqMap_CI(const CConstRef<CSeqMap>& seqMap, CScope* scope, SSeqMapSelector& selector, ENa_strand strand) : m_Scope(scope), m_Selector(selector){ TSeqPos pos = GetPosition(); x_Push(seqMap, m_Selector.m_Position, m_Selector.m_Length, IsReverse(strand), 0); while ( !x_Found() ) { if ( !x_Push(pos - GetPosition()) ) { x_SettleNext(); break; } }}CSeqMap_CI::CSeqMap_CI(const CConstRef<CSeqMap>& seqMap, CScope* scope, SSeqMapSelector& selector) : m_Scope(scope), m_Selector(selector){ TSeqPos pos = GetPosition(); if (m_Selector.m_Length == kInvalidSeqPos) { m_Selector.SetRange(pos, seqMap->GetLength(scope)); } x_Push(seqMap, m_Selector.m_Position, m_Selector.m_Length, false, 0); while ( !x_Found() ) { if ( !x_Push(pos - GetPosition()) ) { x_SettleNext(); break; } }}CSeqMap_CI::~CSeqMap_CI(void){}const CSeq_data& CSeqMap_CI::GetData(void) const{ if ( !*this ) { NCBI_THROW(CSeqMapException, eOutOfRange, "Iterator out of range"); } if ( GetRefPosition() != 0 || GetRefMinusStrand() ) { NCBI_THROW(CSeqMapException, eDataError, "Non standard Seq_data: use methods " "GetRefData/GetRefPosition/GetRefMinusStrand"); } return GetRefData();}const CSeq_data& CSeqMap_CI::GetRefData(void) const{ if ( !*this ) { NCBI_THROW(CSeqMapException, eOutOfRange, "Iterator out of range"); } return x_GetSeqMap().x_GetSeq_data(x_GetSegment());}CSeq_id_Handle CSeqMap_CI::GetRefSeqid(void) const{ if ( !*this ) { NCBI_THROW(CSeqMapException, eOutOfRange, "Iterator out of range"); } return CSeq_id_Mapper::GetSeq_id_Mapper(). GetHandle(x_GetSeqMap().x_GetRefSeqid(x_GetSegment()));}TSeqPos CSeqMap_CI_SegmentInfo::GetRefPosition(void) const{ if ( !InRange() ) { NCBI_THROW(CSeqMapException, eOutOfRange, "Iterator out of range"); } const CSeqMap::CSegment& seg = x_GetSegment(); TSignedSeqPos skip; if ( !seg.m_RefMinusStrand ) { skip = m_LevelRangePos - seg.m_Position; } else { skip = (seg.m_Position + seg.m_Length) - m_LevelRangeEnd; } if ( skip < 0 ) skip = 0; return seg.m_RefPosition + skip;}TSeqPos CSeqMap_CI_SegmentInfo::x_GetTopOffset(void) const{ TSignedSeqPos offset; if ( !m_MinusStrand ) { offset = min(x_GetLevelRealPos(), m_LevelRangeEnd) - m_LevelRangePos; } else { offset = m_LevelRangeEnd - max(x_GetLevelRealEnd(), m_LevelRangePos); } if ( offset < 0 ) offset = 0; return offset;}TSeqPos CSeqMap_CI::x_GetTopOffset(void) const{ return x_GetSegmentInfo().x_GetTopOffset();}bool CSeqMap_CI::x_RefTSEMatch(const CSeqMap::CSegment& seg) const{ _ASSERT(m_Selector.m_TSE); _ASSERT(CSeqMap::ESegmentType(seg.m_SegType) == CSeqMap::eSeqRef); CSeq_id_Handle id = CSeq_id_Mapper::GetSeq_id_Mapper(). GetHandle(x_GetSeqMap().x_GetRefSeqid(seg)); CSeq_entry_Handle tse_info; CScope& scope = *m_Scope; if ( m_Selector.m_TSE_Info ) { tse_info = CSeq_entry_Handle(scope, static_cast<const CTSE_Info&> (*m_Selector.m_TSE_Info)); } else { tse_info = scope.GetSeq_entryHandle(*m_Selector.m_TSE); const_cast<SSeqMapSelector&>(m_Selector).m_TSE_Info = tse_info.GetTSE_Info();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?