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

Go to the SVN repository for this file.

1 /* $Id: gui_object_info_clone_feat.cpp 47166 2022-10-05 19:18:35Z 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 clone features.
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/tempstr.hpp>
39 #include <gui/objutils/tooltip.hpp>
40 
41 
44 
46 {
47 public:
48  virtual void GetToolTip(ITooltipFormatter& tooltip, string& t_title, TSeqPos at_p = (TSeqPos)-1, bool* isGeneratedBySvc = NULL) const;
49  virtual void GetLinks(ITooltipFormatter& links, bool no_ncbi_base) const;
50 private:
51  enum TAccInfo {
52  eAcc_GSS = 0, // GSS sequences
53  eAcc_Nuc, // Nucleotide sequences(e.g.HTG records)
54  eAcc_Trace // Trace
55  };
57  string x_FormatAccessionLinks(const ITooltipFormatter& tooltip, const vector<string> &strings, const TAccessionInfoMap &acc_info, bool occurences = true) const;
58  void x_IdentifyAccession(const CSeq_id &id, const string &id_str, TAccessionInfoMap &acc_info) const;
59 private:
61  const static string m_BaseURLs[];
62 };
63 
64 const string CGuiObjectInfoClone::m_BaseURLs[] = {
65  "/nucgss/",
66  "/nuccore/",
67  "/Traces/trace.cgi?&cmd=retrieve&retrieve=Submit&val="
68 };
69 
70 void CGuiObjectInfoClone::GetToolTip(ITooltipFormatter& tooltip, string& t_title, TSeqPos /*at_p*/, bool* isGeneratedBySvc) const
71 {
72  if(isGeneratedBySvc) {
73  *isGeneratedBySvc = false;
74  }
76 
77  const CSeqFeatData::TClone& clone = m_Feat->GetData().GetClone();
78  if (m_Location) {
79  tooltip.AddRow("Total length:", NStr::IntToString(m_Location->GetTotalRange().GetLength(), NStr::fWithCommas));
80 
81  string range = NStr::IntToString(
83  range += "..";
86  tooltip.AddRow("Total range:", range);
87  }
88 
89  if (m_Feat->IsSetComment() && m_Feat->GetComment() != t_title) {
90  tooltip.AddRow("Comment:", m_Feat->GetComment());
91  }
92 
93  if (clone.IsSetPlacement_method()) {
94  const CEnumeratedTypeValues* type_val =
95  CClone_ref::GetTypeInfo_enum_EPlacement_method();
96  if (type_val) {
97  string method = type_val->FindName(clone.GetPlacement_method(), true);
98  if ( !method.empty() ) {
99  tooltip.AddRow("Placement method:", method);
100  }
101  }
102  }
103  if (clone.IsSetConcordant()) {
104  tooltip.AddRow("Clone placement:", clone.GetConcordant() ? "concordant" : "discordant");
105  }
106  if (clone.IsSetUnique()) {
107  tooltip.AddRow("Clone placement:", clone.GetUnique() ? "unique" : "multiple");
108  }
109  if (clone.IsSetClone_seq()) {
110  typedef map<int, vector<string> > TEndMap;
111  TEndMap end_map;
112  TAccessionInfoMap info_map;
113  const CClone_ref::TClone_seq::Tdata& ends = clone.GetClone_seq().Get();
114  ITERATE (CClone_ref::TClone_seq::Tdata, e_iter, ends) {
115  const CClone_seq& seq = **e_iter;
116  if (seq.CanGetSeq() && seq.CanGetSupport()) {
117  const CSeq_id* id = seq.GetSeq().GetId();
118  if (id) {
119  string id_str;
120  CSeq_id_Handle idh;
121  try {
122  idh = sequence::GetId(*id, *m_Scope);
123  }
124  catch(const CException& ) {}
125  if (idh) {
126  CSeq_id_Handle idhb =
128  if( idhb ){
129  idh = idhb;
130  }
131  }
132  if (idh) {
133  CConstRef<CSeq_id> seq_id_ref = idh.GetSeqId();
134  seq_id_ref->GetLabel( &id_str, CSeq_id::eContent );
135  // Identify the accession
136  if (info_map.end() == info_map.find(id_str))
137  x_IdentifyAccession(*seq_id_ref, id_str, info_map);
138  } else {
139  id->GetLabel(&id_str);
140  // Identify the accession
141  if (info_map.end() == info_map.find(id_str))
142  x_IdentifyAccession(*id, id_str, info_map);
143  }
144  if (eAcc_Trace != info_map[id_str]) { // Ignore links to Trace DB
145  end_map[seq.GetSupport()].push_back(id_str);
146  }
147  }
148  }
149  }
150 
151  if (end_map.count(CClone_seq::eSupport_prototype) > 0) {
152  tooltip.AddRow("Prototype:", x_FormatAccessionLinks(tooltip, end_map[CClone_seq::eSupport_prototype], info_map, false), 200, true);
153  }
154 
155  if (end_map.count(CClone_seq::eSupport_supporting) > 0) {
156  tooltip.StartRow();
157  tooltip.AddTagCol("Supporting (" +
159  "):");
160  tooltip.AddValueCol(x_FormatAccessionLinks(tooltip, end_map[CClone_seq::eSupport_supporting], info_map));
161  tooltip.FinishRow();
162  }
163 
164  if (end_map.count(CClone_seq::eSupport_non_supporting) > 0) {
165  tooltip.StartRow();
166  tooltip.AddTagCol("Non-supporting (" +
168  "):");
169  tooltip.AddValueCol(x_FormatAccessionLinks(tooltip, end_map[CClone_seq::eSupport_non_supporting], info_map));
170  tooltip.FinishRow();
171  }
172 
173  if (end_map.count(CClone_seq::eSupport_supports_other) > 0) {
174  tooltip.StartRow();
175  tooltip.AddTagCol("Supports other (" +
177  "):");
178  tooltip.AddValueCol(x_FormatAccessionLinks(tooltip, end_map[CClone_seq::eSupport_supports_other], info_map));
179  tooltip.FinishRow();
180  }
181  }
182 }
183 
184 string CGuiObjectInfoClone::x_FormatAccessionLinks(const ITooltipFormatter& tooltip, const vector<string> &strings, const TAccessionInfoMap &acc_info, bool occurences) const
185 {
186  string out_str;
187  bool first = true;
188  typedef map<string, unsigned> TStrCountMap;
189  TStrCountMap count;
190  ITERATE(vector<string>, itStr, strings) {
191  if (0 == count.count(*itStr))
192  count[*itStr] = 1;
193  else
194  ++count[*itStr];
195  }
196  ITERATE(TStrCountMap, iter, count) {
197  if (first) {
198  first = false;
199  }
200  else {
201  out_str += ',';
202  }
203  string link_name(iter->first);
204  if (occurences) {
205  link_name += '(';
206  link_name += NStr::NumericToString(iter->second);
207  link_name += ')';
208  }
209  TAccessionInfoMap::const_iterator itAccInfo = acc_info.find(iter->first);
210  if (acc_info.end() == itAccInfo) {
211  out_str += link_name;
212  continue;
213  }
214  _ASSERT((unsigned)(itAccInfo->second) < (sizeof(m_BaseURLs) / sizeof(m_BaseURLs[0])));
215  string url(m_BaseURLs[itAccInfo->second]);
216  CTempString accession(itAccInfo->first);
217  if (eAcc_Trace == itAccInfo->second) {
218  NStr::TrimPrefixInPlace(accession, "ti:", NStr::eNocase);
219  }
220  url += accession;
221  out_str += tooltip.CreateNcbiLink(link_name, url);
222  }
223  return out_str;
224 }
225 
226 void CGuiObjectInfoClone::x_IdentifyAccession(const CSeq_id &id, const string &id_str, TAccessionInfoMap &acc_info) const
227 {
228  size_t info = id.IdentifyAccession();
229  if (!(info & CSeq_id::fAcc_nuc))
230  return;
231 
232  switch (info & CSeq_id::eAcc_division_mask) {
233  case CSeq_id::eAcc_gss:
234  acc_info[id_str] = eAcc_GSS;
235  return;
236  case CSeq_id::eAcc_htgs:
237  acc_info[id_str] = eAcc_Nuc;
238  return;
239  default:
240  break;
241  }
242 
243  switch (info & CSeq_id::eAcc_type_mask) {
244  case CSeq_id::e_General: {
245  acc_info[id_str] = eAcc_Trace;
246  return;
247  }
248  case CSeq_id::e_Embl:
249  acc_info[id_str] = eAcc_Nuc;
250  return;
251  default:
252  break;
253  }
254 }
255 
256 void CGuiObjectInfoClone::GetLinks(ITooltipFormatter& links, bool no_ncbi_base) const
257 {
258 }
259 
261 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
CClone_ref –.
Definition: Clone_ref.hpp:66
CClone_seq –.
Definition: Clone_seq.hpp:66
string x_FormatAccessionLinks(const ITooltipFormatter &tooltip, const vector< string > &strings, const TAccessionInfoMap &acc_info, bool occurences=true) const
map< CSeq_id::EAccessionInfo, string > TBaseURLforAccession
void x_IdentifyAccession(const CSeq_id &id, const string &id_str, TAccessionInfoMap &acc_info) const
virtual void GetLinks(ITooltipFormatter &links, bool no_ncbi_base) const
Get a set of links.
virtual void GetToolTip(ITooltipFormatter &tooltip, string &t_title, TSeqPos at_p=(TSeqPos) -1, bool *isGeneratedBySvc=NULL) const
Get tooltip.
map< string, TAccInfo > TAccessionInfoMap
static const string m_BaseURLs[]
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
const string & FindName(TEnumValueType value, bool allowBadValue) const
Find name of the enum by its numeric value.
Definition: enumerated.cpp:146
virtual void FinishRow()=0
finish the row (i.e. no other contents will be added to it)
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
virtual void AddRow(const string &sContents="", unsigned colspan=2)=0
add a row with a cell, spanning across all columns
virtual void AddValueCol(const string &sContents="", unsigned width=200, bool isNoWrap=false)=0
adds a value column to the row
virtual void AddTagCol(const string &sContents="", const string &sBulletSrc="")=0
adds a tag column to the row
CRef< objects::CScope > m_Scope
CConstRef< objects::CSeq_feat > m_Feat
CConstRef< objects::CSeq_loc > m_Location
Mapped location in top sequence coordinate (can be set externally).
virtual void StartRow()=0
start a new table row
virtual string CreateNcbiLink(const string &sText, const string &sUrl) const =0
construct the HTML code for a link from the displayed text label and supplied NCBI URL path
@ eContent
Definition: label.hpp:62
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2039
CConstRef< CSeq_id > GetSeqId(void) const
@ eAcc_htgs
Definition: Seq_id.hpp:262
@ eAcc_type_mask
Definition: Seq_id.hpp:222
@ eAcc_gss
Definition: Seq_id.hpp:249
@ fAcc_nuc
Definition: Seq_id.hpp:226
@ eAcc_division_mask
Definition: Seq_id.hpp:273
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:573
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
static void TrimPrefixInPlace(string &str, const CTempString prefix, ECase use_case=eCase)
Trim prefix from a string (in-place)
Definition: ncbistr.cpp:3238
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
@ fWithCommas
Use commas as thousands separator.
Definition: ncbistr.hpp:254
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
TConcordant GetConcordant(void) const
Get the Concordant member data.
Definition: Clone_ref_.hpp:512
bool IsSetUnique(void) const
OPTIONAL? Check if a value has been assigned to Unique data member.
Definition: Clone_ref_.hpp:537
bool IsSetConcordant(void) const
OPTIONAL? Check if a value has been assigned to Concordant data member.
Definition: Clone_ref_.hpp:487
bool CanGetSeq(void) const
Check if it is safe to call GetSeq method.
Definition: Clone_seq_.hpp:528
list< CRef< CClone_seq > > Tdata
TSupport GetSupport(void) const
Get the Support member data.
Definition: Clone_seq_.hpp:583
bool IsSetPlacement_method(void) const
Check if a value has been assigned to Placement_method data member.
Definition: Clone_ref_.hpp:587
TUnique GetUnique(void) const
Get the Unique member data.
Definition: Clone_ref_.hpp:562
const Tdata & Get(void) const
Get the member data.
const TClone_seq & GetClone_seq(void) const
Get the Clone_seq member data.
Definition: Clone_ref_.hpp:646
TPlacement_method GetPlacement_method(void) const
Get the Placement_method member data.
Definition: Clone_ref_.hpp:606
const TSeq & GetSeq(void) const
Get the Seq member data.
Definition: Clone_seq_.hpp:534
bool CanGetSupport(void) const
Check if it is safe to call GetSupport method.
Definition: Clone_seq_.hpp:570
bool IsSetClone_seq(void) const
Check if a value has been assigned to Clone_seq data member.
Definition: Clone_ref_.hpp:634
@ eSupport_supporting
sequence supports placement
Definition: Clone_seq_.hpp:113
@ eSupport_supports_other
supports a different placement
Definition: Clone_seq_.hpp:114
@ eSupport_prototype
sequence used to place clone
Definition: Clone_seq_.hpp:112
@ eSupport_non_supporting
does not support any placement
Definition: Clone_seq_.hpp:115
@ e_General
for other databases
Definition: Seq_id_.hpp:105
USING_SCOPE(objects)
static MDB_envinfo info
Definition: mdb_load.c:37
range(_Ty, _Ty) -> range< _Ty >
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char *const strings[]
Definition: utf8.c:21
#define _ASSERT
Modified on Thu Nov 30 04:55:57 2023 by modify_doxy.py rev. 669887