1 /* $Id: idmapper_scope.cpp 632526 2021-06-02 17:25:01Z ivanov $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Aleksey Grichenko
27 *
28 * File Description:
29 *
30 */
31
32 #include <ncbi_pch.hpp>
33
34 #include <objmgr/scope.hpp>
35 #include <objmgr/seq_map_ci.hpp>
36 #include <objtools/readers/idmapper.hpp>
37
38
39 BEGIN_NCBI_SCOPE
40 USING_SCOPE(objects);
41
42
CIdMapperScope(CScope & scope,const CSeq_id_Handle & focus_idh)43 CIdMapperScope::CIdMapperScope(CScope& scope,
44 const CSeq_id_Handle& focus_idh)
45 : m_Scope(&scope)
46 {
47 x_Init(focus_idh);
48 }
49
50
CIdMapperScope(CScope & scope,const CSeq_id & focus_id)51 CIdMapperScope::CIdMapperScope(CScope& scope,
52 const CSeq_id& focus_id)
53 : m_Scope(&scope)
54 {
55 x_Init(CSeq_id_Handle::GetHandle(focus_id));
56 }
57
58
x_Init(const CSeq_id_Handle & focus_idh)59 void CIdMapperScope::x_Init(const CSeq_id_Handle& focus_idh)
60 {
61 CBioseq_Handle bh = m_Scope->GetBioseqHandle(focus_idh);
62 if ( bh ) {
63 x_AddMappings(bh);
64 SSeqMapSelector sel(CSeqMap::fFindRef, size_t(-1));
65 CSeqMap_CI it(bh, sel);
66 for (; it; ++it) {
67 _ASSERT(it.GetType() == CSeqMap::eSeqRef);
68 CBioseq_Handle itbh = m_Scope->GetBioseqHandle(it.GetRefSeqid());
69 x_AddMappings(itbh);
70 }
71 }
72 }
73
74
x_AddMappings(const CBioseq_Handle & bh)75 void CIdMapperScope::x_AddMappings(const CBioseq_Handle& bh)
76 {
77 if ( !bh ) return;
78 CBioseq_Handle::TId ids = bh.GetId();
79 CSeq_id::TSeqIdHandles matches;
80 ITERATE(CBioseq_Handle::TId, it, ids) {
81 //AddMapping(*it, *it);
82 matches.clear();
83 it->GetSeqId()->GetMatchingIds(matches);
84 ITERATE(CSeq_id::TSeqIdHandles, mit, matches) {
85 AddMapping(*mit, *it);
86 }
87 }
88 }
89
90
91 END_NCBI_SCOPE
92