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

Go to the SVN repository for this file.

1 /* $Id: feature_field_name_panel.cpp 46819 2021-10-25 17:53:43Z 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: Colleen Bollin
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 10/06/2013 17:47:10
31 
32 #include <ncbi_pch.hpp>
34 #include <serial/enumvalues.hpp>
40 
42 #include <wx/sizer.h>
43 
44 ////@begin XPM images
45 
48 
49 /*!
50  * CFeatureFieldNamePanel type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( CFeatureFieldNamePanel, CFieldNamePanel )
54 
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_UPDATE_FEATLIST)
56 
57 /*!
58  * CFeatureFieldNamePanel event table definition
59  */
60 
61 BEGIN_EVENT_TABLE( CFeatureFieldNamePanel, CFieldNamePanel )
62 
63 ////@begin CFeatureFieldNamePanel event table entries
64  EVT_LISTBOX( ID_FEATQUALIFIER_LISTBOX, CFeatureFieldNamePanel::OnQualifierListboxSelected)
65 
66 ////@end CFeatureFieldNamePanel event table entries
67 
69 
70 
71 /*!
72  * CFeatureFieldNamePanel constructors
73  */
74 
76 : m_code_table(CGen_code_table::GetCodeTable())
77 {
78  Init();
79 }
80 
81 CFeatureFieldNamePanel::CFeatureFieldNamePanel( wxWindow* parent, CFeatureFieldNamePanel* sibling, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
82  : m_Sibling(sibling), m_code_table(CGen_code_table::GetCodeTable())
83 
84 {
85  Init();
86  Create(parent, id, pos, size, style);
87 }
88 
89 
90 /*!
91  * CFeatureFieldNamePanel creator
92  */
93 
94 bool CFeatureFieldNamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
95 {
96 ////@begin CFeatureFieldNamePanel creation
97  CFieldNamePanel::Create( parent, id, pos, size, style );
98 
100  if (GetSizer())
101  {
102  GetSizer()->SetSizeHints(this);
103  }
104  Centre();
105 ////@end CFeatureFieldNamePanel creation
106  return true;
107 }
108 
109 
110 /*!
111  * CFeatureFieldNamePanel destructor
112  */
113 
115 {
116 ////@begin CFeatureFieldNamePanel destruction
117 ////@end CFeatureFieldNamePanel destruction
118 }
119 
120 
121 /*!
122  * Member initialisation
123  */
124 
126 {
127 ////@begin CFeatureFieldNamePanel member initialisation
131  m_show_legal_only = false;
132 ////@end CFeatureFieldNamePanel member initialisation
133 }
134 
135 
136 /*!
137  * Control creation for CFeatureFieldNamePanel
138  */
139 
141 {
142 ////@begin CFeatureFieldNamePanel content construction
143  CFeatureFieldNamePanel* itemCFieldNamePanel1 = this;
144 
145  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
146  itemCFieldNamePanel1->SetSizer(itemBoxSizer2);
147 
148  wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
149  itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
150 
151  m_FeatureTypeLabel = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("Feature Type"), wxDefaultPosition, wxDefaultSize, 0 );
152  itemFlexGridSizer3->Add(m_FeatureTypeLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 3);
153 
154  wxStaticText* itemStaticText5 = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("Qualifier"), wxDefaultPosition, wxDefaultSize, 0 );
155  itemFlexGridSizer3->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxBOTTOM, 3);
156 
157  m_FeatureType = new CFeatureTypePanel( itemCFieldNamePanel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
158  itemFlexGridSizer3->Add(m_FeatureType, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
159 
160  wxArrayString m_QualifierNameStrings;
161  m_QualifierName = new wxListBox(itemCFieldNamePanel1, ID_FEATQUALIFIER_LISTBOX, wxDefaultPosition, wxSize(200, 109), m_QualifierNameStrings, wxLB_SINGLE);
162  itemFlexGridSizer3->Add(m_QualifierName, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
163 
164 ////@end CFeatureFieldNamePanel content construction
165  if (m_Sibling) {
166  m_FeatureTypeLabel->Show(false);
167  m_FeatureType->Show(false);
168  }
169 
171 }
172 
173 void CFeatureFieldNamePanel::ListPresentFeaturesFirst(objects::CSeq_entry_Handle seh, vector<const objects::CFeatListItem *> *featlist)
174 {
175  if (!m_FeatureType)
176  return;
177  m_FeatureType->ListPresentFeaturesFirst(seh, featlist);
178 }
179 
181 {
183  m_QualifierName->SetSelection(wxNOT_FOUND);
184  m_QualifierName->SetFirstItem(0);
185 }
186 
188 {
189  vector<string> names;
190  for (auto qual : CSeqFeatData::GetLegalQualifiers(subtype))
191  {
193  names.push_back(CSeqFeatData::GetQualifierAsString(qual));
194  }
195 
196  wxArrayString list;
197  bool product_present = false;
198  bool note_present = false;
199  for (auto &name : names)
200  {
201  NStr::ReplaceInPlace(name, "_","-");
202  if (NStr::EqualNocase(name, "gene"))
203  {
204  name = "locus";
205  }
206  if (NStr::EqualNocase(name, "product"))
207  {
208  product_present = true;
209  continue;
210  }
211  if (NStr::EqualNocase(name, "note"))
212  {
213  note_present = true;
214  continue;
215  }
216  if (NStr::EqualNocase(name, "satellite-type") || (NStr::EqualNocase(name, "satellite-name"))
217  || (NStr::EqualNocase(name, "mobile-element-type-type")) || (NStr::EqualNocase(name, "mobile-element-type-name")) )
218  {
219  continue;
220  }
221  if (NStr::EqualNocase(name, "trans-splicing"))
222  {
223  continue;
224  }
225  list.Add(wxString(name));
226  if (NStr::EqualNocase(name, "satellite"))
227  {
228  list.Add(wxString("satellite-type"));
229  list.Add(wxString("satellite-name"));
230  }
231  if (NStr::EqualNocase(name, "mobile-element-type"))
232  {
233  list.Add(wxString("mobile-element-type-type"));
234  list.Add(wxString("mobile-element-type-name"));
235  }
236  }
237  list.Sort();
238  if (note_present)
239  list.Insert(_T("note"), 0);
240  if (product_present)
241  list.Insert(_T("product"), 0);
242  return list;
243 }
244 
245 string CFeatureFieldNamePanel::GetMacroFieldName(const string &target, const string& selected_field)
246 {
247  return s_GetMacroFieldName(GetFeatureType(), GetQualifierName(), target, selected_field);
248 }
249 
250 string CFeatureFieldNamePanel::s_GetMacroFieldName(const string& feat, const string& qualifier,
251  const string& target, const string& selected_field)
252 {
253  string str;
254  string feature = feat;
255  string field = qualifier;
256 
257  if (NStr::EqualNocase(feature, "CDS")) {
258  feature = "cdregion";
259  }
260  if (NStr::EqualNocase(feature, "preRNA")) {
261  feature = "precursor_RNA";
262  }
263 
264  if (NStr::EqualNocase(feature, "misc_RNA")) {
265  feature = "miscRNA";
266  }
267 
268  if (field == "gene" || field == "locus")
269  {
270  if (NStr::EqualNocase(feature, "gene"))
271  str = "\"data.gene.locus\"";
272  else
273  str = "\"qual\", \"locus\"";
274  }
275 
276  if (field == "product" || field == "name")
277  {
278  if (NStr::EqualNocase(feature, "mRNA") ||
279  NStr::EqualNocase(feature, "rRNA") ||
280  NStr::EqualNocase(feature, "preRNA") ||
281  NStr::EqualNocase(feature, "precursor_RNA"))
282  str = "\"data.rna.ext.name\"";
283  else if (NStr::EqualNocase(feature, "miscRNA") ||
284  NStr::EqualNocase(feature, "ncRNA") ||
285  NStr::EqualNocase(feature, "tmRNA"))
286  str = "\"data.rna.ext.gen.product\"";
287  else if (NStr::EqualNocase(feature, "protein"))
288  str = "\"data.prot.name\"";
289  else if (NStr::EqualNocase(feature, "cdregion"))
290  {
291  feature = "protein";
292  str = "\"data.prot.name\"";
293  }
294  }
295 
296  if (field == "note")
297  {
298  str = "\"comment\"";
299  }
300 
301  if (field == "db_xref")
302  //str = "\"dbxref.db\"";
303  str = macro::CMacroFunction_GetDBXref::GetFuncName() + "()";
304 
305  if (field == "desc" || field == "description")
306  {
307  if (NStr::EqualNocase(feature, "gene"))
308  str = "\"data.gene.desc\"";
309  else if (NStr::EqualNocase(feature, "protein"))
310  str = "\"data.prot.desc\"";
311  else
312  str = "\"qual\", \"description\"";
313  }
314 
315  if (NStr::EqualNocase(feature, "gene")) {
316  if (macro::NMacroUtil::StringsAreEquivalent(field, "locus-tag")) {
317  str = "\"data.gene.locus-tag\"";
318  }
319  else if (field == "synonym" || macro::NMacroUtil::StringsAreEquivalent(field, "gene_synonym")) {
320  str = "\"data.gene.syn\"";
321  }
322  else if (field == "allele") {
323  str = "\"data.gene.allele\"";
324  }
325  }
326 
327  if (field == "activity") {
328  if (NStr::EqualNocase(feature, "protein"))
329  str = "\"data.prot.activity\"";
330  else if (NStr::EqualNocase(feature, "cdregion"))
331  {
332  feature = "protein";
333  str = "\"data.prot.activity\"";
334  }
335  }
336 
337  if (macro::NMacroUtil::StringsAreEquivalent(field, "ec-number")) {
338  if (NStr::EqualNocase(feature, "protein"))
339  str = "\"data.prot.ec\"";
340  else if (NStr::EqualNocase(feature, "cdregion"))
341  {
342  feature = "protein";
343  str = "\"data.prot.ec\"";
344  }
345  }
346  if (macro::NMacroUtil::StringsAreEquivalent(field, "tag_peptide")) {
347  if (NStr::EqualNocase(feature, "tmRNA")) {
348  str = "\"data.rna.ext.gen.quals\", \"" + field + "\"";
349  }
350  }
351 
352  if (field == "translation")
353  {
354  if (NStr::EqualNocase(feature, "cdregion"))
355  str = "TRANSLATION()";
356  }
357 
358  if (field == "satellite_type") {
359  str = macro::CMacroFunction_SatelliteType::GetFuncName() + "()";
360  }
361  else if (field == "satellite_name") {
362  str = macro::CMacroFunction_SatelliteName::GetFuncName() + "()";
363  }
364  else if (field == "mobile_element_type_type") {
365  str = macro::CMacroFunction_MobileElementType::GetFuncName() + "()";
366  }
367  else if (field == "mobile_element_type_name") {
368  str = macro::CMacroFunction_MobileElementName::GetFuncName() + "()";
369  }
370 
371  if (str.empty())
372  str = "\"qual\", \"" + field + "\"";
373 
374  if (NStr::EqualNocase(target, feature)) {
375  return str;
376  }
377  else {
378  if (!selected_field.empty() && !NStr::EqualNocase(target, selected_field)) {
379  if (NStr::EqualNocase(selected_field, feature) ||
380  (selected_field == "preRNA" && feature == "precursor_RNA")) {
381  return str;
382  }
383  }
384  }
385 
386  if (NStr::EqualNocase(feature, "cdregion")) {
387  feature = "cds";
388  }
389 
390  if (CFieldNamePanel::IsFeature(target))
391  {
392  str = "RELATED_FEATURE(\"" + feature + "\", " + str + ")";
393  return str;
394  }
395  str = "FEATURES(\"" + feature + "\"," + str + ")";
396  return str;
397 }
398 
399 /*!
400  * Should we show tooltips?
401  */
402 
404 {
405  return true;
406 }
407 
408 /*!
409  * Get bitmap resources
410  */
411 
412 wxBitmap CFeatureFieldNamePanel::GetBitmapResource( const wxString& name )
413 {
414  // Bitmap retrieval
415 ////@begin CFeatureFieldNamePanel bitmap retrieval
416  wxUnusedVar(name);
417  return wxNullBitmap;
418 ////@end CFeatureFieldNamePanel bitmap retrieval
419 }
420 
421 /*!
422  * Get icon resources
423  */
424 
425 wxIcon CFeatureFieldNamePanel::GetIconResource( const wxString& name )
426 {
427  // Icon retrieval
428 ////@begin CFeatureFieldNamePanel icon retrieval
429  wxUnusedVar(name);
430  return wxNullIcon;
431 ////@end CFeatureFieldNamePanel icon retrieval
432 }
433 
434 
435 /*!
436  * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_QUALIFIER_LISTBOX
437  */
438 
440 {
441  x_UpdateParent();
442  event.Skip();
443 }
444 
445 
447 {
448  string feat = "";
449 
450  if (m_Sibling) {
451  feat = m_Sibling->GetFeatureType();
452  } else {
453  feat = m_FeatureType->GetFieldName();
454  }
455  return feat;
456 }
457 
458 
459 bool CFeatureFieldNamePanel::SetFeatureType(const string& feature_type)
460 {
461  bool rval = false;
462  if (m_Sibling) {
463  rval = m_Sibling->SetFeatureType(feature_type);
464  } else {
465  rval = m_FeatureType->SetFieldName(feature_type);
466  }
467  return rval;
468 }
469 
470 
472 {
473  string qual_name = "";
474  int qual_val = m_QualifierName->GetSelection();
475  if (qual_val > -1) {
476  qual_name = ToStdString(m_QualifierName->GetString(qual_val));
477  NStr::ReplaceInPlace(qual_name,"-","_");
478  }
479  return qual_name;
480 }
481 
482 
483 string CFeatureFieldNamePanel::GetFieldName(const bool subfield)
484 {
485  string field = "";
486  string feat = GetFeatureType();
487  string qual = GetQualifierName();
488 
489  if (!NStr::IsBlank(feat) && !NStr::IsBlank(qual)) {
490  field = feat + " " + qual;
491  }
492  if (subfield && !NStr::IsBlank(qual)) {
493  field = qual;
494  }
495 
496  return field;
497 }
498 
499 
500 bool CFeatureFieldNamePanel::SetFieldName(const string& field)
501 {
502  bool rval = false;
503 
504  // First field may have embeddeed blanks. second does not,
505  // so we locate last space
506  size_t pos = NStr::Find(field, " ", NStr::eCase, NStr::eReverseSearch);
507  if (pos != string::npos) {
508  string feat = field.substr(0, pos);
509  string qual = field.substr(pos + 1);
510  rval = SetFeatureType(feat);
511  if (rval) {
512  NStr::ReplaceInPlace(qual, "_", "-");
513  rval = m_QualifierName->SetStringSelection(ToWxString(qual));
514  if (rval)
515  m_QualifierName->SetFirstItem(ToWxString(qual));
516  }
517  }
518  else
519  {
520  SetFeatureType(field);
521  }
522 
523  return rval;
524 }
525 
527 {
528  m_show_legal_only = show;
530 }
531 
533 {
534  if (!m_show_legal_only)
535  return;
536  string field_name = GetFeatureType();
537  if (field_name.empty())
538  return;
540  m_QualifierName->Set(s_FillFeatQualList(subtype));
541 }
542 
544 {
545  wxCommandEvent listbxEvent(wxEVT_COMMAND_UPDATE_FEATLIST, GetId());
546  listbxEvent.SetEventObject(this);
547  GetEventHandler()->ProcessEvent(listbxEvent);
548 }
549 
550 vector<string> CFeatureFieldNamePanel::GetChoices(bool& allow_other)
551 {
552  vector<string> choices;
553 
554  string field_name = GetFieldName(true);
555 
556  if (field_name == "codon_start")
557  {
558  choices.push_back("1");
559  choices.push_back("2");
560  choices.push_back("3");
561  allow_other = false;
562  }
563  if (field_name == "pseudo")
564  {
565  choices.push_back("Processed");
566  choices.push_back("Unprocessed");
567  choices.push_back("Unitary");
568  choices.push_back("Allelic");
569  choices.push_back("Unknown");
570  choices.push_back("Unqualified");
571  allow_other = false;
572  }
573  if (field_name == "transl_table")
574  {
575  const CGenetic_code_table::Tdata& codes = m_code_table.Get();
576  choices.reserve(codes.size());
577  ITERATE (CGenetic_code_table::Tdata, it, codes)
578  {
579  string str = (*it)->GetName();
580  choices.push_back(str);
581  }
582  allow_other = false;
583  }
584  return choices;
585 }
586 
static wxArrayString s_FillFeatQualList(objects::CSeqFeatData::ESubtype subtype)
virtual bool SetFieldName(const string &field)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
const objects::CGenetic_code_table & m_code_table
void CreateControls()
Creates the controls and sizers.
static string s_GetMacroFieldName(const string &feature, const string &qualifier, const string &target, const string &selected_field=kEmptyStr)
CFeatureFieldNamePanel * m_Sibling
virtual void SetShowLegalOnly(bool show)
static bool ShowToolTips()
Should we show tooltips?
virtual string GetMacroFieldName(const string &target, const string &selected_field=kEmptyStr)
virtual vector< string > GetChoices(bool &allow_other)
bool SetFeatureType(const string &feature_type)
void OnQualifierListboxSelected(wxCommandEvent &event)
wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_QUALIFIER_LISTBOX
void Init()
Initialises member variables.
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
bool Create(wxWindow *parent, wxWindowID id=ID_CFEATUREFIELDNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
Creation.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void ListPresentFeaturesFirst(objects::CSeq_entry_Handle seh, vector< const objects::CFeatListItem * > *featlist=nullptr)
virtual bool SetFieldName(const string &field)
virtual void ClearValues(void)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
virtual void SetShowLegalOnly(bool show)
void ListPresentFeaturesFirst(const objects::CSeq_entry_Handle &entry, vector< const objects::CFeatListItem * > *featlist=nullptr)
void x_UpdateParent(void)
static bool IsFeature(const string &target)
static bool IsDiscouragedQual(EQualifier qual)
const TLegalQualifiers & GetLegalQualifiers(void) const
Get a list of all the legal qualifiers for the feature.
static CTempString GetQualifierAsString(EQualifier qual)
Convert a qualifier from an enumerated value to a string representation or empty if not found.
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
#define _(proto)
Definition: ct_nlmzip_i.h:78
USING_SCOPE(objects)
static const struct name_t names[]
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
bool StringsAreEquivalent(const string &name1, const string &name2)
Definition: macro_util.cpp:397
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,...
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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:2891
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:5353
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
@ eReverseSearch
Search in a backward direction.
Definition: ncbistr.hpp:1947
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
list< CRef< CGenetic_code > > Tdata
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Apr 17 13:09:48 2024 by modify_doxy.py rev. 669887