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

Go to the SVN repository for this file.

1 #ifndef GUI_OBJUTILS___OBJ_FINGERPRINT__HPP
2 #define GUI_OBJUTILS___OBJ_FINGERPRINT__HPP
3 
4 /* $Id: obj_fingerprint.hpp 47483 2023-05-02 14:11:07Z ucko $
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: Roman Katargin, Victor Joukov
30  *
31  * File Description:
32  *
33  */
34 
35 #include <gui/gui_export.h>
36 #include <serial/typeinfo.hpp>
38 #include <gui/objutils/snp_gui.hpp>
39 
41 
42 BEGIN_SCOPE(objects) // namespace ncbi::objects::
43 class CScope;
44 class CSeq_feat;
45 class CSeq_align;
46 class CSeq_loc;
47 class CSeq_graph;
48 class CSeq_id_Handle;
49 class CSeq_annot_Handle;
51 
52 class CChecksum;
53 
55 {
56 public:
57  typedef void (*TFingerPFunc)(CChecksum& checksum, const CObject& obj,
58  objects::CScope* scope, const CObjFingerprint& fingerP);
59 
60  static void Register(TTypeInfo type_info, TFingerPFunc func);
61 
62  static void GetFingerprint(CChecksum& checksum, const CObject& obj,
63  objects::CScope* scope = NULL);
64 
65  void Fingerprint(CChecksum& checksum, const CObject& obj, objects::CScope* scope) const;
66 
67  static void AddInteger(CChecksum& checksum, unsigned char* pvalue, int size);
68  static void AddDouble(CChecksum& checksum, double value);
69 
70  // object signatures
71  // AAAAAAAA-BBBBBBBB-CCCCCCCC-DDEE-FFFFFFFF-GGGGGGGG[-HHHHHHHH]
72  //
73  // where:
74  // AAAAAAAA = id str as Fasta string,
75  // can be in any form of id and with varied length
76  // BBBBBBBB-CCCCCCCC = total bounded range (from-to) of object
77  // DD = type code for object type (alignment, feature, graph, subsequence, etc.)
78  // 01 - Feature (CSeq_feat)
79  // 02 - Alignment (CSeq_align)
80  // 03 - Location (CSeq_loc)
81  // 04 - Graph (CSeq_graph)
82  // EE = subtype code for object (i.e., feature subtype)
83  // FFFFFFFF = object fingerprint
84  // GGGGGGGG = hash code for the data source, i.e., annotation's name. (optional)
85  // For named annotation accession, we use the real annotation name
86  // For remote file URLs, we use the real url
87  // instead of hash code
88  // HHHHHHHH = hash code of sAdditionalInfo (currently: filter that was used to create the track where that feature is located;
89  // this helps to distinguish features when several tracks are created from the same data source, but using different filters)
90 
91  enum EObjectType {
92  eUnknown = 0,
93  eFeature = 1,
94  eAlignment = 2,
95  eLocation = 3,
96  eGraph = 4,
97  eSnpTrack = 5,
98  eVarTrack = 6,
99  eComponent = 7,
100  eRsite = 8,
101  eVcfTrack = 9
102  };
103 
104  static string GetFeatSignature(const objects::CSeq_feat& feat,
105  objects::CScope* scope,
106  const string& data_source = "",
107  const string& sAdditionalInfo = "");
108 
109  static string GetFeatSignature(const objects::CSeq_feat& feat,
110  objects::CScope* scope,
111  const objects::CSeq_annot_Handle& annot_handle,
112  const string& sAdditionalInfo = "");
113 
114  /// Get signature for a feature with a separate location.
115  static string GetFeatSignature(const objects::CSeq_feat& feat,
116  const objects::CSeq_loc& loc,
117  objects::CScope* scope,
118  const objects::CSeq_annot_Handle& annot_handle,
119  const string& sAdditionalInfo = "");
120 
121  /// Get signature for a feature with a separate location.
122  static string GetFeatSignature(const objects::CSeq_feat& feat,
123  const objects::CSeq_loc& loc,
124  objects::CScope* scope,
125  const string& data_source = "",
126  const string& sAdditionalInfo = "");
127 
128  static string GetGraphSignature(const objects::CSeq_graph& graph,
129  objects::CScope* scope,
130  const string& data_source = "");
131 
132  static string GetSeqLocSignature(const objects::CSeq_loc& loc,
133  objects::CScope* scope);
134 
135  static string GetHistogramSignature(const objects::CSeq_loc& loc,
136  EObjectType obj_type,
137  objects::CScope* scope,
138  const string& title,
139  const string& data_source = "",
140  int subtype = 0);
141 
142  static string GetComponentSignature(const objects::CSeq_loc& comp_loc,
143  const objects::CSeq_loc& mapped_loc,
144  objects::CScope* scope);
145 
146  static string GetAlignSignature(const objects::CSeq_align& align,
147  const objects::CSeq_loc& on_loc,
148  objects::CScope* scope,
149  const objects::CSeq_annot_Handle& annot_handle);
150 
151  static string GetAlignSignature(const objects::CSeq_align& align,
152  const objects::CSeq_loc& on_loc,
153  objects::CScope* scope,
154  const string& data_source = "");
155 
156  static string GetRsiteSignature(const objects::CSeq_feat& feat,
157  int pnt,
158  objects::CScope* scope);
159 
160  static string GetVcfVariantSignature(const objects::CVcfVariant& vcf_variant, objects::CScope* scope);
161 
162  /// parse signature with data source info.
163  /// data source can either be a checksum or ds name.
164  static void ParseSignature(const string& sig,
165  objects::CSeq_id_Handle& sih,
166  TSeqPos& from,
167  TSeqPos& to,
168  EObjectType& type,
169  int& subtype,
170  Uint4& fingerprint,
171  Uint4& ds_fingerprint,
172  string& ds_name,
173  objects::CScope* scope);
174 
175  // get a data source part from the signature
176  static string ParseSignatureDS(const string& sig);
177 
178  typedef struct SFingerprint {
179  objects::CSeq_id_Handle sih;
180  TSeqPos from = 0;
181  TSeqPos to = 0;
183  int subtype = 0;
184  Uint4 fingerprint = 0;
185  Uint4 ds_fingerprint = 0;
186  string ds_name;
187  } SFingerprint;
188 
189  static void ParseSignature(const string& sig, SFingerprint& fp, objects::CScope* scope);
190 private:
191  static CObjFingerprint& x_GetInstance();
192 
193  void x_Register(TTypeInfo type_info, TFingerPFunc func);
194 
197 };
198 
199 inline
200 void CObjFingerprint::ParseSignature(const string& sig, SFingerprint& fp, objects::CScope* scope)
201 {
202  ParseSignature(sig, fp.sih, fp.from, fp.to, fp.type, fp.subtype, fp.fingerprint, fp.ds_fingerprint, fp.ds_name, scope);
203 }
204 
205 inline
206 ostream& operator<<(ostream& os, const CObjFingerprint::SFingerprint& fp)
207 {
208  return os <<
209  "id=" << fp.sih.GetSeqId()->AsFastaString()
210  << " from=" << fp.from
211  << " to=" << fp.to
212  << " type=" << fp.type
213  << " subtype=" << fp.subtype
214  << " fingerprint=" << fp.fingerprint
215  << " ds_fingerprint=" << fp.ds_fingerprint;
216 }
217 
218 
220 
221 
222 #endif // GUI_OBJUTILS___OBJ_FINGERPRINT__HPP
CChecksum – Checksum calculator.
Definition: checksum.hpp:302
static void ParseSignature(const string &sig, objects::CSeq_id_Handle &sih, TSeqPos &from, TSeqPos &to, EObjectType &type, int &subtype, Uint4 &fingerprint, Uint4 &ds_fingerprint, string &ds_name, objects::CScope *scope)
parse signature with data source info.
map< TTypeInfo, TFingerPFunc > TMap
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
CSeq_annot_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
char value[7]
Definition: config.c:431
static const char fp[]
Definition: des.c:87
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define NULL
Definition: ncbistd.hpp:225
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#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
#define NCBI_GUIOBJUTILS_EXPORT
Definition: gui_export.h:512
Defines to provide correct exporting from DLLs in Windows.
const struct ncbi::grid::netcache::search::fields::SIZE size
uint64_t Fingerprint(uint128_t x)
Definition: farmhash.h:158
ostream & operator<<(ostream &os, const CObjFingerprint::SFingerprint &fp)
objects::CSeq_id_Handle sih
Definition: type.c:6
Modified on Tue Dec 05 02:19:12 2023 by modify_doxy.py rev. 669887