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

Go to the SVN repository for this file.

1 /* $Id: cross_aln_demo_dlg.cpp 46046 2021-01-21 18:02:04Z grichenk $
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: Vlad Lebedev
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbitime.hpp>
35 
36 #include "cross_aln_demo_dlg.hpp"
37 
39 
40 // Register commands
44 
45 #include <serial/objistr.hpp>
46 #include <serial/serial.hpp>
47 
48 
49 #include <wx/msgdlg.h>
50 #include <wx/statline.h>
51 #include <wx/sizer.h>
52 #include <wx/textctrl.h>
53 #include <wx/button.h>
54 #include <wx/bitmap.h>
55 #include <wx/icon.h>
56 
57 
60 
61 
62 
63 
64 IMPLEMENT_DYNAMIC_CLASS( CCrossAlnDemoDlg, wxDialog )
65 
66 
67 
68 BEGIN_EVENT_TABLE( CCrossAlnDemoDlg, wxDialog )
69 ////@begin CCrossAlnDemoDlg event table entries
71 
73 
75 
76  EVT_BUTTON( wxID_CLOSE, CCrossAlnDemoDlg::OnCloseClick )
77 
78 ////@end CCrossAlnDemoDlg event table entries
80 
81 
83 {
84  Init();
85 }
86 
87 CCrossAlnDemoDlg::CCrossAlnDemoDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
88 {
89  Init();
90  Create(parent, id, caption, pos, size, style);
91 }
92 
93 
94 
95 
96 
97 bool CCrossAlnDemoDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
98 {
99 ////@begin CCrossAlnDemoDlg creation
100  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
101  wxDialog::Create( parent, id, caption, pos, size, style );
102 
103  CreateControls();
104  Centre();
105 ////@end CCrossAlnDemoDlg creation
106  return true;
107 }
108 
109 
110 
111 
112 
114 {
115 ////@begin CCrossAlnDemoDlg destruction
116 ////@end CCrossAlnDemoDlg destruction
117 }
118 
119 
120 
121 
122 
124 {
125 ////@begin CCrossAlnDemoDlg member initialisation
127  m_AccInput = NULL;
128  m_FileInput = NULL;
129 ////@end CCrossAlnDemoDlg member initialisation
130 
131  if ( !m_ObjMgr ) {
134 
135  m_Scope.Reset(new CScope(*m_ObjMgr));
136  m_Scope->AddDefaults();
137  }
138 
141  WidgetsWx_RegisterCommands(cmd_reg, *provider);
142  CCrossAlnWidget::RegisterCommands(cmd_reg, *provider);
143 }
144 
145 
146 
147 #define DEF_ACC "19568015"
148 #define DEF_FILE "/Users/lebedev/asn/simple-align1.asn"
149 
151 {
152 ////@begin CCrossAlnDemoDlg content construction
153  CCrossAlnDemoDlg* itemDialog1 = this;
154 
155  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
156  itemDialog1->SetSizer(itemBoxSizer2);
157 
158  m_CrossAlnWidget = new CCrossAlnWidget( itemDialog1, ID_WIDGET, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
159  itemBoxSizer2->Add(m_CrossAlnWidget, 1, wxGROW|wxALL, 5);
160 
161  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
162  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);
163 
164  wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(0, 2, 0, 0);
165  itemBoxSizer4->Add(itemFlexGridSizer5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 0);
166 
167  m_AccInput = new wxTextCtrl( itemDialog1, ID_ACC_TEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
168  m_AccInput->SetMaxLength(20);
169  m_AccInput->SetHelpText(_("Enter Accession"));
171  m_AccInput->SetToolTip(_("Enter Accession"));
172  itemFlexGridSizer5->Add(m_AccInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 
174  wxButton* itemButton7 = new wxButton( itemDialog1, ID_ACC, _("Load Accession"), wxDefaultPosition, wxDefaultSize, 0 );
175  itemFlexGridSizer5->Add(itemButton7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
176 
177  m_FileInput = new wxTextCtrl( itemDialog1, ID_FILE_TEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
178  m_FileInput->SetMaxLength(256);
179  m_FileInput->SetHelpText(_("Enter asn file name"));
181  m_FileInput->SetToolTip(_("Enter asn file name"));
182  itemFlexGridSizer5->Add(m_FileInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
183 
184  wxButton* itemButton9 = new wxButton( itemDialog1, ID_FILE, _("Load File"), wxDefaultPosition, wxDefaultSize, 0 );
185  itemFlexGridSizer5->Add(itemButton9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
186 
187  itemFlexGridSizer5->AddGrowableCol(0);
188 
189  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
190  itemBoxSizer4->Add(itemStaticLine10, 0, wxGROW|wxALL, 5);
191 
192  wxButton* itemButton11 = new wxButton( itemDialog1, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
193  itemBoxSizer4->Add(itemButton11, 0, wxALIGN_BOTTOM|wxALL, 5);
194 
195 ////@end CCrossAlnDemoDlg content construction
197  m_FileInput->SetValue(ToWxString(DEF_FILE));
198  m_AccInput->SetValue(ToWxString(DEF_ACC));
199 }
200 
201 
202 
203 
204 
205 void CCrossAlnDemoDlg::OnCloseWindow( wxCloseEvent& event )
206 {
207  Destroy();
208 }
209 
210 
211 
212 
213 
214 void CCrossAlnDemoDlg::OnAccClick( wxCommandEvent& event )
215 {
216  CSeq_id id;
217 
218  string acc = ToStdString(m_AccInput->GetValue());
219  try {
220  id.Set(acc);
221  }
222  catch (CSeqIdException&) {
223  string msg("Accession '");
224  msg += acc + " not recognized as a valid accession";
225  wxMessageBox(ToWxString(msg), _("Cannot load accesion"),
226  wxOK | wxICON_ERROR);
227  return;
228  }
229 
230  // retrieve our sequence
231  CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
232  if (handle) {
234 
235  m_Builder.Init(*m_Scope, handle);
237 
238  if (m_DataSource->SelectDefaultIds()) {
240  }
241  } else {
242  string msg("Can't find sequence for accession '");
243  msg += acc + "'";
244  wxMessageBox(ToWxString(msg), _("Cannot load accesion"),
245  wxOK | wxICON_ERROR);
246  return;
247  }
248 }
249 
250 
251 
252 
254 /// loads a serializable object of type T
255 template <class T> bool LoadObject(const wxString& filename, CScope& scope, CHitMatrixDSBuilder& builder)
256 {
257  try {
258  CNcbiIfstream istr(filename.fn_str());
259  unique_ptr<CObjectIStream> os(CObjectIStream::Open(eSerial_AsnText, istr));
260 
261  CRef<T> obj(new T());
262  *os >> *obj;
263 
264  builder.Init(scope, *obj);
265  return true;
266  } catch(CException& /*e*/) {
267  return false;
268  }
269 }
270 
271 
272 void CCrossAlnDemoDlg::OnFileClick( wxCommandEvent& event )
273 {
275 
276  wxString filename = m_FileInput->GetValue();
277  try {
278  bool ok = LoadObject<CSeq_align>(filename, *m_Scope, m_Builder);
279  if (!ok) {
280  ok = LoadObject<CSeq_annot>(filename, *m_Scope, m_Builder);
281  }
282  if (!ok) {
283  ok = LoadObject<CBioseq>(filename, *m_Scope, m_Builder);
284  }
285  if (ok) {
287 
288  if(m_DataSource->SelectDefaultIds()) {
290  }
291  } else {
292  wxMessageBox(_("This type of file is not supported"),
293  _("Error loading file."),
294  wxOK | wxICON_ERROR);
295  }
296  } catch(CException& e) {
297  LOG_POST(Error << e.ReportAll());
298  wxString s = ToWxString(e.GetMsg());
299  wxMessageBox(s, _("Error loading file."), wxOK | wxICON_ERROR);
300  }
301 }
302 
303 
304 
305 
306 void CCrossAlnDemoDlg::OnCloseClick( wxCommandEvent& event )
307 {
308  Close();
309 }
310 
311 
312 
313 
314 
316 {
317  return true;
318 }
319 
320 
321 
322 
323 wxBitmap CCrossAlnDemoDlg::GetBitmapResource( const wxString& name )
324 {
325  // Bitmap retrieval
326 ////@begin CCrossAlnDemoDlg bitmap retrieval
327  wxUnusedVar(name);
328  return wxNullBitmap;
329 ////@end CCrossAlnDemoDlg bitmap retrieval
330 }
331 
332 
333 
334 
335 wxIcon CCrossAlnDemoDlg::GetIconResource( const wxString& name )
336 {
337  // Icon retrieval
338 ////@begin CCrossAlnDemoDlg icon retrieval
339  wxUnusedVar(name);
340  return wxNullIcon;
341 ////@end CCrossAlnDemoDlg icon retrieval
342 }
343 
CBioseq_Handle –.
CHitMatrixDSBuilder m_Builder
CIRef< ICrossAlnDataSource > m_DataSource
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("CCrossAlnDemoDlg"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(600, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX)
CRef< CScope > m_Scope
void OnAccClick(wxCommandEvent &event)
static bool ShowToolTips()
void OnFileClick(wxCommandEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
CCrossAlnWidget * m_CrossAlnWidget
wxIcon GetIconResource(const wxString &name)
CRef< CObjectManager > m_ObjMgr
void OnCloseWindow(wxCloseEvent &event)
void OnCloseClick(wxCommandEvent &event)
void SetDataSource(ICrossAlnDataSource *ds)
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
virtual void Create()
creates controls and performs basic initialization
CHitMatrixDSBuilder.
CIRef< IHitMatrixDataSource > CreateDataSource()
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
CScope –.
Definition: scope.hpp:92
CSeqIdException –.
Definition: Seq_id.hpp:1001
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
vector< CConstRef< objects::CSeq_align > > TAlignVector
Include a standard set of the NCBI C++ Toolkit most basic headers.
USING_SCOPE(objects)
#define DEF_FILE
IHitMatrixDataSource::TAlignVector TAlignVector
#define DEF_ACC
bool LoadObject(const wxString &filename, CScope &scope, CHitMatrixDSBuilder &builder)
loads a serializable object of type T
#define ID_WIDGET
#define ID_ACC_TEXT
#define ID_ACC
#define ID_FILE_TEXT
#define ID_FILE
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define T(s)
Definition: common.h:230
static void Init(void)
Definition: cursor6.c:76
#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
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
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
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines: CTimeFormat - storage class for time format.
void WidgetsWx_RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
Register standard commands defined in this file and wxWidgets headers.
Definition: commands.cpp:46
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat May 25 14:18:01 2024 by modify_doxy.py rev. 669887