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

Go to the SVN repository for this file.

1 /* $Id: barcode_tool.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34 
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38 
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42 
43 #include <wx/filename.h>
44 #include <wx/hyperlink.h>
45 #include <wx/graphics.h>
46 #include <wx/renderer.h>
47 
49 #include <objects/seq/MolInfo.hpp>
50 
51 #include <objmgr/seq_entry_ci.hpp>
52 #include <objmgr/bioseq_ci.hpp>
53 #include <objmgr/seqdesc_ci.hpp>
54 #include <objmgr/feat_ci.hpp>
55 #include <objmgr/util/sequence.hpp>
59 
63 
67 
72 
73 
76 
77 IMPLEMENT_DYNAMIC_CLASS( CBarcodeTool, wxFrame )
78 
79 BEGIN_EVENT_TABLE( CBarcodeTool, wxFrame )
88 
89 CBarcodeTool::CBarcodeTool( wxWindow* parent, objects::CSeq_entry_Handle seh, ICommandProccessor* cmdProcessor, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
90 : m_CmdProcessor(cmdProcessor), m_TopSeqEntry(seh), m_Workbench(wb)
91 {
92  GetValues();
93  Init();
94  Create(parent, id, caption, pos, size, style);
96 }
97 
99 {
100  wxBusyCursor wait;
101  m_barcode.clear();
102  m_selected.clear();
103  if (m_TopSeqEntry)
104  {
105  objects::CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na);
106  for ( ; b_iter ; ++b_iter )
107  {
108  FindBarcodeFeats(*b_iter);
109  }
110  }
111 }
112 
114 {
115  wxPanel* itemPanel1 = new wxPanel(this, wxID_ANY);
116 
117  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
118  itemPanel1->SetSizer(itemBoxSizer2);
119 
120  wxGridSizer *header = new wxFlexGridSizer(0, 14, 0, 0);
121  itemBoxSizer2->Add(header, 0, wxGROW|wxALL, 5);
122 
123  wxStaticText* itemStaticHeader0 = new wxStaticText( itemPanel1, wxID_STATIC, _(" "), wxDefaultPosition, wxSize(30,-1), 0 );
124  header->Add(itemStaticHeader0, 0, wxALIGN_CENTER|wxALL, 5);
125  wxStaticText* itemStaticHeader1 = new wxStaticText( itemPanel1, wxID_STATIC, _("Barcode ID"), wxDefaultPosition, wxSize(150,-1), 0 );
126  header->Add(itemStaticHeader1, 0, wxALIGN_CENTER|wxALL, 5);
127  wxStaticText* itemStaticHeader2 = new wxStaticText( itemPanel1, wxID_STATIC, _("Genbank Accession"), wxDefaultPosition, wxSize(100,-1), 0 );
128  itemStaticHeader2->Wrap(100);
129  header->Add(itemStaticHeader2, 0, wxALIGN_CENTER|wxALL, 5);
130  wxStaticText* itemStaticHeader3 = new wxStaticText( itemPanel1, wxID_STATIC, _("Length"), wxDefaultPosition, wxSize(80,-1), 0 );
131  header->Add(itemStaticHeader3, 0, wxALIGN_CENTER|wxALL, 5);
132  wxStaticText* itemStaticHeader4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Primers"), wxDefaultPosition, wxSize(80,-1), 0 );
133  header->Add(itemStaticHeader4, 0, wxALIGN_CENTER|wxALL, 5);
134  wxStaticText* itemStaticHeader5 = new wxStaticText( itemPanel1, wxID_STATIC, _("Country"), wxDefaultPosition, wxSize(80,-1), 0 );
135  header->Add(itemStaticHeader5, 0, wxALIGN_CENTER|wxALL, 5);
136  wxStaticText* itemStaticHeader6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Voucher"), wxDefaultPosition, wxSize(80,-1), 0 );
137  header->Add(itemStaticHeader6, 0, wxALIGN_CENTER|wxALL, 5);
138  wxStaticText* itemStaticHeader7 = new wxStaticText( itemPanel1, wxID_STATIC, _("Structured Voucher"), wxDefaultPosition, wxSize(80,-1), 0 );
139  itemStaticHeader7->Wrap(80);
140  header->Add(itemStaticHeader7, 0, wxALIGN_CENTER|wxALL, 5);
141  wxStaticText* itemStaticHeader8 = new wxStaticText( itemPanel1, wxID_STATIC, _("Percent Ns"), wxDefaultPosition, wxSize(80,-1), 0 );
142  itemStaticHeader8->Wrap(80);
143  header->Add(itemStaticHeader8, 0, wxALIGN_CENTER|wxALL, 5);
144  wxStaticText* itemStaticHeader9 = new wxStaticText( itemPanel1, wxID_STATIC, _("Collection Date"), wxDefaultPosition, wxSize(80,-1), 0 );
145  itemStaticHeader9->Wrap(80);
146  header->Add(itemStaticHeader9, 0, wxALIGN_CENTER|wxALL, 5);
147  wxStaticText* itemStaticHeader10 = new wxStaticText( itemPanel1, wxID_STATIC, _("Order Assignment"), wxDefaultPosition, wxSize(80,-1), 0 );
148  itemStaticHeader10->Wrap(80);
149  header->Add(itemStaticHeader10, 0, wxALIGN_CENTER|wxALL, 5);
150  wxStaticText* itemStaticHeader11 = new wxStaticText( itemPanel1, wxID_STATIC, _("Low Trace"), wxDefaultPosition, wxSize(80,-1), 0 );
151  itemStaticHeader11->Wrap(80);
152  header->Add(itemStaticHeader11, 0, wxALIGN_CENTER|wxALL, 5);
153  wxStaticText* itemStaticHeader12 = new wxStaticText( itemPanel1, wxID_STATIC, _("Frame Shift"), wxDefaultPosition, wxSize(80,-1), 0 );
154  itemStaticHeader12->Wrap(80);
155  header->Add(itemStaticHeader12, 0, wxALIGN_CENTER|wxALL, 5);
156  wxStaticText* itemStaticHeader13 = new wxStaticText( itemPanel1, wxID_STATIC, _("Has BARCODE Keyword"), wxDefaultPosition, wxSize(80,-1), 0 );
157  itemStaticHeader13->Wrap(80);
158  header->Add(itemStaticHeader13, 0, wxALIGN_CENTER|wxALL, 5);
159 
160 
161  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
162  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);
163 
164  m_scrolled = new CBarcodePanel(itemPanel1, &m_barcode, &m_selected, wxID_ANY, wxDefaultPosition, wxSize(-1, 170));
165  itemBoxSizer3->Add(m_scrolled, 1, wxGROW|wxALL, 0);
166 
167  wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxHORIZONTAL);
168  itemBoxSizer2->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
169 
170 
171  wxArrayString radioboxStrings;
172  radioboxStrings.Add(_("Check features where"));
173  radioboxStrings.Add(_("Uncheck features where"));
174  m_Radiobox = new wxRadioBox( itemPanel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, radioboxStrings, 0, wxRA_SPECIFY_ROWS );
175  m_Radiobox->SetSelection(0);
176  itemBoxSizer17->Add(m_Radiobox, 0, wxALIGN_TOP|wxRIGHT|wxLEFT, 5);
177 
178  wxArrayString choice_strings;
179  choice_strings.Add(_("Barcode ID"));
180  choice_strings.Add(_("Genbank Accession"));
181  choice_strings.Add(_("Percent Ns"));
182  m_Choice = new wxChoice( itemPanel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, choice_strings, 0 );
183  m_Choice->SetSelection(0);
184  itemBoxSizer17->Add(m_Choice, 0, wxALIGN_TOP|wxALL, 7);
185 
186  m_StringConstraintPanel = new CStringConstraintPanel( itemPanel1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
187  itemBoxSizer17->Add(m_StringConstraintPanel, 0, wxALIGN_TOP|wxALL|wxFIXED_MINSIZE, 0);
189 
190 
191  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
192  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
193 
194  wxButton* itemButton13 = new wxButton(itemPanel1, ID_BARCODE_TOOL_SELECT, _("Select"), wxDefaultPosition, wxDefaultSize, 0);
195  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
196 
197  wxButton* itemButton14 = new wxButton(itemPanel1, ID_BARCODE_TOOL_SELECT_ALL, _("Select All"), wxDefaultPosition, wxDefaultSize, 0);
198  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
199 
200  wxButton* itemButton15 = new wxButton(itemPanel1, ID_BARCODE_TOOL_UNSELECT_ALL, _("Unselect All"), wxDefaultPosition, wxDefaultSize, 0);
201  itemBoxSizer12->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
202 
203  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
204  itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
205 
206  wxButton* itemButton16 = new wxButton( itemPanel1, ID_BARCODE_TOOL_APPLY_DBXREFS, _("Apply Dbxrefs"), wxDefaultPosition, wxDefaultSize, 0 );
207  itemBoxSizer16->Add(itemButton16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
208 
209  wxButton* itemButton17 = new wxButton( itemPanel1, ID_BARCODE_TOOL_REMOVE_KEYWORD, _("Remove BARCODE Keyword from Selected"), wxDefaultPosition, wxDefaultSize, 0 );
210  itemBoxSizer16->Add(itemButton17, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
211 
212  wxButton* itemButton18 = new wxButton( itemPanel1, ID_BARCODE_TOOL_ADD_KEYWORD, _("Add BARCODE Keyword to BARCODE Tech"), wxDefaultPosition, wxDefaultSize, 0 );
213  itemBoxSizer16->Add(itemButton18, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
214 
215  wxButton* itemButton19 = new wxButton( itemPanel1, ID_BARCODE_TOOL_DISMISS, _("Dismiss"), wxDefaultPosition, wxDefaultSize, 0 );
216  itemBoxSizer16->Add(itemButton19, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
217 
218 
219 }
220 
221 
222 
224 {
225  bool has_keyword(false);
226  for (CSeqdesc_CI desc_ci(bsh, CSeqdesc::e_Genbank); desc_ci; ++desc_ci)
227  {
228  FOR_EACH_KEYWORD_ON_GENBANKBLOCK(qual_it, desc_ci->GetGenbank())
229  {
230  const string &keyword = *qual_it;
231  if (NStr::EqualNocase(keyword, "BARCODE"))
232  has_keyword = true;
233  }
234  }
235  return has_keyword;
236 }
237 
238 
240 {
241  if (!validator::IsTechBarcode(bsh))
242  return;
243 
244  validator::SBarcode b;
245 
246  // After propagation, call this:
247  // remember to remove all the copy-pasted code as well
250  m_barcode.push_back(b);
251  }
252 }
253 
254 
255 void CBarcodeTool::OnSelectAll( wxCommandEvent& event )
256 {
257  m_selected.clear();
258  std::set<int>::iterator it = m_selected.end();
259  for (size_t i = 0; i < m_barcode.size(); i++)
260  it = m_selected.insert(it, static_cast<int>(i));
261  m_scrolled->Refresh();
262 }
263 
264 void CBarcodeTool::OnUnselectAll( wxCommandEvent& event )
265 {
266  m_selected.clear();
267  m_scrolled->Refresh();
268 }
269 
270 void CBarcodeTool::OnSelect( wxCommandEvent& event )
271 {
272  bool select = m_Radiobox->GetSelection() == 0;
273  string choice = m_Choice->GetStringSelection().ToStdString();
275  if (!constraint)
276  return;
277  for (size_t i = 0; i < m_barcode.size(); i++)
278  {
279  string value;
280  if (choice =="Barcode ID")
281  {
282  value = m_barcode[i].barcode;
283  }
284  else if (choice == "Genbank Accession")
285  {
286  value = m_barcode[i].genbank;
287  }
288  else if (choice == "Percent Ns")
289  {
290  value = m_barcode[i].percent_n;
291  }
292  if (value.empty())
293  continue;
294  if (constraint->DoesTextMatch(value))
295  {
296  if (select)
297  {
298  m_selected.insert(static_cast<int>(i));
299  }
300  else
301  {
302  m_selected.erase(static_cast<int>(i));
303  }
304  }
305  }
306  m_scrolled->Refresh();
307 }
308 
310 {
311  if (m_selected.find(i) == m_selected.end())
313  else
314  m_selected.erase(i);
315  m_scrolled->Refresh();
316 }
317 
319 {
320 }
321 
322 
323 bool CBarcodeTool::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
324 {
325  wxFrame::Create( parent, id, caption, pos, size, style );
326  CreateControls();
327  if (GetSizer())
328  {
329  GetSizer()->SetSizeHints(this);
330  }
331  Centre();
332  return true;
333 }
334 
335 void CBarcodeTool::OnDismiss( wxCommandEvent& event )
336 {
337  Close();
338 }
339 
340 void CBarcodeTool::OnAddKeyword( wxCommandEvent& event ) // Add BARCODE keyword should act on all bioseqs (not only those in the window) which have tech = barcode
341 {
342  CRef<CCmdComposite> cmd(new CCmdComposite("Add BARCODE Keyword"));
343  objects::CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na);
344  for ( ; b_iter ; ++b_iter )
345  {
346  CBioseq_Handle bsh = *b_iter;
347 
348  if (!validator::IsTechBarcode(bsh))
349  continue;
350  if (GetHasKeyword(bsh))
351  continue;
352 
353  CSeqdesc_CI desc_ci(bsh, CSeqdesc::e_Genbank);
354  if (desc_ci)
355  {
356  CRef<CSeqdesc> new_desc(new CSeqdesc);
357  new_desc->Assign(*desc_ci);
358  new_desc->SetGenbank().SetKeywords().push_back("BARCODE");
359  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(desc_ci.GetSeq_entry_Handle(), *desc_ci, *new_desc));
360  cmd->AddCommand(*ecmd);
361  }
362  else
363  {
365  CRef<CSeqdesc> new_desc(new CSeqdesc);
366  new_desc->SetGenbank().SetKeywords().push_back("BARCODE");
367  cmd->AddCommand( *CRef<CCmdCreateDesc>(new CCmdCreateDesc(seh, *new_desc)) );
368  }
369  }
371  GetValues();
372  m_scrolled->Refresh();
373 }
374 
375 void CBarcodeTool::OnRemoveKeyword( wxCommandEvent& event ) // remove BARCODE keyword should act on selected bioseqs. If nothing is selected it should ask if all should be selected. Acts only on bioseqs in the window.
376 {
377  bool selected_all(false);
378  if (m_selected.empty())
379  {
380  int answer = wxMessageBox(_("You have not selected any Bioseqs - remove BARCODE keyword from all?"), wxT("Remove from all"), wxYES_NO | wxICON_QUESTION, this);
381  if (answer == wxYES)
382  {
383  m_selected.clear();
384  std::set<int>::iterator it = m_selected.end();
385  for (size_t i = 0; i < m_barcode.size(); i++)
386  it = m_selected.insert(it, static_cast<int>(i));
387  selected_all = true;
388  }
389  else
390  {
391  return;
392  }
393  }
394 
395  CRef<CCmdComposite> cmd(new CCmdComposite("Remove BARCODE Keyword"));
396  for (set<int>::iterator j = m_selected.begin(); j != m_selected.end(); ++j)
397  {
398  int i = *j;
399  if (!m_barcode[i].has_keyword)
400  continue;
401  CBioseq_Handle bsh = m_barcode[i].bsh;
402  CSeqdesc_CI desc_ci(bsh, CSeqdesc::e_Genbank);
403  if (desc_ci)
404  {
405  CRef<CSeqdesc> new_desc(new CSeqdesc);
406  new_desc->Assign(*desc_ci);
407  EDIT_EACH_KEYWORD_ON_GENBANKBLOCK(qual_it, new_desc->SetGenbank())
408  {
409  const string &keyword = *qual_it;
410  if (NStr::EqualNocase(keyword, "BARCODE"))
411  ERASE_KEYWORD_ON_GENBANKBLOCK(qual_it, new_desc->SetGenbank());
412  }
413  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(desc_ci.GetSeq_entry_Handle(), *desc_ci, *new_desc));
414  cmd->AddCommand (*ecmd);
415  }
416  }
418 // When using remove BARCODE button a report should be presented
419  ShowReport();
420  if (selected_all)
421  {
422  m_selected.clear();
423  }
424  GetValues();
425  m_scrolled->Refresh();
426 }
427 
429 {
430  string msg;
431  for (set<int>::iterator j = m_selected.begin(); j != m_selected.end(); ++j)
432  {
433  int i = *j;
434 
435  const validator::SBarcode &b = m_barcode[i];
436  msg += b.barcode;
437  msg += "\t";
438  msg += b.genbank;
439 
440  vector<string> values;
441  if (b.length)
442  values.push_back("Too Short");
443  if (b.primers)
444  values.push_back("Missing Primers");
445  if (b.country)
446  values.push_back("Missing Country");
447  if (b.voucher)
448  values.push_back("Missing Voucher");
449  if (b.structured_voucher)
450  values.push_back("Structured Voucher");
451  if (!b.percent_n.empty())
452  values.push_back("Too Many Ns:"+b.percent_n+"%");
453  if (b.collection_date)
454  values.push_back("Bad Collection Date");
455  if (b.order_assignment)
456  values.push_back("Missing Order Assignment");
457  if (b.low_trace)
458  values.push_back("Low Trace");
459  if (b.frame_shift)
460  values.push_back("Frame Shift");
461 
462  msg += "\t";
463  msg += NStr::Join(values, ",");
464  msg += "\n";
465  }
466 
467  if (!msg.empty())
468  {
469  CGenericReportDlg* report = new CGenericReportDlg(this);
470  report->SetTitle(wxT("BARCODE Keywords Removed"));
471  report->SetText(wxString(msg));
472  report->Show(true);
473  }
474 }
475 
476 void CBarcodeTool::OnApplyDbxrefs( wxCommandEvent& event ) // apply dbxrefs should act on all bioseqs
477 {
480 }
481 
483 {
484  CRef<CCmdComposite> cmd(new CCmdComposite("Apply Dbxrefs"));
485 
486  for ( objects::CBioseq_CI b_iter(seh, objects::CSeq_inst::eMol_na); b_iter ; ++b_iter )
487  {
488  CBioseq_Handle bsh = *b_iter;
489 
490  string barcode;
491  for (CBioseq_Handle::TId::const_iterator it = bsh.GetId().begin(); it != bsh.GetId().end(); ++it)
492  {
493  const CSeq_id &id = *(it->GetSeqId());
494  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && NStr::EqualNocase(id.GetGeneral().GetDb(), "uoguelph") && id.GetGeneral().IsSetTag())
495  {
496  const CObject_id &obj_id = id.GetGeneral().GetTag();
497  if (obj_id.IsStr())
498  barcode = obj_id.GetStr();
499  if (obj_id.IsId())
500  barcode = NStr::IntToString(obj_id.GetId());
501  }
502  }
503 
504  if (barcode.empty())
505  continue;
506 
507  for (CSeqdesc_CI source_ci(bsh, CSeqdesc::e_Source); source_ci; ++source_ci)
508  {
509  bool found(false);
510  if (source_ci->GetSource().IsSetOrg())
511  {
512  FOR_EACH_DBXREF_ON_ORGREF(dbxref, source_ci->GetSource().GetOrg())
513  {
514  if ((*dbxref)->IsSetDb() && (*dbxref)->GetDb() == "BOLD" && (*dbxref)->IsSetTag())
515  {
516  string tag;
517  const CObject_id &obj_id = (*dbxref)->GetTag();
518  if (obj_id.IsStr())
519  tag = obj_id.GetStr();
520  if (obj_id.IsId())
521  tag = NStr::IntToString(obj_id.GetId());
522  if (tag == barcode)
523  found = true;
524  }
525  }
526  }
527  if (!found)
528  {
529  CRef<CSeqdesc> new_desc(new CSeqdesc);
530  new_desc->Assign(*source_ci);
531  CRef< CDbtag > dbtag(new CDbtag);
532  dbtag->SetDb("BOLD");
533  dbtag->SetTag().SetStr(barcode);
534  new_desc->SetSource().SetOrg().SetDb().push_back(dbtag);
535  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(source_ci.GetSeq_entry_Handle(), *source_ci, *new_desc));
536  cmd->AddCommand (*ecmd);
537  }
538  }
539  }
540  return cmd;
541 }
542 
543 void CBarcodeTool::ClickLink( int i ) // Clicking on record should take the user to that record in sequin
544 {
545  CBioseq_Handle bsh = m_barcode[i].bsh;
547  string accession;
548  int version;
549  best.GetSeqId()->GetLabel(&accession, &version, CSeq_id::eContent);
551  if (!srv) return;
552  CIRef<IProjectView> pTextView(srv->FindView(*m_TopSeqEntry.GetObjectCore(), "Text View"));
553  CIRef<IFlatFileCtrl> FlatFileCtrl(dynamic_cast<IFlatFileCtrl*>(pTextView.GetPointer()));
554 
555  if (FlatFileCtrl)
556  {
557  FlatFileCtrl->SetPosition(bsh, bsh.GetBioseqCore().GetPointer());
558  }
559 }
560 
561 
562 
563 
564 IMPLEMENT_DYNAMIC_CLASS( CBarcodePanel, wxVScrolledWindow )
565 
566 
567 BEGIN_EVENT_TABLE(CBarcodePanel, wxVScrolledWindow)
568  EVT_PAINT(CBarcodePanel::OnPaint)
569  EVT_ERASE_BACKGROUND(CBarcodePanel::OnEraseBackground)
570  EVT_SIZE(CBarcodePanel::OnResize)
571  EVT_LEFT_DOWN(CBarcodePanel::OnMouseClick)
573 
574 
575 CBarcodePanel::CBarcodePanel(wxWindow *parent, validator::TBarcodeResults *barcode, set<int> *selected,
576  wxWindowID id, const wxPoint &pos, const wxSize &size)
577 : wxVScrolledWindow(parent,id, pos, size, wxFULL_REPAINT_ON_RESIZE), m_barcode(barcode), m_selected(selected)
578 {
579  SetBackgroundStyle(wxBG_STYLE_PAINT);
580  wxGraphicsContext *gc = wxGraphicsContext::Create();
581  gc->SetFont(GetFont(), *wxBLACK);
582  wxDouble width;
583  wxDouble height;
584  wxDouble descent;
585  wxDouble externalLeading;
586  gc->GetTextExtent(_("A"), &width, &height, &descent, &externalLeading);
587  m_RowHeight = ceil(height) + 3;
588  delete gc;
589  SetRowCount(m_barcode->size());
590 }
591 
592 wxCoord CBarcodePanel::OnGetRowHeight( size_t row ) const
593 {
594  return m_RowHeight;
595 }
596 
598 {
599 }
600 
601 
602 // Empty implementation, to prevent flicker
603 void CBarcodePanel::OnEraseBackground(wxEraseEvent& event)
604 {
605 }
606 
607 ////////////////////////////////////////////////////////////
608 /// Notification for the derived class that moment is good
609 /// for doing its update and drawing stuff
610 ////////////////////////////////////////////////////////////
612 {
613 }
614 
615 void CBarcodePanel::OnResize(wxSizeEvent& event)
616 {
617 }
618 
619 void CBarcodePanel::OnPaint(wxPaintEvent& event)
620 {
621  wxAutoBufferedPaintDC dc(this);
622 
623  wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
624  wxColour backgroundColour = GetBackgroundColour();
625  if (!backgroundColour.Ok())
626  backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
627  wxSize sz = GetClientSize();
628  wxRect windowRect(wxPoint(0,0), sz);
629  gc->SetBrush(wxBrush(backgroundColour));
630  gc->SetPen(wxPen(backgroundColour, 1));
631  gc->DrawRectangle(windowRect.GetX(),windowRect.GetY(),windowRect.GetWidth(),windowRect.GetHeight());
632  delete gc;
633 
634  m_checkboxes.clear();
635  m_links.clear();
636  if (!m_barcode || !m_selected || m_barcode->empty())
637  return;
638  SetRowCount(m_barcode->size());
639  auto start = GetVisibleRowsBegin();
640  auto stop = GetVisibleRowsEnd();
641  if (start >= m_barcode->size())
642  start = m_barcode->size() - 1;
643  if (stop >= m_barcode->size())
644  stop = m_barcode->size() - 1;
645 
646  wxRendererNative &renderer = wxRendererNative::Get();
647  wxRect rect(wxPoint(5, 5), renderer.GetCheckBoxSize(this));
648  for (size_t i = start; i <= stop; i++)
649  {
650  renderer.DrawCheckBox(this, dc, rect, m_selected->find(static_cast<int>(i)) != m_selected->end() ? wxCONTROL_CHECKED : 0);
651  m_checkboxes.push_back(pair<size_t, wxRect>(i, rect));
652  rect.x += 30 + 10;
653 
654  const validator::SBarcode &b = (*m_barcode)[i];
655  rect.width += 150;
656  dc.DrawLabel(wxString(b.barcode), rect);
657  rect.x += 150 + 10;
658  rect.width -= 150;
659 
660 
661  rect.width += 100;
662  dc.DrawLabel(wxString(b.genbank), rect);
663  m_links.push_back(pair<size_t, wxRect>(i, rect));
664  rect.x += 100 + 10;
665  rect.width -= 100;
666 
667  renderer.DrawCheckBox(this, dc, rect, b.length ? wxCONTROL_CHECKED : 0);
668  rect.x += 80 + 10;
669 
670  renderer.DrawCheckBox(this, dc, rect, b.primers ? wxCONTROL_CHECKED : 0);
671  rect.x += 80 + 10;
672 
673  renderer.DrawCheckBox(this, dc, rect, b.country ? wxCONTROL_CHECKED : 0);
674  rect.x += 80 + 10;
675 
676  renderer.DrawCheckBox(this, dc, rect, b.voucher ? wxCONTROL_CHECKED : 0);
677  rect.x += 80 + 10;
678 
679  renderer.DrawCheckBox(this, dc, rect, b.structured_voucher ? wxCONTROL_CHECKED : 0);
680  rect.x += 80 + 10;
681 
682  rect.width += 80;
683  dc.DrawLabel(wxString(b.percent_n), rect);
684  rect.x += 80 + 10;
685  rect.width -= 80;
686 
687  renderer.DrawCheckBox(this, dc, rect, b.collection_date ? wxCONTROL_CHECKED : 0);
688  rect.x += 80 + 10;
689 
690  renderer.DrawCheckBox(this, dc, rect, b.order_assignment ? wxCONTROL_CHECKED : 0);
691  rect.x += 80 + 10;
692 
693  renderer.DrawCheckBox(this, dc, rect, b.low_trace ? wxCONTROL_CHECKED : 0);
694  rect.x += 80 + 10;
695 
696  renderer.DrawCheckBox(this, dc, rect, b.frame_shift ? wxCONTROL_CHECKED : 0);
697  rect.x += 80 + 10;
698 
699  renderer.DrawCheckBox(this, dc, rect, b.has_keyword ? wxCONTROL_CHECKED : 0);
700  rect.x += 80 + 10;
701 
702  rect.y += m_RowHeight;
703  rect.x = 5;
704  }
705 }
706 
707 void CBarcodePanel::OnMouseClick(wxMouseEvent& evt)
708 {
709  wxPoint p = evt.GetPosition();
710  wxWindow *win = GetGrandParent();
711  CBarcodeTool *parent = dynamic_cast<CBarcodeTool *>(win);
712  if (!parent)
713  {
714  evt.Skip();
715  return;
716  }
717  bool found(false);
718  for (size_t k = 0; k < m_checkboxes.size(); k++)
719  {
720  if (m_checkboxes[k].second.Contains(p))
721  {
722  auto i = m_checkboxes[k].first;
723  parent->CheckRow(static_cast<int>(i));
724  found = true;
725  break;
726  }
727  }
728 
729  if (!found)
730  {
731  for (size_t k = 0; k < m_links.size(); k++)
732  {
733  if (m_links[k].second.Contains(p))
734  {
735  auto i = m_links[k].first;
736  parent->ClickLink(static_cast<int>(i));
737  found = true;
738  break;
739  }
740  }
741  }
742 
743  evt.Skip();
744 }
745 
746 
747 CRef<CCmdComposite> CApplyFBOL::apply(objects::CSeq_entry_Handle seh)
748 {
749  CRef<CCmdComposite> cmd(new CCmdComposite("Apply FBOL Dbxrefs"));
750  objects::CBioseq_CI b_iter(seh, objects::CSeq_inst::eMol_na);
751  for ( ; b_iter ; ++b_iter )
752  {
753  CBioseq_Handle bsh = *b_iter;
754 
755  string fbol;
756  for (CBioseq_Handle::TId::const_iterator it = bsh.GetId().begin(); it != bsh.GetId().end(); ++it)
757  {
758  const CSeq_id &id = *(it->GetSeqId());
759  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && NStr::EqualNocase(id.GetGeneral().GetDb(), "FBOL") && id.GetGeneral().IsSetTag())
760  {
761  const CObject_id &obj_id = id.GetGeneral().GetTag();
762  if (obj_id.IsStr())
763  fbol = obj_id.GetStr();
764  if (obj_id.IsId())
765  fbol = NStr::IntToString(obj_id.GetId());
766  }
767  }
768 
769  if (fbol.empty())
770  continue;
771 
772  for (CSeqdesc_CI source_ci(bsh, CSeqdesc::e_Source); source_ci; ++source_ci)
773  {
774  bool found(false);
775  if (source_ci->GetSource().IsSetOrg())
776  {
777  FOR_EACH_DBXREF_ON_ORGREF(dbxref, source_ci->GetSource().GetOrg())
778  {
779  if ((*dbxref)->IsSetDb() && (*dbxref)->GetDb() == "FBOL")
780  {
781  found = true;
782  }
783  }
784  }
785  if (!found)
786  {
787  CRef<CSeqdesc> new_desc(new CSeqdesc);
788  new_desc->Assign(*source_ci);
789  CRef< CDbtag > dbtag(new CDbtag);
790  dbtag->SetDb("FBOL");
791  dbtag->SetTag().SetStr(fbol);
792  new_desc->SetSource().SetOrg().SetDb().push_back(dbtag);
793  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(source_ci.GetSeq_entry_Handle(), *source_ci, *new_desc));
794  cmd->AddCommand (*ecmd);
795  }
796  }
797  }
798  return cmd;
799 }
800 
User-defined methods of the data storage class.
USING_SCOPE(ncbi::objects)
#define ID_BARCODE_TOOL_DISMISS
#define ID_BARCODE_TOOL_APPLY_DBXREFS
#define ID_BARCODE_TOOL_REMOVE_KEYWORD
#define ID_BARCODE_TOOL_UNSELECT_ALL
#define ID_BARCODE_TOOL_SELECT
#define ID_BARCODE_TOOL_ADD_KEYWORD
#define ID_BARCODE_TOOL_SELECT_ALL
static CRef< CCmdComposite > apply(objects::CSeq_entry_Handle seh)
void OnResize(wxSizeEvent &)
vector< pair< size_t, wxRect > > m_links
virtual void OnPaint(wxPaintEvent &event)
void OnMouseClick(wxMouseEvent &evt)
virtual ~CBarcodePanel()
set< int > * m_selected
vector< pair< size_t, wxRect > > m_checkboxes
virtual void OnUpdate()
Notification for the derived class that moment is good for doing its update and drawing stuff.
virtual wxCoord OnGetRowHeight(size_t row) const
validator::TBarcodeResults * m_barcode
virtual void OnEraseBackground(wxEraseEvent &event)
validator::TBarcodeResults m_barcode
void ShowReport(void)
void OnApplyDbxrefs(wxCommandEvent &event)
bool GetHasKeyword(CBioseq_Handle bsh)
void OnSelectAll(wxCommandEvent &event)
wxChoice * m_Choice
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("BARCODE Discrepancy Tool"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1350, 470), long style=wxCAPTION|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL|wxBG_STYLE_PAINT)
void ClickLink(int i)
void CheckRow(int i)
CStringConstraintPanel * m_StringConstraintPanel
static CRef< CCmdComposite > ApplyDbxrefs(CSeq_entry_Handle seh)
set< int > m_selected
IWorkbench * m_Workbench
ICommandProccessor * m_CmdProcessor
void CreateControls()
void OnDismiss(wxCommandEvent &event)
CBarcodePanel * m_scrolled
void GetValues(void)
virtual void Init()
void OnRemoveKeyword(wxCommandEvent &event)
wxRadioBox * m_Radiobox
void OnUnselectAll(wxCommandEvent &event)
void FindBarcodeFeats(CBioseq_Handle bsh)
void OnAddKeyword(wxCommandEvent &event)
CSeq_entry_Handle m_TopSeqEntry
void OnSelect(wxCommandEvent &event)
CBioseq_Handle –.
Definition: Dbtag.hpp:53
void SetText(const wxString &text)
CProjectService - a service providing API for operations with Workspaces and Projects.
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
void SetStringSelection(const wxString &str)
CRef< edit::CStringConstraint > GetStringConstraint()
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
CConstRef< CSeq_id > GetSeqId(void) const
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
TBioseqCore GetBioseqCore(void) const
Get bioseq core structure.
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CConstRef< TObject > GetObjectCore(void) const
const TId & GetId(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Definition: seqdesc_ci.cpp:326
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
TKeywords & SetKeywords(void)
Assign a value to Keywords data member.
Definition: GB_block_.hpp:532
void SetOrg(TOrg &value)
Assign a value to Org data member.
Definition: BioSource_.cpp:108
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
void SetTag(TTag &value)
Assign a value to Tag data member.
Definition: Dbtag_.cpp:66
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
void SetDb(const TDb &value)
Assign a value to Db data member.
Definition: Dbtag_.hpp:229
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
TGenbank & SetGenbank(void)
Select the variant.
Definition: Seqdesc_.cpp:340
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
@ e_Genbank
GenBank specific info.
Definition: Seqdesc_.hpp:121
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
END_EVENT_TABLE()
int i
static int version
Definition: mdb_load.c:29
#define wxT(x)
Definition: muParser.cpp:41
const TYPE & Get(const CNamedParameterList *param)
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
Utility macros and typedefs for exploring NCBI objects from seqblock.asn.
#define FOR_EACH_KEYWORD_ON_GENBANKBLOCK(Itr, Var)
FOR_EACH_KEYWORD_ON_GENBANKBLOCK EDIT_EACH_KEYWORD_ON_GENBANKBLOCK.
#define ERASE_KEYWORD_ON_GENBANKBLOCK(Itr, Var)
ERASE_KEYWORD_ON_GENBANKBLOCK.
#define EDIT_EACH_KEYWORD_ON_GENBANKBLOCK(Itr, Var)
#define FOR_EACH_DBXREF_ON_ORGREF(Itr, Var)
FOR_EACH_DBXREF_ON_ORGREF EDIT_EACH_DBXREF_ON_ORGREF.
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
bool BarcodeTestFails(const SBarcode &b)
bool IsTechBarcode(CBioseq_Handle bsh)
vector< SBarcode > TBarcodeResults
void BarcodeTestBioseq(CBioseq_Handle bsh, SBarcode &b)
#define const
Definition: zconf.h:232
Modified on Fri May 24 14:49:49 2024 by modify_doxy.py rev. 669887