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

Go to the SVN repository for this file.

1 /* $Id: resolve_intersecting_feats.cpp 34540 2016-01-21 21:06:51Z asztalos $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: 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( CResolveIntersectingFeats, CBulkCmdDlg )
65 
66 
67 BEGIN_EVENT_TABLE( CResolveIntersectingFeats, 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 CResolveIntersectingFeats::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 {
119 }
120 
121 
122 
123 
125 {
126  CResolveIntersectingFeats* itemDialog1 = this;
127 
128  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
129  itemDialog1->SetSizer(itemBoxSizer2);
130 
131  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
132  itemBoxSizer2->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
133 
134  wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL);
135  itemBoxSizer7->Add(itemBoxSizer8, 0, wxALL|wxGROW, 0);
136 
137  wxStaticText* itemStaticText1 = new wxStaticText( itemDialog1, wxID_STATIC, _("Trim features of type"), wxDefaultPosition, wxDefaultSize, 0 );
138  itemBoxSizer8->Add(itemStaticText1, 1, wxALIGN_TOP|wxALL, 5);
139 
140  wxStaticText* itemStaticText2 = new wxStaticText( itemDialog1, wxID_STATIC, _("Where they overlap features of type"), wxDefaultPosition, wxDefaultSize, 0 );
141  itemBoxSizer8->Add(itemStaticText2, 1, wxALIGN_TOP|wxALL, 5);
142 
143  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
144  itemBoxSizer7->Add(itemBoxSizer9, 0, wxALIGN_TOP|wxALL, 0);
145 
146  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
147  itemBoxSizer9->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
148 
149  m_FeatureType1 = new CFeatureTypePanel(itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
150  itemBoxSizer3->Add(m_FeatureType1, 0, wxALIGN_TOP|wxALL, 5);
152 
153  wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Constraints"));
154  wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxHORIZONTAL);
155  itemBoxSizer3->Add(itemStaticBoxSizer4, 0, wxALIGN_TOP|wxALL, 5);
156 
157  m_FeatureConstraint1 = new CFeatureFieldNamePanel(itemDialog1, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
158  itemStaticBoxSizer4->Add(m_FeatureConstraint1, 0, wxALIGN_TOP|wxALL, 5);
160 
161  m_StringConstraintPanel1 = new CStringConstraintPanel( itemDialog1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
162  itemStaticBoxSizer4->Add(m_StringConstraintPanel1, 0, wxALIGN_TOP|wxALL, 5);
163 
164  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
165  itemBoxSizer9->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
166 
167  m_FeatureType2 = new CFeatureTypePanel(itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
168  itemBoxSizer5->Add(m_FeatureType2, 0, wxALIGN_TOP|wxALL, 5);
170 
171  wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Constraints"));
172  wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxHORIZONTAL);
173  itemBoxSizer5->Add(itemStaticBoxSizer6, 0, wxALIGN_TOP|wxALL, 5);
174 
175  m_FeatureConstraint2 = new CFeatureFieldNamePanel(itemDialog1, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
176  itemStaticBoxSizer6->Add(m_FeatureConstraint2, 0, wxALIGN_TOP|wxALL, 5);
178 
179  m_StringConstraintPanel2 = new CStringConstraintPanel( itemDialog1, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
180  itemStaticBoxSizer6->Add(m_StringConstraintPanel2, 0, wxALIGN_TOP|wxALL, 5);
181 
182  COkCancelPanel *OkCancel = new COkCancelPanel( itemDialog1, ID_RESOLVE_INTERSECTING_FEATS_OKCANCEL, wxDefaultPosition, wxSize(100, 100), 0 );
183  itemBoxSizer2->Add(OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
184 }
185 
186 
187 /*!
188  * Should we show tooltips?
189  */
190 
192 {
193  return true;
194 }
195 
196 /*!
197  * Get bitmap resources
198  */
199 
200 wxBitmap CResolveIntersectingFeats::GetBitmapResource( const wxString& name )
201 {
202  // Bitmap retrieval
203  wxUnusedVar(name);
204  return wxNullBitmap;
205 }
206 
207 /*!
208  * Get icon resources
209  */
210 
211 wxIcon CResolveIntersectingFeats::GetIconResource( const wxString& name )
212 {
213  // Icon retrieval
214  wxUnusedVar(name);
215  return wxNullIcon;
216 }
217 
219 {
220  CRef<CCmdComposite> cmd( new CCmdComposite("Resolve Feature Overlap") );
221 
222  string field_name1 = m_FeatureType1->GetFieldName(true);
223  if (field_name1.empty())
224  return cmd;
225  field_name1 += " " + kPartialStart;
226 
228  string constraint_field1 = m_FeatureConstraint1->GetFieldName(false);
229 
231  vector<CRef<edit::CApplyObject> > objects1 = col1->GetApplyObjects(m_TopSeqEntry, constraint_field1, constraint1);
232 
233  string field_name2 = m_FeatureType2->GetFieldName(true);
234  if (field_name2.empty())
235  return cmd;
236  field_name2 += " " + kPartialStart;
237 
239  string constraint_field2 = m_FeatureConstraint2->GetFieldName(false);
240 
242  vector<CRef<edit::CApplyObject> > objects2 = col2->GetApplyObjects(m_TopSeqEntry, constraint_field2, constraint2);
243 
244  CScope &scope = m_TopSeqEntry.GetScope();
245 
246  ITERATE(vector<CRef<edit::CApplyObject> >, obj_it1, objects1)
247  {
248  const CSeq_feat *feat1 = dynamic_cast<const CSeq_feat*> ( (*obj_it1)->GetOriginalObject() );
249  if (feat1)
250  {
251  ITERATE(vector<CRef<edit::CApplyObject> >, obj_it2, objects2)
252  {
253  const CSeq_feat *feat2 = dynamic_cast<const CSeq_feat*> ( (*obj_it2)->GetOriginalObject() );
254  if (feat2)
255  {
256  if (feat1->IsSetLocation() && feat2->IsSetLocation() && sequence::TestForOverlap(feat1->GetLocation(), feat2->GetLocation(),sequence::eOverlap_Interval, kInvalidSeqPos, &scope) != -1)
257  {
258  CRef<CSeq_feat> new_feat(new CSeq_feat);
259  new_feat->Assign(*feat1);
260  CRef<CSeq_loc> new_loc = sequence::Seq_loc_Subtract(feat1->GetLocation(), feat2->GetLocation(), 0, &scope);
261  if (new_loc)
262  {
263  new_feat->SetLocation(*new_loc);
265  CSeq_feat_Handle fh = scope.GetSeq_featHandle(*feat1);
266  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(fh, *new_feat)));
267  }
268  }
269  }
270  }
271  }
272  }
273 
274 
275  return cmd;
276 }
277 
278 
280 {
281  UpdateChildrenFeaturePanels(this->GetSizer());
282 }
283 
285 {
286  wxSizerItemList& slist = sizer->GetChildren();
287  int n =0;
288  for (wxSizerItemList::iterator iter = slist.begin(); iter != slist.end(); ++iter, ++n) {
289  if ((*iter)->IsSizer()) {
290  UpdateChildrenFeaturePanels((*iter)->GetSizer());
291  } else if ((*iter)->IsWindow()) {
292  wxWindow* child = (*iter)->GetWindow();
293  if (child) {
294  CFeatureTypePanel* panel = dynamic_cast<CFeatureTypePanel*>(child);
295  if (panel) {
297  } else {
298  wxSizer* subsizer = child->GetSizer();
299  if (subsizer) {
300  UpdateChildrenFeaturePanels(subsizer);
301  }
302  }
303  }
304  }
305  }
306 }
307 
308 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
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)
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)
void UpdateChildrenFeaturePanels(wxSizer *sizer)
static bool ShowToolTips()
Should we show tooltips?
CFeatureFieldNamePanel * m_FeatureConstraint1
void Init()
Initialises member variables.
CStringConstraintPanel * m_StringConstraintPanel2
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CFeatureFieldNamePanel * m_FeatureConstraint2
void CreateControls()
Creates the controls and sizers.
CStringConstraintPanel * m_StringConstraintPanel1
void ProcessUpdateFeatEvent(wxCommandEvent &event)
bool Create(wxWindow *parent, wxWindowID id=11000, const wxString &caption=_("Resolve Feature Overlaps"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
virtual CRef< CCmdComposite > GetCommand()
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CScope –.
Definition: scope.hpp:92
CSeq_feat_Handle –.
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
#define _(proto)
Definition: ct_nlmzip_i.h:78
const string kPartialStart
#define EVT_UPDATE_FEATURE_LIST(id, fn)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static char col1[256]
Definition: compute.c:13
static char col2[256]
Definition: compute.c:13
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
bool IsPartialStart(ESeqLocExtremes ext) const
check start or stop of location for e_Lim fuzz
Definition: Seq_loc.cpp:3222
bool IsPartialStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:3251
CRef< CSeq_loc > Seq_loc_Subtract(const CSeq_loc &loc1, const CSeq_loc &loc2, CSeq_loc::TOpFlags flags, CScope *scope)
Subtract the second seq-loc from the first one.
int TestForOverlap(const CSeq_loc &loc1, const CSeq_loc &loc2, EOverlapType type, TSeqPos circular_len=kInvalidSeqPos, CScope *scope=0)
Calls TestForOverlap64() and if the result is greater than kMax_Int truncates it to kMax_Int.
@ eOverlap_Interval
at least one pair of intervals must overlap
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
void SetPartial(TPartial value)
Assign a value to Partial data member.
Definition: Seq_feat_.hpp:971
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
bool IsSetLocation(void) const
feature made from Check if a value has been assigned to Location data member.
Definition: Seq_feat_.hpp:1105
END_EVENT_TABLE()
yy_size_t n
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_RESOLVE_INTERSECTING_FEATS_OKCANCEL
static static static wxID_ANY
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
Modified on Fri Apr 12 17:22:12 2024 by modify_doxy.py rev. 669887