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

Go to the SVN repository for this file.

1 /* $Id: remove_dup_feats_dlg.cpp 40679 2018-03-28 21:45:29Z filippov $
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 #include <objmgr/scope.hpp>
37 #include <objmgr/feat_ci.hpp>
38 #include <objmgr/seq_annot_ci.hpp>
39 #include <objmgr/bioseq_ci.hpp>
41 #include <objmgr/util/feature.hpp>
45 #include <gui/objutils/utils.hpp>
50 
51 #include <util/xregexp/regexp.hpp>
52 
53 #include <wx/button.h>
54 #include <wx/statbox.h>
55 #include <wx/msgdlg.h>
56 
57 ////@begin XPM images
58 ////@end XPM images
59 
61 
62 
63 
64 IMPLEMENT_DYNAMIC_CLASS( CRmDupFeaturesDlg, CBulkCmdDlg )
65 
66 
67 BEGIN_EVENT_TABLE( CRmDupFeaturesDlg, CBulkCmdDlg )
70 
72 {
73  Init();
74 }
75 
77  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
78  : CBulkCmdDlg(wb)
79 {
80  Init();
81  Create(parent, id, caption, pos, size, style);
82 }
83 
84 
85 bool CRmDupFeaturesDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 {
87  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
88  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
89 
91  if (GetSizer())
92  {
93  GetSizer()->SetSizeHints(this);
94  }
95  Centre();
96 
97 
98  return true;
99 }
100 
101 
103 {
104 }
105 
106 
107 /*!
108  * Member initialisation
109  */
110 
112 {
117 }
118 
119 
120 
121 
123 {
124  CRmDupFeaturesDlg* itemDialog1 = this;
125 
126  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
127  itemDialog1->SetSizer(itemBoxSizer2);
128 
129  m_FeatureType = new CFeatureTypePanel(itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
130  itemBoxSizer2->Add(m_FeatureType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
132 
133  m_CheckPartials = new wxCheckBox( itemDialog1, wxID_ANY, _("Check partials"), wxDefaultPosition, wxDefaultSize, 0 );
134  m_CheckPartials->SetValue(false);
135  itemBoxSizer2->Add(m_CheckPartials, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
136 
137  m_CaseSensitive = new wxCheckBox( itemDialog1, wxID_ANY, _("Case sensitive"), wxDefaultPosition, wxDefaultSize, 0 );
138  m_CaseSensitive->SetValue(false);
139  itemBoxSizer2->Add(m_CaseSensitive, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
140 
141  m_RemoveProteins = new wxCheckBox( itemDialog1, wxID_ANY, _("Remove proteins"), wxDefaultPosition, wxDefaultSize, 0 );
142  m_RemoveProteins->SetValue(true);
143  itemBoxSizer2->Add(m_RemoveProteins, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
144 
145  m_FeatureConstraint = new CFeatureFieldNamePanel(itemDialog1, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
146  itemBoxSizer2->Add(m_FeatureConstraint, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
148 
149  m_StringConstraintPanel = new CStringConstraintPanel( itemDialog1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
150  itemBoxSizer2->Add(m_StringConstraintPanel, 0, wxALIGN_LEFT|wxALL, 0);
151 
152  COkCancelPanel *OkCancel = new COkCancelPanel( itemDialog1, ID_RM_DUP_FEATURES_OKCANCEL, wxDefaultPosition, wxSize(100, 100), 0 );
153  itemBoxSizer2->Add(OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
154 }
155 
156 
157 /*!
158  * Should we show tooltips?
159  */
160 
162 {
163  return true;
164 }
165 
166 /*!
167  * Get bitmap resources
168  */
169 
170 wxBitmap CRmDupFeaturesDlg::GetBitmapResource( const wxString& name )
171 {
172  // Bitmap retrieval
173  wxUnusedVar(name);
174  return wxNullBitmap;
175 }
176 
177 /*!
178  * Get icon resources
179  */
180 
181 wxIcon CRmDupFeaturesDlg::GetIconResource( const wxString& name )
182 {
183  // Icon retrieval
184  wxUnusedVar(name);
185  return wxNullIcon;
186 }
187 
189 {
190  CRef<CCmdComposite> cmd( new CCmdComposite("Remove Duplicate Features") );
191  bool modified = false;
193 
194 
195  string field_name = m_FeatureType->GetFieldName(true);
196  if (field_name.empty())
197  return empty;
198  int itype, isubtype;
199  if (!CSeqFeatData::GetFeatList()->GetTypeSubType(field_name, itype, isubtype))
200  return empty;
201  CSeqFeatData::ESubtype subtype = static_cast<CSeqFeatData::ESubtype>(isubtype);
202 
203  vector<CSeq_entry_Handle> entry_handles;
205  string constraint_field = m_FeatureConstraint->GetFieldName(false);
206  if (constraint && !constraint_field.empty())
207  {
208  CRef<CMiscSeqTableColumn> col(new CMiscSeqTableColumn(constraint_field));
209  vector<CRef<edit::CApplyObject> > objects = col->GetApplyObjects(m_TopSeqEntry, constraint_field, constraint);
210  ITERATE(vector<CRef<edit::CApplyObject> >, obj_it, objects)
211  {
212  const CSeq_feat *feat = dynamic_cast<const CSeq_feat*> ( (*obj_it)->GetOriginalObject() );
213  if (feat)
214  {
215  CBioseq_Handle bsh = m_TopSeqEntry.GetScope().GetBioseqHandle(feat->GetLocation());
216  if (bsh)
217  {
218  entry_handles.push_back(bsh.GetSeq_entry_Handle());
219  }
220  }
221  }
222  }
223  else
224  {
225  entry_handles.push_back(m_TopSeqEntry);
226  }
227 
228  bool remove_proteins = m_RemoveProteins->GetValue();
230  GetProductToCDSMap(m_TopSeqEntry.GetScope(), product_to_cds);
231  ITERATE(vector<CSeq_entry_Handle>, seh_it, entry_handles)
232  {
233  set< CSeq_feat_Handle > deleted_feats;
234  for (CFeat_CI feat1(*seh_it, SAnnotSelector(subtype)); feat1; ++feat1)
235  {
236  for (CFeat_CI feat2(*seh_it, SAnnotSelector(subtype)); feat2; ++feat2)
237  {
238  if (feat1->GetSeq_feat_Handle() < feat2->GetSeq_feat_Handle() &&
239  deleted_feats.find(feat1->GetSeq_feat_Handle()) == deleted_feats.end() &&
240  deleted_feats.find(feat2->GetSeq_feat_Handle()) == deleted_feats.end() &&
241  validator::IsDuplicate(feat1->GetSeq_feat_Handle(),feat2->GetSeq_feat_Handle(), m_CheckPartials->GetValue(), m_CaseSensitive->GetValue()) != validator::eDuplicate_Not )
242  {
243  cmd->AddCommand(*GetDeleteFeatureCommand(feat2->GetSeq_feat_Handle(), remove_proteins, product_to_cds));
244  deleted_feats.insert(feat2->GetSeq_feat_Handle());
245  modified = true;
246  }
247  }
248  }
249  }
250  if (modified)
251  return cmd;
252  return empty;
253 }
254 
255 
256 void CRmDupFeaturesDlg::ProcessUpdateFeatEvent( wxCommandEvent& event )
257 {
258  UpdateChildrenFeaturePanels(this->GetSizer());
259 }
260 
262 {
263  wxSizerItemList& slist = sizer->GetChildren();
264  int n =0;
265  for (wxSizerItemList::iterator iter = slist.begin(); iter != slist.end(); ++iter, ++n) {
266  if ((*iter)->IsSizer()) {
267  UpdateChildrenFeaturePanels((*iter)->GetSizer());
268  } else if ((*iter)->IsWindow()) {
269  wxWindow* child = (*iter)->GetWindow();
270  if (child) {
271  CFeatureTypePanel* panel = dynamic_cast<CFeatureTypePanel*>(child);
272  if (panel) {
274  } else {
275  wxSizer* subsizer = child->GetSizer();
276  if (subsizer) {
277  UpdateChildrenFeaturePanels(subsizer);
278  }
279  }
280  }
281  }
282  }
283 }
284 
285 
CBioseq_Handle –.
objects::CSeq_entry_Handle m_TopSeqEntry
bool Create(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
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.
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)
vector< CRef< objects::edit::CApplyObject > > GetApplyObjects(objects::CBioseq_Handle bsh)
CStringConstraintPanel * m_StringConstraintPanel
bool Create(wxWindow *parent, wxWindowID id=11000, const wxString &caption=_("Remove Duplicate Features"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
void Init()
Initialises member variables.
CFeatureFieldNamePanel * m_FeatureConstraint
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
static bool ShowToolTips()
Should we show tooltips?
virtual CRef< CCmdComposite > GetCommand()
void CreateControls()
Creates the controls and sizers.
CFeatureTypePanel * m_FeatureType
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void UpdateChildrenFeaturePanels(wxSizer *sizer)
void ProcessUpdateFeatEvent(wxCommandEvent &event)
CRmDupFeaturesDlg()
Constructors.
static const CFeatList * GetFeatList()
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CRef< edit::CStringConstraint > GetStringConstraint()
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
Definition: map.hpp:338
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define EVT_UPDATE_FEATURE_LIST(id, fn)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
END_EVENT_TABLE()
yy_size_t n
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
EDuplicateFeatureType IsDuplicate(const CSeq_feat_Handle &f1, const CSeq_feat_Handle &f2, bool check_partials=false, bool case_sensitive=false)
Reports how two features duplicate each other.
Definition: utilities.cpp:1838
@ eDuplicate_Not
Definition: utilities.hpp:192
#define ID_RM_DUP_FEATURES_OKCANCEL
static static static wxID_ANY
SAnnotSelector –.
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
void GetProductToCDSMap(objects::CScope &scope, map< objects::CBioseq_Handle, set< objects::CSeq_feat_Handle > > &product_to_cds)
CRef< CCmdComposite > GetDeleteFeatureCommand(const objects::CSeq_feat_Handle &fh, bool remove_proteins=true)
Modified on Thu Jul 18 16:08:35 2024 by modify_doxy.py rev. 669887