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

Go to the SVN repository for this file.

1 #ifndef SNP_OBJUTILS___SNP_GUI__HPP
2 #define SNP_OBJUTILS___SNP_GUI__HPP
3 
4 /* $Id: snp_gui.hpp 47426 2023-03-30 01:23:30Z rudnev $
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: Dmitry Rudnev
30  *
31  * File Description:
32  * Some GUI attributes and other helpers for SNP objects and annots
33  *
34  */
35 
36 #include <string>
37 
38 #include <corelib/ncbistd.hpp>
39 
42 #include <gui/utils/rgba_color.hpp>
43 #include <gui/objutils/tooltip.hpp>
44 #include <gui/objutils/label.hpp>
45 #include <objmgr/graph_ci.hpp>
48 
49 /** @addtogroup GUI_UTILS
50  *
51  * @{
52  */
53 
54 
57 
58 /// function to work with SNP annotations
60 {
61 public:
62  static CGraph_CI GetGraph_CI(const TSeqRange& range, const string& sAnnotName, CBioseq_Handle& Handle);
63  static CFeat_CI GetFeat_CI(const TSeqRange& range, const string& sAnnotName, CBioseq_Handle& Handle);
64  static size_t EstimateSNPCount(const TSeqRange& range, const string& sAnnotName, CBioseq_Handle& Handle);
65 };
66 
67 /// a collection of functions helping to display the SNP bins
69 {
70 public:
71  /// preferred colorings for SNP clinical significances
72  ///
73  /// @param ClinSigID
74  /// clinical significance ID
75  /// @return
76  /// a registry key to color used for the given clinical significance
77  static string ClinSigAsColorKey(NSnp::TClinSigID ClinSigID);
78 
79  /// gets a URL to an image representing the given clinical significance
80  ///
81  /// @param[in] ClinSigID
82  /// clinical significance ID
83  /// @param[in] colorTheme
84  /// Current color theme
85  /// @return
86  /// URL path to the image that is hosted on NCBI servers
87  /// (currently within /projects/sviewer/images/)
88  static string ClinSigAsImgURL(NSnp::TClinSigID ClinSigID,
89  const string &colorTheme);
90 
91 
92  /// converts string to clinical significance type (CPhenotype::EClinical_significance)
93  ///
94  /// @param clinsig
95  /// clinical significance as string
96  /// @return
97  /// clinical significance ID, if string value is not mapped returns CPhenotype::eClinical_significance_other
98  static NSnp::TClinSigID ClinSigFromString(const string& clinsig);
99 
100  /// returns color for clinsig values (SV-4908)
101  /// returns #767677 for undefined values
102  static void ClinSigAsColor(NSnp::TClinSigID ClinSigID, CRgbaColor& color);
103 
104  /// returns the term with the highest pathogenicity if the CLNSIG string has multiple parts (terms)
105  ///
106  /// @param clinsig
107  /// clinical significance as string
108  /// @return
109  /// the CLNSIG term with the highest pathogenicity
110  static string SelectClinSigTerm(const string& clinsig);
111 
112  /// preferred colorings for a given pvalue
113  ///
114  /// @param pvalue
115  /// p-value as often contained within SNP bins
116  /// @return
117  /// a registry key to color associated with the given p-value
118  static string PValueAsColorKey(double pvalue);
119 
120  // converts a double pvalue to a string with precision 3
121  static string PValueToString(double pvalue);
122 
123  /// generate a tooltip for a given bin object and put it into the formatter
124  ///
125  /// @param[in] bin
126  /// SNP bin from which data for the tooltip will be taken
127  /// @param[out] pFormatter
128  /// The generated tooltip will be put into the formatter provided here
129  /// @param[in] gi
130  /// gi of sequence on which tooltip is located
131  /// @param[in] colorTheme
132  /// Current color theme
133  static void GetBinTooltip(const NSnpBins::SBin& bin,
134  CIRef<ITooltipFormatter> pFormatter,
135  TGi gi,
136  const std::string &colorTheme);
137 
138  /// representation for a link have an URL and a human-readable label
139  ///
140  /// in the pair, first is the label, second is the URL
141  typedef pair<string, string> TLink;
142 
143  /// list of URL links
144  typedef list<TLink> TLinkList;
145 
146  /// get a list of links associated with a given SNP bin
147  ///
148  /// @param bin
149  /// SNP bin for which the links will be generated
150  /// @param LinkList
151  /// The generated links will be put into the list provided here
152  /// links to NCBI resources are URL paths, outside links are absolute
153  static void GetBinLinks(const NSnpBins::SBin& bin,
154  TLinkList& LinkList);
155 
156  /// standard width and height of a bin
157  static const int c_BinWidth;
158  static const int c_BinHeight;
159 
160  // helpers for dealing with variation info that was read from a VCF file by CVcfReader and
161  // and put into a Variation_ref in its idiosyncratic way
162  // later this should better be moved into NSnp
163  // checks whether this feature was created by CVcfReader by looking for "VcfAttibutes" signature in ext and
164  // returns true if it is present there
165  static bool isFromVcf(const CSeq_feat& variation_ref);
166 
167  /// returns CLNSIG attribute value from VcfAttribute user object
168  /// returns false if not found
169  static bool GetClinSigValue(const CSeq_feat& ref, string& attr_value);
170 
171  // decontructs list of alleles and tries to deduce the variation type from alleles created by CVcfReader
172  // returns CVariation_inst::eType_unknown if variation_ref was not obtained from CVcfReader
173  static CVariation_inst::EType GetVcfType(const CSeq_feat& variation_ref);
174 
175  // same deduction, but from a reference allele and a list of alt alleles as read from a VCF record
176  static CVariation_inst::EType GetVcfType(const string& ref, const vector<string>& alt);
177 
178  /// standard NCBI resourse URLs
179  static const string ClinVarIdURL;
180  static const string snpURL;
181 
182 private:
183  /// makes a varVu link suitable for putting into a tooltip
184  static void x_MakeVarVuLink(CConstRef<NSnpBins::SBinEntry> BinEntry,
185  CIRef<ITooltipFormatter> pFormatter,
186  bool& isGoToPresent,
187  TGi gi);
188  /// makes a varVu link suitable for putting into a link list
189  static void x_MakeVarVuLink(CConstRef<NSnpBins::SBinEntry> BinEntry,
190  TLinkList& LinkList,
191  TGi gi);
192 
193  /// makes a ClinVar link suitable for putting into a tooltip
194  static void x_MakeClinVarLink(CConstRef<NSnpBins::SBinEntry> BinEntry,
195  CIRef<ITooltipFormatter> pFormatter,
196  bool& isGoToPresent);
197  /// makes a ClinVar link suitable for putting into a link list
198  static void x_MakeClinVarLink(CConstRef<NSnpBins::SBinEntry> BinEntry,
199  TLinkList& LinkList);
200 
201  /// processes dbgaptext field and puts its contents into a tooltip
202  ///
203  /// unpacks whatever may be in dbgaptext field, creates links and
204  /// puts them into the supplied tooltip formatter
205  /// dbgaptext is a set of URL encoded key/value pairs, see DG-1985 for details
206  static void x_ProcessDbgaptext(CConstRef<NSnpBins::SBinEntry> BinEntry,
207  ITooltipFormatter* pFormatter);
208 
209  /// standard NCBI resourse URLs
210  static const string pmURL;
211  static const string omimURL;
212  static const string geneSymURL;
213  static const string geneRevURL;
214  static const string phenotypeURL;
215  static const string GAPStudyURL;
216  static const string PHAURL;
217  static const string GenomeURL;
218  static const string VarVuURL;
219  static const string ClinVarURL;
220 };
221 
222 /// helpers for accessing SNP web services
224 {
225 public:
226  /// various placements of a variation
227  typedef list<CRef<CVariation> > TSNPSearchResultList;
228  /// results of a search for a given id (string)
229  /// TSNPSearchResultList may be empty if the id has been found to be valid, but not satisfying other search criteria
230  /// (currently: assembly accession)
231  typedef pair<string, TSNPSearchResultList> TSNPSearchCompoundResult;
232 
233  /// results of a search for one or several ids
234  typedef list<TSNPSearchCompoundResult> TSNPSearchCompoundResultList;
235 
236  /// search for given SNP ID(s) and get a list of results
237  ///
238  /// uses projects/SNP/beVarSearch.cgi
239  ///
240  /// @param sTerm
241  /// search term, a comma-delimited list of ss or rs ids (e.g. ss222424,rs4334323)
242  ///
243  /// @param sAssemblyAccession
244  /// if not empty, limit the results only to a given assembly accession
245  /// @return
246  /// true if the search term is valid
247  /// list of results as list of found IDs and linked results per each ID
248  /// in addition to standard CVariation fields, variations have some additional data in ext User-field
249  /// the following labels can appear in ext:
250  /// c_SNPVarExt_GeneSymbol ("gene_symbol")
251  /// c_SNPVarExt_TopLevel ("top_level") "yes" if this particular placement is on top-level genomic seq
252  /// c_SNPVarExt_QueryId ("query_id") original query id
253  /// c_SNPVarExt_Comment ("comment")
254  static void Search(const std::string& sTerms, const std::string& sAssemblyAccession, TSNPSearchCompoundResultList& ResultList);
255  /// same thing without taking assembly into account
256  static void Search(const std::string& sTerms, TSNPSearchResultList& ResultList);
257 
258  static void SearchByVarId(const std::string& sTerms, const string& sAssemblyAccession, TSNPSearchCompoundResultList& ResultList);
259 
260  static const string c_SNPVarExt_SearchClass;
261  static const string c_SNPVarExt_GeneSymbol;
262  static const string c_SNPVarExt_TopLevel;
263  static const string c_SNPVarExt_QueryId;
264  static const string c_SNPVarExt_Comment;
265 
266 private:
267  static void x_GetSearchHost();
268  static string m_sSearchHost;
269  static bool m_isSearchByRsid;
270 };
271 
272 
274  public CObject
275 {
276 public:
277  CVcfVariant(const objects::CSeq_id& seq_id,
278  const string& sVariantID,
279  size_t pos, ///< in VCF (i.e. 1-based coordinates)
280  const string& ref_allele,
281  const string& alt_alleles); ///< alternative alleles separated by /
282  CVcfVariant(const string& sSeqId,
283  const string& sVariantID,
284  size_t pos, ///< in VCF (i.e. 1-based coordinates)
285  const string& ref_allele,
286  const string& alt_alleles); ///< alternative alleles separated by /
287  string GetID() const { return m_sID; }
288  size_t GetPos() const { return m_Pos; }
289  size_t GetLen() const { return m_Len; }
290  string GetRefAllele_display() const { return m_sRefAllele_display; }
291  const list<string>& GetAltAlleles_display() const { return m_AltAlleles_display; }
292  string GetAllAlleles_display() const;
293 
294  string GetRefAllele_orig() const { return m_sRefAllele_orig; }
295  string GetAltAlleles_orig() const;
296 
297  // if possible to calculate allele length, will return a positive number representing the longest allele
298  // all_alt_alleles_same_len is true if all alt alleles have the same length
299  int GetLongestAlleleLen(bool& all_alt_alleles_same_len) const;
300  objects::CVariation_inst::EType GetVariationType() const { return m_VariationType; }
301  string GetVariationTypeAsString() const;
302  const objects::CSeq_loc& GetLocation() const { return *m_SeqLoc; }
303  void GetLabel(string& label, CLabel::ELabelType type) const;
304  static string GetTypeName() { return typeid(CVcfVariant).name(); }
305 
306  // first string is column name, second is its value
308 
309  const TColumns& GetInfoColumns() const { return m_InfoColumns; }
310  string GetInfoColumnsAsString() const;
311  const TColumns& GetSampleColumns() const { return m_SampleColumns; }
312  TColumns& SetInfoColumns() { return m_InfoColumns; }
313  TColumns& SetSampleColumns() { return m_SampleColumns; }
314  // matching variants does not take alleles into account
315  bool WeakMatch(const CVcfVariant& right) const { return m_sID == right.m_sID && m_Pos == right.m_Pos && m_Len == right.m_Len && m_VariationType == right.m_VariationType; }
316  void ParseInfoColumns();
317 
318  bool IsClinVar() const {
319  return m_VCF_Type == EVCF_Type::eVCF_ClinVar;
320  }
321  bool IsDbVar() const {
322  return m_VCF_Type == EVCF_Type::eVCF_DbVar;
323  }
324 
325 private:
326  string m_sID;
327  size_t m_Pos;
328  size_t m_Len;
329 
330  // alleles as originally in VCF record
332  vector<string> m_AltAlleles_orig;
333 
334  // alleles modified for display
336  list<string> m_AltAlleles_display;
337 
338  objects::CVariation_inst::EType m_VariationType;
339  // Uncertainties in integer values limit value
340  unique_ptr<objects::CInt_fuzz::ELim> m_LimitValue;
341 
342  unique_ptr<objects::CDelta_item::EAction> m_DeltaItemAction;
343 
347  typedef enum {
350  eVCF_ClinVar
351  } EVCF_Type;
352  EVCF_Type m_VCF_Type{eVCF_regular};
353 };
354 
355 
356 
357 
360 /* @} */
361 #endif // SNP_OBJUTILS___SNP_GUI__HPP
362 
User-defined methods of the data storage class.
CBioseq_Handle –.
CConstRef –.
Definition: ncbiobj.hpp:1266
CFeat_CI –.
Definition: feat_ci.hpp:64
CGraph_CI –.
Definition: graph_ci.hpp:234
CObject –.
Definition: ncbiobj.hpp:180
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
helpers for accessing SNP web services
Definition: snp_gui.hpp:224
function to work with SNP annotations
Definition: snp_gui.hpp:60
a collection of functions helping to display the SNP bins
Definition: snp_gui.hpp:69
int TClinSigID
Definition: snp_utils.hpp:76
Include a standard set of the NCBI C++ Toolkit most basic headers.
string
Definition: cgiapp.hpp:687
#define Handle
Definition: ncbistd.hpp:119
vector< string > m_AltAlleles_orig
Definition: snp_gui.hpp:332
string GetID() const
Definition: snp_gui.hpp:287
bool WeakMatch(const CVcfVariant &right) const
Definition: snp_gui.hpp:315
static const string pmURL
standard NCBI resourse URLs
Definition: snp_gui.hpp:210
string GetRefAllele_display() const
Definition: snp_gui.hpp:290
static const string snpURL
Definition: snp_gui.hpp:180
list< TSNPSearchCompoundResult > TSNPSearchCompoundResultList
results of a search for one or several ids
Definition: snp_gui.hpp:234
static const string c_SNPVarExt_TopLevel
Definition: snp_gui.hpp:262
list< CRef< CVariation > > TSNPSearchResultList
various placements of a variation
Definition: snp_gui.hpp:227
objects::CVariation_inst::EType GetVariationType() const
Definition: snp_gui.hpp:300
size_t m_Pos
Definition: snp_gui.hpp:327
string m_sRefAllele_orig
Definition: snp_gui.hpp:331
pair< string, string > TLink
representation for a link have an URL and a human-readable label
Definition: snp_gui.hpp:141
TColumns & SetInfoColumns()
Definition: snp_gui.hpp:312
static const int c_BinWidth
standard width and height of a bin
Definition: snp_gui.hpp:157
static bool m_isSearchByRsid
Definition: snp_gui.hpp:269
string m_sID
Definition: snp_gui.hpp:326
const list< string > & GetAltAlleles_display() const
Definition: snp_gui.hpp:291
string GetRefAllele_orig() const
Definition: snp_gui.hpp:294
static const string c_SNPVarExt_SearchClass
Definition: snp_gui.hpp:260
objects::CVariation_inst::EType m_VariationType
Definition: snp_gui.hpp:338
bool IsClinVar() const
Definition: snp_gui.hpp:318
TColumns & SetSampleColumns()
Definition: snp_gui.hpp:313
size_t GetPos() const
Definition: snp_gui.hpp:288
size_t GetLen() const
Definition: snp_gui.hpp:289
static const string c_SNPVarExt_GeneSymbol
Definition: snp_gui.hpp:261
static const string geneRevURL
Definition: snp_gui.hpp:213
string m_sRefAllele_display
Definition: snp_gui.hpp:335
CConstRef< objects::CSeq_loc > m_SeqLoc
Definition: snp_gui.hpp:344
static const string VarVuURL
Definition: snp_gui.hpp:218
size_t m_Len
Definition: snp_gui.hpp:328
static const string phenotypeURL
Definition: snp_gui.hpp:214
static const string PHAURL
Definition: snp_gui.hpp:216
pair< string, TSNPSearchResultList > TSNPSearchCompoundResult
results of a search for a given id (string) TSNPSearchResultList may be empty if the id has been foun...
Definition: snp_gui.hpp:231
static const string geneSymURL
Definition: snp_gui.hpp:212
static const string GAPStudyURL
Definition: snp_gui.hpp:215
map< string, string > TColumns
Definition: snp_gui.hpp:307
bool IsDbVar() const
Definition: snp_gui.hpp:321
static const string GenomeURL
Definition: snp_gui.hpp:217
static const string ClinVarIdURL
standard NCBI resourse URLs
Definition: snp_gui.hpp:179
list< string > m_AltAlleles_display
Definition: snp_gui.hpp:336
unique_ptr< objects::CInt_fuzz::ELim > m_LimitValue
Definition: snp_gui.hpp:340
static const string omimURL
Definition: snp_gui.hpp:211
static const string c_SNPVarExt_QueryId
Definition: snp_gui.hpp:263
TColumns m_SampleColumns
Definition: snp_gui.hpp:346
static const string c_SNPVarExt_Comment
Definition: snp_gui.hpp:264
ELabelType
Definition: label.hpp:60
list< TLink > TLinkList
list of URL links
Definition: snp_gui.hpp:144
static string GetTypeName()
Definition: snp_gui.hpp:304
static const string ClinVarURL
Definition: snp_gui.hpp:219
static string m_sSearchHost
Definition: snp_gui.hpp:268
const TColumns & GetSampleColumns() const
Definition: snp_gui.hpp:311
CVcfVariant(const objects::CSeq_id &seq_id, const string &sVariantID, size_t pos, const string &ref_allele, const string &alt_alleles)
alternative alleles separated by /
TColumns m_InfoColumns
Definition: snp_gui.hpp:345
const TColumns & GetInfoColumns() const
Definition: snp_gui.hpp:309
static const int c_BinHeight
Definition: snp_gui.hpp:158
static void Search(const std::string &sTerms, const std::string &sAssemblyAccession, TSNPSearchCompoundResultList &ResultList)
search for given SNP ID(s) and get a list of results
const objects::CSeq_loc & GetLocation() const
Definition: snp_gui.hpp:302
unique_ptr< objects::CDelta_item::EAction > m_DeltaItemAction
Definition: snp_gui.hpp:342
string GetLabel(const CSeq_id &id)
#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
static const char label[]
n background color
range(_Ty, _Ty) -> range< _Ty >
representation of a bin
Definition: snp_bins.hpp:102
Definition: type.c:6
Modified on Sun Apr 14 05:28:47 2024 by modify_doxy.py rev. 669887