NCBI C++ ToolKit
gui_object_info_variant.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: gui_object_info_variant.cpp 35413 2016-05-04 17:51:26Z evgeniev $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Liangshou Wu
27 *
28 * File Description:
29 * Gui Object Info class specifically for structural variations from dbVar.
30 *
31 */
32 
41 #include <gui/objutils/tooltip.hpp>
42 
45 
47 {
48 public:
49  virtual string GetSubtype() const;
50  virtual void GetToolTip(ITooltipFormatter& tooltip, string& t_title, TSeqPos at_p = (TSeqPos)-1) const;
51  virtual void GetLinks(ITooltipFormatter& links, bool no_ncbi_base) const;
52 };
53 
54 
56 {
57  return "Structural variant";
58 }
59 
60 
61 static int s_GetChildNum(const objects::CSeq_feat& feat)
62 {
63  string num_str = feat.GetNamedQual("Child Count");
64  if ( !num_str.empty() ) {
65  try {
66  return NStr::StringToInt(num_str);
67  } catch (CException&) {
68  // ingore it
69  }
70  }
71  return -1;
72 }
73 
74 
75 void CGuiObjectInfoVariant::GetToolTip(ITooltipFormatter& tooltip, string& t_title, TSeqPos /*at_p*/) const
76 {
78 
79  const CVariation_ref& var = m_Feat->GetData().GetVariation();
80  string validation = "Not Tested";
81  string additional_info = kEmptyStr;
82  if (var.IsSetValidated()) {
83  if (var.GetValidated()) {
84  validation = "Yes";
85  } else {
86  validation = "Fail";
87  }
88  } else if (var.IsSetVariant_prop() && var.GetVariant_prop().IsSetOther_validation()) {
89  if (var.GetVariant_prop().GetOther_validation()) {
90  validation = "Yes";
91  } else {
92  validation = "Fail";
93  }
94  } else if (m_Feat->IsSetExts()) {
95  const CSeq_feat::TExts& exts = m_Feat->GetExts();
96  ITERATE (CSeq_feat::TExts, iter, exts) {
97  if ( (*iter)->GetType().IsStr() &&
98  NStr::EqualNocase((*iter)->GetType().GetStr(), "Validation") &&
99  (*iter)->GetFieldRef("Status") &&
100  (*iter)->GetFieldRef("Status")->GetData().IsStr()) {
101  validation = (*iter)->GetFieldRef("Status")->GetData().GetStr();
102  CConstRef<CUser_field> a_field = (*iter)->GetFieldRef("Addition");
103  if (a_field) {
104  additional_info = a_field->GetData().GetStr();
105  }
106  break;
107  }
108  }
109  }
110 
111  // phenotype and clinical-significance
112  string phenotype = "";
113  string clinical_sig = "";
114  if (var.CanGetPhenotype()) {
115  ITERATE (CVariation_ref::TPhenotype, pnt_iter, var.GetPhenotype()) {
116  if (clinical_sig.empty() && (*pnt_iter)->CanGetClinical_significance()) {
117  clinical_sig = NSnp::ClinSigAsString((*pnt_iter)->GetClinical_significance());
118  }
119 
120  if (phenotype.empty() && (*pnt_iter)->CanGetTerm()) {
121  phenotype = (*pnt_iter)->GetTerm();
122  }
123  }
124  }
125 
126  string sample_sex = "";
127  if (var.CanGetSomatic_origin()) {
128  ITERATE (CVariation_ref::TSomatic_origin, so_iter, var.GetSomatic_origin()) {
129  if ((*so_iter)->CanGetSource() &&
130  (*so_iter)->GetSource().GetSubtype() == CSubSource::eSubtype_sex) {
131  sample_sex = (*so_iter)->GetSource().GetName();
132  break;
133  }
134  }
135  }
136 
137  bool is_sv = !var.IsSetId() || (var.GetId().GetTag().IsStr() &&
138  var.GetId().GetTag().GetStr().find("sv") == 1);
139 
140  // allele type
141  string variant_type;
142  int multiplier = -1;
143  if (var.IsComplex()) {
144  variant_type = "Complex";
145  } else if (var.IsInsertion()) {
146  variant_type = "Insertion";
147  } else if (var.IsInversion()) {
148  variant_type = "Inversion";
149  } else if (var.IsEversion()) {
150  variant_type = "Tandem duplication";
151  } else if (var.IsTranslocation()) {
152  variant_type = "Translocation";
153  } else if (var.IsDeletion()) {
154  variant_type = "Deletion";
155  } else if (var.IsDeletionInsertion()) {
156  variant_type = "Indel";
157  } else if (var.IsCNV()) {
158  if (var.GetData().GetInstance().IsSetDelta()) {
159  const CVariation_inst::TDelta& delta = var.GetData().GetInstance().GetDelta();
160  ITERATE (CVariation_inst::TDelta, iter, delta) {
161  if ((*iter)->IsSetMultiplier()) {
162  multiplier = (*iter)->GetMultiplier();
163  break;
164  }
165  }
166  }
167  if (is_sv) {
168  variant_type = "Copy number variation";
169  } else {
170  if (var.IsGain()) {
171  variant_type = "Copy number gain";
172  } else if (var.IsLoss()) {
173  variant_type = "Copy number loss";
174  }
175  }
176  } else { // everything else is treated as 'unknown' regardless
177  variant_type = "Unknown";
178  }
179 
180  if (is_sv) {
181  int child_num = s_GetChildNum(*m_Feat);
182  if (child_num == 0) {
183  // sv, but treated as ssv
184  is_sv = false;
185  } else {
186  if (child_num > 0) {
187  tooltip.AddRow("Supporting Variant Calls:", NStr::IntToString(child_num));
188  }
189  tooltip.AddRow("Variant Region Type:", variant_type);
190  if (multiplier > -1) {
191  tooltip.AddRow("Copy Number:", NStr::NumericToString(multiplier));
192  }
193  if ( !phenotype.empty() ) {
194  tooltip.AddRow("Phenotype:", phenotype);
195  }
196  if ( !clinical_sig.empty() ) {
197  tooltip.AddRow("Clinical Interpretation:", clinical_sig);
198  }
199  if ( !sample_sex.empty() ) {
200  tooltip.AddRow("Gender:", sample_sex);
201  }
202  tooltip.AddRow("Validation Status:", validation);
203  if ( !additional_info.empty() ) {
204  tooltip.AddRow("Additional Info:", additional_info);
205  }
206  if (m_Feat->IsSetComment()) {
207  tooltip.AddRow("Comment:", m_Feat->GetComment());
208  }
209 
210  if (m_Location) {
211  tooltip.AddRow("Total Length:", NStr::IntToString(m_Location->GetTotalRange().GetLength(), NStr::fWithCommas));
212  }
213  }
214  }
215 
216  if ( !is_sv ) {
217  if (var.CanGetParent_id()) {
218  string parent;
219  if (var.GetParent_id().GetTag().IsId()) {
220  parent = NStr::IntToString(var.GetParent_id().GetTag().GetId());
221  } else {
222  parent = var.GetParent_id().GetTag().GetStr();
223  }
224  tooltip.AddRow("Parent Variant Region:", parent);
225  }
226 
227  tooltip.AddRow("Variant Call Type:", variant_type);
228  if (multiplier > -1) {
229  tooltip.AddRow("Copy Number:", NStr::NumericToString(multiplier));
230  }
231  if ( !phenotype.empty() ) {
232  tooltip.AddRow("Phenotype:", phenotype);
233  }
234  if ( !clinical_sig.empty() ) {
235  tooltip.AddRow("Clinical Interpretation:", clinical_sig);
236  }
237  if ( !sample_sex.empty() ) {
238  tooltip.AddRow("Gender:", sample_sex);
239  }
240 
241  // inheritance
243  if (var.IsSetAllele_origin()) {
244  org = var.GetAllele_origin();
245  } else if (var.IsSetVariant_prop() && var.GetVariant_prop().IsSetAllele_origin()) {
246  org = var.GetVariant_prop().GetAllele_origin();
247  }
248 
249  if (org > 0) {
250  string inh;
252  inh += "somatic ";
253  }
255  inh += "inherited ";
256  }
258  inh += "paternal ";
259  }
261  inh += "maternal ";
262  }
264  inh += "de_novo ";
265  }
267  inh += "biparental ";
268  }
270  inh += "uniparental ";
271  }
273  inh += "not-tested ";
274  }
276  inh += "tested-inconclusive ";
277  }
279  inh += "other";
280  }
281 
283  inh = "unknown";
284  }
285 
286  tooltip.AddRow("Inheritance:", inh);
287  }
288 
289  // validation status
290  tooltip.AddRow("Validation Status:", validation);
291  if ( !additional_info.empty() ) {
292  tooltip.AddRow("Additional Info:", additional_info);
293  }
294 
295  if (m_Feat->CanGetComment()) {
296  tooltip.AddRow("Comment:", m_Feat->GetComment());
297  }
298  }
299 
300  int allele_len = -1;
301  if (var.GetData().IsInstance() && var.GetData().GetInstance().IsSetDelta()) {
302  const CVariation_inst::TDelta& delta = var.GetData().GetInstance().GetDelta();
303  ITERATE (CVariation_inst::TDelta, iter, delta) {
304  if ((*iter)->IsSetSeq() && (*iter)->GetSeq().IsLiteral()) {
305  allele_len = (*iter)->GetSeq().GetLiteral().GetLength();
306  break;
307  }
308  }
309  }
310  if (allele_len > -1) {
311  tooltip.AddRow("Allele Length:", NStr::NumericToString(allele_len, NStr::fWithCommas));
312  }
313  if (var.CanGetSample_id()) {
314  string sample_id;
315  const CVariation_ref::TSample_id& sid = var.GetSample_id();
316  if (sid.IsStr()) {
317  sample_id = sid.GetStr();
318  } else {
319  sample_id = NStr::NumericToString(sid.GetId());
320  }
321  if ( !sample_id.empty() ) {
322  tooltip.AddRow("Sample id:", sample_id);
323  }
324  }
325 }
326 
327 static const string kBaseUrl = "http://ncbi.nlm.nih.gov/dbvar/";
328 
329 void CGuiObjectInfoVariant::GetLinks(ITooltipFormatter& links, bool no_ncbi_base) const
330 {
331  // maps link names to link urls and labels (allows links with same name to be consolidated)
332  // (I don't see for dbvar that links generally require this, but it was an issue in
333  // CGuiObjectInfoSeq_feat
335  CIRef<ITooltipFormatter> tmp_links = links.CreateInstance();
336 
337  const CVariation_ref& var = m_Feat->GetData().GetVariation();
338  string label, name, url;
339  if (var.CanGetId() && var.GetId().GetTag().IsStr() &&
340  var.GetId().GetTag().GetStr().find("sv") == 1) {
342  } else if (var.CanGetParent_id()) {
343  if (var.GetParent_id().GetTag().IsId()) {
344  label = NStr::IntToString(var.GetParent_id().GetTag().GetId());
345  } else {
346  label = var.GetParent_id().GetTag().GetStr();
347  }
348  }
349 
350  if ( !label.empty() ) {
351  name = "dbVar";
352  url = kBaseUrl + "variants/" + label;
353  tmp_links->AddLinkRow("dbVar", label, url);
354  }
355 
356  if (m_Feat->IsSetExts()) {
357  ITERATE (CSeq_feat::TExts, iter, m_Feat->GetExts()) {
358  if ((*iter)->GetType().IsStr() &&
359  !(*iter)->GetData().empty()) {
360  name = "Other Variant Calls from this Sample";
361  if ((*iter)->GetType().GetStr() == "related calls") {
362  const CUser_object::TData& fields = (*iter)->GetData();
363  if (fields.size() < 5) {
364  ITERATE (CUser_object::TData, f_iter, fields) {
365  label = (*f_iter)->GetLabel().GetStr();
366  url = kBaseUrl + "variants/" + (*f_iter)->GetData().GetStr();
367  //table_rows += CSeqUtils::CreateLinkRow(name, label, url);
368  link_map[name].push_back(std::pair<string, string>(label, url));
369  }
370  } else if (var.CanGetSample_id()) {
371  string term;
372  if (var.GetSample_id().IsStr()) {
373  term = var.GetSample_id().GetStr();
374  } else {
375  term = NStr::NumericToString(var.GetSample_id().GetId());
376  }
377  CConstRef<CDbtag> study_id = m_Feat->GetNamedDbxref("study_accession");
378  if (study_id) {
379  term += " and " + study_id->GetTag().GetStr();
380  }
381 
382  label = NStr::NumericToString(fields.size());
383  url = kBaseUrl + "?term=" + term;
384  //table_rows += CSeqUtils::CreateLinkRow(name, label, url);
385  link_map[name].push_back(std::pair<string, string>(label, url));
386  }
387  break;
388  } else if ((*iter)->GetType().GetStr() == "related call count") {
389  string term;
390  ITERATE (CUser_object::TData, f_iter, (*iter)->GetData()) {
391  if ((*f_iter)->GetLabel().IsStr() && (*f_iter)->GetData().IsStr()) {
392  label = (*f_iter)->GetLabel().GetStr();
393  term = (*f_iter)->GetData().GetStr();
394  break;
395  }
396  }
397 
398  if ( !term.empty() ) {
399  CConstRef<CDbtag> study_id = m_Feat->GetNamedDbxref("study_accession");
400  if (study_id) {
401  term += " and " + study_id->GetTag().GetStr();
402  }
403  url = kBaseUrl + "?term=" + term;
404  //table_rows += CSeqUtils::CreateLinkRow(name, label, url);
405  link_map[name].push_back(std::pair<string, string>(label, url));
406  }
407  break;
408  }
409  }
410  }
411  }
412 
413  // Create links, consolidating links with same name into a single row
414  map<string, vector<pair<string, string> > >::iterator iter;
415  for (iter=link_map.begin(); iter != link_map.end(); ++iter) {
416  string table_rows;
417 
418  for (size_t i=0; i<(*iter).second.size(); ++i) {
419  // This gives a separate row to each link:
420  //tmp_links += CSeqUtils::CreateLinkRow((*iter).first, (*uiter).first, (*uiter).second);
421  if (i>0) table_rows += ",&nbsp;";
422  table_rows += tmp_links->CreateLink((*iter).second[i].first, (*iter).second[i].second);
423  }
424  tmp_links->AddLinkRow((*iter).first, table_rows, 250);
425  }
426 
427  if ( !tmp_links->IsEmpty()) {
428  links.AddLinksTitle("Go To");
429  links.Append(*tmp_links);
430  }
431 }
432 
433 
Use commas as thousands separator.
Definition: ncbistr.hpp:269
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:970
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:953
bool CanGetSample_id(void) const
Check if it is safe to call GetSample_id method.
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
User-defined methods of the data storage class.
const TParent_id & GetParent_id(void) const
Get the Parent_id member data.
list< CRef< CDelta_item > > TDelta
CConstRef< objects::CSeq_feat > m_Feat
#define kEmptyStr
Definition: ncbistr.hpp:120
vector< CRef< CUser_field > > TData
CRef< objects::CScope > m_Scope
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:893
int i
bool CanGetId(void) const
Check if it is safe to call GetId method.
virtual void Append(const ITooltipFormatter &tooltip)=0
appends another formatter to this one
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5107
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
CConstRef< CUser_field > GetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Return a field reference representing the tokenized key, or a NULL reference if the key doesn't exist...
Definition: User_field.cpp:226
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
list< CRef< CPhenotype > > TPhenotype
virtual void GetToolTip(ITooltipFormatter &tooltip, string &t_title, TSeqPos at_p=(TSeqPos)-1) const
Get tooltip.
User-defined methods of the data storage class.
virtual CIRef< ITooltipFormatter > CreateInstance()=0
creates another instance of the same tooltip formatter
static int s_GetChildNum(const objects::CSeq_feat &feat)
virtual void GetLinks(ITooltipFormatter &links, bool no_ncbi_base) const
Get a set of links.
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
list< CRef< CUser_object > > TExts
Definition: Seq_feat_.hpp:127
Int4 delta(size_t dimension_, const Int4 *score_)
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:54
Definition: map.hpp:337
const TId & GetId(void) const
Get the Id member data.
CException –.
Definition: ncbiexpt.hpp:709
User-defined methods of the data storage class.
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
CConstRef< objects::CSeq_loc > m_Location
Mapped location in top sequence coordinate (can be set externally).
list< CRef< C_E_Somatic_origin > > TSomatic_origin
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:251
static bool EqualNocase(const CTempString str, SIZE_TYPE pos, SIZE_TYPE n, const char *pattern)
Case-insensitive equality of a substring with a pattern.
Definition: ncbistr.hpp:5386
USING_SCOPE(objects)
bool CanGetParent_id(void) const
Check if it is safe to call GetParent_id method.
virtual void AddRow(const string &sContents="", unsigned colspan=2)=0
add a row with a cell, spanning across all columns
User-defined methods of the data storage class.
static string ClinSigAsString(const CVariation_ref &var, ELetterCase LetterCase=eLetterCase_Mixed)
get a human-readable text for various clinical significance types
Definition: snp_utils.cpp:144
const_iterator begin() const
Definition: map.hpp:151
User-defined methods of the data storage class.
static const string kBaseUrl
virtual string GetSubtype() const
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
virtual void AddLinksTitle(const string &sTitle)=0
add a row with the links title
static string NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:4370
const TSample_id & GetSample_id(void) const
Get the Sample_id member data.
User-defined methods of the data storage class.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:531
Modified on Tue Aug 23 18:26:54 2016 by modify_doxy.py rev. 506947