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

Go to the SVN repository for this file.

1 /* $Id: subannotation_panel.cpp 46622 2021-08-06 20:19:47Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
33 #include <gui/objutils/utils.hpp>
40 #include <chrono>
41 
42 #include <wx/sizer.h>
43 #include <wx/cshelp.h>
44 #include <wx/button.h>
45 #include <wx/icon.h>
46 
47 
49 
50 /*
51  * CSubAnnotationPanel type definition
52  */
53 
54 IMPLEMENT_DYNAMIC_CLASS( CSubAnnotationPanel, wxPanel )
55 
56 
57 /*
58  * CSubAnnotationPanel event table definition
59  */
60 
61 BEGIN_EVENT_TABLE( CSubAnnotationPanel, wxPanel )
62 
63 ////@begin CSubAnnotationPanel event table entries
64  EVT_BUTTON( ID_IMPORT_FTABLE_BTN, CSubAnnotationPanel::OnImportFeatTableClick )
65  EVT_BUTTON( wxID_CONTEXT_HELP, CSubAnnotationPanel::OnContextHelpClick )
66 ////@end CSubAnnotationPanel event table entries
67 
69 
70 
71 /*
72  * CSubAnnotationPanel constructors
73  */
74 
76 {
77  Init();
78 }
79 
80 CSubAnnotationPanel::CSubAnnotationPanel( wxWindow* parent, ICommandProccessor* proc, const wxString &dir, objects::CSeq_entry_Handle seh, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
81  : m_CmdProcessor(proc), m_WorkDir(dir), m_Seh(seh)
82 {
83  Init();
84  Create(parent, id, pos, size, style);
85 }
86 
87 
88 /*
89  * CSubAnnotationPanel creator
90  */
91 
92 bool CSubAnnotationPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
93 {
94 ////@begin CSubAnnotationPanel creation
95  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
96  wxPanel::Create( parent, id, pos, size, style );
97 
99  if (GetSizer())
100  {
101  GetSizer()->SetSizeHints(this);
102  }
103  Centre();
104 ////@end CSubAnnotationPanel creation
105  return true;
106 }
107 
108 
109 /*
110  * CSubAnnotationPanel destructor
111  */
112 
114 {
115 ////@begin CSubAnnotationPanel destruction
116 ////@end CSubAnnotationPanel destruction
117 }
118 
119 
120 /*
121  * Member initialisation
122  */
123 
125 {
126 ////@begin CSubAnnotationPanel member initialisation
128 ////@end CSubAnnotationPanel member initialisation
129 }
130 
131 
132 /*
133  * Control creation for CSubAnnotationPanel
134  */
135 
137 {
138 ////@begin CSubAnnotationPanel content construction
139  CSubAnnotationPanel* itemPanel1 = this;
140 
141  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
142  itemPanel1->SetSizer(itemBoxSizer2);
143 
144  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
145  itemBoxSizer2->Add(itemBoxSizer1, 0, wxALIGN_LEFT|wxALL, 0);
146 
147  wxButton* itemButton2 = new wxButton( itemPanel1, ID_IMPORT_FTABLE_BTN, _("Import from feature table"), wxDefaultPosition, wxDefaultSize, 0 );
148  itemBoxSizer1->Add(itemButton2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
149 
150  m_FeatureTable = new CGenericPanel(itemPanel1, true, NULL, ID_SUBANNOTFEATTBL, wxDefaultPosition, wxSize(100, 100), 0);
151  itemBoxSizer2->Add(m_FeatureTable, 1, wxGROW | wxALL, 5);
153 
154 ////@end CSubAnnotationPanel content construction
155 }
156 
158 {
159  wxFont font = CTextPanel::GetFont(CGuiRegistry::GetInstance().GetInt("GBENCH.TextView.FontSize", 1));
160  m_FeatureTable->SetInitialSize(wxSize(100 * font.GetPointSize() / 10, 100));
161  m_FeatureTable->SetFont(font);
162 }
163 
164 
165 /*
166  * Should we show tooltips?
167  */
168 
170 {
171  return true;
172 }
173 
174 /*
175  * Get bitmap resources
176  */
177 
178 wxBitmap CSubAnnotationPanel::GetBitmapResource( const wxString& name )
179 {
180  // Bitmap retrieval
181 ////@begin CSubAnnotationPanel bitmap retrieval
182  wxUnusedVar(name);
183  return wxNullBitmap;
184 ////@end CSubAnnotationPanel bitmap retrieval
185 }
186 
187 /*
188  * Get icon resources
189  */
190 
191 wxIcon CSubAnnotationPanel::GetIconResource( const wxString& name )
192 {
193  // Icon retrieval
194 ////@begin CSubAnnotationPanel icon retrieval
195  wxUnusedVar(name);
196  return wxNullIcon;
197 ////@end CSubAnnotationPanel icon retrieval
198 }
199 
200 
201 /*
202  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CONTEXT_HELP
203  */
204 
205 void CSubAnnotationPanel::OnContextHelpClick( wxCommandEvent& event )
206 {
207 
208 }
209 
210 
211 /*
212  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ORGINFOBTN
213  */
214 
215 void CSubAnnotationPanel::OnImportFeatTableClick( wxCommandEvent& event )
216 {
217  if (!m_Seh || !m_CmdProcessor) return;
218  try {
219  CImportFeatTable worker(m_Seh);
221  if (!cmd)
222  return;
223 
225  } catch (const CException& e) {
226  LOG_POST(Error << "Importing feature table in the submission wizard failed: " << e.GetMsg());
227  return;
228  }
229  catch (const exception& e) {
230  LOG_POST(Error << "Importing feature table in the submission wizard failed: " << e.what());
231  return;
232  }
233 }
234 
235 
237 {
238  m_FeatureTable->SetText(ToWxString("Loading..."));
239 
241 
242  // show protein IDs, do not show sources
243  SFeatTableParams input(true, false);
244  input.seh = m_Seh;
245 
246  m_JobAdapter.Reset(LaunchAdapterJob<SFeatTableParams, string>
247  (this, input, Create5ColFeatTable, "C5ColFeatTableJob", "Generate 5 Column tab delimited feature table"));
248  return true;
249 }
250 
251 
253 {
254  if (canceled.IsCanceled())
255  return false;
256 
257  if (canceled.IsCanceled())
258  return false;
259 
260  LOG_POST(Info << "Generate feature table... ");
261  try {
262  auto start = chrono::steady_clock::now();
263  objects::CFlatFileConfig ff_config;
264  ff_config.SetFormatFTable();
265 
266  ff_config.SetShowContigFeatures().SetShowContigSources();
267  ff_config.SetShowPeptides();
268  ff_config.SetViewNuc();
269 
270  if (!input.showProteinId) {
271  ff_config.SetHideProteinID();
272  }
273  if (!input.showSrcFeature) {
274  ff_config.SetHideSourceFeatures();
275  }
276 
277  // default: show protein ids, transcript_ids, no source features
278  objects::CFlatFileGenerator ff(ff_config);
279  ff.SetAnnotSelector() = CSeqUtils::GetAnnotSelector();
280 
281  CNcbiOstrstream ostr;
282  ff.Generate(input.seh, ostr);
284  auto diff = chrono::steady_clock::now() - start;
285  LOG_POST(Info << "Feature generation took: " <<
286  chrono::duration_cast<chrono::milliseconds>(diff).count() << " ms");
287  }
288  catch (const CException& e) {
289  error = e.GetMsg();
290  LOG_POST(Error << "Feature generation failed: " << error);
291  return false;
292  }
293  catch (const std::exception& e) {
294  error = e.what();
295  LOG_POST(Error << "Feature generation failed: " << error);
296  return false;
297  }
298 
299  return true;
300 }
301 
302 
304 {
305  CJobAdapterResult<string>* jobResult = dynamic_cast<CJobAdapterResult<string>*>(result);
306  if (jobResult) {
307  const string& data = jobResult->GetData();
309  LOG_POST(Info << "Finished generating feature table.");
310  }
311 }
312 
313 void CSubAnnotationPanel::OnJobFailed(const string& errMsg, CJobAdapter&)
314 {
315  string err_msg = "Feature generation failed: ";
316  if (!errMsg.empty()) {
317  err_msg += errMsg;
318  }
319  else {
320  err_msg += "Unknown fatal error";
321  }
322 
323  NcbiErrorBox(err_msg);
324 }
325 
326 
void SetText(const wxString &text)
void SetFindMode(int mode)
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CIRef< IEditCommand > ImportFeaturesFromFile(const wxString &workDir=wxEmptyString, const string &format_id=kEmptyStr)
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObject –.
Definition: ncbiobj.hpp:180
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void Init()
Initialises member variables.
void CreateControls()
Creates the controls and sizers.
void OnImportFeatTableClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ORGINFOBTN
virtual void OnJobFailed(const string &, CJobAdapter &adapter)
void OnContextHelpClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CONTEXT_HELP
static bool Create5ColFeatTable(SFeatTableParams &input, string &output, string &error, ICanceled &canceled)
virtual bool TransferDataToWindow()
bool Create(wxWindow *parent, wxWindowID id=ID_CSUBANNOTATIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
CSubAnnotationPanel()
Constructors.
ICommandProccessor * m_CmdProcessor
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CGenericPanel * m_FeatureTable
objects::CSeq_entry_Handle m_Seh
CRef< CJobAdapter > m_JobAdapter
virtual void OnJobResult(CObject *result, CJobAdapter &adapter)
static bool ShowToolTips()
Should we show tooltips?
static wxFont GetFont(int size)
Definition: text_panel.cpp:174
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
static SQLCHAR output[256]
Definition: print.c:5
static const char * proc
Definition: stats.c:21
char data[12]
Definition: iconv.c:80
#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
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static objects::SAnnotSelector GetAnnotSelector(TAnnotFlags flags=0)
request an annotation selector for a given type
Definition: utils.cpp:167
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
void Cancel()
Definition: job_adapter.cpp:48
const T & GetData()
Definition: job_adapter.hpp:84
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
virtual bool IsCanceled(void) const =0
END_EVENT_TABLE()
static int input()
const struct ncbi::grid::netcache::search::fields::SIZE size
else result
Definition: token2.c:20
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Wed Apr 17 13:09:52 2024 by modify_doxy.py rev. 669887