seq_loc_cvt.cpp

来自「ncbi源码」· C++ 代码 · 共 970 行 · 第 1/3 页

CPP
970
字号
/* * =========================================================================== * PRODUCTION $Log: seq_loc_cvt.cpp,v $ * PRODUCTION Revision 1000.5  2004/06/01 19:24:09  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.29 * PRODUCTION * =========================================================================== *//*  $Id: seq_loc_cvt.cpp,v 1000.5 2004/06/01 19:24:09 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: Eugene Vasilchenko** File Description:*   Class for mapping Seq-loc petween sequences.**/#include <ncbi_pch.hpp>#include <objmgr/impl/seq_loc_cvt.hpp>#include <objmgr/impl/seq_align_mapper.hpp>#include <objmgr/seq_map_ci.hpp>#include <objmgr/impl/scope_impl.hpp>#include <objmgr/annot_types_ci.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <objects/seqloc/Seq_point.hpp>#include <objects/seqloc/Seq_loc_equiv.hpp>#include <objects/seqloc/Seq_bond.hpp>#include <objects/seqfeat/Seq_feat.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)/////////////////////////////////////////////////////////////////////////////// CSeq_loc_Conversion/////////////////////////////////////////////////////////////////////////////CSeq_loc_Conversion::CSeq_loc_Conversion(CSeq_loc& master_loc_empty,                                         const CSeq_id_Handle& dst_id,                                         const CSeqMap_CI& seg,                                         const CSeq_id_Handle& src_id,                                         CScope* scope)    : m_Src_id_Handle(src_id),      m_Src_from(0),      m_Src_to(0),      m_Shift(0),      m_Reverse(false),      m_Dst_id_Handle(dst_id),      m_Dst_loc_Empty(&master_loc_empty),      m_Partial(false),      m_LastType(eMappedObjType_not_set),      m_LastStrand(eNa_strand_unknown),      m_Scope(scope){    SetConversion(seg);    Reset();}CSeq_loc_Conversion::CSeq_loc_Conversion(const CSeq_id_Handle& master_id,                                         CScope* scope)    : m_Src_id_Handle(master_id),      m_Src_from(0),      m_Src_to(kInvalidSeqPos - 1),      m_Shift(0),      m_Reverse(false),      m_Dst_id_Handle(master_id),      m_Dst_loc_Empty(0),      m_Partial(false),      m_LastType(eMappedObjType_not_set),      m_LastStrand(eNa_strand_unknown),      m_Scope(scope){    m_Dst_loc_Empty.Reset(new CSeq_loc);    m_Dst_loc_Empty->SetEmpty().Assign(*master_id.GetSeqId());    Reset();}CSeq_loc_Conversion::~CSeq_loc_Conversion(void){    _ASSERT(!IsSpecialLoc());}void CSeq_loc_Conversion::SetConversion(const CSeqMap_CI& seg){    m_Src_from = seg.GetRefPosition();    m_Src_to = m_Src_from + seg.GetLength() - 1;    m_Reverse = seg.GetRefMinusStrand();    if ( !m_Reverse ) {        m_Shift = seg.GetPosition() - m_Src_from;    }    else {        m_Shift = seg.GetPosition() + m_Src_to;    }}bool CSeq_loc_Conversion::ConvertPoint(TSeqPos src_pos,                                       ENa_strand src_strand){    _ASSERT(!IsSpecialLoc());    if ( src_pos < m_Src_from || src_pos > m_Src_to ) {        m_Partial = true;        return false;    }    TSeqPos dst_pos;    if ( !m_Reverse ) {        m_LastStrand = src_strand;        dst_pos = m_Shift + src_pos;    }    else {        m_LastStrand = Reverse(src_strand);        dst_pos = m_Shift - src_pos;    }    m_LastType = eMappedObjType_Seq_point;    m_TotalRange += m_LastRange.SetFrom(dst_pos).SetTo(dst_pos);    return true;}bool CSeq_loc_Conversion::ConvertInterval(TSeqPos src_from, TSeqPos src_to,                                          ENa_strand src_strand){    _ASSERT(!IsSpecialLoc());    if ( src_from < m_Src_from ) {        m_Partial = true;        src_from = m_Src_from;    }    if ( src_to > m_Src_to ) {        m_Partial = true;        src_to = m_Src_to;    }    if ( src_from > src_to ) {        return false;    }    TSeqPos dst_from, dst_to;    if ( !m_Reverse ) {        m_LastStrand = src_strand;        dst_from = m_Shift + src_from;        dst_to = m_Shift + src_to;    }    else {        m_LastStrand = Reverse(src_strand);        dst_from = m_Shift - src_to;        dst_to = m_Shift - src_from;    }    m_LastType = eMappedObjType_Seq_interval;    m_TotalRange += m_LastRange.SetFrom(dst_from).SetTo(dst_to);    return true;}inlinevoid CSeq_loc_Conversion::CheckDstInterval(void){    if ( m_LastType != eMappedObjType_Seq_interval ) {        NCBI_THROW(CAnnotException, eBadLocation,                   "Wrong last location type");    }    m_LastType = eMappedObjType_not_set;}inlinevoid CSeq_loc_Conversion::CheckDstPoint(void){    if ( m_LastType != eMappedObjType_Seq_point ) {        NCBI_THROW(CAnnotException, eBadLocation,                   "Wrong last location type");    }    m_LastType = eMappedObjType_not_set;}CRef<CSeq_interval> CSeq_loc_Conversion::GetDstInterval(void){    CheckDstInterval();    CRef<CSeq_interval> ret(new CSeq_interval);    CSeq_interval& interval = *ret;    interval.SetId(GetDstId());    interval.SetFrom(m_LastRange.GetFrom());    interval.SetTo(m_LastRange.GetTo());    if ( m_LastStrand != eNa_strand_unknown ) {        interval.SetStrand(m_LastStrand);    }    return ret;}CRef<CSeq_point> CSeq_loc_Conversion::GetDstPoint(void){    CheckDstPoint();    _ASSERT(m_LastRange.GetLength() == 1);    CRef<CSeq_point> ret(new CSeq_point);    CSeq_point& point = *ret;    point.SetId(GetDstId());    point.SetPoint(m_LastRange.GetFrom());    if ( m_LastStrand != eNa_strand_unknown ) {        point.SetStrand(m_LastStrand);    }    return ret;}void CSeq_loc_Conversion::SetDstLoc(CRef<CSeq_loc>* dst){    CSeq_loc* loc = 0;    if ( !(*dst) ) {        switch ( m_LastType ) {        case eMappedObjType_Seq_interval:            dst->Reset(loc = new CSeq_loc);            loc->SetInt(*GetDstInterval());            break;        case eMappedObjType_Seq_point:            dst->Reset(loc = new CSeq_loc);            loc->SetPnt(*GetDstPoint());            break;        default:            _ASSERT(0);            break;        }    }    else {        _ASSERT(!IsSpecialLoc());    }}bool CSeq_loc_Conversion::Convert(const CSeq_loc& src, CRef<CSeq_loc>* dst,                                  EConvertFlag flag){    dst->Reset();    CSeq_loc* loc = 0;    _ASSERT(!IsSpecialLoc());    m_LastType = eMappedObjType_Seq_loc;    switch ( src.Which() ) {    case CSeq_loc::e_not_set:    case CSeq_loc::e_Feat:        // Nothing to do, although this should never happen --        // the seq_loc is intersecting with the conv. loc.        _ASSERT("this cannot happen" && 0);        break;    case CSeq_loc::e_Null:    {        dst->Reset(loc = new CSeq_loc);        loc->SetNull();        break;    }    case CSeq_loc::e_Empty:    {        if ( GoodSrcId(src.GetEmpty()) ) {            dst->Reset(loc = new CSeq_loc);            loc->SetEmpty(GetDstId());        }        break;    }    case CSeq_loc::e_Whole:    {        const CSeq_id& src_id = src.GetWhole();        // Convert to the allowed master seq interval        if ( GoodSrcId(src_id) ) {            CBioseq_Handle bh = m_Scope->GetBioseqHandle(src_id,                CScope::eGetBioseq_All);            ConvertInterval(0, bh.GetBioseqLength()-1, eNa_strand_unknown);        }        break;    }    case CSeq_loc::e_Int:    {        ConvertInterval(src.GetInt());        break;    }    case CSeq_loc::e_Pnt:    {        ConvertPoint(src.GetPnt());        break;    }    case CSeq_loc::e_Packed_int:    {        const CPacked_seqint::Tdata& src_ints = src.GetPacked_int().Get();        CPacked_seqint::Tdata* dst_ints = 0;        ITERATE ( CPacked_seqint::Tdata, i, src_ints ) {            if ( ConvertInterval(**i) ) {                if ( !dst_ints ) {                    dst->Reset(loc = new CSeq_loc);                    dst_ints = &loc->SetPacked_int().Set();                }                dst_ints->push_back(GetDstInterval());            }        }        break;    }    case CSeq_loc::e_Packed_pnt:    {        const CPacked_seqpnt& src_pack_pnts = src.GetPacked_pnt();        if ( !GoodSrcId(src_pack_pnts.GetId()) ) {

⌨️ 快捷键说明

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