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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___VCF_HISTOGRAM__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___VCF_HISTOGRAM__HPP
3 
4 /*
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Vladislav Evgeniev
30  *
31  * File Description:
32  *
33  */
37 #include <mutex>
38 #include <map>
39 #include <vector>
40 
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 /// CVcfHistogram
46 {
47 public:
49 
50  static string GetStorageName() {
51  return "VcfHistogramCache";
52  }
53 
54  ///< Creates a cache key for the given remote file and seq_id
55  ///< the key value is CCompoundID
56  ///< that parsed by constructor when the class is instantiated
57  static string GetCacheKey(const string& annot_name, const size_t bin_width);
58 
59  CVcfHistogram(const string& cache_key);
60 
61  ///< Copy constructor is invoked by CGraphCache
62  ///< which clones the data for aynchroneous saving operation
63  CVcfHistogram(const CVcfHistogram& data);
64 
65  virtual ~CVcfHistogram() { }
66 
67  ///< Init is invoked by CGraphCache
68  ///< when a new instance of CWigGraph is initialized
69  void Init(TGraphCachePool& icache_pool);
70 
71  ///< Save is invoked by CGraphCache
72  ///< when cached data needs to be permanently saved into NetCache
73  void Save(TGraphCachePool& icache_pool);
74 
75  ///< Initializes the histogram map for a given range
76  void GetHistogram(const TSeqRange& range, CHistogramGlyph::TMap& dmap) const;
77 
78  ///< Sets the histogram data
79  void SetData(const THistogramVector& data)
80  {
81  lock_guard<mutex> guard(m_DataMutex);
82  m_Data = data;
83  }
84 
85  static void InitHistogramGlyph(size_t bin_width, const TSeqRange& range, const THistogramVector& histogram, CHistogramGlyph::TMap& dmap)
86  {
87  size_t bin_start = range.GetFrom();
88  while (bin_start < range.GetTo())
89  {
90  TSeqRange BinRange = TSeqRange(static_cast<TSeqPos>(bin_start), static_cast<TSeqPos>(bin_start + bin_width - 1));
91  size_t bin_pos = (bin_start / bin_width);
92  dmap.AddRange(BinRange, bin_pos < histogram.size() ? histogram[static_cast<THistogramVector::size_type>(bin_pos)] : 0);
93  bin_start += bin_width;
94  }
95  }
96 
97  static void EraseCachePerAnnotation(const string& annot_name);
98 
99 protected:
100  string m_AnnotName;
101  size_t m_BinWidth;
102 
103  mutable mutex m_DataMutex; ///< data access mutex
104 
105  string m_DataKey;
107 
108  static mutex m_KeysMapMutex; ///< Mutex for the cache keys
109  static map<string, vector<string>> m_KeysMap; ///< Map of cache keys per annotation
110 };
111 
113 
114 #endif // GUI_WIDGETS_SEQ_GRAPHIC___VCF_HISTOGRAM__HPP
CObject –.
Definition: ncbiobj.hpp:180
CPosToIndex::svector svector
CVcfHistogram.
void SetData(const THistogramVector &data)
static mutex m_KeysMapMutex
Mutex for the cache keys.
static string GetStorageName()
Creates a cache key for the given remote file and seq_id the key value is CCompoundID that parsed by ...
virtual ~CVcfHistogram()
Init is invoked by CGraphCache when a new instance of CWigGraph is initialized.
static map< string, vector< string > > m_KeysMap
Map of cache keys per annotation.
static void InitHistogramGlyph(size_t bin_width, const TSeqRange &range, const THistogramVector &histogram, CHistogramGlyph::TMap &dmap)
mutex m_DataMutex
data access mutex
THistogramVector m_Data
succinct sparse vector with runtime compression using bit-slicing / transposition method
Definition: bmsparsevec.h:87
bvector_type::size_type size_type
Definition: bmsparsevec.h:92
size_type size() const noexcept
return size of the vector
Definition: bmsparsevec.h:729
Definition: map.hpp:338
static void Init(void)
Definition: cursor6.c:76
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
virtual void AddRange(TSeqRange range, CntType score=1, bool expand=false)
CRange< TSeqPos > TSeqRange
typedefs for sequence ranges
Definition: range.hpp:419
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
range(_Ty, _Ty) -> range< _Ty >
Modified on Fri Jan 05 07:24:27 2024 by modify_doxy.py rev. 669887