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

Go to the SVN repository for this file.

1 /* $Id: annot_type_index.cpp 99883 2023-05-18 17:55:27Z vasilche $
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: Aleksey Grichenko
27 *
28 * File Description:
29 * Annotation type indexes
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbimtx.hpp>
41 #include <objmgr/impl/tse_info.hpp>
42 
45 
46 
47 // All ranges are in format [x, y)
48 
49 DEFINE_STATIC_FAST_MUTEX(sm_TablesInitializeMutex);
50 atomic<bool> CAnnotType_Index::sm_TablesInitialized{false};
51 
56 
58 {
59  CFastMutexGuard guard(sm_TablesInitializeMutex);
60  if ( sm_TablesInitialized.load(memory_order_acquire) ) {
61  return;
62  }
63  // Check flag, lock tables
73 
77  vector< vector<Uint1> > type_subtypes(kFeatType_size);
78  for ( Uint1 subtype = 0; subtype < kFeatSubtype_size; ++subtype ) {
79  Uint1 type =
81  if ( type != CSeqFeatData::e_not_set ||
82  subtype == CSeqFeatData::eSubtype_bad ) {
83  type_subtypes[type].push_back(subtype);
84  }
85  }
86 
87  Uint1 cur_idx = kAnnotIndex_Ftable;
88  fill_n(sm_IndexSubtype, cur_idx,
90  for ( Uint1 type = 0; type < kFeatType_size; ++type ) {
91  sm_FeatTypeIndexRange[type][0] = cur_idx;
92  ITERATE ( vector<Uint1>, it, type_subtypes[type] ) {
93  _ASSERT(cur_idx < kAnnotIndex_size);
94  sm_FeatSubtypeIndex[*it] = cur_idx;
95  sm_IndexSubtype[cur_idx] = *it;
96  ++cur_idx;
97  }
98  sm_FeatTypeIndexRange[type][1] = cur_idx;
99  }
100 
104  _ASSERT(cur_idx <= kAnnotIndex_size);
107 
108  sm_TablesInitialized.store(true, memory_order_release);
109 
110 #if defined(_DEBUG)
111  _TRACE("Index size: "<<cur_idx<<" of "<<kAnnotIndex_size);
115  //_ASSERT(GetAnnotTypeRange(CSeq_annot::C_Data::e_MaxChoice) == TIndexRange(0, 0));
117  //_ASSERT(GetFeatTypeRange(CSeqFeatData::e_MaxChoice) == TIndexRange(0, 0));
121  for ( size_t type = 0; type < kFeatType_size; ++type ) {
123  TIndexRange range = GetFeatTypeRange(feat_type);
124  _TRACE("type: "<<feat_type
125  << " range: "<<range.first<<"-"<<range.second);
126  if ( type == 0 ) {
127  continue;
128  }
129  for ( size_t ind = range.first; ind < range.second; ++ind ) {
131  _TRACE("index: "<<ind
132  << " type: "<<sel.GetFeatType()
133  << " subtype: "<<sel.GetFeatSubtype());
135  _ASSERT(sel.GetFeatType() == feat_type);
136  _ASSERT(GetSubtypeIndex(sel.GetFeatSubtype()) == ind);
137  }
138  }
139  for ( size_t st = 0; st <= CSeqFeatData::eSubtype_max; ++st ) {
143  if ( type != CSeqFeatData::e_not_set ||
144  subtype == CSeqFeatData::eSubtype_bad ) {
145  size_t ind = GetSubtypeIndex(subtype);
146  _ASSERT(GetSubtypeForIndex(ind) == subtype);
147  }
148  }
149 #endif
150 }
151 
152 
155 {
156  Initialize();
157  if ( info.GetFeatSubtype() != CSeqFeatData::eSubtype_any ) {
158  size_t index = GetSubtypeIndex(info.GetFeatSubtype());
159  if ( index ) {
160  return TIndexRange(index, index+1);
161  }
162  }
163  else if ( info.GetFeatType() != CSeqFeatData::e_not_set ) {
164  return GetFeatTypeRange(info.GetFeatType());
165  }
166  return GetAnnotTypeRange(info.GetAnnotType());
167 }
168 
169 
172 {
173  Initialize();
174  TIndexRange r;
176  r.first = GetSubtypeIndex(sel.GetFeatSubtype());
177  r.second = r.first? r.first + 1: 0;
178  }
179  else if ( sel.GetFeatType() != CSeqFeatData::e_not_set ) {
180  r = GetFeatTypeRange(sel.GetFeatType());
181  }
182  else {
184  }
185  return r;
186 }
187 
188 
191  const SIdAnnotObjs& objs)
192 {
194  range = GetIndexRange(sel);
195  range.second = min(range.second, objs.m_AnnotSet.size());
196  return range;
197 }
198 
199 
201 {
202  SAnnotTypeSelector sel;
203  switch (index) {
204  case kAnnotIndex_Align:
206  break;
207  case kAnnotIndex_Graph:
209  break;
212  break;
213  default:
215  break;
216  }
217  return sel;
218 }
219 
220 
DEFINE_STATIC_FAST_MUTEX(sm_TablesInitializeMutex)
static void x_InitIndexTables(void)
static CSeqFeatData::ESubtype GetSubtypeForIndex(size_t index)
pair< size_t, size_t > TIndexRange
static TIndexRange GetFeatTypeRange(CSeqFeatData::E_Choice type)
static TIndexRange GetTypeIndex(const CAnnotObject_Info &info)
static size_t GetSubtypeIndex(CSeqFeatData::ESubtype subtype)
static Uint1 sm_FeatSubtypeIndex[kFeatSubtype_size]
static SAnnotTypeSelector GetTypeSelector(size_t index)
static Uint1 sm_FeatTypeIndexRange[kFeatType_size][2]
static void Initialize(void)
static Uint1 sm_AnnotTypeIndexRange[kAnnotType_size][2]
static Uint1 sm_IndexSubtype[kAnnotIndex_size]
static TIndexRange GetIndexRange(const SAnnotTypeSelector &sel)
static TIndexRange GetAnnotTypeRange(CSeq_annot::C_Data::E_Choice type)
static atomic< bool > sm_TablesInitialized
static E_Choice GetTypeFromSubtype(ESubtype subtype)
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
static int type
Definition: getdata.c:31
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define _TRACE(message)
Definition: ncbidbg.hpp:122
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
#define kMax_UI1
Definition: ncbi_limits.h:213
#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
E_Choice
Choice variants.
@ e_not_set
No variant selected.
@ e_Ids
used for communication between tools
Definition: Seq_annot_.hpp:136
@ e_not_set
No variant selected.
Definition: Seq_annot_.hpp:132
@ e_Locs
used for communication between tools
Definition: Seq_annot_.hpp:137
static MDB_envinfo info
Definition: mdb_load.c:37
range(_Ty, _Ty) -> range< _Ty >
Multi-threading – mutexes; rw-locks; semaphore.
T min(T x_, T y_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
TFeatSubtype GetFeatSubtype(void) const
TAnnotType GetAnnotType(void) const
TFeatType GetFeatType(void) const
void SetAnnotType(TAnnotType type)
void SetFeatSubtype(TFeatSubtype subtype)
TAnnotSet m_AnnotSet
Definition: tse_info.hpp:127
Definition: type.c:6
#define _ASSERT
Modified on Thu Sep 21 03:43:51 2023 by modify_doxy.py rev. 669887