seq_loc_cvt.cpp
来自「ncbi源码」· C++ 代码 · 共 970 行 · 第 1/3 页
CPP
970 行
break; } const CPacked_seqpnt::TPoints& src_pnts = src_pack_pnts.GetPoints(); CPacked_seqpnt::TPoints* dst_pnts = 0; ITERATE ( CPacked_seqpnt::TPoints, i, src_pnts ) { TSeqPos dst_pos = ConvertPos(*i); if ( dst_pos != kInvalidSeqPos ) { if ( !dst_pnts ) { dst->Reset(loc = new CSeq_loc); CPacked_seqpnt& pnts = loc->SetPacked_pnt(); pnts.SetId(GetDstId()); dst_pnts = &pnts.SetPoints(); if ( src_pack_pnts.IsSetStrand() ) { pnts.SetStrand(ConvertStrand(src_pack_pnts.GetStrand())); } } dst_pnts->push_back(dst_pos); m_TotalRange += TRange(dst_pos, dst_pos); } } break; } case CSeq_loc::e_Mix: { const CSeq_loc_mix::Tdata& src_mix = src.GetMix().Get(); CSeq_loc_mix::Tdata* dst_mix = 0; CRef<CSeq_loc> dst_loc; ITERATE ( CSeq_loc_mix::Tdata, i, src_mix ) { if ( Convert(**i, &dst_loc, eCnvAlways) ) { if ( !dst_mix ) { dst->Reset(loc = new CSeq_loc); dst_mix = &loc->SetMix().Set(); } _ASSERT(dst_loc); dst_mix->push_back(dst_loc); } } break; } case CSeq_loc::e_Equiv: { const CSeq_loc_equiv::Tdata& src_equiv = src.GetEquiv().Get(); CSeq_loc_equiv::Tdata* dst_equiv = 0; CRef<CSeq_loc> dst_loc; ITERATE ( CSeq_loc_equiv::Tdata, i, src_equiv ) { if ( Convert(**i, &dst_loc, eCnvAlways) ) { if ( !dst_equiv ) { dst->Reset(loc = new CSeq_loc); dst_equiv = &loc->SetEquiv().Set(); } dst_equiv->push_back(dst_loc); } } break; } case CSeq_loc::e_Bond: { const CSeq_bond& src_bond = src.GetBond(); CSeq_bond* dst_bond = 0; if ( ConvertPoint(src_bond.GetA()) ) { dst->Reset(loc = new CSeq_loc); dst_bond = &loc->SetBond(); dst_bond->SetA(*GetDstPoint()); if ( src_bond.IsSetB() ) { dst_bond->SetB().Assign(src_bond.GetB()); } } if ( src_bond.IsSetB() ) { if ( ConvertPoint(src_bond.GetB()) ) { if ( !dst_bond ) { dst->Reset(loc = new CSeq_loc); dst_bond = &loc->SetBond(); dst_bond->SetA().Assign(src_bond.GetA()); } dst_bond->SetB(*GetDstPoint()); } } break; } default: NCBI_THROW(CAnnotException, eBadLocation, "Unsupported location type"); } if ( flag == eCnvAlways && IsSpecialLoc() ) { SetDstLoc(dst); } return *dst;}void CSeq_loc_Conversion::Convert(CAnnotObject_Ref& ref, ELocationType loctype){ Reset(); const CAnnotObject_Info& obj = ref.GetAnnotObject_Info(); switch ( obj.Which() ) { case CSeq_annot::C_Data::e_Ftable: { CRef<CSeq_loc> mapped_loc; const CSeq_loc* src_loc; if ( loctype != eProduct ) { src_loc = &obj.GetFeatFast()->GetLocation(); } else { src_loc = &obj.GetFeatFast()->GetProduct(); } Convert(*src_loc, &mapped_loc); ref.SetMappedSeq_loc(mapped_loc.GetPointerOrNull()); break; } case CSeq_annot::C_Data::e_Graph: { CRef<CSeq_loc> mapped_loc; Convert(obj.GetGraphFast()->GetLoc(), &mapped_loc); ref.SetMappedSeq_loc(mapped_loc.GetPointerOrNull()); break; } default: _ASSERT(0); break; } SetMappedLocation(ref, loctype);}void CSeq_loc_Conversion::SetMappedLocation(CAnnotObject_Ref& ref, ELocationType loctype){ ref.SetProduct(loctype == eProduct); ref.SetPartial(m_Partial || ref.IsPartial()); ref.SetTotalRange(m_TotalRange); if ( IsSpecialLoc() ) { // special interval or point ref.SetMappedSeq_id(GetDstId(), m_LastType == eMappedObjType_Seq_point); ref.SetMappedStrand(m_LastStrand); m_LastType = eMappedObjType_not_set; }}/////////////////////////////////////////////////////////////////////////////// CSeq_loc_Conversion_Set/////////////////////////////////////////////////////////////////////////////CSeq_loc_Conversion_Set::CSeq_loc_Conversion_Set(CHeapScope& scope) : m_SingleConv(0), m_SingleIndex(0), m_Partial(false), m_TotalRange(TRange::GetEmpty()), m_Scope(scope){ return;}void CSeq_loc_Conversion_Set::Add(CSeq_loc_Conversion& cvt, unsigned int loc_index){ if (!m_SingleConv) { m_SingleConv.Reset(&cvt); m_SingleIndex = loc_index; return; } else { TIdMap& id_map = m_CvtByIndex[m_SingleIndex]; TRangeMap& ranges = id_map[m_SingleConv->m_Src_id_Handle]; ranges.insert(TRangeMap::value_type (TRange(cvt.m_Src_from, cvt.m_Src_to), m_SingleConv)); } TIdMap& id_map = m_CvtByIndex[loc_index]; TRangeMap& ranges = id_map[cvt.m_Src_id_Handle]; ranges.insert(TRangeMap::value_type(TRange(cvt.m_Src_from, cvt.m_Src_to), Ref(&cvt)));}CSeq_loc_Conversion_Set::TRangeIteratorCSeq_loc_Conversion_Set::BeginRanges(CSeq_id_Handle id, TSeqPos from, TSeqPos to, unsigned int loc_index){ TIdMap::iterator ranges = m_CvtByIndex[loc_index].find(id); if (ranges == m_CvtByIndex[loc_index].end()) { return TRangeIterator(); } return ranges->second.begin(TRange(from, to));}void CSeq_loc_Conversion_Set::Convert(CAnnotObject_Ref& ref, CSeq_loc_Conversion::ELocationType loctype){ _ASSERT(m_SingleConv); if (m_CvtByIndex.size() == 0 && !ref.IsAlign()) { // No multiple mappings m_SingleConv->Convert(ref, loctype); return; } const CAnnotObject_Info& obj = ref.GetAnnotObject_Info(); switch ( obj.Which() ) { case CSeq_annot::C_Data::e_Ftable: { CRef<CSeq_loc> mapped_loc; const CSeq_loc* src_loc; unsigned int loc_index = 0; if ( loctype != CSeq_loc_Conversion::eProduct ) { src_loc = &obj.GetFeatFast()->GetLocation(); } else { src_loc = &obj.GetFeatFast()->GetProduct(); loc_index = 1; } Convert(*src_loc, &mapped_loc, loc_index); ref.SetMappedSeq_loc(mapped_loc.GetPointerOrNull()); break; } case CSeq_annot::C_Data::e_Graph: { CRef<CSeq_loc> mapped_loc; Convert(obj.GetGraphFast()->GetLoc(), &mapped_loc, 0); ref.SetMappedSeq_loc(mapped_loc.GetPointerOrNull()); break; } case CSeq_annot::C_Data::e_Align: { ref.SetMappedSeq_align_Cvts(*this); break; } default: _ASSERT(0); break; } ref.SetProduct(loctype == CSeq_loc_Conversion::eProduct); ref.SetPartial(m_Partial); ref.SetTotalRange(m_TotalRange);}bool CSeq_loc_Conversion_Set::ConvertPoint(const CSeq_point& src, CRef<CSeq_loc>* dst, unsigned int loc_index){ _ASSERT(*dst); bool res = false; TRangeIterator mit = BeginRanges(CSeq_id_Handle::GetHandle(src.GetId()), src.GetPoint(), src.GetPoint(), loc_index); for ( ; mit; ++mit) { CSeq_loc_Conversion& cvt = *mit->second; cvt.Reset(); if (cvt.ConvertPoint(src)) { (*dst)->SetPnt(*cvt.GetDstPoint()); m_TotalRange += cvt.GetTotalRange(); res = true; break; } } m_Partial |= !res; return res;}bool CSeq_loc_Conversion_Set::ConvertInterval(const CSeq_interval& src, CRef<CSeq_loc>* dst, unsigned int loc_index){ _ASSERT(*dst); CRef<CSeq_loc> tmp(new CSeq_loc); CPacked_seqint::Tdata& ints = tmp->SetPacked_int().Set(); TRange total_range(TRange::GetEmpty()); bool revert_order = (src.IsSetStrand() && src.GetStrand() == eNa_strand_minus); bool res = false; TRangeIterator mit = BeginRanges(CSeq_id_Handle::GetHandle(src.GetId()), src.GetFrom(), src.GetTo(), loc_index); for ( ; mit; ++mit) { CSeq_loc_Conversion& cvt = *mit->second; cvt.Reset(); if (cvt.ConvertInterval(src)) { if (revert_order) { ints.push_front(cvt.GetDstInterval()); } else { ints.push_back(cvt.GetDstInterval()); } total_range += cvt.GetTotalRange(); res = true; } } if (ints.size() > 1) { dst->Reset(tmp); } else if (ints.size() == 1) { (*dst)->SetInt(**ints.begin()); } m_TotalRange += total_range; // does not guarantee the whole interval is mapped, but should work // in normal situations m_Partial |= (!res || src.GetLength() > total_range.GetLength()); return res;}bool CSeq_loc_Conversion_Set::Convert(const CSeq_loc& src, CRef<CSeq_loc>* dst, unsigned int loc_index){ dst->Reset(new CSeq_loc); bool res = false; 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)->SetNull(); res = true;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?