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

Go to the SVN repository for this file.

1 /* $Id: id_handler.cpp 65385 2014-11-25 16:39:11Z whlavina $
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: Vyacheslav Chetvernin
27  * File Description:
28  *
29  */
30 
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbistr.hpp>
33 
35 
40 #include <objmgr/scope.hpp>
41 #include <objmgr/util/sequence.hpp>
42 #include <objmgr/seq_vector.hpp>
43 
45 BEGIN_SCOPE(gnomon)
46 
48 
50  : m_Scope(scope)
51 {
52 }
53 
55 {
56  CConstRef<CSeq_id> canonical_id;
57  try {
59  canonical_id = idh.GetSeqId();
60  } catch (sequence::CSeqIdFromHandleException& e) {
61  if (e.GetErrCode() != sequence::CSeqIdFromHandleException::eRequestedIdNotFound)
62  throw;
63  canonical_id.Reset(&id);
64  }
65  return canonical_id;
66 }
67 
68 string CIdHandler::ToString(const CSeq_id& id)
69 {
70  return id.AsFastaString();
71 }
72 
74 {
75  return CRef<CSeq_id>(new CSeq_id(str));
76 }
77 
79 {
81  CSeq_id::TGeneral& gnl = result->SetGeneral();
82  gnl.SetDb("GNOMON");
83  gnl.SetTag().SetStr(NStr::NumericToString(id) + ".m");
84  return result;
85 }
86 
88 {
90  CSeq_id::TGeneral& gnl = result->SetGeneral();
91  gnl.SetDb("GNOMON");
92  gnl.SetTag().SetStr(NStr::NumericToString(id) + ".p");
93  return result;
94 }
95 
96 bool CIdHandler::IsId(const CObject_id& obj)
97 {
98  Int8 id;
99  switch (obj.GetIdType(id)) {
101  return false;
102  default:
103  return true;
104  }
105 }
106 
108 {
109  Int8 id;
110  switch (obj.GetIdType(id)) {
112  NCBI_THROW(CException, eUnknown, "No integral ID for object ID");
113  default:
114  ;
115  }
116  return id;
117 }
118 
120 {
123  obj.SetId(static_cast<CObject_id::TId>(value));
124  } else {
126  }
127 }
128 
129 
131 {
132  CBioseq_Handle bh (scope.GetBioseqHandle(*id));
133  if (!bh) {
134  NCBI_THROW(CException, eUnknown, "Sequence '"+CIdHandler::ToString(*id)+"' retrieval failed");
135  }
137  string seq;
138  sv.GetSeqData(0, sv.size(), seq);
139 
140  return seq;
141 }
142 
143 END_SCOPE(gnomon)
static CRef< CScope > m_Scope
CBioseq_Handle –.
Definition: Dbtag.hpp:53
static bool IsId(const CObject_id &obj)
Definition: id_handler.cpp:96
static CRef< CSeq_id > GnomonMRNA(Int8 id)
Definition: id_handler.cpp:78
static void SetId(CObject_id &obj, Int8 value)
Definition: id_handler.cpp:119
static CRef< CSeq_id > ToSeq_id(const string &str)
Definition: id_handler.cpp:73
static string ToString(const CSeq_id &id)
Definition: id_handler.cpp:68
static Int8 GetId(const CObject_id &obj)
Definition: id_handler.cpp:107
CScope & m_Scope
Definition: id_handler.hpp:66
static CRef< CSeq_id > GnomonProtein(Int8 id)
Definition: id_handler.cpp:87
CConstRef< CSeq_id > ToCanonical(const CSeq_id &id) const
Definition: id_handler.cpp:54
E_Choice GetIdType(TId8 &value) const
Definition: Object_id.cpp:93
CScope –.
Definition: scope.hpp:92
CSeqVector –.
Definition: seq_vector.hpp:65
char value[7]
Definition: config.c:431
The NCBI C++ standard methods for dealing with std::string.
#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
@ eUnknown
Definition: app_popup.hpp:72
CConstRef< CSeq_id > GetSeqId(void) const
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,...
@ eGetId_ThrowOnError
Throw exception on errors. If not set, an empty value is returned.
Definition: sequence.hpp:122
@ eGetId_Canonical
Definition: sequence.hpp:114
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CSeqVector GetSeqVector(EVectorCoding coding, ENa_strand strand=eNa_strand_plus) const
Get sequence: Iupacna or Iupacaa if use_iupac_coding is true.
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
void GetSeqData(TSeqPos start, TSeqPos stop, string &buffer) const
Fill the buffer string with the sequence data for the interval [start, stop).
Definition: seq_vector.cpp:304
TSeqPos size(void) const
Definition: seq_vector.hpp:291
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
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
void SetTag(TTag &value)
Assign a value to Tag data member.
Definition: Dbtag_.cpp:66
TStr & SetStr(void)
Select the variant.
Definition: Object_id_.hpp:304
void SetDb(const TDb &value)
Assign a value to Db data member.
Definition: Dbtag_.hpp:229
TId & SetId(void)
Select the variant.
Definition: Object_id_.hpp:277
@ e_not_set
No variant selected.
Definition: Object_id_.hpp:89
USING_SCOPE(objects)
string GetDNASequence(CConstRef< objects::CSeq_id > id, CScope &scope)
Definition: id_handler.cpp:130
T max(T x_, T y_)
T min(T x_, T y_)
The Object manager core.
static const char * str(char *buf, int n)
Definition: stats.c:84
else result
Definition: token2.c:20
Modified on Thu Mar 28 17:05:29 2024 by modify_doxy.py rev. 669887