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

Go to the SVN repository for this file.

1 /* $Id: macro_feats_on_seq_constraint_panel.cpp 46807 2021-10-20 18:32:21Z 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  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>
32 
36 #include <gui/objutils/utils.hpp>
37 
45 
46 #include <wx/statbox.h>
47 #include <wx/stattext.h>
48 #include <wx/textctrl.h>
49 #include <wx/choice.h>
50 #include <wx/sizer.h>
51 #include <wx/valtext.h>
52 
55 /*
56  * CMacroFeatsOnSeqPanel type definition
57  */
58 
60 
61 
62 /*
63  * CMacroFeatsOnSeqPanel event table definition
64  */
65 
66 BEGIN_EVENT_TABLE( CMacroFeatsOnSeqPanel, wxPanel )
71 
72 
73 /*
74  * CMacroFeatsOnSeqPanel constructors
75  */
76 
78 {
79  Init();
80 }
81 
82 CMacroFeatsOnSeqPanel::CMacroFeatsOnSeqPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
83 {
84  Init();
85  Create( parent, id, pos, size, style );
86 }
87 
88 
89 /*
90  * CMacroFeatsOnSeqPanel creator
91  */
92 
93 bool CMacroFeatsOnSeqPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
94 {
95 ////@begin CMacroFeatsOnSeqPanel creation
96  wxPanel::Create( parent, id, pos, size, style );
97 
99  Centre();
100 ////@end CMacroFeatsOnSeqPanel creation
101  return true;
102 }
103 
104 
105 /*
106  * CMacroFeatsOnSeqPanel destructor
107  */
108 
110 {
111 ////@begin CMacroFeatsOnSeqPanel destruction
112 ////@end CMacroFeatsOnSeqPanel destruction
113 }
114 
115 
116 /*
117  * Member initialisation
118  */
119 
121 {
122 ////@begin CMacroFeatsOnSeqPanel member initialisation
124  m_FeatChoice = NULL;
125  m_FeatCount = NULL;
127  m_Length = NULL;
135 ////@end CMacroFeatsOnSeqPanel member initialisation
136 }
137 
138 
139 /*
140  * Control creation for CMacroFeatsOnSeqPanel
141  */
142 
144 {
145 ////@begin CMacroFeatsOnSeqPanel content construction
146  CMacroFeatsOnSeqPanel* itemPanel2 = this;
147 
148  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
149  itemPanel2->SetSizer(itemBoxSizer1);
150 
151  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemPanel2, wxID_ANY, _("Number of features on sequence"));
152  wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxHORIZONTAL);
153  itemBoxSizer1->Add(itemStaticBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
154 
155  m_FeatureType = new CFeatureTypePanel( itemPanel2, wxID_ANY, wxDefaultPosition, wxSize(100, 100), wxSIMPLE_BORDER );
156  itemStaticBoxSizer4->Add(m_FeatureType, 0, wxALIGN_TOP|wxALL, 5);
157  objects::CSeq_entry_Handle seh;
160 
161  wxArrayString countTypeStrings;
162  countTypeStrings.Add(_("Exactly"));
163  countTypeStrings.Add(_("Fewer than"));
164  countTypeStrings.Add(_("Fewer than or equal to"));
165  countTypeStrings.Add(_("More than"));
166  countTypeStrings.Add(_("More than or equal to"));
167  m_FeatChoice = new wxChoice( itemPanel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, countTypeStrings, 0 );
168  m_FeatChoice->SetSelection(0);
169  itemStaticBoxSizer4->Add(m_FeatChoice, 0, wxALIGN_TOP|wxALL, 5);
170 
171  m_FeatCount = new wxTextCtrl( itemPanel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
172  itemStaticBoxSizer4->Add(m_FeatCount, 0, wxALIGN_TOP|wxALL, 5);
173  m_FeatCount->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
174 
175  wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(0, 2, 0, 0);
176  itemBoxSizer1->Add(itemFlexGridSizer5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
177 
178  wxStaticText* itemStaticText6 = new wxStaticText(itemPanel2, wxID_STATIC, _("Length of sequence"), wxDefaultPosition, wxDefaultSize, 0);
179  itemFlexGridSizer5->Add(itemStaticText6, 0, wxALIGN_RIGHT | wxALL, 5);
180 
181  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
182  itemFlexGridSizer5->Add(itemBoxSizer7, 0, wxALIGN_LEFT, 0);
183 
184  countTypeStrings.Insert("Any", 0);
185  m_LengthChoice = new wxChoice(itemPanel2, ID_MACRO_FEATS_CHOICE, wxDefaultPosition, wxDefaultSize, countTypeStrings, 0);
186  m_LengthChoice->SetSelection(0);
187  itemBoxSizer7->Add(m_LengthChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
188 
189  m_Length = new wxTextCtrl(itemPanel2, ID_MACRO_FEATS_LENGTHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
190  itemBoxSizer7->Add(m_Length, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
191  m_Length->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
192 
193  wxStaticText* itemStaticText8 = new wxStaticText(itemPanel2, wxID_STATIC, _("Sequence representation"), wxDefaultPosition, wxDefaultSize, 0);
194  itemFlexGridSizer5->Add(itemStaticText8, 0, wxALIGN_RIGHT | wxALL, 5);
195 
196  wxArrayString seqReprStrings;
197  bool allow_other = false;
198  vector<string> choices = CMolInfoFieldType::GetChoicesForField(CMolInfoFieldType::e_Repr, allow_other);
199  ToArrayString(choices, seqReprStrings);
200  seqReprStrings.Insert("Default", 0);
201  m_SeqReprChoice = new wxChoice(itemPanel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, seqReprStrings, 0);
202  m_SeqReprChoice->SetSelection(0);
203  itemFlexGridSizer5->Add(m_SeqReprChoice, 0, wxALIGN_LEFT | wxALL, 5);
204 
205  wxFlexGridSizer* itemFlexGridSizer8 = new wxFlexGridSizer(0, 2, 0, 0);
206  itemBoxSizer1->Add(itemFlexGridSizer8, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
207 
208  wxStaticText* itemStaticText9 = new wxStaticText(itemPanel2, wxID_STATIC, _("There are"), wxDefaultPosition, wxDefaultSize, 0);
209  itemFlexGridSizer8->Add(itemStaticText9, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
210 
211  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
212  itemFlexGridSizer8->Add(itemBoxSizer10, 0, wxALIGN_LEFT | wxALL, 0);
213 
214  wxArrayString distancetypes;
215  distancetypes.Add(_("Any distance"));
216  distancetypes.Add(_("Exactly"));
217  distancetypes.Add(_("At least"));
218  distancetypes.Add(_("At most"));
219  m_Dist5EndChoice = new wxChoice(itemPanel2, ID_MACRO_FEATS_DISTCHOICE1, wxDefaultPosition, wxDefaultSize, distancetypes, 0);
220  m_Dist5EndChoice->SetSelection(0);
221  itemBoxSizer10->Add(m_Dist5EndChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
222 
223  m_5EndDistance = new wxTextCtrl(itemPanel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
224  itemBoxSizer10->Add(m_5EndDistance, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
225  m_5EndDistance->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
226  m_5EndDistance->Disable();
227 
228  wxStaticText* itemStaticText11 = new wxStaticText(itemPanel2, wxID_STATIC, _("nucleotides before the first"), wxDefaultPosition, wxDefaultSize, 0);
229  itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
230 
231  wxArrayString features = x_GetFeatureChoices();
232  m_FirstFeatureChoice = new wxChoice(itemPanel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, features, 0);
233  m_FirstFeatureChoice->SetSelection(0);
234  itemBoxSizer10->Add(m_FirstFeatureChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
235 
236  wxStaticText* itemStaticText12 = new wxStaticText(itemPanel2, wxID_STATIC, _("There are"), wxDefaultPosition, wxDefaultSize, 0);
237  itemFlexGridSizer8->Add(itemStaticText12, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL |wxRIGHT, 5);
238 
239  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
240  itemFlexGridSizer8->Add(itemBoxSizer13, 0, wxALIGN_LEFT | wxALL, 0);
241 
242  m_Dist3EndChoice = new wxChoice(itemPanel2, ID_MACRO_FEATS_DISTCHOICE2, wxDefaultPosition, wxDefaultSize, distancetypes, 0);
243  m_Dist3EndChoice->SetSelection(0);
244  itemBoxSizer13->Add(m_Dist3EndChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
245 
246  m_3EndDistance = new wxTextCtrl(itemPanel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
247  itemBoxSizer13->Add(m_3EndDistance, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
248  m_3EndDistance->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
249  m_3EndDistance->Disable();
250 
251  wxStaticText* itemStaticText14 = new wxStaticText(itemPanel2, wxID_STATIC, _("nucleotides after the last"), wxDefaultPosition, wxDefaultSize, 0);
252  itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
253 
254  m_LastFeatureChoice = new wxChoice(itemPanel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, features, 0);
255  m_LastFeatureChoice->SetSelection(0);
256  itemBoxSizer13->Add(m_LastFeatureChoice, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
257 
258 ////@end CMacroFeatsOnSeqPanel content construction
259 }
260 
261 // includes the feature names and the option 'Any'
263 {
264  set<string> existing;
265  map<pair<int, int>, string> types;
266  vector<string> features;
267 
268  CSeq_entry_Handle seh;
269  vector<const CFeatListItem *> featlist = GetSortedFeatList(seh);
270 
271  ITERATE(vector<const CFeatListItem *>, feat_it, featlist) {
272  const CFeatListItem& item = **feat_it;
273  string desc = item.GetDescription();
274  int feat_type = item.GetType();
275  int feat_subtype = item.GetSubtype();
276  types[pair<int, int>(feat_type, feat_subtype)] = desc;
277  if (existing.find(desc) == existing.end()) {
278  existing.insert(desc);
279  features.push_back(desc);
280  }
281  }
282 
283  wxArrayString selected_features;
284  selected_features.push_back(_("Any"));
285  bool show_legal_only = false;
286  for (size_t i = 1; i < features.size(); ++i) {
288  bool legal = !show_legal_only || !CSeqFeatData::GetLegalQualifiers(subtype).empty();
290  selected_features.push_back(ToWxString(features[i]));
291  }
292  }
293 
294  return selected_features;
295 }
296 
297 
299 {
300  bool enable = m_LengthChoice->GetSelection() > 0;
301  event.Enable(enable);
302 }
303 
304 /*
305  * Should we show tooltips?
306  */
307 
309 {
310  return true;
311 }
312 
313 /*
314  * Get bitmap resources
315  */
316 
317 wxBitmap CMacroFeatsOnSeqPanel::GetBitmapResource( const wxString& name )
318 {
319  // Bitmap retrieval
320 ////@begin CMacroFeatsOnSeqPanel bitmap retrieval
321  wxUnusedVar(name);
322  return wxNullBitmap;
323 ////@end CMacroFeatsOnSeqPanel bitmap retrieval
324 }
325 
326 /*
327  * Get icon resources
328  */
329 
330 wxIcon CMacroFeatsOnSeqPanel::GetIconResource( const wxString& name )
331 {
332  // Icon retrieval
333 ////@begin CMacroFeatsOnSeqPanel icon retrieval
334  wxUnusedVar(name);
335  return wxNullIcon;
336 ////@end CMacroFeatsOnSeqPanel icon retrieval
337 }
338 
339 pair<string,string> CMacroFeatsOnSeqPanel::GetMatcher(const pair<string, string> &target, size_t num)
340 {
341  string feat = m_FeatureType->GetFieldName();
342  if (NStr::EqualNocase(feat, "any")) {
343  feat = "any";
344  }
345  if (NStr::EqualNocase(feat, "all")) {
346  feat = "all";
347  }
348  return make_pair(GetDescription(feat), GetLocationConstraint(feat, target.first));
349 }
350 
351 vector<CFuncWithArgs> CMacroFeatsOnSeqPanel::GetFuncWithArgs(const pair<string, string>& target, size_t num) const
352 {
353  vector<CFuncWithArgs> functions;
354  string feat = m_FeatureType->GetFieldName();
355  {
356  CFuncWithArgs fn;
357  if (m_FeatChoice->GetSelection() >= 0 && !m_FeatCount->GetValue().IsEmpty() && !feat.empty()) {
358  fn.m_FName = macro::CMacroFunction_NumberOfFeatures::GetFuncName();
359  fn.m_FArgs.emplace(NMacroArgs::kConstr_FeatType, feat);
360  fn.m_FArgs.emplace(NMacroArgs::kConstr_FeatCount, m_FeatCount->GetValue().ToStdString());
361  switch (m_FeatChoice->GetSelection()) {
362  case 0: fn.m_ParentFnc = "="; break;
363  case 1: fn.m_ParentFnc = "<"; break;
364  case 2: fn.m_ParentFnc = "<="; break;
365  case 3: fn.m_ParentFnc = ">"; break;
366  case 4: fn.m_ParentFnc = ">="; break;
367  }
368  functions.push_back(fn);
369  }
370  }
371  {
372  CFuncWithArgs fn;
373  if (!m_Length->GetValue().IsEmpty()) {
374  if (CFieldNamePanel::IsFeature(target.first)) {
375  fn.m_FName = macro::CMacroFunction_GetSequence::sm_SeqForFeat;
376  }
377  else if (CFieldNamePanel::IsDescriptor(target.first)) {
378  fn.m_FName = macro::CMacroFunction_GetSequence::sm_SeqForDescr;
379  }
380  else {
382  }
383  fn.m_FArgs.emplace(NMacroArgs::kField, "inst.length");
384  fn.m_FArgs.emplace(NMacroArgs::kConstr_Match, m_Length->GetValue().ToStdString());
385  switch (m_LengthChoice->GetSelection()) {
386  case 1: fn.m_ParentFnc = "="; break;
387  case 2: fn.m_ParentFnc = "<"; break;
388  case 3: fn.m_ParentFnc = "<="; break;
389  case 4: fn.m_ParentFnc = ">"; break;
390  case 5: fn.m_ParentFnc = ">="; break;
391  }
392  functions.push_back(fn);
393  }
394  }
395  {
396  CFuncWithArgs fn;
397  int repr_index = m_SeqReprChoice->GetSelection();
398  if (repr_index > 0) {
399  if (CFieldNamePanel::IsFeature(target.first)) {
400  fn.m_FName = macro::CMacroFunction_GetSequence::sm_SeqForFeat;
401  }
402  else if (CFieldNamePanel::IsDescriptor(target.first)) {
403  fn.m_FName = macro::CMacroFunction_GetSequence::sm_SeqForDescr;
404  }
405  else {
407  }
409  string selected = m_SeqReprChoice->GetString(repr_index).ToStdString();
410 
411  string value = CMacroEditorContext::GetInstance().GetAsnMolinfoValue(repr, selected);
412  fn.m_FArgs.emplace(NMacroArgs::kField, "inst.repr");
414  functions.push_back(fn);
415  }
416  }
417  {
418  CFuncWithArgs fn;
419  if (m_Dist5EndChoice->GetSelection() > 0 && !m_5EndDistance->IsEmpty()) {
420  fn.m_FName = macro::CMacroFunction_LocationDistConstraint::sm_FromStart;
421 
422  string feature = m_FirstFeatureChoice->GetStringSelection().ToStdString();
423  if (NStr::EqualNocase(feature, "any"))
424  feature = "any";
425  fn.m_FArgs.emplace(NMacroArgs::kFeatType, feature);
426  fn.m_FArgs.emplace(NMacroArgs::kConstr_Distance, m_5EndDistance->GetValue().ToStdString());
427  switch (m_Dist5EndChoice->GetSelection()) {
428  case 1: fn.m_ParentFnc = "="; break;
429  case 2: fn.m_ParentFnc = ">="; break;
430  case 3: fn.m_ParentFnc = "<="; break;
431  }
432  functions.push_back(fn);
433  }
434  }
435  {
436  CFuncWithArgs fn;
437  if (m_Dist3EndChoice->GetSelection() > 0 && !m_3EndDistance->IsEmpty()) {
438  fn.m_FName = macro::CMacroFunction_LocationDistConstraint::sm_FromStop;
439 
440  string feature = m_LastFeatureChoice->GetStringSelection().ToStdString();
441  if (NStr::EqualNocase(feature, "any"))
442  feature = "any";
443  fn.m_FArgs.emplace(NMacroArgs::kFeatType, feature);
444  fn.m_FArgs.emplace(NMacroArgs::kConstr_Distance, m_3EndDistance->GetValue().ToStdString());
445  switch (m_Dist3EndChoice->GetSelection()) {
446  case 1: fn.m_ParentFnc = "="; break;
447  case 2: fn.m_ParentFnc = ">="; break;
448  case 3: fn.m_ParentFnc = "<="; break;
449  }
450  functions.push_back(fn);
451  }
452  }
453  return functions;
454 }
455 
456 void CMacroFeatsOnSeqPanel::SetMatcher(const vector<CFuncWithArgs>& func_info)
457 {
458  for (const auto& fn_it : func_info) {
459  const auto& args = fn_it.m_FArgs;
460  if (NStr::EqualNocase(fn_it.m_FName, macro::CMacroFunction_NumberOfFeatures::GetFuncName())) {
461  auto feat_type = args.find(NMacroArgs::kConstr_FeatType);
462  auto feat_count = args.find(NMacroArgs::kConstr_FeatCount);
463  if (feat_type != args.end() && feat_count != args.end()) {
464  m_FeatureType->SetFieldName(feat_type->second);
465  m_FeatCount->ChangeValue(ToWxString(feat_count->second));
466  int sel = 0;
467  if (fn_it.m_ParentFnc == "=")
468  sel = 0;
469  else if (fn_it.m_ParentFnc == "<")
470  sel = 1;
471  else if (fn_it.m_ParentFnc == "<=")
472  sel = 2;
473  else if (fn_it.m_ParentFnc == ">")
474  sel = 3;
475  else if (fn_it.m_ParentFnc == ">=")
476  sel = 4;
477  m_FeatChoice->SetSelection(sel);
478  }
479  }
480  else if (NStr::EqualNocase(fn_it.m_FName, macro::CMacroFunction_GetSequence::sm_SeqForFeat) ||
481  NStr::EqualNocase(fn_it.m_FName, macro::CMacroFunction_GetSequence::sm_SeqForDescr) ||
483  auto field = args.find(NMacroArgs::kField);
484  auto count = args.find(NMacroArgs::kConstr_Match);
485  if (field != args.end() && count != args.end()) {
486  if (field->second == "inst.length") {
487  m_Length->ChangeValue(count->second);
488  int sel = 0;
489  if (fn_it.m_ParentFnc == "=")
490  sel = 1;
491  else if (fn_it.m_ParentFnc == "<")
492  sel = 2;
493  else if (fn_it.m_ParentFnc == "<=")
494  sel = 3;
495  else if (fn_it.m_ParentFnc == ">")
496  sel = 4;
497  else if (fn_it.m_ParentFnc == ">=")
498  sel = 5;
499  m_LengthChoice->SetSelection(sel);
500  }
501  else if (field->second == "inst.repr") {
502  string value = CMacroEditorContext::GetInstance().GetGUIMolinfoValue(count->second, "representation");
503  m_SeqReprChoice->SetStringSelection(value);
504  }
505  }
506  }
507  else if (NStr::EqualNocase(fn_it.m_FName, macro::CMacroFunction_LocationDistConstraint::sm_FromStart)) {
508  auto feat_it = args.find(NMacroArgs::kFeatType);
509  auto dist_it = args.find(NMacroArgs::kConstr_Distance);
510  if (feat_it != args.end() && dist_it != args.end()) {
511  m_FirstFeatureChoice->SetStringSelection(feat_it->second);
512  m_5EndDistance->Enable();
513  m_5EndDistance->ChangeValue(ToWxString(dist_it->second));
514  }
515  int sel = 0;
516  if (fn_it.m_ParentFnc == "=")
517  sel = 1;
518  else if (fn_it.m_ParentFnc == ">=")
519  sel = 2;
520  else if (fn_it.m_ParentFnc == "<=")
521  sel = 3;
522  m_Dist5EndChoice->SetSelection(sel);
523  }
524  else if (NStr::EqualNocase(fn_it.m_FName, macro::CMacroFunction_LocationDistConstraint::sm_FromStop)) {
525  auto feat_it = args.find(NMacroArgs::kFeatType);
526  auto dist_it = args.find(NMacroArgs::kConstr_Distance);
527  if (feat_it != args.end() && dist_it != args.end()) {
528  m_LastFeatureChoice->SetStringSelection(feat_it->second);
529  m_3EndDistance->Enable();
530  m_3EndDistance->ChangeValue(ToWxString(dist_it->second));
531  }
532  int sel = 0;
533  if (fn_it.m_ParentFnc == "=")
534  sel = 1;
535  else if (fn_it.m_ParentFnc == ">=")
536  sel = 2;
537  else if (fn_it.m_ParentFnc == "<=")
538  sel = 3;
539  m_Dist3EndChoice->SetSelection(sel);
540  }
541  }
542 }
543 
544 string CMacroFeatsOnSeqPanel::GetLocationConstraint(const string &feat, const string& target)
545 {
546  vector<string> constraints;
547 
548  if (!m_Length->GetValue().IsEmpty()) {
549  string length_asn = "inst.length";
550  string str = length_asn;
551  if (CFieldNamePanel::IsFeature(target)) {
552  str = macro::CMacroFunction_GetSequence::sm_SeqForFeat + string("(\"" + length_asn + "\")");
553  }
554  else if (CFieldNamePanel::IsDescriptor(target)) {
555  str = macro::CMacroFunction_GetSequence::sm_SeqForDescr + string("(\"" + length_asn + "\")");
556  }
557 
558  string d = m_Length->GetValue().ToStdString();
559  switch (m_LengthChoice->GetSelection()) {
560  case 1: str += " = " + d; break;
561  case 2: str += " < " + d; break;
562  case 3: str += " <= " + d; break;
563  case 4: str += " > " + d; break;
564  case 5: str += " >= " + d; break;
565  default: str.clear(); break;
566  }
567  if (!str.empty())
568  constraints.push_back(str);
569  }
570 
571  int repr_index = m_SeqReprChoice->GetSelection();
572  if (repr_index > 0) {
573  string repr_asn = "inst.repr";
574  string str = repr_asn;
575  if (CFieldNamePanel::IsFeature(target)) {
576  str = macro::CMacroFunction_GetSequence::sm_SeqForFeat + string("(\"" + repr_asn +"\")");
577  }
578  else if (CFieldNamePanel::IsDescriptor(target)) {
579  str = macro::CMacroFunction_GetSequence::sm_SeqForDescr + string("(\"" + repr_asn + "\")");
580  }
581 
583  string value = m_SeqReprChoice->GetString(repr_index).ToStdString();
584 
585  str += " = \"" + CMacroEditorContext::GetInstance().GetAsnMolinfoValue(repr, value) + "\"";
586  constraints.push_back(str);
587  }
588 
589  if (m_FeatChoice->GetSelection() >= 0 && !m_FeatCount->GetValue().IsEmpty() && !feat.empty())
590  {
591  string d = m_FeatCount->GetValue().ToStdString();
592  string str = macro::CMacroFunction_NumberOfFeatures::GetFuncName();
593  str += "(\"" + feat + "\")";
594  switch (m_FeatChoice->GetSelection())
595  {
596  case 0: str += " = " + d; break;
597  case 1: str += " < " + d; break;
598  case 2: str += " <= " + d; break;
599  case 3: str += " > " + d; break;
600  case 4: str += " >= " + d; break;
601  default: str.clear(); break;
602  }
603  if (!str.empty())
604  constraints.push_back(str);
605  }
606 
607  if (m_Dist5EndChoice->GetSelection() > 0 && !m_5EndDistance->IsEmpty()) {
608  string str = macro::CMacroFunction_LocationDistConstraint::sm_FromStart;
609  str += "(" + string(macro::CMacroFunction_FirstOrLastItem::sm_First) + "(";
610  str += macro::CMacroFunction_Features_For_Object::GetFuncName();
611 
612  string feature = m_FirstFeatureChoice->GetStringSelection().ToStdString();
613  if (NStr::EqualNocase(feature, "any"))
614  feature = "any";
615  str += "(\"" + feature + "\")))";
616 
617  string d = m_5EndDistance->GetValue().ToStdString();
618  switch (m_Dist5EndChoice->GetSelection()) {
619  case 1: str += " = " + d; break;
620  case 2: str += " >= " + d; break;
621  case 3: str += " <= " + d; break;
622  default: str.clear(); break;
623  }
624 
625  if (!str.empty())
626  constraints.push_back(str);
627  }
628 
629  if (m_Dist3EndChoice->GetSelection() > 0 && !m_3EndDistance->IsEmpty()) {
630  string str = macro::CMacroFunction_LocationDistConstraint::sm_FromStop;
631  str += "(" + string(macro::CMacroFunction_FirstOrLastItem::sm_Last) + "(";
632  str += macro::CMacroFunction_Features_For_Object::GetFuncName();
633 
634  string feature = m_LastFeatureChoice->GetStringSelection().ToStdString();
635  if (NStr::EqualNocase(feature, "any"))
636  feature = "any";
637  str += "(\"" + feature + "\")))";
638 
639  string d = m_3EndDistance->GetValue().ToStdString();
640  switch (m_Dist3EndChoice->GetSelection()) {
641  case 1: str += " = " + d; break;
642  case 2: str += " >= " + d; break;
643  case 3: str += " <= " + d; break;
644  default: str.clear(); break;
645  }
646 
647  if (!str.empty())
648  constraints.push_back(str);
649  }
650 
651  if (!constraints.empty()) {
652  return NStr::Join(constraints, " AND ");
653  }
654  return kEmptyStr;
655 }
656 
657 string CMacroFeatsOnSeqPanel::GetDescription(const string& feat) const
658 {
659  vector<string> descriptions;
660 
661  int repr_index = m_SeqReprChoice->GetSelection();
662  if (repr_index > 0) {
663  string value = m_SeqReprChoice->GetString(repr_index).ToStdString();
664  if (value.empty())
665  value = "not-set";
666  string label = "sequence is " + value;
667  descriptions.push_back(label);
668  }
669 
670  if (!m_Length->GetValue().IsEmpty()) {
671  string label = "sequence length is ";
672 
673  switch (m_LengthChoice->GetSelection()) {
674  case 1: label += "exactly "; break;
675  case 2: label += "fewer than "; break;
676  case 3: label += "fewer than or equal to "; break;
677  case 4: label += "more than "; break;
678  case 5: label += "more than or equal to "; break;
679  default: break;
680  }
681  label += m_Length->GetValue().ToStdString();
682  descriptions.push_back(label);
683  }
684 
685  if (m_FeatChoice->GetSelection() >= 0 && !m_FeatCount->GetValue().IsEmpty() && !feat.empty()) {
686  string label = "the number of "+ feat + " features on sequence is ";
687  switch (m_FeatChoice->GetSelection())
688  {
689  case 0: label += "exactly "; break;
690  case 1: label += "fewer than "; break;
691  case 2: label += "fewer than or equal to "; break;
692  case 3: label += "more than "; break;
693  case 4: label += "more than or equal to "; break;
694  default: break;
695  }
696  label += m_FeatCount->GetValue().ToStdString();
697  descriptions.push_back(label);
698  }
699 
700  if (m_Dist5EndChoice->GetSelection() > 0 && !m_5EndDistance->IsEmpty()) {
701  string label = "there are ";
702 
703  switch (m_Dist5EndChoice->GetSelection()) {
704  case 1: label += "exactly "; break;
705  case 2: label += "at least "; break;
706  case 3: label += "at most "; break;
707  default: label.clear(); break;
708  }
709 
710  label += m_5EndDistance->GetValue().ToStdString();
711  label += " nucleotides before the first ";
712 
713  string feature = m_FirstFeatureChoice->GetStringSelection().ToStdString();
714  if (!NStr::EqualNocase(feature, "any"))
715  label += feature + " ";
716 
717  label += "feature";
718  descriptions.push_back(label);
719  }
720 
721  if (m_Dist3EndChoice->GetSelection() > 0 && !m_3EndDistance->IsEmpty()) {
722  string label = "there are ";
723 
724  switch (m_Dist3EndChoice->GetSelection()) {
725  case 1: label += "exactly "; break;
726  case 2: label += "at least "; break;
727  case 3: label += "at most "; break;
728  default: label.clear(); break;
729  }
730 
731  label += m_3EndDistance->GetValue().ToStdString();
732  label += " nucleotides after the last ";
733 
734  string feature = m_LastFeatureChoice->GetStringSelection().ToStdString();
735  if (!NStr::EqualNocase(feature, "any"))
736  label += feature + " ";
737 
738  label += "feature";
739  descriptions.push_back(label);
740  }
741 
742  if (!descriptions.empty()) {
743  return NStr::Join(descriptions, " and ");
744  }
745  return kEmptyStr;
746 }
747 
748 void CMacroFeatsOnSeqPanel::OnDistanceSelected(wxCommandEvent& event)
749 {
750  if (event.GetId() == ID_MACRO_FEATS_DISTCHOICE1) {
751  if (m_Dist5EndChoice->GetSelection() > 0) {
752  m_5EndDistance->Enable();
753  }
754  else {
755  m_5EndDistance->SetValue(wxEmptyString);
756  m_5EndDistance->Disable();
757  }
758  }
759  else if (event.GetId() == ID_MACRO_FEATS_DISTCHOICE2) {
760  if (m_Dist3EndChoice->GetSelection() > 0) {
761  m_3EndDistance->Enable();
762  }
763  else {
764  m_3EndDistance->SetValue(wxEmptyString);
765  m_3EndDistance->Disable();
766  }
767  }
768 }
769 
770 
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
CFeatListItem - basic configuration data for one "feature" type.
int GetSubtype() const
string GetDescription() const
int GetType() const
virtual bool SetFieldName(const string &field)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
static bool s_IsRarelyUsedOrDiscouragedFeatureType(int subtype)
void ListPresentFeaturesFirst(const objects::CSeq_entry_Handle &entry, vector< const objects::CFeatListItem * > *featlist=nullptr)
static bool IsDescriptor(const string &target)
static bool IsFeature(const string &target)
Class to store one function as it appears in the macro and its arguments (as GUI fieldnames)
TInterpretedArgs m_FArgs
string m_FName
Function name as it appears in the macro.
string GetGUIMolinfoValue(const string &macro_field, const string &molinfo_field)
static CMacroEditorContext & GetInstance()
string GetAsnMolinfoValue(const string &molinfo_field, const string &choice)
void OnDistanceSelected(wxCommandEvent &event)
string GetLocationConstraint(const string &feat, const string &target)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnLengthTextCtrlUpdate(wxUpdateUIEvent &event)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
string GetDescription(const string &feat) const
virtual void SetMatcher(const vector< CFuncWithArgs > &func_info)
virtual vector< CFuncWithArgs > GetFuncWithArgs(const pair< string, string > &target, size_t num) const
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
static bool ShowToolTips()
Should we show tooltips?
void CreateControls()
Creates the controls and sizers.
virtual pair< string, string > GetMatcher(const pair< string, string > &target, size_t num)
void Init()
Initialises member variables.
static string GetFieldName(EMolInfoFieldType field_type)
static vector< string > GetChoicesForField(CMolInfoFieldType::EMolInfoFieldType field_type, bool &allow_other)
const TLegalQualifiers & GetLegalQualifiers(void) const
Get a list of all the legal qualifiers for the feature.
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
static bool IsRegulatory(ESubtype subtype)
CSeq_entry_Handle –.
Definition: map.hpp:338
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
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
static const struct type types[]
Definition: type.c:22
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
vector< const objects::CFeatListItem * > GetSortedFeatList(objects::CSeq_entry_Handle seh, size_t max=numeric_limits< size_t >::max())
#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 string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2699
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5347
static const char label[]
END_EVENT_TABLE()
int i
USING_SCOPE(objects)
#define ID_MACRO_FEATS_DISTCHOICE2
#define ID_MACRO_FEATS_LENGTHTEXT
#define ID_MACRO_FEATS_DISTCHOICE1
const string kComparisonOp
const string kConstr_FeatCount
const string kField
const string kConstr_FeatType
const string kFeatType
const string kConstr_Match
const string kConstr_Distance
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define count
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
void ToArrayString(const vector< string > &out, wxArrayString &in)
Definition: wx_utils.cpp:353
Modified on Fri Sep 20 14:57:58 2024 by modify_doxy.py rev. 669887