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

Go to the SVN repository for this file.

1 /* $Id: bulk_location_panel.cpp 42098 2018-12-19 16:32:59Z 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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
33 #include <objmgr/util/sequence.hpp>
34 ////@begin includes
35 ////@end includes
36 
39 #include <wx/sizer.h>
40 #include <wx/stattext.h>
41 
42 ////@begin XPM images
43 ////@end XPM images
44 
46 
48 
49 /*!
50  * CBulkLocationPanel type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( CBulkLocationPanel, wxPanel )
54 
55 
56 /*!
57  * CBulkLocationPanel event table definition
58  */
59 
60 BEGIN_EVENT_TABLE( CBulkLocationPanel, wxPanel )
61 
62 ////@begin CBulkLocationPanel event table entries
63  EVT_RADIOBUTTON( ID_BULKLOC_RBTN1, CBulkLocationPanel::OnBulklocRbtn1Selected )
64  EVT_RADIOBUTTON( ID_BULKLOC_RBTN2, CBulkLocationPanel::OnBulklocRbtn2Selected )
65 ////@end CBulkLocationPanel event table entries
66 
68 
69 
70 /*!
71  * CBulkLocationPanel constructors
72  */
73 
75 {
76  Init();
77 }
78 
79 CBulkLocationPanel::CBulkLocationPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
80 {
81  Init();
82  Create(parent, id, pos, size, style);
83 }
84 
85 
86 /*!
87  * CBulkLocationPanel creator
88  */
89 
90 bool CBulkLocationPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
91 {
92 ////@begin CBulkLocationPanel creation
93  wxPanel::Create( parent, id, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end CBulkLocationPanel creation
102  return true;
103 }
104 
105 
106 /*!
107  * CBulkLocationPanel destructor
108  */
109 
111 {
112 ////@begin CBulkLocationPanel destruction
113 ////@end CBulkLocationPanel destruction
114 }
115 
116 
117 /*!
118  * Member initialisation
119  */
120 
122 {
123 ////@begin CBulkLocationPanel member initialisation
124  m_Partial5 = NULL;
125  m_Partial3 = NULL;
126  m_Strand = NULL;
127  m_WholeSeq = NULL;
129  m_From = NULL;
130  m_To = NULL;
132 ////@end CBulkLocationPanel member initialisation
133 }
134 
135 
136 /*!
137  * Control creation for CBulkLocationPanel
138  */
139 
141 {
142 ////@begin CBulkLocationPanel content construction
143  CBulkLocationPanel* itemPanel1 = this;
144 
145  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
146  itemPanel1->SetSizer(itemBoxSizer2);
147 
148  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
149  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
150 
151  m_Partial5 = new wxCheckBox( itemPanel1, ID_BULKLOC_CHCKBOX1, _("Incomplete at 5' end"), wxDefaultPosition, wxDefaultSize, 0 );
152  m_Partial5->SetValue(false);
153  itemBoxSizer3->Add(m_Partial5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
154 
155  m_Partial3 = new wxCheckBox( itemPanel1, ID_BULKLOC_CHCKBOX2, _("Incomplete at 3' end"), wxDefaultPosition, wxDefaultSize, 0 );
156  m_Partial3->SetValue(false);
157  itemBoxSizer3->Add(m_Partial3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
158 
159  wxArrayString m_StrandStrings;
160  m_StrandStrings.Add(_("&Plus"));
161  m_StrandStrings.Add(_("&Minus"));
162  m_Strand = new wxRadioBox( itemPanel1, ID_BULKLOC_RBOX, _("Strand"), wxDefaultPosition, wxDefaultSize, m_StrandStrings, 1, wxRA_SPECIFY_ROWS );
163  m_Strand->SetSelection(0);
164  itemBoxSizer2->Add(m_Strand, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
165 
166  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
167  itemBoxSizer2->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
168 
169  wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL);
170  itemBoxSizer7->Add(itemBoxSizer8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  m_WholeSeq = new wxRadioButton( itemPanel1, ID_BULKLOC_RBTN1, _("Use Whole Sequence Interval"), wxDefaultPosition, wxSize(-1, 15), 0 );
173  m_WholeSeq->SetValue(true);
174  itemBoxSizer8->Add(m_WholeSeq, 0, wxALIGN_LEFT|wxALL, 5);
175 
176  m_Coordinates = new wxRadioButton( itemPanel1, ID_BULKLOC_RBTN2, _("Use these coordinates:"), wxDefaultPosition, wxSize(-1, 15), 0 );
177  m_Coordinates->SetValue(false);
178  itemBoxSizer8->Add(m_Coordinates, 0, wxALIGN_LEFT|wxALL, 5);
179 
180  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
181  itemBoxSizer7->Add(itemBoxSizer11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
182 
183  itemBoxSizer11->Add(5, 15, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
184 
185  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
186  itemBoxSizer11->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
187 
188  wxStaticText* itemStaticText14 = new wxStaticText( itemPanel1, wxID_STATIC, _("From"), wxDefaultPosition, wxDefaultSize, 0 );
189  itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
190 
191  m_From = new wxTextCtrl( itemPanel1, ID_BULKLOC_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
192  m_From->Enable(false);
193  itemBoxSizer13->Add(m_From, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
194 
195  wxStaticText* itemStaticText16 = new wxStaticText( itemPanel1, wxID_STATIC, _("To"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemBoxSizer13->Add(itemStaticText16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
197 
198  m_To = new wxTextCtrl( itemPanel1, ID_BULKLOC_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
199  m_To->Enable(false);
200  itemBoxSizer13->Add(m_To, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
201 
202  m_AddToExisting = new wxCheckBox( itemPanel1, ID_BULKLOC_CHCKBOX3, _("Also add to sequences that already have a feature like this"), wxDefaultPosition, wxDefaultSize, 0 );
203  m_AddToExisting->SetValue(true);
204  itemBoxSizer2->Add(m_AddToExisting, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
205 
206 ////@end CBulkLocationPanel content construction
207 }
208 
209 
210 /*!
211  * Should we show tooltips?
212  */
213 
215 {
216  return true;
217 }
218 
219 /*!
220  * Get bitmap resources
221  */
222 
223 wxBitmap CBulkLocationPanel::GetBitmapResource( const wxString& name )
224 {
225  // Bitmap retrieval
226 ////@begin CBulkLocationPanel bitmap retrieval
227  wxUnusedVar(name);
228  return wxNullBitmap;
229 ////@end CBulkLocationPanel bitmap retrieval
230 }
231 
232 /*!
233  * Get icon resources
234  */
235 
236 wxIcon CBulkLocationPanel::GetIconResource( const wxString& name )
237 {
238  // Icon retrieval
239 ////@begin CBulkLocationPanel icon retrieval
240  wxUnusedVar(name);
241  return wxNullIcon;
242 ////@end CBulkLocationPanel icon retrieval
243 }
244 
245 
246 /*!
247  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_RADIOBUTTON2
248  */
249 
250 void CBulkLocationPanel::OnBulklocRbtn1Selected( wxCommandEvent& event )
251 {
252  m_From->Enable(false);
253  m_To->Enable(false);
254 }
255 
256 
257 /*!
258  * wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_RADIOBUTTON3
259  */
260 
261 void CBulkLocationPanel::OnBulklocRbtn2Selected( wxCommandEvent& event )
262 {
263  m_From->Enable(true);
264  m_To->Enable(true);
265 }
266 
267 
269 {
270  int max = bioseq.GetLength() - 1;
271  int from = 0;
272  int to = max;
273  bool fuzz = false;
274  if (m_Coordinates->GetValue()) {
275  string val = ToStdString(m_From->GetValue());
276  if (NStr::IsBlank(val)) {
278  return empty;
279  } else {
280  try {
281  fuzz |= NStr::StartsWith(val,"^") || NStr::EndsWith(val,"^");
284  from = NStr::StringToInt(val);
285  from = from - 1;
286  } catch(CException &e) {
288  return empty;
289  }
290  catch (exception &e) {
292  return empty;
293  }
294  }
295 
296  val = ToStdString(m_To->GetValue());
297  if (NStr::IsBlank(val)) {
299  return empty;
300  } else {
301  try {
302  fuzz |= NStr::StartsWith(val,"^") || NStr::EndsWith(val,"^");
305  to = NStr::StringToInt(val);
306  to = to - 1;
307  } catch(CException &e) {
309  return empty;
310  }
311  catch (exception &e) {
313  return empty;
314  }
315  }
316 
317  if (from > max) {
318  from = max;
319  }
320  if (to > max) {
321  to = max;
322  }
323  if (from > to) {
324  int swap = from;
325  from = to;
326  to = swap;
327  }
328  }
329 
330 
331  CRef<CSeq_loc> loc(new CSeq_loc());
332 
334  if (from == to)
335  {
336  CRef<CSeq_point> seq_pnt(new CSeq_point);
337  seq_pnt->SetPoint(from);
338  if (m_Strand->GetSelection() == 1) {
339  seq_pnt->SetStrand(eNa_strand_minus);
340  }
341  seq_pnt->SetId().Assign(*best_idh.GetSeqId());
342  loc->SetPnt(*seq_pnt);
343  }
344  else if (fuzz && abs(to - from) <= 1)
345  {
346  CRef<CSeq_point> seq_pnt(new CSeq_point);
347  seq_pnt->SetPoint(from);
348  if (m_Strand->GetSelection() == 1) {
349  seq_pnt->SetStrand(eNa_strand_minus);
350  }
351  seq_pnt->SetId().Assign(*best_idh.GetSeqId());
352  seq_pnt->SetFuzz().SetLim(CInt_fuzz::eLim_tr);
353  loc->SetPnt(*seq_pnt);
354  }
355  else
356  {
357  loc->SetInt().SetId().Assign(*best_idh.GetSeqId());
358  loc->SetInt().SetFrom(from);
359  loc->SetInt().SetTo(to);
360 
361  if (m_Strand->GetSelection() == 1) {
362  loc->SetInt().SetStrand(eNa_strand_minus);
363  }
364  }
365 
366  if (m_Partial5->GetValue()) {
368  }
369  if (m_Partial3->GetValue()) {
370  loc->SetPartialStop (true, eExtreme_Biological);
371  }
372  return loc;
373 }
374 
375 
377 
378 
379 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
USING_SCOPE(ncbi::objects)
TSeqPos GetLength(void) const
Definition: Bioseq.cpp:360
~CBulkLocationPanel()
Destructor.
wxRadioButton * m_Coordinates
CRef< objects::CSeq_loc > GetLocForBioseq(const objects::CBioseq &bioseq)
CBulkLocationPanel()
Constructors.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxRadioButton * m_WholeSeq
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
void OnBulklocRbtn2Selected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_BULKLOC_RBTN2
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CBULKLOCATIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 500), long style=wxTAB_TRAVERSAL)
Creation.
void OnBulklocRbtn1Selected(wxCommandEvent &event)
wxEVT_COMMAND_RADIOBUTTON_SELECTED event handler for ID_BULKLOC_RBTN1
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define NULL
Definition: ncbistd.hpp:225
CConstRef< CSeq_id > GetSeqId(void) const
void SetPnt(TPnt &v)
Definition: Seq_loc.hpp:985
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
void SetPartialStart(bool val, ESeqLocExtremes ext)
set / remove e_Lim fuzz on start or stop (lt/gt - indicating partial interval)
Definition: Seq_loc.cpp:3280
void SetPartialStop(bool val, ESeqLocExtremes ext)
Definition: Seq_loc.cpp:3313
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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:5412
static void TrimSuffixInPlace(string &str, const CTempString suffix, ECase use_case=eCase)
Trim suffix from a string (in-place)
Definition: ncbistr.cpp:3274
static void TrimPrefixInPlace(string &str, const CTempString prefix, ECase use_case=eCase)
Trim prefix from a string (in-place)
Definition: ncbistr.cpp:3238
@ eLim_tr
space to right of position
Definition: Int_fuzz_.hpp:213
void SetPoint(TPoint value)
Assign a value to Point data member.
Definition: Seq_point_.hpp:312
void SetId(TId &value)
Assign a value to Id data member.
Definition: Seq_point_.cpp:61
void SetStrand(TStrand value)
Assign a value to Strand data member.
Definition: Seq_point_.hpp:359
void SetFuzz(TFuzz &value)
Assign a value to Fuzz data member.
Definition: Seq_point_.cpp:71
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
END_EVENT_TABLE()
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
#define abs(a)
Definition: ncbi_heapmgr.c:130
T max(T x_, T y_)
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat Feb 24 07:48:44 2024 by modify_doxy.py rev. 669887