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

Go to the SVN repository for this file.

1 /* $Id: gassembly_other_panel.cpp 47029 2022-05-16 18:09:35Z 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>
40 #include <objmgr/bioseq_ci.hpp>
41 #include <objmgr/seqdesc_ci.hpp>
45 
46 #include <wx/sizer.h>
47 #include <wx/scrolwin.h>
48 #include <wx/stattext.h>
49 #include <wx/textctrl.h>
50 #include <wx/combobox.h>
51 #include <wx/icon.h>
52 
54 
55 /*
56  * CGAssemblyOtherPanel type definition
57  */
58 
59 IMPLEMENT_DYNAMIC_CLASS( CGAssemblyOtherPanel, wxPanel )
60 
61 
62 /*
63  * CGAssemblyOtherPanel event table definition
64  */
65 
66 BEGIN_EVENT_TABLE( CGAssemblyOtherPanel, wxPanel )
67 
68 ////@begin CGAssemblyOtherPanel event table entries
69  EVT_HYPERLINK( ID_SEQTECHHYPERLINK, CGAssemblyOtherPanel::OnAddNewSeqtechnology )
70  EVT_HYPERLINK(ID_DELETESEQTECH, CGAssemblyOtherPanel::OnDeleteSeqtechnology)
71 ////@end CGAssemblyOtherPanel event table entries
72 
74 
75 
76 /*
77  * CGAssemblyOtherPanel constructors
78  */
79 
81 {
82  Init();
83 }
84 
85 CGAssemblyOtherPanel::CGAssemblyOtherPanel( wxWindow* parent, ICommandProccessor* cmdproc, objects::CSeq_entry_Handle seh, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 : m_CmdProcessor(cmdproc), m_Seh(seh)
87 {
88  Init();
89  Create(parent, id, pos, size, style);
90 }
91 
92 
93 /*
94  * CGAssemblyOtherPanel creator
95  */
96 
97 bool CGAssemblyOtherPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
98 {
99 ////@begin CGAssemblyOtherPanel creation
100  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
101  wxPanel::Create( parent, id, pos, size, style );
102 
103  CreateControls();
104  if (GetSizer())
105  {
106  GetSizer()->SetSizeHints(this);
107  }
108  Centre();
109 ////@end CGAssemblyOtherPanel creation
110  return true;
111 }
112 
113 
114 /*
115  * CGAssemblyOtherPanel destructor
116  */
117 
119 {
120 ////@begin CGAssemblyOtherPanel destruction
121 ////@end CGAssemblyOtherPanel destruction
122 }
123 
124 
125 /*
126  * Member initialisation
127  */
128 
130 {
131 ////@begin CGAssemblyOtherPanel member initialisation
134  m_Sizer = NULL;
135 ////@end CGAssemblyOtherPanel member initialisation
136 }
137 
138 
139 /*
140  * Control creation for CGAssemblyOtherPanel
141  */
142 
144 {
145 ////@begin CGAssemblyOtherPanel content construction
146  CGAssemblyOtherPanel* itemPanel1 = this;
147 
148  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
149  itemPanel1->SetSizer(itemBoxSizer2);
150 
151  wxFlexGridSizer* itemFlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
152  itemBoxSizer2->Add(itemFlexGridSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
153 
154  wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Genome coverage"), wxDefaultPosition, wxDefaultSize, 0 );
155  itemFlexGridSizer2->Add(itemStaticText6, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
156 
157  m_GenomeCoverage = new wxTextCtrl( itemPanel1, ID_GENOMECOVERAGE, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
159  m_GenomeCoverage->SetToolTip(_("The estimated base coverage across the genome, eg 12x. This can be calculated by dividing the number of bases sequenced by the expected genome size and multiplying that by the percentage of bases that were placed in the final assembly. More simply it is the number of bases sequenced divided by the expected genome size."));
160  itemFlexGridSizer2->Add(m_GenomeCoverage, 0, wxALIGN_LEFT |wxALIGN_CENTER_VERTICAL|wxALL, 5);
161 
162  itemFlexGridSizer2->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
163 
164  wxStaticText* itemStaticText1 = new wxStaticText( itemPanel1, wxID_STATIC, _("Sequencing technology"), wxDefaultPosition, wxDefaultSize, 0 );
165  itemFlexGridSizer2->Add(itemStaticText1, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  m_ScrolledWindow = new wxScrolledWindow( itemPanel1, ID_SEQTECHSCROLLEDWND, wxDefaultPosition, wxSize(256, 92), wxTAB_TRAVERSAL );
168  itemFlexGridSizer2->Add(m_ScrolledWindow, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
169  m_ScrolledWindow->SetScrollbars(1, 1, 0, 0);
170  m_Sizer = new wxFlexGridSizer(0, 2, 0, 0);
171  m_ScrolledWindow->SetSizer(m_Sizer);
172 
173  for (size_t index = 0; index < m_Rows; ++index) {
174  x_AddEmptyRow();
175  }
176  wxHyperlinkCtrl* itemHyperlinkCtrl2 = new wxHyperlinkCtrl( itemPanel1, ID_SEQTECHHYPERLINK, _("Add another sequencing technology"), wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
177  itemFlexGridSizer2->Add(itemHyperlinkCtrl2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
178 
179 ////@end CGAssemblyOtherPanel content construction
180 }
181 
183 {
184  wxArrayString m_SeqTechnologyStrings;
185  m_SeqTechnologyStrings.Add(_("ABI3730"));
186  m_SeqTechnologyStrings.Add(_("Sanger"));
187  m_SeqTechnologyStrings.Add(_("454"));
188  m_SeqTechnologyStrings.Add(_("Illumina"));
189  m_SeqTechnologyStrings.Add(_("Illumina GAII"));
190  m_SeqTechnologyStrings.Add(_("Illumina GAIIx"));
191  m_SeqTechnologyStrings.Add(_("Illumina HiSeq"));
192  m_SeqTechnologyStrings.Add(_("Illumina iSeq"));
193  m_SeqTechnologyStrings.Add(_("Illumina MiniSeq"));
194  m_SeqTechnologyStrings.Add(_("Illumina MiSeq"));
195  m_SeqTechnologyStrings.Add(_("Illumina NextSeq"));
196  m_SeqTechnologyStrings.Add(_("Illumina NovaSeq"));
197  m_SeqTechnologyStrings.Add(_("IonTorrent"));
198  m_SeqTechnologyStrings.Add(_("Oxford Nanopore"));
199  m_SeqTechnologyStrings.Add(_("Oxford Nanopore GridION"));
200  m_SeqTechnologyStrings.Add(_("Oxford Nanopore MiniION"));
201  m_SeqTechnologyStrings.Add(_("Oxford Nanopore PromethION"));
202  m_SeqTechnologyStrings.Add(_("PacBio"));
203  m_SeqTechnologyStrings.Add(_("PacBio RS"));
204  m_SeqTechnologyStrings.Add(_("PacBio RSII"));
205  m_SeqTechnologyStrings.Add(_("PacBio Sequel"));
206  m_SeqTechnologyStrings.Add(_("Helicos"));
207  m_SeqTechnologyStrings.Add(_("SOLiD"));
208  m_SeqTechnologyStrings.Add(_("Complete Genomics"));
209  wxComboBox* row = new wxComboBox(m_ScrolledWindow, ID_SEQTECHCOMBOBOX, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_SeqTechnologyStrings, wxCB_DROPDOWN);
210 #ifdef __WXOSX_COCOA__
211  row->SetSelection(-1);
212 #endif
214  row->SetToolTip(_("The sequencing machine(s) used to generate the data, eg Illumina MiSeq or 454. Select the sequencing technology from the pulldown list, or type the name of the technology directly in the box."));
215 
216  if (m_RowHeight == 0) {
217  int row_width;
218  row->GetClientSize(&row_width, &m_RowHeight);
219  }
220  x_AddRowToWindow(row);
221 }
222 
224 {
225  m_Sizer->Add(row, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 0);
226  wxHyperlinkCtrl* itemHyperLink = new CNoTabHyperlinkCtrl(m_ScrolledWindow, ID_DELETESEQTECH, wxT("Delete"), wxT("delete"));
227  itemHyperLink->SetVisitedColour(itemHyperLink->GetNormalColour());
228  m_Sizer->Add(itemHyperLink, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 0);
229 
230 #ifdef __WXMSW__
231  m_ScrolledWindow->SetScrollRate(0, m_RowHeight);
232  m_ScrolledWindow->FitInside();
233  m_ScrolledWindow->Refresh();
234 #else
235  int row_width, row_height;
236  row->GetClientSize(&row_width, &row_height);
237 
238  int link_width, link_height;
239  itemHyperLink->GetClientSize(&link_width, &link_height);
240  if (link_height > row_height) {
241  row_height = link_height;
242  }
243  row_width += link_width;
244 
245  if (row_width > m_TotalWidth) {
246  m_TotalWidth = row_width;
247  }
248 
249  m_TotalHeight += row_height;
250  m_ScrollRate = row_height;
251 
252  m_ScrolledWindow->SetVirtualSize(m_TotalWidth, m_TotalHeight);
253  m_ScrolledWindow->SetScrollRate(0, m_ScrollRate);
254  m_ScrolledWindow->FitInside();
255  m_ScrolledWindow->SetMinSize(wxSize(m_TotalWidth + 20, m_MaxRows * m_ScrollRate));
256  m_ScrolledWindow->Refresh();
257 #endif
258 }
259 
260 /*
261  * Should we show tooltips?
262  */
263 
265 {
266  return true;
267 }
268 
269 /*
270  * Get bitmap resources
271  */
272 
273 wxBitmap CGAssemblyOtherPanel::GetBitmapResource( const wxString& name )
274 {
275  // Bitmap retrieval
276 ////@begin CGAssemblyOtherPanel bitmap retrieval
277  wxUnusedVar(name);
278  return wxNullBitmap;
279 ////@end CGAssemblyOtherPanel bitmap retrieval
280 }
281 
282 /*
283  * Get icon resources
284  */
285 
286 wxIcon CGAssemblyOtherPanel::GetIconResource( const wxString& name )
287 {
288  // Icon retrieval
289 ////@begin CGAssemblyOtherPanel icon retrieval
290  wxUnusedVar(name);
291  return wxNullIcon;
292 ////@end CGAssemblyOtherPanel icon retrieval
293 }
294 
295 /*
296  * wxEVT_COMMAND_HYPERLINK event handler for ID_SEQTECHHYPERLINK
297  */
298 
299 void CGAssemblyOtherPanel::OnAddNewSeqtechnology( wxHyperlinkEvent& event )
300 {
301  x_AddEmptyRow();
302  int x, y;
303  m_ScrolledWindow->GetVirtualSize(&x, &y);
304 
305  int xUnit, yUnit;
306  m_ScrolledWindow->GetScrollPixelsPerUnit(&xUnit, &yUnit);
307  m_ScrolledWindow->Scroll(0, y / yUnit);
308 }
309 
310 
311 void CGAssemblyOtherPanel::OnDeleteSeqtechnology(wxHyperlinkEvent& event)
312 {
313  wxWindow *win = dynamic_cast<wxWindow*>(event.GetEventObject());
314  if (!win)
315  return;
316  wxWindowList &children = m_ScrolledWindow->GetChildren();
317  wxWindow *prev = NULL;
318  for (wxWindowList::iterator child = children.begin(); child != children.end(); ++child)
319  {
320  if (*child == win)
321  {
322  wxSizer *sizer = win->GetContainingSizer();
323  win->Destroy();
324  prev->Destroy();
325  m_Sizer->Remove(sizer);
326  m_Sizer->Layout();
327  m_ScrolledWindow->FitInside();
328  break;
329  }
330  prev = *child;
331  }
332 }
333 
334 
335 void CGAssemblyOtherPanel::ApplyUser(objects::CUser_object& user)
336 {
337  m_User.Reset(&user);
339 }
340 
341 
343 {
344  m_GenomeCoverage->SetValue(wxT(""));
345  for (auto it : m_ScrolledWindow->GetChildren()) {
346  wxComboBox* row = dynamic_cast<wxComboBox *>(it);
347  if (row) {
348  row->SetValue(wxT(""));
349  }
350 
351  }
352 }
353 
354 const string kGenomeCoverage = "Genome Coverage";
355 const string kSequencingTechnology = "Sequencing Technology";
357 {
358  x_Reset();
359  if (m_User && m_User->IsSetData()) {
360  for (auto it : m_User->GetData()) {
361  if (it->IsSetLabel() && it->GetLabel().IsStr() &&
362  it->IsSetData() && it->GetData().IsStr()) {
363  const string& label = it->GetLabel().GetStr();
365  m_GenomeCoverage->SetValue(ToWxString(it->GetString()));
366  } else if (NStr::Equal(label, kSequencingTechnology)) {
367  // Set value for sequencing technology
368  vector<string> techs;
369  NStr::Split(it->GetString(), ";", techs);
370  size_t num_rows = 0;
371  for (auto rit : m_ScrolledWindow->GetChildren()) {
372  wxComboBox* row = dynamic_cast<wxComboBox *>(rit);
373  if (row) {
374  num_rows++;
375  }
376  }
377  while (techs.size() > num_rows) {
378  x_AddEmptyRow();
379  num_rows++;
380  }
381  auto s = techs.begin();
382  for (auto rit : m_ScrolledWindow->GetChildren()) {
383  wxComboBox* row = dynamic_cast<wxComboBox *>(rit);
384  if (row) {
385  row->SetValue(*s);
386  s++;
387  if (s == techs.end()) {
388  break;
389  }
390  }
391  }
392  }
393  }
394  }
395  }
396  return true;
397 }
398 
399 
401 {
402  if (m_User) {
403  if (m_GenomeCoverage->IsEmpty()) {
404  m_User->RemoveNamedField(kGenomeCoverage);
405  } else {
406  objects::CUser_field& coverage = m_User->SetField(kGenomeCoverage);
407  coverage.SetData().SetStr(ToStdString(m_GenomeCoverage->GetValue()));
408  }
409 
410  //Get value for Sequencing Technology
411  string tech = kEmptyStr;
412  for (auto it : m_ScrolledWindow->GetChildren()) {
413  wxComboBox* row = dynamic_cast<wxComboBox *>(it);
414  if (row) {
415  string new_val = row->GetValue().ToStdString();
416  if (!new_val.empty()) {
417  tech += ToStdString(new_val);
418  tech += ";";
419  }
420  }
421  }
422  if (!tech.empty()) {
423  // remove trailing semicolon
424  tech = tech.substr(0, tech.length() - 1);
425  }
426  if (tech.empty()) {
427  m_User->RemoveNamedField(kSequencingTechnology);
428  } else {
429  objects::CUser_field& seqtech = m_User->SetField(kSequencingTechnology);
430  seqtech.SetData().SetStr(tech);
431  }
432  // sort fields
433  CConstRef<objects::CComment_set> rules = objects::CComment_set::GetCommentRules();
434  if (rules) {
435  try {
436  const objects::CComment_rule& rule = rules->FindCommentRule("Genome-Assembly-Data");
437  rule.ReorderFields(*m_User);
438  } catch (const CException&) {
439  }
440  }
441  }
442  return true;
443 }
444 
446 {
447  if (!m_User)
448  return;
450 
451  CRef<objects::CUser_object> empty = objects::edit::CStructuredCommentField::MakeUserObject("Genome-Assembly-Data");
452  if (m_User->Equals(*empty))
453  return;
454 
455  CRef<CCmdComposite> cmd(new CCmdComposite("update genome assembly structured comment"));
456  bool any_changes = false;
457 
458  for (objects::CBioseq_CI bi(m_Seh, objects::CSeq_inst::eMol_na); bi; ++bi)
459  {
460  bool found = false;
461  for (objects::CSeqdesc_CI di(*bi, objects::CSeqdesc::e_User); di; ++di)
462  {
463  if (di && di->IsUser() && di->GetUser().GetObjectType() == objects::CUser_object::eObjectType_StructuredComment &&
464  NStr::Equal(objects::CComment_rule::GetStructuredCommentPrefix(di->GetUser()), "Genome-Assembly-Data"))
465  {
466 
467  // edit existing descriptor
468  CRef<objects::CSeqdesc> cpy(new objects::CSeqdesc());
469  cpy->SetUser(*m_User);
470  if (!di->Equals(*cpy))
471  {
472  CRef<CCmdChangeSeqdesc> chg(new CCmdChangeSeqdesc(di.GetSeq_entry_Handle(), *di, *cpy));
473  cmd->AddCommand(*chg);
474  any_changes = true;
475  }
476  found = true;
477  }
478  }
479 
480  if (!found)
481  {
482  // create new source descriptor on this sequence or on the nuc-prot that contains it
483  CRef<objects::CSeqdesc> new_desc(new objects::CSeqdesc());
484  new_desc->SetUser(*m_User);
485  objects::CBioseq_set_Handle parent = bi->GetParentBioseq_set();
486  auto entry = bi->GetParentEntry();
487  if (parent && parent.IsSetClass() && parent.GetClass() == objects::CBioseq_set::eClass_nuc_prot)
488  entry = parent.GetParentEntry();
489  CIRef<IEditCommand> cmdAddDesc(new CCmdCreateDesc(entry, *new_desc));
490  cmd->AddCommand(*cmdAddDesc);
491  any_changes = true;
492  }
493  }
494 
495  if (any_changes)
496  {
498  }
499 }
500 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
void CreateControls()
Creates the controls and sizers.
void ApplyUser(objects::CUser_object &user)
void OnAddNewSeqtechnology(wxHyperlinkEvent &event)
wxEVT_COMMAND_HYPERLINK event handler for ID_SEQTECHHYPERLINK
CGAssemblyOtherPanel()
Constructors.
void x_AddRowToWindow(wxWindow *row)
bool Create(wxWindow *parent, wxWindowID id=ID_CGASSEMBLYOTHERPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnDeleteSeqtechnology(wxHyperlinkEvent &event)
virtual bool TransferDataFromWindow()
ICommandProccessor * m_CmdProcessor
objects::CSeq_entry_Handle m_Seh
wxScrolledWindow * m_ScrolledWindow
CRef< objects::CUser_object > m_User
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
const string kGenomeCoverage
const string kSequencingTechnology
#define NULL
Definition: ncbistd.hpp:225
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
#define kEmptyStr
Definition: ncbistr.hpp:123
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
static const char label[]
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sun Mar 03 03:15:19 2024 by modify_doxy.py rev. 669887