NCBI C++ ToolKit
genbank_id_resolve.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: genbank_id_resolve.cpp 93574 2021-04-30 16:19:19Z stakhovv $
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  * Authors: Frank Ludwig
27  *
28  * File Description: Write gff file
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <objmgr/util/sequence.hpp>
35 
38 
41 
42 // ----------------------------------------------------------------------------
44  mThrowOnUnresolvedGi(false),
45  mLabelType(CSeq_id::eContent)
46 // ----------------------------------------------------------------------------
47 {}
48 
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
52 {}
53 
54 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
58 {
59  static CGenbankIdResolve resolver;
60  return resolver;
61 }
62 
63 // ----------------------------------------------------------------------------
65  CSeq_id_Handle idh,
66  CScope& scope,
67  string& best_id)
68 // ----------------------------------------------------------------------------
69 {
70  if (!idh) {
71  return false;
72  }
74  if (!best_idh) {
75  best_idh = idh;
76  }
77  if (best_idh.IsGi() && mThrowOnUnresolvedGi) {
78  // we are not supposed to let any GI numbers see the light of day:
79  string msg("Unable to resolve GI number ");
80  msg += NStr::NumericToString(best_idh.GetGi());
81  NCBI_THROW(CObjWriterException, eBadInput, msg);
82  }
83  string backup = best_id;
84  try {
85  best_idh.GetSeqId()->GetLabel(&best_id, mLabelType);
86  }
87  catch (...) {
88  best_id = backup;
89  return false;
90  }
91  return true;
92 }
93 
94 // ----------------------------------------------------------------------------
96  const CMappedFeat& mf,
97  string& best_id)
98 // ----------------------------------------------------------------------------
99 {
100  CSeq_id_Handle idh = mf.GetLocationId();
101  if (idh) {
102  return GetBestId(idh, mf.GetScope(), best_id);
103  }
104  const CSeq_loc& loc = mf.GetLocation();
105  idh = sequence::GetIdHandle(loc, &mf.GetScope());
106  return GetBestId(idh, mf.GetScope(), best_id);
107 }
108 
109 // -----------------------------------------------------------------------------
111  const CSeq_loc& loc,
112  string& best_id)
113 // -----------------------------------------------------------------------------
114 {
115  const CSeq_id* pId = loc.GetId();
116  if (!pId) {
117  NCBI_THROW(CObjWriterException, eBadInput,
118  "CGenbankIdResolve: Location without good ID");
119  }
120  return GetBestId(
123  best_id);
124 }
125 
126 // -----------------------------------------------------------------------------
128 // -----------------------------------------------------------------------------
129 {
130  if (!mpDefaultScope) {
133  }
134  return *mpDefaultScope;
135 }
136 
static CGenbankIdResolve & Get()
CRef< CScope > mpDefaultScope
CSeq_id::ELabelType mLabelType
bool GetBestId(CSeq_id_Handle, CScope &, string &)
CMappedFeat –.
Definition: mapped_feat.hpp:59
CScope –.
Definition: scope.hpp:92
#define false
Definition: bool.h:36
USING_SCOPE(objects)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
CConstRef< CSeq_id > GetSeqId(void) const
bool IsGi(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
TGi GetGi(void) const
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
@ eContent
Definition: feature.hpp:87
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
CSeq_id_Handle GetIdHandle(const CSeq_loc &loc, CScope *scope)
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
CScope & GetScope(void) const
Get scope this handle belongs to.
const CSeq_loc & GetLocation(void) const
CSeq_id_Handle GetLocationId(void) const
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
Modified on Wed May 15 15:05:08 2024 by modify_doxy.py rev. 669887