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

Go to the SVN repository for this file.

1 /* $Id: ngalign_panel.cpp 47031 2022-05-19 19:04:59Z asztalos $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 
35 #include "ngalign_panel.hpp"
36 
37 #include <wx/sizer.h>
38 #include <wx/stattext.h>
39 #include <wx/statbox.h>
40 #include <wx/choice.h>
41 #include <wx/msgdlg.h>
42 
43 #include "wx/bitmap.h"
44 #include "wx/icon.h"
45 
47 
48 ////@begin includes
49 #include "wx/imaglist.h"
50 ////@end includes
51 
54 
55 ////@begin XPM images
56 ////@end XPM images
57 
58 IMPLEMENT_DYNAMIC_CLASS( CNGAlignPanel, CAlgoToolManagerParamsPanel )
59 
60 BEGIN_EVENT_TABLE( CNGAlignPanel, CAlgoToolManagerParamsPanel )
61 
62 ////@begin CNGAlignPanel event table entries
63 ////@end CNGAlignPanel event table entries
64 
66 
68 {
69  Init();
70 }
71 
72 CNGAlignPanel::CNGAlignPanel( wxWindow* parent )
73 {
74  Init();
75  Create(parent);
76 }
77 
78 bool CNGAlignPanel::Create( wxWindow* parent, wxWindowID id )
79 {
80  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
81  CAlgoToolManagerParamsPanel::Create( parent, id, wxDefaultPosition, wxSize(0, 0), SYMBOL_CNGALIGNPANEL_STYLE );
82 
83  Hide();
84 
86  if (GetSizer())
87  {
88  GetSizer()->SetSizeHints(this);
89  }
90  Centre();
91 
92  return true;
93 }
94 
96 {
97 ////@begin CNGAlignPanel destruction
98 ////@end CNGAlignPanel destruction
99 }
100 
102 {
103 ////@begin CNGAlignPanel member initialisation
106 ////@end CNGAlignPanel member initialisation
107 }
108 
110 {
111 ////@begin CNGAlignPanel content construction
112  CNGAlignPanel* itemCAlgoToolManagerParamsPanel1 = this;
113 
114  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
115  itemCAlgoToolManagerParamsPanel1->SetSizer(itemBoxSizer2);
116 
117  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemCAlgoToolManagerParamsPanel1, wxID_ANY, _("Query Sequences"));
118  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
119  itemBoxSizer2->Add(itemStaticBoxSizer3, 1, wxGROW|wxALL, 5);
120 
121  m_QueryListCtrl = new CObjectListWidget( itemStaticBoxSizer3->GetStaticBox(), ID_QUERY_LIST, wxDefaultPosition, itemStaticBoxSizer3->GetStaticBox()->ConvertDialogToPixels(wxSize(200, 75)), wxLC_REPORT );
122  itemStaticBoxSizer3->Add(m_QueryListCtrl, 1, wxGROW|wxALL, 5);
123 
124  wxStaticBox* itemStaticBoxSizer5Static = new wxStaticBox(itemCAlgoToolManagerParamsPanel1, wxID_ANY, _("Subject Sequence"));
125  wxStaticBoxSizer* itemStaticBoxSizer5 = new wxStaticBoxSizer(itemStaticBoxSizer5Static, wxVERTICAL);
126  itemBoxSizer2->Add(itemStaticBoxSizer5, 1, wxGROW|wxALL, 5);
127 
128  m_SubjectListCtrl = new CObjectListWidget( itemStaticBoxSizer5->GetStaticBox(), ID_SUBJ_LIST, wxDefaultPosition, itemStaticBoxSizer5->GetStaticBox()->ConvertDialogToPixels(wxSize(200, 75)), wxLC_REPORT|wxLC_SINGLE_SEL );
129  itemStaticBoxSizer5->Add(m_SubjectListCtrl, 1, wxGROW|wxALL, 5);
130 
131 ////@end CNGAlignPanel content construction
132 }
133 
135 {
136  return true;
137 }
138 wxBitmap CNGAlignPanel::GetBitmapResource( const wxString& name )
139 {
140  // Bitmap retrieval
141 ////@begin CNGAlignPanel bitmap retrieval
142  wxUnusedVar(name);
143  return wxNullBitmap;
144 ////@end CNGAlignPanel bitmap retrieval
145 }
146 wxIcon CNGAlignPanel::GetIconResource( const wxString& name )
147 {
148  // Icon retrieval
149 ////@begin CNGAlignPanel icon retrieval
150  wxUnusedVar(name);
151  return wxNullIcon;
152 ////@end CNGAlignPanel icon retrieval
153 }
154 
156 {
157  CRef<CObjectList> objList(new CObjectList());
158  objList->Init(objects);
159  objList->AddColumn(CObjectList::eInteger, "Length");
160 
161  int row = 0;
162  for (auto& i : objects) {
163  TSeqPos length = 0;
164  const CSeq_loc* seqLoc = dynamic_cast<const CSeq_loc*>(i.object.GetPointer());
165  if (seqLoc) {
166  try {
167  if (seqLoc->IsWhole()) {
168  CBioseq_Handle handle = i.scope->GetBioseqHandle(*seqLoc);
169  if (handle)
170  length = (int)handle.GetBioseqLength();
171  }
172  else {
173  length = seqLoc->GetTotalRange().GetLength();
174  }
175  } NCBI_CATCH("CNGAlignPanel get Seq-loc length.");
176  }
177 
178  objList->SetInteger(0, row, length);
179  ++row;
180  }
181 
182  return objList.Release();
183 }
184 
185 static void s_GetMinMaxRows(const CObjectList& objList, int& min_row, int& max_row)
186 {
187  min_row = max_row = 0;
188  // we expect to have a single column, which represents the length of the bioseq
189  if (objList.GetNumColumns() != 1) {
190  return;
191  }
192 
193  int min_length = 0, max_length = 0;
194  int nr_rows = objList.GetNumRows();
195  int col = 0;
196 
197  if (nr_rows > 0) {
198  int length = objList.GetInteger(col, 0);
199  min_length = max_length = length;
200  }
201 
202  for (int row = 1; row < nr_rows; ++row) {
203  int length = objList.GetInteger(col, row);
204  if (length <= min_length) {
205  min_length = length;
206  min_row = row;
207  }
208  if (length >= max_length) {
209  max_length = length;
210  max_row = row;
211  }
212  }
213 }
214 
216 {
217  if (objects) {
219  m_QueryListCtrl->Init(*objList, new CObjectListTableModel());
220 
221  objList.Reset(s_CreateObjList(*objects));
222  m_SubjectListCtrl->Init(*objList, new CObjectListTableModel());
223 
224  int min_row = 0, max_row = 0;
225  s_GetMinMaxRows(*objList, min_row, max_row);
226 
227  if (objects->size() > 0) {
228  m_QueryListCtrl->SetItemState(min_row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
229  m_SubjectListCtrl->SetItemState(max_row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
230  }
231  LoadSettings();
232  }
233 }
234 
236 {
237  if (!CAlgoToolManagerParamsPanel::TransferDataFromWindow())
238  return false;
239 
240  TConstScopedObjects que_sel, sub_sel;
241 
242  m_QueryListCtrl->GetSelection(que_sel);
243  if( que_sel.empty() ){
244  wxMessageBox(
245  wxT("Please select Query sequences."), wxT("Error"),
246  wxOK | wxICON_ERROR, this
247  );
248  m_QueryListCtrl->SetFocus();
249  return false;
250  }
251 
253  if( sub_sel.empty() ){
254  wxMessageBox(
255  wxT("Please select Subject sequence."), wxT("Error"),
256  wxOK | wxICON_ERROR, this
257  );
258  m_SubjectListCtrl->SetFocus();
259  return false;
260  }
261 
262  CRef<CScope> scope = sub_sel[0].scope;
263 
264  ITERATE( TConstScopedObjects, oit, que_sel ){
265  const CRef<CScope> os = oit->scope;
266  if( os != scope ){
267  wxMessageBox
268  (wxT("This tool gives unpredictable results with sequences\nfrom different projects.\n\nPlease move all sequences to the same project\nand try again."), wxT("Error"),
269  wxOK | wxICON_ERROR, this
270  );
271  return false;
272  }
273  }
274 
275  SetQueries() = que_sel;
276  SetSubject() = sub_sel[0];
277 
278  return true;
279 }
280 
281 static const char *kTable1Tag = "Table1", *kTable2Tag = "Table2";
282 
284 {
285  if (!m_RegPath.empty()) {
287  string reg_path = CGuiRegistryUtil::MakeKey(m_RegPath, kTable1Tag);
288  CRegistryWriteView table_view = gui_reg.GetWriteView(reg_path);
289  m_QueryListCtrl->SaveTableSettings(table_view, false);
290 
292  table_view = gui_reg.GetWriteView(reg_path);
293  m_SubjectListCtrl->SaveTableSettings(table_view, false);
294  }
295 }
296 
298 {
299  if (!m_RegPath.empty()) {
301  string reg_path;
302  CRegistryReadView table_view;
303 
305  table_view = gui_reg.GetReadView(reg_path);
306  m_QueryListCtrl->LoadTableSettings(table_view);
307 
309  table_view = gui_reg.GetReadView(reg_path);
311  }
312 }
313 
315 {
316 }
317 
CAlgoToolManagerParamsPanel.
string m_RegPath
registry path to the settings
CBioseq_Handle –.
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
CObjectListTableModel.
CObjectListWidget - mediator widget.
void Init(CObjectList &list, CObjectListTableModel *model=new CObjectListTableModel())
Inits widget with object list and optional model.
void GetSelection(TConstScopedObjects &objects)
ISelection-style API.
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
void Init(TConstScopedObjects &objects)
initializers
void SetInteger(int col, int row, int val)
int AddColumn(EColumnType type, const string &name, int col=-1)
int GetNumRows() const
int GetInteger(int col, int row) const
int GetNumColumns() const
access to columns (attribute, indexes)
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
void LoadTableSettings(const CRegistryReadView &view, bool byName=false)
void SaveTableSettings(CRegistryWriteView &view, bool saveSorting=true) const
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
bool Create(wxWindow *parent, wxWindowID id=ID_CNGALIGNPANEL)
static bool ShowToolTips()
void SetObjects(TConstScopedObjects *objects)
virtual void RestoreDefaults()
override in derived classes
virtual void SaveSettings() const
override in derived classes
SConstScopedObject & SetSubject()
virtual bool TransferDataFromWindow()
TConstScopedObjects & SetQueries()
wxIcon GetIconResource(const wxString &name)
CObjectListWidget * m_QueryListCtrl
CObjectListWidget * m_SubjectListCtrl
wxBitmap GetBitmapResource(const wxString &name)
virtual void LoadSettings()
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
TRange GetTotalRange(void) const
Definition: Seq_loc.hpp:913
TSeqPos GetBioseqLength(void) const
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * Release(void)
Release a reference to the object and return a pointer to the object.
Definition: ncbiobj.hpp:846
position_type GetLength(void) const
Definition: range.hpp:158
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsWhole(void) const
Check if variant Whole is selected.
Definition: Seq_loc_.hpp:522
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
USING_SCOPE(ncbi::objects)
static const char * kTable2Tag
static CObjectList * s_CreateObjList(TConstScopedObjects &objects)
static void s_GetMinMaxRows(const CObjectList &objList, int &min_row, int &max_row)
static const char * kTable1Tag
#define SYMBOL_CNGALIGNPANEL_STYLE
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Thu May 02 14:34:25 2024 by modify_doxy.py rev. 669887