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

Go to the SVN repository for this file.

1 /* $Id: snploader.cpp 100509 2023-08-08 16:07:21Z 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: Eugene Vasilchenko
27  *
28  * File Description: SNP file data loader
29  *
30  * ===========================================================================
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 
38 #include <objects/seq/seq__.hpp>
40 
47 
50 
52 
53 NCBI_PARAM_ENUM_ARRAY(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT) {
54  {"", objects::CSeq_id::eSNPScaleLimit_Default},
55  {"Unit", objects::CSeq_id::eSNPScaleLimit_Unit},
56  {"Contig", objects::CSeq_id::eSNPScaleLimit_Contig},
57  {"Supercontig", objects::CSeq_id::eSNPScaleLimit_Supercontig},
58  {"Chromosome", objects::CSeq_id::eSNPScaleLimit_Chromosome},
59 };
60 NCBI_PARAM_ENUM_DECL(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT);
61 NCBI_PARAM_ENUM_DEF_EX(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT,
62  objects::CSeq_id::eSNPScaleLimit_Default,
63  0, SNP_LOADER_SCALE_LIMIT);
64 typedef NCBI_PARAM_TYPE(SNP_LOADER, SCALE_LIMIT) TScale_Limit;
65 
67 
68 class CDataLoader;
69 
71 
73 public:
74  bool IsDataLoaderMatches(CDataLoader& loader) const {
75  return dynamic_cast<CSNPDataLoader*>(&loader) != 0;
76  }
77 };
78 
79 
80 class CRevoker {
81 public:
83  CLoaderFilter filter;
85  }
86 };
90 
92 
93 
94 /////////////////////////////////////////////////////////////////////////////
95 // CSNPDataLoader params
96 /////////////////////////////////////////////////////////////////////////////
97 
98 
99 NCBI_PARAM_DECL(string, SNP, ACCESSIONS);
100 NCBI_PARAM_DEF_EX(string, SNP, ACCESSIONS, "",
101  eParam_NoThread, SNP_ACCESSIONS);
102 
103 
104 NCBI_PARAM_DECL(bool, SNP_LOADER, PTIS);
105 NCBI_PARAM_DEF_EX(bool, SNP_LOADER, PTIS, true,
106  eParam_NoThread, SNP_LOADER_PTIS);
107 
108 
110  : m_AddPTIS(NCBI_PARAM_TYPE(SNP_LOADER, PTIS)::GetDefault())
111 {
112 }
113 
115 {
117  str << "CSNPDataLoader:" << m_DirPath;
118  if ( !m_VDBFiles.empty() ) {
119  str << "/files=";
120  for ( auto& file : m_VDBFiles ) {
121  str << "+" << file;
122  }
123  }
124  if ( !m_AnnotName.empty() ) {
125  str << "/name=" << m_AnnotName;
126  }
128 }
129 
130 
132 {
134  NStr::Split(NCBI_PARAM_TYPE(SNP, ACCESSIONS)::GetDefault(), ",",
135  params.m_VDBFiles);
136  return params;
137 }
138 
139 
140 /////////////////////////////////////////////////////////////////////////////
141 // CSNPDataLoader
142 /////////////////////////////////////////////////////////////////////////////
143 
146  const SLoaderParams& params,
147  CObjectManager::EIsDefault is_default,
148  CObjectManager::TPriority priority)
149 {
150  TMaker maker(params);
151  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
152  return maker.GetRegisterInfo();
153 }
154 
155 
158  CObjectManager::EIsDefault is_default,
159  CObjectManager::TPriority priority)
160 {
162  TMaker maker(params);
163  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
164  return maker.GetRegisterInfo();
165 }
166 
167 
170  const string& path,
171  CObjectManager::EIsDefault is_default,
172  CObjectManager::TPriority priority)
173 {
174  SLoaderParams params;
175  params.m_DirPath = path;
176  TMaker maker(params);
177  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
178  return maker.GetRegisterInfo();
179 }
180 
181 
184  const vector<string>& files,
185  CObjectManager::EIsDefault is_default,
186  CObjectManager::TPriority priority)
187 {
188  SLoaderParams params;
189  params.m_VDBFiles = files;
190  TMaker maker(params);
191  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
192  return maker.GetRegisterInfo();
193 }
194 
195 
198  const string& dir_path,
199  const string& file,
200  CObjectManager::EIsDefault is_default,
201  CObjectManager::TPriority priority)
202 {
203  SLoaderParams params;
204  params.m_DirPath = dir_path;
205  params.m_VDBFiles.push_back(file);
206  TMaker maker(params);
207  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
208  return maker.GetRegisterInfo();
209 }
210 
211 
214  const string& dir_path,
215  const vector<string>& files,
216  CObjectManager::EIsDefault is_default,
217  CObjectManager::TPriority priority)
218 {
219  SLoaderParams params;
220  params.m_DirPath = dir_path;
221  params.m_VDBFiles = files;
222  TMaker maker(params);
223  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
224  return maker.GetRegisterInfo();
225 }
226 
227 
229 {
231 }
232 
233 
235 {
236  return params.GetLoaderName();
237 }
238 
239 
240 string CSNPDataLoader::GetLoaderNameFromArgs(const string& path)
241 {
242  SLoaderParams params;
243  params.m_DirPath = path;
244  return GetLoaderNameFromArgs(params);
245 }
246 
247 
248 string CSNPDataLoader::GetLoaderNameFromArgs(const vector<string>& files)
249 {
250  SLoaderParams params;
251  params.m_VDBFiles = files;
252  return GetLoaderNameFromArgs(params);
253 }
254 
255 
256 string CSNPDataLoader::GetLoaderNameFromArgs(const string& dir_path,
257  const string& file)
258 {
259  SLoaderParams params;
260  params.m_DirPath = dir_path;
261  params.m_VDBFiles.push_back(file);
262  return GetLoaderNameFromArgs(params);
263 }
264 
265 
266 string CSNPDataLoader::GetLoaderNameFromArgs(const string& dir_path,
267  const vector<string>& files)
268 {
269  SLoaderParams params;
270  params.m_DirPath = dir_path;
271  params.m_VDBFiles = files;
272  return GetLoaderNameFromArgs(params);
273 }
274 
275 
276 CSNPDataLoader::CSNPDataLoader(const string& loader_name,
277  const SLoaderParams& params)
278  : CDataLoader(loader_name)
279 {
280  string dir_path = params.m_DirPath;
281 /*
282  if ( dir_path.empty() ) {
283  dir_path = NCBI_PARAM_TYPE(SNP, DIR_PATH)::GetDefault();
284  }
285 */
286  m_Impl.Reset(new CSNPDataLoader_Impl(params));
287 }
288 
289 
291 {
292 }
293 
294 
297 {
298  return TBlobId(new CSNPBlobId(str));
299 }
300 
301 
303 {
304  return true;
305 }
306 
307 
310  EChoice choice)
311 {
312  return m_Impl->GetRecords(GetDataSource(), idh, choice);
313 }
314 
315 
318  const SAnnotSelector* sel,
319  TProcessedNAs* processed_nas)
320 {
321  return m_Impl->GetOrphanAnnotRecords(GetDataSource(), idh, sel, processed_nas);
322 }
323 
324 
326 {
327  TBlobId blob_id = chunk->GetBlobId();
328  const CSNPBlobId& id = dynamic_cast<const CSNPBlobId&>(*blob_id);
329  m_Impl->GetChunk(id, *chunk);
330 }
331 
332 
334 {
335  ITERATE ( TChunkSet, it, chunks ) {
336  GetChunk(*it);
337  }
338 }
339 
340 
343 {
344  return m_Impl->GetBlobById(GetDataSource(),
345  dynamic_cast<const CSNPBlobId&>(*blob_id));
346 }
347 
348 
350 {
351  return m_Impl->GetDefaultPriority();
352 }
353 
354 
356 {
357  return m_Impl->GetPossibleAnnotNames();
358 }
359 
360 
362 {
363  return CSnpPtisClient::IsEnabled();
364 }
365 
366 
368 {
369  return TScale_Limit::GetDefault();
370 }
371 
372 
374 {
375  TScale_Limit::SetDefault(value);
376 }
377 
378 
380 
381 // ===========================================================================
382 
384 
386 {
387  RegisterEntryPoint<CDataLoader>(NCBI_EntryPoint_xloader_snp);
388 }
389 
390 
391 const char kDataLoader_SNP_DriverName[] = "snp";
392 
394 {
395 public:
398  virtual ~CSNP_DataLoaderCF(void) {}
399 
400 protected:
403  const TPluginManagerParamTree* params) const;
404 };
405 
406 
409  const TPluginManagerParamTree* params) const
410 {
411  if ( !ValidParams(params) ) {
412  // Use constructor without arguments
414  }
415  // IsDefault and Priority arguments may be specified
417  om,
418  GetIsDefault(params),
419  GetPriority(params)).GetLoader();
420 }
421 
422 
426 {
428 }
429 
430 
CObjectManager::TPriority GetPriority(const TPluginManagerParamTree *params) const
CObjectManager::EIsDefault GetIsDefault(const TPluginManagerParamTree *params) const
bool ValidParams(const TPluginManagerParamTree *params) const
bool IsDataLoaderMatches(CDataLoader &loader) const
Definition: snploader.cpp:74
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObjectManager –.
CDataLoader::TTSE_LockSet GetRecords(CDataSource *data_source, const CSeq_id_Handle &idh, CDataLoader::EChoice choice)
CObjectManager::TPriority GetDefaultPriority(void) const
CTSE_LoadLock GetBlobById(CDataSource *data_source, const CSNPBlobId &blob_id)
CDataLoader::TTSE_LockSet GetOrphanAnnotRecords(CDataSource *ds, const CSeq_id_Handle &idh, const SAnnotSelector *sel, CDataLoader::TProcessedNAs *processed_nas)
TAnnotNames GetPossibleAnnotNames(void) const
void GetChunk(const CSNPBlobId &blob_id, CTSE_Chunk_Info &chunk)
~CSNPDataLoader(void)
Definition: snploader.cpp:290
CParamLoaderMaker< CSNPDataLoader, SLoaderParams > TMaker
Definition: snploader.hpp:133
CSNPDataLoader(void)
virtual bool CanGetBlobById(void) const override
Definition: snploader.cpp:302
virtual TTSE_LockSet GetRecords(const CSeq_id_Handle &idh, EChoice choice) override
Request from a datasource using handles and ranges instead of seq-loc The TSEs loaded in this call wi...
Definition: snploader.cpp:309
vector< CAnnotName > TAnnotNames
Definition: snploader.hpp:110
virtual CObjectManager::TPriority GetDefaultPriority(void) const override
Definition: snploader.cpp:349
static void SetSNP_Scale_Limit(CSeq_id::ESNPScaleLimit value)
Definition: snploader.cpp:373
virtual TBlobId GetBlobIdFromString(const string &str) const override
Definition: snploader.cpp:296
virtual void GetChunk(TChunk chunk) override
Definition: snploader.cpp:325
virtual TTSE_LockSet GetOrphanAnnotRecordsNA(const CSeq_id_Handle &idh, const SAnnotSelector *sel, TProcessedNAs *processed_nas) override
new Get*AnnotRecords() methods
Definition: snploader.cpp:317
static CSeq_id::ESNPScaleLimit GetSNP_Scale_Limit(void)
Definition: snploader.cpp:367
virtual TTSE_Lock GetBlobById(const TBlobId &blob_id) override
Definition: snploader.cpp:342
static bool IsUsingPTIS()
Definition: snploader.cpp:361
CRef< CSNPDataLoader_Impl > m_Impl
Definition: snploader.hpp:143
static string GetLoaderNameFromArgs(void)
Definition: snploader.cpp:228
TAnnotNames GetPossibleAnnotNames(void) const
Definition: snploader.cpp:355
virtual void GetChunks(const TChunkSet &chunks) override
Definition: snploader.cpp:333
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, const SLoaderParams &params, CObjectManager::EIsDefault is_default=CObjectManager::eNonDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: snploader.cpp:144
virtual ~CSNP_DataLoaderCF(void)
Definition: snploader.cpp:398
virtual CDataLoader * CreateAndRegister(CObjectManager &om, const TPluginManagerParamTree *params) const
Definition: snploader.cpp:407
CSafeStaticLifeSpan::
@ eLifeLevel_AppMain
Destroyed in CNcbiApplication::AppMain, if possible.
CSafeStatic<>::
static bool IsEnabled()
Definition: snpptis.cpp:92
TBlobId GetBlobId(void) const
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
ESNPScaleLimit
SNP annotation scale limits.
Definition: Seq_id.hpp:847
TLoader * GetLoader(void) const
Get pointer to the loader.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void RevokeDataLoaders(IDataLoaderFilter &filter)
Revoke data loaders by filter, even if they were still used.
CBlobIdKey TBlobId
CDataSource * GetDataSource(void) const
Definition: data_loader.cpp:92
EChoice
main blob is blob with sequence all other blobs are external and contain external annotations
EIsDefault
Flag defining if the data loader is included in the "default" group.
TRegisterInfo GetRegisterInfo(void)
static void RegisterInObjectManager(CObjectManager &om, CLoaderMaker_Base &loader_maker, CObjectManager::EIsDefault is_default, CObjectManager::TPriority priority)
Register the loader only if the name is not yet registered in the object manager.
Definition: data_loader.cpp:53
vector< TChunk > TChunkSet
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
#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 list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
FILE * file
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Helper classes and templates to implement plugins.
const char kDataLoader_SNP_DriverName[]
Definition: snploader.cpp:391
USING_SCOPE(objects)
static CSNPDataLoader::SLoaderParams s_GetDefaultParams()
Definition: snploader.cpp:131
NCBI_PARAM_DECL(string, SNP, ACCESSIONS)
BEGIN_LOCAL_NAMESPACE
Definition: snploader.cpp:68
NCBI_PARAM_ENUM_ARRAY(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT)
Definition: snploader.cpp:53
NCBI_PARAM_DEF_EX(string, SNP, ACCESSIONS, "", eParam_NoThread, SNP_ACCESSIONS)
END_LOCAL_NAMESPACE
Definition: snploader.cpp:91
void DataLoaders_Register_SNP(void)
Definition: snploader.cpp:385
void NCBI_EntryPoint_xloader_snp(CPluginManager< objects::CDataLoader >::TDriverInfoList &info_list, CPluginManager< objects::CDataLoader >::EEntryPointRequest method)
Definition: snploader.cpp:423
NCBI_PARAM_ENUM_DEF_EX(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT, objects::CSeq_id::eSNPScaleLimit_Default, 0, SNP_LOADER_SCALE_LIMIT)
NCBI_PARAM_ENUM_DECL(objects::CSeq_id::ESNPScaleLimit, SNP_LOADER, SCALE_LIMIT)
static CSafeStatic< CRevoker > s_Revoker(CSafeStaticLifeSpan(CSafeStaticLifeSpan::eLifeLevel_AppMain, CSafeStaticLifeSpan::eLifeSpan_Long))
typedef NCBI_PARAM_TYPE(SNP_LOADER, SCALE_LIMIT) TScale_Limit
CRef< objects::CObjectManager > om
string GetLoaderName(void) const
Definition: snploader.cpp:114
SAnnotSelector –.
SRegisterLoaderInfo –.
Modified on Sat May 25 14:21:11 2024 by modify_doxy.py rev. 669887