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

Go to the SVN repository for this file.

1 /* $Id: cds_gene_prot_field_name_panel.cpp 47479 2023-05-02 13:24:02Z ucko $
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>
34 
35 #include <wx/sizer.h>
36 
37 ////@begin XPM images
38 ////@end XPM images
39 
41 
42 /*!
43  * CCDSGeneProtFieldNamePanel type definition
44  */
45 
46 IMPLEMENT_DYNAMIC_CLASS( CCDSGeneProtFieldNamePanel, CFieldNamePanel )
47 
48 
49 /*!
50  * CCDSGeneProtFieldNamePanel event table definition
51  */
52 
53 BEGIN_EVENT_TABLE( CCDSGeneProtFieldNamePanel, CFieldNamePanel )
54 
55 ////@begin CCDSGeneProtFieldNamePanel event table entries
56  EVT_LISTBOX( ID_CCDSGENEPROTFIELDNAME_FIELD, CCDSGeneProtFieldNamePanel::OnFieldSelected)
57 
58 ////@end CCDSGeneProtFieldNamePanel event table entries
59 
61 
62 
63 /*!
64  * CCDSGeneProtFieldNamePanel constructors
65  */
66 
68 {
69  Init();
70 }
71 
72 CCDSGeneProtFieldNamePanel::CCDSGeneProtFieldNamePanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
73 {
74  Init();
75  Create(parent, id, pos, size, style);
76 }
77 
78 
79 /*!
80  * CCDSGeneProtFieldNamePanel creator
81  */
82 
83 bool CCDSGeneProtFieldNamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
84 {
85 ////@begin CCDSGeneProtFieldNamePanel creation
86  CFieldNamePanel::Create( parent, id, pos, size, style );
87 
89  if (GetSizer())
90  {
91  GetSizer()->SetSizeHints(this);
92  }
93  Centre();
94 ////@end CCDSGeneProtFieldNamePanel creation
95  return true;
96 }
97 
98 
99 /*!
100  * CCDSGeneProtFieldNamePanel destructor
101  */
102 
104 {
105 ////@begin CCDSGeneProtFieldNamePanel destruction
106 ////@end CCDSGeneProtFieldNamePanel destruction
107 }
108 
109 
110 /*!
111  * Member initialisation
112  */
113 
115 {
116 ////@begin CCDSGeneProtFieldNamePanel member initialisation
117  m_Field = NULL;
118 ////@end CCDSGeneProtFieldNamePanel member initialisation
119 }
120 
121 
122 /*!
123  * Control creation for CCDSGeneProtFieldNamePanel
124  */
125 
127 {
128 ////@begin CCDSGeneProtFieldNamePanel content construction
129  CCDSGeneProtFieldNamePanel* itemCFieldNamePanel1 = this;
130 
131  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
132  itemCFieldNamePanel1->SetSizer(itemBoxSizer2);
133 
134  vector<string> options = GetStrings();
135  wxArrayString m_FieldStrings;
136  ITERATE(vector<string>, it, options) {
137  m_FieldStrings.Add(ToWxString(*it));
138  }
139  m_Field = new wxListBox(itemCFieldNamePanel1, ID_CCDSGENEPROTFIELDNAME_FIELD, wxDefaultPosition, wxSize(220, 109), m_FieldStrings, 0);
140  itemBoxSizer2->Add(m_Field, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
141 
142 ////@end CCDSGeneProtFieldNamePanel content construction
143 }
144 
146 {
147  m_Field->SetSelection(0);
148  m_Field->SetFirstItem(0);
149 }
150 
151 /*!
152  * Should we show tooltips?
153  */
154 
156 {
157  return true;
158 }
159 
160 /*!
161  * Get bitmap resources
162  */
163 
164 wxBitmap CCDSGeneProtFieldNamePanel::GetBitmapResource( const wxString& name )
165 {
166  // Bitmap retrieval
167 ////@begin CCDSGeneProtFieldNamePanel bitmap retrieval
168  wxUnusedVar(name);
169  return wxNullBitmap;
170 ////@end CCDSGeneProtFieldNamePanel bitmap retrieval
171 }
172 
173 /*!
174  * Get icon resources
175  */
176 
177 wxIcon CCDSGeneProtFieldNamePanel::GetIconResource( const wxString& name )
178 {
179  // Icon retrieval
180 ////@begin CCDSGeneProtFieldNamePanel icon retrieval
181  wxUnusedVar(name);
182  return wxNullIcon;
183 ////@end CCDSGeneProtFieldNamePanel icon retrieval
184 }
185 
186 
187 /*!
188  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_CCDSGENEPROTFIELDNAME_FIELD
189  */
190 
191 void CCDSGeneProtFieldNamePanel::OnFieldSelected( wxCommandEvent& event )
192 {
193  x_UpdateParent();
194  event.Skip();
195 }
196 
197 
198 string CCDSGeneProtFieldNamePanel::GetFieldName(const bool subfield)
199 {
200  string field = "";
201  int val = m_Field->GetSelection();
202  if (val < 0) {
203  return field;
204  }
205  field = m_Field->GetString(val);
206  return field;
207 }
208 
209 
211 {
212  bool rval = false;
213  for (size_t i = 0; i < m_Field->GetStrings().size(); i++) {
214  string cgp_field = ToStdString(m_Field->GetString(static_cast<unsigned int>(i)));
216  m_Field->SetSelection(static_cast<int>(i));
217  m_Field->SetFirstItem(static_cast<int>(i));
218  rval = true;
219  break;
220  }
221  }
222  return rval;
223 }
224 
226 {
227  vector<string> options;
228  options.push_back("protein name");
229  options.push_back("protein description");
230  options.push_back("CDS comment");
231  options.push_back("CDS inference");
232  options.push_back("codon-start");
233  options.push_back("gene locus");
234  options.push_back("gene description");
235  options.push_back("gene comment");
236  options.push_back("gene inference");
237  options.push_back("gene allele");
238  options.push_back("gene maploc");
239  options.push_back("gene locus tag");
240  options.push_back("gene synonym");
241  options.push_back("gene old_locus_tag");
242  options.push_back("mRNA product");
243  options.push_back("mRNA comment");
244  options.push_back("protein name");
245  options.push_back("protein description");
246  options.push_back("protein EC number");
247  options.push_back("protein activity");
248  options.push_back("protein comment");
249  options.push_back("mat_peptide name");
250  options.push_back("mat_peptide description");
251  options.push_back("mat_peptide EC number");
252  options.push_back("mat_peptide activity");
253  options.push_back("mat_peptide comment");
254  return options;
255 }
256 
257 vector<string> CCDSGeneProtFieldNamePanel::GetChoices(bool& allow_other)
258 {
259  vector<string> choices;
260 
261  string field_name = GetFieldName();
262 
263  if (field_name == "codon-start")
264  {
265  choices.push_back("1");
266  choices.push_back("2");
267  choices.push_back("3");
268  allow_other = false;
269  }
270 
271  return choices;
272 }
273 
274 string CCDSGeneProtFieldNamePanel::GetMacroFieldName(const string &target, const string& selected_field)
275 {
276  return s_GetMacroFieldName(GetFieldName(), target, selected_field);
277 }
278 
279 string CCDSGeneProtFieldNamePanel::s_GetMacroFieldName(const string& field_name, const string& target, const string& selected_field)
280 {
281  string feature, qualifier;
282  SIZE_TYPE pos = field_name.find(" ");
283  if (pos != NPOS) {
284  feature = field_name.substr(0, pos);
285  qualifier = field_name.substr(pos + 1);
286  }
287 
288 
289  if (NStr::EqualNocase(feature, "CDS")) {
290  feature = "cdregion";
291  }
292 
293  string str;
294  if (field_name == "codon-start") {
295  feature = "cdregion";
296  str = "\"data.cdregion.frame\"";
297  }
298 
299  if (qualifier == "name") {
300  str = "\"data.prot.name\"";
301  }
302  else if (qualifier == "description") {
303  if (NStr::EqualNocase(feature, "gene")) {
304  str = "\"data.gene.desc\"";
305  }
306  else if (NStr::EqualNocase(feature, "protein") || NStr::EqualNocase(feature, "mat-peptide")) {
307  str = "\"data.prot.desc\"";
308  }
309  }
310  else if (qualifier == "comment") {
311  str = "\"comment\"";
312  }
313  else if (qualifier == "locus") {
314  str = "\"data.gene.locus\"";
315  }
316  else if (qualifier == "allele") {
317  str = "\"data.gene.allele\"";
318  }
319  else if (qualifier == "maploc") {
320  str = "\"data.gene.maploc\"";
321  }
322  else if (qualifier == "locus tag") {
323  str = "\"data.gene.locus-tag\"";
324  }
325  else if (qualifier == "synonym") {
326  str = "\"data.gene.syn\"";
327  }
328  else if (NStr::EqualNocase(qualifier,"EC Number")) {
329  str = "\"data.prot.ec\"";
330  }
331  else if (qualifier == "activity") {
332  str = "\"data.prot.activity\"";
333  }
334 
335  if (qualifier == "product" && feature == "mRNA") {
336  str = "\"data.rna.ext.name\"";
337  }
338 
339  if (str.empty()) {
340  str = "\"qual\", \"" + qualifier + "\"";
341  }
342 
343  if (NStr::EqualNocase(target, feature)) {
344  return str;
345  }
346 
347  if (NStr::EqualNocase(feature, "cdregion")) {
348  feature = "cds";
349  }
350 
351  if (CFieldNamePanel::IsFeature(target))
352  {
353  str = "RELATED_FEATURE(\"" + feature + "\", " + str + ")";
354  return str;
355  }
356  str = "FEATURES(\"" + feature + "\"," + str + ")";
357  return str;
358 }
359 
virtual vector< string > GetChoices(bool &allow_other)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
static bool ShowToolTips()
Should we show tooltips?
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CCDSGENEPROTFIELDNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual string GetMacroFieldName(const string &target, const string &selected_field=kEmptyStr)
static string s_GetMacroFieldName(const string &field_name, const string &target, const string &selected_field=kEmptyStr)
virtual bool SetFieldName(const string &field)
void OnFieldSelected(wxCommandEvent &event)
wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_FIELD
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
void Init()
Initialises member variables.
void x_UpdateParent(void)
static bool IsFeature(const string &target)
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define NPOS
Definition: ncbistr.hpp:133
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:5355
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
bool QualifierNamesAreEquivalent(string name1, string name2)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Tue Jul 23 17:57:56 2024 by modify_doxy.py rev. 669887