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

Go to the SVN repository for this file.

1  /* $Id: segregate_sets.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 ////@begin includes
33 ////@end includes
34 #include <sstream>
35 
36 #include <objmgr/scope.hpp>
37 #include <objmgr/feat_ci.hpp>
38 #include <objmgr/seqdesc_ci.hpp>
43 #include <gui/objutils/utils.hpp>
50 
51 #include <wx/button.h>
52 #include <wx/statbox.h>
53 #include <wx/stattext.h>
54 
55 ////@begin XPM images
56 ////@end XPM images
57 
58 
59 
61 
62 
63 
64 IMPLEMENT_DYNAMIC_CLASS( CSegregateSets, wxFrame )
65 
66 
67 /*!
68  * CSegregateSets event table definition
69  */
70 
71 BEGIN_EVENT_TABLE( CSegregateSets, wxFrame )
72 
73 EVT_BUTTON( wxID_CANCEL, CSegregateSets::OnCancel)
74 EVT_BUTTON( wxID_OK, CSegregateSets::OnAccept)
75 
77 
78 
79 /*!
80  * CSegregateSets constructors
81  */
82 
84 {
85  Init();
86 }
87 
88 CSegregateSets::CSegregateSets( wxWindow* parent, objects::CSeq_entry_Handle seh, ICommandProccessor* cmdProcessor,
89  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91  this->m_TopSeqEntry = seh;
92  m_CmdProcessor = cmdProcessor;
93  m_SetSeq.clear();
94  ReadBioseq(*(m_TopSeqEntry.GetCompleteSeq_entry()));
95  Init();
96  Create(parent, id, caption, pos, size, style);
98 }
99 
100 
101 /*!
102  * CVectorTrimDlg creator
103  */
104 
105 bool CSegregateSets::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
106 {
107 ////@begin CSegregateSets creation
108  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
109  wxFrame::Create( parent, id, caption, pos, size, style );
110 
111  CreateControls();
112  if (GetSizer())
113  {
114  GetSizer()->SetSizeHints(this);
115  }
116  Centre();
117 ////@end CSegregateSets creation
118 
119  return true;
120 }
121 
122 
123 /*!
124  * CSegregateSets destructor
125  */
126 
128 {
129 ////@begin CSegregateSets destruction
130 ////@end CSegregateSets destruction
131 }
132 
133 
134 /*!
135  * Member initialisation
136  */
137 
139 {
140 }
141 
142 
143 /*!
144  * Control creation for CSegregateSets
145  */
146 
148 {
149  CSegregateSets *frame = this;
150  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
151  frame->SetSizer(itemBoxSizer1);
152 
153  wxPanel* itemDialog1 = new wxPanel(this);
154  itemBoxSizer1->Add(itemDialog1, 1, wxGROW|wxALL, 0);
155 
156  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
157  itemDialog1->SetSizer(itemBoxSizer2);
158 
159  m_Notebook = new wxNotebook(itemDialog1, ID_CSEGREGATE_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
160  itemBoxSizer2->Add(m_Notebook, 1, wxGROW|wxALL, 5);
161 
162  CIDSubpanel *panel1 = new CIDSubpanel(m_Notebook, ID_CSEGREGATE_IDTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
163  m_Notebook->AddPage(panel1,_("ID"));
164 
165  CTextSubpanel *panel2 = new CTextSubpanel(m_Notebook, ID_CSEGREGATE_TEXTTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
166  m_Notebook->AddPage(panel2,_("Text"));
167 
168  CLengthSubpanel *panel3 = new CLengthSubpanel(m_Notebook, ID_CSEGREGATE_NUMSLENTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
169  m_Notebook->AddPage(panel3,_("Num Seq Length"));
170 
171  CNumSubpanel *panel4 = new CNumSubpanel(m_Notebook, ID_CSEGREGATE_NUMSETSTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
172  m_Notebook->AddPage(panel4,_("Num Sets"));
173 
174  CFileSubpanel *panel5 = new CFileSubpanel(m_Notebook, ID_CSEGREGATE_FNAMETAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
175  m_Notebook->AddPage(panel5,_("File Name"));
176 
177  CFieldSubpanel *panel6 = new CFieldSubpanel(m_Notebook, ID_CSEGREGATE_FIELDTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
178  m_Notebook->AddPage(panel6,_("Field"));
179 
180  CFeatureTypeSubpanel *panel7 = new CFeatureTypeSubpanel(m_Notebook, ID_CSEGREGATE_FEATTYPETAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
181  m_Notebook->AddPage(panel7,_("Feature Type"));
182 
183  CDescTypeSubpanel *panel8 = new CDescTypeSubpanel(m_Notebook, ID_CSEGREGATE_DESCTYPETAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
184  m_Notebook->AddPage(panel8,_("Desc Type"));
185 
186  CMolInfoSubpanel *panel9 = new CMolInfoSubpanel(m_Notebook, ID_CSEGREGATE_MOLINFOTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
187  m_Notebook->AddPage(panel9,_("MolInfo"));
188 
189  CStructCommentSubpanel *panel10 = new CStructCommentSubpanel(m_Notebook, ID_CSEGREGATE_STRCOMMENTTAB, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
190  m_Notebook->AddPage(panel10,_("Struct Comment"));
191 
192  m_SetClassPanel = new CSetClassPanel(itemDialog1);
193  itemBoxSizer2->Add(m_SetClassPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
194  if (!m_SetSeq.empty() && m_SetSeq.front().parent.IsSetClass())
195  m_SetClassPanel->SetClass(m_SetSeq.front().parent.GetClass());
196  else
198 
199  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
200  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
201 
202  wxButton* itemButton13 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
203  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
204 
205  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
206  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
207 
208  m_LeaveUp = new wxCheckBox( itemDialog1, wxID_ANY, _("Leave Dialog Up"), wxDefaultPosition, wxDefaultSize, 0 );
209  m_LeaveUp->SetValue(false);
210  itemBoxSizer12->Add(m_LeaveUp, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
211 }
212 
213 
215 {
216  if (se.IsSet())
217  {
219  {
220  ReadBioseq(**it);
221  }
222  }
223  if (se.IsSeq() && se.GetSeq().IsNa())
224  {
225  CBioseq_Handle bsh = m_TopSeqEntry.GetBioseqHandle(*se.GetSeq().GetFirstId());
226  if (bsh)
227  {
230  if (bssh && bssh.CanGetClass() && bssh.GetClass() == CBioseq_set::eClass_nuc_prot && bssh.GetParentBioseq_set()) // if it is a nuc-prot set go a level higher
231  {
232  seh = bssh.GetParentEntry();
233  bssh = bssh.GetParentBioseq_set();
234  }
235 
236  if (bssh)
237  {
238  SSetSeqRecord s;
239  s.grandparent = bssh;
240  s.parent = bssh;
241  s.entry = seh;
242  CBioseq_set_Handle grandparent = bssh.GetParentBioseq_set();
243  if (grandparent)
244  {
245  s.grandparent = grandparent;
246  }
247  m_SetSeq.push_back(s);
248  }
249  }
250  }
251 }
252 
253 /*!
254  * Should we show tooltips?
255  */
256 
258 {
259  return true;
260 }
261 
262 /*!
263  * Get bitmap resources
264  */
265 
266 wxBitmap CSegregateSets::GetBitmapResource( const wxString& name )
267 {
268  // Bitmap retrieval
269  wxUnusedVar(name);
270  return wxNullBitmap;
271 }
272 
273 /*!
274  * Get icon resources
275  */
276 
277 wxIcon CSegregateSets::GetIconResource( const wxString& name )
278 {
279  // Icon retrieval
280  wxUnusedVar(name);
281  return wxNullIcon;
282 }
283 
284 void CSegregateSets::OnCancel( wxCommandEvent& event )
285 {
286  Close();
287 }
288 
289 void CSegregateSets::OnAccept( wxCommandEvent& event )
290 {
292  if (cmd)
294  if (m_LeaveUp->GetValue())
295  {
296  m_SetSeq.clear();
297  if (m_TopSeqEntry)
298  ReadBioseq(*(m_TopSeqEntry.GetCompleteSeq_entry()));
299  for (size_t i = 0; i < m_Notebook->GetPageCount(); ++i)
300  {
301  CRBSubpanel* panel = dynamic_cast<CRBSubpanel*>(m_Notebook->GetPage(i));
302  if (panel)
303  {
304  panel->GetSubsets().clear();
305  panel->SetClusters();
306  panel->UpdateList();
307  }
308  }
309  Refresh();
310  }
311  else
312  Close();
313 }
314 
315 
317 {
319  vector< vector<int> > &subsets = GetSubsets();
320  if (m_TopSeqEntry && !subsets.empty() && !subsets.front().empty())
321  {
322  cmd.Reset( new CCmdComposite("Segregate Sets") );
323  int i = subsets.front().front();
324  CBioseq_set_Handle grandparent = m_SetSeq[i].grandparent;
325  CBioseq_set_Handle parent = m_SetSeq[i].parent;
326  CRef<objects::CBioseq_set> changed_set(new objects::CBioseq_set());
327  bool created = false;
328  if (grandparent != parent)
329  {
330  changed_set->Assign(*grandparent.GetCompleteBioseq_set());
331  }
332  else
333  {
334  CRef<CSeq_entry> new_se(new CSeq_entry());
335  CRef<CBioseq_set> bss(new CBioseq_set());
336  bss->Assign(*parent.GetCompleteBioseq_set());
337  new_se->SetSet(*bss);
338  changed_set->SetSeq_set().push_back(new_se);
339  changed_set->SetClass(parent.GetClass());
340  created = true;
341  }
342  MoveDescrToEntries(*changed_set);
343  for (unsigned int s = 0; s < subsets.size(); s++)
344  {
345  PopulateSet(*changed_set, subsets[s], m_SetClassPanel->GetClass());
346  }
347  if (changed_set->GetClass() == m_SetClassPanel->GetClass())
348  {
349  changed_set->SetClass(CBioseq_set::eClass_genbank);
350  }
351  if (created && changed_set->GetClass() == CBioseq_set::eClass_genbank)
352  {
353  AddUserObject(*changed_set);
354  }
355  CCmdChangeBioseqSet *set_cmd = new CCmdChangeBioseqSet(grandparent, *changed_set);
356  cmd->AddCommand(*set_cmd);
357  }
358  return cmd;
359 }
360 
362 {
363  CRef<CSeqdesc> user_object( new CSeqdesc );
364  CSeqdesc_Base::TUser& user = user_object->SetUser();
365  user.SetType().SetStr("GbenchModification");
366  CRef<CUser_field> method = user.SetFieldRef("method");
367  method->SetValue("SegregateSets");
368  se.SetDescr().Set().push_back( user_object );
369 }
370 
372 {
374  return;
375  bool user_object_present = false;
377  {
378  bool title_present = false;
379  if ((*it)->IsSetDescr())
380  {
381  for (CSeq_descr::Tdata::const_iterator desc = (*it)->GetDescr().Get().begin(); desc != (*it)->GetDescr().Get().end(); ++desc)
382  {
383  if ((*desc)->IsTitle() && !(*desc)->GetTitle().empty())
384  {
385  title_present = true;
386  break;
387  }
388  }
389  }
390  if (se.IsSetDescr())
391  {
392  for (CSeq_descr::Tdata::const_iterator desc = se.GetDescr().Get().begin(); desc != se.GetDescr().Get().end(); ++desc)
393  {
394  if (title_present && (*desc)->IsTitle())
395  continue;
396  if ((*desc)->IsUser() && (*desc)->GetUser().IsSetType() && (*desc)->GetUser().GetType().IsStr() && (*desc)->GetUser().GetType().GetStr() == "GbenchModification")
397  {
398  user_object_present = true;
399  continue;
400  }
401  (*it)->SetDescr().Set().push_back(*desc);
402  }
403  }
404 
405  if ((*it)->IsSet())
406  {
407  MoveDescrToEntries((*it)->SetSet());
408  }
409  }
410 
411  se.ResetDescr();
412  if (user_object_present)
413  {
414  AddUserObject(se);
415  }
416 }
417 
418 void CSegregateSetsBase::PopulateSet(CBioseq_set& changed_set, const vector<int> &subset, CBioseq_set::EClass top_class)
419 {
420  if (changed_set.CanGetSeq_set())
421  {
422  CRef<objects::CBioseq_set> new_set(new objects::CBioseq_set());
423  new_set->SetClass(top_class);
424 
425  for ( unsigned int j = 0; j < subset.size(); j++)
426  {
427  int i = subset[j];
428  CRef<CSeq_entry> se(new CSeq_entry());
429  se->Assign(*m_SetSeq[i].entry.GetCompleteSeq_entry());
430  TakeFromSet(changed_set,se);
431  new_set->SetSeq_set().push_back(se);
432  }
433  CRef<CSeq_entry> new_se(new CSeq_entry());
434  new_se->SetSet(*new_set);
435  changed_set.SetSeq_set().push_back(new_se);
436  }
437 }
438 
440 {
441  if (!changed_set.CanGetSeq_set())
442  return;
443  CBioseq_set::TSeq_set::iterator it = changed_set.SetSeq_set().begin();
444  while (it != changed_set.SetSeq_set().end())
445  {
446  bool match = false;
447  bool take = true;
448  if ( (*it)->IsSeq() && (*it)->GetSeq().CanGetId() && se->IsSeq() && se->GetSeq().CanGetId() && (*it)->GetSeq().GetFirstId()->Match(*se->GetSeq().GetFirstId()) )
449  match = true;
450 
451  if ((*it)->IsSet())
452  {
453  if (se->IsSet() && se->GetSet().CanGetClass() && se->GetSet().GetClass() == CBioseq_set::eClass_nuc_prot && se->GetSet().GetNucFromNucProtSet().CanGetId() &&
454  (*it)->GetSet().CanGetClass() && (*it)->GetSet().GetClass() == CBioseq_set::eClass_nuc_prot && (*it)->GetSet().GetNucFromNucProtSet().CanGetId() &&
455  (*it)->GetSet().GetNucFromNucProtSet().GetFirstId()->Match(*se->GetSet().GetNucFromNucProtSet().GetFirstId()) )
456  match = true;
457  else
458  {
459  TakeFromSet((*it)->SetSet(),se);
460  if ( (*it)->GetSet().GetSeq_set().empty() )
461  {
462  match = true;
463  take = false;
464  }
465  }
466  }
467 
468  if (match)
469  {
470  if (take)
471  se->Assign(**it);
472  it = changed_set.SetSeq_set().erase(it);
473  }
474  else
475  ++it;
476  }
477 }
478 
479 vector< vector<int> > & CSegregateSets::GetSubsets()
480 {
481  int sel = m_Notebook->GetSelection();
482  CRBSubpanel *win = dynamic_cast<CRBSubpanel*>(m_Notebook->GetPage(sel));
483  return win->GetSubsets();
484 }
485 
487 {
488  int sel = m_Notebook->GetSelection();
489  CRBSubpanel *win = dynamic_cast<CRBSubpanel*>(m_Notebook->GetPage(sel));
490  win->SetSubsets(selected);
491 }
492 
493 
494 /*
495  * CRBSubpanel type definition
496  */
497 
498 IMPLEMENT_DYNAMIC_CLASS( CRBSubpanel, wxPanel )
499 
500 BEGIN_EVENT_TABLE( CRBSubpanel, wxPanel )
502 
503 
504 void CRBSubpanel::CreateControlsHeader()
505 {
506  CRBSubpanel* itemPanel1 = this;
507 
508  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
509  itemPanel1->SetSizer(itemBoxSizer2);
510 
511  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
512  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
513 
514  m_TreeCtrl = new wxTreeCtrl(itemPanel1, wxID_ANY, wxDefaultPosition, wxSize(400,320),wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT|wxTR_MULTIPLE );
515  itemBoxSizer3->Add(m_TreeCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
516 
517  m_ListCtrl2 = new wxListCtrl( itemPanel1, wxID_ANY, wxDefaultPosition, wxSize(400, 320), wxLC_REPORT|wxLC_NO_HEADER );
518  itemBoxSizer3->Add(m_ListCtrl2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
519  m_ListCtrl2->InsertColumn(0,wxEmptyString,wxLIST_FORMAT_LEFT,380);
520 
521  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
522  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
523 
524  wxButton* itemButton1 = new wxButton(itemPanel1, ID_RBSUB_TOLEFT, _("<<<"), wxDefaultPosition, wxDefaultSize, 0);
525  itemBoxSizer4->Add(itemButton1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 15);
526 
527  wxButton* itemButton2 = new wxButton( itemPanel1, ID_RBSUB_TORIGHT, _(">>>"), wxDefaultPosition, wxDefaultSize, 0 );
528  itemBoxSizer4->Add(itemButton2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 15);
529 
530  itemButton1->Bind(wxEVT_BUTTON, &CRBSubpanel::OnButtonMoveLeft, this);
531  itemButton2->Bind(wxEVT_BUTTON, &CRBSubpanel::OnButtonMoveRight, this);
532 }
533 
535 {
536  CRBSubpanel* itemPanel1 = this;
537  wxSizer* itemBoxSizer2 = GetSizer();
538 
539  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
540  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
541 
542  wxButton* itemButton13 = new wxButton( itemPanel1, wxID_ANY, _("Select"), wxDefaultPosition, wxDefaultSize, 0 );
543  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
544 
545  wxButton* itemButton14 = new wxButton( itemPanel1, wxID_ANY, _("Select All"), wxDefaultPosition, wxDefaultSize, 0 );
546  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
547 
548  wxButton* itemButton15 = new wxButton( itemPanel1, wxID_ANY, _("Unselect All"), wxDefaultPosition, wxDefaultSize, 0 );
549  itemBoxSizer12->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
550 
551  itemButton13->Bind(wxEVT_BUTTON, &CRBSubpanel::OnSelect, this);
552  itemButton14->Bind(wxEVT_BUTTON, &CRBSubpanel::OnSelectAll, this);
553  itemButton15->Bind(wxEVT_BUTTON, &CRBSubpanel::OnUnselectAll, this);
554 }
555 
557 {
558  wxWindow *win = GetParent();
559  while (win)
560  {
561  CSegregateSetsBase *base = dynamic_cast<CSegregateSetsBase*>(win);
562  if (base)
563  return base;
564  win = win->GetParent();
565  }
566  return NULL;
567 }
568 
569 void CRBSubpanel::CombineLabels(const CSeq_id &id, vector<string> &labels)
570 {
571  if (id.IsGenbank() && id.GetGenbank().IsSetAccession())
572  labels[0] = id.GetGenbank().GetAccession();
573  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "BankIt" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
574  labels[1] = id.GetGeneral().GetTag().GetStr();
575  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "NCBIFILE" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
576  labels[2] = id.GetGeneral().GetTag().GetStr();
577  if (id.IsLocal() && id.GetLocal().IsStr())
578  labels[3] = id.GetLocal().GetStr();
579 }
580 
581 void CRBSubpanel::CollectLabels(CSeq_entry_Handle seh, list<string> &strs)
582 {
583  vector<string> labels(4);
584  if (seh.IsSeq())
585  {
586  if (seh.GetSeq().IsSetId())
587  for (CBioseq_Handle::TId::const_iterator it = seh.GetSeq().GetId().begin(); it != seh.GetSeq().GetId().end(); ++it)
588  CombineLabels(*(it->GetSeqId()),labels);
589 
590  }
591  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
593  {
594  for (CBioseq::TId::const_iterator it = seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().begin(); it != seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().end(); ++it)
595  CombineLabels(**it,labels);
596  }
597 
598  for (int i=0; i<labels.size(); i++)
599  if (!labels[i].empty())
600  strs.push_back(labels[i]);
601 }
602 
604 {
605  if (id.IsGenbank() && id.GetGenbank().IsSetAccession())
606  labels.insert(id.GetGenbank().GetAccession());
607  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "BankIt" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
608  {
609  labels.insert(id.GetGeneral().GetTag().GetStr());
610  labels.insert("BankIt" + id.GetGeneral().GetTag().GetStr());
611  string first, second;
612  NStr::SplitInTwo(id.GetGeneral().GetTag().GetStr(), "/", first, second);
613  labels.insert(first);
614  labels.insert("BankIt" + first);
615  }
616  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "NCBIFILE" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
617  {
618  labels.insert(id.GetGeneral().GetTag().GetStr());
619  labels.insert("NCBIFILE" + id.GetGeneral().GetTag().GetStr());
620  }
621  if (id.IsLocal() && id.GetLocal().IsStr())
622  labels.insert(id.GetLocal().GetStr());
623  string label;
624  id.GetLabel(&label, CSeq_id::eContent);
625  labels.insert(label);
626 }
627 
629 {
630  if (seh.IsSeq())
631  {
632  if (seh.GetSeq().IsSetId())
633  for (CBioseq_Handle::TId::const_iterator it = seh.GetSeq().GetId().begin(); it != seh.GetSeq().GetId().end(); ++it)
634  CombineLabelsAll(*(it->GetSeqId()), strs);
635 
636  }
637  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
639  {
640  for (CBioseq::TId::const_iterator it = seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().begin(); it != seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().end(); ++it)
641  CombineLabelsAll(**it,strs);
642  }
643 }
644 
646 {
647  list<string> strs;
648  CollectLabels(seh,strs);
649  string label = NStr::Join(strs," ");
650  return label;
651 }
652 
654 {
655  set<string> strs;
656  CollectLabelsAll(seh,strs);
657  vector<string> vec(strs.begin(), strs.end());
658  return constraint->DoesListMatch(vec);
659 }
660 
661 void CRBSubpanel::UpdateList() // Updates visuals and m_Available based on m_Subsets and m_Clusters
662 {
663  Freeze();
665 
666  m_TreeCtrl->DeleteAllItems();
667  m_ListCtrl2->DeleteAllItems();
668  set<int> removed;
669  for (unsigned int k=0; k<m_Subsets.size(); k++)
670  for (unsigned int j=0; j<m_Subsets[k].size(); j++)
671  {
672  int i = m_Subsets[k][j];
673  CSeq_entry_Handle seh = win->GetSeqEntry(i);
674  string label = GetLabel(seh);
675  long item = m_ListCtrl2->GetItemCount();
676  item = m_ListCtrl2->InsertItem(item,ToWxString(label));
677  m_ListCtrl2->SetItemData(item,i);
678  if (k % 2 != 0)
679  m_ListCtrl2->SetItemBackgroundColour(item,*wxLIGHT_GREY);
680  removed.insert(i);
681  }
682  m_Available.clear();
683  size_t set_size = win->GetSetSize();
684  for (unsigned int i=0; i<set_size; ++i)
685  if (removed.find(i) == removed.end())
686  {
687  m_Available.push_back(i);
688  }
689  map<int, pair<string,string> > avail_to_cluster_label;
690  for (map<string, vector<pair<int,string> > >::iterator it = m_Clusters.begin(); it != m_Clusters.end(); ++it)
691  for (vector<pair<int,string> >::iterator s = it->second.begin(); s != it->second.end(); ++s)
692  avail_to_cluster_label[s->first] = pair<string,string>(it->first,s->second);
693 
694  map<wxString, wxTreeItemId> cluster_to_id;
695  wxTreeItemId root = m_TreeCtrl->AddRoot(wxEmptyString);
696  for (vector<int>::iterator j=m_Available.begin(); j != m_Available.end(); ++j)
697  {
698  map<int,pair<string,string> >::iterator i = avail_to_cluster_label.find(*j);
699  if ( i == avail_to_cluster_label.end())
700  continue;
701 
702  map<string, vector<pair<int,string> > >::iterator it = m_Clusters.find(i->second.first);
703  wxTreeItemId parent;
704  if (cluster_to_id.find(wxString(it->first)) == cluster_to_id.end())
705  {
706  parent = m_TreeCtrl->AppendItem(root,wxString(it->first));
707  cluster_to_id[wxString(it->first)] = parent;
708  }
709  else
710  parent = cluster_to_id[wxString(it->first)];
711 
712  m_TreeCtrl->AppendItem(parent,wxString(i->second.second),-1,-1,new ItemData(*j));
713  }
714 
715  vector<wxTreeItemId> to_delete;
716  wxTreeItemIdValue cookie;
717  wxTreeItemId id = m_TreeCtrl->GetFirstChild( root, cookie );
718  while( id.IsOk() )
719  {
720  if (m_TreeCtrl->ItemHasChildren(id) && m_TreeCtrl->GetChildrenCount(id) == 1)
721  {
722  wxTreeItemIdValue cookie2;
723  wxTreeItemId item = m_TreeCtrl->GetFirstChild( id, cookie2 );
724  if ( item.IsOk() && m_TreeCtrl->GetItemText(id) == m_TreeCtrl->GetItemText(item) )
725  {
726  int data = (dynamic_cast<ItemData*>(m_TreeCtrl->GetItemData(item)))->GetData();
727  m_TreeCtrl->SetItemData(id,new ItemData(data));
728  to_delete.push_back(id);
729  }
730  }
731  id = m_TreeCtrl->GetNextChild( root, cookie);
732  }
733 
734  for (size_t i=0; i<to_delete.size(); i++)
735  m_TreeCtrl->DeleteChildren(to_delete[i]);
736  Thaw();
737  m_TreeCtrl->Refresh();
738 }
739 
740 CRBSubpanel * CRBSubpanel::GetEventCaller(wxCommandEvent& event)
741 {
742  wxWindow *btn = dynamic_cast<wxWindow*>(event.GetEventObject());
743  CRBSubpanel *self = NULL;
744  if (btn)
745  {
746  self = dynamic_cast<CRBSubpanel*>(btn->GetParent());
747  }
748  return self;
749 }
750 
751 void CRBSubpanel::OnButtonMoveRight( wxCommandEvent& event )
752 {
753  if (!GetEventCaller(event))
754  {
755  event.Skip();
756  return;
757  }
758 
759  vector<int> subset;
760  wxArrayTreeItemIds selection;
761  size_t size_sel = m_TreeCtrl->GetSelections(selection);
762  for (unsigned int i=0; i<size_sel; i++)
763  {
764  wxTreeItemId id = selection[i];
765  if (!id.IsOk())
766  continue;
767  if (m_TreeCtrl->ItemHasChildren(id))
768  {
769  vector<int> cluster_subset;
770  wxTreeItemIdValue cookie;
771  wxTreeItemId item = m_TreeCtrl->GetFirstChild( id, cookie );
772  while( item.IsOk() )
773  {
774  if (m_TreeCtrl->GetItemData(item))
775  {
776  int data = (dynamic_cast<ItemData*>(m_TreeCtrl->GetItemData(item)))->GetData();
777  cluster_subset.push_back(data);
778  }
779  item = m_TreeCtrl->GetNextChild( id, cookie);
780  }
781  m_Subsets.push_back(cluster_subset);
782  }
783  else if (m_TreeCtrl->GetItemData(id))
784  {
785  int data = (dynamic_cast<ItemData*>(m_TreeCtrl->GetItemData(id)))->GetData();
786  if (m_Subsets.empty())
787  subset.push_back(data);
788  else
789  m_Subsets.back().push_back(data);
790  }
791  }
792  if (m_Subsets.empty() && !subset.empty())
793  m_Subsets.push_back(subset);
794  UpdateList();
795 }
796 
797 void CRBSubpanel::OnButtonMoveLeft( wxCommandEvent& event )
798 {
799  if (!GetEventCaller(event))
800  {
801  event.Skip();
802  return;
803  }
804 
805  long item = -1;
806  for ( ;; )
807  {
808  item = m_ListCtrl2->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
809  if ( item == -1 ) break;
810  int i = static_cast<int>(m_ListCtrl2->GetItemData(item));
811  for (unsigned int k=0; k<m_Subsets.size(); k++)
812  {
813  vector<int>::iterator it = find(m_Subsets[k].begin(), m_Subsets[k].end(), i);
814  if (it != m_Subsets[k].end())
815  {
816  m_Subsets[k].erase(it);
817  break;
818  }
819  }
820  }
821 
822  UpdateList();
823 }
824 
825 void CRBSubpanel::OnSelectAll( wxCommandEvent& event )
826 {
827  if (!GetEventCaller(event))
828  {
829  event.Skip();
830  return;
831  }
832 
833  vector<int> subset;
834  wxTreeItemId root = m_TreeCtrl->GetRootItem();
835  wxTreeItemIdValue cookie;
836  wxTreeItemId id = m_TreeCtrl->GetFirstChild( root, cookie );
837 
838  while( id.IsOk() )
839  {
840 
841  if (m_TreeCtrl->ItemHasChildren(id))
842  {
843  vector<int> cluster_subset;
844  wxTreeItemIdValue cookie2;
845  wxTreeItemId item = m_TreeCtrl->GetFirstChild( id, cookie2 );
846  while( item.IsOk() )
847  {
848  if (m_TreeCtrl->GetItemData(item))
849  {
850  int data = (dynamic_cast<ItemData*>(m_TreeCtrl->GetItemData(item)))->GetData();
851  cluster_subset.push_back(data);
852  }
853  item = m_TreeCtrl->GetNextChild( id, cookie2);
854  }
855  m_Subsets.push_back(cluster_subset);
856  }
857  else if (m_TreeCtrl->GetItemData(id))
858  {
859  int data = (dynamic_cast<ItemData*>(m_TreeCtrl->GetItemData(id)))->GetData();
860  if (m_Subsets.empty())
861  subset.push_back(data);
862  else
863  m_Subsets.back().push_back(data);
864  }
865  id = m_TreeCtrl->GetNextChild( root, cookie);
866  }
867 
868  if (m_Subsets.empty() && !subset.empty())
869  m_Subsets.push_back(subset);
870  UpdateList();
871 }
872 
873 void CRBSubpanel::OnUnselectAll( wxCommandEvent& event )
874 {
875  if (!GetEventCaller(event))
876  {
877  event.Skip();
878  return;
879  }
880 
881  m_Subsets.clear();
882  UpdateList();
883 }
884 
885 void CRBSubpanel::OnSelect( wxCommandEvent& event )
886 {
887  if (!GetEventCaller(event))
888  {
889  event.Skip();
890  return;
891  }
893  if (!win)
894  return;
895  OnSelectButton(win);
896  UpdateList();
897 }
898 
900 {
901  m_TreeCtrl = NULL;
902  m_ListCtrl2 = NULL;
903 }
904 
906 {
910  SetClusters();
911  UpdateList();
912 }
913 
914 bool CRBSubpanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
915 {
916  wxPanel::Create( parent, id, pos, size, style );
917  CreateControls();
918  if (GetSizer())
919  {
920  GetSizer()->SetSizeHints(this);
921  }
922  Centre();
923  return true;
924 }
925 
926 
928 {
930  if (!win)
931  return;
932 
933  vector<int> subset;
934  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
935  {
936  int i = *j;
937  CSeq_entry_Handle seh = win->GetSeqEntry(i);
938  CBioseq_Handle bsh;
939  if (seh.IsSeq())
940  {
941  bsh = seh.GetSeq();
942  }
943  else if (seh.IsSet() && seh.GetSet().CanGetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot)
944  {
946  }
947  if (!bsh)
948  continue;
949 
950  if (selected.find(bsh) != selected.end())
951  subset.push_back(i);
952  }
953  if (!subset.empty())
954  m_Subsets.push_back(subset);
955  UpdateList();
956 }
957 
958 IMPLEMENT_DYNAMIC_CLASS( CLengthSubpanel, CRBSubpanel )
959 
960 BEGIN_EVENT_TABLE( CLengthSubpanel, CRBSubpanel )
962 
963 void CLengthSubpanel::CreateControlsMiddle()
964 {
965  CLengthSubpanel* itemPanel1 = this;
966 
967  wxSizer* itemBoxSizer2 = GetSizer();
968 
969  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
970  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
971 
972  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
973  itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
974 
975  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("Minimum Length"), wxDefaultPosition, wxDefaultSize, 0 );
976  itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
977 
978  wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Maximum Length"), wxDefaultPosition, wxDefaultSize, 0 );
979  itemBoxSizer4->Add(itemStaticText6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
980 
981  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxVERTICAL);
982  itemBoxSizer3->Add(itemBoxSizer7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
983 
984  m_Min = new wxTextCtrl(itemPanel1, ID_LENGTH_MINTEXT, wxEmptyString, wxDefaultPosition, wxSize(250, -1), 0);
985  itemBoxSizer7->Add(m_Min, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
986 
987  m_Max = new wxTextCtrl(itemPanel1, ID_LENGTH_MAXTEXT, wxEmptyString, wxDefaultPosition, wxSize(250, -1), 0);
988  itemBoxSizer7->Add(m_Max, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
989 }
990 
992 {
993  unsigned long min_length = 0;
994  unsigned long max_length = INT_MAX;
995  bool min_num = m_Min->GetValue().ToULong(&min_length);
996  bool max_num = m_Max->GetValue().ToULong(&max_length);
997  if ( !min_num && !max_num )
998  return;
999 
1000  vector<int> subset;
1001  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1002  {
1003  int i = *j;
1004  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1005  TSeqPos length = 0;
1006  if (seh.IsSeq())
1007  length = seh.GetSeq().GetBioseqLength();
1008  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1010  {
1012  }
1013  if (length == 0)
1014  continue;
1015  if (length >= min_length && length <= max_length)
1016  subset.push_back(i);
1017  }
1018  if (!subset.empty())
1019  m_Subsets.push_back(subset);
1020 }
1021 
1023 {
1025  size_t set_size = win->GetSetSize();
1026  m_Clusters.clear();
1027  for (unsigned i = 0; i < set_size; i++)
1028  {
1029  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1030  string label = GetLabel(seh);
1031  TSeqPos length = 0;
1032  if (seh.IsSeq())
1033  {
1034  length = seh.GetSeq().GetBioseqLength();
1035  }
1036  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1038  {
1040  }
1041  if (!label.empty())
1042  {
1043  m_Clusters[NStr::IntToString(length)].push_back(pair<int,string>(i,label));
1044  }
1045  }
1046 }
1047 
1048 
1049 IMPLEMENT_DYNAMIC_CLASS( CIDSubpanel, CRBSubpanel )
1050 
1051 BEGIN_EVENT_TABLE( CIDSubpanel, CRBSubpanel )
1053 
1054 void CIDSubpanel::CreateControlsMiddle()
1055 {
1056  CIDSubpanel* itemPanel1 = this;
1057 
1058  wxSizer* itemBoxSizer2 = GetSizer();
1059 
1060  m_StringConstraintPanel = new CStringConstraintPanel( itemPanel1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
1061  itemBoxSizer2->Add(m_StringConstraintPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 0);
1062  m_StringConstraintPanel->SetStringSelection(_("Is one of"));
1063 
1064 }
1065 
1067 {
1069  if (!constraint) return;
1070 
1071  vector<int> subset;
1072  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1073  {
1074  int i = *j;
1075  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1076 
1077  if (MatchConstraint(constraint,seh))
1078  subset.push_back(i);
1079  }
1080  if (!subset.empty())
1081  m_Subsets.push_back(subset);
1082 }
1083 
1085 {
1087  size_t set_size = win->GetSetSize();
1088  m_Clusters.clear();
1089  for (unsigned i = 0; i < set_size; i++)
1090  {
1091  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1092  string label = GetLabel(seh);
1093  if (!label.empty())
1094  {
1095  m_Clusters[label].push_back(pair<int,string>(i,label));
1096  }
1097  }
1098 }
1099 
1100 
1101 IMPLEMENT_DYNAMIC_CLASS( CTextSubpanel, CRBSubpanel )
1102 
1103 BEGIN_EVENT_TABLE( CTextSubpanel, CRBSubpanel )
1107 EVT_RADIOBUTTON(wxID_ANY, CTextSubpanel::OnChoiceChanged)
1108 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, CTextSubpanel::OnPageChanged)
1110 
1111 void CTextSubpanel::CreateControlsMiddle()
1112 {
1113  CTextSubpanel* itemPanel1 = this;
1114 
1115  wxSizer* itemBoxSizer2 = GetSizer();
1116 
1117  CSegregateSetsBase* owner = GetBaseFrame();
1118  CSeq_entry_Handle seh = owner->GetTopSeqEntry();
1119  m_Constraint = new CConstraintPanel( itemPanel1, seh);
1120  itemBoxSizer2->Add(m_Constraint, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
1121 }
1122 
1123 void CTextSubpanel::OnChoiceChanged( wxCommandEvent& event )
1124 {
1125  SetClusters();
1126  UpdateList();
1127  event.Skip();
1128 }
1129 
1130 void CTextSubpanel::OnPageChanged(wxBookCtrlEvent& event)
1131 {
1132  SetClusters();
1133  UpdateList();
1134  event.Skip();
1135 }
1136 
1137 
1139 {
1140  CFieldNamePanel* constraint_field_panel = m_Constraint->GetFieldNamePanel();
1141  string constraint_field;
1142  string constraint_field_type = m_Constraint->GetFieldType();
1143  if (constraint_field_panel)
1144  constraint_field = constraint_field_panel->GetFieldName();
1145 
1146  if (NStr::IsBlank(constraint_field)) {
1147  constraint_field = constraint_field_type;
1148  } else {
1149  if (NStr::StartsWith(constraint_field_type, "RNA") && NStr::Find(constraint_field, "RNA") == NPOS ) {
1150  constraint_field = "RNA " + constraint_field;
1151  }
1152  }
1154 
1155  if (!constraint || constraint_field.empty()) return;
1156 
1157  vector<int> subset;
1158  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1159  {
1160  int i = *j;
1161  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1162  CRef<CMiscSeqTableColumn> src_col(new CMiscSeqTableColumn(constraint_field));
1163  vector<CRef<edit::CApplyObject> > src_objects = src_col->GetApplyObjects(seh, constraint_field, constraint);
1164 
1165  if (!src_objects.empty())
1166  subset.push_back(i);
1167  }
1168  if (!subset.empty())
1169  m_Subsets.push_back(subset);
1170 }
1171 
1173 {
1175  size_t set_size = win->GetSetSize();
1176  m_Clusters.clear();
1177 
1178  CFieldNamePanel* constraint_field_panel = m_Constraint->GetFieldNamePanel();
1179  string constraint_field;
1180  string constraint_field_type = m_Constraint->GetFieldType();
1181  if (constraint_field_panel)
1182  constraint_field = constraint_field_panel->GetFieldName();
1183 
1184  if (NStr::IsBlank(constraint_field)) {
1185  constraint_field = constraint_field_type;
1186  } else {
1187  if (NStr::StartsWith(constraint_field_type, "RNA") && NStr::Find(constraint_field, "RNA") == NPOS ) {
1188  constraint_field = "RNA " + constraint_field;
1189  }
1190  }
1191 
1192  if (constraint_field.empty()) return;
1193  CRef<CMiscSeqTableColumn> src_col(new CMiscSeqTableColumn(constraint_field));
1194 
1195  for (unsigned i = 0; i < set_size; i++)
1196  {
1197  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1198  set<string> values;
1199  src_col->GetApplyObjectsValues(seh,constraint_field,values);
1200  string label = GetLabel(seh);
1201  values.erase(kEmptyStr);
1202  if (!label.empty() && !values.empty())
1203  {
1204  m_Clusters[NStr::Join(values, " AND ")].push_back(pair<int,string>(i,label));
1205  }
1206  }
1207 }
1208 
1209 
1210 void CTextSubpanel::ProcessUpdateFeatEvent( wxCommandEvent& event )
1211 {
1212  UpdateChildrenFeaturePanels(this->GetSizer());
1213 }
1214 
1216 {
1217  CSegregateSetsBase* owner = GetBaseFrame();
1218  if (!owner)
1219  return;
1221 }
1222 
1223 IMPLEMENT_DYNAMIC_CLASS( CNumSubpanel, CRBSubpanel )
1224 
1225 BEGIN_EVENT_TABLE( CNumSubpanel, CRBSubpanel )
1227 
1228 void CNumSubpanel::CreateControlsMiddle()
1229 {
1230  CNumSubpanel* itemPanel1 = this;
1231 
1232  wxSizer* itemBoxSizer2 = GetSizer();
1233 
1234  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
1235  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
1236 
1237  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
1238  itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
1239 
1240  wxStaticText* itemStaticText5 = new wxStaticText( itemPanel1, wxID_STATIC, _("Number of Sets"), wxDefaultPosition, wxDefaultSize, 0 );
1241  itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
1242 
1243  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxVERTICAL);
1244  itemBoxSizer3->Add(itemBoxSizer7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
1245 
1246  m_Num = new wxTextCtrl(itemPanel1, ID_NUM_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(250, -1), 0);
1247  itemBoxSizer7->Add(m_Num, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
1248 
1249 }
1250 
1252 {
1253  unsigned long num = 0;
1254  bool num_exists = m_Num->GetValue().ToULong(&num);
1255  if ( !num_exists )
1256  return;
1257 
1258  long total_items = m_Available.size();
1259  long remainder = total_items % num;
1260  long items_per_subset = total_items / num;
1261 
1262  vector<int> subset;
1263  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1264  {
1265  int i = *j;
1266  subset.push_back(i);
1267  if (m_Subsets.size() < remainder)
1268  {
1269  if (subset.size() >= items_per_subset+1)
1270  {
1271  m_Subsets.push_back(subset);
1272  subset.clear();
1273  }
1274  }
1275  else
1276  {
1277  if (subset.size() >= items_per_subset && !subset.empty())
1278  {
1279  m_Subsets.push_back(subset);
1280  subset.clear();
1281  }
1282  }
1283  }
1284 }
1285 
1286 IMPLEMENT_DYNAMIC_CLASS( CFileSubpanel, CRBSubpanel )
1287 
1288 BEGIN_EVENT_TABLE( CFileSubpanel, CRBSubpanel )
1290 
1291 void CFileSubpanel::CreateControlsMiddle()
1292 {
1293 
1294 }
1295 
1297 {
1298  string name;
1299  if (tag.IsId())
1300  name = NStr::IntToString(tag.GetId());
1301  else if (tag.IsStr())
1302  name = tag.GetStr();
1303  auto pos = NStr::Find(name, "/", NStr::eCase, NStr::eReverseSearch);
1304  if (pos != NPOS)
1305  name = name.substr(0,pos);
1306  return name;
1307 }
1308 
1310 {
1311  map<string,vector<int> > tag_to_subset;
1312  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1313  {
1314  int i = *j;
1315  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1316 
1317  if (seh.IsSeq())
1318  {
1319  if (seh.GetSeq().IsSetId())
1320  {
1321  for (vector<CSeq_id_Handle>::const_iterator idh = seh.GetSeq().GetId().begin(); idh != seh.GetSeq().GetId().end(); ++idh)
1322  if (idh->GetSeqId()->IsGeneral() && idh->GetSeqId()->GetGeneral().IsSetDb() && idh->GetSeqId()->GetGeneral().GetDb() == "NCBIFILE" && idh->GetSeqId()->GetGeneral().IsSetTag() )
1323  {
1324  string filename = GetFilename(idh->GetSeqId()->GetGeneral().GetTag());
1325  if (!filename.empty())
1326  tag_to_subset[filename].push_back(i);
1327  }
1328  }
1329  }
1330  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1332  {
1333  for (CBioseq::TId::const_iterator idh = seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().begin(); idh != seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().end(); ++idh)
1334  if ((*idh)->IsGeneral() && (*idh)->GetGeneral().IsSetDb() && (*idh)->GetGeneral().GetDb() == "NCBIFILE" && (*idh)->GetGeneral().IsSetTag())
1335  {
1336  string filename = GetFilename((*idh)->GetGeneral().GetTag());
1337  if (!filename.empty())
1338  tag_to_subset[filename].push_back(i);
1339  }
1340  }
1341  }
1342 
1343  for ( map<string,vector<int> >::iterator it = tag_to_subset.begin(); it != tag_to_subset.end(); ++it)
1344  if (!it->second.empty())
1345  m_Subsets.push_back(it->second);
1346 }
1347 
1349 {
1351  size_t set_size = win->GetSetSize();
1352  m_Clusters.clear();
1353 
1354  for (unsigned i = 0; i < set_size; i++)
1355  {
1356  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1357  string label = GetLabel(seh);
1358  string filename;
1359  if (seh.IsSeq())
1360  {
1361  if (seh.GetSeq().IsSetId())
1362  {
1363  for (vector<CSeq_id_Handle>::const_iterator idh = seh.GetSeq().GetId().begin(); idh != seh.GetSeq().GetId().end(); ++idh)
1364  if (idh->GetSeqId()->IsGeneral() && idh->GetSeqId()->GetGeneral().IsSetDb() && idh->GetSeqId()->GetGeneral().GetDb() == "NCBIFILE" && idh->GetSeqId()->GetGeneral().IsSetTag())
1365  {
1366  filename = GetFilename(idh->GetSeqId()->GetGeneral().GetTag());
1367  }
1368  }
1369  }
1370  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1372  {
1373  for (CBioseq::TId::const_iterator idh = seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().begin(); idh != seh.GetSet().GetCompleteBioseq_set()->GetNucFromNucProtSet().GetId().end(); ++idh)
1374  if ((*idh)->IsGeneral() && (*idh)->GetGeneral().IsSetDb() && (*idh)->GetGeneral().GetDb() == "NCBIFILE" && (*idh)->GetGeneral().IsSetTag())
1375  {
1376  filename = GetFilename((*idh)->GetGeneral().GetTag());
1377  }
1378  }
1379  if (!label.empty() && !filename.empty())
1380  {
1381  m_Clusters[filename].push_back(pair<int,string>(i,label));
1382  }
1383  }
1384 }
1385 
1386 IMPLEMENT_DYNAMIC_CLASS( CFieldSubpanel, CRBSubpanel )
1387 
1388 BEGIN_EVENT_TABLE( CFieldSubpanel, CRBSubpanel )
1392 EVT_RADIOBUTTON(wxID_ANY, CFieldSubpanel::OnChoiceChanged)
1394 
1395 void CFieldSubpanel::CreateControlsMiddle()
1396 {
1397  CFieldSubpanel* itemPanel1 = this;
1398 
1399  wxSizer* itemBoxSizer2 = GetSizer();
1400 
1401  wxPanel *container1 = new wxPanel( itemPanel1, wxID_ANY, wxDefaultPosition, wxSize(800,260), 0 );
1402  itemBoxSizer2->Add(container1, 0, wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 0);
1403 
1404  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
1405  container1->SetSizer(itemBoxSizer3);
1406 
1407  vector<CFieldNamePanel::EFieldType> field_types;
1408  field_types.push_back(CFieldNamePanel::eFieldType_Taxname);
1409  field_types.push_back(CFieldNamePanel::eFieldType_Source);
1410  field_types.push_back(CFieldNamePanel::eFieldType_Misc);
1411  field_types.push_back(CFieldNamePanel::eFieldType_Feature);
1412  field_types.push_back(CFieldNamePanel::eFieldType_CDSGeneProt);
1413  field_types.push_back(CFieldNamePanel::eFieldType_RNA);
1414  field_types.push_back(CFieldNamePanel::eFieldType_MolInfo);
1415  field_types.push_back(CFieldNamePanel::eFieldType_Pub);
1416  field_types.push_back(CFieldNamePanel::eFieldType_DBLink);
1417  field_types.push_back(CFieldNamePanel::eFieldType_Misc);
1418  field_types.push_back(CFieldNamePanel::eFieldType_SeqId);
1419  m_FieldType = new CFieldChoicePanel( container1, field_types, true, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
1420  itemBoxSizer3->Add(m_FieldType, 0, wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 0);
1421 }
1422 
1423 void CFieldSubpanel::OnChoiceChanged( wxCommandEvent& event )
1424 {
1425  SetClusters();
1426  UpdateList();
1427  event.Skip();
1428 }
1429 
1431 {
1432  string constraint_field = m_FieldType->GetFieldName(false);
1433  if (constraint_field.empty()) return;
1434 
1435  map<string,vector<int> > value_to_subset;
1436  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1437  {
1438  int i = *j;
1439  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1440  CRef<CMiscSeqTableColumn> src_col(new CMiscSeqTableColumn(constraint_field));
1441  set<string> values;
1442  src_col->GetApplyObjectsValues(seh,constraint_field,values);
1443  if (!values.empty() && !values.begin()->empty())
1444  {
1445  value_to_subset[*values.begin()].push_back(i); // TODO what to do if more than 1 value?
1446  }
1447  }
1448  for ( map<string,vector<int> >::iterator it = value_to_subset.begin(); it != value_to_subset.end(); ++it)
1449  if (!it->second.empty())
1450  m_Subsets.push_back(it->second);
1451 }
1452 
1453 
1455 {
1457  size_t set_size = win->GetSetSize();
1458  m_Clusters.clear();
1459  if (!m_FieldType) return;
1460  string constraint_field = m_FieldType->GetFieldName(false);
1461  if (constraint_field.empty()) return;
1462  CRef<CMiscSeqTableColumn> src_col(new CMiscSeqTableColumn(constraint_field));
1463 
1464  for (unsigned i = 0; i < set_size; i++)
1465  {
1466  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1467  set<string> values;
1468  src_col->GetApplyObjectsValues(seh,constraint_field,values);
1469  string label = GetLabel(seh);
1470  values.erase(kEmptyStr);
1471  if (!label.empty() && !values.empty())
1472  {
1473  m_Clusters[NStr::Join(values, " AND ")].push_back(pair<int,string>(i,label));
1474  }
1475  }
1476 }
1477 
1478 void CFieldSubpanel::ProcessUpdateFeatEvent( wxCommandEvent& event )
1479 {
1480  UpdateChildrenFeaturePanels(this->GetSizer());
1481 }
1482 
1484 {
1485  wxSizerItemList& slist = sizer->GetChildren();
1486  CSegregateSetsBase* owner =GetBaseFrame();
1487  if (!owner)
1488  return;
1489  int n =0;
1490  for (wxSizerItemList::iterator iter = slist.begin(); iter != slist.end(); ++iter, ++n) {
1491  if ((*iter)->IsSizer()) {
1492  UpdateChildrenFeaturePanels((*iter)->GetSizer());
1493  } else if ((*iter)->IsWindow()) {
1494  wxWindow* child = (*iter)->GetWindow();
1495  if (child) {
1496  CFeatureTypePanel* panel = dynamic_cast<CFeatureTypePanel*>(child);
1497  if (panel) {
1498  panel->ListPresentFeaturesFirst(owner->GetTopSeqEntry());
1499  } else {
1500  wxSizer* subsizer = child->GetSizer();
1501  if (subsizer) {
1502  UpdateChildrenFeaturePanels(subsizer);
1503  }
1504  }
1505  }
1506  }
1507  }
1508 }
1509 
1510 
1511 IMPLEMENT_DYNAMIC_CLASS( CFeatureTypeSubpanel, CRBSubpanel )
1512 
1513 BEGIN_EVENT_TABLE( CFeatureTypeSubpanel, CRBSubpanel )
1518 
1519 void CFeatureTypeSubpanel::CreateControlsMiddle()
1520 {
1521  CFeatureTypeSubpanel* itemPanel1 = this;
1522 
1523  wxSizer* itemBoxSizer2 = GetSizer();
1524 
1525  m_FeatureType = new CFeatureTypePanel(itemPanel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
1526  itemBoxSizer2->Add(m_FeatureType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 0);
1527 
1528  CSegregateSetsBase* owner =GetBaseFrame();
1529  m_FeatureType->ListPresentFeaturesFirst(owner->GetTopSeqEntry());
1530 }
1531 
1532 void CFeatureTypeSubpanel::OnChoiceChanged( wxCommandEvent& event )
1533 {
1534  SetClusters();
1535  UpdateList();
1536  event.Skip();
1537 }
1538 
1540 {
1541  string constraint_field = m_FeatureType->GetFieldName(true);
1542  if (constraint_field.empty()) return;
1543  int itype, isubtype;
1544  if (!CSeqFeatData::GetFeatList()->GetTypeSubType(constraint_field, itype, isubtype))
1545  return;
1546  CSeqFeatData::ESubtype subtype = static_cast<CSeqFeatData::ESubtype>(isubtype);
1547 
1548  vector<int> subset;
1549  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1550  {
1551  int i = *j;
1552  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1553 
1554  CFeat_CI feat_iter(seh,SAnnotSelector(subtype));
1555  if (feat_iter)
1556  {
1557  subset.push_back(i);
1558  }
1559  }
1560  if (!subset.empty())
1561  m_Subsets.push_back(subset);
1562 }
1563 
1564 
1566 {
1568  size_t set_size = win->GetSetSize();
1569  m_Clusters.clear();
1570  if (!m_FeatureType) return;
1571  string constraint_field = m_FeatureType->GetFieldName(true);
1572  if (constraint_field.empty()) return;
1573  int itype, isubtype;
1574  if (!CSeqFeatData::GetFeatList()->GetTypeSubType(constraint_field, itype, isubtype))
1575  return;
1576  CSeqFeatData::ESubtype subtype = static_cast<CSeqFeatData::ESubtype>(isubtype);
1577 
1578  for (unsigned i = 0; i < set_size; i++)
1579  {
1580  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1581  string label = GetLabel(seh);
1582 
1583  CFeat_CI feat_iter(seh,SAnnotSelector(subtype));
1584  if (!label.empty() && feat_iter)
1585  {
1586  m_Clusters[constraint_field].push_back(pair<int,string>(i,label));
1587  }
1588  }
1589 }
1590 
1591 IMPLEMENT_DYNAMIC_CLASS( CDescTypeSubpanel, CRBSubpanel )
1592 
1593 BEGIN_EVENT_TABLE( CDescTypeSubpanel, CRBSubpanel )
1596 
1597 void CDescTypeSubpanel::CreateControlsMiddle()
1598 {
1599  CDescTypeSubpanel* itemPanel1 = this;
1600 
1601  wxSizer* itemBoxSizer2 = GetSizer();
1602 
1603  wxArrayString choices;
1604  for (int i = CSeqdesc::e_not_set+1; i != CSeqdesc::e_MaxChoice; i++)
1605  choices.Add(wxString(CSeqdesc::SelectionName(static_cast<CSeqdesc::E_Choice>(i))));
1606  m_DescType = new wxChoice(itemPanel1, ID_DESC_CHOICE, wxDefaultPosition, wxDefaultSize, choices, 0);
1607  itemBoxSizer2->Add(m_DescType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 0);
1608  m_DescType->SetSelection(0);
1609 
1610 
1611 }
1612 
1613 void CDescTypeSubpanel::OnChoiceChanged( wxCommandEvent& event )
1614 {
1615  SetClusters();
1616  UpdateList();
1617  event.Skip();
1618 }
1619 
1621 {
1622  int ichoice = m_DescType->GetSelection();
1623  if (ichoice == wxNOT_FOUND) return;
1624  CSeqdesc::E_Choice choice = static_cast<CSeqdesc::E_Choice>(ichoice+1);
1625 
1626  vector<int> subset;
1627  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1628  {
1629  int i = *j;
1630  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1631 
1632  CSeqdesc_CI desc_iter(seh, choice);
1633  if (desc_iter)
1634  {
1635  subset.push_back(i);
1636  }
1637  }
1638  if (!subset.empty())
1639  m_Subsets.push_back(subset);
1640 }
1641 
1643 {
1645  size_t set_size = win->GetSetSize();
1646  m_Clusters.clear();
1647  if (!m_DescType) return;
1648  int ichoice = m_DescType->GetSelection();
1649  if (ichoice == wxNOT_FOUND)
1650  return;
1651  CSeqdesc::E_Choice choice = static_cast<CSeqdesc::E_Choice>(ichoice+1);
1652 
1653 
1654 
1655  for (unsigned i = 0; i < set_size; i++)
1656  {
1657  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1658  string label = GetLabel(seh);
1659  string desc_label;
1660 
1661  CSeqdesc_CI desc_iter(seh, choice);
1662  if (desc_iter)
1663  {
1664  desc_iter->GetLabel(&desc_label, CSeqdesc:: eContent);
1665  }
1666  if (!label.empty() && !desc_label.empty())
1667  {
1668  m_Clusters[desc_label].push_back(pair<int,string>(i,label));
1669  }
1670  }
1671 }
1672 
1673 
1674 
1675 
1676 IMPLEMENT_DYNAMIC_CLASS( CMolInfoSubpanel, CRBSubpanel )
1677 
1678 BEGIN_EVENT_TABLE( CMolInfoSubpanel, CRBSubpanel )
1681 
1682 void CMolInfoSubpanel::CreateControlsMiddle()
1683 {
1684  CMolInfoSubpanel* itemPanel1 = this;
1685 
1686  wxSizer* itemBoxSizer2 = GetSizer();
1687 
1688  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
1689  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
1690 
1691  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
1692  itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_TOP|wxALL, 5);
1693 
1694  m_Class = new wxCheckBox(itemPanel1, ID_MOLINFO_CHKBX1, _("Class"));
1695  itemBoxSizer4->Add(m_Class, 0, wxALIGN_LEFT|wxALL, 5);
1696 
1697  m_Type = new wxCheckBox(itemPanel1, ID_MOLINFO_CHKBX2, _("Type"));
1698  itemBoxSizer4->Add(m_Type, 0, wxALIGN_LEFT|wxALL, 5);
1699 
1700  m_Topology = new wxCheckBox(itemPanel1, ID_MOLINFO_CHKBX3, _("Topology"));
1701  itemBoxSizer4->Add(m_Topology, 0, wxALIGN_LEFT|wxALL, 5);
1702 }
1703 
1704 void CMolInfoSubpanel::OnChoiceChanged( wxCommandEvent& event )
1705 {
1706  SetClusters();
1707  UpdateList();
1708  event.Skip();
1709 }
1710 
1712 {
1713  if (!m_Class->IsChecked() && !m_Type->IsChecked() && !m_Topology->IsChecked())
1714  return;
1715 
1716 
1717  map< pair<int, pair<int,int> >, vector<int> > class_type_topology_to_subset;
1718  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1719  {
1720  int i = *j;
1721  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1722 
1723  int iclass = -1;
1724  if (m_Class->IsChecked())
1725  {
1726  iclass = CSeq_inst::eMol_not_set;
1727  if (seh.IsSeq() && seh.GetSeq().IsSetInst_Mol())
1728  iclass = seh.GetSeq().GetInst_Mol();
1729  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1732  {
1734  }
1735  }
1736 
1737  int itype = -1;
1738  if (m_Type->IsChecked() )
1739  {
1740  itype = CMolInfo::eBiomol_unknown;
1741  CSeqdesc_CI desc_iter(seh, CSeqdesc:: e_Molinfo);
1742  if (desc_iter && desc_iter->GetMolinfo().IsSetBiomol())
1743  {
1744  itype = desc_iter->GetMolinfo().GetBiomol();
1745  }
1746  }
1747 
1748  int itopology = -1;
1749  if (m_Topology->IsChecked())
1750  {
1751  itopology = CSeq_inst::eTopology_linear;
1752  if (seh.IsSeq() && seh.GetSeq().IsSetInst_Topology())
1753  itopology = seh.GetSeq().GetInst_Topology();
1754  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1757  {
1759  }
1760  }
1761 
1762  class_type_topology_to_subset[pair<int, pair<int,int> >(iclass,pair<int,int>(itype,itopology))].push_back(i);
1763  }
1764 
1765  for ( map< pair<int, pair<int,int> >,vector<int> >::iterator it = class_type_topology_to_subset.begin(); it != class_type_topology_to_subset.end(); ++it)
1766  if (!it->second.empty())
1767  m_Subsets.push_back(it->second);
1768 }
1769 
1770 
1771 
1773 {
1775  size_t set_size = win->GetSetSize();
1776  m_Clusters.clear();
1777  if (!m_Class || !m_Type || !m_Topology)
1778  return;
1779  if (!m_Class->IsChecked() && !m_Type->IsChecked() && !m_Topology->IsChecked())
1780  return;
1781 
1782 
1783  for (unsigned i = 0; i < set_size; i++)
1784  {
1785  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1786  string label = GetLabel(seh);
1787  stringstream str;
1788 
1789  if (m_Class->IsChecked())
1790  {
1791  int iclass = CSeq_inst::eMol_not_set;
1792  if (seh.IsSeq() && seh.GetSeq().IsSetInst_Mol())
1793  iclass = seh.GetSeq().GetInst_Mol();
1794  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1797  {
1799  }
1800  str << CSeq_inst::ENUM_METHOD_NAME(EMol)()->FindName(iclass, true);
1801  }
1802 
1803  if (m_Type->IsChecked() )
1804  {
1805  int itype = CMolInfo::eBiomol_unknown;
1806  CSeqdesc_CI desc_iter(seh, CSeqdesc:: e_Molinfo);
1807  if (desc_iter && desc_iter->GetMolinfo().IsSetBiomol())
1808  {
1809  itype = desc_iter->GetMolinfo().GetBiomol();
1810  }
1811  if (!str.str().empty())
1812  str << ", ";
1813  str << CMolInfo::ENUM_METHOD_NAME(EBiomol)()->FindName(itype, true);
1814  }
1815 
1816 
1817  if (m_Topology->IsChecked())
1818  {
1819  int itopology = CSeq_inst::eTopology_linear;
1820  if (seh.IsSeq() && seh.GetSeq().IsSetInst_Topology())
1821  itopology = seh.GetSeq().GetInst_Topology();
1822  else if (seh.IsSet() && seh.GetSet().IsSetClass() && seh.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot
1825  {
1827  }
1828  if (!str.str().empty())
1829  str << ", ";
1830  str << CSeq_inst::ENUM_METHOD_NAME(ETopology)()->FindName(itopology, true);
1831  }
1832 
1833  if (!label.empty() && !str.str().empty())
1834  {
1835  m_Clusters[str.str()].push_back(pair<int,string>(i,label));
1836  }
1837  }
1838 }
1839 
1840 IMPLEMENT_DYNAMIC_CLASS( CStructCommentSubpanel, CRBSubpanel )
1841 
1842 BEGIN_EVENT_TABLE( CStructCommentSubpanel, CRBSubpanel )
1845 
1846 void CStructCommentSubpanel::CreateControlsMiddle()
1847 {
1848  CStructCommentSubpanel* itemPanel1 = this;
1849 
1850  wxSizer* itemBoxSizer2 = GetSizer();
1851 
1852  wxArrayString choices;
1853  GetAllLabels(choices);
1854  m_Label = new wxChoice(itemPanel1, ID_STRCOMMENT_CHOICE, wxDefaultPosition, wxDefaultSize, choices, 0);
1855  itemBoxSizer2->Add(m_Label, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 0);
1856 }
1857 
1858 void CStructCommentSubpanel::OnChoiceChanged( wxCommandEvent& event )
1859 {
1860  SetClusters();
1861  UpdateList();
1862  event.Skip();
1863 }
1864 
1865 void CStructCommentSubpanel::GetAllLabels(wxArrayString &choices)
1866 {
1868  if (!win)
1869  return;
1870  set<string> labels;
1871  size_t set_size = win->GetSetSize();
1872  for (unsigned i = 0; i < set_size; i++)
1873  {
1874  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1875  GetLabelsFromSeq(seh,labels);
1876  }
1877  for (set<string>::iterator label = labels.begin(); label != labels.end(); ++label)
1878  choices.Add(wxString(*label));
1879 }
1880 
1882 {
1883  CSeqdesc_CI desc_iter(seh, CSeqdesc::e_User);
1884  while (desc_iter)
1885  {
1886  const CUser_object& user = desc_iter->GetUser();
1887 
1888  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment" && user.IsSetData()) // User-object.type.str
1889  {
1890  CUser_object::TData::const_iterator i = user.GetData().begin();
1891  while (i != user.GetData().end())
1892  {
1893  CRef< CUser_field > uf = *i;
1894  if (uf->CanGetLabel() && uf->GetLabel().IsStr())
1895  {
1896  string label = uf->GetLabel().GetStr();
1897  if (!label.empty() && label != "StructuredCommentPrefix" && label != "StructuredCommentSuffix")
1898  labels.insert(label);
1899  }
1900  i++;
1901  }
1902  }
1903  ++desc_iter;
1904  }
1905 }
1906 
1908 {
1909  int ichoice = m_Label->GetSelection();
1910  if (ichoice == wxNOT_FOUND) return;
1911  string label = m_Label->GetString(ichoice).ToStdString();
1912 
1913  vector<int> subset;
1914  for(vector<int>::iterator j = m_Available.begin(); j != m_Available.end(); ++j)
1915  {
1916  int i = *j;
1917  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1918  set<string> labels;
1919  GetLabelsFromSeq(seh,labels);
1920  if (labels.find(label) != labels.end())
1921  {
1922  subset.push_back(i);
1923  }
1924  }
1925  if (!subset.empty())
1926  m_Subsets.push_back(subset);
1927 }
1928 
1929 
1931 {
1933  size_t set_size = win->GetSetSize();
1934  m_Clusters.clear();
1935 
1936 
1937  for (unsigned i = 0; i < set_size; i++)
1938  {
1939  CSeq_entry_Handle seh = win->GetSeqEntry(i);
1940  string label = GetLabel(seh);
1941  set<string> comments;
1942  GetLabelsFromSeq(seh,comments);
1943  comments.erase(kEmptyStr);
1944  if (!label.empty() && !comments.empty())
1945  {
1946  m_Clusters[NStr::Join(comments, " AND ")].push_back(pair<int,string>(i,label));
1947  }
1948  }
1949 }
1950 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
CBioseq_Handle –.
CBioseq_set_Handle –.
const CBioseq & GetNucFromNucProtSet(void) const
Definition: Bioseq_set.cpp:227
const CSeq_id * GetFirstId() const
Definition: Bioseq.cpp:271
TSeqPos GetLength(void) const
Definition: Bioseq.cpp:360
bool IsSetLength(void) const
Definition: Bioseq.cpp:355
bool IsNa(void) const
Definition: Bioseq.cpp:345
string GetFieldType(void) const
CFieldNamePanel * GetFieldNamePanel(void)
void ListPresentFeaturesFirst(objects::CSeq_entry_Handle seh)
CRef< edit::CStringConstraint > GetStringConstraint(void)
virtual void SetClusters()
virtual void OnSelectButton(CSegregateSetsBase *win)
void OnChoiceChanged(wxCommandEvent &event)
CFeat_CI –.
Definition: feat_ci.hpp:64
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
void ListPresentFeaturesFirst(const objects::CSeq_entry_Handle &entry, vector< const objects::CFeatListItem * > *featlist=nullptr)
virtual void SetClusters()
CFeatureTypePanel * m_FeatureType
void OnChoiceChanged(wxCommandEvent &event)
virtual void OnSelectButton(CSegregateSetsBase *win)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
virtual string GetFieldName(const bool subfield=false)=0
Returns the name of the field as selected in the panel.
virtual void OnSelectButton(CSegregateSetsBase *win)
void ProcessUpdateFeatEvent(wxCommandEvent &event)
void OnChoiceChanged(wxCommandEvent &event)
virtual void SetClusters()
CFieldChoicePanel * m_FieldType
void UpdateChildrenFeaturePanels(wxSizer *sizer)
virtual void OnSelectButton(CSegregateSetsBase *win)
string GetFilename(const objects::CObject_id &tag)
virtual void SetClusters()
virtual void OnSelectButton(CSegregateSetsBase *win)
virtual void SetClusters()
CStringConstraintPanel * m_StringConstraintPanel
virtual void SetClusters()
virtual void OnSelectButton(CSegregateSetsBase *win)
wxTextCtrl * m_Max
wxTextCtrl * m_Min
vector< CRef< objects::edit::CApplyObject > > GetApplyObjects(objects::CBioseq_Handle bsh)
void GetApplyObjectsValues(objects::CSeq_entry_Handle seh, const string &constraint_field, set< string > &values)
wxCheckBox * m_Class
wxCheckBox * m_Type
wxCheckBox * m_Topology
virtual void OnSelectButton(CSegregateSetsBase *win)
virtual void SetClusters()
void OnChoiceChanged(wxCommandEvent &event)
wxTextCtrl * m_Num
virtual void OnSelectButton(CSegregateSetsBase *win)
void OnSelect(wxCommandEvent &event)
void CollectLabels(objects::CSeq_entry_Handle seh, list< string > &strs)
map< string, vector< pair< int, string > > > m_Clusters
vector< vector< int > > m_Subsets
virtual void CreateControlsMiddle()
void OnUnselectAll(wxCommandEvent &event)
wxListCtrl * m_ListCtrl2
vector< vector< int > > & GetSubsets()
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
void CombineLabelsAll(const CSeq_id &id, set< string > &labels)
void CreateControls()
void OnButtonMoveRight(wxCommandEvent &event)
virtual void Init()
CRBSubpanel * GetEventCaller(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
CSegregateSetsBase * GetBaseFrame()
string GetLabel(objects::CSeq_entry_Handle seh)
virtual void SetClusters()
vector< int > m_Available
void CreateControlsHeader()
virtual void OnSelectButton(CSegregateSetsBase *win)
void CreateControlsFooter()
bool MatchConstraint(CRef< objects::edit::CStringConstraint > constraint, objects::CSeq_entry_Handle seh)
void OnButtonMoveLeft(wxCommandEvent &event)
wxTreeCtrl * m_TreeCtrl
void CollectLabelsAll(CSeq_entry_Handle seh, set< string > &strs)
void CombineLabels(const objects::CSeq_id &id, vector< string > &labels)
void OnSelectAll(wxCommandEvent &event)
virtual void PopulateSet(objects::CBioseq_set &new_set, const vector< int > &subset, CBioseq_set::EClass top_class)
objects::CSeq_entry_Handle GetTopSeqEntry()
void AddUserObject(objects::CBioseq_set &se)
void TakeFromSet(objects::CBioseq_set &changed_set, CRef< objects::CSeq_entry > se)
void ReadBioseq(const objects::CSeq_entry &se)
vector< SSetSeqRecord > m_SetSeq
void MoveDescrToEntries(objects::CBioseq_set &se)
objects::CSeq_entry_Handle m_TopSeqEntry
objects::CSeq_entry_Handle GetSeqEntry(unsigned int i)
static bool ShowToolTips()
Should we show tooltips?
ICommandProccessor * m_CmdProcessor
wxCheckBox * m_LeaveUp
void SetSubsets(const set< objects::CBioseq_Handle > &selected)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxNotebook * m_Notebook
virtual ~CSegregateSets()
Destructor.
vector< vector< int > > & GetSubsets()
virtual CRef< CCmdComposite > GetCommand()
void OnAccept(wxCommandEvent &event)
CSetClassPanel * m_SetClassPanel
CSegregateSets()
Constructors.
void OnCancel(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool Create(wxWindow *parent, wxWindowID id=ID_CSEGREGATE_SETS, const wxString &caption=_("Segregate Sets"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
static const CFeatList * GetFeatList()
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
void GetLabel(string *const label, ELabelType label_type) const
Definition: Seqdesc.cpp:134
@ eContent
Definition: Seqdesc.hpp:61
objects::CBioseq_set::EClass GetClass()
void SetClass(objects::CBioseq_set::EClass class_type)
CRef< edit::CStringConstraint > GetStringConstraint()
virtual void OnSelectButton(CSegregateSetsBase *win)
void GetAllLabels(wxArrayString &choices)
void OnChoiceChanged(wxCommandEvent &event)
void GetLabelsFromSeq(objects::CSeq_entry_Handle seh, set< string > &labels)
void ProcessUpdateFeatEvent(wxCommandEvent &event)
void OnChoiceChanged(wxCommandEvent &event)
void OnPageChanged(wxBookCtrlEvent &event)
virtual void SetClusters()
void UpdateChildrenFeaturePanels(wxSizer *sizer)
CConstraintPanel * m_Constraint
virtual void OnSelectButton(CSegregateSetsBase *win)
CUser_field & SetValue(int value)
set a data field to a given value Int8 and TGi values can be stored into 'str' field if the value doe...
Definition: User_field.hpp:283
CRef< CUser_field > SetFieldRef(const string &str, const string &delim=".", const string &obj_subtype=kEmptyStr, NStr::ECase use_case=NStr::eCase)
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
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
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
#define wxFIXED_MINSIZE
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
#define EVT_UPDATE_FEATURE_LIST(id, fn)
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#define ENUM_METHOD_NAME(EnumName)
Definition: serialbase.hpp:994
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:573
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
bool IsSetInst_Mol(void) const
TClass GetClass(void) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
bool CanGetClass(void) const
TSeqPos GetBioseqLength(void) const
TSet GetSet(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
TInst_Mol GetInst_Mol(void) const
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
TSeq GetSeq(void) const
TInst_Topology GetInst_Topology(void) const
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsSetClass(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
bool IsSet(void) const
bool IsSetId(void) const
bool IsSetInst_Topology(void) const
const TId & GetId(void) const
CConstRef< CBioseq_set > GetBioseq_setCore(void) const
Return core data for the bioseq-set.
bool IsSeq(void) const
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2887
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5411
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3550
@ eReverseSearch
Search in a backward direction.
Definition: ncbistr.hpp:1947
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
static const char label[]
bool IsSetData(void) const
the object itself Check if a value has been assigned to Data data member.
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
bool IsSetType(void) const
type of object within class Check if a value has been assigned to Type data member.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TData & GetData(void) const
Get the Data member data.
void SetType(TType &value)
Assign a value to Type data member.
const TLabel & GetLabel(void) const
Get the Label member data.
const TType & GetType(void) const
Get the Type member data.
bool CanGetLabel(void) const
Check if it is safe to call GetLabel method.
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
bool IsSetClass(void) const
Check if a value has been assigned to Class data member.
const TDescr & GetDescr(void) const
Get the Descr member data.
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
bool CanGetSeq_set(void) const
Check if it is safe to call GetSeq_set method.
TClass GetClass(void) const
Get the Class member data.
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSetDescr(void) const
Check if a value has been assigned to Descr data member.
bool CanGetClass(void) const
Check if it is safe to call GetClass method.
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
void ResetDescr(void)
Reset Descr data member.
void SetDescr(TDescr &value)
Assign a value to Descr data member.
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
@ eClass_genbank
converted genbank
const TUser & GetUser(void) const
Get the variant data.
Definition: Seqdesc_.cpp:384
const TInst & GetInst(void) const
Get the Inst member data.
Definition: Bioseq_.hpp:336
TTopology GetTopology(void) const
Get the Topology member data.
Definition: Seq_inst_.hpp:733
bool IsSetMol(void) const
Check if a value has been assigned to Mol data member.
Definition: Seq_inst_.hpp:593
bool IsSetBiomol(void) const
Check if a value has been assigned to Biomol data member.
Definition: MolInfo_.hpp:422
const TId & GetId(void) const
Get the Id member data.
Definition: Bioseq_.hpp:290
const Tdata & Get(void) const
Get the member data.
Definition: Seq_descr_.hpp:166
bool IsSetInst(void) const
the sequence data Check if a value has been assigned to Inst data member.
Definition: Bioseq_.hpp:324
TMol GetMol(void) const
Get the Mol member data.
Definition: Seq_inst_.hpp:612
E_Choice
Choice variants.
Definition: Seqdesc_.hpp:109
TBiomol GetBiomol(void) const
Get the Biomol member data.
Definition: MolInfo_.hpp:447
bool CanGetId(void) const
Check if it is safe to call GetId method.
Definition: Bioseq_.hpp:284
TUser & SetUser(void)
Select the variant.
Definition: Seqdesc_.cpp:390
bool IsSetId(void) const
equivalent identifiers Check if a value has been assigned to Id data member.
Definition: Bioseq_.hpp:278
const TMolinfo & GetMolinfo(void) const
Get the variant data.
Definition: Seqdesc_.cpp:588
static string SelectionName(E_Choice index)
Retrieve selection name (for diagnostic purposes).
Definition: Seqdesc_.cpp:218
bool IsSetTopology(void) const
Check if a value has been assigned to Topology data member.
Definition: Seq_inst_.hpp:708
@ e_MaxChoice
== e_Modelev+1
Definition: Seqdesc_.hpp:139
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
@ e_Molinfo
info on the molecule and techniques
Definition: Seqdesc_.hpp:134
@ e_not_set
No variant selected.
Definition: Seqdesc_.hpp:110
@ eMol_not_set
> cdna = rna
Definition: Seq_inst_.hpp:109
END_EVENT_TABLE()
int i
yy_size_t n
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::CREATED created
const char * tag
const CConstRef< CSeq_id > GetAccession(const CSeq_id_Handle &id_handle)
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
static static static wxID_ANY
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define EDIT_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
static const char * str(char *buf, int n)
Definition: stats.c:84
objects::CBioseq_set_Handle parent
objects::CSeq_entry_Handle entry
objects::CBioseq_set_Handle grandparent
SAnnotSelector –.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Tue Oct 03 02:48:03 2023 by modify_doxy.py rev. 669887