📄 seq_loc.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: Seq_loc.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:34:35 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R6.42 * PRODUCTION * =========================================================================== *//* $Id: Seq_loc.cpp,v 1000.3 2004/06/01 19:34:35 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: Author: Cliff Clausen, Eugene Vasilchenko * * File Description: * ....... * * Remark: * This code was originally generated by application DATATOOL * using specifications from the ASN data definition file * 'seqloc.asn'. * * =========================================================================== */#include <ncbi_pch.hpp>#include <serial/enumvalues.hpp>#include <objects/general/Int_fuzz.hpp>#include <objects/seqloc/Seq_point.hpp>#include <objects/seqloc/Packed_seqint.hpp>#include <objects/seqloc/Packed_seqpnt.hpp>#include <objects/seqloc/Seq_loc_mix.hpp>#include <objects/seqloc/Seq_loc_equiv.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqfeat/Feat_id.hpp>BEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::// constructorsCSeq_loc::CSeq_loc(E_Choice index){ x_InvalidateCache(); switch ( index ) { case e_Null: { SetNull(); break; } case e_Empty: { SetEmpty(); break; } case e_Whole: { SetWhole(); break; } case e_Int: { SetInt(); break; } case e_Packed_int: { SetPacked_int(); break; } case e_Pnt: { SetPnt(); break; } case e_Packed_pnt: { SetPacked_pnt(); break; } case e_Mix: { SetMix(); break; } case e_Equiv: { SetEquiv(); break; } case e_Bond: { SetBond(); break; } case e_Feat: { SetFeat(); break; } case e_not_set: default: break; }}CSeq_loc::CSeq_loc(TId& id, TPoint point, TStrand strand){ x_InvalidateCache(); SetPnt(*new CSeq_point(id, point, strand));}CSeq_loc::CSeq_loc(TId& id, const TPoints& points, TStrand strand){ x_InvalidateCache(); if ( points.size() == 1 ) { SetPnt(*new CSeq_point(id, points.front(), strand)); } else { SetPacked_pnt(*new CPacked_seqpnt(id, points, strand)); }}CSeq_loc::CSeq_loc(TId& id, TPoint from, TPoint to, TStrand strand){ x_InvalidateCache(); SetInt(*new CSeq_interval(id, from, to, strand));}CSeq_loc::CSeq_loc(TId& id, TRanges ranges, TStrand strand){ x_InvalidateCache(); if ( ranges.size() == 1 ) { SetInt(*new CSeq_interval(id, ranges.front().GetFrom(), ranges.front().GetTo(), strand)); } else { SetPacked_int(*new CPacked_seqint(id, ranges, strand)); }}// destructorCSeq_loc::~CSeq_loc(void){}inlinevoid x_Assign(CInt_fuzz& dst, const CInt_fuzz& src){ switch ( src.Which() ) { case CInt_fuzz::e_not_set: dst.Reset(); break; case CInt_fuzz::e_P_m: dst.SetP_m(src.GetP_m()); break; case CInt_fuzz::e_Range: dst.SetRange().SetMin(src.GetRange().GetMin()); dst.SetRange().SetMax(src.GetRange().GetMax()); break; case CInt_fuzz::e_Pct: dst.SetPct(src.GetPct()); break; case CInt_fuzz::e_Lim: dst.SetLim(src.GetLim()); break; case CInt_fuzz::e_Alt: dst.SetAlt() = src.GetAlt(); break; default: NCBI_THROW(CException, eUnknown, "Invalid Int-fuzz variant"); }}inlinevoid x_Assign(CSeq_interval& dst, const CSeq_interval& src){ dst.SetFrom(src.GetFrom()); dst.SetTo(src.GetTo()); if ( src.IsSetStrand() ) { dst.SetStrand(src.GetStrand()); } else { dst.ResetStrand(); } dst.SetId().Assign(src.GetId()); if ( src.IsSetFuzz_from() ) { x_Assign(dst.SetFuzz_from(), src.GetFuzz_from()); } else { dst.ResetFuzz_from(); } if ( src.IsSetFuzz_to() ) { x_Assign(dst.SetFuzz_to(), src.GetFuzz_to()); } else { dst.ResetFuzz_to(); }}inlinevoid x_Assign(CSeq_point& dst, const CSeq_point& src){ dst.SetPoint(src.GetPoint()); if ( src.IsSetStrand() ) { dst.SetStrand(src.GetStrand()); } else { dst.ResetStrand(); } dst.SetId().Assign(src.GetId()); if ( src.IsSetFuzz() ) { x_Assign(dst.SetFuzz(), src.GetFuzz()); } else { dst.ResetFuzz(); }}inlinevoid x_Assign(CPacked_seqint& dst, const CPacked_seqint& src){ CPacked_seqint::Tdata& data = dst.Set(); data.clear(); ITERATE ( CPacked_seqint::Tdata, i, src.Get() ) { data.push_back(CRef<CSeq_interval>(new CSeq_interval)); x_Assign(*data.back(), **i); }}inlinevoid x_Assign(CPacked_seqpnt& dst, const CPacked_seqpnt& src){ if ( src.IsSetStrand() ) { dst.SetStrand(src.GetStrand()); } else { dst.ResetStrand(); } dst.SetId().Assign(src.GetId()); if ( src.IsSetFuzz() ) { x_Assign(dst.SetFuzz(), src.GetFuzz()); } else { dst.ResetFuzz(); } dst.SetPoints() = src.GetPoints();}inlinevoid x_Assign(CSeq_bond& dst, const CSeq_bond& src){ x_Assign(dst.SetA(), src.GetA()); if ( src.IsSetB() ) { x_Assign(dst.SetB(), src.GetB()); } else { dst.ResetB(); }}inlinevoid x_Assign(CSeq_loc_mix& dst, const CSeq_loc_mix& src){ CSeq_loc_mix::Tdata& data = dst.Set(); data.clear(); ITERATE ( CSeq_loc_mix::Tdata, i, src.Get() ) { data.push_back(CRef<CSeq_loc>(new CSeq_loc)); data.back()->Assign(**i); }}inlinevoid x_Assign(CSeq_loc_equiv& dst, const CSeq_loc_equiv& src){ CSeq_loc_equiv::Tdata& data = dst.Set(); data.clear(); ITERATE ( CSeq_loc_equiv::Tdata, i, src.Get() ) { data.push_back(CRef<CSeq_loc>(new CSeq_loc)); data.back()->Assign(**i); }}void CSeq_loc::Assign(const CSerialObject& obj, ESerialRecursionMode how){ if ( GetTypeInfo() == obj.GetThisTypeInfo() ) { const CSeq_loc& loc = static_cast<const CSeq_loc&>(obj); switch ( loc.Which() ) { case CSeq_loc::e_not_set: Reset(); return; case CSeq_loc::e_Null: SetNull(); return; case CSeq_loc::e_Empty: SetEmpty().Assign(loc.GetEmpty()); return; case CSeq_loc::e_Whole: SetWhole().Assign(loc.GetWhole()); return; case CSeq_loc::e_Int: x_Assign(SetInt(), loc.GetInt()); return; case CSeq_loc::e_Pnt: x_Assign(SetPnt(), loc.GetPnt()); return; case CSeq_loc::e_Packed_int: x_Assign(SetPacked_int(), loc.GetPacked_int()); return; case CSeq_loc::e_Packed_pnt: x_Assign(SetPacked_pnt(), loc.GetPacked_pnt()); return; case CSeq_loc::e_Mix: x_Assign(SetMix(), loc.GetMix()); return; case CSeq_loc::e_Equiv: x_Assign(SetEquiv(), loc.GetEquiv()); return; case CSeq_loc::e_Bond: x_Assign(SetBond(), loc.GetBond()); return; case CSeq_loc::e_Feat: SetFeat().Assign(loc.GetFeat()); return; } } CSerialObject::Assign(obj, how);}CSeq_loc::TRange CSeq_loc::x_UpdateTotalRange(void) const{ TRange range = m_TotalRangeCache; if ( range.GetFrom() == TSeqPos(kDirtyCache) ) { const CSeq_id* id = 0; range = m_TotalRangeCache = x_CalculateTotalRangeCheckId(id); m_IdCache = id; } return range;}void CSeq_loc::x_UpdateId(const CSeq_id*& total_id, const CSeq_id* id) const{ if ( total_id == id ) { return; } if ( !total_id ) { total_id = id; } else if ( (id && !total_id->Equals(*id)) || !id ) { NCBI_THROW(CException, eUnknown, "CSeq_loc -- multiple seq-ids"); }} // returns enclosing location range// the total range is meaningless if there are several seq-ids// in the locationCSeq_loc::TRange CSeq_loc::x_CalculateTotalRangeCheckId(const CSeq_id*& id) const{ TRange total_range; switch ( Which() ) { case CSeq_loc::e_not_set: case CSeq_loc::e_Null: { // Ignore locations without id total_range = TRange::GetEmpty(); break; } case CSeq_loc::e_Empty: { x_UpdateId(id, &GetEmpty()); total_range = TRange::GetEmpty(); break; } case CSeq_loc::e_Whole: { x_UpdateId(id, &GetWhole()); total_range = TRange::GetWhole(); break; } case CSeq_loc::e_Int: { const CSeq_interval& loc = GetInt(); x_UpdateId(id, &loc.GetId()); total_range.Set(loc.GetFrom(), loc.GetTo()); break; } case CSeq_loc::e_Pnt: { const CSeq_point& pnt = GetPnt(); x_UpdateId(id, &pnt.GetId()); TSeqPos pos = pnt.GetPoint(); total_range.Set(pos, pos); break; } case CSeq_loc::e_Packed_int: { // Check ID of each interval const CPacked_seqint& ints = GetPacked_int(); total_range = TRange::GetEmpty(); ITERATE ( CPacked_seqint::Tdata, ii, ints.Get() ) { const CSeq_interval& loc = **ii; x_UpdateId(id, &loc.GetId()); total_range += TRange(loc.GetFrom(), loc.GetTo()); } break; } case CSeq_loc::e_Packed_pnt: { const CPacked_seqpnt& pnts = GetPacked_pnt(); x_UpdateId(id, &pnts.GetId()); total_range = TRange::GetEmpty(); ITERATE( CPacked_seqpnt::TPoints, pi, pnts.GetPoints() ) { TSeqPos pos = *pi; total_range += TRange(pos, pos); } break; } case CSeq_loc::e_Mix: { // Check ID of each sub-location. const CSeq_loc_mix& mix = GetMix(); total_range = TRange::GetEmpty(); ITERATE( CSeq_loc_mix::Tdata, li, mix.Get() ) { // instead of Get... to be able to check ID total_range += (*li)->x_CalculateTotalRangeCheckId(id); } break; } case CSeq_loc::e_Equiv:/* { // Does it make any sense to GetTotalRange() from an equiv? total_range = TRange::GetEmpty(); ITERATE(CSeq_loc_equiv::Tdata, li, GetEquiv().Get()) { total_range += (*li)->GetTotalRange(); } break; }*/ case CSeq_loc::e_Bond:/* { // Does it make any sense to GetTotalRange() from a bond? const CSeq_bond& loc = GetBond(); TSeqPos pos = loc.GetA().GetPoint(); total_range = TRange(pos, pos); if ( loc.IsSetB() ) { pos = loc.GetB().GetPoint(); total_range += TRange(pos, pos); } break; }*/ case CSeq_loc::e_Feat: default: { NCBI_THROW(CException, eUnknown, "CSeq_loc::CalculateTotalRange -- " "unsupported location type"); } } return total_range;}TSeqPos CSeq_loc::GetStart(TSeqPos seq_len) const{ if (seq_len == kInvalidSeqPos) { return GetTotalRange().GetFrom(); } switch ( Which() ) { case CSeq_loc::e_not_set: case CSeq_loc::e_Null: case CSeq_loc::e_Empty: { return kInvalidSeqPos; } case CSeq_loc::e_Whole: { return TRange::GetWhole().GetFrom(); } case CSeq_loc::e_Int: { return GetInt().GetFrom(); } case CSeq_loc::e_Pnt: { return GetPnt().GetPoint(); } case CSeq_loc::e_Packed_int: { return (*GetPacked_int().Get().begin())->GetFrom(); } case CSeq_loc::e_Packed_pnt: { return *GetPacked_pnt().GetPoints().begin(); } case CSeq_loc::e_Mix: { return (*GetMix().Get().begin())->GetStart(seq_len); } case CSeq_loc::e_Equiv: case CSeq_loc::e_Bond: case CSeq_loc::e_Feat: default: { NCBI_THROW(CException, eUnknown, "CSeq_loc::GetStart -- " "unsupported location type"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -