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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___SPARSE_GRAPH__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___SPARSE_GRAPH__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: Andrei Shkeda
30  *
31  * File Description:
32  *
33  */
37 #include <util/bitset/bmdef.h>
38 #include <util/bitset/bmserial.h>
41 #include <mutex>
42 
44 
46  class CSeq_id;
47  class CScope;
49 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// CSparseGraph
53 
54 class CSparseGraph : public CObject
55 {
56  public:
57  using TValType = uint64_t;
58  CSparseGraph();
59  // Copy constructor
61  virtual ~CSparseGraph();
62 
63  static CCompoundID CreateCompoundID(objects::CScope& scope, const objects::CSeq_id& seq_id, const string& remote_path);
64  void InitFromCompoundID(CCompoundID id);
65 
66  virtual void Init(TGraphCachePool& icache_pool);
67  virtual void Save(TGraphCachePool& icache_pool);
68  bool IsCacheGood() const;
69 
71  void Update(const TSeqRange& range, const TUpdateMap& update);
72  void GetMissingRegions(const TSeqRange& range, vector<TSeqRange>& missing_ranges);
73 
74 protected:
76  void x_WriteMap(ICache& icache, bm::word_t* tb = 0);
77  void x_WriteData(ICache& icache, const string& data_key, TSparseVector& sv);
78  void x_ReadMap(ICache& icache, string& tag, string& remote_path, string& last_modified, time_t& last_checked, string& md5, bm::bvector<>& bv, bm::word_t* tb = 0);
79  bool x_ReadData(ICache& icache, const string& data_key, const string& tag, TSparseVector& sv, bm::word_t* tb = 0);
80  void x_CheckRemoteData();
81  void x_Sync(TGraphCachePool& icache_pool);
82 
83  string m_SessionTag; ///< A current session tag, used to separate session netcache blobs from the blobs saved by other sessions
84  string m_NetCacheKey; ///< data access key
85  bm::bvector<> m_DataMap; ///< bvector shows the regions m_Data exist
86  string m_SeqId; ///< NCBI seq_id, e.g. NC_000001
87  size_t m_DataSize = 0; ///< size of each vector of m_Data
88  map<string, unique_ptr<TSparseVector>> m_Data; ///< map of sprasvectors, the key is used as a part of suffix of NetCache key (m_NetCacheKey + "_" + this map key
89  mutex m_DataMutex; ///< data access mutex
90  string m_RemotePath; ///< path to remote data or srz accession
91  string m_LastModified; ///< timestamp of the remote data last modified date as reported by www server
92  time_t m_LastChecked = 0; ///< timestamp: last time when m_LastModified was checked
93  bool m_IsCacheGood = true; ///< false value indicates that remote data were updated and the cache was reset
95 };
96 
97 ///////////////////////////////////////////////////////////////////////////////
98 /// CPileUpGraph
99 
101 {
102 public:
103  static string GetStorageName() {
104  return "GraphCache";
105  }
106  // New data key
107  static string CreateCacheKey(objects::CScope& scope,
108  const objects::CSeq_id& seq_id,
109  const string& remote_path);
110  CPileUpGraph(const string& data_key);
111  void UpdateAlignStats(const TSeqRange& range, float window, CAlnStatGlyph::TStatVec& stats);
112  // guesstimated number of reads based on average 150bp read size
113 
114  int GetNumberOfReads(const TSeqRange& range);
115 };
116 
117 /// inline methods
118 inline
120 {
121  return m_IsCacheGood;
122 }
123 
124 inline
126 {}
127 
129 
130 #endif // GUI_WIDGETS_SEQ_GRAPHIC___SPARSE_GRAPH__HPP
Definitions(internal)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Sparse constainer sparse_vector<> for integer types using bit-transposition transform.
vector< SStatStruct > TStatVec
Base64-encoded ID string that contains extractable typed fields.
CObject –.
Definition: ncbiobj.hpp:180
CPileUpGraph.
void UpdateAlignStats(const TSeqRange &range, float window, CAlnStatGlyph::TStatVec &stats)
CPileUpGraph(const string &data_key)
static string CreateCacheKey(objects::CScope &scope, const objects::CSeq_id &seq_id, const string &remote_path)
CPileUpGraph.
int GetNumberOfReads(const TSeqRange &range)
static string GetStorageName()
CScope –.
Definition: scope.hpp:92
CSparseGraph.
string m_RemotePath
path to remote data or srz accession
string m_NetCacheKey
data access key
bool IsCacheGood() const
inline methods
map< string, vector< TValType > * > TUpdateMap
string m_LastModified
timestamp of the remote data last modified date as reported by www server
mutex m_DataMutex
data access mutex
map< string, unique_ptr< TSparseVector > > m_Data
map of sprasvectors, the key is used as a part of suffix of NetCache key (m_NetCacheKey + "_" + this ...
uint64_t TValType
virtual ~CSparseGraph()
string m_SeqId
NCBI seq_id, e.g. NC_000001.
bm::sparse_vector< TValType, bm::bvector<> > TSparseVector
CTime m_LastSynced
bm::bvector m_DataMap
bvector shows the regions m_Data exist
bool m_IsCacheGood
false value indicates that remote data were updated and the cache was reset
string m_SessionTag
A current session tag, used to separate session netcache blobs from the blobs saved by other sessions...
CTime –.
Definition: ncbitime.hpp:296
BLOB cache read/write/maintenance interface.
Definition: icache.hpp:64
succinct sparse vector with runtime compression using bit-slicing / transposition method
Definition: bmsparsevec.h:87
Definition: map.hpp:338
#define md5
Definition: compat-1.3.h:2010
Declarations of CCompoundIDPool, CCompoundID, and CCompoundIDField.
static void Init(void)
Definition: cursor6.c:76
char data[12]
Definition: iconv.c:80
#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
unsigned int word_t
Definition: bmconst.h:39
range(_Ty, _Ty) -> range< _Ty >
Compressed bitset (entry point to bm.h)
const char * tag
#define uint64_t
Definition: config.h:48
Modified on Sun Apr 21 03:43:29 2024 by modify_doxy.py rev. 669887