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

Go to the SVN repository for this file.

1 /* $Id: seq_table_info.cpp 89909 2020-04-30 12:40:14Z grichenk $
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: Eugene Vasilchenko
27 *
28 * File Description:
29 * CSeq_table_Info -- parsed information about Seq-table and its columns
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
42 #include <objmgr/error_codes.hpp>
43 
44 #include <objmgr/feat_ci.hpp>
45 #include <objmgr/table_field.hpp>
46 
47 #define NCBI_USE_ERRCODE_X ObjMgr_SeqTable
48 
50 
52 
54 
55 
56 /////////////////////////////////////////////////////////////////////////////
57 // CSeqTableColumnInfo
58 /////////////////////////////////////////////////////////////////////////////
59 
60 bool CSeqTableColumnInfo::IsSet(size_t row) const
61 {
62  return m_Column->IsSet(row);
63 }
64 
65 
67 {
68  NCBI_THROW(CAnnotException, eOtherError,
69  "CSeqTableColumnInfo::GetValue: value is not set");
70 }
71 
72 
74 {
75  const CSeqTable_column& col = *m_Column;
76  return col.IsSetDefault() && !col.IsSetData() && !col.IsSetSparse();
77 }
78 
79 
80 const string* CSeqTableColumnInfo::GetStringPtr(size_t row,
81  bool force) const
82 {
83  const string* ret = m_Column->GetStringPtr(row);
84  if ( !ret && force ) {
86  }
87  return ret;
88 }
89 
90 
91 const vector<char>* CSeqTableColumnInfo::GetBytesPtr(size_t row,
92  bool force) const
93 {
94  const vector<char>* ret = m_Column->GetBytesPtr(row);
95  if ( !ret && force ) {
97  }
98  return ret;
99 }
100 
101 
103  bool force) const
104 {
106  if ( !ret && force ) {
108  }
109  return ret;
110 }
111 
112 
114  bool force) const
115 {
117  if ( !ret && force ) {
119  }
120  return ret;
121 }
122 
123 
125  const CSeqTable_single_data& data,
126  const CSeqTableSetLocField& setter) const
127 {
128  switch ( data.GetValueType() ) {
130  setter.SetInt(loc, data.GetInt());
131  return;
133  setter.SetInt8(loc, data.GetInt8());
134  return;
136  setter.SetReal(loc, data.GetReal());
137  return;
139  setter.SetString(loc, data.GetString());
140  return;
141  default:
142  ERR_POST_X(1, "Bad field data type: "<<data.Which());
143  return;
144  }
145 }
146 
147 
149  const CSeqTable_single_data& data,
150  const CSeqTableSetFeatField& setter) const
151 {
152  switch ( data.GetValueType() ) {
154  setter.SetInt(feat, data.GetBit());
155  return;
157  setter.SetInt(feat, data.GetInt());
158  return;
160  setter.SetInt8(feat, data.GetInt8());
161  return;
163  setter.SetReal(feat, data.GetReal());
164  return;
166  setter.SetString(feat, data.GetString());
167  return;
169  setter.SetBytes(feat, data.GetBytes());
170  return;
171  default:
172  ERR_POST_X(2, "Bad field data type: "<<data.Which());
173  return;
174  }
175 }
176 
177 
179  const CSeqTable_multi_data& data,
180  size_t index,
181  const CSeqTableSetLocField& setter) const
182 {
183  switch ( data.GetValueType() ) {
185  int value_int;
186  if ( data.TryGetValue(index, value_int) ) {
187  setter.SetInt(loc, value_int);
188  return true;
189  }
190  break;
192  Int8 value_int8;
193  if ( data.TryGetValue(index, value_int8) ) {
194  setter.SetInt8(loc, value_int8);
195  return true;
196  }
197  break;
199  double value_real;
200  if ( data.TryGetValue(index, value_real) ) {
201  setter.SetReal(loc, value_real);
202  return true;
203  }
204  break;
206  if ( const string* ptr = data.GetStringPtr(index) ) {
207  setter.SetString(loc, *ptr);
208  return true;
209  }
210  break;
211  default:
212  ERR_POST_X(4, "Bad field data type: "<<data.Which());
213  return true;
214  }
215  return false;
216 }
217 
218 
220  const CSeqTable_multi_data& data,
221  size_t index,
222  const CSeqTableSetFeatField& setter) const
223 {
224  switch ( data.GetValueType() ) {
226  int value_int;
227  if ( data.TryGetValue(index, value_int) ) {
228  setter.SetInt(feat, value_int);
229  return true;
230  }
231  break;
233  Int8 value_int8;
234  if ( data.TryGetValue(index, value_int8) ) {
235  setter.SetInt8(feat, value_int8);
236  return true;
237  }
238  break;
240  double value_real;
241  if ( data.TryGetValue(index, value_real) ) {
242  setter.SetReal(feat, value_real);
243  return true;
244  }
245  break;
248  if ( const string* ptr = data.GetStringPtr(index) ) {
249  setter.SetString(feat, *ptr);
250  return true;
251  }
252  break;
255  if ( const vector<char>* ptr = data.GetBytesPtr(index) ) {
256  setter.SetBytes(feat, *ptr);
257  return true;
258  }
259  break;
260  default:
261  ERR_POST_X(7, "Bad field data type: "<<data.Which());
262  return true;
263  }
264  return false;
265 }
266 
267 
269  const CSeqTableSetLocField& setter) const
270 {
271  size_t index = row;
272  if ( m_Column->IsSetSparse() ) {
273  index = m_Column->GetSparse().GetIndexAt(row);
274  if ( index == CSeqTable_sparse_index::kSkipped ) {
275  if ( m_Column->IsSetSparse_other() ) {
276  UpdateSeq_loc(loc, m_Column->GetSparse_other(), setter);
277  }
278  return;
279  }
280  }
281 
282  if ( m_Column->IsSetData() &&
283  UpdateSeq_loc(loc, m_Column->GetData(), index, setter) ) {
284  return;
285  }
286 
287  if ( m_Column->IsSetDefault() ) {
288  UpdateSeq_loc(loc, m_Column->GetDefault(), setter);
289  }
290  else if ( !m_Column->IsSetData() ) {
291  // no multi or single data -> no value, but we need to touch the field
292  setter.SetInt(loc, 0);
293  }
294 }
295 
296 
298  const CSeqTableSetFeatField& setter) const
299 {
300  size_t index = row;
301  if ( m_Column->IsSetSparse() ) {
302  index = m_Column->GetSparse().GetIndexAt(row);
303  if ( index == CSeqTable_sparse_index::kSkipped ) {
304  if ( m_Column->IsSetSparse_other() ) {
305  UpdateSeq_feat(feat, m_Column->GetSparse_other(), setter);
306  }
307  return;
308  }
309  }
310 
311  if ( m_Column->IsSetData() &&
312  UpdateSeq_feat(feat, m_Column->GetData(), index, setter) ) {
313  return;
314  }
315 
316  if ( m_Column->IsSetDefault() ) {
317  UpdateSeq_feat(feat, m_Column->GetDefault(), setter);
318  }
319  else if ( !m_Column->IsSetData() ) {
320  // no multi or single data -> no value, but we need to touch the field
321  setter.SetInt(feat, 0);
322  }
323 }
324 
325 
326 /////////////////////////////////////////////////////////////////////////////
327 // CSeqTableLocColumns
328 /////////////////////////////////////////////////////////////////////////////
329 
330 
333  : m_FieldName(name),
334  m_BaseValue(base),
335  m_Is_set(false),
336  m_Is_real_loc(false),
337  m_Is_simple(false),
338  m_Is_probably_simple(false),
339  m_Is_simple_point(false),
340  m_Is_simple_interval(false),
341  m_Is_simple_whole(false)
342 {
343 }
344 
345 
347 {
348 }
349 
350 
352  const CSeqTable_column& column)
353 {
354  if ( field ) {
355  NCBI_THROW_FMT(CAnnotException, eBadLocation,
356  "Duplicate "<<m_FieldName<<" column");
357  }
358  field = CSeqTableColumnInfo(column);
359  m_Is_set = true;
360 }
361 
362 
364  const CSeqTableSetLocField* setter)
365 {
366  m_ExtraColumns.push_back(TColumnInfo(column, ConstRef(setter)));
367  m_Is_set = true;
368 }
369 
370 
372 {
373  const CSeqTable_column_info& type = column.GetHeader();
374  if ( type.IsSetField_id() ) {
375  int field = type.GetField_id() - m_BaseValue +
379  return false;
380  }
381  switch ( field ) {
384  return true;
387  return true;
390  return true;
393  return true;
396  return true;
399  return true;
402  return true;
405  return true;
406  default:
407  break;
408  }
409  }
410  if ( !type.IsSetField_name() ) {
411  return false;
412  }
413 
414  CTempString field(type.GetField_name());
415  if ( field == m_FieldName ) {
417  return true;
418  }
419  else if ( NStr::StartsWith(field, m_FieldName) &&
420  field[m_FieldName.size()] == '.' ) {
421  CTempString extra = field.substr(m_FieldName.size()+1);
422  if ( extra == "id" || NStr::EndsWith(extra, ".id") ) {
424  return true;
425  }
426  else if ( extra == "gi" || NStr::EndsWith(extra, ".gi") ) {
428  return true;
429  }
430  else if ( extra == "pnt.point" || extra == "int.from" ) {
432  return true;
433  }
434  else if ( extra == "int.to" ) {
436  return true;
437  }
438  else if ( extra == "strand" ||
439  NStr::EndsWith(extra, ".strand") ) {
441  return true;
442  }
443  else if ( extra == "int.fuzz-from.lim" ||
444  extra == "pnt.fuzz.lim" ) {
446  return true;
447  }
448  else if ( extra == "int.fuzz-to.lim" ) {
450  return true;
451  }
452  }
453  return false;
454 }
455 
456 
458 {
459  if ( !m_Is_set ) {
460  return;
461  }
462  if ( m_Loc ) {
463  m_Is_real_loc = true;
464  if ( m_Id || m_Gi || m_From || m_To || m_Strand ||
465  !m_ExtraColumns.empty() ) {
466  NCBI_THROW_FMT(CAnnotException, eBadLocation,
467  "Conflicting "<<m_FieldName<<" columns");
468  }
469  return;
470  }
471 
472  if ( !m_Id && !m_Gi ) {
473  NCBI_THROW_FMT(CAnnotException, eBadLocation,
474  "No "<<m_FieldName<<".id column");
475  }
476  if ( m_Id && m_Gi ) {
477  NCBI_THROW_FMT(CAnnotException, eBadLocation,
478  "Conflicting "<<m_FieldName<<" columns");
479  }
480  if ( m_Id ) {
481  if ( m_Id->IsSetDefault() ) {
484  }
485  }
486  if ( m_Gi ) {
487  if ( m_Gi->IsSetDefault() ) {
488  TIntId gi;
489  m_Gi->GetDefault().GetValue(gi);
491  }
492  }
493 
494  if ( m_To ) {
495  // interval
496  if ( !m_From ) {
497  NCBI_THROW_FMT(CAnnotException, eBadLocation,
498  "column "<<m_FieldName<<".to without "<<
499  m_FieldName<<".from");
500  }
501  m_Is_simple_interval = true;
502  }
503  else if ( m_From ) {
504  // point
505  m_Is_simple_point = true;
506  }
507  else {
508  // whole
509  if ( m_Strand || !m_ExtraColumns.empty() ) {
510  NCBI_THROW_FMT(CAnnotException, eBadLocation,
511  "extra columns in whole "<<m_FieldName);
512  }
513  m_Is_simple_whole = true;
514  }
515  if ( m_ExtraColumns.empty() ) {
516  m_Is_simple = true;
517  }
518  else {
519  m_Is_probably_simple = true;
520  }
521 }
522 
523 
525 {
526  _ASSERT(m_Loc);
528  return m_Loc.GetSeq_loc(row);
529 }
530 
531 
533 {
534  _ASSERT(!m_Loc);
535  _ASSERT(m_Id);
536  return m_Id.GetSeq_id(row);
537 }
538 
539 
541 {
542  _ASSERT(!m_Loc);
543  if ( m_Id ) {
544  _ASSERT(!m_Id->IsSetSparse());
545  if ( m_Id->IsSetData() ) {
546  const CSeq_id* id = m_Id.GetSeq_id(row);
547  if ( id ) {
548  return CSeq_id_Handle::GetHandle(*id);
549  }
550  }
551  }
552  else {
553  _ASSERT(!m_Gi->IsSetSparse());
554  if ( m_Gi->IsSetData() ) {
555  TIntId gi;
556  if ( m_Gi.GetValue(row, gi) ) {
558  }
559  }
560  }
561  return m_DefaultIdHandle;
562 }
563 
564 
566 {
567  _ASSERT(!m_Loc);
568  _ASSERT(m_From);
569  int from;
570  if ( !m_From || !m_From.GetValue(row, from) ) {
571  return 0;
572  }
573  return from;
574 }
575 
576 
578 {
579  _ASSERT(!m_Loc);
580  _ASSERT(m_From);
581  int from;
582  if ( !m_From || !m_From.GetValue(row, from) ) {
583  return CRange<TSeqPos>::GetWhole();
584  }
585  int to = from;
586  if ( m_To ) {
587  m_To.GetValue(row, to);
588  }
589  return CRange<TSeqPos>(from, to);
590 }
591 
592 
594 {
595  _ASSERT(!m_Loc);
596  int strand = eNa_strand_unknown;
597  if ( m_Strand ) {
598  m_Strand.GetValue(row, strand);
599  }
600  return ENa_strand(strand);
601 }
602 
603 
605  CRef<CSeq_loc>& seq_loc,
606  CRef<CSeq_point>& seq_pnt,
607  CRef<CSeq_interval>& seq_int) const
608 {
609  _ASSERT(m_Is_set);
610  if ( m_Loc ) {
611  seq_loc = &const_cast<CSeq_loc&>(*GetLoc(row));
612  return;
613  }
614  if ( !seq_loc ) {
615  seq_loc = new CSeq_loc();
616  }
617  CSeq_loc& loc = *seq_loc;
618 
620  TGi gi = ZERO_GI;
621  if ( m_Id ) {
622  id = GetId(row);
623  }
624  else {
625  _ASSERT(m_Gi);
626  TIntId igi = 0;
627  m_Gi.GetValue(row, igi);
628  gi = GI_FROM(TIntId, igi);
629  }
630 
631  int from = 0;
632  if ( !m_From || !m_From.GetValue(row, from) ) {
633  // whole
634  if ( id ) {
635  loc.SetWhole(const_cast<CSeq_id&>(*id));
636  }
637  else {
638  loc.SetWhole().SetGi(gi);
639  }
640  }
641  else {
642  int strand = -1;
643  if ( m_Strand ) {
644  m_Strand.GetValue(row, strand);
645  }
646 
647  int to = 0;
648  if ( !m_To || !m_To.GetValue(row, to) ) {
649  // point
650  if ( !seq_pnt ) {
651  seq_pnt = new CSeq_point();
652  }
653  CSeq_point& point = *seq_pnt;
654  if ( id ) {
655  point.SetId(const_cast<CSeq_id&>(*id));
656  }
657  else {
658  point.SetId().SetGi(gi);
659  }
660  point.SetPoint(from);
661  if ( strand >= 0 ) {
662  point.SetStrand(ENa_strand(strand));
663  }
664  else {
665  point.ResetStrand();
666  }
667  point.ResetFuzz();
668  loc.SetPnt(point);
669  }
670  else {
671  // interval
672  if ( !seq_int ) {
673  seq_int = new CSeq_interval();
674  }
675  CSeq_interval& interval = *seq_int;
676  if ( id ) {
677  interval.SetId(const_cast<CSeq_id&>(*id));
678  }
679  else {
680  interval.SetId().SetGi(gi);
681  }
682  interval.SetFrom(from);
683  interval.SetTo(to);
684  if ( strand >= 0 ) {
685  interval.SetStrand(ENa_strand(strand));
686  }
687  else {
688  interval.ResetStrand();
689  }
690  interval.ResetFuzz_from();
691  interval.ResetFuzz_to();
692  loc.SetInt(interval);
693  }
694  }
696  it->first.UpdateSeq_loc(loc, row, *it->second);
697  }
698 }
699 
700 
703  SAnnotObject_Index& index) const
704 {
705  key.m_Handle = GetIdHandle(row);
706  key.m_Range = GetRange(row);
707  ENa_strand strand = GetStrand(row);
708  index.m_Flags = 0;
709  if ( strand == eNa_strand_unknown ) {
710  index.m_Flags |= index.fStrand_both;
711  }
712  else {
713  if ( IsForward(strand) ) {
714  index.m_Flags |= index.fStrand_plus;
715  }
716  if ( IsReverse(strand) ) {
717  index.m_Flags |= index.fStrand_minus;
718  }
719  }
720  bool simple = m_Is_simple;
721  if ( !simple && m_Is_probably_simple ) {
722  simple = true;
724  if ( it->first.IsSet(row) ) {
725  simple = false;
726  break;
727  }
728  }
729  }
730  if ( simple ) {
731  if ( m_Is_simple_interval ) {
732  index.SetLocationIsInterval();
733  }
734  else if ( m_Is_simple_point ) {
735  index.SetLocationIsPoint();
736  }
737  else {
739  index.SetLocationIsWhole();
740  }
741  }
742 }
743 
744 
745 /////////////////////////////////////////////////////////////////////////////
746 // CSeqTableInfo
747 /////////////////////////////////////////////////////////////////////////////
748 
749 
751 {
752  if ( !table.IsSetFeat_type() ||
753  table.GetFeat_type() <= CSeqFeatData::e_not_set ||
754  table.GetFeat_type() >= CSeqFeatData::e_MaxChoice ) {
755  return false; // not a feature table
756  }
757  if ( table.IsSetFeat_subtype() &&
758  (table.GetFeat_subtype() <= CSeqFeatData::eSubtype_bad ||
759  table.GetFeat_subtype() >= CSeqFeatData::eSubtype_max) ) {
760  return false; // bad subtype
761  }
762  return true;
763 }
764 
765 
766 CSeqTableInfo::CSeqTableInfo(const CSeq_table& feat_table, bool is_feat)
767  : m_IsFeatTable(is_feat),
768  m_Location("loc", CSeqTable_column_info::eField_id_location),
769  m_Product("product", CSeqTable_column_info::eField_id_product)
770 {
771  x_Initialize(feat_table);
772 }
773 
774 
776  : m_IsFeatTable(IsGoodFeatTable(feat_table)),
777  m_Location("loc", CSeqTable_column_info::eField_id_location),
778  m_Product("product", CSeqTable_column_info::eField_id_product)
779 {
780  x_Initialize(feat_table);
781 }
782 
783 
785 {
786  m_Seq_table = &feat_table;
787  m_IsSorted = false;
788  m_SortedMaxLength = 0;
789  ITERATE ( CSeq_table::TColumns, it, feat_table.GetColumns() ) {
790  const CSeqTable_column& col = **it;
791  const CSeqTable_column_info& type = col.GetHeader();
792  if ( type.IsSetField_id() ) {
793  int id = type.GetField_id();
795  if ( IsFeatTable() && !type.IsSetField_name() ) {
796  string name = type.GetNameForId(id);
797  if ( !name.empty() ) {
799  }
800  }
801  }
802  if ( type.IsSetField_name() ) {
803  string name = type.GetField_name();
805  if ( IsFeatTable() && !type.IsSetField_id() ) {
806  int id = type.GetIdForName(name);
807  if ( id >= 0 ) {
809  }
810  }
811  if ( name == "Seq-table location" ) {
812  if ( m_TableLocation ) {
813  ERR_POST("Duplicate 'Seq-table location' column");
814  }
815  try {
817  m_TableLocation = info.GetSeq_loc(0);
818  }
819  NCBI_CATCH("Bad 'Seq-table location' column");
820  }
821  }
822  if ( !IsFeatTable() ) {
823  continue;
824  }
825 
826  if ( m_Location.AddColumn(col) || m_Product.AddColumn(col) ) {
827  continue;
828  }
830  if ( type.IsSetField_id() ) {
831  int id = type.GetField_id();
832  switch ( id ) {
834  if ( m_Partial ) {
835  NCBI_THROW_FMT(CAnnotException, eOtherError,
836  "Duplicate partial column");
837  }
839  continue;
841  setter = new CSeqTableSetComment();
842  break;
844  setter = new CSeqTableSetDataImpKey();
845  break;
847  setter = new CSeqTableSetDataRegion();
848  break;
850  setter = new CSeqTableSetExtType();
851  break;
853  setter = new CSeqTableSetExt(type.GetField_name());
854  break;
856  setter = new CSeqTableSetDbxref(type.GetField_name());
857  break;
859  setter = new CSeqTableSetQual(type.GetField_name());
860  break;
861  default:
862  if ( !type.IsSetField_name() ) {
863  ERR_POST_X(8, "SeqTable-column-info.field-id = "<<id);
864  continue;
865  }
866  break;
867  }
868  }
869  else if ( !type.IsSetField_name() ) {
870  ERR_POST_X(9, "SeqTable-column-info: "
871  "neither field-id nor field-name is set");
872  continue;
873  }
874  if ( !setter && type.IsSetField_name() ) {
875  CTempString name(type.GetField_name());
876  if ( name.empty() ) {
877  ERR_POST_X(10, "SeqTable-column-info.field-name is empty");
878  continue;
879  }
880  else if ( name[0] == 'E' ) {
881  setter = new CSeqTableSetExt(name);
882  }
883  else if ( name[0] == 'D' ) {
884  setter = new CSeqTableSetDbxref(name);
885  }
886  else if ( name[0] == 'Q' ) {
887  setter = new CSeqTableSetQual(name);
888  }
889  else if ( name == "partial" ) {
890  if ( m_Partial ) {
891  NCBI_THROW_FMT(CAnnotException, eOtherError,
892  "Duplicate partial column");
893  }
895  continue;
896  }
897  else if ( name == "disabled" ) {
898  if ( m_Disabled ) {
899  NCBI_THROW_FMT(CAnnotException, eOtherError,
900  "Duplicate disabled column ");
901  }
903  continue;
904  }
905  else if ( name == "Seq-table location" ) {
906  // already processed above
907  continue;
908  }
909  else if ( name == "Sorted, max length" ) {
910  if ( m_SortedMaxLength ) {
911  ERR_POST("Duplicate 'Sorted, max length' column");
912  }
913  try {
915  int value;
916  if ( info.GetValue(0, value) ) {
918  }
919  }
920  NCBI_CATCH("Bad 'Sorted, max length' column");
921  continue;
922  }
923  if ( !setter ) {
924  try {
925  setter = new CSeqTableSetAnyFeatField(name);
926  }
927  catch ( CAnnotException& /*exc*/ ) {
928  // ignore invalid column names
929  }
930  }
931  }
932  if ( setter ) {
933  m_ExtraColumns.push_back(TColumnInfo(col, setter));
934  }
935  }
936 
937  if ( IsFeatTable() ) {
940  }
941 
943  if ( !m_IsSorted ) {
944  m_SortedMaxLength = 0;
945  }
946 }
947 
948 
950 {
951 }
952 
953 
955 {
956  _ASSERT(IsFeatTable());
957  const CSeq_table& table = *m_Seq_table;
959  if ( table.IsSetFeat_subtype() ) {
960  type.SetFeatSubtype(CSeqFeatData::ESubtype(table.GetFeat_subtype()));
961  }
962  return type;
963 }
964 
965 
967 {
968  return m_TableLocation;
969 }
970 
971 
973 {
974  return m_SortedMaxLength;
975 }
976 
977 
979 {
980  // 1. no product
981  // 2. location has singular Seq-id
982  // 3. location is either simple interval or simple point
983  // 4. has whole table location that is Seq-interval
984  // 5. sorted max length information is present, and has suitable value
985  if ( m_Product.IsSet() ) {
986  return false;
987  }
988  if ( !m_Location.IsSet() || m_Location.IsRealLoc() || !m_Location.m_Id ) {
989  return false;
990  }
991  if ( !m_Location.m_Id.IsSingular() ) {
992  return false;
993  }
994  if ( !m_Location.m_Is_simple ||
996  return false;
997  }
998  if ( !m_TableLocation || !m_TableLocation->IsInt() ) {
999  return false;
1000  }
1001  if ( !m_SortedMaxLength ||
1003  return false;
1004  }
1005  return true;
1006 }
1007 
1008 
1010  CRef<CSeq_feat>& seq_feat,
1011  CRef<CSeq_point>& seq_pnt,
1012  CRef<CSeq_interval>& seq_int) const
1013 {
1014  if ( !seq_feat ) {
1015  seq_feat = new CSeq_feat;
1016  }
1017  else {
1018  seq_feat->Reset();
1019  }
1020  CSeq_feat& feat = *seq_feat;
1021  if ( m_Location.IsSet() ) {
1022  CRef<CSeq_loc> seq_loc;
1023  if ( feat.IsSetLocation() ) {
1024  seq_loc = &feat.SetLocation();
1025  }
1026  m_Location.UpdateSeq_loc(row, seq_loc, seq_pnt, seq_int);
1027  feat.SetLocation(*seq_loc);
1028  }
1029  if ( m_Product.IsSet() ) {
1030  CRef<CSeq_loc> s_loc;
1031  CRef<CSeq_point> s_pnt;
1032  CRef<CSeq_interval> s_int;
1033  if ( feat.IsSetProduct() ) {
1034  s_loc = &feat.SetProduct();
1035  }
1036  m_Product.UpdateSeq_loc(row, s_loc, s_pnt, s_int);
1037  feat.SetProduct(*s_loc);
1038  }
1039  if ( m_Partial ) {
1040  bool val = false;
1041  if ( m_Partial.GetValue(row, val) ) {
1042  feat.SetPartial(val);
1043  }
1044  }
1046  it->first.UpdateSeq_feat(feat, row, *it->second);
1047  }
1048 }
1049 
1050 
1051 bool CSeqTableInfo::HasLabel(size_t /*index*/) const
1052 {
1053  for ( auto& c : m_ExtraColumns ) {
1054  const CSeqTable_column& col = *c.first.Get();
1055  const CSeqTable_column_info& col_info = col.GetHeader();
1056  if ( col_info.IsSetField_name() ) {
1057  const string& name = col_info.GetField_name();
1058  if ( !name.empty() && name[0] == 'Q' ) {
1059  return true;
1060  }
1061  }
1062  }
1063  return false;
1064 }
1065 
1066 
1067 string CSeqTableInfo::GetLabel(size_t index) const
1068 {
1070  char sep = '/';
1071  for ( auto& c : m_ExtraColumns ) {
1072  const CSeqTable_column& col = *c.first.Get();
1073  const CSeqTable_column_info& col_info = col.GetHeader();
1074  if ( col_info.IsSetField_name() ) {
1075  const string& name = col_info.GetField_name();
1076  if ( !name.empty() && name[0] == 'Q' ) {
1077  str << sep;
1078  sep = ' ';
1079  str << name.substr(2);
1080  const string* value_ptr = c.first.GetStringPtr(index);
1081  if ( value_ptr && !value_ptr->empty() ) {
1082  str << '=' << *value_ptr;
1083  }
1084  }
1085  }
1086  }
1087  return CNcbiOstrstreamToString(str);
1088 }
1089 
1090 
1092  size_t index) const
1093 {
1094  for ( auto& c : m_ExtraColumns ) {
1095  const CSeqTable_column& col = *c.first.Get();
1096  const CSeqTable_column_info& col_info = col.GetHeader();
1097  if ( col_info.IsSetField_name() ) {
1098  const string& name = col_info.GetField_name();
1099  if ( name == "E.QualityCodes" ) {
1100  const vector<char>* bytes = c.first.GetBytesPtr(index);
1101  if ( !bytes || bytes->size() != 8 ) {
1102  continue;
1103  }
1104  Uint8 bits = *reinterpret_cast<const Uint8*>(bytes->data());
1105  return (bits & sel.GetFilterMask()) == sel.GetFilterBits();
1106  }
1107  }
1108  }
1109  // assume match if no quality bit info is set
1110  return true;
1111 }
1112 
1113 
1114 const CSeqTableColumnInfo*
1115 CSeqTableInfo::FindColumn(int field_id) const
1116 {
1118  if ( iter == m_ColumnsById.end() ) {
1119  return 0;
1120  }
1121  return &iter->second;
1122 }
1123 
1124 
1125 const CSeqTableColumnInfo*
1126 CSeqTableInfo::FindColumn(const string& field_name) const
1127 {
1129  if ( iter == m_ColumnsByName.end() ) {
1130  return 0;
1131  }
1132  return &iter->second;
1133 }
1134 
1135 
1136 const CSeqTableColumnInfo&
1137 CSeqTableInfo::GetColumn(int field_id) const
1138 {
1139  const CSeqTableColumnInfo* column = FindColumn(field_id);
1140  if ( !column ) {
1141  NCBI_THROW_FMT(CAnnotException, eOtherError,
1142  "CSeqTableInfo::GetColumn: "
1143  "column "<<field_id<<" not found");
1144  }
1145  return *column;
1146 }
1147 
1148 
1149 const CSeqTableColumnInfo&
1150 CSeqTableInfo::GetColumn(const string& field_name) const
1151 {
1152  const CSeqTableColumnInfo* column = FindColumn(field_name);
1153  if ( !column ) {
1154  NCBI_THROW_FMT(CAnnotException, eOtherError,
1155  "CSeqTableInfo::GetColumn: "
1156  "column "<<field_name<<" not found");
1157  }
1158  return *column;
1159 }
1160 
1161 
bool IsForward(ENa_strand s)
Definition: Na_strand.hpp:68
bool IsReverse(ENa_strand s)
Definition: Na_strand.hpp:75
#define false
Definition: bool.h:36
#define bool
Definition: bool.h:34
Annotation iterators exceptions.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
void UpdateSeq_loc(CSeq_loc &loc, size_t row, const CSeqTableSetLocField &setter) const
void UpdateSeq_feat(CSeq_feat &feat, size_t row, const CSeqTableSetFeatField &setter) const
bool GetValue(size_t row, Value &v, bool force=false) const
CConstRef< CSeq_loc > GetSeq_loc(size_t row, bool force=false) const
const vector< char > * GetBytesPtr(size_t row, bool force=false) const
bool x_ThrowUnsetValue(void) const
const string * GetStringPtr(size_t row, bool force=false) const
CConstRef< CSeq_id > GetSeq_id(size_t row, bool force=false) const
CConstRef< CSeqTable_column > m_Column
bool IsSingular(void) const
CSeqTableInfo(const CSeq_table &feat_table, bool is_feat)
static bool IsGoodFeatTable(const CSeq_table &table)
string GetLabel(size_t row) const
bool HasLabel(size_t row) const
bool IsFeatTable(void) const
TColumnsById m_ColumnsById
bool MatchBitFilter(const SAnnotSelector &sel, size_t row) const
CSeqTableLocColumns m_Location
bool x_IsSorted(void) const
TColumnsByName m_ColumnsByName
void UpdateSeq_feat(size_t row, CRef< CSeq_feat > &seq_feat, CRef< CSeq_point > &seq_pnt, CRef< CSeq_interval > &seq_int) const
CSeqTableColumnInfo m_Partial
SAnnotTypeSelector GetType(void) const
CConstRef< CSeq_table > m_Seq_table
vector< TColumnInfo > TExtraColumns
const CSeqTableColumnInfo * FindColumn(int field_id) const
CSeqTableLocColumns m_Product
CConstRef< CSeq_loc > m_TableLocation
TSeqPos m_SortedMaxLength
CSeqTableColumnInfo m_Disabled
TSeqPos GetSortedMaxLength(void) const
TExtraColumns m_ExtraColumns
CConstRef< CSeq_loc > GetTableLocation(void) const
void x_Initialize(const CSeq_table &table)
const CSeqTableColumnInfo & GetColumn(int field_id) const
pair< CSeqTableColumnInfo, CConstRef< TSetter > > TColumnInfo
void AddExtraColumn(const CSeqTable_column &column, const CSeqTableSetLocField *setter)
CSeqTableColumnInfo m_Loc
ENa_strand GetStrand(size_t row) const
CSeqTableColumnInfo m_To
CSeqTableColumnInfo m_Id
CSeqTable_column_info::EField_id m_BaseValue
TSeqPos GetFrom(size_t row) const
bool IsSet(void) const
CSeq_id_Handle m_DefaultIdHandle
CConstRef< CSeq_id > GetId(size_t row) const
void SetTableKeyAndIndex(size_t row, SAnnotObject_Key &key, SAnnotObject_Index &index) const
CSeq_id_Handle GetIdHandle(size_t row) const
vector< TColumnInfo > TExtraColumns
bool IsRealLoc(void) const
void UpdateSeq_loc(size_t row, CRef< CSeq_loc > &seq_loc, CRef< CSeq_point > &seq_pnt, CRef< CSeq_interval > &seq_int) const
CSeqTableColumnInfo m_From
pair< CSeqTableColumnInfo, CConstRef< TSetter > > TColumnInfo
TExtraColumns m_ExtraColumns
CSeqTableLocColumns(const char *field_name, CSeqTable_column_info::EField_id base_value)
CConstRef< CSeq_loc > GetLoc(size_t row) const
void SetColumn(CSeqTableColumnInfo &field, const CSeqTable_column &column)
bool AddColumn(const CSeqTable_column &column)
CRange< TSeqPos > GetRange(size_t row) const
CSeqTableColumnInfo m_Strand
CSeqTableColumnInfo m_Gi
virtual void SetString(CSeq_feat &feat, const string &value) const
virtual void SetInt8(CSeq_feat &feat, Int8 value) const
virtual void SetBytes(CSeq_feat &feat, const vector< char > &value) const
virtual void SetReal(CSeq_feat &feat, double value) const
virtual void SetInt(CSeq_feat &feat, int value) const
virtual void SetInt8(CSeq_loc &loc, Int8 value) const
virtual void SetInt(CSeq_loc &loc, int value) const
virtual void SetReal(CSeq_loc &loc, double value) const
virtual void SetString(CSeq_loc &loc, const string &value) const
const vector< char > * GetBytesPtr(size_t row) const
const string * GetStringPtr(size_t row) const
CConstRef< CSeq_id > GetSeq_id(size_t row) const
CConstRef< CSeq_loc > GetSeq_loc(size_t row) const
bool IsSet(size_t row) const
const string * GetStringPtr(size_t row) const
E_Choice GetValueType(void) const
const TBytesValue * GetBytesPtr(size_t row) const
bool TryGetValue(size_t row, Int1 &v) const
void GetValue(bool &v) const
E_Choice GetValueType(void) const
static const size_t kSkipped
size_t GetIndexAt(size_t row) const
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
TSeqPos GetLength(void) const
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
const_iterator find(const key_type &key) const
Definition: map.hpp:153
char value[7]
Definition: config.c:431
static int type
Definition: getdata.c:31
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
Int8 TIntId
Definition: ncbimisc.hpp:999
#define ZERO_GI
Definition: ncbimisc.hpp:1088
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#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 NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
static CSeq_id_Handle GetGiHandle(TGi gi)
Faster way to create a handle for a gi.
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
void SetPnt(TPnt &v)
Definition: Seq_loc.hpp:985
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
TBitFilter GetFilterMask(void) const
TBitFilter GetFilterBits(void) const
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
static TThisType GetWhole(void)
Definition: range.hpp:272
#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 bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5429
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5411
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
Definition: tempstr.hpp:776
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
const TDefault & GetDefault(void) const
Get the Default member data.
const TColumns & GetColumns(void) const
Get the Columns member data.
Definition: Seq_table_.hpp:433
E_Choice Which(void) const
Which variant is currently selected.
EField_id
identification of the column data in the objects described by the table known column data types posit...
const TSparse_other & GetSparse_other(void) const
Get the Sparse_other member data.
const TSparse & GetSparse(void) const
Get the Sparse member data.
const TId & GetId(void) const
Get the variant data.
const TString & GetString(void) const
Get the variant data.
bool IsSetField_name(void) const
any column can be identified by ASN.1 text locator string with omitted object type.
bool IsSetSparse_other(void) const
single value for indexes not listed in sparse table Check if a value has been assigned to Sparse_othe...
vector< CRef< CSeqTable_column > > TColumns
Definition: Seq_table_.hpp:92
const THeader & GetHeader(void) const
Get the Header member data.
const TField_name & GetField_name(void) const
Get the Field_name member data.
TInt8 GetInt8(void) const
Get the variant data.
TBit GetBit(void) const
Get the variant data.
bool IsSetData(void) const
row data Check if a value has been assigned to Data data member.
bool IsSetSparse(void) const
in case not all rows contain data this field will contain sparse info Check if a value has been assig...
const TBytes & GetBytes(void) const
Get the variant data.
TReal GetReal(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
E_Choice Which(void) const
Which variant is currently selected.
bool IsSetDefault(void) const
default value for sparse table, or if row data is too short Check if a value has been assigned to Def...
TInt GetInt(void) const
Get the variant data.
@ eField_id_location
location as Seq-loc
@ eField_id_qual
field-name must be "Q.xxx", see below
@ eField_id_ext
field-name must be "E.xxx", see below
@ eField_id_location_strand
location strand
@ eField_id_ext_type
extra fields, see also special values for str below
@ eField_id_dbxref
field-name must be "D.xxx", see below
@ eField_id_product
product as Seq-loc
@ eField_id_data_imp_key
various data fields
@ e_Int8
a set of signed 8-byte integers
@ e_Real
a set of reals, one per row
@ e_Common_bytes
a set of byte arrays with small set of possible values
@ e_Bytes
a set of byte arrays, one per row
@ e_String
a set of strings, one per row
@ e_Int
a set of 4-byte integers, one per row
@ e_Common_string
a set of string with small set of possible values
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
void SetPartial(TPartial value)
Assign a value to Partial data member.
Definition: Seq_feat_.hpp:971
void SetProduct(TProduct &value)
Assign a value to Product data member.
Definition: Seq_feat_.cpp:110
E_Choice
Choice variants.
virtual void Reset(void)
Reset the whole object.
Definition: Seq_feat_.cpp:229
bool IsSetProduct(void) const
product of process Check if a value has been assigned to Product data member.
Definition: Seq_feat_.hpp:1084
bool IsSetLocation(void) const
feature made from Check if a value has been assigned to Location data member.
Definition: Seq_feat_.hpp:1105
@ e_not_set
No variant selected.
@ e_MaxChoice
== e_Variation+1
void SetTo(TTo value)
Assign a value to To data member.
void SetPoint(TPoint value)
Assign a value to Point data member.
Definition: Seq_point_.hpp:312
void SetId(TId &value)
Assign a value to Id data member.
Definition: Seq_point_.cpp:61
void ResetFuzz_to(void)
Reset Fuzz_to data member.
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
void SetId(TId &value)
Assign a value to Id data member.
void SetStrand(TStrand value)
Assign a value to Strand data member.
Definition: Seq_point_.hpp:359
void ResetFuzz(void)
Reset Fuzz data member.
Definition: Seq_point_.cpp:66
void SetFrom(TFrom value)
Assign a value to From data member.
void ResetStrand(void)
Reset Strand data member.
Definition: Seq_point_.hpp:343
void ResetFuzz_from(void)
Reset Fuzz_from data member.
bool IsInt(void) const
Check if variant Int is selected.
Definition: Seq_loc_.hpp:528
const TInt & GetInt(void) const
Get the variant data.
Definition: Seq_loc_.cpp:194
void SetStrand(TStrand value)
Assign a value to Strand data member.
void ResetStrand(void)
Reset Strand data member.
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
Definition of all error codes used in objmgr libraries (xobjmgr.lib, xobjutil.lib and others).
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::KEY key
NCBI_DEFINE_ERR_SUBCODE_X(12)
static const char * str(char *buf, int n)
Definition: stats.c:84
static const char * column
Definition: stats.c:23
SAnnotSelector –.
Definition: type.c:6
#define _ASSERT
Modified on Wed Oct 04 02:25:07 2023 by modify_doxy.py rev. 669887