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

Go to the SVN repository for this file.

1 /* $Id: gff_feature_record.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  * Author: Frank Ludwig
27  *
28  * File Description:
29  * GFF file reader
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
36 
38 BEGIN_objects_SCOPE // namespace ncbi::objects::
39 
40 // ----------------------------------------------------------------------------
42  const string& id):
43 // ----------------------------------------------------------------------------
44  CGffBaseRecord(id)
45 {};
46 
47 // ----------------------------------------------------------------------------
49  const CGffFeatureRecord& other):
50 // ----------------------------------------------------------------------------
51 CGffBaseRecord(other){};
52 
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
56 {};
57 
58 // ----------------------------------------------------------------------------
60  const CSeq_loc& loc)
61 // ----------------------------------------------------------------------------
62 {
63  m_pLoc.Reset(new CSeq_loc());
64  m_pLoc->Assign(loc);
65 }
66 
67 // ----------------------------------------------------------------------------
69  unsigned int start,
70  unsigned int stop,
71  ENa_strand strand)
72 // ----------------------------------------------------------------------------
73 {
74  CGffBaseRecord::SetLocation(start, stop, strand);
75 }
76 
77 // ----------------------------------------------------------------------------
79  const CSeq_interval& interval,
80  unsigned int wrapSize,
81  unsigned int wrapPoint)
82 // ----------------------------------------------------------------------------
83 {
84  m_pLoc.Reset(new CSeq_loc());
85  m_pLoc->SetInt().Assign(interval);
86  if ( interval.CanGetFrom() ) {
87  mSeqStart = interval.GetFrom();
88  }
89  if ( interval.CanGetTo() ) {
90  mSeqStop = interval.GetTo();
91  }
92  if (wrapSize != 0 && mSeqStart < wrapPoint) {
93  mSeqStart += wrapSize;
94  mSeqStop += wrapSize;
95  }
96  unsigned int seqStart = Location().GetStart(eExtreme_Positional);
97  unsigned int seqStop = Location().GetStop(eExtreme_Positional);
98  string min = NStr::IntToString(seqStart + 1);
99  string max = NStr::IntToString(seqStop + 1);
100  if (Location().IsPartialStart(eExtreme_Biological)) {
101  if (Location().GetStrand() == eNa_strand_minus) {
102  SetAttribute("end_range", max + string(",."));
103  }
104  else {
105  SetAttribute("start_range", string(".,") + min);
106  }
107  }
108  if (Location().IsPartialStop(eExtreme_Biological)) {
109  if (Location().GetStrand() == eNa_strand_minus) {
110  SetAttribute("start_range", string(".,") + min);
111  }
112  else {
113  SetAttribute("end_range", max + string(",."));
114  }
115  }
116 
117  if ( interval.IsSetStrand() ) {
118  SetStrand(interval.GetStrand());
119  }
120 }
121 
122 // ----------------------------------------------------------------------------
124  CMappedFeat mf)
125 // ----------------------------------------------------------------------------
126 {
127  SetAttribute("gbkey", mf.GetData().GetKey());
128 }
129 
130 // ----------------------------------------------------------------------------
132  const string& id):
133 // ----------------------------------------------------------------------------
134  CGffBaseRecord(id),
135  mRecordId(id),
136  mGapIsTrivial(true),
137  mAccumulatedMatches(0)
138 {
139 }
140 
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
144 {
145  return mAttrGap;
146 }
147 
148 // ----------------------------------------------------------------------------
150  unsigned int size)
151 // ----------------------------------------------------------------------------
152 {
153  FinalizeMatches();
154  if (!mAttrGap.empty()) {
155  mAttrGap += " ";
156  }
157  mAttrGap += "I";
159  mGapIsTrivial = false;
160 }
161 
162 
163 // ----------------------------------------------------------------------------
165  unsigned int size)
166 // ----------------------------------------------------------------------------
167 {
168  FinalizeMatches();
169  if (!mAttrGap.empty()) {
170  mAttrGap += " ";
171  }
172  mAttrGap += "F";
174  mGapIsTrivial = false;
175 }
176 
177 
178 // ----------------------------------------------------------------------------
180  unsigned int size)
181 // ----------------------------------------------------------------------------
182 {
183  FinalizeMatches();
184  if (!mAttrGap.empty()) {
185  mAttrGap += " ";
186  }
187  mAttrGap += "R";
189  mGapIsTrivial = false;
190 }
191 
192 
193 // ----------------------------------------------------------------------------
195  unsigned int size)
196 // ----------------------------------------------------------------------------
197 {
198  FinalizeMatches();
199  if (!mAttrGap.empty()) {
200  mAttrGap += " ";
201  }
202  mAttrGap += "D";
204  mGapIsTrivial = false;
205 }
206 
207 
208 // ----------------------------------------------------------------------------
210  unsigned int size)
211 // ----------------------------------------------------------------------------
212 {
214 }
215 
216 // -----------------------------------------------------------------------------
218 // -----------------------------------------------------------------------------
219 {
220  if (mAccumulatedMatches != 0) {
221  if (!mAttrGap.empty()) {
222  mAttrGap += " ";
223  }
224  mAttrGap += "M";
227  }
228  if (!mGapIsTrivial) {
229  SetAttribute("Gap", mAttrGap);
230  }
231 }
232 
233 // -----------------------------------------------------------------------------
235 // -----------------------------------------------------------------------------
236 {
237  string attributes;
238  attributes.reserve(256);
239 
240  if (!mRecordId.empty()) {
241  attributes += "ID=";
243  }
244  auto baseAttributes = CGffBaseRecord::StrAttributes();
245  if (!baseAttributes.empty()) {
247  attributes += baseAttributes;
248  }
249  return attributes;
250 }
251 
252 END_objects_SCOPE
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
void AddInsertion(unsigned int)
void AddMatch(unsigned int)
void AddReverseShift(unsigned int)
string StrGap() const
void AddDeletion(unsigned int)
unsigned int mAccumulatedMatches
string StrAttributes() const
void AddForwardShift(unsigned int)
CGffAlignRecord(const string &id="")
virtual string StrAttributes() const
CRef< CSeq_loc > m_pLoc
void SetLocation(unsigned int, unsigned int, ENa_strand=objects::eNa_strand_unknown)
void SetStrand(ENa_strand)
bool SetAttribute(const string &, const string &)
static const char * ATTR_SEPARATOR
unsigned int mSeqStart
unsigned int mSeqStop
void InitLocation(const CSeq_loc &)
const CSeq_loc & Location() const
void SetLocation(const CSeq_interval &, unsigned int, unsigned int=0)
void SetGbKeyFrom(CMappedFeat)
void SetEndpoints(unsigned int start, unsigned int stop, ENa_strand strand)
CGffFeatureRecord(const string &id="")
CMappedFeat –.
Definition: mapped_feat.hpp:59
string GetKey(EVocabulary vocab=eVocabulary_full) const
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define true
Definition: bool.h:35
static const struct attribute attributes[]
Definition: attributes.c:165
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Override Assign() to incorporate cache invalidation.
Definition: Seq_loc.cpp:337
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
Definition: Seq_loc.cpp:915
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
TSeqPos GetStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:963
ENa_strand GetStrand(const CSeq_loc &loc, CScope *scope=0)
Returns eNa_strand_unknown if multiple Bioseqs in loc Returns eNa_strand_other if multiple strands in...
const CSeqFeatData & GetData(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 string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
TFrom GetFrom(void) const
Get the From member data.
bool CanGetTo(void) const
Check if it is safe to call GetTo method.
bool IsSetStrand(void) const
Check if a value has been assigned to Strand data member.
TStrand GetStrand(void) const
Get the Strand member data.
TTo GetTo(void) const
Get the To member data.
bool CanGetFrom(void) const
Check if it is safe to call GetFrom method.
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
const struct ncbi::grid::netcache::search::fields::SIZE size
T max(T x_, T y_)
T min(T x_, T y_)
#define const
Definition: zconf.h:232
Modified on Wed Apr 17 13:10:27 2024 by modify_doxy.py rev. 669887