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

Go to the SVN repository for this file.

1 /* $Id: seqdb_demo.cpp 93349 2021-04-05 17:22:01Z 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: Kevin Bealer
27  *
28  */
29 
30 /// @file seqdb_demo.cpp
31 /// Task demonstration application for SeqDB.
32 
33 #include <ncbi_pch.hpp>
35 #include <objects/seq/Seq_inst.hpp>
36 #include <corelib/ncbimtx.hpp>
37 #include <corelib/ncbi_system.hpp>
38 #include <sstream>
39 #include <random>
40 
42 
44 
45 
46 /// Demo case base class.
47 class ISeqDBDemoCase : public CObject {
48 public:
49  /// Destructor
50  virtual ~ISeqDBDemoCase()
51  {
52  }
53 
54  /// Show description for this test case.
55  virtual void DisplayHelp() = 0;
56 
57  /// Run this test case.
58  virtual void Run() = 0;
59 };
60 
61 
62 /// Demo for GetSequence() methods.
64 public:
65  /// Destructor
67  {
68  }
69 
70  /// Show description for this test case.
71  virtual void DisplayHelp()
72  {
73  cout << " GetSequence() provides a basic interface to fetch\n"
74  << " a sequence from a SeqDB object given an OID.\n";
75  }
76 
77  /// Run this test case.
78  virtual void Run()
79  {
80  CSeqDB nr("nr", CSeqDB::eProtein);
81 
82  TGi gi = GI_CONST(129295);
83  int oid(0);
84 
85  if (nr.GiToOid(gi, oid)) {
86  const char * buffer(0);
87  unsigned length = nr.GetSequence(oid, & buffer);
88 
89  int alanine = 1; // encoding for the amino acid alanine
90  unsigned count_a = 0;
91 
92  for(unsigned i = 0; i<length; i++) {
93  if (buffer[i] == alanine) {
94  ++ count_a;
95  }
96  }
97 
98  cout << " Found " << count_a
99  << " alanines in sequence with GI " << gi
100  << "." << endl;
101 
102  nr.RetSequence(& buffer);
103  } else {
104  cout << " Failed: could not find GI " << gi << endl;
105  }
106  }
107 };
108 
109 
110 /// Demo for simple (single threaded) iteration methods.
112 public:
113  /// Destructor
115  {
116  }
117 
118  /// Show description for this test case.
119  virtual void DisplayHelp()
120  {
121  cout << " CheckOrFindOID() provides a simple OID based iteration\n"
122  << " over the database. The method works well as the test\n"
123  << " clause of a for loop. This example counts the number\n"
124  << " of sequences in the \"swissprot\" database, displaying\n"
125  << " the count and the combined length of the first 1000.\n";
126  }
127 
128  /// Run this test case.
129  virtual void Run()
130  {
131  CSeqDB sp("swissprot", CSeqDB::eProtein);
132 
133  int oid_count = 0;
134  int length_1000 = 0;
135 
136  for(int oid = 0; sp.CheckOrFindOID(oid); oid++) {
137  if (oid_count++ < 1000) {
138  length_1000 += sp.GetSeqLength(oid);
139  }
140  }
141 
142  int measured = (oid_count > 1000) ? 1000 : oid_count;
143 
144  cout << " Number of swissprot sequences in (from iteration): "
145  << oid_count << endl;
146 
147  cout << " Number of sequences in swissprot (from index file): "
148  << sp.GetNumSeqs() << endl;
149 
150  cout << " Combined length of the first " << measured
151  << " sequences: " << length_1000 << endl;
152  }
153 };
154 
155 
156 /// Demo for chunk iteration methods (single-threaded).
158 public:
159  /// Destructor
161  {
162  }
163 
164  /// Show description for this test case.
165  virtual void DisplayHelp()
166  {
167  cout << " GetNextOIDChunk() provides versatile iteration meant\n"
168  << " for multithreaded applications. Each thread fetches\n"
169  << " a set of OIDs to work with, only returning for more\n"
170  << " when done with that set. SeqDB guarantees that all\n"
171  << " OIDs will be assigned, and no OID will be returned\n"
172  << " more than once.\n\n"
173  << " The data will be returned in one of two forms, either\n"
174  << " as a pair of numbers representing a range of OIDs, or\n"
175  << " in a vector. The number of OIDs desired is indicated\n"
176  << " by setting the size of the vector on input.\n";
177  }
178 
179  /// Run this test case.
180  virtual void Run()
181  {
182  CSeqDB sp("swissprot", CSeqDB::eProtein);
183 
184  // Summary data to collect
185 
186  int oid_count = 0;
187  int length_1000 = 0;
188 
189  // This many OIDs will be fetched at once.
190 
191  int at_a_time = 1000;
192 
193  vector<int> oids;
194 
195  // These will be set to a range if SeqDB chooses to return one.
196 
197  int begin(0), end(0);
198 
199  // In a real multithreaded application, each thread might have
200  // code like the loop inside the "iteration shell" markers,
201  // all using a reference to the same SeqDB object and the same
202  // local_state variable (if needed). The locking inside SeqDB
203  // will prevent simultaneous access - each thread will get
204  // seperate slices of the OID range.
205 
206 
207  // This (local_state) variable is only needed if more than one
208  // iteration will be done. The GetNextOIDChunk() call would
209  // work the same way (in this example) with the last parameter
210  // omitted, because we only iterate over the database once.
211  //
212  // Multiple, simultaneous, independant, iterations (ie. each
213  // getting every OID), would need more than one "local_state"
214  // variable. Iterations pulling OIDs from the same collection
215  // would need to share one variable. If only three parameters
216  // are specified to the GetNextOIDChunk() method, the method
217  // uses a variable which is a field of the SeqDB object.
218 
219  int local_state = 0;
220 
221  // --- Start of iteration "shell" ---
222 
223  bool done = false;
224 
225  while(! done) {
226 
227  // The GetNextOIDChunk() uses the third argument to
228  // determine how many OIDs the user needs, even if the
229  // begin/end variables are used to return the range. In
230  // other words, at_a_time is an INPUT to this call, and
231  // begin, end, and the size and contents of oids, are all
232  // outputs. local_state keeps track of the position in
233  // the iteration - the only user adjustment of it should
234  // be to reset it to 0 at the beginning of each iteration.
235 
236  switch(sp.GetNextOIDChunk(begin, end, at_a_time, oids, & local_state)) {
237  case CSeqDB::eOidList:
238  for(int index = 0; index < (int)oids.size(); index++) {
239  x_UseOID(sp, oids[index], oid_count, length_1000);
240  }
241  done = oids.empty();
242  break;
243 
244  case CSeqDB::eOidRange:
245  for(int oid = begin; oid < end; oid++) {
246  x_UseOID(sp, oid, oid_count, length_1000);
247  }
248  done = (begin == end);
249  break;
250  }
251  }
252 
253  // --- End of iteration "shell" ---
254 
255  unsigned measured = (oid_count > 1000) ? 1000 : oid_count;
256 
257  cout << " Sequences in swissprot (counted during iteration): "
258  << oid_count << endl;
259  cout << " Sequences in swissprot (from database index file): "
260  << sp.GetNumSeqs() << endl;
261  cout << " Combined length of the first " << measured
262  << " sequences: " << length_1000 << endl;
263  }
264 
265 private:
266  /// Use this OID as part of the set.
267  void x_UseOID(
268  CSeqDB& sp,
269  int oid,
270  int& oid_count,
271  int& length_1000
272  )
273  {
274  if (oid_count++ < 1000) {
275  length_1000 += sp.GetSeqLength(oid);
276  }
277  }
278 };
279 
280 
282 {
283 public:
285  int index,
286  int at_a_time,
287  int max_length
288  );
289 
290  virtual void* Main(void);
291  virtual void OnExit(void);
292  const int GetIndex(void) const;
293 
294  static void Init(CSeqDB& db, bool oid_shuffle, bool use_ambigs)
295  {
296  sm_sp = &db;
298  sm_oid_shuffle = oid_shuffle;
299  sm_use_ambigs = use_ambigs;
300  }
301 
302  bool IsRunning(void) const
303  {
304  return m_Running;
305  }
306 
307 private:
308  static CSeqDB* sm_sp;
309  static bool sm_is_protein;
310  static bool sm_oid_shuffle;
311  static bool sm_use_ambigs;
312  static int sm_oid_state;
313 
314  const int m_Index;
315  const int m_AtATime;
316  const int m_MaxLength;
317  bool m_Running;
318  char* m_Temp;
319  // int* m_HeapVar;
320 
321  /// Use this OID as part of the set.
322  long x_UseOID(
323  int letter,
324  int oid
325  )
326  {
327  static const int kNuclCode = kSeqDBNuclNcbiNA8;
328 
329  static const int kLoops = 1;
330 
331  static char* mask = NULL;
332  static char* lets = NULL;
333 
334  if (mask == NULL) {
335  mask = new char[4];
336  lets = new char[4];
337  for (int i = 0; i < 4; ++i) {
338  mask[i] = static_cast<char>(0x03 << (i << 1));
339  lets[i] = static_cast<char>((letter & 0x03) << (i << 1));
340  }
341  }
342 
343  long count = 0;
344 
345  const char* buffer = NULL;
346  if (!sm_is_protein && sm_use_ambigs) {
347 
348  int length = sm_sp->GetAmbigSeq(oid, &buffer, kNuclCode);
349  if (length > 0) {
350 
351  // Artificially inflate the amount of "work" being performed
352  // on each oid.
353 
354  for (int loop = 0; loop < kLoops; ++loop) {
355  count = 0L;
356  const char* p = buffer;
357  for (int i = 0; i < length; ++i) {
358  if (*p++ == letter) {
359  ++count;
360  }
361  }
362  }
363 
364  }
366 
367  } else {
368 
369  int length = sm_sp->GetSequence(oid, &buffer);
370  if (length > 0) {
371 
372  // Artificially inflate the amount of "work" being performed
373  // on each oid.
374 
375  for (int loop = 0; loop < kLoops; ++loop) {
376  count = 0L;
377  const char* p = buffer;
378  if (sm_is_protein) {
379  for (int i = 0; i < length; ++i) {
380  if (*p++ == letter) {
381  ++count;
382  }
383  }
384  } else {
385  int nbytes = (length + 3) / 4;
386  for (int i = 0; i < nbytes; ++i) {
387  char c = *p++;
388  for (int j = 0; j < 4; ++j) {
389  if ((c & mask[j]) == lets[j]) {
390  ++count;
391  }
392  }
393  }
394  }
395  }
396 
397  }
399 
400  }
401 
402  return count;
403  }
404 };
405 
411 
413  int index,
414  int at_a_time,
415  int max_length
416 ) : m_Index(index), m_AtATime(at_a_time), m_MaxLength(max_length),
417  m_Running(true), m_Temp(NULL)
418 {
419 }
420 
422 {
423  long* retval = new long;
424 
425  // m_HeapVar = new int;
426  // *m_HeapVar = 12345;
427 
428  // Summary data to collect
429  long count = 0;
430 
431  // This will be set to a collection of oids
432  // if SeqDB chooses to return one.
433  vector<int> oids;
434 
435  // These will be set to a range if SeqDB chooses to return one.
436  int oid_begin(0), oid_end(0);
437 
438  bool done = false;
439  while (!done) {
440 
441  // The GetNextOIDChunk() uses the third argument to
442  // determine how many OIDs the user needs, even if the
443  // begin/end variables are used to return the range. In
444  // other words, at_a_time is an INPUT to this call, and
445  // begin, end, and the size and contents of oids, are all
446  // outputs. local_state keeps track of the position in
447  // the iteration - the only user adjustment of it should
448  // be to reset it to 0 at the beginning of each iteration.
449 
450  const int letter = 1;
451 
452  if (sm_use_ambigs) {
453  if (
455  oid_begin,
456  oid_end,
457  m_AtATime,
458  oids,
459  &sm_oid_state
460  ) == CSeqDB::eOidRange
461  ) {
462  oids.clear();
463  for (int oid = oid_begin; oid < oid_end; ++oid) {
464  oids.push_back(oid);
465  }
466  }
467  } else {
468  if (
470  oid_begin,
471  oid_end,
472  m_AtATime,
473  oids,
474  &sm_oid_state
475  ) == CSeqDB::eOidRange
476  ) {
477  oids.clear();
478  for (int oid = oid_begin; oid < oid_end; ++oid) {
479  oids.push_back(oid);
480  }
481  }
482  }
483 
484  if (sm_oid_shuffle) {
485  shuffle(oids.begin(), oids.end(), default_random_engine());
486  }
487  ITERATE(vector<int>, oid, oids) {
488  count += x_UseOID(letter, *oid);
489  }
490  done = oids.empty();
491 
492  }
493 
494  std::ostringstream oss;
495  oss << "Thread " << m_Index << " says: "
496  << count << " occurrences of A" << endl;
497 
498  s_mutex.Lock();
499  cout << oss.str() << flush;
500  s_mutex.Unlock();
501 
502  *retval = count;
503  return retval;
504 }
505 
507 {
508  // Delete here anything declared on the heap in Main,
509  // except for the return value. All such items should
510  // have their pointers as data members of this class.
511 
512  // delete m_HeapVar;
513 
514  if (m_Temp != NULL) {
515  delete [] m_Temp;
516  }
517 
518  m_Running = false;
519 }
520 
521 const int CSeqDBDemo_Thread::GetIndex(void) const
522 {
523  return m_Index;
524 }
525 
526 
527 /// Demo for chunk iteration methods (multi-threaded).
529 private:
530 
531  static string sm_DbName;
532  static int sm_NumThreads;
533  static int sm_OidBatchSize;
534  static bool sm_ListVols;
535  static bool sm_NoMmap;
536  static bool sm_OidShuffle;
537  static bool sm_UseAmbigs;
538 
539 public:
540 
541  /// Destructor
543  {
544  }
545 
546  static void SetDbName(const string& dbname)
547  {
548  sm_DbName = dbname;
549  }
550 
551  static void SetNumThreads(const int nthreads)
552  {
553  sm_NumThreads = nthreads;
554  }
555 
556  static void SetListVols(void)
557  {
558  sm_ListVols = true;
559  }
560 
561  static void SetNoMmap(void)
562  {
563  sm_NoMmap = true;
564  }
565 
566  static void SetOidShuffle(void)
567  {
568  sm_OidShuffle = true;
569  }
570 
571  static void SetUseAmbigs(void)
572  {
573  sm_UseAmbigs = true;
574  }
575 
576  static void SetOidBatchSize(const int num)
577  {
578  sm_OidBatchSize = num;
579  }
580 
581  /// Show description for this test case.
582  virtual void DisplayHelp()
583  {
584  cout << " GetNextOIDChunk() provides versatile iteration meant\n"
585  << " for multithreaded applications. Each thread fetches\n"
586  << " a set of OIDs to work with, only returning for more\n"
587  << " when done with that set. SeqDB guarantees that all\n"
588  << " OIDs will be assigned, and no OID will be returned\n"
589  << " more than once.\n\n"
590  << " The data will be returned in one of two forms, either\n"
591  << " as a pair of numbers representing a range of OIDs, or\n"
592  << " in a vector. The number of OIDs desired is indicated\n"
593  << " by setting the size of the vector on input.\n";
594  }
595 
596  /// Run this test case.
597  virtual void Run()
598  {
599  // Open and configure access to the database.
602  if (sp.GetSequenceType() == CSeqDB::eProtein) {
603  cout << "Sequence type is PROTEIN" << endl;
604  } else {
605  cout << "Sequence type is NUCLEOTIDE" << endl;
606  }
607 
608  // Set the database for the thread class.
610 
611  if (sm_ListVols) {
612  // Show the base names of all volumes.
613  vector<string> paths;
614  bool recursive = true;
615  sp.FindVolumePaths(paths, recursive);
616  cout << "Volume paths:" << endl;
617  ITERATE(vector<string>, path, paths) {
618  cout << "\t" << *path << endl;
619  }
620  }
621 
622  // Get the length of the largest sequence in the database.
623  int max_length = sp.GetMaxLength();
624 
625  // The locking inside SeqDB will prevent simultaneous access -
626  // each thread will get separate slices of the OID range.
627  //
628  // The (local_state) variable is only needed if more than one
629  // iteration will be done. The GetNextOIDChunk() call would
630  // work the same way (in this example) with the last parameter
631  // omitted, because we only iterate over the database once.
632  //
633  // Multiple, simultaneous, independent, iterations (ie. each
634  // getting every OID), would need more than one "local_state"
635  // variable. Iterations pulling OIDs from the same collection
636  // would need to share one variable. If only three parameters
637  // are specified to the GetNextOIDChunk() method, the method
638  // uses a variable which is a field of the SeqDB object.
639 
640  vector<CSeqDBDemo_Thread*> threads;
641 
642  for (int index = 1; index <= sm_NumThreads; ++index) {
643  CSeqDBDemo_Thread* thread(
644  new CSeqDBDemo_Thread(
645  index,
647  max_length
648  )
649  );
650  threads.push_back(thread);
651  }
652 
653  NON_CONST_ITERATE(vector<CSeqDBDemo_Thread*>, thread, threads) {
654  (*thread)->Run();
655  }
656 
657  long sumval = 0;
658  vector<CSeqDBDemo_Thread*>::iterator thr;
659  while (!threads.empty()) {
660  bool found = false;
662  vector<CSeqDBDemo_Thread*>,
663  thread,
664  threads
665  ) {
666  CSeqDBDemo_Thread* th = *thread;
667  if (!th->IsRunning()) {
668  thr = thread;
669  found = true;
670  break;
671  }
672  }
673  if (found) {
674  long* retval;
675  (*thr)->Join(reinterpret_cast<void**>(&retval));
676  s_mutex.Lock();
677  cout << "Thread " << (*thr)->GetIndex() << " returned "
678  << *retval << endl;
679  s_mutex.Unlock();
680  threads.erase(thr);
681  sumval += *retval;
682  } else {
683  SleepMilliSec(100);
684  }
685  }
686  cout << "Threads combined returned " << sumval << endl;
687  }
688 };
689 
690 string CSeqDBDemo_Threaded::sm_DbName ("swissprot");
694 bool CSeqDBDemo_Threaded::sm_NoMmap (false);
697 
698 
699 /// Demo for fetching a bioseq from a seqid methods.
701 public:
702  /// Destructor
704  {
705  }
706 
707  /// Show description for this test case.
708  virtual void DisplayHelp()
709  {
710  cout << " SeqidToBioseq() provides a basic interface to fetch\n"
711  << " sequences from a SeqDB object. Given a Seq-id, the\n"
712  << " method returns the first matching CBioseq found in\n"
713  << " the database.\n";
714  }
715 
716  /// Run this test case.
717  virtual void Run()
718  {
719  CSeqDB sp("swissprot", CSeqDB::eProtein);
720 
721  string str("gi|129295");
722 
723  CSeq_id seqid(str);
724  CRef<CBioseq> bs = sp.SeqidToBioseq(seqid);
725 
726  if (! bs.Empty()) {
727  if (bs->CanGetInst()) {
728  if (bs->GetInst().CanGetLength()) {
729  cout << " Length of sequence \"" << str
730  << "\": " << bs->GetInst().GetLength() << endl;
731  } else {
732  cout << " Failed: could not get length from CSeq_inst."
733  << endl;
734  }
735  } else {
736  cout << " Failed: could not get CSeq_inst from CBioseq."
737  << endl;
738  }
739  } else {
740  cout << " Failed: could not get CBioseq from SeqDB." << endl;
741  }
742  }
743 };
744 
745 
746 /// Run one or more test cases.
747 extern "C"
748 int main(int argc, char ** argv)
749 {
750  // Build a set of available test options
751 
752  typedef map< string, CRef<ISeqDBDemoCase> > TDemoSet;
753  TDemoSet demo_set;
754 
755  demo_set["-get-sequence"].Reset(new CSeqDBDemo_GetSequence);
756  demo_set["-iteration-simple"].Reset(new CSeqDBDemo_SimpleIteration);
757  demo_set["-iteration-chunk"].Reset(new CSeqDBDemo_ChunkIteration);
758  demo_set["-iteration-threaded"].Reset(new CSeqDBDemo_Threaded);
759  demo_set["-seqid-to-bioseq"].Reset(new CSeqDBDemo_SeqidToBioseq);
760 
761  // Additional options recognized:
762  // These are used only by "-iteration-threaded" test.
763  // -db <database>
764  // -list_vols
765  // -no_mmap
766  // -num_threads <number of threads>
767  // -oid_batch <number of oids>
768  // -shuffle_oids
769  // -use_ambigs (only applies to nucleotide searches)
770 
771  // Create a list for the tests which will be queued.
772  list< CRef<ISeqDBDemoCase> > demo_list;
773 
774  // Parse and attempt to run everything the user throws at us.
775 
776  bool display_help = false;
777 
778  cout << endl;
779  if (argc > 1) {
780  for (int arg = 1; arg < argc; arg++) {
781  char* args = argv[arg];
782  if (string(args) == "-db") {
783  if (++arg == argc) {
784  cout << "** No database name specified. **\n" << endl;
785  return -1;
786  } else {
787  CSeqDBDemo_Threaded::SetDbName(string(argv[arg]));
788  }
789  } else if (string(args) == "-num_threads") {
790  if (++arg == argc) {
791  cout << "** Number of threads not given. **\n" << endl;
792  return -1;
793  } else {
794  CSeqDBDemo_Threaded::SetNumThreads(atoi(argv[arg]));
795  }
796  } else if (string(args) == "-oid_batch") {
797  if (++arg == argc) {
798  cout << "** Number of oids not given. **\n" << endl;
799  return -1;
800  } else {
801  CSeqDBDemo_Threaded::SetOidBatchSize(atoi(argv[arg]));
802  }
803  } else if (string(args) == "-list_vols") {
805  } else if (string(args) == "-no_mmap") {
807  } else if (string(args) == "-shuffle_oids") {
809  } else if (string(args) == "-use_ambigs") {
811  } else {
812  TDemoSet::iterator it = demo_set.find(string(args));
813  if (it == demo_set.end()) {
814  cout << "** Sorry, option [" << argv[arg]
815  << "] was not found. **\n" << endl;
816  display_help = true;
817  } else {
818  cout << "Queueing test [" << argv[arg] << "]:" << endl;
819  demo_list.push_back(it->second);
820  cout << endl;
821  }
822  }
823  }
824  } else {
825  cout << " This application is meant to be read (as source code),\n"
826  << " stepped through in a debugger, or as a minimal test app.\n"
827  << " It demonstrates use of the CSeqDB library API to perform\n"
828  << " simple and/or common blast database operations.\n";
829 
830  display_help = true;
831  }
832 
833  // If there was a problem, display usage messages
834 
835  if (display_help) {
836  cout << "\nAvailable options:\n\n";
837 
838  NON_CONST_ITERATE(TDemoSet, demo, demo_set) {
839  cout << demo->first << ":\n";
840  demo->second->DisplayHelp();
841  cout << endl;
842  }
843 
844  return -1;
845  }
846 
847  // Run the queued demos.
848 
849  NON_CONST_ITERATE(list<CRef<ISeqDBDemoCase> >, it, demo_list) {
850  (*it)->Run();
851  }
852 
853  return 0;
854 }
855 
857 
ncbi::TMaskedQueryRegions mask
CObject –.
Definition: ncbiobj.hpp:180
Demo for chunk iteration methods (single-threaded).
Definition: seqdb_demo.cpp:157
void x_UseOID(CSeqDB &sp, int oid, int &oid_count, int &length_1000)
Use this OID as part of the set.
Definition: seqdb_demo.cpp:267
virtual void DisplayHelp()
Show description for this test case.
Definition: seqdb_demo.cpp:165
virtual void Run()
Run this test case.
Definition: seqdb_demo.cpp:180
virtual ~CSeqDBDemo_ChunkIteration()
Destructor.
Definition: seqdb_demo.cpp:160
Demo for GetSequence() methods.
Definition: seqdb_demo.cpp:63
virtual ~CSeqDBDemo_GetSequence()
Destructor.
Definition: seqdb_demo.cpp:66
virtual void Run()
Run this test case.
Definition: seqdb_demo.cpp:78
virtual void DisplayHelp()
Show description for this test case.
Definition: seqdb_demo.cpp:71
Demo for fetching a bioseq from a seqid methods.
Definition: seqdb_demo.cpp:700
virtual void DisplayHelp()
Show description for this test case.
Definition: seqdb_demo.cpp:708
virtual ~CSeqDBDemo_SeqidToBioseq()
Destructor.
Definition: seqdb_demo.cpp:703
virtual void Run()
Run this test case.
Definition: seqdb_demo.cpp:717
Demo for simple (single threaded) iteration methods.
Definition: seqdb_demo.cpp:111
virtual void Run()
Run this test case.
Definition: seqdb_demo.cpp:129
virtual void DisplayHelp()
Show description for this test case.
Definition: seqdb_demo.cpp:119
virtual ~CSeqDBDemo_SimpleIteration()
Destructor.
Definition: seqdb_demo.cpp:114
virtual void * Main(void)
Derived (user-created) class must provide a real thread function.
Definition: seqdb_demo.cpp:421
const int GetIndex(void) const
Definition: seqdb_demo.cpp:521
long x_UseOID(int letter, int oid)
Use this OID as part of the set.
Definition: seqdb_demo.cpp:322
static CSeqDB * sm_sp
Definition: seqdb_demo.cpp:308
static bool sm_oid_shuffle
Definition: seqdb_demo.cpp:310
static bool sm_is_protein
Definition: seqdb_demo.cpp:309
bool IsRunning(void) const
Definition: seqdb_demo.cpp:302
static void Init(CSeqDB &db, bool oid_shuffle, bool use_ambigs)
Definition: seqdb_demo.cpp:294
static bool sm_use_ambigs
Definition: seqdb_demo.cpp:311
const int m_AtATime
Definition: seqdb_demo.cpp:315
static int sm_oid_state
Definition: seqdb_demo.cpp:312
CSeqDBDemo_Thread(int index, int at_a_time, int max_length)
Definition: seqdb_demo.cpp:412
const int m_MaxLength
Definition: seqdb_demo.cpp:316
virtual void OnExit(void)
Override this to execute finalization code.
Definition: seqdb_demo.cpp:506
Demo for chunk iteration methods (multi-threaded).
Definition: seqdb_demo.cpp:528
static void SetListVols(void)
Definition: seqdb_demo.cpp:556
static bool sm_ListVols
Definition: seqdb_demo.cpp:534
static int sm_OidBatchSize
Definition: seqdb_demo.cpp:533
static bool sm_NoMmap
Definition: seqdb_demo.cpp:535
static void SetUseAmbigs(void)
Definition: seqdb_demo.cpp:571
static void SetNoMmap(void)
Definition: seqdb_demo.cpp:561
virtual ~CSeqDBDemo_Threaded()
Destructor.
Definition: seqdb_demo.cpp:542
virtual void Run()
Run this test case.
Definition: seqdb_demo.cpp:597
static bool sm_OidShuffle
Definition: seqdb_demo.cpp:536
static void SetNumThreads(const int nthreads)
Definition: seqdb_demo.cpp:551
virtual void DisplayHelp()
Show description for this test case.
Definition: seqdb_demo.cpp:582
static void SetDbName(const string &dbname)
Definition: seqdb_demo.cpp:546
static void SetOidShuffle(void)
Definition: seqdb_demo.cpp:566
static void SetOidBatchSize(const int num)
Definition: seqdb_demo.cpp:576
static bool sm_UseAmbigs
Definition: seqdb_demo.cpp:537
static string sm_DbName
Definition: seqdb_demo.cpp:531
static int sm_NumThreads
Definition: seqdb_demo.cpp:532
CSeqDB.
Definition: seqdb.hpp:161
static void FindVolumePaths(const string &dbname, ESeqType seqtype, vector< string > &paths, vector< string > *alias_paths=NULL, bool recursive=true, bool expand_links=true)
Find volume paths.
Definition: seqdb.cpp:1040
@ eOidRange
Definition: seqdb.hpp:169
@ eOidList
Definition: seqdb.hpp:168
int GetMaxLength() const
Returns the length of the largest sequence in the database.
Definition: seqdb.cpp:705
int GetSeqLength(int oid) const
Returns the sequence length in base pairs or residues.
Definition: seqdb.cpp:400
ESeqType GetSequenceType() const
Returns the type of database opened - protein or nucleotide.
Definition: seqdb.cpp:427
@ eUnknown
Definition: seqdb.hpp:176
@ eProtein
Definition: seqdb.hpp:174
void RetAmbigSeq(const char **buffer) const
Returns any resources associated with the sequence.
Definition: seqdb.cpp:563
void RetSequence(const char **buffer) const
Returns any resources associated with the sequence.
Definition: seqdb.cpp:523
int GetNumSeqs() const
Returns the number of sequences available.
Definition: seqdb.cpp:670
EOidListType GetNextOIDChunk(int &begin_chunk, int &end_chunk, int oid_size, vector< int > &oid_list, int *oid_state=NULL)
Return a chunk of OIDs, and update the OID bookmark.
Definition: seqdb.cpp:739
int GetSequence(int oid, const char **buffer) const
Get a pointer to raw sequence data.
Definition: seqdb.cpp:530
bool CheckOrFindOID(int &next_oid) const
Find an included OID, incrementing next_oid if necessary.
Definition: seqdb.cpp:728
void SetNumberOfThreads(int num_threads, bool force_mt=false)
Setting the number of threads.
Definition: seqdb.cpp:1321
CRef< CBioseq > SeqidToBioseq(const CSeq_id &seqid) const
Get a CBioseq for a given Seq-id.
Definition: seqdb.cpp:1021
int GetAmbigSeq(int oid, const char **buffer, int nucl_code) const
Get a pointer to sequence data with ambiguities.
Definition: seqdb.cpp:550
Demo case base class.
Definition: seqdb_demo.cpp:47
virtual void DisplayHelp()=0
Show description for this test case.
virtual ~ISeqDBDemoCase()
Destructor.
Definition: seqdb_demo.cpp:50
virtual void Run()=0
Run this test case.
Definition: map.hpp:338
#define true
Definition: bool.h:35
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
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define GI_CONST(gi)
Definition: ncbimisc.hpp:1087
#define NULL
Definition: ncbistd.hpp:225
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TInst & GetInst(void) const
Get the Inst member data.
Definition: Bioseq_.hpp:336
bool CanGetLength(void) const
Check if it is safe to call GetLength method.
Definition: Seq_inst_.hpp:646
TLength GetLength(void) const
Get the Length member data.
Definition: Seq_inst_.hpp:659
bool CanGetInst(void) const
Check if it is safe to call GetInst method.
Definition: Bioseq_.hpp:330
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6929
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n th
int i
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Multi-threading – mutexes; rw-locks; semaphore.
#define count
static uint8_t * buffer
Definition: pcre2test.c:1016
Defines BLAST database access classes.
int main(int argc, char **argv)
Run one or more test cases.
Definition: seqdb_demo.cpp:748
DEFINE_STATIC_MUTEX(s_mutex)
const int kSeqDBNuclNcbiNA8
Used to request ambiguities in Ncbi/NA8 format.
static SLJIT_INLINE sljit_ins nr(sljit_gpr dst, sljit_gpr src)
CRef< CTestThread > thr[k_NumThreadsMax]
Definition: test_mt.cpp:267
done
Definition: token1.c:1
static Uint4 letter(char c)
Modified on Fri Sep 20 14:57:39 2024 by modify_doxy.py rev. 669887