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

Go to the SVN repository for this file.

1 /* $Id: table_data_ftable.cpp 32240 2015-01-22 21:53:03Z katargir $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <gui/objutils/label.hpp>
35 #include <objmgr/util/feature.hpp>
36 
37 #include "table_data_ftable.hpp"
38 
41 
43 {
44  CTableDataFTable* table_data = new CTableDataFTable();
45  table_data->m_Object = object.object;
46  table_data->m_Scope = object.scope;
47  table_data->Init();
48  return table_data;
49 }
50 
52 {
53  const CSeq_annot& seq_annot = dynamic_cast<const CSeq_annot&>(*m_Object);
54  if (seq_annot.IsFtable()) {
55  const CSeq_annot::TData::TFtable& ftable = seq_annot.GetData().GetFtable();
56  copy(ftable.begin(), ftable.end(), back_inserter(m_FTable));
57  }
58 }
59 
61 {
63 
64  if (row < m_FTable.size()) {
65  value.object = m_FTable[row];
66  value.scope = m_Scope;
67  }
68 
69  return value;
70 }
71 
73 {
74  try {
75  if (col == 0) {
76  return kString;
77  }
78  else if (col == 1) {
79  return kString;
80  }
81  else if (col == 2) {
82  return kInt;
83  }
84  else if (col == 3) {
85  return kInt;
86  }
87  else if (col == 4) {
88  return kInt;
89  }
90  else if (col == 5) {
91  return kString;
92  }
93  else if (col == 6) {
94  return kString;
95  }
96  else if (col == 7) {
97  return kInt;
98  }
99  return kNone;
100  }
101  catch (const std::exception& e) {
102  LOG_POST(Error << "CTableDataFTable: " << e.what());
103  return kNone;
104  }
105 }
106 
107 string CTableDataFTable::GetColumnLabel(size_t col) const
108 {
109  string label;
110 
111  try {
112  if (col == 0)
113  label = "Label";
114  else if (col == 1)
115  label = "Type";
116  else if (col == 2)
117  label = "Start";
118  else if (col == 3)
119  label = "Stop";
120  else if (col == 4)
121  label = "Length";
122  else if (col == 5)
123  label = "Strand";
124  else if (col == 6)
125  label = "Product";
126  else if (col == 7)
127  label = "Intervals";
128  }
129  catch (const std::exception& e) {
130  LOG_POST(Error << "CTableDataFTable: " << e.what());
131  }
132 
133  return label;
134 }
135 
137 {
138  try {
139  return m_FTable.size();
140  }
141  catch (const std::exception& e) {
142  LOG_POST(Error << "CTableDataFTable: " << e.what());
143  return 0;
144  }
145 }
146 
148 {
149  try {
150  return 8;
151  }
152  catch (const std::exception& e) {
153  LOG_POST(Error << "CTableDataFTable: " << e.what());
154  return 0;
155  }
156 }
157 
158 static int s_CountIntervals( const CSeq_loc& loc ){
159 
160  switch( loc.Which() ){
161  case CSeq_loc::e_Null:
162  case CSeq_loc::e_Empty:
163  case CSeq_loc::e_Whole:
164  case CSeq_loc::e_Int:
165  case CSeq_loc::e_Pnt:
166  case CSeq_loc::e_Bond:
167  case CSeq_loc::e_Feat:
168  return 1;
169 
171  return (int)loc.GetPacked_int().Get().size();
172 
174  return (int)loc.GetPacked_pnt().GetPoints().size();
175 
176  case CSeq_loc::e_Mix:
177  {{
178  int ivals = 0;
179  ITERATE( CSeq_loc::TMix::Tdata, iter, loc.GetMix().Get() ){
180  ivals += s_CountIntervals(**iter);
181  }
182  return ivals;
183  }}
184 
185  default:
186  {{
187  int size = 0;
188  for( CSeq_loc_CI iter( loc ); iter; ++iter ){
189  ++size;
190  }
191  return size;
192  }}
193  }
194 }
195 
196 void CTableDataFTable::GetStringValue(size_t row, size_t col, string& value) const
197 {
198  value.resize(0);
199  try {
200  if (row < m_FTable.size()) {
201 
202  switch(col) {
203  case 0 :
205  break;
206  case 1 :
208  break;
209  case 5 :
210  {{
211  ENa_strand naStrand = sequence::GetStrand( m_FTable[row]->GetLocation() );
212  switch( naStrand ){
213  case eNa_strand_unknown:
214  value = "?";
215  break;
216  case eNa_strand_plus:
217  value = "+";
218  break;
219  case eNa_strand_minus:
220  value = "-";
221  break;
222  case eNa_strand_both:
223  value = "+-";
224  break;
225  case eNa_strand_both_rev:
226  value = "+- (rev)";
227  break;
228  case eNa_strand_other:
229  value = "other";
230  break;
231  }
232  }}
233  break;
234  case 6 :
235  if (m_FTable[row]->IsSetProduct()) {
236  const CSeq_loc& loc = m_FTable[row]->GetProduct();
238  }
239  break;
240  default:
241  break;
242  }
243  }
244  }
245  catch (const std::exception& e) {
246  LOG_POST(Error << "CTableDataFTable: " << e.what());
247  }
248 }
249 
250 
251 long CTableDataFTable::GetIntValue(size_t row, size_t col) const
252 {
253  long value = 0;
254  try {
255  if (row < m_FTable.size()) {
256  const CSeq_loc& loc = m_FTable[row]->GetLocation();
258  switch(col) {
259  case 2 :
260  value = (int) range.GetFrom() + 1;
261  break;
262  case 3 :
263  value = (int) range.GetTo() + 1;
264  break;
265  case 4 :
266  value = (int) range.GetLength();
267  break;
268  case 7 :
269  value = s_CountIntervals(loc);
270  break;
271  default:
272  break;
273  }
274  }
275  }
276  catch (const std::exception& e) {
277  LOG_POST(Error << "CTableDataFTable: " << e.what());
278  }
279  return value;
280 }
281 
282 double CTableDataFTable::GetRealValue(size_t row, size_t col) const
283 {
284  double value = 0;
285  return value;
286 }
287 
289 {
291  return value;
292 }
293 
bool IsFtable(void) const
Definition: Seq_annot.cpp:177
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:453
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
virtual string GetColumnLabel(size_t col) const
static CTableDataFTable * CreateObject(SConstScopedObject &object, ICreateParams *params)
CConstRef< CObject > m_Object
virtual void GetStringValue(size_t row, size_t col, string &value) const
virtual double GetRealValue(size_t row, size_t col) const
virtual long GetIntValue(size_t row, size_t col) const
virtual SConstScopedObject GetRowObject(size_t row) const
vector< CRef< objects::CSeq_feat > > m_FTable
virtual size_t GetRowsCount() const
virtual SConstScopedObject GetObjectValue(size_t row, size_t col) const
CRef< objects::CScope > m_Scope
virtual size_t GetColsCount() const
virtual ColumnType GetColumnType(size_t col) const
@ eDefault
Definition: label.hpp:73
string GetLabel(const CSeq_id &id)
TRange GetTotalRange(void) const
Definition: Seq_loc.hpp:913
@ fFGL_Type
Always include the feature's type.
Definition: feature.hpp:72
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...
#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 const char label[]
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
const Tdata & Get(void) const
Get the member data.
list< CRef< CSeq_loc > > Tdata
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_loc_.hpp:475
const Tdata & Get(void) const
Get the member data.
const TPacked_pnt & GetPacked_pnt(void) const
Get the variant data.
Definition: Seq_loc_.cpp:260
const TPoints & GetPoints(void) const
Get the Points member data.
const TMix & GetMix(void) const
Get the variant data.
Definition: Seq_loc_.cpp:282
const TPacked_int & GetPacked_int(void) const
Get the variant data.
Definition: Seq_loc_.cpp:216
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_other
Definition: Na_strand_.hpp:70
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
@ eNa_strand_both_rev
in reverse orientation
Definition: Na_strand_.hpp:69
@ eNa_strand_both
in forward orientation
Definition: Na_strand_.hpp:68
@ e_Null
not placed
Definition: Seq_loc_.hpp:98
@ e_Empty
to NULL one Seq-id in a collection
Definition: Seq_loc_.hpp:99
@ e_Feat
indirect, through a Seq-feat
Definition: Seq_loc_.hpp:108
@ e_Int
from to
Definition: Seq_loc_.hpp:101
@ e_Whole
whole sequence
Definition: Seq_loc_.hpp:100
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:621
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
range(_Ty, _Ty) -> range< _Ty >
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
#define row(bind, expected)
Definition: string_bind.c:73
USING_SCOPE(objects)
static int s_CountIntervals(const CSeq_loc &loc)
#define ftable
Definition: utilfeat.h:37
Modified on Wed Apr 24 14:12:43 2024 by modify_doxy.py rev. 669887