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

Go to the SVN repository for this file.

1  /* $Id: clear_keywords.cpp 39538 2017-10-06 14:50:51Z bollin $
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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 #include <sstream>
35 
36 #include <objmgr/scope.hpp>
37 #include <objmgr/feat_ci.hpp>
38 #include <objmgr/seq_entry_ci.hpp>
39 #include <objmgr/seqdesc_ci.hpp>
44 #include <gui/objutils/utils.hpp>
47 
48 #include <wx/button.h>
49 #include <wx/statbox.h>
50 #include <wx/stattext.h>
51 
52 ////@begin XPM images
53 ////@end XPM images
54 
55 
56 
58 
59 
60 
61 IMPLEMENT_DYNAMIC_CLASS( CClearKeywords, wxDialog )
62 
63 
64 /*!
65  * CClearKeywords event table definition
66  */
67 
68 BEGIN_EVENT_TABLE( CClearKeywords, wxDialog )
70 
72 
73 
74 /*!
75  * CClearKeywords constructors
76  */
77 
79 {
80  Init();
81 }
82 
83 CClearKeywords::CClearKeywords( wxWindow* parent, objects::CSeq_entry_Handle seh,
84  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
85  : m_TopSeqEntry(seh)
86 {
87  Init();
88  Create(parent, id, caption, pos, size, style);
89 }
90 
91 
92 /*!
93  * CVectorTrimDlg creator
94  */
95 
96 bool CClearKeywords::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CClearKeywords creation
99  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
100  wxDialog::Create( parent, id, caption, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CClearKeywords creation
109 
110  return true;
111 }
112 
113 
114 /*!
115  * CClearKeywords destructor
116  */
117 
119 {
120 ////@begin CClearKeywords destruction
121 ////@end CClearKeywords destruction
122 }
123 
124 
125 /*!
126  * Member initialisation
127  */
128 
130 {
131 }
132 
133 
134 /*!
135  * Control creation for CClearKeywords
136  */
137 
139 {
140  CClearKeywords* itemDialog1 = this;
141 
142  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
143  itemDialog1->SetSizer(itemBoxSizer2);
144 
145  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
146  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
147 
148  wxStaticText* stattext2 = new wxStaticText( itemDialog1, wxID_STATIC, _("Remove Keyword"), wxDefaultPosition, wxDefaultSize, 0 );
149  itemBoxSizer3->Add(stattext2, 0, wxALIGN_TOP|wxALL, 5);
150  m_Keyword = new wxTextCtrl( itemDialog1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
151  itemBoxSizer3->Add(m_Keyword, 0, wxALIGN_TOP|wxLEFT|wxRIGHT|wxBOTTOM, 5);
152  m_AllKeywords = new wxCheckBox(itemDialog1, wxID_ANY, _("All Keywords"), wxDefaultPosition, wxDefaultSize, 0);
153  itemBoxSizer3->Add(m_AllKeywords, 0, wxALIGN_TOP | wxLEFT | wxRIGHT | wxBOTTOM, 5);
154 
155  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Constraints"));
156  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
157  itemBoxSizer2->Add(itemStaticBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
158 
159  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
160  itemStaticBoxSizer3->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
161 
162  m_Any = new wxRadioButton( itemDialog1, wxID_ANY, _("Any sequence"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
163  m_Any->SetValue(true);
164  itemBoxSizer7->Add(m_Any, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  m_Nuc = new wxRadioButton( itemDialog1, wxID_ANY, _("Nucleotides"), wxDefaultPosition, wxDefaultSize, 0 );
167  m_Nuc->SetValue(false);
168  itemBoxSizer7->Add(m_Nuc, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
169 
170  m_DNA = new wxRadioButton( itemDialog1, wxID_ANY, _("DNA"), wxDefaultPosition, wxDefaultSize, 0 );
171  m_DNA->SetValue(false);
172  itemBoxSizer7->Add(m_DNA, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  m_RNA = new wxRadioButton( itemDialog1, wxID_ANY, _("RNA"), wxDefaultPosition, wxDefaultSize, 0 );
175  m_RNA->SetValue(false);
176  itemBoxSizer7->Add(m_RNA, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
177 
178  m_Proteins = new wxRadioButton( itemDialog1, wxID_ANY, _("Proteins"), wxDefaultPosition, wxDefaultSize, 0 );
179  m_Proteins->SetValue(false);
180  itemBoxSizer7->Add(m_Proteins, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxArrayString choices;
183  set<string> str_choices;
185  {
186  for ( CSeqdesc_CI biosource_it(*entry_it, CSeqdesc::e_Source, 1); biosource_it; ++biosource_it)
187  {
188  if (biosource_it->GetSource().IsSetGenome())
189  {
190  string line = CBioSource::GetOrganelleByGenome(biosource_it->GetSource().GetGenome());
191  str_choices.insert(line);
192  }
193  }
194  }
195  for (set<string>::const_iterator str_it = str_choices.begin(); str_it != str_choices.end(); ++str_it)
196  {
197  choices.Add(wxString(*str_it));
198  }
199 
200  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
201  itemStaticBoxSizer3->Add(itemBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
202 
203  wxStaticText* itemStaticText12 = new wxStaticText( itemDialog1, wxID_STATIC, _("Where source location is "), wxDefaultPosition, wxDefaultSize, 0 );
204  itemBoxSizer9->Add(itemStaticText12, 0, wxALIGN_TOP|wxALL, 5);
205 
206  m_SourceLoc = new wxListBox( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices, wxLB_SINGLE );
207  itemBoxSizer9->Add(m_SourceLoc, 0, wxALIGN_TOP|wxALL, 5);
208 
209  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
210  itemStaticBoxSizer3->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
211 
212  wxStaticText* itemStaticText11 = new wxStaticText( itemDialog1, wxID_STATIC, _("Where Sequence ID"), wxDefaultPosition, wxDefaultSize, 0 );
213  itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_TOP|wxALL, 5);
214 
215  m_StringConstraintPanel = new CStringConstraintPanel( itemDialog1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
216  itemBoxSizer10->Add(m_StringConstraintPanel, 0, wxALIGN_TOP|wxALL|wxFIXED_MINSIZE, 0);
218 
219  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
220  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
221 
222  wxButton* itemButton13 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
223  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
224 
225  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
226  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
227 }
228 
229 
230 
231 /*!
232  * Should we show tooltips?
233  */
234 
236 {
237  return true;
238 }
239 
240 /*!
241  * Get bitmap resources
242  */
243 
244 wxBitmap CClearKeywords::GetBitmapResource( const wxString& name )
245 {
246  // Bitmap retrieval
247  wxUnusedVar(name);
248  return wxNullBitmap;
249 }
250 
251 /*!
252  * Get icon resources
253  */
254 
255 wxIcon CClearKeywords::GetIconResource( const wxString& name )
256 {
257  // Icon retrieval
258  wxUnusedVar(name);
259  return wxNullIcon;
260 }
261 
263 {
264  if (m_Keyword->GetValue().IsEmpty() && !m_AllKeywords->GetValue())
265  return CRef<CCmdComposite>(NULL);
266  CRef<CCmdComposite> cmd( new CCmdComposite("Remove Keyword") );
267  bool pass_genome = true;
268  if (m_SourceLoc->GetSelection() != wxNOT_FOUND)
269  pass_genome = false;
270  ApplyToCSeq_entry(*(m_TopSeqEntry.GetCompleteSeq_entry()), cmd, pass_genome);
271  return cmd;
272 }
273 
274 void CClearKeywords::ApplyToCSeq_entry(const CSeq_entry& se, CCmdComposite* composite, bool pass_genome)
275 {
276 
277  if (!pass_genome)
278  {
279  CBioSource::EGenome organelle = CBioSource::GetGenomeByOrganelle(m_SourceLoc->GetString(m_SourceLoc->GetSelection()).ToStdString());
280 
282  {
283  if ((*it)->IsSource() && (*it)->GetSource().IsSetGenome() && (*it)->GetSource().GetGenome() == organelle)
284  {
285  pass_genome = true;
286  }
287  }
288  }
289 
290  if (se.IsSet()) {
292  ApplyToCSeq_entry (**it, composite, pass_genome);
293  }
294  }
295 
296  if (!pass_genome)
297  return;
298 
299  bool pass = false;
300  if (m_Any->GetValue())
301  pass = true;
302  if (m_Nuc->GetValue() && se.IsSeq() && se.GetSeq().IsNa() )
303  pass = true;
304  if (m_DNA->GetValue() && se.IsSeq() && se.GetSeq().IsSetInst() && se.GetSeq().GetInst().IsSetMol() &&
306  pass = true;
307  if (m_RNA->GetValue() && se.IsSeq() && se.GetSeq().IsSetInst() && se.GetSeq().GetInst().IsSetMol() &&
309  pass = true;
310  if (m_Proteins->GetValue() && se.IsSeq() && se.GetSeq().IsAa() )
311  pass = true;
312 
313  if (!pass)
314  return;
315 
317 
318  if (constraint && se.IsSeq())
319  {
320  pass = false;
322  {
323  string label;
324  (*id)->GetLabel(&label,CSeq_id::eContent);
325  if (constraint->DoesTextMatch(label))
326  pass = true;
327  }
328  if (!pass)
329  return;
330  }
331 
332 
333  string remove = m_Keyword->GetValue().ToStdString();
334  bool remove_all = m_AllKeywords->GetValue();
336  {
337  if ((*it)->IsGenbank())
338  {
339  CRef<CSerialObject> edited_object;
340  edited_object.Reset((CSerialObject*)CGB_block::GetTypeInfo()->Create());
341  edited_object->Assign((*it)->GetGenbank());
342  CGB_block& edited = dynamic_cast<CGB_block&>(*edited_object);
343 
344  EDIT_EACH_KEYWORD_ON_GENBANKBLOCK(keyword, edited)
345  {
346  if (remove_all || *keyword == remove)
347  ERASE_KEYWORD_ON_GENBANKBLOCK(keyword, edited);
348  }
349  if (edited.IsSetKeywords() && edited.GetKeywords().empty())
350  edited.ResetKeywords();
352  CObject* actual = (CObject*) &((*it)->GetGenbank());
353  cmd->Add(actual, CConstRef<CObject>(edited_object));
354  composite->AddCommand(*cmd);
355  }
356  }
357 
358 }
359 
360 
361 void CClearKeywords::OnAllKeywordsSelected(wxCommandEvent& event)
362 {
363  if (m_AllKeywords->GetValue()) {
364  m_Keyword->Enable(false);
365  } else {
366  m_Keyword->Enable(true);
367  }
368 }
369 
370 
371 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
static string GetOrganelleByGenome(unsigned int genome)
Definition: BioSource.cpp:216
static CBioSource::EGenome GetGenomeByOrganelle(const string &organelle, NStr::ECase use_case=NStr::eCase, bool starts_with=false)
Definition: BioSource.cpp:168
bool IsNa(void) const
Definition: Bioseq.cpp:345
bool IsAa(void) const
Definition: Bioseq.cpp:350
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxRadioButton * m_Any
void OnAllKeywordsSelected(wxCommandEvent &event)
CRef< CCmdComposite > GetCommand()
wxListBox * m_SourceLoc
CChangeUnindexedObjectCommand< objects::CGB_block > CChangeGenbankBlockCommand
~CClearKeywords()
Destructor.
static bool ShowToolTips()
Should we show tooltips?
CStringConstraintPanel * m_StringConstraintPanel
wxCheckBox * m_AllKeywords
void CreateControls()
Creates the controls and sizers.
CClearKeywords()
Constructors.
wxRadioButton * m_DNA
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxRadioButton * m_Proteins
wxTextCtrl * m_Keyword
wxRadioButton * m_RNA
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Clear Keywords"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
objects::CSeq_entry_Handle m_TopSeqEntry
void ApplyToCSeq_entry(const CSeq_entry &se, CCmdComposite *composite, bool pass_genome)
wxRadioButton * m_Nuc
void AddCommand(IEditCommand &command)
CObject –.
Definition: ncbiobj.hpp:180
CSeq_entry_CI –.
Definition: Seq_entry.hpp:56
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
Base class for all serializable objects.
Definition: serialbase.hpp:150
void SetStringSelection(const wxString &str)
CRef< edit::CStringConstraint > GetStringConstraint()
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void DLIST_NAME() remove(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:90
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
@ fIncludeGivenEntry
Include the top (given) entry.
@ fRecursive
Iterate recursively.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 const char label[]
void ResetKeywords(void)
Reset Keywords data member.
Definition: GB_block_.cpp:63
const TKeywords & GetKeywords(void) const
Get the Keywords member data.
Definition: GB_block_.hpp:526
bool IsSetKeywords(void) const
Check if a value has been assigned to Keywords data member.
Definition: GB_block_.hpp:514
EGenome
biological context
Definition: BioSource_.hpp:97
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const TInst & GetInst(void) const
Get the Inst member data.
Definition: Bioseq_.hpp:336
bool IsSetMol(void) const
Check if a value has been assigned to Mol data member.
Definition: Seq_inst_.hpp:593
bool IsSetInst(void) const
the sequence data Check if a value has been assigned to Inst data member.
Definition: Bioseq_.hpp:324
TMol GetMol(void) const
Get the Mol member data.
Definition: Seq_inst_.hpp:612
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
#define FOR_EACH_SEQID_ON_BIOSEQ(Itr, Var)
FOR_EACH_SEQID_ON_BIOSEQ EDIT_EACH_SEQID_ON_BIOSEQ.
Definition: seq_macros.hpp:308
#define ERASE_KEYWORD_ON_GENBANKBLOCK(Itr, Var)
ERASE_KEYWORD_ON_GENBANKBLOCK.
#define EDIT_EACH_KEYWORD_ON_GENBANKBLOCK(Itr, Var)
static static static wxID_ANY
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define FOR_EACH_SEQDESC_ON_SEQENTRY(Itr, Var)
FOR_EACH_SEQDESC_ON_SEQENTRY EDIT_EACH_SEQDESC_ON_SEQENTRY.
Modified on Sun May 12 04:58:43 2024 by modify_doxy.py rev. 669887