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

Go to the SVN repository for this file.

1 /* $Id: blast_search_options_panel.cpp 39666 2017-10-25 16:01:13Z katargir $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
39 
42 
47 
48 #include <wx/sizer.h>
49 #include <wx/image.h>
50 #include <wx/stattext.h>
51 #include <wx/button.h>
52 #include <wx/combobox.h>
53 #include <wx/choice.h>
54 #include <wx/radiobut.h>
55 #include <wx/statbox.h>
56 #include <wx/msgdlg.h>
57 
58 ////@begin XPM images
59 ////@end XPM images
60 
61 
63 
64 
65 IMPLEMENT_DYNAMIC_CLASS( CBLASTSearchOptionsPanel, CAlgoToolManagerParamsPanel )
66 
68 
69 ////@begin CBLASTSearchOptionsPanel event table entries
70  EVT_RADIOBUTTON( ID_NUC_RADIO, CBLASTSearchOptionsPanel::OnNucRadioSelected )
71 
72  EVT_RADIOBUTTON( ID_PROT_RADIO, CBLASTSearchOptionsPanel::OnProtRadioSelected )
73 
74  EVT_CHOICE( ID_QUERY_SEQ_SET, CBLASTSearchOptionsPanel::OnQuerySequenceSetSelected )
75 
76  EVT_COMBOBOX( ID_PROGRAM_COMBO, CBLASTSearchOptionsPanel::OnProgramComboSelected )
77 
79 
81 
83 
84  EVT_CHOICE( ID_SUBJECT_SEQ_SET, CBLASTSearchOptionsPanel::OnSubjectSequenceSetSelected )
85 
86  EVT_COMBOBOX( ID_DB_COMBO, CBLASTSearchOptionsPanel::OnDatabaseComboSelected )
87 
88  EVT_BUTTON( ID_SELECT_NCBI_DB, CBLASTSearchOptionsPanel::OnBrowseDatabases )
89 
90  EVT_BUTTON( ID_SELECT_LOCAL_DB_BTN, CBLASTSearchOptionsPanel::OnSelectLocalDB )
91 
93 
94 ////@end CBLASTSearchOptionsPanel event table entries
95 
96  EVT_BUTTON( ID_DBS_TRY_AGAIN, CBLASTSearchOptionsPanel::OnTryAgain )
98 
100 
101 
103  : m_DataSource(NULL)
104  , m_NucObjects(NULL)
105  , m_ProtObjects(NULL)
106  , m_Params(NULL)
107  , m_Timer(this)
108  , m_DBLoadState(CBLASTDatabases::eInitial)
109 {
110  Init();
111 }
112 
113 
114 CBLASTSearchOptionsPanel::CBLASTSearchOptionsPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
115  : m_Timer(this)
116  , m_DBLoadState(CBLASTDatabases::eInitial)
117 {
118  Init();
119  Create(parent, id, pos, size, style);
120 }
121 
122 
123 bool CBLASTSearchOptionsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
124 {
125  wxPanel::Create( parent, id, pos, size, style );
126 
127  Hide();
128 
129  CreateControls();
130  if (GetSizer())
131  {
132  GetSizer()->SetSizeHints(this);
133  }
134 
135  return true;
136 }
137 
138 
140 {
141 ////@begin CBLASTSearchOptionsPanel destruction
142 ////@end CBLASTSearchOptionsPanel destruction
143 }
144 
146 const string& tool_name)
147 {
148  m_DataSource = &ds;
149  m_ToolName = tool_name;
150 }
151 
154  map<string, TConstScopedObjects>* prot_objects)
155 {
156  m_Params = params;
157 
158  _ASSERT(nuc_objects && prot_objects);
159 
160  m_NucObjects = nuc_objects;
161  m_ProtObjects = prot_objects;
162 
163 }
164 
165 
167 {
168 ////@begin CBLASTSearchOptionsPanel member initialisation
169  m_NucRadio = NULL;
170  m_ProtRadio = NULL;
175  m_LocalSizer = NULL;
184  m_DBSizer = NULL;
187  m_QueryCombo = NULL;
191 ////@end CBLASTSearchOptionsPanel member initialisation
192 
193  m_DataSource = NULL;
194  m_ToolName.clear();
195 
196  m_NucObjects = NULL;
198 
199  m_Params = NULL;
200 
202 }
203 
204 
206 {
207 ////@begin CBLASTSearchOptionsPanel content construction
208  CBLASTSearchOptionsPanel* itemCAlgoToolManagerParamsPanel1 = this;
209 
210  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
211  itemCAlgoToolManagerParamsPanel1->SetSizer(itemBoxSizer2);
212 
213  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemCAlgoToolManagerParamsPanel1, wxID_ANY, _("Query Sequences"));
214  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
215  itemBoxSizer2->Add(itemStaticBoxSizer3, 1, wxGROW|wxALL, 5);
216 
217  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
218  itemStaticBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_RIGHT|wxALL, 5);
219 
220  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
221  itemStaticBoxSizer3->Add(itemBoxSizer5, 0, wxGROW, 5);
222 
223  m_NucRadio = new wxRadioButton( itemCAlgoToolManagerParamsPanel1, ID_NUC_RADIO, _("Nucleotides"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
224  m_NucRadio->SetValue(true);
225  itemBoxSizer5->Add(m_NucRadio, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
226 
227  m_ProtRadio = new wxRadioButton( itemCAlgoToolManagerParamsPanel1, ID_PROT_RADIO, _("Proteins"), wxDefaultPosition, wxDefaultSize, 0 );
228  m_ProtRadio->SetValue(false);
229  itemBoxSizer5->Add(m_ProtRadio, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
230 
231  itemBoxSizer5->Add(7, 8, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
232 
233  m_QuerySeqSetStatic = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Sequence set:"), wxDefaultPosition, wxDefaultSize, 0 );
234  itemBoxSizer5->Add(m_QuerySeqSetStatic, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
235 
236  wxArrayString m_QuerySeqSetComboStrings;
237  m_QuerySeqSetCombo = new wxChoice( itemCAlgoToolManagerParamsPanel1, ID_QUERY_SEQ_SET, wxDefaultPosition, wxDefaultSize, m_QuerySeqSetComboStrings, 0 );
238  itemBoxSizer5->Add(m_QuerySeqSetCombo, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
239 
240  m_QueryListCtrl = new CObjectListWidget( itemCAlgoToolManagerParamsPanel1, ID_LIST, wxDefaultPosition, itemCAlgoToolManagerParamsPanel1->ConvertDialogToPixels(wxSize(350, 75)), wxLC_REPORT );
241  itemStaticBoxSizer3->Add(m_QueryListCtrl, 1, wxGROW|wxALL, 5);
242 
243  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
244  itemBoxSizer2->Add(itemBoxSizer12, 0, wxGROW|wxALL, 5);
245 
246  wxStaticText* itemStaticText13 = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Program:"), wxDefaultPosition, wxDefaultSize, 0 );
247  itemBoxSizer12->Add(itemStaticText13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
248 
249  wxArrayString m_ProgramComboStrings;
250  m_ProgramCombo = new wxComboBox( itemCAlgoToolManagerParamsPanel1, ID_PROGRAM_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_ProgramComboStrings, wxCB_READONLY );
251  itemBoxSizer12->Add(m_ProgramCombo, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
252 
253  wxStaticBox* itemStaticBoxSizer15Static = new wxStaticBox(itemCAlgoToolManagerParamsPanel1, wxID_ANY, _("Subject"));
254  m_LocalSizer = new wxStaticBoxSizer(itemStaticBoxSizer15Static, wxVERTICAL);
255  itemBoxSizer2->Add(m_LocalSizer, 1, wxGROW|wxALL, 0);
256 
257  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
258  m_LocalSizer->Add(itemBoxSizer16, 0, wxGROW|wxALL, 0);
259 
260  m_SubjectTypeSeqsCtrl = new wxRadioButton( itemCAlgoToolManagerParamsPanel1, ID_RADIOBUTTON, _("Sequences"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
261  m_SubjectTypeSeqsCtrl->SetValue(true);
262  itemBoxSizer16->Add(m_SubjectTypeSeqsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
263 
264  m_SubjectTypeNCBICtrl = new wxRadioButton( itemCAlgoToolManagerParamsPanel1, ID_RADIOBUTTON2, _("NCBI Database"), wxDefaultPosition, wxDefaultSize, 0 );
265  m_SubjectTypeNCBICtrl->SetValue(false);
266  itemBoxSizer16->Add(m_SubjectTypeNCBICtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
267 
268  m_SubjectTypeLDBCtrl = new wxRadioButton( itemCAlgoToolManagerParamsPanel1, ID_RADIOBUTTON1, _("Local Database"), wxDefaultPosition, wxDefaultSize, 0 );
269  m_SubjectTypeLDBCtrl->SetValue(false);
270  itemBoxSizer16->Add(m_SubjectTypeLDBCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
271 
272  itemBoxSizer16->Add(7, 8, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
273 
274  m_SubjectSeqSetStatic = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Sequence set:"), wxDefaultPosition, wxDefaultSize, 0 );
275  itemBoxSizer16->Add(m_SubjectSeqSetStatic, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
276 
277  wxArrayString m_SubjectSeqSetComboStrings;
278  m_SubjectSeqSetCombo = new wxChoice( itemCAlgoToolManagerParamsPanel1, ID_SUBJECT_SEQ_SET, wxDefaultPosition, wxDefaultSize, m_SubjectSeqSetComboStrings, 0 );
279  itemBoxSizer16->Add(m_SubjectSeqSetCombo, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
280 
281  m_LocalSeqsSizer = new wxBoxSizer(wxVERTICAL);
282  m_LocalSizer->Add(m_LocalSeqsSizer, 1, wxGROW, 0);
283 
284  m_SubjectListCtrl = new CObjectListWidget( itemCAlgoToolManagerParamsPanel1, ID_SUBJ_LIST, wxDefaultPosition, itemCAlgoToolManagerParamsPanel1->ConvertDialogToPixels(wxSize(350, 75)), wxLC_REPORT );
285  m_LocalSeqsSizer->Add(m_SubjectListCtrl, 1, wxGROW|wxALL, 5);
286 
287  m_NCBIDBSizer = new wxFlexGridSizer(0, 2, 0, 0);
288  m_LocalSizer->Add(m_NCBIDBSizer, 0, wxGROW|wxALL, 5);
289 
290  wxStaticText* itemStaticText26 = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Database:"), wxDefaultPosition, wxDefaultSize, 0 );
291  m_NCBIDBSizer->Add(itemStaticText26, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
292 
293  m_DBSizer = new wxBoxSizer(wxHORIZONTAL);
294  m_NCBIDBSizer->Add(m_DBSizer, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5);
295 
296  wxArrayString m_DatabaseComboStrings;
297  m_DatabaseCombo = new wxComboBox( itemCAlgoToolManagerParamsPanel1, ID_DB_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_DatabaseComboStrings, wxCB_READONLY );
298  m_DBSizer->Add(m_DatabaseCombo, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
299 
300  m_BrowseDBBtn = new wxBitmapButton( itemCAlgoToolManagerParamsPanel1, ID_SELECT_NCBI_DB, itemCAlgoToolManagerParamsPanel1->GetBitmapResource(wxT("menu::open")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
301  m_BrowseDBBtn->SetHelpText(_("Select NCBI DB"));
303  m_BrowseDBBtn->SetToolTip(_("Select NCBI DB"));
304  m_DBSizer->Add(m_BrowseDBBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
305 
306  wxStaticText* itemStaticText30 = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Entrez Query:"), wxDefaultPosition, wxDefaultSize, 0 );
307  m_NCBIDBSizer->Add(itemStaticText30, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
308 
309  wxArrayString m_QueryComboStrings;
310  m_QueryCombo = new wxComboBox( itemCAlgoToolManagerParamsPanel1, ID_ENTREZ_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_QueryComboStrings, wxCB_DROPDOWN );
311  m_NCBIDBSizer->Add(m_QueryCombo, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
312 
313  m_NCBIDBSizer->AddGrowableCol(1);
314 
315  m_LocalDBSizer = new wxBoxSizer(wxVERTICAL);
316  m_LocalSizer->Add(m_LocalDBSizer, 0, wxGROW, 5);
317 
318  wxBoxSizer* itemBoxSizer33 = new wxBoxSizer(wxHORIZONTAL);
319  m_LocalDBSizer->Add(itemBoxSizer33, 0, wxGROW|wxALL, 0);
320 
321  wxStaticText* itemStaticText34 = new wxStaticText( itemCAlgoToolManagerParamsPanel1, wxID_STATIC, _("Database:"), wxDefaultPosition, wxDefaultSize, 0 );
322  itemBoxSizer33->Add(itemStaticText34, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
323 
324  m_LocalDBCtrl = new wxTextCtrl( itemCAlgoToolManagerParamsPanel1, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
325  itemBoxSizer33->Add(m_LocalDBCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
326 
327  wxBitmapButton* itemBitmapButton36 = new wxBitmapButton( itemCAlgoToolManagerParamsPanel1, ID_SELECT_LOCAL_DB_BTN, itemCAlgoToolManagerParamsPanel1->GetBitmapResource(wxT("menu::open")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
328  itemBitmapButton36->SetHelpText(_("Select Local DB"));
330  itemBitmapButton36->SetToolTip(_("Select Local DB"));
331  itemBoxSizer33->Add(itemBitmapButton36, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
332 
333  m_LocalDBLoaderCtrl = new wxCheckBox( itemCAlgoToolManagerParamsPanel1, ID_CHECKBOX, _("Add Local BLAST DB data loader to the project"), wxDefaultPosition, wxDefaultSize, 0 );
334  m_LocalDBLoaderCtrl->SetValue(false);
335  m_LocalDBSizer->Add(m_LocalDBLoaderCtrl, 0, wxALIGN_LEFT|wxALL, 5);
336 
337 ////@end CBLASTSearchOptionsPanel content construction
338 
339  wxStaticText* failedText = new wxStaticText( this, ID_DBS_FAILED, wxT("Failed to load..."), wxDefaultPosition, wxDefaultSize, 0 );
340 
341  wxFont bold(wxNORMAL_FONT->GetPointSize(), wxNORMAL_FONT->GetFamily(), wxNORMAL_FONT->GetStyle(), wxFONTWEIGHT_BOLD, wxNORMAL_FONT->GetUnderlined(), wxNORMAL_FONT->GetFaceName());
342  failedText->SetFont(bold);
343 
344  failedText->SetForegroundColour(*wxRED);
345  m_DBSizer->Add(failedText, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
346  m_DBSizer->Hide(failedText);
347 
348  wxButton* tryAgainBtn = new wxButton( this, ID_DBS_TRY_AGAIN, _("Try Again"), wxDefaultPosition, wxDefaultSize, 0 );
349  m_DBSizer->Add(tryAgainBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
350  m_DBSizer->Hide(tryAgainBtn);
351 
352  wxStaticText* loadingText = new wxStaticText( this, ID_DBS_LOADING_TEXT, wxT("Loading..."), wxDefaultPosition, wxDefaultSize, 0 );
353  loadingText->SetFont(bold);
354  loadingText->SetForegroundColour(*wxBLACK);
355  m_DBSizer->Add(loadingText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
356  m_DBSizer->Hide(loadingText);
357 
358  CIndProgressBar* progress = new CIndProgressBar(this, ID_DBS_LOADING_PROGRESS, wxDefaultPosition, 100);
359  m_DBSizer->Add(progress, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
360  m_DBSizer->Hide(progress);
361 
362  m_LocalSizer->Show(m_LocalSeqsSizer, true);
363  m_LocalSizer->Hide(m_LocalDBSizer, true);
364  m_LocalSizer->Hide(m_NCBIDBSizer, true);
365 }
366 
367 
369 {
370  return true;
371 }
372 
373 
374 wxBitmap CBLASTSearchOptionsPanel::GetBitmapResource( const wxString& name )
375 {
376  return wxArtProvider::GetBitmap(name);
377 }
378 
379 
380 wxIcon CBLASTSearchOptionsPanel::GetIconResource( const wxString& name )
381 {
382  // Icon retrieval
383 ////@begin CBLASTSearchOptionsPanel icon retrieval
384  wxUnusedVar(name);
385  return wxNullIcon;
386 ////@end CBLASTSearchOptionsPanel icon retrieval
387 }
388 
389 static const char* kTableTag = "Table";
390 
392 {
393  if( ! m_RegPath.empty()) {
395  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kTableTag);
396 
397  CRegistryWriteView query_table_view = gui_reg.GetWriteView(
398  reg_path + ".QueryTable"
399  );
400  m_QueryListCtrl->SaveTableSettings(query_table_view);
401 
402  CRegistryWriteView subject_table_view = gui_reg.GetWriteView(
403  reg_path + ".SubjectTable"
404  );
405  m_SubjectListCtrl->SaveTableSettings(subject_table_view);
406  }
407 }
408 
409 
411 {
412  if( ! m_RegPath.empty()) {
414  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kTableTag);
415 
416  CRegistryReadView query_table_view = gui_reg.GetReadView(
417  reg_path + ".QueryTable"
418  );
419  m_QueryListCtrl->LoadTableSettings(query_table_view);
420 
421  CRegistryReadView subject_table_view = gui_reg.GetReadView(
422  reg_path + ".SubjectTable"
423  );
424  m_SubjectListCtrl->LoadTableSettings(subject_table_view);
425  }
426 }
427 
429 {
430  bool nuc_subj = m_Params->IsNucInput();
431  m_NucRadio->SetValue(nuc_subj);
432  m_ProtRadio->SetValue(!nuc_subj);
433 
435  m_SubjectTypeSeqsCtrl->SetValue(subjectType == CBLASTParams::eSequences);
436  m_SubjectTypeNCBICtrl->SetValue(subjectType == CBLASTParams::eNCBIDB);
437  m_SubjectTypeLDBCtrl->SetValue(subjectType == CBLASTParams::eLocalDB);
438 
440 
442 
443  x_CheckDBLoaded();
444 
445  x_OnInputTypeChanged(nuc_subj);
446 
447  wxString query = ToWxString(m_Params->GetEntrezQuery());
448  m_QueryCombo->SetValue(query);
449 
450  return wxPanel::TransferDataToWindow();
451 }
452 
454 {
455  if (!wxPanel::TransferDataFromWindow())
456  return false;
457 
458  m_Params->GetSeqLocs().clear();
460 
461  if (m_Params->GetSeqLocs().empty()) {
462  wxMessageBox(wxT("Please select at least one query sequence!"),
463  wxT("BALST Tool Error"),
464  wxOK | wxICON_ERROR);
465  m_QueryListCtrl->SetFocus();
466  return false;
467  }
468 
470 
471  m_Params->GetSubjSeqLocs().clear();
472  if (subjectType == CBLASTParams::eNCBIDB) {
473  if (!CBLASTDatabases::GetInstance().Loaded()) {
474  wxMessageBox(wxT("BLAST database must be selected.\n")
475  wxT("Please, wait till databases are loaded."),
476  wxT("BALST Tool Error"),
477  wxOK | wxICON_ERROR);
478  return false;
479  }
480 
482  m_Params->GetCurrDatabase() = ToStdString(m_DatabaseCombo->GetStringSelection());
483  if (m_Params->GetCurrDatabase().empty()) {
484  wxMessageBox(wxT("Please select a database!"),
485  wxT("BALST Tool Error"),
486  wxOK | wxICON_ERROR);
487  return false;
488  }
489  }
490  else if (subjectType == CBLASTParams::eLocalDB) {
491  wxString dbText = m_LocalDBCtrl->GetValue();
492  if (dbText.empty()) {
493  wxMessageBox(wxT("Please, select a local database."), wxT("Error"),
494  wxOK | wxICON_ERROR, this);
495  m_LocalDBCtrl->SetFocus();
496  return false;
497  }
498 
499  bool subjProteins = !m_Params->IsSubjNucInput();
500  if (!CLBLASTParamsPanel::ValidateLocalDatabase(dbText, subjProteins)) {
501  wxMessageBox(wxT("Invalid local database: \"") + dbText + wxT("\"."), wxT("Error"),
502  wxOK | wxICON_ERROR, this);
503  m_LocalDBCtrl->SetFocus();
504  return false;
505  }
506 
507  string db(dbText.ToUTF8());
508 
509  if (subjProteins)
511  else
512  m_Params->SetLocalNucDB(db);
513  }
514  else {
516  if (m_Params->GetSubjSeqLocs().empty()) {
517  wxMessageBox(wxT("No subject sequences selected."), wxT("Error"),
518  wxOK | wxICON_ERROR, this);
519  return false;
520  }
521  }
522 
523  wxString program = m_ProgramCombo->GetStringSelection();
526 
527  m_Params->IsNucInput() = m_NucRadio->GetValue();
528  return true;
529 }
530 
531 
533 {
534  x_OnInputTypeChanged(false);
535 }
536 
537 
539 {
540  x_OnInputTypeChanged(true);
541 }
542 
543 static const char* kSelectedSequences = "Selected sequences";
544 
546 {
547  m_Params->IsNucInput() = nuc_input;
548 
549  wxArrayString programLabels;
550 
551  vector<string> labels;
552  CBLASTParams::GetProgramLabels(nuc_input, labels);
553  ToArrayString(labels, programLabels);
554 
555  m_ProgramCombo->Clear();
556  m_ProgramCombo->Append(programLabels);
557 
558  wxString program = ToWxString(CBLASTParams::GetProgramLabel
559  (m_Params->GetCurrProgram()));
560  m_ProgramCombo->SetValue(program);
561 
563  x_FillQueryList();
564 
566 }
567 
568 
570 {
571  if (objects.size() <= 1)
572  return false;
573 
574  size_t count = 0;
575  for (auto& i : objects)
576  count += i.second.size();
577  return (count > 10);
578 }
579 
581 {
583  if (s_UseSets(objects)) {
584  m_QuerySeqSetStatic->Show(true);
585  m_QuerySeqSetCombo->Show(true);
586  m_QuerySeqSetCombo->Clear();
587  for (const auto& i : objects) {
588  if (i.first == kSelectedSequences)
590  else
591  m_QuerySeqSetCombo->Append(ToWxString(i.first));
592  }
593 
594  int sel = 0;
595  if (!m_CurrentQuerySet.empty()) {
596  sel = m_QuerySeqSetCombo->FindString(ToWxString(m_CurrentQuerySet));
597  if (sel == wxNOT_FOUND) sel = 0;
598  }
599 
600  m_QuerySeqSetCombo->SetSelection(sel);
602  }
603  else {
604  m_QuerySeqSetStatic->Show(false);
605  m_QuerySeqSetCombo->Show(false);
606  m_QuerySeqSetCombo->Clear();
607  }
608 }
609 
610 
612 {
614 
615  if (s_UseSets(objects)) {
617 
618  if (it != objects.end())
619  m_QueryListCtrl->SetObjects(it->second);
620  else {
623  }
624 
625  if (m_QueryListCtrl->GetItemCount() <= 100) {
627  }
628  else if (m_SubjectListCtrl->GetItemCount() > 0) {
629  m_QueryListCtrl->Select(0);
630  }
631  }
632  else {
633  TConstScopedObjects allObjects;
634  for (auto& i : objects)
635  for (auto& o : i.second)
636  allObjects.push_back(o);
637  m_QueryListCtrl->SetObjects(allObjects);
639  }
640 }
641 
643 {
644  string sequenceSet = ToStdString(event.GetString());
645  if (sequenceSet != m_CurrentQuerySet) {
646  m_CurrentQuerySet = sequenceSet;
647  x_FillQueryList();
648  }
649 }
650 
652 {
653  bool nuc_subj = m_Params->IsSubjNucInput();
654 
655  wxString program = m_ProgramCombo->GetStringSelection();
658 
659  if (m_Params->IsSubjNucInput() != nuc_subj)
661 }
662 
664 {
665  string database = ToStdString(m_DatabaseCombo->GetStringSelection());
668 }
669 
671 {
673  if (subjectType == CBLASTParams::eNCBIDB) {
674  x_UpdateDBCombo();
675  }
676  else if (subjectType == CBLASTParams::eLocalDB) {
677  wxString db = m_Params->IsSubjNucInput() ?
678  wxString::FromUTF8(m_Params->GetLocalNucDB().c_str()) :
679  wxString::FromUTF8(m_Params->GetLocalProtDB().c_str());
680  m_LocalDBCtrl->SetValue(db);
681  } else {
684  }
685 }
686 
688 {
690  if (s_UseSets(objects)) {
691  m_SubjectSeqSetStatic->Show(true);
692  m_SubjectSeqSetCombo->Show(true);
693  m_SubjectSeqSetCombo->Clear();
694 
695  for (const auto& i : objects) {
696  if (i.first == kSelectedSequences)
698  else
699  m_SubjectSeqSetCombo->Append(ToWxString(i.first));
700  }
701 
702  int sel = 0;
703  if (!m_CurrentSubjectSet.empty()) {
705  if (sel == wxNOT_FOUND) sel = 0;
706  }
707 
708  m_SubjectSeqSetCombo->SetSelection(sel);
710 
711  } else {
712  m_SubjectSeqSetStatic->Show(false);
713  m_SubjectSeqSetCombo->Show(false);
714  m_SubjectSeqSetCombo->Clear();
715  }
716 }
717 
718 
720 {
722 
723  if (s_UseSets(objects)) {
725 
726  if (it != objects.end())
727  m_SubjectListCtrl->SetObjects(it->second);
728  else {
731  }
732 
733  if (m_SubjectListCtrl->GetItemCount() <= 100) {
735  }
736  else if (m_SubjectListCtrl->GetItemCount() > 0) {
737  m_SubjectListCtrl->Select(0);
738  }
739  }
740  else {
741  TConstScopedObjects allObjects;
742  for (auto& i : objects)
743  for (auto& o : i.second)
744  allObjects.push_back(o);
745  m_SubjectListCtrl->SetObjects(allObjects);
747  }
748 }
749 
751 {
752  string sequenceSet = ToStdString(event.GetString());
753  if (sequenceSet != m_CurrentSubjectSet) {
754  m_CurrentSubjectSet = sequenceSet;
756  }
757 }
758 
759 static const char* kDBBrowserSection = ".DB Browser";
760 
761 void CBLASTSearchOptionsPanel::OnBrowseDatabases( wxCommandEvent& event )
762 {
764  if (!dbs.Loaded())
765  return;
766 
767  wxString database = m_DatabaseCombo->GetStringSelection();
768  vector<string> databases;
769  databases.push_back(ToStdString(database));
770 
771  CBLAST_DB_Dialog dlg(this);
773 
774  dlg.SetToolName(m_ToolName);
775  dlg.SelectDatabases(databases);
776 
777  bool nuc_db = m_Params->IsSubjNucInput();
778  const CBLASTDatabases::TDbMap& map = dbs.GetDbMap(nuc_db);
779  dlg.SetDBMap(map);
780 
781  if(dlg.ShowModal() == wxID_OK) {
782  // User selected a database
783  databases.clear();
784  dlg.GetSelectedDatabases(databases);
785 
786  _ASSERT(databases.size() == 1);
787 
788  string db = databases[0];
789  m_Params->GetCurrDatabase() = db;
791 
792  x_UpdateDBCombo();
793  }
794 }
795 
797 {
799  return;
800 
801  wxWindow* tryAgainBtn = FindWindow(ID_DBS_TRY_AGAIN);
802  wxWindow* progress = FindWindow(ID_DBS_LOADING_PROGRESS);
803 
805  switch(dbs.GetState()) {
809  m_Timer.Stop();
810 
811  m_DBSizer->Show(FindWindow(ID_DBS_FAILED));
812  m_DBSizer->Show(tryAgainBtn);
813 
814  m_DBSizer->Hide(FindWindow(ID_DBS_LOADING_TEXT));
815  m_DBSizer->Hide(progress);
816 
817  m_DBSizer->Hide(m_DatabaseCombo);
818  m_DBSizer->Hide(m_BrowseDBBtn);
819  Layout();
821  }
822  break;
825  m_Timer.Start(300);
826 
827  int height = tryAgainBtn->GetSize().GetHeight();
828  progress->SetMinSize(wxSize(1, height));
829 
830  m_DBSizer->Hide(FindWindow(ID_DBS_FAILED));
831  m_DBSizer->Hide(tryAgainBtn);
832 
833  m_DBSizer->Show(FindWindow(ID_DBS_LOADING_TEXT));
834  m_DBSizer->Show(progress);
835 
836  m_DBSizer->Hide(m_DatabaseCombo);
837  m_DBSizer->Hide(m_BrowseDBBtn);
838  Layout();
840  }
841  break;
844  m_Timer.Stop();
845 
846  m_DBSizer->Hide(FindWindow(ID_DBS_FAILED));
847  m_DBSizer->Hide(tryAgainBtn);
848 
849  m_DBSizer->Hide(FindWindow(ID_DBS_LOADING_TEXT));
850  m_DBSizer->Hide(progress);
851 
852  x_UpdateDBCombo();
853 
854  m_DBSizer->Show(m_DatabaseCombo);
855  m_DBSizer->Show(m_BrowseDBBtn);
856  Layout();
858  }
859  break;
860  }
861 }
862 
864 {
866  if (!dbs.Loaded())
867  return;
868 
869  wxBusyCursor wait;
870 
872  bool nuc_db = CBLASTParams::IsNucDatabase(program);
873 
874  const CBLASTDatabases::TDbMap& db_map = dbs.GetDbMap(nuc_db);
875 
877  const CBLASTParams::TMRUDatabases::TItems& mruItems = mru_dbs.GetItems();
878 
879  list<string> newItems;
881  if (db_map.find(*it) != db_map.end())
882  newItems.push_back(*it);
883  }
884 
885  if (!newItems.empty()) {
886  mru_dbs.SetItems(newItems);
887  } else {
888  const vector<string>& mru = dbs.GetDefaultMRU_DBs(nuc_db);
889  newItems.assign(mru.begin(), mru.end());
890  mru_dbs.SetItems(newItems);
891  }
892 
893  string& db = m_Params->GetCurrDatabase();
894 
895  if (std::find(newItems.begin(), newItems.end(), db) == newItems.end()) {
896  if (db_map.find(db) != db_map.end()) {
897  mru_dbs.AddItem(db); // valid DB name - add to the MRU
898  } else if (!mru_dbs.GetItems().empty()) {
899  m_Params->GetDatabase(nuc_db) = *mru_dbs.GetItems().begin();
900  }
901  }
902 
903  wxArrayString arr;
904  ITERATE(CMRUList<string>::TItems, it, mru_dbs.GetItems()) {
905  const string& db_name = *it;
906  arr.Add(ToWxString(db_name));
907  LOG_POST(Info << "\t" << db_name);
908  }
909  m_DatabaseCombo->Clear();
910  m_DatabaseCombo->Append(arr);
911 
913 }
914 
915 void CBLASTSearchOptionsPanel::OnTryAgain( wxCommandEvent& event )
916 {
917  wxString homePath = CSysPath::ResolvePath(wxT("<home>"));
918  wxString dbTreePath = CSysPath::ResolvePath(wxT("<std>/etc/blastdb-spec/blast-db-tree.asn"));
919  CBLASTDatabases::GetInstance().Load(homePath.ToUTF8(), dbTreePath.ToUTF8());
920  x_CheckDBLoaded();
921 }
922 
923 void CBLASTSearchOptionsPanel::OnTimer(wxTimerEvent& event)
924 {
925  x_CheckDBLoaded();
926 }
927 
929 {
931 }
932 
934 {
935  if (!m_Params)
936  return;
938  wxBusyCursor wait;
940 }
941 
943 {
945  if (subjectType == CBLASTParams::eNCBIDB) {
946  m_SubjectSeqSetStatic->Show(false);
947  m_SubjectSeqSetCombo->Show(false);
948  m_SubjectSeqSetCombo->Clear();
949 
950  m_LocalSizer->Hide(m_LocalSeqsSizer, true);
951  m_LocalSizer->Show(m_NCBIDBSizer, true);
952  m_LocalSizer->Hide(m_LocalDBSizer, true);
954  x_CheckDBLoaded();
955  }
956  else if (subjectType == CBLASTParams::eLocalDB) {
957  m_SubjectSeqSetStatic->Show(false);
958  m_SubjectSeqSetCombo->Show(false);
959  m_SubjectSeqSetCombo->Clear();
960 
961  m_LocalSizer->Hide(m_LocalSeqsSizer, true);
962  m_LocalSizer->Hide(m_NCBIDBSizer, true);
963  m_LocalSizer->Show(m_LocalDBSizer, true);
964  }
965  else {
967  m_LocalSizer->Show(m_LocalSeqsSizer, true);
968  m_LocalSizer->Hide(m_NCBIDBSizer, true);
969  m_LocalSizer->Hide(m_LocalDBSizer, true);
970  }
971 }
972 
974 {
977  Layout();
978 }
979 
981 {
984  Layout();
985 }
986 
988 {
991  Layout();
992 }
993 
995 {
996  m_Params->SetLocalDBLoader(event.IsChecked());
997 }
998 
999 void CBLASTSearchOptionsPanel::OnSelectLocalDB( wxCommandEvent& event )
1000 {
1001  wxString text = m_LocalDBCtrl->GetValue();
1002  bool subjProteins = !m_Params->IsSubjNucInput();
1003 
1004  if (CLBLASTParamsPanel::SelectDatabase(this, text, subjProteins)) {
1005  string db(text.ToUTF8());
1006  if (subjProteins)
1007  m_Params->SetLocalProtDB(db);
1008  else
1009  m_Params->SetLocalNucDB(db);
1010 
1011  m_LocalDBCtrl->SetValue(text);
1012  }
1013 }
1014 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
static const char * kSelectedSequences
static bool s_UseSets(map< string, TConstScopedObjects > &objects)
static const char * kTableTag
static const char * kDBBrowserSection
EProgram
This enumeration is to evolve into a task/program specific list that specifies sets of default parame...
Definition: blast_types.hpp:56
CAlgoToolManagerParamsPanel.
string m_RegPath
registry path to the settings
static CBLASTDatabases & GetInstance()
const TDbMap & GetDbMap(bool nuc)
void Load(const char *path, const char *dbtree)
bool Loaded() const
const vector< string > & GetDefaultMRU_DBs(bool nuc_db)
std::unordered_map< string, string > TDbMap
EState GetState() const
CBLASTParams - save user-specified parameters and preferences.
CBLAST_DB_Dialog.
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
static string MakeKey(const string &section, const string &key, const string &delim=CGuiRegistry::kDecimalDot)
create a key from a section and a subkey
Definition: registry.cpp:504
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
static bool ValidateLocalDatabase(const wxString &db, bool proteins)
static bool SelectDatabase(wxWindow *parent, wxString &db, bool proteins)
list< string > TItems
Definition: mru_list.hpp:53
const TItems & GetItems() const
Definition: mru_list.hpp:96
void SetItems(const TItems &items)
Definition: mru_list.hpp:110
void AddItem(T item)
Definition: mru_list.hpp:60
CObjectListWidget - mediator widget.
void SetObjects(TConstScopedObjects &objects)
void GetSelection(TConstScopedObjects &objects)
ISelection-style API.
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Definition: sys_path.cpp:106
void LoadTableSettings(const CRegistryReadView &view, bool byName=false)
void SaveTableSettings(CRegistryWriteView &view, bool saveSorting=true) const
db_map template, mimics std::map<> using BerkeleyDB as the underlying Btree mechanism.
Definition: bdb_map.hpp:406
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
const_iterator find(const K &key) const
Definition: bdb_map.hpp:532
const_iterator end() const
Definition: bdb_map.hpp:524
#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 Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
TMRUDatabases & GetCurrMRUDatabases()
returns MRU databases for the current program
wxBitmap GetBitmapResource(const wxString &name)
bool GetLocalDBLoader() const
void OnSubjectLocalDBSelected(wxCommandEvent &event)
void Setup(CNetBLASTUIDataSource &ds, const string &tool_name)
void SetLocalNucDB(const string &value)
map< string, TConstScopedObjects > * m_NucObjects
TConstScopedObjects & GetSeqLocs()
wxIcon GetIconResource(const wxString &name)
TConstScopedObjects & GetSubjSeqLocs()
void OnTimer(wxTimerEvent &event)
void OnTryAgain(wxCommandEvent &event)
map< string, TConstScopedObjects > * m_ProtObjects
void SelectDatabases(vector< string > &databases)
void OnLocalDBLoaderClick(wxCommandEvent &event)
void GetSelectedDatabases(vector< string > &databases)
string GetLocalNucDB() const
static blast::EProgram GetProgramByLabel(const string &str)
void SetLocalProtDB(const string &value)
void OnSelectLocalDB(wxCommandEvent &event)
void OnBrowseDatabases(wxCommandEvent &event)
void OnSubjectSequencesSelected(wxCommandEvent &event)
void SetSubjectType(ESubjectType subjectType)
static bool IsNucDatabase(blast::EProgram program)
void SetDBMap(const TDbMap &map)
bool Create(wxWindow *parent, wxWindowID id=ID_CBLASTSEARCHOPTIONSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(), long style=wxTAB_TRAVERSAL)
void SetToolName(const string &tool)
void OnProgramComboSelected(wxCommandEvent &event)
void SetLocalDBLoader(bool value)
void SetParams(CBLASTParams *params, map< string, TConstScopedObjects > *nuc_objects, map< string, TConstScopedObjects > *prot_objects)
blast::EProgram & GetCurrProgram()
returns the current program for the currently selected input type
void OnSubjectNCBIDBSelected(wxCommandEvent &event)
void OnProtRadioSelected(wxCommandEvent &event)
void OnQuerySequenceSetSelected(wxCommandEvent &event)
TMRUDatabases & GetMRUDatabases(bool nuc_db)
string GetLocalProtDB() const
string & GetCurrDatabase()
returns the current database for the current program
virtual void SaveSettings() const
override in derived classes
void RestoreDefaults()
override in derived classes
void OnSubjectSequenceSetSelected(wxCommandEvent &event)
static void GetProgramLabels(bool nuc_input, vector< string > &labels)
void OnDatabaseComboSelected(wxCommandEvent &event)
CNetBLASTUIDataSource * m_DataSource
bool IsSubjNucInput() const
ESubjectType GetSubjectType() const
string & GetDatabase(bool nuc_db)
returns the database of the specified type
string & GetEntrezQuery()
void OnNucRadioSelected(wxCommandEvent &event)
static string GetProgramLabel(blast::EProgram program)
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define ID_RADIOBUTTON1
#define ID_RADIOBUTTON
use only n Cassandra database for the lookups</td > n</tr > n< tr > n< td > yes</td > n< td > do not use tables BIOSEQ_INFO and BLOB_PROP in the Cassandra database
END_EVENT_TABLE()
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_CHECKBOX
static static static wxID_ANY
static string query
#define _ASSERT
#define ID_RADIOBUTTON2
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void ToArrayString(const vector< string > &out, wxArrayString &in)
Definition: wx_utils.cpp:353
Modified on Mon Apr 22 04:06:56 2024 by modify_doxy.py rev. 669887