NCBI C++ ToolKit
snpread.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef SRA__READER__SRA__SNPREAD__HPP
2 #define SRA__READER__SRA__SNPREAD__HPP
3 /* $Id: snpread.hpp 100244 2023-07-12 15:04:46Z vasilche $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Eugene Vasilchenko
29  *
30  * File Description:
31  * Access to SNP files
32  *
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbimtx.hpp>
37 #include <util/range.hpp>
40 #include <objects/seq/Bioseq.hpp>
42 #include <objects/seq/Seq_inst.hpp>
43 #include <objects/seq/Seq_data.hpp>
44 #include <map>
45 #include <vector>
46 
49 
50 class CSeq_entry;
51 class CSeq_annot;
52 class CSeq_graph;
53 class CSeq_feat;
54 class CUser_object;
55 class CUser_field;
56 class CBioseq;
57 class CID2S_Split_Info;
58 class CID2S_Chunk;
59 
61 class CSNPDbSeqIterator;
62 class CSNPDbPageIterator;
64 class CSNPDbFeatIterator;
65 
67 {
68  enum ESearchMode {
71  };
72 
73  enum EFeatSubtype {
83  };
94  };
95 
96  typedef Uint8 TFilter;
97 
98  struct SFilter {
100  : m_Filter(0),
101  m_FilterMask(0)
102  {
103  }
104  SFilter(TFilter filter,
105  TFilter filter_mask = TFilter(-1))
106  : m_Filter(filter),
107  m_FilterMask(filter_mask)
108  {
109  }
110 
111  void SetNoFilter(void)
112  {
113  m_Filter = 0;
114  m_FilterMask = 0;
115  }
116  void SetFilter(TFilter filter,
117  TFilter filter_mask = TFilter(-1))
118  {
119  m_Filter = filter;
120  m_FilterMask = filter_mask;
121  }
122 
123  void Normalize(void)
124  {
126  }
127 
128  bool IsSet(void) const
129  {
130  return m_FilterMask != 0;
131  }
132  bool Matches(TFilter bits) const
133  {
134  return (bits & m_FilterMask) == m_Filter;
135  }
136 
139  };
140 
141  struct SSelector {
142  SSelector(const SFilter& filter = SFilter())
144  m_Filter(filter)
145  {
146  }
147  SSelector(ESearchMode search_mode,
148  const SFilter& filter = SFilter())
149  : m_SearchMode(search_mode),
150  m_Filter(filter)
151  {
152  }
153 
155  {
156  m_Filter = SFilter();
157  return *this;
158  }
159  SSelector& SetFilter(const SFilter& filter)
160  {
161  m_Filter = filter;
162  return *this;
163  }
165  TFilter filter_mask = TFilter(-1))
166  {
167  m_Filter = SFilter(filter, filter_mask);
168  return *this;
169  }
170 
173  };
174 
175  typedef int TSplitVersion;
176  typedef int TChunkId;
177 };
178 
179 
181 {
182 public:
183  CSNPDb_Impl(CVDBMgr& mgr,
184  CTempString path_or_acc);
185  virtual ~CSNPDb_Impl(void);
186 
187  // SSeqInfo holds cached refseq information - ids, len, rows
188  struct SSeqInfo {
193 
194  const CRef<CSeq_id>& GetMainSeq_id(void) const {
195  return m_Seq_id;
196  }
198  return m_Seq_id_Handle;
199  }
200  struct SPageSet {
204 
205  TSeqPos GetSeqPosEnd(TSeqPos page_size) const {
206  return m_SeqPos + m_PageCount*page_size;
207  }
208  TVDBRowId GetRowIdEnd(void) const {
209  return m_RowId + m_PageCount;
210  }
211  };
213  return COpenRange<TVDBRowId>(m_PageSets.front().m_RowId,
214  m_PageSets.back().GetRowIdEnd());
215  }
216 
217  typedef vector<SPageSet> TPageSets; // sorted by sequence position
220  //vector<TSeqPos> m_AlnOverStarts; // relative to m_RowFirst
221  };
222  typedef vector<SSeqInfo> TSeqInfoList;
224 
225  // STrackInfo holds cached filter track information - name, bits
226  struct STrackInfo {
227  string m_Name;
229  };
230  typedef vector<STrackInfo> TTrackInfoList;
232 
233  const string& GetDbPath(void) const {
234  return m_DbPath;
235  }
236 
237  const TSeqInfoList& GetSeqInfoList(void) const {
238  return m_SeqList;
239  }
241  return m_SeqMapBySeq_id;
242  }
243 
244  const TTrackInfoList& GetTrackInfoList(void) const {
245  return m_TrackList;
246  }
248  return m_TrackMapByName;
249  }
250 
251  TTrackInfoList::const_iterator FindTrack(const string& name) const;
252  TSeqInfoList::const_iterator FindSeq(const string& accession, int version);
253  TSeqInfoList::const_iterator FindSeq(const CSeq_id_Handle& seq_id);
254 
255  TSeqPos GetPageSize(void) const;
256  TSeqPos GetOverviewZoom(void) const;
257  TSeqPos GetCoverageZoom(void) const;
258 
259 protected:
260  friend class CSNPDbTrackIterator;
261  friend class CSNPDbSeqIterator;
262  friend class CSNPDbPageIterator;
263  friend class CSNPDbGraphIterator;
264  friend class CSNPDbFeatIterator;
265 
266  // SSeqTableCursor is helper accessor structure for SEQUENCE table
267  struct SSeqTableCursor;
268  // STrackTableCursor is helper accessor structure for TRACK_FILTER table
269  struct STrackTableCursor;
270  // SPageTableCursor is helper accessor structure for PAGE table
271  struct SPageTableCursor;
272  // SGraphTableCursor is helper accessor structure for COVERAGE_GRAPH table
273  struct SGraphTableCursor;
274  // SFeatTableCursor is helper accessor structure for SNP feature table
275  struct SFeatTableCursor;
276  // SExtraTableCursor is helper accessor structure for extra info (alleles)
277  struct SExtraTableCursor;
278 
279  const CVDBTable& SeqTable(void) {
280  return m_SeqTable;
281  }
282 
283  const CVDBTable& GraphTable(void) {
284  return m_GraphTable;
285  }
286 
287  const CVDBTable& PageTable(void) {
288  return m_PageTable;
289  }
290 
291  const CVDBTable& FeatTable(void) {
292  return m_FeatTable;
293  }
294 
295  const CVDBTable& ExtraTable(void) {
296  return m_ExtraTable;
297  }
298 
299  // get table accessor object for exclusive access
301  // return table accessor object for reuse
302  void Put(CRef<SSeqTableCursor>& curs, TVDBRowId row = 0);
303 
304  // get table accessor object for exclusive access
306  // return table accessor object for reuse
307  void Put(CRef<SGraphTableCursor>& curs, TVDBRowId row = 0);
308 
309  // get table accessor object for exclusive access
311  // return table accessor object for reuse
312  void Put(CRef<SPageTableCursor>& curs, TVDBRowId row = 0);
313 
314  // get table accessor object for exclusive access
316  // return table accessor object for reuse
317  void Put(CRef<SFeatTableCursor>& curs, TVDBRowId row = 0);
318 
319  // get extra table accessor object for exclusive access
321  // return table accessor object for reuse
322  void Put(CRef<SExtraTableCursor>& curs, TVDBRowId row = 0);
323 
324  size_t x_GetSeqVDBIndex(TSeqInfoList::const_iterator seq) const {
325  return seq - GetSeqInfoList().begin();
326  }
327  size_t x_GetTrackVDBIndex(TTrackInfoList::const_iterator track) const {
328  return track - GetTrackInfoList().begin();
329  }
330  TVDBRowId x_GetSeqVDBRowId(TSeqInfoList::const_iterator seq) const {
331  return TVDBRowId(x_GetSeqVDBIndex(seq) + 1);
332  }
333  TVDBRowId x_GetTrackVDBRowId(TTrackInfoList::const_iterator track) const {
334  return TVDBRowId(x_GetTrackVDBIndex(track) + 1);
335  }
336 
337  void x_Update(TSeqInfoList::const_iterator seq);
339  x_GetPageVDBRowRange(TSeqInfoList::const_iterator seq);
340  TVDBRowId x_GetGraphVDBRowId(TSeqInfoList::const_iterator seq,
341  TTrackInfoList::const_iterator track);
342 private:
344  string m_DbPath;
351 
358 
359  TSeqInfoList m_SeqList; // list of cached refseqs' information
360  TSeqInfoMapBySeq_id m_SeqMapBySeq_id; // index for refseq info lookup
363 
364  TTrackInfoList m_TrackList; // list of cached filter track information
365  TTrackInfoMapByName m_TrackMapByName; // index for track lookup
367 };
368 
369 
370 class CSNPDb : public CRef<CSNPDb_Impl>, public SSNPDb_Defs
371 {
372 public:
373  CSNPDb(void)
374  {
375  }
377  : CRef<CSNPDb_Impl>(impl)
378  {
379  }
381  CTempString path_or_acc)
382  : CRef<CSNPDb_Impl>(new CSNPDb_Impl(mgr, path_or_acc))
383  {
384  }
385 
386  size_t GetTrackCount() const
387  {
388  return GetObject().GetTrackInfoList().size();
389  }
390 
392  {
393  return GetObject().GetCoverageZoom();
394  }
396  {
397  return GetObject().GetOverviewZoom();
398  }
399 };
400 
401 
402 // iterate filtered tracks in VDB object
404 {
405 public:
408 
410  {
411  }
412  explicit CSNPDbTrackIterator(const CSNPDb& db);
413  CSNPDbTrackIterator(const CSNPDb& db, size_t track_index);
414  CSNPDbTrackIterator(const CSNPDb& db, const string& name);
415 
416  void Reset(void);
417 
418  DECLARE_OPERATOR_BOOL(m_Db && m_Iter != GetList().end());
419 
420  const TInfo& operator*(void) const {
421  return GetInfo();
422  }
423  const TInfo* operator->(void) const {
424  return &GetInfo();
425  }
426 
427  TVDBRowId GetVDBRowId(void) const {
428  return GetDb().x_GetTrackVDBRowId(m_Iter);
429  }
430  size_t GetVDBTrackIndex(void) const {
431  return GetDb().x_GetTrackVDBIndex(m_Iter);
432  }
433 
435  ++m_Iter;
436  return *this;
437  }
438 
439  const string& GetName(void) const {
440  return GetInfo().m_Name;
441  }
442  const SFilter& GetFilter(void) const {
443  return GetInfo().m_Filter;
444  }
445  TFilter GetFilterBits(void) const {
446  return GetFilter().m_Filter;
447  }
448  TFilter GetFilterMask(void) const {
449  return GetFilter().m_FilterMask;
450  }
451 
452 protected:
453  friend class CSNPDbSeqIterator;
454 
455  CSNPDb_Impl& GetDb(void) const {
456  return m_Db.GetNCObject();
457  }
458  const TList& GetList() const {
459  return GetDb().GetTrackInfoList();
460  }
461  const TInfo& GetInfo() const;
462 
463  friend class CSNPDbPageIterator;
464  friend class CSNPDbGraphIterator;
465 
466 private:
468  TList::const_iterator m_Iter;
469 };
470 
471 
472 // iterate sequences in VDB object
474 {
475 public:
478 
480  {
481  }
482  explicit CSNPDbSeqIterator(const CSNPDb& db);
483  CSNPDbSeqIterator(const CSNPDb& db, size_t seq_index);
484  CSNPDbSeqIterator(const CSNPDb& db, const string& accession, int version);
485  CSNPDbSeqIterator(const CSNPDb& db, const CSeq_id_Handle& seq_id);
486 
487  void Reset(void);
488 
489  DECLARE_OPERATOR_BOOL(m_Db && m_Iter != GetList().end());
490 
491  const TInfo& operator*(void) const {
492  return GetInfo();
493  }
494  const TInfo* operator->(void) const {
495  return &GetInfo();
496  }
497 
498  CSNPDbSeqIterator& operator++(void);
499 
500  CRef<CSeq_id> GetSeqId(void) const {
501  return m_Iter->GetMainSeq_id();
502  }
503  const CSeq_id_Handle& GetSeqIdHandle(void) const {
504  return m_Iter->GetMainSeq_id_Handle();
505  }
506 
507  TSeqPos GetSeqLength(void) const {
508  return m_Iter->m_SeqLength;
509  }
510 
511  bool IsCircular(void) const;
512 
513  TSeqPos GetPageSize(void) const {
514  return GetDb().GetPageSize();
515  }
516  TSeqPos GetOverviewZoom(void) const {
517  return GetDb().GetOverviewZoom();
518  }
519  TSeqPos GetCoverageZoom(void) const {
520  return GetDb().GetCoverageZoom();
521  }
522  TSeqPos GetMaxSNPLength(void) const;
523 
524  // return count of SNP features that intersect with the range
525  Uint8 GetSNPCount(CRange<TSeqPos> range) const;
526  // return count of all SNP features
527  Uint8 GetSNPCount(void) const;
528  CRange<TSeqPos> GetSNPRange(void) const;
529 
530  TVDBRowId GetVDBRowId(void) const {
531  return GetDb().x_GetSeqVDBRowId(m_Iter);
532  }
533  size_t GetVDBSeqIndex(void) const {
534  return GetDb().x_GetSeqVDBIndex(m_Iter);
535  }
537  return GetDb().x_GetPageVDBRowRange(m_Iter);
538  }
540  return GetDb().x_GetGraphVDBRowId(m_Iter, m_TrackIter);
541  }
542 
543  enum EFlags {
544  fZoomPage = 1<<0,
545  fNoGaps = 1<<1,
546  fNoSNPFeat = 1<<2, // exclude features from generated entry
547  fNoCoverageGraph = 1<<3, // exclude coverage graphs from generated entry
548  fNoOverviewGraph = 1<<4, // exclude overview graph from generated entry
549  fOnlySNPFeat = fNoCoverageGraph | fNoOverviewGraph,
550  // control naming of overview graph
551  // by default if base name is "SNP" than no zoom level, otherwise with zoom level
552  fOverviewWithZoomAlways = 1<<5, // name overview graph with zoom level
553  fOverviewWithZoomNever = 1<<6, // name overview graph without zoom level
554  fDefaultFlags = 0
555  };
557 
558  CRef<CSeq_graph> GetOverviewGraph(CRange<TSeqPos> range,
559  TFlags flags = fDefaultFlags) const;
560 
561  CRef<CSeq_annot> GetOverviewAnnot(CRange<TSeqPos> range,
562  const string& annot_name,
563  TFlags flags = fDefaultFlags) const;
564  CRef<CSeq_annot> GetOverviewAnnot(CRange<TSeqPos> range,
565  TFlags flags = fDefaultFlags) const;
566 
567  CRef<CSeq_graph> GetCoverageGraph(CRange<TSeqPos> range) const;
568 
569  CRef<CSeq_annot> GetCoverageAnnot(CRange<TSeqPos> range,
570  const string& annot_name,
571  TFlags flags = fDefaultFlags) const;
572  CRef<CSeq_annot> GetCoverageAnnot(CRange<TSeqPos> range,
573  TFlags flags = fDefaultFlags) const;
574 
576  const SFilter& filter,
577  TFlags flags = fDefaultFlags) const;
579  TFlags flags = fDefaultFlags) const;
580  typedef vector< CRef<CSeq_annot> > TAnnotSet;
581  TAnnotSet GetTableFeatAnnots(CRange<TSeqPos> range,
582  const string& annot_name,
583  const SFilter& filter,
584  TFlags flags = fDefaultFlags) const;
585  TAnnotSet GetTableFeatAnnots(CRange<TSeqPos> range,
586  const SFilter& filter,
587  TFlags flags = fDefaultFlags) const;
588  TAnnotSet GetTableFeatAnnots(CRange<TSeqPos> range,
589  TFlags flags = fDefaultFlags) const;
590  TAnnotSet GetTableFeatAnnots(CRange<TSeqPos> range,
591  const string& annot_name,
592  TFlags flags = fDefaultFlags) const;
593 
594  // Generate Seq-entry
595  CRef<CSeq_entry> GetEntry(const string& base_name,
596  TFlags flags = fDefaultFlags) const;
597  // Generate split-info with split-version
598  pair<CRef<CID2S_Split_Info>, TSplitVersion>
599  GetSplitInfoAndVersion(const string& base_name,
600  TFlags flags = fDefaultFlags) const;
602  GetChunkForVersion(const string& base_name,
603  TChunkId chunk_id,
604  TSplitVersion split_version) const;
605 
606  CSNPDb_Impl& GetDb(void) const {
607  return m_Db.GetNCObject();
608  }
609 
610  const SFilter& GetFilter() const {
611  return x_GetTrackIter()->m_Filter;
612  }
613 
614  void SetTrack(const CSNPDbTrackIterator& track);
615 
616 protected:
617  friend class CSNPDbPageIterator;
618  friend class CSNPDbGraphIterator;
619 
620  const TList& GetList() const {
621  return GetDb().GetSeqInfoList();
622  }
623  const TInfo& GetInfo() const;
624 
625  TList::const_iterator x_GetSeqIter() const {
626  return m_Iter;
627  }
628  CSNPDb_Impl::TTrackInfoList::const_iterator x_GetTrackIter() const {
629  return m_TrackIter;
630  }
631 
632 private:
634  TList::const_iterator m_Iter;
635  CSNPDb_Impl::TTrackInfoList::const_iterator m_TrackIter;
636 };
638 
639 
640 // iterate sequence pages of predefined fixed size
642 {
643 public:
644  CSNPDbPageIterator(void);
645 
646  CSNPDbPageIterator(const CSNPDb& db,
647  const CSeq_id_Handle& ref_id,
648  TSeqPos ref_pos = 0,
649  TSeqPos window = 0,
650  ESearchMode search_mode = eSearchByOverlap);
651  CSNPDbPageIterator(const CSNPDb& db,
652  const CSeq_id_Handle& ref_id,
653  COpenRange<TSeqPos> ref_range,
654  ESearchMode search_mode = eSearchByOverlap);
656  COpenRange<TSeqPos> ref_range,
657  ESearchMode search_mode = eSearchByOverlap);
659  ~CSNPDbPageIterator(void);
660 
662 
663  CSNPDbPageIterator& Select(COpenRange<TSeqPos> ref_range,
664  ESearchMode search_mode = eSearchByOverlap);
665 
666  void Reset(void);
667 
668  DECLARE_OPERATOR_BOOL(m_CurrPagePos < m_SearchRange.GetToOpen());
669 
671  x_Next();
672  return *this;
673  }
674 
675  const CRange<TSeqPos>& GetSearchRange(void) const {
676  return m_SearchRange;
677  }
679  return m_SearchMode;
680  }
681 
682  CRef<CSeq_id> GetSeqId(void) const {
683  return GetRefIter().GetSeqId();
684  }
686  return GetRefIter().GetSeqIdHandle();
687  }
688 
689  TSeqPos GetPageSize(void) const {
690  return GetDb().GetPageSize();
691  }
692  TSeqPos GetPagePos(void) const {
693  return m_CurrPagePos;
694  }
696  TSeqPos pos = GetPagePos();
697  return COpenRange<TSeqPos>(pos, pos+GetPageSize());
698  }
699 
700  TVDBRowId GetPageRowId(void) const {
701  return m_CurrPageRowId;
702  }
703 
704  const CSNPDbSeqIterator& GetRefIter(void) const {
705  return m_SeqIter;
706  }
707 
708  TVDBRowId GetFirstFeatRowId(void) const;
709  TVDBRowCount GetFeatCount(void) const;
710 
711  void SetTrack(const CSNPDbTrackIterator& track) {
712  m_SeqIter.SetTrack(track);
713  }
714 
715 protected:
716  friend class CSNPDbFeatIterator;
717 
718  CSNPDb_Impl& GetDb(void) const {
719  return GetRefIter().GetDb();
720  }
721  const CSNPDb_Impl::SPageTableCursor& Cur(void) const {
722  return *m_Cur;
723  }
724 
725  CSNPDb_Impl::TSeqInfoList::const_iterator x_GetSeqIter() const {
726  return GetRefIter().x_GetSeqIter();
727  }
728  CSNPDb_Impl::TTrackInfoList::const_iterator x_GetTrackIter() const {
729  return GetRefIter().x_GetTrackIter();
730  }
731 
733  return GetDb().x_GetSeqVDBRowId(x_GetSeqIter());
734  }
736  return GetDb().x_GetTrackVDBRowId(x_GetTrackIter());
737  }
738 
740  return GetRefIter().GetPageVDBRowRange();
741  }
743  return GetRefIter().GetGraphVDBRowId();
744  }
745 
746  void x_ReportInvalid(const char* method) const;
747  void x_CheckValid(const char* method) const {
748  if ( !*this ) {
749  x_ReportInvalid(method);
750  }
751  }
752 
753  void x_Next(void);
754 
755 private:
756  CSNPDbSeqIterator m_SeqIter; // refseq selector
757 
759  mutable CRef<CSNPDb_Impl::SGraphTableCursor> m_GraphCur; // graph table accessor
761 
762  CRange<TSeqPos> m_SearchRange; // requested refseq range
763 
767 
769 };
770 
771 
772 // iterate non-zero pages of predefined fixed size for a sequence/track pair
774 {
775 public:
776  CSNPDbGraphIterator(void);
777 
778  explicit
780  COpenRange<TSeqPos> ref_range);
782  ~CSNPDbGraphIterator(void);
783 
785 
786  CSNPDbGraphIterator& Select(const CSNPDbSeqIterator& iter,
787  COpenRange<TSeqPos> ref_range);
788 
789  void Reset(void);
790 
792 
794  x_Next();
795  return *this;
796  }
797 
798  const CRange<TSeqPos>& GetSearchRange(void) const {
799  return m_SearchRange;
800  }
801 
802  TSeqPos GetPageSize(void) const {
803  return GetDb().GetPageSize();
804  }
805  TSeqPos GetPagePos(void) const {
806  return m_CurrPagePos;
807  }
809  TSeqPos pos = GetPagePos();
810  return COpenRange<TSeqPos>(pos, pos+GetPageSize());
811  }
812 
813  TVDBRowId GetGraphRowId(void) const {
814  return m_CurrPageRowId;
815  }
816 
817  Uint4 GetTotalValue(void) const;
818  CVDBValueFor<Uint4> GetCoverageValues(void) const;
819 
820 protected:
821  CSNPDb_Impl& GetDb(void) const {
822  return m_Db.GetNCObject();
823  }
824  const CSNPDb_Impl::SGraphTableCursor& Cur(void) const {
825  return *m_Cur;
826  }
827 
828  void x_ReportInvalid(const char* method) const;
829  void x_CheckValid(const char* method) const {
830  if ( !*this ) {
831  x_ReportInvalid(method);
832  }
833  }
834 
835  void x_Next(void);
836 
837 private:
840 
843  CRange<TSeqPos> m_SearchRange; // requested refseq range
844 
847 };
848 
849 
850 // iterate SNP features
852 {
853 public:
854  CSNPDbFeatIterator(void);
855  CSNPDbFeatIterator(const CSNPDb& db,
856  const CSeq_id_Handle& ref_id,
857  TSeqPos ref_pos = 0,
858  TSeqPos window = 0,
859  const SSelector& sel = SSelector());
860  CSNPDbFeatIterator(const CSNPDb& db,
861  const CSeq_id_Handle& ref_id,
862  COpenRange<TSeqPos> ref_range,
863  const SSelector& sel = SSelector());
865  COpenRange<TSeqPos> ref_range,
866  const SSelector& sel = SSelector());
868  ~CSNPDbFeatIterator(void);
869 
871 
872  CSNPDbFeatIterator& Select(COpenRange<TSeqPos> ref_range,
873  const SSelector& sel = SSelector());
874 
875  void Reset(void);
876 
877  DECLARE_OPERATOR_BOOL(m_CurrFeatId < m_FirstBadFeatId);
878 
880  x_Next();
881  return *this;
882  }
883 
884  CTempString GetFeatType(void) const;
885  EFeatSubtype GetFeatSubtype(void) const;
886  CTempString GetFeatSubtypeString(void) const;
887  static char GetFeatSubtypeChar(EFeatSubtype subtype);
888  static CTempString GetFeatSubtypeString(EFeatSubtype subtype);
889 
890  typedef pair<TVDBRowId, size_t> TExtraRange;
891  TExtraRange GetExtraRange(void) const;
892  CTempString GetAllele(const TExtraRange& range, size_t index) const;
893 
894  const CSNPDbPageIterator& GetPageIter(void) const {
895  return m_PageIter;
896  }
897  const CSNPDbSeqIterator& GetRefIter(void) const {
898  return GetPageIter().GetRefIter();
899  }
900 
901  CRef<CSeq_id> GetSeqId(void) const {
902  return GetPageIter().GetSeqId();
903  }
905  return GetPageIter().GetSeqIdHandle();
906  }
907  const CRange<TSeqPos>& GetSearchRange(void) const {
908  return GetPageIter().GetSearchRange();
909  }
911  return GetPageIter().GetSearchMode();
912  }
913 
914  TSeqPos GetSNPPosition(void) const {
915  return m_CurRange.GetFrom();
916  }
917  TSeqPos GetSNPLength(void) const {
918  return m_CurRange.GetLength();
919  }
920 
922  eFeatIdPrefix_none = 0,
923  eFeatIdPrefix_rs = 1,
924  eFeatIdPrefix_ss = 2
925  };
926  Uint4 GetFeatIdPrefix(void) const;
927  Uint8 GetFeatId(void) const;
928 
929  TFilter GetBitfield(void) const;
930  void GetBitfieldOS(vector<char>& octet_stream) const;
931 
932  // use GetBitfield()
934  Uint8 GetQualityCodes(void) const {
935  return GetBitfield();
936  }
938  void GetQualityCodes(vector<char>& codes) const {
939  GetBitfieldOS(codes);
940  }
941 
942  enum EFlags {
943  fIncludeAlleles = 1<<0,
944  fIncludeRsId = 1<<1,
945  fIncludeBitfield = 1<<2,
946  fIncludeQualityCodes = fIncludeBitfield,
947  fIncludeNeighbors = 1<<3,
948  fIncludeSubtype = 1<<4,
949  fUseSharedObjects = 1<<8,
950  fDefaultFlags = ( fIncludeAlleles |
951  fIncludeRsId |
952  fIncludeBitfield |
953  fIncludeNeighbors |
954  fIncludeSubtype |
955  fUseSharedObjects )
956  };
958 
959  CRef<CSeq_feat> GetSeq_feat(TFlags flags = fDefaultFlags) const;
960 
961 protected:
962  CSNPDb_Impl& GetDb(void) const {
963  return GetPageIter().GetDb();
964  }
965  const CSNPDb_Impl::SFeatTableCursor& Cur(void) const {
966  return *m_Feat;
967  }
968 
969  TVDBRowId GetPageRowId(void) const {
970  return GetPageIter().GetPageRowId();
971  }
972 
973  TSeqPos x_GetFrom(void) const;
974  TSeqPos x_GetLength(void) const;
975 
976  void x_Init(const CSNPDb& snp_db);
977 
978  void x_ReportInvalid(const char* method) const;
979  void x_CheckValid(const char* method) const {
980  if ( !*this ) {
981  x_ReportInvalid(method);
982  }
983  }
984 
985  void x_Next(void);
986  void x_Settle(void);
987  enum EExcluded {
990  ePassedTheRegion
991  };
992  EExcluded x_Excluded(void);
993 
994  void x_SetFilter(const SSelector& sel);
995  void x_InitPage(void);
996 
997  TVDBRowId x_GetGraphVDBRowId() const;
998 
999  CSNPDb_Impl::TSeqInfoList::const_iterator x_GetSeqIter() const {
1000  return GetPageIter().x_GetSeqIter();
1001  }
1002 
1003 private:
1008  mutable CRef<CSNPDb_Impl::SGraphTableCursor> m_Graph; // for page filtering
1010 
1011  COpenRange<TSeqPos> m_CurRange; // current SNP refseq range
1013 
1015 
1018 
1019  struct SCreateCache;
1021  SCreateCache& x_GetCreateCache(void) const;
1022 };
1024 
1025 
1028 
1029 #endif // SRA__READER__SRA__SNPREAD__HPP
AutoPtr –.
Definition: ncbimisc.hpp:401
CID2S_Chunk –.
Definition: ID2S_Chunk.hpp:66
CID2S_Split_Info –.
CMutex –.
Definition: ncbimtx.hpp:749
CObject –.
Definition: ncbiobj.hpp:180
CRange –.
Definition: Range.hpp:68
AutoPtr< SCreateCache > m_CreateCache
Definition: snpread.hpp:1019
TVDBRowId m_GraphBaseRowId
Definition: snpread.hpp:1009
const CSNPDb_Impl::SFeatTableCursor & Cur(void) const
Definition: snpread.hpp:965
CSNPDbFeatIterator & operator++(void)
Definition: snpread.hpp:879
CSNPDb_Impl & GetDb(void) const
Definition: snpread.hpp:962
DECLARE_OPERATOR_BOOL(m_CurrFeatId< m_FirstBadFeatId)
TVDBRowId m_FirstBadFeatId
Definition: snpread.hpp:1014
ESearchMode GetSearchMode(void) const
Definition: snpread.hpp:910
COpenRange< TSeqPos > m_CurRange
Definition: snpread.hpp:1011
pair< TVDBRowId, size_t > TExtraRange
Definition: snpread.hpp:890
void x_Init(const CSNPDb &snp_db)
TSeqPos GetSNPLength(void) const
Definition: snpread.hpp:917
TVDBRowId GetPageRowId(void) const
Definition: snpread.hpp:969
const CSNPDbSeqIterator & GetRefIter(void) const
Definition: snpread.hpp:897
void x_Next(void)
Definition: snpread.cpp:2441
TVDBRowId m_ExtraRowId
Definition: snpread.hpp:1007
TSeqPos GetSNPPosition(void) const
Definition: snpread.hpp:914
CRef< CSNPDb_Impl::SGraphTableCursor > m_Graph
Definition: snpread.hpp:1008
map< CTempString, CRef< CUser_field > > TUserFieldCache
Definition: snpread.hpp:1017
CRef< CSNPDb_Impl::SExtraTableCursor > m_Extra
Definition: snpread.hpp:1006
void x_CheckValid(const char *method) const
Definition: snpread.hpp:979
CSNPDb_Impl::TSeqInfoList::const_iterator x_GetSeqIter() const
Definition: snpread.hpp:999
const CRange< TSeqPos > & GetSearchRange(void) const
Definition: snpread.hpp:907
CSeq_id_Handle GetSeqIdHandle(void) const
Definition: snpread.hpp:904
CSNPDbPageIterator m_PageIter
Definition: snpread.hpp:1004
CRef< CSNPDb_Impl::SFeatTableCursor > m_Feat
Definition: snpread.hpp:1005
DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags)
Uint8 GetQualityCodes(void) const
Definition: snpread.hpp:934
CRef< CObject_id > TObjectIdCache
Definition: snpread.hpp:1016
void x_ReportInvalid(const char *method) const
Definition: snpread.cpp:2449
void GetQualityCodes(vector< char > &codes) const
Definition: snpread.hpp:938
CRef< CSeq_id > GetSeqId(void) const
Definition: snpread.hpp:901
const CSNPDbPageIterator & GetPageIter(void) const
Definition: snpread.hpp:894
TSeqPos GetPagePos(void) const
Definition: snpread.hpp:805
TVDBRowId m_SeqRowId
Definition: snpread.hpp:841
TVDBRowId GetGraphRowId(void) const
Definition: snpread.hpp:813
TVDBRowId m_CurrPageRowId
Definition: snpread.hpp:845
CSNPDb_Impl & GetDb(void) const
Definition: snpread.hpp:821
TSeqPos GetPageSize(void) const
Definition: snpread.hpp:802
const CRange< TSeqPos > & GetSearchRange(void) const
Definition: snpread.hpp:798
CRef< CSNPDb_Impl::SGraphTableCursor > m_Cur
Definition: snpread.hpp:839
DECLARE_OPERATOR_BOOL(m_CurrPagePos !=kInvalidSeqPos)
TSeqPos m_CurrPagePos
Definition: snpread.hpp:846
CSNPDbGraphIterator & operator++(void)
Definition: snpread.hpp:793
const CSNPDb_Impl::SGraphTableCursor & Cur(void) const
Definition: snpread.hpp:824
void x_CheckValid(const char *method) const
Definition: snpread.hpp:829
TVDBRowId m_TrackRowId
Definition: snpread.hpp:842
CRange< TSeqPos > m_SearchRange
Definition: snpread.hpp:843
CRange< TSeqPos > GetPageRange(void) const
Definition: snpread.hpp:808
TVDBRowId GetPageRowId(void) const
Definition: snpread.hpp:700
CSeq_id_Handle GetSeqIdHandle(void) const
Definition: snpread.hpp:685
TSeqPos GetPageSize(void) const
Definition: snpread.hpp:689
TSeqPos GetPagePos(void) const
Definition: snpread.hpp:692
CSNPDbPageIterator & operator++(void)
Definition: snpread.hpp:670
const CSNPDb_Impl::SPageTableCursor & Cur(void) const
Definition: snpread.hpp:721
size_t m_CurrPageSet
Definition: snpread.hpp:764
ESearchMode GetSearchMode(void) const
Definition: snpread.hpp:678
TVDBRowId m_LastGraphRowId
Definition: snpread.hpp:760
CSNPDb_Impl::TSeqInfoList::const_iterator x_GetSeqIter() const
Definition: snpread.hpp:725
TSeqPos m_CurrPagePos
Definition: snpread.hpp:766
void SetTrack(const CSNPDbTrackIterator &track)
Definition: snpread.hpp:711
CRange< TVDBRowId > x_GetPageVDBRowRange() const
Definition: snpread.hpp:739
CSNPDbSeqIterator m_SeqIter
Definition: snpread.hpp:756
const CRange< TSeqPos > & GetSearchRange(void) const
Definition: snpread.hpp:675
CSNPDb_Impl::TTrackInfoList::const_iterator x_GetTrackIter() const
Definition: snpread.hpp:728
CRef< CSeq_id > GetSeqId(void) const
Definition: snpread.hpp:682
ESearchMode m_SearchMode
Definition: snpread.hpp:768
CSNPDb_Impl & GetDb(void) const
Definition: snpread.hpp:718
CRange< TSeqPos > GetPageRange(void) const
Definition: snpread.hpp:695
void x_CheckValid(const char *method) const
Definition: snpread.hpp:747
CRef< CSNPDb_Impl::SPageTableCursor > m_Cur
Definition: snpread.hpp:758
TVDBRowId m_CurrPageRowId
Definition: snpread.hpp:765
CRange< TSeqPos > m_SearchRange
Definition: snpread.hpp:762
const CSNPDbSeqIterator & GetRefIter(void) const
Definition: snpread.hpp:704
TVDBRowId x_GetSeqVDBRowId() const
Definition: snpread.hpp:732
TVDBRowId x_GetTrackVDBRowId() const
Definition: snpread.hpp:735
CRef< CSNPDb_Impl::SGraphTableCursor > m_GraphCur
Definition: snpread.hpp:759
DECLARE_OPERATOR_BOOL(m_CurrPagePos< m_SearchRange.GetToOpen())
TVDBRowId x_GetGraphVDBRowId() const
Definition: snpread.hpp:742
const SFilter & GetFilter() const
Definition: snpread.hpp:610
TList::const_iterator m_Iter
Definition: snpread.hpp:634
const TList & GetList() const
Definition: snpread.hpp:620
const TInfo * operator->(void) const
Definition: snpread.hpp:494
TSeqPos GetSeqLength(void) const
Definition: snpread.hpp:507
CSNPDb_Impl::TTrackInfoList::const_iterator m_TrackIter
Definition: snpread.hpp:635
CRef< CSeq_id > GetSeqId(void) const
Definition: snpread.hpp:500
vector< CRef< CSeq_annot > > TAnnotSet
Definition: snpread.hpp:580
TSeqPos GetCoverageZoom(void) const
Definition: snpread.hpp:519
TSeqPos GetOverviewZoom(void) const
Definition: snpread.hpp:516
const TInfo & operator*(void) const
Definition: snpread.hpp:491
TSeqPos GetPageSize(void) const
Definition: snpread.hpp:513
CSNPDb_Impl & GetDb(void) const
Definition: snpread.hpp:606
const CSeq_id_Handle & GetSeqIdHandle(void) const
Definition: snpread.hpp:503
CSNPDbSeqIterator(void)
Definition: snpread.hpp:479
TVDBRowId GetVDBRowId(void) const
Definition: snpread.hpp:530
const TInfo & GetInfo() const
Definition: snpread.cpp:779
TVDBRowId GetGraphVDBRowId() const
Definition: snpread.hpp:539
TList::value_type TInfo
Definition: snpread.hpp:477
CSNPDb_Impl::TSeqInfoList TList
Definition: snpread.hpp:476
DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags)
CRange< TVDBRowId > GetPageVDBRowRange(void) const
Definition: snpread.hpp:536
DECLARE_OPERATOR_BOOL(m_Db &&m_Iter !=GetList().end())
TList::const_iterator x_GetSeqIter() const
Definition: snpread.hpp:625
size_t GetVDBSeqIndex(void) const
Definition: snpread.hpp:533
CSNPDb_Impl::TTrackInfoList::const_iterator x_GetTrackIter() const
Definition: snpread.hpp:628
CSNPDb_Impl & GetDb(void) const
Definition: snpread.hpp:455
const TInfo & operator*(void) const
Definition: snpread.hpp:420
TFilter GetFilterMask(void) const
Definition: snpread.hpp:448
CSNPDbTrackIterator & operator++(void)
Definition: snpread.hpp:434
TList::const_iterator m_Iter
Definition: snpread.hpp:468
TVDBRowId GetVDBRowId(void) const
Definition: snpread.hpp:427
const SFilter & GetFilter(void) const
Definition: snpread.hpp:442
size_t GetVDBTrackIndex(void) const
Definition: snpread.hpp:430
CSNPDbTrackIterator(void)
Definition: snpread.hpp:409
const string & GetName(void) const
Definition: snpread.hpp:439
TList::value_type TInfo
Definition: snpread.hpp:407
TFilter GetFilterBits(void) const
Definition: snpread.hpp:445
const TInfo * operator->(void) const
Definition: snpread.hpp:423
CSNPDb_Impl::TTrackInfoList TList
Definition: snpread.hpp:406
const TList & GetList() const
Definition: snpread.hpp:458
DECLARE_OPERATOR_BOOL(m_Db &&m_Iter !=GetList().end())
CVDBObjectCache< SGraphTableCursor > m_Graph
Definition: snpread.hpp:354
CVDBTable m_PageTable
Definition: snpread.hpp:348
map< CSeq_id_Handle, size_t > TSeqInfoMapBySeq_id
Definition: snpread.hpp:223
CVDBTable m_ExtraTable
Definition: snpread.hpp:350
const CVDBTable & ExtraTable(void)
Definition: snpread.hpp:295
TTrackInfoMapByName m_TrackMapByName
Definition: snpread.hpp:365
const TTrackInfoMapByName & GetTrackInfoMapByName(void) const
Definition: snpread.hpp:247
map< TVDBRowId, TVDBRowId > TSeq2PageMap
Definition: snpread.hpp:361
const CVDBTable & PageTable(void)
Definition: snpread.hpp:287
const string & GetDbPath(void) const
Definition: snpread.hpp:233
const TTrackInfoList & GetTrackInfoList(void) const
Definition: snpread.hpp:244
TVDBRowId x_GetSeqVDBRowId(TSeqInfoList::const_iterator seq) const
Definition: snpread.hpp:330
CMutex m_Mutex
Definition: snpread.hpp:366
vector< SSeqInfo > TSeqInfoList
Definition: snpread.hpp:222
const CVDBTable & FeatTable(void)
Definition: snpread.hpp:291
const TSeqInfoList & GetSeqInfoList(void) const
Definition: snpread.hpp:237
TTrackInfoList m_TrackList
Definition: snpread.hpp:364
TSeqPos GetOverviewZoom(void) const
Definition: snpread.cpp:458
const CVDBTable & SeqTable(void)
Definition: snpread.hpp:279
TSeqPos GetCoverageZoom(void) const
Definition: snpread.cpp:464
size_t x_GetTrackVDBIndex(TTrackInfoList::const_iterator track) const
Definition: snpread.hpp:327
CVDBMgr m_Mgr
Definition: snpread.hpp:343
CVDBTable m_FeatTable
Definition: snpread.hpp:349
string m_DbPath
Definition: snpread.hpp:344
map< string, size_t > TTrackInfoMapByName
Definition: snpread.hpp:231
CVDBTable m_GraphTable
Definition: snpread.hpp:347
CVDBObjectCache< SExtraTableCursor > m_Extra
Definition: snpread.hpp:357
CVDBObjectCache< SFeatTableCursor > m_Feat
Definition: snpread.hpp:356
CVDBTableIndex m_SeqAccIndex
Definition: snpread.hpp:353
CVDBObjectCache< SSeqTableCursor > m_Seq
Definition: snpread.hpp:352
CVDBTable m_SeqTable
Definition: snpread.hpp:346
size_t x_GetSeqVDBIndex(TSeqInfoList::const_iterator seq) const
Definition: snpread.hpp:324
TSeq2PageMap m_Seq2PageMap
Definition: snpread.hpp:362
TVDBRowId x_GetTrackVDBRowId(TTrackInfoList::const_iterator track) const
Definition: snpread.hpp:333
const TSeqInfoMapBySeq_id & GetSeqInfoMapBySeq_id(void) const
Definition: snpread.hpp:240
CVDBObjectCache< SPageTableCursor > m_Page
Definition: snpread.hpp:355
vector< STrackInfo > TTrackInfoList
Definition: snpread.hpp:230
TSeqInfoList m_SeqList
Definition: snpread.hpp:359
const CVDBTable & GraphTable(void)
Definition: snpread.hpp:283
TSeqInfoMapBySeq_id m_SeqMapBySeq_id
Definition: snpread.hpp:360
size_t GetTrackCount() const
Definition: snpread.hpp:386
CSNPDb(CSNPDb_Impl *impl)
Definition: snpread.hpp:376
CSNPDb(CVDBMgr &mgr, CTempString path_or_acc)
Definition: snpread.hpp:380
TSeqPos GetCoverageZoom() const
Definition: snpread.hpp:391
TSeqPos GetOverviewZoom() const
Definition: snpread.hpp:395
CSNPDb(void)
Definition: snpread.hpp:373
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
objects::CSeqFeatData::ESubtype GetFeatSubtype(const string &feat_type)
Definition: macro_util.cpp:350
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
TObjectType & GetObject(void)
Get object.
Definition: ncbiobj.hpp:1011
TObjectType & GetNCObject(void) const
Get object.
Definition: ncbiobj.hpp:1187
#define NCBI_DEPRECATED
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define NCBI_SRAREAD_EXPORT
Definition: ncbi_export.h:1227
static int version
Definition: mdb_load.c:29
range(_Ty, _Ty) -> range< _Ty >
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
Multi-threading – mutexes; rw-locks; semaphore.
BEGIN_NAMESPACE(objects)
END_NCBI_NAMESPACE
Definition: snpread.hpp:1027
END_NAMESPACE(objects)
BEGIN_NCBI_NAMESPACE
Definition: snpread.hpp:47
DECLARE_SAFE_FLAGS(CSNPDbSeqIterator::EFlags)
#define row(bind, expected)
Definition: string_bind.c:73
TSeqPos GetSeqPosEnd(TSeqPos page_size) const
Definition: snpread.hpp:205
TVDBRowId GetRowIdEnd(void) const
Definition: snpread.hpp:208
vector< SPageSet > TPageSets
Definition: snpread.hpp:217
CRange< TVDBRowId > GetPageVDBRowRange() const
Definition: snpread.hpp:212
const CSeq_id_Handle & GetMainSeq_id_Handle(void) const
Definition: snpread.hpp:197
const CRef< CSeq_id > & GetMainSeq_id(void) const
Definition: snpread.hpp:194
TPageSets m_PageSets
Definition: snpread.hpp:218
TVDBRowId m_GraphRowId
Definition: snpread.hpp:192
CRef< CSeq_id > m_Seq_id
Definition: snpread.hpp:189
CSeq_id_Handle m_Seq_id_Handle
Definition: snpread.hpp:190
SFilter(TFilter filter, TFilter filter_mask=TFilter(-1))
Definition: snpread.hpp:104
void SetNoFilter(void)
Definition: snpread.hpp:111
bool Matches(TFilter bits) const
Definition: snpread.hpp:132
void SetFilter(TFilter filter, TFilter filter_mask=TFilter(-1))
Definition: snpread.hpp:116
bool IsSet(void) const
Definition: snpread.hpp:128
void Normalize(void)
Definition: snpread.hpp:123
SSelector(ESearchMode search_mode, const SFilter &filter=SFilter())
Definition: snpread.hpp:147
SSelector & SetFilter(const SFilter &filter)
Definition: snpread.hpp:159
ESearchMode m_SearchMode
Definition: snpread.hpp:171
SSelector & SetNoFilter(void)
Definition: snpread.hpp:154
SSelector(const SFilter &filter=SFilter())
Definition: snpread.hpp:142
SSelector & SetFilter(TFilter filter, TFilter filter_mask=TFilter(-1))
Definition: snpread.hpp:164
@ eFeatSubtypeChar_insertion
Definition: snpread.hpp:92
@ eFeatSubtypeChar_str
Definition: snpread.hpp:93
@ eFeatSubtypeChar_identity
Definition: snpread.hpp:86
@ eFeatSubtypeChar_unknown
Definition: snpread.hpp:85
@ eFeatSubtypeChar_multi_nucleotide_variation
Definition: snpread.hpp:89
@ eFeatSubtypeChar_deletion
Definition: snpread.hpp:91
@ eFeatSubtypeChar_single_nucleotide_variation
Definition: snpread.hpp:88
@ eFeatSubtypeChar_inversion
Definition: snpread.hpp:87
@ eFeatSubtypeChar_deletion_insertion
Definition: snpread.hpp:90
int TChunkId
Definition: snpread.hpp:176
@ eFeatSubtype_deletion_insertion
Definition: snpread.hpp:79
@ eFeatSubtype_identity
Definition: snpread.hpp:75
@ eFeatSubtype_multi_nucleotide_variation
Definition: snpread.hpp:78
@ eFeatSubtype_single_nucleotide_variation
Definition: snpread.hpp:77
@ eFeatSubtype_inversion
Definition: snpread.hpp:76
@ eFeatSubtype_deletion
Definition: snpread.hpp:80
@ eFeatSubtype_insertion
Definition: snpread.hpp:81
@ eFeatSubtype_str
Definition: snpread.hpp:82
@ eFeatSubtype_unknown
Definition: snpread.hpp:74
Uint8 TFilter
Definition: snpread.hpp:96
@ eSearchByOverlap
Definition: snpread.hpp:69
@ eSearchByStart
Definition: snpread.hpp:70
int TSplitVersion
Definition: snpread.hpp:175
uint64_t TVDBRowCount
Definition: vdbread.hpp:83
int64_t TVDBRowId
Definition: vdbread.hpp:80
Modified on Tue May 21 10:55:38 2024 by modify_doxy.py rev. 669887