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

Go to the SVN repository for this file.

1 /* $Id: generic_props_panel.cpp 42778 2019-04-11 16:12:41Z filippov $
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: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 #include <gui/objutils/utils.hpp>
36 #include <objmgr/util/sequence.hpp>
38 
39 ////@begin includes
40 ////@end includes
41 
44 
45 #include "generic_props_panel.hpp"
46 #include "gene_panel.hpp"
48 
49 #include <wx/sizer.h>
50 #include <wx/stattext.h>
51 #include <wx/textctrl.h>
52 #include <wx/choice.h>
53 #include <wx/bitmap.h>
54 #include <wx/icon.h>
55 #include <wx/treebook.h>
56 #include <wx/msgdlg.h>
57 
60 
61 ////@begin XPM images
62 ////@end XPM images
63 
64 
65 /*!
66  * CGenericPropsPanel type definition
67  */
68 
69 IMPLEMENT_DYNAMIC_CLASS( CGenericPropsPanel, wxPanel )
70 
71 
72 /*!
73  * CGenericPropsPanel event table definition
74  */
75 
76 BEGIN_EVENT_TABLE( CGenericPropsPanel, wxPanel )
77 
78 ////@begin CGenericPropsPanel event table entries
79  EVT_COMBOBOX( ID_EXPLANATION, CGenericPropsPanel::OnExplanationSelected )
80  EVT_TEXT( ID_EXPLANATION, CGenericPropsPanel::OnExplanationUpdated )
81  EVT_CHOICE(ID_PSEUDOGENE_CHOICE, CGenericPropsPanel::OnPseudoChanged)
82 ////@end CGenericPropsPanel event table entries
83 
85 
86 
87 /*!
88  * CGenericPropsPanel constructors
89  */
90 
92 {
93  Init();
94 }
95 
96 CGenericPropsPanel::CGenericPropsPanel( wxWindow* parent, CObject& object, CScope& scope,
97  wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
98  m_Object(0), m_Scope(&scope)
99 {
100  m_Object = dynamic_cast<CSeq_feat*>(&object);
101  Init();
102  Create(parent, id, pos, size, style);
103 }
104 
105 
106 /*!
107  * CGenePropsPanel creator
108  */
109 
110 bool CGenericPropsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
111 {
112 ////@begin CGenericPropsPanel creation
113  wxPanel::Create( parent, id, pos, size, style );
114 
115  CreateControls();
116  if (GetSizer())
117  {
118  GetSizer()->SetSizeHints(this);
119  }
120  Centre();
121 ////@end CGenericPropsPanel creation
122  return true;
123 }
124 
125 
126 /*!
127  * CGenericPropsPanel destructor
128  */
129 
131 {
132 ////@begin CGenericPropsPanel destruction
133 ////@end CGenericPropsPanel destruction
134 }
135 
136 
137 /*!
138  * Member initialisation
139  */
140 
142 {
143 ////@begin CGenericPropsPanel member initialisation
146  m_Evidence = NULL;
147  m_Partial = NULL;
148 ////@end CGenericPropsPanel member initialisation
149 }
150 
151 
152 static const string kPseudogene = "pseudogene";
153 
154 /*!
155  * Control creation for CGenePropsPanel
156  */
157 
159 {
160 ////@begin CGenericPropsPanel content construction
161  CGenericPropsPanel* itemPanel1 = this;
162 
163  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
164  itemPanel1->SetSizer(itemBoxSizer2);
165 
166  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
167  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxALL, 5);
168 
169  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Pseudogene"), wxDefaultPosition, wxDefaultSize, 0 );
170  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  wxArrayString m_PseudogeneChoiceStrings;
173  m_PseudogeneChoice = new wxChoice( itemPanel1, ID_PSEUDOGENE_CHOICE, wxDefaultPosition, wxDefaultSize, m_PseudogeneChoiceStrings, 0 );
174  itemBoxSizer3->Add(m_PseudogeneChoice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
175 
176  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
177  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_LEFT|wxALL, 0);
178 
179  wxStaticText* itemStaticText7 = new wxStaticText( itemPanel1, wxID_STATIC, _("Exception"), wxDefaultPosition, wxDefaultSize, 0 );
180  itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxArrayString m_ExplanationStrings;
183  m_Explanation = new wxComboBox( itemPanel1, ID_EXPLANATION, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ExplanationStrings, wxCB_DROPDOWN );
184  itemBoxSizer6->Add(m_Explanation, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
187  itemBoxSizer2->Add(itemBoxSizer9, 0, wxALIGN_LEFT|wxALL, 0);
188 
189  wxArrayString m_EvidenceStrings;
190  m_EvidenceStrings.Add(_("N/A"));
191  m_EvidenceStrings.Add(_("Experimental"));
192  m_EvidenceStrings.Add(_("Non-Experimental"));
193  m_Evidence = new wxRadioBox( itemPanel1, ID_RADIOBOX3, _("Evidence"), wxDefaultPosition, wxDefaultSize, m_EvidenceStrings, 1, wxRA_SPECIFY_ROWS );
194  m_Evidence->SetSelection(0);
196  m_Evidence->SetToolTip(_("The use of the Evidence field is discouraged - if you wish to list experimental evidence, please use the Experiments tab. If you wish to describe how similar sequences, alignments, or gene prediction software were used to infer the presence of the feature, please use the Inferences tab."));
197  itemBoxSizer9->Add(m_Evidence, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
198 
199  m_Partial = new wxCheckBox( itemPanel1, ID_RADIOBOX2, _("Partial"), wxDefaultPosition, wxDefaultSize, 0 );
200  m_Partial->SetValue(false);
201  m_Partial->Enable(false);
202  itemBoxSizer2->Add(m_Partial, 0, wxALIGN_LEFT|wxALL, 5);
203 
204  // Set validators
205  m_Evidence->SetValidator( CSerialEnumValidator(*m_Object, "exp-ev") );
206 ////@end CGenericPropsPanel content construction
207 
208  m_ExplanationStrings.clear();
209  vector<string> explanation_strings = CSeq_feat::GetListOfLegalExceptions(x_IsRefSeq());
210  for (vector<string>::const_iterator s = explanation_strings.begin(); s != explanation_strings.end(); ++s)
211  m_ExplanationStrings.Add(wxString(*s));
212  m_Explanation->Append(m_ExplanationStrings);
213 
214  CSeq_feat& feat = dynamic_cast<CSeq_feat&>(*m_Object);
215  if (feat.IsSetPartial() && feat.GetPartial()) {
216  m_Partial->SetValue (true);
217  unsigned int partial_loc = sequence::SeqLocPartialCheck(feat.GetLocation(), m_Scope );
218  if (!( partial_loc & sequence::eSeqlocPartial_Start )
219  && !( partial_loc & sequence::eSeqlocPartial_Stop )
220  && !( partial_loc & sequence::eSeqlocPartial_Internal )
221  && !( partial_loc & sequence::eSeqlocPartial_Other )
222  && !( partial_loc & sequence::eSeqlocPartial_Nostart )
223  && !( partial_loc & sequence::eSeqlocPartial_Nostop )
224  && !( partial_loc & sequence::eSeqlocPartial_Nointernal)) {
225  m_Partial->Enable(true);
226  }
227  }
228 
229  string pseudo_choice = "";
230  if (sequence::IsPseudo(feat, *m_Scope)) {
231  pseudo_choice = "Unqualified";
232  }
233 
234  if (feat.IsSetQual()) {
235  ITERATE(CSeq_feat::TQual, it, feat.GetQual()) {
236  if ((*it)->IsSetQual()
237  && NStr::EqualNocase((*it)->GetQual(), kPseudogene)
238  && (*it)->IsSetVal()) {
239  pseudo_choice = (*it)->GetVal();
240  }
241  }
242  }
243  // add blank, to allow user to remove pseudogene value
244  m_PseudogeneChoice->Append(wxT(""));
245  auto pseudogene_values = CGb_qual::GetSetOfLegalPseudogenes();
246  for (auto it : pseudogene_values) {
247  m_PseudogeneChoice->Append(ToWxString(it));
248  }
249  // add unqualified, to allow the gene.pseudo = true option
250  m_PseudogeneChoice->Append(wxT("unqualified"));
251 
252  if (NStr::IsBlank(pseudo_choice)) {
253  if (!(x_IsGene() || x_IsCds())) {
254  m_PseudogeneChoice->Enable(false);
255  }
256  } else {
257  if (!m_PseudogeneChoice->SetStringSelection(ToWxString(pseudo_choice))) {
258  bool found = false;
259  for (auto it : pseudogene_values) {
260  if (NStr::EqualNocase(it, pseudo_choice)) {
261  m_PseudogeneChoice->SetStringSelection(ToWxString(it));
262  found = true;
263  break;
264  }
265  }
266  if (!found) {
267  m_PseudogeneChoice->Append(ToWxString(pseudo_choice));
268  m_PseudogeneChoice->SetStringSelection(ToWxString(pseudo_choice));
269  }
270  }
271  }
272 
273  m_OriginalPseudoSelection = m_PseudogeneChoice->GetStringSelection();
274 
275  if (feat.IsSetExcept_text()) {
276  m_Explanation->SetValue (ToWxString(feat.GetExcept_text()));
277  }
278  if (!feat.IsSetExp_ev()) {
279  m_Evidence->Enable(false);
280  }
281 }
282 
284 {
285  return (m_OriginalPseudoSelection != m_PseudogeneChoice->GetStringSelection() && !x_IsGene());
286 }
287 
289 {
290  if (!wxPanel::TransferDataFromWindow()) {
291  return false;
292  }
293  CSeq_feat& feat = dynamic_cast<CSeq_feat&>(*m_Object);
294  if (m_Partial->IsEnabled() && m_Partial->GetValue()) {
295  feat.SetPartial(true);
296  } else {
297  feat.ResetPartial();
298  }
299 
300 
301  ModifyPseudo(feat, GetPseudoChoice());
302 
303  string exception_text = ToStdString(m_Explanation->GetValue());
304  if (NStr::IsBlank(exception_text)) {
305  feat.ResetExcept();
306  feat.ResetExcept_text();
307  } else {
308  feat.SetExcept(true);
309  feat.SetExcept_text(exception_text);
310  }
311  return true;
312 }
313 
315 {
316  string pseudo_choice = ToStdString(m_PseudogeneChoice->GetStringSelection());
317  NStr::ToLower(pseudo_choice);
318  return pseudo_choice;
319 }
320 
321 void CGenericPropsPanel::ModifyPseudo(CSeq_feat &feat, const string &pseudo_choice)
322 {
323  if (feat.IsSetQual()) {
324  CSeq_feat::TQual::iterator it = feat.SetQual().begin();
325  while (it != feat.SetQual().end()) {
326  if ((*it)->IsSetQual() && NStr::EqualNocase((*it)->GetQual(), kPseudogene)) {
327  it = feat.SetQual().erase(it);
328  } else {
329  ++it;
330  }
331  }
332  if (feat.SetQual().empty()) {
333  feat.ResetQual();
334  }
335  }
336  if (!NStr::IsBlank(pseudo_choice)) {
337  if (pseudo_choice != "unqualified")
338  {
339  CRef<CGb_qual> qual(new CGb_qual(kPseudogene, pseudo_choice));
340  feat.SetQual().push_back(qual);
341  }
342  feat.SetPseudo(true);
343  } else {
344  feat.ResetPseudo();
345  }
346 }
347 
349 {
350  string pseudo_choice = ToStdString(m_PseudogeneChoice->GetStringSelection());
351  NStr::ToLower(pseudo_choice);
352  return !NStr::IsBlank(pseudo_choice);
353 }
354 
356 {
357  if (m_PseudogeneChoice && m_PseudogeneChoice->IsEnabled())
358  {
359  m_PseudogeneChoice->SetStringSelection(wxEmptyString);
361  }
362 }
363 
364 /*!
365  * Should we show tooltips?
366  */
367 
369 {
370  return true;
371 }
372 
373 /*!
374  * Get bitmap resources
375  */
376 
377 wxBitmap CGenericPropsPanel::GetBitmapResource( const wxString& name )
378 {
379  // Bitmap retrieval
380 ////@begin CGenericPropsPanel bitmap retrieval
381  wxUnusedVar(name);
382  return wxNullBitmap;
383 ////@end CGenericPropsPanel bitmap retrieval
384 }
385 
386 /*!
387  * Get icon resources
388  */
389 
390 wxIcon CGenericPropsPanel::GetIconResource( const wxString& name )
391 {
392  // Icon retrieval
393 ////@begin CGenericPropsPanel icon retrieval
394  wxUnusedVar(name);
395  return wxNullIcon;
396 ////@end CGenericPropsPanel icon retrieval
397 }
398 
399 
401 {
402  bool rval = false;
403  wxWindow* parent = this->GetParent();
404  wxTreebook* tbook = dynamic_cast<wxTreebook*>(parent);
405  if (tbook) {
406  CGenePanel* genePanel = 0;
407  for (size_t i = 0; i < tbook->GetPageCount() && !genePanel; ++i) {
408  genePanel = dynamic_cast<CGenePanel*>(tbook->GetPage(i));
409  }
410  if (genePanel) {
411  rval = true;
412  }
413  }
414  return rval;
415 }
416 
418 {
419  CSeq_feat& feat = dynamic_cast<CSeq_feat&>(*m_Object);
420  if (feat.IsSetData() && feat.GetData().IsCdregion())
421  return true;
422  return false;
423 }
424 
426 {
427  bool refseq = false;
428  CSeq_feat& feat = dynamic_cast<CSeq_feat&>(*m_Object);
430  if (bsh && bsh.IsSetId())
431  {
432  for (CBioseq_Handle::TId::const_iterator idh = bsh.GetId().begin(); idh != bsh.GetId().end(); ++idh)
433  {
434  CConstRef<CSeq_id> id = idh->GetSeqId();
435  if (id->IsOther())
436  {
437  refseq = true;
438  break;
439  }
440  }
441  }
442  return refseq;
443 }
444 
445 /*!
446  * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_EXPLANATION
447  */
448 
450 {
451  wxWindow* w = this->GetParent();
452  while (w != NULL) {
453  wxTreebook* parent = dynamic_cast<wxTreebook*>(w);
454  if (parent) {
455  return parent;
456  } else {
457  w = w->GetParent();
458  }
459  }
460  return NULL;
461 }
462 
463 
464 void CGenericPropsPanel::OnExplanationSelected( wxCommandEvent& event )
465 {
467 }
468 
470 {
471  // need to enable/disable RetranslateOnOk based on selection
472  wxTreebook* parent = x_GetTree();
473 
474  CCDSTranslationPanel* translation_panel = 0;
475  for (size_t i = 0; i < parent->GetPageCount(); ++i) {
476  translation_panel = dynamic_cast<CCDSTranslationPanel*>(parent->GetPage(i));
477  if (translation_panel)
478  break;
479  }
480  if (translation_panel) {
481  bool valid_exception = CCDSTranslationPanel::IsValidException(ToStdString(m_Explanation->GetValue()));
482  bool is_pseudo = IsPseudo();
483  translation_panel->DisableRetranslateOnOk(valid_exception, is_pseudo);
484  translation_panel->UpdateForceNear();
485  }
486 }
487 
488 
489 /*!
490  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_EXPLANATION
491  */
492 
493 void CGenericPropsPanel::OnExplanationUpdated( wxCommandEvent& event )
494 {
496 }
497 
498 void CGenericPropsPanel::OnPseudoChanged( wxCommandEvent& event )
499 {
501 }
502 
static CRef< CScope > m_Scope
CBioseq_Handle –.
static bool IsValidException(const string &text)
void DisableRetranslateOnOk(bool exception, bool pseudo)
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
static const TLegalPseudogeneSet & GetSetOfLegalPseudogenes(void)
Definition: Gb_qual.cpp:285
void Init()
Initialises member variables.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CGenericPropsPanel()
Constructors.
bool Create(wxWindow *parent, wxWindowID id=ID_CGENEPROPSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
bool PseudoSelectionChanged() const
void OnExplanationSelected(wxCommandEvent &event)
wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_EXPLANATION
void OnExplanationUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_EXPLANATION
static void ModifyPseudo(objects::CSeq_feat &feat, const string &pseudo_choice)
objects::CScope * m_Scope
objects::CSeq_feat * m_Object
static bool ShowToolTips()
Should we show tooltips?
~CGenericPropsPanel()
Destructor.
void OnPseudoChanged(wxCommandEvent &event)
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
static vector< string > GetListOfLegalExceptions(bool include_refseq)
Produces the list of legal exceptions.
Definition: Seq_feat.cpp:526
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
USING_SCOPE(objects)
static const string kPseudogene
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
objects::CBioseq_Handle GetBioseqForSeqFeat(const objects::CSeq_feat &f, objects::CScope &scope)
int SeqLocPartialCheck(const CSeq_loc &loc, CScope *scope)
@ eSeqlocPartial_Nostart
@ eSeqlocPartial_Nostop
@ eSeqlocPartial_Internal
@ eSeqlocPartial_Nointernal
@ eSeqlocPartial_Other
@ eSeqlocPartial_Stop
@ eSeqlocPartial_Start
bool IsPseudo(const CSeq_feat &feat, CScope &scope)
Determines whether given feature is pseudo, using gene associated with feature if necessary Checks to...
Definition: sequence.cpp:1428
bool IsSetId(void) const
const TId & GetId(void) const
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5347
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
void ResetPartial(void)
Reset Partial data member.
Definition: Seq_feat_.hpp:955
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
bool IsSetQual(void) const
qualifiers Check if a value has been assigned to Qual data member.
Definition: Seq_feat_.hpp:1135
bool IsCdregion(void) const
Check if variant Cdregion is selected.
void ResetExcept(void)
Reset Except data member.
Definition: Seq_feat_.hpp:1002
void SetPartial(TPartial value)
Assign a value to Partial data member.
Definition: Seq_feat_.hpp:971
const TQual & GetQual(void) const
Get the Qual member data.
Definition: Seq_feat_.hpp:1147
bool IsSetPartial(void) const
incomplete in some way? Check if a value has been assigned to Partial data member.
Definition: Seq_feat_.hpp:943
void ResetExcept_text(void)
Reset Except_text data member.
Definition: Seq_feat_.cpp:194
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
void SetExcept(TExcept value)
Assign a value to Except data member.
Definition: Seq_feat_.hpp:1018
void ResetPseudo(void)
Reset Pseudo data member.
Definition: Seq_feat_.hpp:1358
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TExcept_text & GetExcept_text(void) const
Get the Except_text member data.
Definition: Seq_feat_.hpp:1405
bool IsSetExcept_text(void) const
explain if except=TRUE Check if a value has been assigned to Except_text data member.
Definition: Seq_feat_.hpp:1393
bool IsSetExp_ev(void) const
Check if a value has been assigned to Exp_ev data member.
Definition: Seq_feat_.hpp:1249
void SetPseudo(TPseudo value)
Assign a value to Pseudo data member.
Definition: Seq_feat_.hpp:1374
TPartial GetPartial(void) const
Get the Partial member data.
Definition: Seq_feat_.hpp:962
void SetExcept_text(const TExcept_text &value)
Assign a value to Except_text data member.
Definition: Seq_feat_.hpp:1414
vector< CRef< CGb_qual > > TQual
Definition: Seq_feat_.hpp:117
TQual & SetQual(void)
Assign a value to Qual data member.
Definition: Seq_feat_.hpp:1153
void ResetQual(void)
Reset Qual data member.
Definition: Seq_feat_.cpp:136
bool IsOther(void) const
Check if variant Other is selected.
Definition: Seq_id_.hpp:871
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:57:04 2024 by modify_doxy.py rev. 669887