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

Go to the SVN repository for this file.

1 /* $Id: align_multiple_demo_dlg.cpp 46027 2021-01-21 13:48:45Z 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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbitime.hpp>
35 
36 
38 
40 
44 
46 
48 
50 
51 #include <serial/objistr.hpp>
52 #include <serial/serial.hpp>
53 
54 
55 #include <wx/sizer.h>
56 #include <wx/msgdlg.h>
57 #include <wx/statline.h>
58 #include <wx/textctrl.h>
59 #include <wx/button.h>
60 #include <wx/bitmap.h>
61 #include <wx/icon.h>
62 
63 
64 
67 
68 
69 IMPLEMENT_DYNAMIC_CLASS( CAlignMultipleDemoDlg, wxDialog )
70 
71 
72 BEGIN_EVENT_TABLE( CAlignMultipleDemoDlg, wxDialog )
73 ////@begin CAlignMultipleDemoDlg event table entries
75 
77 
79 
80  EVT_BUTTON( wxID_CLOSE, CAlignMultipleDemoDlg::OnCloseClick )
81 
82 ////@end CAlignMultipleDemoDlg event table entries
84 
85 
87 {
88  Init();
89 }
90 
91 
92 CAlignMultipleDemoDlg::CAlignMultipleDemoDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
93 {
94  Init();
95  Create(parent, id, caption, pos, size, style);
96 }
97 
98 
99 bool CAlignMultipleDemoDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
100 {
101 ////@begin CAlignMultipleDemoDlg creation
102  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
103  wxDialog::Create( parent, id, caption, pos, size, style );
104 
105  CreateControls();
106  if (GetSizer())
107  {
108  GetSizer()->SetSizeHints(this);
109  }
110  Centre();
111 ////@end CAlignMultipleDemoDlg creation
112  return true;
113 }
114 
115 
117 {
118 ////@begin CAlignMultipleDemoDlg destruction
119 ////@end CAlignMultipleDemoDlg destruction
120 }
121 
122 
124 {
125 ////@begin CAlignMultipleDemoDlg member initialisation
126  m_AlnWidget = NULL;
127  m_AccInput = NULL;
128  m_FileInput = NULL;
129 ////@end CAlignMultipleDemoDlg member initialisation
130 
131  if ( !m_ObjMgr ) {
134 
135  m_Scope.Reset(new CScope(*m_ObjMgr));
136  m_Scope->AddDefaults();
137  }
138 
139  /// Create an empty data source
140  vector< CConstRef<CSeq_align> > aligns;
141  m_Builder.Init(*m_Scope, aligns);
143 
144 }
145 
146 #define DEF_FILE "E:\\Users\\Yazhuk\\Gbench Data\\blast.asn"
147 #define DEF_ACC "19568015"
148 
149 
151 {
152 ////@begin CAlignMultipleDemoDlg content construction
153  CAlignMultipleDemoDlg* itemDialog1 = this;
154 
155  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
156  itemDialog1->SetSizer(itemBoxSizer2);
157 
158  m_AlnWidget = new CAlnMultiWidget( itemDialog1, ID_WIDGET, wxDefaultPosition, wxSize(800, 400), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
159  itemBoxSizer2->Add(m_AlnWidget, 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 CAlignMultipleDemoDlg content construction
196 
197  /// register command
198  m_FileInput->SetValue(ToWxString(DEF_FILE));
199  m_AccInput->SetValue(ToWxString(DEF_ACC));
200 
202 
205  ws->m_TextFont.SetFontSize(12);
207  ws->m_SeqFont.SetFontSize(8);
208 
209 
212 
214 
216 
217  // register commands
220 
221  WidgetsWx_RegisterCommands(cmd_reg, *provider);
222  CAlnMultiWidget::RegisterCommands(cmd_reg, *provider);
223 }
224 
225 
227 {
228  return true;
229 }
230 
231 
232 wxBitmap CAlignMultipleDemoDlg::GetBitmapResource( const wxString& name )
233 {
234  // Bitmap retrieval
235 ////@begin CAlignMultipleDemoDlg bitmap retrieval
236  wxUnusedVar(name);
237  return wxNullBitmap;
238 ////@end CAlignMultipleDemoDlg bitmap retrieval
239 }
240 
241 wxIcon CAlignMultipleDemoDlg::GetIconResource( const wxString& name )
242 {
243  // Icon retrieval
244 ////@begin CAlignMultipleDemoDlg icon retrieval
245  wxUnusedVar(name);
246  return wxNullIcon;
247 ////@end CAlignMultipleDemoDlg icon retrieval
248 }
249 
250 
251 void CAlignMultipleDemoDlg::OnCloseWindow(wxCloseEvent& event)
252 {
253  Destroy();
254 }
255 
256 
257 void CAlignMultipleDemoDlg::OnCloseClick( wxCommandEvent& event )
258 {
259  Close();
260 }
261 
262 
263 void CAlignMultipleDemoDlg::OnAccClick( wxCommandEvent& event )
264 {
265  CSeq_id id;
266 
267  string acc = ToStdString(m_AccInput->GetValue());
268  try {
269  id.Set(acc);
270  }
271  catch (CSeqIdException&) {
272  string msg("Accession '");
273  msg += acc + " not recognized as a valid accession";
274  wxMessageBox(ToWxString(msg), wxT("Cannot load accesion"),
275  wxOK | wxICON_ERROR);
276  return;
277  }
278 
279  // retrieve our sequence
280  CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
281  if(handle) {
282  m_Builder.Init(*m_Scope, handle);
283  OnRebuild();
284  } else {
285  string msg("Can't find sequence for accession '");
286  msg += acc + "'";
287  wxMessageBox(ToWxString(msg), wxT("Cannot load accesion"),
288  wxOK | wxICON_ERROR);
289  return;
290  }
291 }
292 
293 
295 
296 
297 /// loads a serializable object of type T
298 template <class T>
299  bool LoadObject(const wxString& filename, CScope& scope, CAlnMultiDSBuilder& builder)
300 {
301  try {
302  CNcbiIfstream istr(filename.fn_str());
303  unique_ptr<CObjectIStream> os(CObjectIStream::Open(eSerial_AsnText, istr));
304 
305  CRef<T> obj(new T());
306  *os >> *obj;
307 
308  builder.Init(scope, *obj);
309  return true;
310  } catch(CException& /*e*/) {
311  return false;
312  }
313 }
314 
315 
316 void CAlignMultipleDemoDlg::OnFileClick( wxCommandEvent& event )
317 {
318  m_AlnWidget->SetDataSource(nullptr, nullptr);
319 
320  wxString filename = m_FileInput->GetValue();
321  try {
322  bool ok = LoadObject<CSeq_align>(filename, *m_Scope, m_Builder);
323  if( ! ok) {
324  ok = LoadObject<CSeq_annot>(filename, *m_Scope, m_Builder);
325  }
326  if( ! ok) {
327  ok = LoadObject<CBioseq>(filename, *m_Scope, m_Builder);
328  }
329  if(ok) {
330  OnRebuild();
331  } else {
332  wxMessageBox(wxT("This type of file is not supported"),
333  wxT("Error loading file."),
334  wxOK | wxICON_ERROR);
335  }
336  } catch(CException& e) {
337  e.ReportAll();
338  wxString s = ToWxString(e.GetMsg());
339  wxMessageBox(s, wxT("Error loading file."), wxOK | wxICON_ERROR);
340  }
341 }
342 
343 
344 
346 {
347  // reset old data
348  m_AlnWidget->SetDataSource(nullptr, nullptr);
349 
350  vector<CBioseq_Handle> handles;
351 
353  m_Builder.GetBioseqHandles(handles);
354 
355  CBuildOptionsDlg dlg(this);
356  dlg.SetParams(m_Builder.SetOptions(), handles, *m_Scope);
357 
358  //if(dlg.ShowModal() == wxID_OK) {
359  //CAlnMultiDSBuilder::TOptions new_options;
360  //dlg.GetOptions(new_options);
361  //m_Builder.SetOptions() = new_options;
362 
364  //}
365 
367  if(m_DataSource) {
369  }
370 }
371 
372 
USING_SCOPE(objects)
#define DEF_FILE
CAlnMultiDSBuilder::TAlignVector TAlignVector
#define DEF_ACC
bool LoadObject(const wxString &filename, CScope &scope, CAlnMultiDSBuilder &builder)
loads a serializable object of type T
CRef< IAlnMultiDataSource > m_DataSource
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("Align Mulitple Widget Demo"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|0x1000)
wxBitmap GetBitmapResource(const wxString &name)
void OnFileClick(wxCommandEvent &event)
void OnCloseClick(wxCommandEvent &event)
CRef< CObjectManager > m_ObjMgr
wxIcon GetIconResource(const wxString &name)
void OnCloseWindow(wxCloseEvent &event)
void OnAccClick(wxCommandEvent &event)
void GetBioseqHandles(vector< CBioseq_Handle > &handles)
vector< CConstRef< objects::CSeq_align > > TAlignVector
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
CRef< IAlnMultiDataSource > CreateDataSource()
void PreCreateDataSource(bool sparse)
class CAlnMultiWidget
virtual void SetDataSource(IAlnMultiDataSource *p_ds, objects::CScope *scope)
virtual void SetStyleCatalog(const CRowStyleCatalog *catalog)
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
class CAlnMultiWidget
virtual const CWidgetDisplayStyle * GetDisplayStyle() const
virtual void CreateWidget(CAlnMultiModel *model=NULL)
performs initialization, creates Model and Controls.
CBioseq_Handle –.
CwxBuildOptionsDlg.
void SetParams(const CAlnMultiDSBuilder::TOptions &options, const vector< CBioseq_Handle > &handles, objects::CScope &scope)
virtual void SetListener(IListener *pListener)
Subscribe a new listener.
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
CRowDisplayStyle is a base class representing a display style for IAlignRow.
void SetDefaultStyle(CRowDisplayStyle *style)
assumes ownership
void SetWidgetStyle(const CWidgetDisplayStyle *style)
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
CWidgetDisplayStyle is a collection of display properties common for all rows in the CAlnMultiWidget.
CGlTextureFont m_TextFont
CGlTextureFont m_SeqFont
text font (description, positions etc.)
Include a standard set of the NCBI C++ Toolkit most basic headers.
#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
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
void SetFontFace(EFontFace face, bool use_bitmap_overrides=true)
void SetFontSize(unsigned int size)
Set/get font size in points.
@ 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()
#define wxT(x)
Definition: muParser.cpp:41
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 Thu Jun 13 17:31:28 2024 by modify_doxy.py rev. 669887