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

Go to the SVN repository for this file.

1 /* $Id: Delta_ext.cpp 74562 2016-09-13 13:46:29Z 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: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'seq.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
47 #include <objects/seq/Seq_data.hpp>
48 #include <objects/seq/IUPACaa.hpp>
49 #include <objects/seq/IUPACna.hpp>
50 #include <objects/seq/NCBI2na.hpp>
51 #include <objects/seq/NCBI4na.hpp>
52 #include <objects/seq/NCBI8na.hpp>
54 
55 // generated classes
56 
58 
59 BEGIN_objects_SCOPE // namespace ncbi::objects::
60 
61 // destructor
63 {
64 }
65 
66 
67 /// add a literal segment at the end
68 /// this variant adds a gap literal
70 {
71  if ( !Get().empty() && Get().back()->IsLiteral()
72  && !Get().back()->GetLiteral().IsSetSeq_data()
73  && !Get().back()->GetLiteral().IsSetFuzz()) {
74  // merge adjacent plain gaps
75  Set().back()->SetLiteral().SetLength() += len;
76  return *Set().back();
77  }
78 
79  CRef<CDelta_seq> seg(new CDelta_seq());
80  seg->SetLiteral().SetLength(len);
81 
82  Set().push_back(seg);
83  return *seg;
84 }
85 
86 
87 /// add a literal segment at the end
88 /// this variant adds a non-gap literal
90  CSeq_inst::EMol mol, bool do_pack)
91 {
92  CRef<CDelta_seq> seg(new CDelta_seq());
93  seg->SetLiteral().SetLength((CSeq_literal::TLength)iupac_seq.size());
94 
95  switch (mol) {
96  case CSeq_inst::eMol_aa:
97  seg->SetLiteral().SetSeq_data().SetIupacaa().Set().assign(iupac_seq.data(), iupac_seq.length());
98  break;
99 
100  case CSeq_inst::eMol_na:
101  case CSeq_inst::eMol_dna:
102  case CSeq_inst::eMol_rna:
103  seg->SetLiteral().SetSeq_data().SetIupacna().Set().assign(iupac_seq.data(), iupac_seq.length());
104  if (do_pack)
105  CSeqportUtil::Pack(&seg->SetLiteral().SetSeq_data());
106  break;
107 
108  default:
110  "CDelta_ext::AddLiteral(): unhandled mol type");
111  break;
112  }
113 
114  Set().push_back(seg);
115  return *seg;
116 }
117 
118 
120 {
121 public:
122  CDelta_ext_PackTarget(CDelta_ext& obj, bool gaps_ok)
123  : m_Obj(obj), m_GapsOK(gaps_ok)
124  { }
125 
126  // Rough memory overhead per segment, in bytes. The actual values
127  // are system specific, but this code's behavior shouldn't be.
129  { return coding == CSeqUtil::e_not_set ? 96 : 128; }
130 
131  virtual bool GapsOK(TCodingType) const { return m_GapsOK; }
132 
133  char* NewSegment(TCoding coding, TSeqPos length);
134 
135 private:
137  bool m_GapsOK;
138 };
139 
140 
142  TSeqPos length)
143 {
145  CSeq_literal& lit = ds->SetLiteral();
146  lit.SetLength(length);
147  m_Obj.Set().push_back(ds);
148 
149  switch (coding) {
150  case CSeqUtil::e_not_set:
151  return NULL;
152 
153 #define CODING_CASE_EX(key, type, setter, len) \
154  case CSeqUtil::key: \
155  { \
156  type& dest = lit.SetSeq_data().setter(); \
157  dest.Set().resize(len); \
158  return &dest.Set()[0]; \
159  }
160 #define CODING_CASE(name, type) \
161  CODING_CASE_EX(e_##name, type, Set##name, length)
162 
163  CODING_CASE_EX(e_Ncbi2na, CNCBI2na, SetNcbi2na, (length + 3) / 4)
164  CODING_CASE_EX(e_Ncbi4na, CNCBI4na, SetNcbi4na, (length + 1) / 2)
165 
166  // case CSeqUtil::e_Ncbi4na_expand:
167  // CODING_CASE(Ncbi8na, CNCBI8na)
168 
169  CODING_CASE(Iupacaa, CIUPACaa)
170  CODING_CASE(Ncbi8aa, CNCBI8aa)
171  CODING_CASE(Ncbieaa, CNCBIeaa)
172  CODING_CASE(Ncbistdaa, CNCBIstdaa)
173 #undef CODING_CASE
174 #undef CODING_CASE_EX
175 
176  default:
177  NCBI_THROW(CSeqUtilException, eInvalidCoding,
178  "CDelta_ext_PackTarget: unexpected coding");
179  }
180 }
181 
182 
184  TSeqPos length /* in residues */,
185  bool gaps_ok, bool allow_packing)
186 {
188 
189  switch (in_format) {
190  case CSeq_data::e_Iupacna: coding = CSeqUtil::e_Iupacna; break;
191  case CSeq_data::e_Iupacaa: coding = CSeqUtil::e_Iupacaa; break;
192  case CSeq_data::e_Ncbi4na: coding = CSeqUtil::e_Ncbi4na; break;
193  case CSeq_data::e_Ncbi8na: coding = CSeqUtil::e_Ncbi8na; break;
194  case CSeq_data::e_Ncbi8aa: coding = CSeqUtil::e_Ncbi8aa; break;
195  case CSeq_data::e_Ncbieaa: coding = CSeqUtil::e_Ncbieaa; break;
196  case CSeq_data::e_Ncbistdaa: coding = CSeqUtil::e_Ncbistdaa; break;
197  default:
198  coding = CSeqUtil::e_not_set;
199  }
200 
201  if (allow_packing)
202  {
203  CDelta_ext_PackTarget dst(*this, gaps_ok);
204  CSeqConvert::Pack(src.data(), length, coding, dst);
205  }
206  else
207  {
208  // add as a single piece
209  CRef<CSeq_data> data (new CSeq_data(src, in_format));
210  CRef<CDelta_seq> ds (new CDelta_seq);
211  CSeq_literal& lit = ds->SetLiteral();
212  lit.SetLength(length);
213  lit.SetSeq_data(*data);
214  Set().push_back(ds);
215  }
216 }
217 
218 /// add a segment that refers to another segment
220  TSeqPos from, TSeqPos to,
221  ENa_strand strand)
222 {
223  CRef<CDelta_seq> seg(new CDelta_seq());
224  seg->SetLoc().SetInt().SetFrom(from);
225  seg->SetLoc().SetInt().SetTo (to);
226  seg->SetLoc().SetId(id);
227  seg->SetLoc().SetStrand(strand);
228 
229  Set().push_back(seg);
230  return *seg;
231 }
232 
233 
234 END_objects_SCOPE // namespace ncbi::objects::
235 
237 
238 /* Original file checksum: lines: 65, chars: 1883, CRC32: 149e396a */
#define CODING_CASE(name, type)
#define CODING_CASE_EX(key, type, setter, len)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CDelta_ext_PackTarget(CDelta_ext &obj, bool gaps_ok)
Definition: Delta_ext.cpp:122
virtual bool GapsOK(TCodingType) const
Definition: Delta_ext.cpp:131
char * NewSegment(TCoding coding, TSeqPos length)
Definition: Delta_ext.cpp:141
SIZE_TYPE GetOverhead(TCoding coding) const
Definition: Delta_ext.cpp:128
CDelta_ext & m_Obj
Definition: Delta_ext.cpp:136
~CDelta_ext(void)
Definition: Delta_ext.cpp:62
void AddAndSplit(const CTempString &src, CSeq_data::E_Choice format, TSeqPos length, bool gaps_ok=false, bool allow_packing=true)
add a chunk of sequence, splitting it as necessary for the sake of compactness (isolating ambiguous p...
Definition: Delta_ext.cpp:183
CDelta_seq & AddSeqRange(const CSeq_id &id, TSeqPos from, TSeqPos to, ENa_strand strand=eNa_strand_plus)
add a segment that refers to another segment
Definition: Delta_ext.cpp:219
CDelta_seq & AddLiteral(TSeqPos len)
add a literal segment at the end this variant adds a gap literal
Definition: Delta_ext.cpp:69
CDelta_seq –.
Definition: Delta_seq.hpp:66
CIUPACaa –.
Definition: IUPACaa.hpp:66
CNCBI2na –.
Definition: NCBI2na.hpp:66
CNCBI4na –.
Definition: NCBI4na.hpp:66
CNCBI8aa –.
Definition: NCBI8aa.hpp:66
CNCBIeaa –.
Definition: NCBIeaa.hpp:66
CNCBIstdaa –.
Definition: NCBIstdaa.hpp:66
CRef –.
Definition: ncbiobj.hpp:618
static SIZE_TYPE Pack(const string &src, TCoding src_coding, vector< char > &dst, TCoding &dst_coding, TSeqPos length=ncbi::numeric_limits< TSeqPos >::max())
@ e_Ncbi8na
Definition: sequtil.hpp:52
@ e_Iupacna
Definition: sequtil.hpp:47
@ e_Ncbieaa
Definition: sequtil.hpp:57
@ e_not_set
Definition: sequtil.hpp:44
@ e_Ncbi8aa
Definition: sequtil.hpp:56
@ e_Ncbi4na
Definition: sequtil.hpp:50
@ e_Ncbistdaa
Definition: sequtil.hpp:58
@ e_Iupacaa
Definition: sequtil.hpp:55
static TSeqPos Pack(CSeq_data *in_seq, TSeqPos uLength=ncbi::numeric_limits< TSeqPos >::max())
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define NULL
Definition: ncbistd.hpp:225
#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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
const char * data(void) const
Return a pointer to the array represented.
Definition: tempstr.hpp:313
size_type length(void) const
Return the length of the represented array.
Definition: tempstr.hpp:320
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
void SetLength(TLength value)
Assign a value to Length data member.
void SetSeq_data(TSeq_data &value)
Assign a value to Seq_data data member.
E_Choice
Choice variants.
Definition: Seq_data_.hpp:102
Tdata & Set(void)
Assign a value to data member.
Definition: Delta_ext_.hpp:170
EMol
molecule class in living organism
Definition: Seq_inst_.hpp:108
const Tdata & Get(void) const
Get the member data.
Definition: Delta_ext_.hpp:164
@ e_Ncbieaa
extended ASCII 1 letter aa codes
Definition: Seq_data_.hpp:111
@ e_Ncbistdaa
consecutive codes for std aas
Definition: Seq_data_.hpp:113
@ e_Iupacna
IUPAC 1 letter nuc acid code.
Definition: Seq_data_.hpp:104
@ e_Ncbi8na
8 bit extended nucleic acid code
Definition: Seq_data_.hpp:108
@ e_Ncbi4na
4 bit nucleic acid code
Definition: Seq_data_.hpp:107
@ e_Iupacaa
IUPAC 1 letter amino acid code.
Definition: Seq_data_.hpp:105
@ e_Ncbi8aa
8 bit extended amino acid codes
Definition: Seq_data_.hpp:110
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
int len
constexpr bool empty(list< Ts... >) noexcept
Modified on Thu Feb 22 17:12:59 2024 by modify_doxy.py rev. 669887