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

Go to the SVN repository for this file.

1 /* $Id: rnanamepanel.cpp 27547 2013-03-04 15:03:09Z 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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objmgr/bioseq_ci.hpp>
37 
38 ////@begin includes
39 ////@end includes
40 
41 #include <wx/checkbox.h>
44 
45 ////@begin XPM images
46 ////@end XPM images
47 
49 
50 /*!
51  * CRNANamePanel type definition
52  */
53 
54 IMPLEMENT_DYNAMIC_CLASS( CRNANamePanel, CBulkCmdPanel )
55 
56 
57 /*!
58  * CRNANamePanel event table definition
59  */
60 
61 BEGIN_EVENT_TABLE( CRNANamePanel, CBulkCmdPanel )
62 
63 ////@begin CRNANamePanel event table entries
64 ////@end CRNANamePanel event table entries
65  EVT_RADIOBUTTON( wxID_ANY, CRNANamePanel::OnRNATypeSelected )
67 
69 
70 
71 /*!
72  * CRNANamePanel constructors
73  */
74 
76 {
77  Init();
78 }
79 
80 CRNANamePanel::CRNANamePanel( wxWindow* parent, objects::CSeq_entry_Handle seh,
83  bool multi,
84  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
85 : m_TopSeqEntry(seh),
86  m_WizardType (wizard_type),
87  m_SrcType (src_type),
88  m_IsMulti (multi)
89 {
90  Init();
91  Create(parent, id, pos, size, style);
92 }
93 
94 
95 /*!
96  * CRNANamePanel creator
97  */
98 
99 bool CRNANamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
100 {
101 ////@begin CRNANamePanel creation
102  CBulkCmdPanel::Create( parent, id, pos, size, style );
103 
104  CreateControls();
105  if (GetSizer())
106  {
107  GetSizer()->SetSizeHints(this);
108  }
109  Centre();
110 ////@end CRNANamePanel creation
111  return true;
112 }
113 
114 
115 /*!
116  * CRNANamePanel destructor
117  */
118 
120 {
121 ////@begin CRNANamePanel destruction
122 ////@end CRNANamePanel destruction
123 }
124 
125 
126 /*!
127  * Member initialisation
128  */
129 
131 {
132 ////@begin CRNANamePanel member initialisation
134 ////@end CRNANamePanel member initialisation
135 }
136 
137 
138 static string s_RNABacteriaArchaea[] = {
139  "16S ribosomal RNA",
140  "16S-23S ribosomal RNA intergenic spacer",
141  "23S ribosomal RNA"
142 };
143 
144 const int s_NumRNABacteriaArchaea = sizeof (s_RNABacteriaArchaea) / sizeof (string);
145 
146 
147 static string s_RNAOrganelle[] = {
148  "small subunit ribosomal RNA",
149  "large subunit ribosomal RNA"
150 };
151 
152 const int s_NumRNAOrganelle = sizeof (s_RNAOrganelle) / sizeof (string);
153 
154 
155 static string s_RNAFungal[] = {
156  "18S ribosomal RNA",
157  "small subunit ribosomal RNA",
158  "internal transcribed spacer 1",
159  "5.8S ribosomal RNA",
160  "internal transcribed spacer 2",
161  "28S ribosomal RNA",
162  "26S ribosomal RNA",
163  "large subunit ribosomal RNA"
164 };
165 
166 const int s_NumRNAFungal = sizeof (s_RNAFungal) / sizeof (string);
167 
168 
169 /*!
170  * Control creation for CRNANamePanel
171  */
172 
174 {
175 ////@begin CRNANamePanel content construction
176  CRNANamePanel* itemCBulkCmdPanel1 = this;
177 
178  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
179  itemCBulkCmdPanel1->SetSizer(itemBoxSizer2);
180 
181  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemCBulkCmdPanel1, wxID_ANY, _("RNA Name"));
182  m_RNANameSizer = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
183  itemBoxSizer2->Add(m_RNANameSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
184 
185 ////@end CRNANamePanel content construction
186 
187  size_t i = 0;
188  wxRadioButton* btn;
189  wxCheckBox* box;
190 
191  switch (m_SrcType) {
193  for (i = 0; i < s_NumRNABacteriaArchaea; i++) {
194  if (m_IsMulti) {
195  box = new wxCheckBox ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNABacteriaArchaea[i]));
196  m_RNANameSizer->Add (box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
197  } else {
198  btn = new wxRadioButton ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNABacteriaArchaea[i]));
199  m_RNANameSizer->Add (btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
200  }
201  }
202  break;
206  for (i = 0; i < s_NumRNAFungal; i++) {
207  if (m_IsMulti) {
208  box = new wxCheckBox ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNAFungal[i]));
209  m_RNANameSizer->Add (box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
210  } else {
211  btn = new wxRadioButton ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNAFungal[i]));
212  m_RNANameSizer->Add (btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
213  }
214  }
215  break;
216  default:
217  for (i = 0; i < s_NumRNABacteriaArchaea; i++) {
218  if (m_IsMulti) {
219  box = new wxCheckBox ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNABacteriaArchaea[i]));
220  m_RNANameSizer->Add (box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
221  } else {
222  btn = new wxRadioButton ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNABacteriaArchaea[i]));
223  m_RNANameSizer->Add (btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
224  }
225  }
226  for (i = 0; i < s_NumRNAFungal; i++) {
227  if (m_IsMulti) {
228  box = new wxCheckBox ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNAFungal[i]));
229  m_RNANameSizer->Add (box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
230  } else {
231  btn = new wxRadioButton ( itemCBulkCmdPanel1, wxID_ANY, ToWxString (s_RNAFungal[i]));
232  m_RNANameSizer->Add (btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
233  }
234  }
235  break;
236  }
237  bool enable = true;
238  if (i > 0) {
239  if (m_IsMulti) {
240  box = new wxCheckBox ( itemCBulkCmdPanel1, wxID_ANY, _("Something else"));
241  m_RNANameSizer->Add (box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
242  } else {
243  btn = new wxRadioButton ( itemCBulkCmdPanel1, wxID_ANY, _("Something else"));
244  m_RNANameSizer->Add (btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
245  }
246  enable = false;
247  }
248 
249  m_OtherLabel = new wxTextCtrl( itemCBulkCmdPanel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1), 0 );
250  m_RNANameSizer->Add(m_OtherLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
251  m_OtherLabel->Enable(enable);
252 
253 }
254 
255 
256 /*!
257  * Should we show tooltips?
258  */
259 
261 {
262  return true;
263 }
264 
265 /*!
266  * Get bitmap resources
267  */
268 
269 wxBitmap CRNANamePanel::GetBitmapResource( const wxString& name )
270 {
271  // Bitmap retrieval
272 ////@begin CRNANamePanel bitmap retrieval
273  wxUnusedVar(name);
274  return wxNullBitmap;
275 ////@end CRNANamePanel bitmap retrieval
276 }
277 
278 /*!
279  * Get icon resources
280  */
281 
282 wxIcon CRNANamePanel::GetIconResource( const wxString& name )
283 {
284  // Icon retrieval
285 ////@begin CRNANamePanel icon retrieval
286  wxUnusedVar(name);
287  return wxNullIcon;
288 ////@end CRNANamePanel icon retrieval
289 }
290 
291 
292 static bool s_IsrRNA (string rna_name)
293 {
294  bool rval = false;
295 
296  if (NStr::IsBlank(rna_name)) {
297  rval = false;
298  } else if ((NStr::StartsWith(rna_name, "large ") || NStr::StartsWith(rna_name, "small "))
299  && NStr::Equal(rna_name.substr(5), " subunit ribosomal RNA")) {
300  rval = true;
301  } else {
302  string::iterator cp = rna_name.begin();
303  size_t pos = 0;
304  if (isdigit (*cp)) {
305  cp++;
306  pos++;
307  while (cp != rna_name.end() && isdigit (*cp)) {
308  cp++;
309  pos++;
310  }
311  if (NStr::Equal(rna_name.substr(pos), "S ribosomal RNA")) {
312  rval = true;
313  }
314  }
315  }
316  return rval;
317 }
318 
319 
320 static bool s_IsRNASpacer (string rna_name)
321 {
322  bool rval = false;
323 
324  if (NStr::IsBlank(rna_name)) {
325  rval = false;
326  } else {
327  string::iterator cp = rna_name.begin();
328  size_t pos = 0;
329  if (isdigit (*cp)) {
330  cp++;
331  pos++;
332  while (cp != rna_name.end() && isdigit (*cp)) {
333  cp++;
334  pos++;
335  }
336  if (NStr::Equal(rna_name.substr(pos, 2), "S-")) {
337  cp++;
338  cp++;
339  pos +=2;
340  if (isdigit (*cp)) {
341  cp++;
342  pos++;
343  while (cp != rna_name.end() && isdigit (*cp)) {
344  cp++;
345  pos++;
346  }
347  if (NStr::Equal(rna_name.substr(pos), "S ribosomal RNA intergenic spacer")) {
348  rval = true;
349  }
350  }
351  }
352  }
353  }
354  return rval;
355 }
356 
357 
359 {
360  string rna_name = "";
361  wxSizerItemList& itemList = m_RNANameSizer->GetChildren();
362  size_t pos = 0;
363  vector<string> labels;
364  labels.clear();
365  while (pos < itemList.size()) {
366  wxCheckBox* c_btn = dynamic_cast<wxCheckBox*>(itemList[pos]->GetWindow());
367  if (c_btn) {
368  if (c_btn->GetValue()) {
369  string label = ToStdString(c_btn->GetLabel());
370  if (NStr::Equal(label, "Something else")) {
371  label = ToStdString(m_OtherLabel->GetValue());
372  }
373  labels.push_back(label);
374  }
375  }
376  pos++;
377  }
378  if (labels.size() == 1) {
379  rna_name = labels[0];
380  } else if (labels.size() == 2) {
381  rna_name = "contains " + labels[0] + " and " + labels[1];
382  } else if (labels.size() > 2) {
383  rna_name = "contains ";
384  for (size_t i = 0; i < labels.size() - 1; i++) {
385  rna_name += labels[i] + ", ";
386  }
387  rna_name += "and " + labels[labels.size() - 1];
388  }
389  return rna_name;
390 }
391 
392 
394 {
395  string rna_name = "";
396  wxSizerItemList& itemList = m_RNANameSizer->GetChildren();
397  size_t pos = 0;
398  while (pos < itemList.size()) {
399  wxRadioButton* r_btn = dynamic_cast<wxRadioButton*>(itemList[pos]->GetWindow());
400  if (r_btn) {
401  if (r_btn->GetValue()) {
402  string label = ToStdString(r_btn->GetLabel());
403  if (NStr::Equal(label, "Something else")) {
404  rna_name = ToStdString(m_OtherLabel->GetValue());
405  } else {
406  rna_name = label;
407  }
408  }
409  }
410  pos++;
411  }
412  return rna_name;
413 }
414 
415 
417 {
418  string rna_name = "";
419  if (m_IsMulti) {
420  rna_name = x_GetMultiElementName();
421  } else {
422  rna_name = x_GetSingleElementName();
423  }
424 
425  if (NStr::IsBlank(rna_name)) {
427  return empty;
428  }
429 
430  bool is_rRNA = s_IsrRNA(rna_name);
431  bool is_RNASpacer = s_IsRNASpacer (rna_name);
432 
433  CRef<CCmdComposite> cmd (new CCmdComposite("Bulk Add RNA Features"));
434 
435  objects::CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na);
436  for ( ; b_iter ; ++b_iter ) {
437  CRef<objects::CSeq_feat> new_feat(new objects::CSeq_feat());
438  if (is_rRNA) {
439  new_feat->SetData().SetRna().SetType(objects::CRNA_ref::eType_rRNA);
440  new_feat->SetData().SetRna().SetExt().SetName(rna_name);
441  } else {
442  new_feat->SetData().SetRna().SetType(objects::CRNA_ref::eType_other);
443  if (is_RNASpacer) {
444  new_feat->SetData().SetRna().SetExt().SetGen().SetProduct(rna_name);
445  } else {
446  new_feat->SetComment(rna_name);
447  }
448  }
449  if (!AlreadyHasFeature(*b_iter, new_feat->GetData().GetSubtype())) {
450  CRef<objects::CSeq_id> new_feat_id(new objects::CSeq_id());
451  new_feat_id->Assign(*(b_iter->GetCompleteBioseq()->GetId().front()));
452  new_feat->SetLocation().SetInt().SetId(*new_feat_id);
453  new_feat->SetLocation().SetInt().SetFrom(0);
454  new_feat->SetLocation().SetInt().SetTo(b_iter->GetBioseqLength() - 1);
455  new_feat->SetLocation().SetPartialStart(true, objects::eExtreme_Biological);
456  new_feat->SetLocation().SetPartialStop(true, objects::eExtreme_Biological);
457  objects::CSeq_entry_Handle seh = b_iter->GetSeq_entry_Handle();
458  cmd->AddCommand(*CRef<CCmdCreateFeat>(new CCmdCreateFeat(seh, *new_feat)));
459  }
460  }
461  return cmd;
462 }
463 
464 
466 {
467  return "You must specify the name for the RNA feature to be created.";
468 }
469 
470 
471 void CRNANamePanel::OnRNATypeSelected( wxCommandEvent& event )
472 {
473  bool enable = false;
474 
475  wxSizerItemList& itemList = m_RNANameSizer->GetChildren();
476  size_t pos = 0;
477  while (pos < itemList.size() && !enable) {
478  wxRadioButton* r_btn = dynamic_cast<wxRadioButton*>(itemList[pos]->GetWindow());
479  if (r_btn) {
480  if (r_btn->GetValue() && NStr::Equal(ToStdString(r_btn->GetLabel()), "Something else")) {
481  enable = true;
482  }
483  } else {
484  wxCheckBox* c_btn = dynamic_cast<wxCheckBox*>(itemList[pos]->GetWindow());
485  if (c_btn) {
486  if (c_btn->GetValue() && NStr::Equal(ToStdString(c_btn->GetLabel()), "Something else")) {
487  enable = true;
488  }
489  }
490  }
491  pos++;
492  }
493  m_OtherLabel->Enable(enable);
494 }
495 
496 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
User-defined methods of the data storage class.
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
objects::CSeq_entry_Handle m_TopSeqEntry
string x_GetSingleElementName()
string x_GetMultiElementName()
~CRNANamePanel()
Destructor.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual CRef< CCmdComposite > GetCommand()
virtual string GetErrorMessage()
static bool ShowToolTips()
Should we show tooltips?
void CreateControls()
Creates the controls and sizers.
CSourceRequirements::EWizardSrcType m_SrcType
bool Create(wxWindow *parent, wxWindowID id=10034, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void OnRNATypeSelected(wxCommandEvent &event)
wxStaticBoxSizer * m_RNANameSizer
void Init()
Initialises member variables.
CRNANamePanel()
Constructors.
wxTextCtrl * m_OtherLabel
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#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 StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
static const char label[]
END_EVENT_TABLE()
int i
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
int isdigit(Uchar c)
Definition: ncbictype.hpp:64
const int s_NumRNAOrganelle
static bool s_IsrRNA(string rna_name)
static bool s_IsRNASpacer(string rna_name)
const int s_NumRNABacteriaArchaea
static string s_RNABacteriaArchaea[]
static string s_RNAOrganelle[]
const int s_NumRNAFungal
static string s_RNAFungal[]
static static static wxID_ANY
bool AlreadyHasFeature(objects::CBioseq_Handle bh, string key, string comment)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat Jun 29 13:56:54 2024 by modify_doxy.py rev. 669887