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

Go to the SVN repository for this file.

1 /* $Id: apply_rna_its_dlg.cpp 42666 2019-04-01 14:27:25Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objmgr/scope.hpp>
32 #include <objmgr/align_ci.hpp>
33 #include <objmgr/bioseq_ci.hpp>
47 #include <util/static_map.hpp>
48 
49 #include <wx/textctrl.h>
50 #include <wx/arrstr.h>
51 #include <wx/sizer.h>
52 #include <wx/radiobox.h>
53 #include <wx/checkbox.h>
54 #include <wx/choice.h>
55 #include <wx/msgdlg.h>
56 #include <wx/valgen.h>
57 #include <wx/button.h>
58 #include <wx/event.h>
59 
62 
64 static const TITSLabelPair s_Rna_ITSStrings[] = {
66  {"18S rRNA", CApplyRNAITSDlg::eRNA_ITS_18S},
67  {"18S small subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_18S_small},
68  {"25S large subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_25S_large},
69  {"25S rRNA", CApplyRNAITSDlg::eRNA_ITS_25S},
70  {"26S large subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_26S_large},
71  {"26S rRNA", CApplyRNAITSDlg::eRNA_ITS_26S},
72  {"28S large subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_28S_large},
73  {"28S rRNA", CApplyRNAITSDlg::eRNA_ITS_28S},
74  {"5.8S rRNA", CApplyRNAITSDlg::eRNA_ITS_58S},
77  {"large subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_large},
78  {"small subunit rRNA", CApplyRNAITSDlg::eRNA_ITS_small},
79 };
80 
83 
84 const string& CApplyRNAITSDlg::GetRNA_ITSName( ERNA_ITSType field_type )
85 {
86  TITSMap::const_iterator iter = sm_ITSMap.begin();
87  for (; iter != sm_ITSMap.end(); ++iter){
88  if (iter->second == field_type){
89  return iter->first;
90  }
91  }
92  return kEmptyStr;
93 }
94 
96 {
97  TITSMap::const_iterator iter = sm_ITSMap.find(label);
98  if (iter != sm_ITSMap.end()){
99  return iter->second;
100  }
102 }
103 
105 static const TIGSLabelPair s_Rna_IGSStrings[] = {
107  {"16S rRNA", CApplyRNAITSDlg::eRNA_IGS_16S},
108  {"16S-23S rRNA IGS", CApplyRNAITSDlg::eRNA_IGS_16S_23S_Igs},
109  {"23S rRNA", CApplyRNAITSDlg::eRNA_IGS_23S},
110 };
111 
114 
116 {
117  TIGSMap::const_iterator iter = sm_IGSMap.begin();
118  for (; iter != sm_IGSMap.end(); ++iter){
119  if (iter->second == field_type){
120  return iter->first;
121  }
122  }
123  return kEmptyStr;
124 }
125 
127 {
128  TIGSMap::const_iterator iter = sm_IGSMap.find(label);
129  if (iter != sm_IGSMap.end()){
130  return iter->second;
131  }
133 }
134 
135 IMPLEMENT_DYNAMIC_CLASS( CApplyRNAITSDlg, CBulkCmdDlg )
136 
137 BEGIN_EVENT_TABLE( CApplyRNAITSDlg, CBulkCmdDlg )
144  EVT_BUTTON( ID_APPLY, CApplyRNAITSDlg::OnGoClick )
146  EVT_CLOSE ( CApplyRNAITSDlg::OnCloseWindow )
148 
150 {
151  Init();
152 }
153 
155  wxWindowID id, const wxString& caption, const wxPoint& pos,
156  const wxSize& size, long style )
157 : CBulkCmdDlg(wb)
158 {
159  Init();
160  Create(parent, id, caption, pos, size, style);
162 }
163 
164 bool CApplyRNAITSDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
165 {
166 ////@begin CApplyRNAITSDlg creation
167  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
168  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
169 
170  CreateControls();
171  if (GetSizer())
172  {
173  GetSizer()->SetSizeHints(this);
174  }
175  Centre();
176 ////@end CApplyRNAITSDlg creation
177  return true;
178 }
179 
181 {
182 }
183 
185 {
186  SetRegistryPath("CApplyRNAITSDlg");
187  m_5partial = NULL;
188  m_3partial = NULL;
191  m_LeaveUp = NULL;
192  m_Choice = 0;
193  m_Alnmap = 0;
194  m_PropSeqids.clear();
195  LoadSettings();
196 }
197 
199 {
200 ////@begin CApplyRNAITSDlg content construction
201  CApplyRNAITSDlg* itemCBulkCmdDlg1 = this;
202 
203  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
204  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
205 
206  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
207  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 3);
208 
209  m_5partial = new wxCheckBox( itemCBulkCmdDlg1, ID_CHECKBOX7, _("5' Partial"), wxDefaultPosition, wxDefaultSize, 0 );
210  m_5partial->SetValue(true);
211  itemBoxSizer3->Add(m_5partial, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
212 
213  itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
214 
215  m_3partial = new wxCheckBox( itemCBulkCmdDlg1, ID_CHECKBOX8, _("3' Partial"), wxDefaultPosition, wxDefaultSize, 0 );
216  m_3partial->SetValue(true);
217  itemBoxSizer3->Add(m_3partial, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
218 
219  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
220  itemBoxSizer2->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
221 
222  // if there are alignments, allow the user to specify alignment coordinates
224  if (x_IsThereAlignment()){
225  m_AlignCoords = new wxCheckBox( itemCBulkCmdDlg1, ID_CHECKBOX9, _("Use alignment coordinates"), wxDefaultPosition, wxDefaultSize, 0 );
226  m_AlignCoords->SetValue(false);
227  itemBoxSizer7->Add(m_AlignCoords, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
228  x_SetupAlnMgr();
229  }
230 
231  wxArrayString m_ITSRadioboxStrings;
232  m_ITSRadioboxStrings.Add(_("&ITS"));
233  m_ITSRadioboxStrings.Add(_("&IGS"));
234  m_ITSRadiobox = new wxRadioBox( itemCBulkCmdDlg1, ID_RADIOBOX_ITS_IGS, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ITSRadioboxStrings, 1, wxRA_SPECIFY_ROWS );
235  m_ITSRadiobox->SetSelection(0);
236  itemBoxSizer7->Add(m_ITSRadiobox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 2);
237 
238  wxArrayString itemChoiceStrings;
239  if (!m_Choice){ // ITS is selected
240  x_Set_ITSArray (itemChoiceStrings);
241  }else{ // IGS is selected
242  x_Set_IGSArray (itemChoiceStrings);
243  }
244 
245  wxFlexGridSizer* itemFlexGridSizer10 = new wxFlexGridSizer(5, 3, -1, -1);
246  itemBoxSizer2->Add(itemFlexGridSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
247 
248  struct SRNAITSChoice first_choice;
249  first_choice.rnaType = new wxChoice( itemCBulkCmdDlg1, ID_CHOICE_FIRST, wxDefaultPosition, wxDefaultSize, itemChoiceStrings, 0 );
250  itemFlexGridSizer10->Add(first_choice.rnaType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
251 
252  first_choice.from = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FFROM, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
253  itemFlexGridSizer10->Add(first_choice.from, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
254 
255  first_choice.to = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FTO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
256  itemFlexGridSizer10->Add(first_choice.to, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
257 
258  struct SRNAITSChoice second_choice;
259  second_choice.rnaType = new wxChoice( itemCBulkCmdDlg1, ID_CHOICE_SECOND, wxDefaultPosition, wxDefaultSize, itemChoiceStrings, 0 );
260  itemFlexGridSizer10->Add(second_choice.rnaType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
261 
262  second_choice.from = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_SFROM, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
263  itemFlexGridSizer10->Add(second_choice.from, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
264 
265  second_choice.to = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_STO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
266  itemFlexGridSizer10->Add(second_choice.to, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
267 
268  struct SRNAITSChoice third_choice;
269  third_choice.rnaType = new wxChoice( itemCBulkCmdDlg1, ID_CHOICE_THIRD, wxDefaultPosition, wxDefaultSize, itemChoiceStrings, 0 );
270  itemFlexGridSizer10->Add(third_choice.rnaType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
271 
272  third_choice.from = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_TFROM, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
273  itemFlexGridSizer10->Add(third_choice.from, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
274 
275  third_choice.to = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_TTO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
276  itemFlexGridSizer10->Add(third_choice.to, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
277 
278  struct SRNAITSChoice fourth_choice;
279  fourth_choice.rnaType = new wxChoice( itemCBulkCmdDlg1, ID_CHOICE_FOURTH, wxDefaultPosition, wxDefaultSize, itemChoiceStrings, 0 );
280  itemFlexGridSizer10->Add(fourth_choice.rnaType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
281 
282  fourth_choice.from = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FOFROM, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
283  itemFlexGridSizer10->Add(fourth_choice.from, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
284 
285  fourth_choice.to = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FOTO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
286  itemFlexGridSizer10->Add(fourth_choice.to, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
287 
288  struct SRNAITSChoice fifth_choice;
289  fifth_choice.rnaType = new wxChoice( itemCBulkCmdDlg1, ID_CHOICE_FIFTH, wxDefaultPosition, wxDefaultSize, itemChoiceStrings, 0 );
290  itemFlexGridSizer10->Add(fifth_choice.rnaType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
291 
292  fifth_choice.from = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FIFROM, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
293  itemFlexGridSizer10->Add(fifth_choice.from, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
294 
295  fifth_choice.to = new wxTextCtrl( itemCBulkCmdDlg1, ID_TEXTCTRL_FITO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
296  itemFlexGridSizer10->Add(fifth_choice.to, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 2);
297 
298  wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxHORIZONTAL);
299  itemBoxSizer2->Add(itemBoxSizer28, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
300 
301  m_OK = new wxButton( itemCBulkCmdDlg1, ID_APPLY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
302  itemBoxSizer28->Add(m_OK, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
303 
304  m_Cancel = new wxButton( itemCBulkCmdDlg1, ID_CLOSEBTN, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
305  itemBoxSizer28->Add(m_Cancel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
306 
307  m_LeaveUp = new wxCheckBox( itemCBulkCmdDlg1, ID_LEAVE_DIALOG_UP, _("Leave Dialog Up"), wxDefaultPosition, wxDefaultSize, 0 );
308  m_LeaveUp->SetValue(false);
309  itemBoxSizer28->Add(m_LeaveUp, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
310 
311 ////@end CApplyRNAITSDlg content construction
312 
313  // connect events and objects
314  first_choice.from->Connect(ID_TEXTCTRL_FFROM, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlFromKillFocus), NULL, this);
315  first_choice.to->Connect(ID_TEXTCTRL_FTO, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlToKillFocus), NULL, this);
316  m_ChoiceList.push_back(first_choice);
317 
318  second_choice.from->Connect(ID_TEXTCTRL_SFROM, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlFromKillFocus), NULL, this);
319  second_choice.to->Connect(ID_TEXTCTRL_STO, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlToKillFocus), NULL, this);
320  m_ChoiceList.push_back(second_choice);
321 
322  third_choice.from->Connect(ID_TEXTCTRL_TFROM, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlFromKillFocus), NULL, this);
323  third_choice.to->Connect(ID_TEXTCTRL_TTO, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlToKillFocus), NULL, this);
324  m_ChoiceList.push_back(third_choice);
325 
326  fourth_choice.from->Connect(ID_TEXTCTRL_FOFROM, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlFromKillFocus), NULL, this);
327  fourth_choice.to->Connect(ID_TEXTCTRL_FOTO, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlToKillFocus), NULL, this);
328  m_ChoiceList.push_back(fourth_choice);
329 
330  fifth_choice.from->Connect(ID_TEXTCTRL_FIFROM, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlFromKillFocus), NULL, this);
331  fifth_choice.to->Connect(ID_TEXTCTRL_FITO, wxEVT_KILL_FOCUS, wxFocusEventHandler(CApplyRNAITSDlg::OnCtrlToKillFocus), NULL, this);
332  m_ChoiceList.push_back(fifth_choice);
333 
334  for (size_t n= 0; n < m_ChoiceList.size(); n++) {
336  }
337 
338  m_ITSRadiobox->SetValidator( wxGenericValidator(&m_Choice));
339 
340  wxWindow::InitDialog(); // uncomment this row, if the frame is changed to dialog
341 }
342 
344 {
345  if (m_TopSeqEntry) {
346  CAlign_CI align_it(m_TopSeqEntry);
347  if (align_it) {
348  const CSeq_align& align = align_it.GetOriginalSeq_align();
349  if (align.IsSetSegs() && align.GetSegs().IsDenseg()) {
350  return true;
351  }
352  }
353  }
354  return false;
355 }
356 
358 {
359  m_Alnmap.Reset();
360  if (m_TopSeqEntry) {
361  CAlign_CI align_iter(m_TopSeqEntry);
362  /* the seqentry should have at most one alignment*/
363  if (align_iter) {
364  const CSeq_align& align = align_iter.GetOriginalSeq_align();
365  if (align.IsSetSegs() && align.GetSegs().IsDenseg()) {
366  m_Alnmap.Reset(new CAlnMap(align.GetSegs().GetDenseg()));
367  }
368  }
369  }
370 }
371 
372 void CApplyRNAITSDlg::x_Set_ITSArray ( wxArrayString& Its_tags )
373 {
388 }
389 
390 void CApplyRNAITSDlg::x_Set_IGSArray ( wxArrayString& Igs_tags )
391 {
392  TIGSMap::const_iterator iter = sm_IGSMap.begin();
393  for (; iter != sm_IGSMap.end(); ++iter){
394  Igs_tags.Add( ToWxString(iter->first) );
395  }
396 }
397 
399 {
400  TVecConstSeqFeat cfeatlist;
401 
402  // set the first feature to partial
403  TVecSeqFeat::iterator feat_it = featlist.begin();
404  if (m_5partial->GetValue()) {
405  (*feat_it)->SetLocation().SetPartialStart(true, eExtreme_Biological);
406  (*feat_it)->SetPartial(true);
407  }
408  // set the last feature to partial
409  if (m_3partial->GetValue()) {
410  feat_it = featlist.end() - 1;
411  (*feat_it)->SetLocation().SetPartialStop(true, eExtreme_Biological);
412  (*feat_it)->SetPartial(true);
413  }
414 
415  ITERATE (TVecSeqFeat, iter, featlist) {
416  cfeatlist.push_back(CConstRef<CSeq_feat>(&(**iter)));
417  }
418  return cfeatlist;
419 }
420 
421 static const char* kApplyChoice = "ApplyRNA_ITS";
422 
423 void CApplyRNAITSDlg::SetRegistryPath(const string& reg_path)
424 {
425  m_RegPath = reg_path;
426 }
427 
429 {
430  if (! m_RegPath.empty()) {
432  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
433  view.Set(kApplyChoice, m_Choice);
434  }
435 }
436 
438 {
439  if (! m_RegPath.empty()) {
441  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
443  }
444 }
445 
446 void CApplyRNAITSDlg::OnGoClick ( wxCommandEvent& event )
447 {
449  if (cmd) {
451  if (!m_LeaveUp->GetValue()) {
452  Close();
453  }
454  } else {
455  string error = GetErrorMessage();
456  if (!NStr::IsBlank(error)) {
457  wxMessageBox(ToWxString(error), wxT("Error"), wxOK | wxICON_ERROR, NULL);
458  }
459  }
460 }
461 
462 void CApplyRNAITSDlg::OnCancelClick ( wxCommandEvent& event )
463 {
465 }
466 
467 void CApplyRNAITSDlg::OnCloseWindow ( wxCloseEvent& event )
468 {
470 }
471 
473 {
474  wxWindow::TransferDataFromWindow(); // uncomment this row, if the frame is changed to dialog
475  SaveSettings();
476  Destroy();
477 }
478 
479 /*!
480  * Should we show tooltips?
481  */
482 
484 {
485  return true;
486 }
487 
488 /*!
489  * Get bitmap resources
490  */
491 
492 wxBitmap CApplyRNAITSDlg::GetBitmapResource( const wxString& name )
493 {
494  // Bitmap retrieval
495 ////@begin CApplyRNAITSDlg bitmap retrieval
496  wxUnusedVar(name);
497  return wxNullBitmap;
498 ////@end CApplyRNAITSDlg bitmap retrieval
499 }
500 
501 /*!
502  * Get icon resources
503  */
504 
505 wxIcon CApplyRNAITSDlg::GetIconResource( const wxString& name )
506 {
507  // Icon retrieval
508 ////@begin CApplyRNAITSDlg icon retrieval
509  wxUnusedVar(name);
510  return wxNullIcon;
511 ////@end CApplyRNAITSDlg icon retrieval
512 }
513 
514 void CApplyRNAITSDlg::OnFirstChoiceSelected( wxCommandEvent& event )
515 {
516  string value = ToStdString(m_ChoiceList[0].rnaType->GetStringSelection());
517 
518  if (! m_ITSRadiobox->GetSelection()){ // ITS is selected
520  if (selected == CApplyRNAITSDlg::eRNA_ITS_unknown){
521  m_ChoiceList[0].from->ChangeValue(wxEmptyString);
522  m_ChoiceList[0].to->ChangeValue(wxEmptyString);
524  }else{
525  m_ChoiceList[0].from->ChangeValue(_("1"));
526  m_ChoiceList[0].from->SetModified(false);
528  }
529  for (size_t n=1; n<m_ChoiceList.size(); n++){
530  selected = GetNextRNA_ITSChoice(selected);
531  m_ChoiceList[n].rnaType->SetStringSelection(ToWxString(GetRNA_ITSName(selected)));
532 
533  if (selected == CApplyRNAITSDlg::eRNA_ITS_unknown){
534  m_ChoiceList[n].from->ChangeValue(wxEmptyString);
535  m_ChoiceList[n].to->ChangeValue(wxEmptyString);
537  }else{
539  }
540  }
541 
542  } else { // IGS is selected
544  if (selected == CApplyRNAITSDlg::eRNA_IGS_unknown){
545  m_ChoiceList[0].from->ChangeValue(wxEmptyString);
546  m_ChoiceList[0].to->ChangeValue(wxEmptyString);
548  }else{
549  m_ChoiceList[0].from->ChangeValue(_("1"));
551  }
552  for (size_t n = 1; n < m_ChoiceList.size(); ++n){
553  selected = GetNextRNA_IGSChoice(selected);
554  m_ChoiceList[n].rnaType->SetStringSelection(ToWxString(GetRNA_IGSName(selected)));
555 
556  if (selected == CApplyRNAITSDlg::eRNA_IGS_unknown){
557  m_ChoiceList[n].from->ChangeValue(wxEmptyString);
558  m_ChoiceList[n].to->ChangeValue(wxEmptyString);
560  }else{
562  }
563  }
564  } // the first choice is the 'driving field': if that gets empty, everything will become empty
565 }
566 
567 void CApplyRNAITSDlg::OnAnyOtherChoiceSelected ( wxCommandEvent& event )
568 {
569  unsigned int event_id = 1;
570 
571  switch (event.GetId()) {
572  case ID_CHOICE_SECOND:
573  break;
574  case ID_CHOICE_THIRD:
575  event_id++;
576  break;
577  case ID_CHOICE_FOURTH:
578  event_id = event_id + 2;
579  break;
580  case ID_CHOICE_FIFTH:
581  event_id = event_id + 3;
582  break;
583  }
584  string value = ToStdString(m_ChoiceList[event_id].rnaType->GetStringSelection());
585 
586  if (! m_ITSRadiobox->GetSelection()){ // ITS is selected
588  if (selected == CApplyRNAITSDlg::eRNA_ITS_unknown) {
589  for (SIZE_TYPE n = event_id; n < m_ChoiceList.size(); ++n) {
591  m_ChoiceList[n].from->ChangeValue(wxEmptyString);
592  m_ChoiceList[n].to->ChangeValue(wxEmptyString);
594  }
595  } else {
597  }
598  } else { // IGS is selected
600  if (selected == CApplyRNAITSDlg::eRNA_IGS_unknown){
601  for (SIZE_TYPE n = event_id; n < m_ChoiceList.size(); ++n) {
603  m_ChoiceList[n].from->ChangeValue(wxEmptyString);
604  m_ChoiceList[n].to->ChangeValue(wxEmptyString);
606  }
607  } else {
609  }
610  }
611 }
612 
613 
614 /* if the 'FROM' field was set to n in row i, the 'TO' field becomes n-1 in row i-1 */
615 void CApplyRNAITSDlg::OnCtrlFromKillFocus( wxFocusEvent& event )
616 {
617  event.Skip();
618  unsigned int row_sel = 0; // the updated row
619  while (row_sel < m_ChoiceList.size() && !m_ChoiceList[row_sel].from->IsModified())
620  row_sel++;
621 
622  if (row_sel == m_ChoiceList.size()) return;
623  if (m_ChoiceList[row_sel].isEmpty == CApplyRNAITSDlg::eChoice_empty){
624  m_ChoiceList[row_sel].from->ChangeValue(wxEmptyString);
625  } else if (m_ChoiceList[row_sel].from->GetLineLength(0) > 0){
626  string from_value = ToStdString(m_ChoiceList[row_sel].from->GetValue());
627  if (from_value.find_first_not_of("0123456789") != NPOS){
628  m_ChoiceList[row_sel].from->ChangeValue(_("1"));
629  } else {
630  try{
631  int from = NStr::StringToInt(from_value); // selected "FROM" position in 'row_sel' row
632  if (from > 1 && row_sel >= 1){
633  m_ChoiceList[row_sel - 1].to->ChangeValue(wxString(NStr::NumericToString(from-1)));
634  }
635 
636  if (from <= 0){
637  from = 1;
638  m_ChoiceList[row_sel].from->ChangeValue(wxString(NStr::NumericToString(from)));
639  }
640  } catch (const CException& e) {
641  LOG_POST(Error << "CApplyRNAITSDlg::OnCtrlFromKillFocus: " << e.GetMsg());
642  m_ChoiceList[row_sel].from->SetModified(false);
643  return;
644  }
645  }
646  }
647  m_ChoiceList[row_sel].from->SetModified(false);
648 }
649 
650 /* if the 'TO' field was set to n in row i, the 'FROM' field becomes n+1 in row i+1 */
651 void CApplyRNAITSDlg::OnCtrlToKillFocus( wxFocusEvent& event )
652 {
653  event.Skip();
654  unsigned int row_sel = 0; // the updated row
655 
656  while (row_sel < m_ChoiceList.size() && !m_ChoiceList[row_sel].to->IsModified())
657  row_sel++;
658 
659  if (row_sel == m_ChoiceList.size()) return;
660  if (m_ChoiceList[row_sel].isEmpty == CApplyRNAITSDlg::eChoice_empty){
661  m_ChoiceList[row_sel].to->ChangeValue(wxEmptyString);
662  } else if (m_ChoiceList[row_sel].to->GetLineLength(0) > 0 && m_ChoiceList[row_sel].from->GetLineLength(0) > 0) {
663  string from_value = ToStdString(m_ChoiceList[row_sel].from->GetValue());
664  string to_value = ToStdString(m_ChoiceList[row_sel].to->GetValue());
665  if ((from_value.find_first_not_of("0123456789") != NPOS) || (to_value.find_first_not_of("0123456789") != NPOS)){
666  m_ChoiceList[row_sel].to->ChangeValue(_("1"));
667  } else {
668  try {
669  int to = NStr::StringToInt(to_value); // "TO" position in 'row_sel' row
670  int from = NStr::StringToInt(from_value); // "FROM" position in 'row_sel' row
671  if (to <= from){
672  to = from + 1;
673  m_ChoiceList[row_sel].to->ChangeValue(wxString(NStr::NumericToString(to)));
674  }
675  if (row_sel < m_ChoiceList.size() - 1 &&
676  m_ChoiceList[row_sel +1].isEmpty != CApplyRNAITSDlg::eChoice_empty){
677  m_ChoiceList[row_sel + 1].from->ChangeValue(wxString(NStr::NumericToString(to + 1)));
678  }
679  }
680  catch (const CException& e) {
681  LOG_POST(Error << "CApplyRNAITSDlg::OnCtrlToKillFocus: " << e.GetMsg());
682  m_ChoiceList[row_sel].to->SetModified(false);
683  return;
684  }
685  }
686  }
687  m_ChoiceList[row_sel].to->SetModified(false);
688 }
689 
690 void CApplyRNAITSDlg::OnITSRadioBoxSelected( wxCommandEvent& event )
691 {
692  m_Choice = m_ITSRadiobox->GetSelection();
693 
694  wxArrayString labels;
695  if (!m_Choice){ // ITS selected
696  x_Set_ITSArray (labels);
697  }else{ // IGS selected
698  x_Set_IGSArray (labels);
699  }
700 
701  for (size_t n=0; n < m_ChoiceList.size(); n++){
702  m_ChoiceList[n].rnaType->Clear();
703  m_ChoiceList[n].rnaType->Append(labels);
704  m_ChoiceList[n].from->Clear();
705  m_ChoiceList[n].to->Clear();
706  }
707 }
708 
709 
711 {
713  switch(field_type){
715  next_choice = CApplyRNAITSDlg::eRNA_ITS_Its1;
716  break;
718  next_choice = CApplyRNAITSDlg::eRNA_ITS_Its1;
719  break;
721  next_choice = CApplyRNAITSDlg::eRNA_ITS_Its1;
722  break;
724  next_choice = CApplyRNAITSDlg::eRNA_ITS_58S;
725  break;
727  next_choice = CApplyRNAITSDlg::eRNA_ITS_Its2;
728  break;
730  next_choice = CApplyRNAITSDlg::eRNA_ITS_28S;
731  CApplyRNAITSDlg::ERNA_ITSType first_selected =
732  GetRNA_ITSTypeFromName( ToStdString(m_ChoiceList[0].rnaType->GetStringSelection()) );
733  if ( first_selected == CApplyRNAITSDlg::eRNA_ITS_small){
734  next_choice = CApplyRNAITSDlg::eRNA_ITS_large;
735  } else if (first_selected == CApplyRNAITSDlg::eRNA_ITS_18S_small){
737  }
738  break;
739  }
740  default:
741  next_choice = CApplyRNAITSDlg::eRNA_ITS_unknown;
742  break;
743  }
744 
745  return next_choice;
746 }
747 
749 {
751  switch (field_type){
754  break;
756  next_choice = CApplyRNAITSDlg::eRNA_IGS_23S;
757  break;
758  default:
759  next_choice = CApplyRNAITSDlg::eRNA_IGS_unknown;
760  break;
761  }
762 
763  return next_choice;
764 }
765 
767 {
768  return m_ErrorMessage;
769 }
770 
772 {
775 
776  bool align_present = false;
777  if (x_IsThereAlignment()){
778  align_present = true;
779  x_SetupAlnMgr();
780  }
782  m_PropSeqids.clear();
783  if (!m_TopSeqEntry) {
784  m_ErrorMessage = "Unknown error";
785  return empty;
786  }
787 
789  if (objects.empty()) {
790  m_ErrorMessage = "No sequences were selected!";
791  return empty;
792  }
793  // check whether all selected objects belong to the same scope:
794  CRef<CScope> sel_scope(NULL);
796  if (!sel_scope) {
797  sel_scope = it->scope;
798  } else if (sel_scope != it->scope) {
799  m_ErrorMessage = "Selected objects are from different projets.\nPlease move all objects to the same project and try again.";
800  return empty;
801  }
802  }
803 
804  CRef<CCmdComposite> composite(new CCmdComposite("Apply rRNA and ITS"));
805  bool modified = false;
806  bool create_general_only = objects::edit::IsGeneralIdProtPresent(m_TopSeqEntry);
807  if (objects.size() == 1) {
808  const CObject* ptr = objects.begin()->object.GetPointer();
809 
810  const CSeq_entry* seqentry = dynamic_cast<const CSeq_entry* >(ptr);
811  const CSeq_submit* seqsubmit = dynamic_cast<const CSeq_submit* >(ptr);
812  if (seqentry || (seqsubmit && seqsubmit->IsEntrys())) {
813  Apply_RNAITS_ToTSE(composite, modified);
814  }
816  const CObject* ptr = objects.back().object.GetPointer();
817 
818  const CSeq_entry* seqentry = dynamic_cast<const CSeq_entry* >(ptr);
819  const CSeq_submit* seqsubmit = dynamic_cast<const CSeq_submit* >(ptr);
820  if (seqentry || (seqsubmit && seqsubmit->IsEntrys())) {
821  Apply_RNAITS_ToTSE(composite, modified);
822  }
823  } else {
825  const CObject* ptr = it->object.GetPointer();
826 
827  const CSeq_loc* seqloc = dynamic_cast<const CSeq_loc*>(ptr);
828  const CBioseq* bioseq = dynamic_cast<const CBioseq* >(ptr);
829  const CBioseq_set* bioseq_set = dynamic_cast<const CBioseq_set* >(ptr);
830 
831  if (seqloc && seqloc->IsWhole()) {
832  CRef<CSeq_id> seqid(new CSeq_id());
833  seqid->Assign(seqloc->GetWhole());
834  CBioseq_Handle bsh = m_TopSeqEntry.GetScope().GetBioseqHandle(*seqid);
835  if (bsh.IsNa()) { // skip the amino acid sequences
836  if ( ! align_present || (align_present && ! x_WasPropagatedTo(bsh)) ) {
837  Apply_RNAITS_ToBioseq(bsh, composite, modified, create_general_only);
838  }
839  } else if (bsh.IsAa()){
840  m_ErrorMessage = "Selected sequence is a protein.";
841  break;
842  }
843  } else if (bioseq) {
844  if (bioseq->IsNa()) {
845  CBioseq_Handle bsh = m_TopSeqEntry.GetScope().GetBioseqHandle(*bioseq, CScope::eMissing_Null);
846  if ( ! align_present || (align_present && ! x_WasPropagatedTo(bsh)) ) {
847  Apply_RNAITS_ToBioseq(bsh, composite, modified, create_general_only);
848  }
849  } else if (bioseq->IsAa()){
850  m_ErrorMessage = "Selected sequence is a protein.";
851  break;
852  }
853  } else if (bioseq_set) {
854  CBioseq_set_Handle bssh = m_TopSeqEntry.GetScope().GetBioseq_setHandle(*bioseq_set, CScope::eMissing_Null);
855  CSeq_entry_Handle seh = bssh.GetParentEntry();
856  Apply_RNAITS_ToBioseqSet(seh, composite, modified);
857  }
858  }
859  }
860 
861  if (modified) {
862  return composite;
863  }
864  return empty;
865 }
866 
867 /* create features (featlist) on the bioseq */
868 void CApplyRNAITSDlg::AddFeatures (const CBioseq_Handle& bsh, TVecConstSeqFeat& featlist, CRef<CCmdComposite> composite, bool& modified)
869 {
870  if ( ! featlist.empty()) {
872  TVecConstSeqFeat::iterator feat_it = featlist.begin();
873  for ( ; feat_it != featlist.end(); ++feat_it) {
874  composite->AddCommand(*CRef<CCmdCreateFeat>(new CCmdCreateFeat(seh, (*feat_it).GetObject())));
875  modified = true;
876  }
877  }
878 }
879 
881 {
882  if (m_AlignCoords && m_AlignCoords->GetValue()) { // alignment coordinates have been entered
884  } else { // sequence coordinates have been entered
885  return GetRNAITSList_SeqCoordFromDlg(bsh);
886  }
887 }
888 
889 
890 void CApplyRNAITSDlg::Apply_RNAITS_ToBioseq( const CBioseq_Handle& bsh, CRef<CCmdComposite> composite, bool& modified, bool create_general_only )
891 {
892  if ( ! bsh ) return;
893  SIZE_TYPE align_nr= x_BioseqInAlignments(bsh);
894  if (align_nr > 1) {
895  m_ErrorMessage = "Cannot proceed. This bioseq belongs to more than one alignment.";
896  return;
897  } else if (align_nr == 1) { // bioseq belongs to exactly one alignment
898  int answer = wxMessageBox (ToWxString("Propagate to other sequences?"), ToWxString("Question"),
899  wxYES_NO | wxCANCEL | wxICON_QUESTION);
900  switch (answer) {
901  case wxYES: {
902  /* apply the features to this sequence and propagate them to other sequences as well,
903  but to those only, that are in alignment with this particular sequence */
904  TVecConstSeqFeat featlist = ObtainRNAITSList(bsh);
905  AddFeatures(bsh, featlist, composite, modified);
906  Propagate_RNAITSList(bsh, featlist, composite, modified, create_general_only);
907  break;
908  }
909  case wxNO: {
910  TVecConstSeqFeat featlist = ObtainRNAITSList(bsh);
911  AddFeatures(bsh, featlist, composite, modified);
912  break;
913  }
914  case wxCANCEL:
915  break;
916  }
917  } else { // the sequence does not belong to any alignment
918  if (m_AlignCoords && m_AlignCoords->GetValue()) {
919  m_ErrorMessage = "This sequence is not in the alignment!";
920  return;
921  } else {
922  /* enter when viewing one sequence, without alignment */
924  AddFeatures(bsh, featlist, composite, modified);
925  }
926  }
927 }
928 
930 {
931  /* apply the feature list to all nt sequences within the set */
932  if ( !entry || entry.IsSeq() ) return;
933  CBioseq_CI b_iter(entry, CSeq_inst::eMol_na);
934  for ( ; b_iter; ++b_iter) {
935  TVecConstSeqFeat featlist = ObtainRNAITSList(*b_iter);
936  AddFeatures(*b_iter, featlist, composite, modified);
937  }
938 }
939 
941 {
942  if ( ! m_TopSeqEntry) return;
943  int answer = wxMessageBox (ToWxString("You are not viewing a single Bioseq. Apply to all Bioseqs?"),
944  ToWxString("Question"), wxYES_NO | wxCANCEL | wxICON_QUESTION);
945  switch (answer) {
946  case wxYES: {
948  for ( ; b_iter; ++b_iter) {
949  TVecConstSeqFeat featlist = ObtainRNAITSList(*b_iter);
950  AddFeatures(*b_iter, featlist, composite, modified);
951  }
952  break;
953  }
954  case wxNO: {
955  /* apply only to the first nt sequence in TSE and do not give the option of propagation */
957  if (b_iter) {
958  TVecConstSeqFeat featlist = ObtainRNAITSList(*b_iter);
959  AddFeatures(*b_iter, featlist, composite, modified);
960  }
961  break;
962  }
963  case wxCANCEL:
964  break;
965  }
966 }
967 
968 void CApplyRNAITSDlg::Propagate_RNAITSList( const CBioseq_Handle& bsh, TVecConstSeqFeat& featlist, CRef<CCmdComposite> composite, bool& modified, bool create_general_only )
969 {
970  if ( ! featlist.empty()) {
971  CConstRef<CSeq_id> seq_id = bsh.GetSeqId();
972  vector<CConstRef<CSeq_align> > alignments = x_GetAlignments(bsh);
973  if (alignments.size() == 1) {
974  // find the target sequence IDs:
975  const CSeq_align& align = *(alignments[0]);
976  TVecConstSeqId targetIDs = x_SeqIdsAlignedWith(bsh, align);
977 
978  CMessageListener_Basic listener;
979  ITERATE (TVecConstSeqId, target_id, targetIDs) {
980  const CSeq_id& tgseq_id = (*target_id).GetObject();
981  CBioseq_Handle target_bsh = m_TopSeqEntry.GetScope().GetBioseqHandle(tgseq_id);
982  PropagateToTarget(composite, featlist, bsh, target_bsh, align,
983  false, false, true, true, create_general_only, &listener);
984  modified = true;
985  }
986  if (listener.Count() > 0) {
987  string msg = "";
988  for (size_t i = 0; i < listener.Count(); i++) {
989  msg += listener.GetMessage(i).GetText() + "\n";
990  }
991  wxMessageBox(ToWxString(msg), wxT("Error"),
992  wxOK | wxICON_ERROR, NULL);
993  }
994 
995  }
996  }
997 }
998 
999 vector<CConstRef<CSeq_align> > CApplyRNAITSDlg::x_GetAlignments( const CBioseq_Handle& bsh )
1000 {
1001  vector<CConstRef<CSeq_align> > alignments;
1002 
1003  if (m_TopSeqEntry) {
1004  CAlign_CI align_it(m_TopSeqEntry);
1005  for ( ; align_it; ++align_it) {
1006  const CSeq_align& align = align_it.GetOriginalSeq_align();
1007 
1008  /* proceed only if the alignment is of dense-seg type*/
1009  if (align.IsSetSegs() && align.GetSegs().IsDenseg() && align.GetSegs().GetDenseg().IsSetIds()) {
1010  CDense_seg_Base::TIds alignIDs = align.GetSegs().GetDenseg().GetIds();
1011  ITERATE (CDense_seg_Base::TIds, align_id, alignIDs) {
1012  CBioseq::TId bseqIDs = bsh.GetCompleteBioseq()->GetId();
1013  ITERATE (CBioseq::TId, bseq_id, bseqIDs) {
1014  if ((*align_id)->Match(**bseq_id)) {
1015  alignments.push_back(CConstRef<CSeq_align>(&align));
1016  }
1017  }
1018  }
1019  }
1020  }
1021  }
1022 
1023  return alignments;
1024 }
1025 
1027 {
1028  vector<CConstRef<CSeq_align> > alignments = x_GetAlignments(bsh);
1029  return alignments.size();
1030 }
1031 
1033 {
1034  TVecConstSeqId seqids;
1035 
1036  if (m_TopSeqEntry) {
1037  CDense_seg::TIds alignIDs = align.GetSegs().GetDenseg().GetIds();
1038  ITERATE (CDense_seg::TIds, align_id, alignIDs) {
1039  CBioseq::TId bseqIDs = bsh.GetCompleteBioseq()->GetId();
1040  bool found = false;
1041  for (CBioseq::TId::const_iterator bseq_id = bseqIDs.begin(); bseq_id != bseqIDs.end() && !found; ++bseq_id) {
1042  if ((*align_id)->Match(**bseq_id)) {
1043  found = true;
1044  }
1045  }
1046  if ( !found) {
1047  seqids.push_back(CConstRef<CSeq_id>(&(**align_id)));
1048  m_PropSeqids.push_back(CConstRef<CSeq_id>(&(**align_id)));
1049  }
1050  }
1051  }
1052  return seqids;
1053 }
1054 
1056 {
1057  CBioseq::TId bseqIDs = bsh.GetCompleteBioseq()->GetId();
1058  ITERATE (CBioseq::TId, bseq_id, bseqIDs) {
1060  const CSeq_id& prop_id = (*iter).GetObject();
1061  if ((*bseq_id)->Match(prop_id)) {
1062  return true;
1063  }
1064  }
1065  }
1066  return false;
1067 }
1068 
1070 {
1071  if (m_Alnmap) {
1072  CBioseq::TId ids = bioseq.GetId();
1073  ITERATE (CBioseq::TId, id, ids) {
1074  for (IAlnExplorer::TNumrow row = 0; row < m_Alnmap->GetNumRows(); ++row) {
1075  if ((*id)->Match(m_Alnmap->GetSeqId(row))) {
1076  return row;
1077  }
1078  }
1079  }
1080  }
1081 
1083  return row;
1084 }
1085 
1087 {
1088  TVecConstSeqFeat const_featlist;
1089  TVecSeqFeat featlist;
1090  if (m_Alnmap) { // alignment coordinates have been entered
1091 
1092  int min = 0;
1093  int max = bsh.GetBioseqLength() - 1;
1094  for (unsigned int row =0; row < m_ChoiceList.size(); ++row) {
1096  const_featlist = x_UpdatePartials(featlist);
1097  return const_featlist;
1098  } else {
1099  int aln_from = 0, seq_from = min;
1100  int aln_to = 0, seq_to = max;
1101 
1102  string from_value = ToStdString(m_ChoiceList[row].from->GetValue());
1103  if (NStr::IsBlank(from_value)) {
1104  break;
1105  } else {
1106  const CBioseq& bioseq = *(bsh.GetCompleteBioseq());
1107  IAlnExplorer::TNumrow seqrow = x_GetRow(bioseq);
1108  if (seqrow == -1) {
1109  m_ErrorMessage = "This sequence is not in the alignment!";
1110  const_featlist = x_UpdatePartials(featlist);
1111  return const_featlist;
1112  }
1113  try {
1114  aln_from = NStr::StringToInt(from_value);
1115  aln_from = aln_from - 1;
1116  seq_from = m_Alnmap->GetSeqPosFromAlnPos(seqrow, aln_from, IAlnExplorer::eForward);
1117  if (seq_from < min) { seq_from = min; }
1118 
1119  // stop if the chain extends past the length of this Bioseq
1120  if (seq_from > max) {
1121  const_featlist = x_UpdatePartials(featlist);
1122  return const_featlist;
1123  }
1124  } catch(const CException& e) {
1125  LOG_POST(Error << "CApplyRNAITSDlg::GetRNAITSList_AlignCoordFromDlg: " << e.GetMsg());
1126  const_featlist = x_UpdatePartials(featlist);
1127  return const_featlist;
1128  }
1129 
1130 
1131  string to_value = ToStdString(m_ChoiceList[row].to->GetValue());
1132  if (!NStr::IsBlank(to_value)) {
1133  try {
1134  aln_to = NStr::StringToInt(to_value);
1135  aln_to = aln_to - 1;
1136  seq_to = m_Alnmap->GetSeqPosFromAlnPos(seqrow, aln_to, IAlnExplorer::eBackwards);
1137  if (seq_to > max) { seq_to = max; }
1138  } catch(const CException& e) {
1139  LOG_POST(Error << "CApplyRNAITSDlg::GetRNAITSList_AlignCoordFromDl: " << e.GetMsg());
1140  const_featlist = x_UpdatePartials(featlist);
1141  return const_featlist;
1142  }
1143  }
1144 
1145  if (seq_from == seq_to) {
1146  continue;
1147  }
1148 
1149  string rna_name = ToStdString(m_ChoiceList[row].rnaType->GetStringSelection());
1150  NStr::ReplaceInPlace(rna_name, "rRNA", "ribosomal RNA");
1151  NStr::ReplaceInPlace(rna_name, "ITS", "internal transcribed spacer ");
1152  NStr::ReplaceInPlace(rna_name, "IGS", "intergenic spacer");
1153 
1154  if (NStr::FindNoCase(rna_name, "spacer") != NPOS) {
1155  CRef<CSeq_feat> new_feat = AddMiscRNA(bsh, rna_name, seq_from, seq_to, false, false);
1156  featlist.push_back(new_feat);
1157  } else {
1158  CRef<CSeq_feat> new_feat = AddRibosomalRNA(bsh, rna_name, seq_from, seq_to, false, false);
1159  featlist.push_back(new_feat);
1160  }
1161  }
1162  }
1163  }
1164  }
1165 
1166  const_featlist = x_UpdatePartials(featlist);
1167  return const_featlist;
1168 }
1169 
1170 
1171 
1173 {
1174  TVecConstSeqFeat const_featlist;
1175  TVecSeqFeat featlist;
1176 
1177  int min = 0;
1178  int max = bsh.GetBioseqLength() - 1;
1179  for (unsigned int row = 0; row < m_ChoiceList.size(); ++row) {
1181  const_featlist = x_UpdatePartials(featlist);
1182  return const_featlist;
1183  } else {
1184  int from = min;
1185  int to = max;
1186 
1187  string from_value = ToStdString(m_ChoiceList[row].from->GetValue());
1188  if (NStr::IsBlank(from_value)) {
1189  break;
1190  } else {
1191  try {
1192  from = NStr::StringToInt(from_value);
1193  from = from - 1;
1194  if (from < min ) { from = min; }
1195 
1196  // stop if the chain extends past the length of this Bioseq
1197  if (from >= max) {
1198  const_featlist = x_UpdatePartials(featlist);
1199  return const_featlist;
1200  }
1201  }
1202  catch (const CException& e) {
1203  LOG_POST(Error << "CApplyRNAITSDlg::GetRNAITSList_SeqCoordFromDlg: " << e.GetMsg());
1204  const_featlist = x_UpdatePartials(featlist);
1205  return const_featlist;
1206  }
1207  string to_value = ToStdString(m_ChoiceList[row].to->GetValue());
1208  if (!NStr::IsBlank(to_value)) {
1209  try {
1210  to = NStr::StringToInt(to_value);
1211  to = to - 1;
1212  if (to > max) { to = max; }
1213  }
1214  catch (const CException& e) {
1215  LOG_POST(Error << "CApplyRNAITSDlg::GetRNAITSList_SeqCoordFromDlg: " << e.GetMsg());
1216  const_featlist = x_UpdatePartials(featlist);
1217  return const_featlist;
1218  }
1219  }
1220 
1221  if (from == to) {
1222  continue;
1223  }
1224  string rna_name = ToStdString(m_ChoiceList[row].rnaType->GetStringSelection());
1225  NStr::ReplaceInPlace(rna_name, "rRNA", "ribosomal RNA");
1226  NStr::ReplaceInPlace(rna_name, "ITS", "internal transcribed spacer ");
1227  NStr::ReplaceInPlace(rna_name, "IGS", "intergenic spacer");
1228 
1229  if (NStr::FindNoCase(rna_name, "spacer") != NPOS) {
1230  CRef<CSeq_feat> new_feat = AddMiscRNA(bsh, rna_name, from, to, false, false);
1231  featlist.push_back(new_feat);
1232  } else {
1233  CRef<CSeq_feat> new_feat = AddRibosomalRNA(bsh, rna_name, from, to, false, false);
1234  featlist.push_back(new_feat);
1235  }
1236  }
1237  }
1238  }
1239  const_featlist = x_UpdatePartials(featlist);
1240  return const_featlist;
1241 }
1242 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
User-defined methods of the data storage class.
CStaticArrayMap< string, CApplyRNAITSDlg::ERNA_IGSType > TIGSMap
DEFINE_STATIC_ARRAY_MAP(TITSMap, sm_ITSMap, s_Rna_ITSStrings)
SStaticPair< const char *, CApplyRNAITSDlg::ERNA_ITSType > TITSLabelPair
static const TITSLabelPair s_Rna_ITSStrings[]
USING_SCOPE(ncbi::objects)
static const char * kApplyChoice
SStaticPair< const char *, CApplyRNAITSDlg::ERNA_IGSType > TIGSLabelPair
static const TIGSLabelPair s_Rna_IGSStrings[]
CStaticArrayMap< string, CApplyRNAITSDlg::ERNA_ITSType > TITSMap
#define ID_CHECKBOX9
#define ID_TEXTCTRL_SFROM
#define ID_CHECKBOX7
#define ID_CHOICE_SECOND
#define ID_LEAVE_DIALOG_UP
#define ID_CHOICE_FIRST
#define ID_TEXTCTRL_STO
#define ID_CHECKBOX8
#define ID_TEXTCTRL_FITO
#define ID_TEXTCTRL_FOTO
#define ID_TEXTCTRL_FTO
#define ID_TEXTCTRL_FOFROM
#define ID_TEXTCTRL_TTO
#define ID_RADIOBOX_ITS_IGS
#define ID_CHOICE_FOURTH
#define ID_TEXTCTRL_FFROM
#define ID_TEXTCTRL_TFROM
#define ID_CHOICE_THIRD
#define ID_TEXTCTRL_FIFROM
#define ID_APPLY
#define ID_CLOSEBTN
#define ID_CHOICE_FIFTH
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
CAlign_CI –.
Definition: align_ci.hpp:63
const CSeq_id & GetSeqId(TNumrow row) const
Definition: alnmap.hpp:645
TSignedSeqPos GetSeqPosFromAlnPos(TNumrow for_row, TSeqPos aln_pos, ESearchDirection dir=eNone, bool try_reverse_dir=true) const
Definition: alnmap.cpp:663
TDim GetNumRows(void) const
Definition: alnmap.hpp:517
TVecConstSeqId m_PropSeqids
void AddFeatures(const CBioseq_Handle &bsh, TVecConstSeqFeat &featlist, CRef< CCmdComposite > composite, bool &modified)
ERNA_ITSType GetNextRNA_ITSChoice(ERNA_ITSType field_type)
wxCheckBox * m_3partial
IAlnExplorer::TNumrow x_GetRow(const CBioseq &bioseq)
void Apply_RNAITS_ToTSE(CRef< CCmdComposite > composite, bool &modified)
bool x_WasPropagatedTo(const CBioseq_Handle &bsh)
returns true if features were already propagated to the sequence
void OnAnyOtherChoiceSelected(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=10307, const wxString &caption=_("Apply rRNA_ITS"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static ERNA_ITSType GetRNA_ITSTypeFromName(const string &label)
~CApplyRNAITSDlg()
Destructor.
void OnGoClick(wxCommandEvent &event)
vector< CRef< CSeq_feat > > TVecSeqFeat
wxCheckBox * m_LeaveUp
void x_Set_ITSArray(wxArrayString &Its_tags)
TVecConstSeqFeat GetRNAITSList_AlignCoordFromDlg(const CBioseq_Handle &bsh)
void OnCancelClick(wxCommandEvent &event)
bool x_IsThereAlignment(void)
TVecConstSeqId x_SeqIdsAlignedWith(const CBioseq_Handle &bsh, const CSeq_align &align)
obtains a vector of seqIds aligned with bsh through the given alignment - used for feature propagatio...
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnITSRadioBoxSelected(wxCommandEvent &event)
vector< CConstRef< CSeq_id > > TVecConstSeqId
TVecConstSeqFeat x_UpdatePartials(TVecSeqFeat &featlist)
if required, sets the first and last features incomplete
CApplyRNAITSDlg()
Constructors.
CRef< CAlnMap > m_Alnmap
void Propagate_RNAITSList(const CBioseq_Handle &bsh, TVecConstSeqFeat &featlist, CRef< CCmdComposite > composite, bool &modified, bool create_general_only)
virtual void SetRegistryPath(const string &reg_path)
virtual string GetErrorMessage()
void OnFirstChoiceSelected(wxCommandEvent &event)
ERNA_IGSType GetNextRNA_IGSChoice(ERNA_IGSType field_type)
static const string & GetRNA_IGSName(ERNA_IGSType field_type)
void x_Set_IGSArray(wxArrayString &Igs_tags)
static ERNA_IGSType GetRNA_IGSTypeFromName(const string &label)
wxCheckBox * m_AlignCoords
vector< CConstRef< CSeq_feat > > TVecConstSeqFeat
void Apply_RNAITS_ToBioseqSet(CSeq_entry_Handle entry, CRef< CCmdComposite > composite, bool &modified)
virtual void SaveSettings() const
static const string & GetRNA_ITSName(ERNA_ITSType field_type)
static bool ShowToolTips()
Should we show tooltips?
wxRadioBox * m_ITSRadiobox
vector< CConstRef< CSeq_align > > x_GetAlignments(const CBioseq_Handle &bsh)
obtains all dense-seg type alignments where this bioseq is present, in this seq-entry
TVecConstSeqFeat ObtainRNAITSList(const CBioseq_Handle &bsh)
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual CRef< CCmdComposite > GetCommand()
CBulkCmdDlg pure virtual functions.
void OnCtrlToKillFocus(wxFocusEvent &event)
virtual void LoadSettings()
TVecConstSeqFeat GetRNAITSList_SeqCoordFromDlg(const CBioseq_Handle &bsh)
void Init()
Initialises member variables.
vector< SRNAITSChoice > m_ChoiceList
void OnCloseWindow(wxCloseEvent &event)
void Apply_RNAITS_ToBioseq(const CBioseq_Handle &bsh, CRef< CCmdComposite > composite, bool &modified, bool create_general_only)
wxCheckBox * m_5partial
void OnCtrlFromKillFocus(wxFocusEvent &event)
SIZE_TYPE x_BioseqInAlignments(const CBioseq_Handle &bsh)
returns the number of dense-seg type alignment which the bioseq belongs to
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
CBioseq_set_Handle –.
bool IsNa(void) const
Definition: Bioseq.cpp:345
bool IsAa(void) const
Definition: Bioseq.cpp:350
TConstScopedObjects GetSelectedObjects()
objects::CSeq_entry_Handle m_TopSeqEntry
bool Create(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
string m_ErrorMessage
bool GetTopLevelSeqEntryAndProcessor()
ICommandProccessor * m_CmdProccessor
void AddCommand(IEditCommand &command)
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
Default implementation of IMessageListener: collects all messages posted.
CObject –.
Definition: ncbiobj.hpp:180
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
bool IsEntrys(void) const
Definition: Seq_submit.cpp:54
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
Definition: static_map.hpp:175
TBase::const_iterator const_iterator
Definition: static_map.hpp:179
@ eBackwards
Towards lower seq coord (to the left if plus strand, right if minus)
@ eForward
Towards higher seq coord (to the right if plus strand, left if minus)
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
void PropagateToTarget(CRef< CCmdComposite > composite, const vector< CConstRef< objects::CSeq_feat >> &feat_list, objects::CBioseq_Handle src, objects::CBioseq_Handle target, const objects::CSeq_align &align, bool stop_at_stop, bool cleanup_partials, bool merge_abutting, bool extend_over_gaps, bool create_general_only, CMessageListener_Basic *listener, objects::CObject_id::TId *feat_id=nullptr)
#define _(proto)
Definition: ct_nlmzip_i.h:78
CRef< objects::CSeq_feat > AddRibosomalRNA(const objects::CBioseq_Handle &bsh, string name, int from, int to, bool ispartial5, bool ispartial3)
CRef< objects::CSeq_feat > AddMiscRNA(const objects::CBioseq_Handle &bsh, string name, int from, int to, bool ispartial5, bool ispartial3)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual size_t Count(void) const
Get total number of collected messages.
virtual string GetText(void) const =0
Get text message.
virtual const IMessage & GetMessage(size_t index) const
Get a previously collected message.
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Optimized implementation of CSerialObject::Assign, which is not so efficient.
Definition: Seq_id.cpp:318
@ eMissing_Null
Definition: scope.hpp:157
CConstRef< CBioseq > GetCompleteBioseq(void) const
Get the complete bioseq.
TSeqPos GetBioseqLength(void) const
bool IsAa(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CConstRef< CSeq_id > GetSeqId(void) const
Get id which can be used to access this bioseq handle Throws an exception if none is available.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsNa(void) const
bool IsSeq(void) const
const CSeq_align & GetOriginalSeq_align(void) const
Get original alignment.
Definition: align_ci.cpp:225
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
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2993
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
#define NPOS
Definition: ncbistr.hpp:133
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
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
static const char label[]
const TDenseg & GetDenseg(void) const
Get the variant data.
Definition: Seq_align_.cpp:153
bool IsSetSegs(void) const
Check if a value has been assigned to Segs data member.
Definition: Seq_align_.hpp:909
vector< CRef< CSeq_id > > TIds
Definition: Dense_seg_.hpp:106
const TIds & GetIds(void) const
Get the Ids member data.
Definition: Dense_seg_.hpp:505
const TSegs & GetSegs(void) const
Get the Segs member data.
Definition: Seq_align_.hpp:921
bool IsDenseg(void) const
Check if variant Denseg is selected.
Definition: Seq_align_.hpp:740
bool IsSetIds(void) const
sequences in order Check if a value has been assigned to Ids data member.
Definition: Dense_seg_.hpp:493
const TWhole & GetWhole(void) const
Get the variant data.
Definition: Seq_loc_.cpp:172
bool IsWhole(void) const
Check if variant Whole is selected.
Definition: Seq_loc_.hpp:522
const TId & GetId(void) const
Get the Id member data.
Definition: Bioseq_.hpp:290
list< CRef< CSeq_id > > TId
Definition: Bioseq_.hpp:94
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
END_EVENT_TABLE()
int i
yy_size_t n
bool FocusedOnNucleotides(TConstScopedObjects &objects, const objects::CSeq_entry_Handle &tse)
#define wxT(x)
Definition: muParser.cpp:41
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T max(T x_, T y_)
T min(T x_, T y_)
#define row(bind, expected)
Definition: string_bind.c:73
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Apr 24 14:14:10 2024 by modify_doxy.py rev. 669887