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

Go to the SVN repository for this file.

1 /* $Id: macro_featloc_itemdata.cpp 46836 2021-10-28 20:47:55Z 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: Andrea Asztalos
27 
28  */
29 
30 
31 #include <ncbi_pch.hpp>
35 
38 
39 // CEditFeatLocTreeItemData
40 CEditFeatLocTreeItemData::CEditFeatLocTreeItemData(const string& description, const string& panel_name, const TArgumentsVector& arguments)
41  : CMacroActionItemData(description), m_PanelName(panel_name), m_Arguments(&arguments)
42 {
43 }
44 
46 {
48  vector<string> features = CMacroEditorContext::GetInstance().GetFeatureTypes(true);
49  m_Panel->SetControlValues(m_Args[0]->GetName(), features);
50 }
51 
53 {
55  bool modified = (m_Target != new_target);
56  m_Target = new_target;
57  m_SelectedField = m_Args[0]->GetValue();
58  return modified;
59 }
60 
62 {
63  string descr = " for ";
64  if (m_Args[0]->GetValue() == "All") {
65  descr += "any";
66  }
67  else {
68  descr += m_Args[0]->GetValue();
69  }
70  descr += " features";
71 
72  if (m_Args[index]->GetValue() == "true") {
73  descr += " and retranslate affected coding regions";
74  }
75  if (m_Args[++index]->GetValue() == "true") {
76  descr += " and adjust overlapping gene";
77  }
78  return descr;
79 }
80 
82 {
83  string variables;
84  for (size_t i = index; i < m_Args.size(); ++i) {
85  variables += m_Args[i]->GetName() + " = %" + m_Args[i]->GetValue() + "%\n";
86  }
87  variables.pop_back();
88  return variables;
89 }
90 
92 {
93  string function;
94  for (size_t i = index; i < m_Args.size(); ++i) {
95  function += ", " + m_Args[i]->GetName();
96  }
97  function += ");";
98  return function;
99 }
100 
101 
102 // CSet5PartialTreeItemData
104  : CEditFeatLocTreeItemData("Set 5' end partial in feature locations",
105  macro::CMacroFunction_Set5Partial::GetFuncName(),
107 {
108  m_5PartialMap.emplace("All", make_pair("all", kEmptyStr));
109  m_5PartialMap.emplace("Only if at 5' end", make_pair("at-end", " when 5' end of location is at end of sequence"));
110  m_5PartialMap.emplace("If bad start codon", make_pair("bad-start", " when coding region has no start codon"));
111  m_5PartialMap.emplace("If CDS frame > 1", make_pair("frame-not-one", " when coding region frame > 1"));
112 }
113 
115 {
116  string descr = "Set 5' partial";
117  auto it = m_5PartialMap.find(m_Args[1]->GetValue());
118  if (it != m_5PartialMap.end()) {
119  descr += it->second.second;
120  }
121 
122  if (m_Args[2]->GetValue() == "true") {
123  descr += ", extend 5' end of feature to end of sequence";
124  }
125  return descr + x_CommonEditFeatLocDescr(3);
126 }
127 
129 {
130  return x_CommonEditFeatLocVars(2);
131 }
132 
134 {
135  NMItemData::UpdateConstraintsForFeatures(constraints, m_Args[0]->GetValue());
136  string function = macro::CMacroFunction_Set5Partial::GetFuncName();
137  auto it = m_5PartialMap.find(m_Args[1]->GetValue());
138  if (it != m_5PartialMap.end()) {
139  function += "(\"" + it->second.first + "\"";
140  }
141  return function + x_CommonEditFeatFunc(2);
142 }
143 
145 {
146  return { macro::CMacroFunction_Set5Partial::GetFuncName() };
147 }
148 
149 
150 // CSet3PartialTreeItemData
152  : CEditFeatLocTreeItemData("Set 3' end partial in feature locations",
153  macro::CMacroFunction_Set3Partial::GetFuncName(),
155 {
156  m_3PartialMap.emplace("All", make_pair("all", kEmptyStr));
157  m_3PartialMap.emplace("Only if at 3' end", make_pair("at-end", " when 3' end of location is at end of sequence"));
158  m_3PartialMap.emplace("If bad stop codon", make_pair("bad-end", " when coding region has no stop codon"));
159 }
160 
162 {
163  string descr = "Set 3' partial";
164  auto it = m_3PartialMap.find(m_Args[1]->GetValue());
165  if (it != m_3PartialMap.end()) {
166  descr += it->second.second;
167  }
168 
169  if (m_Args[2]->GetValue() == "true") {
170  descr += ", extend 3' end of feature to end of sequence";
171  }
172  return descr + x_CommonEditFeatLocDescr(3);
173 }
174 
176 {
177  return x_CommonEditFeatLocVars(2);
178 }
179 
181 {
182  NMItemData::UpdateConstraintsForFeatures(constraints, m_Args[0]->GetValue());
183  string function = macro::CMacroFunction_Set3Partial::GetFuncName();
184  auto it = m_3PartialMap.find(m_Args[1]->GetValue());
185  if (it != m_3PartialMap.end()) {
186  function += "(\"" + it->second.first + "\"";
187  }
188  return function + x_CommonEditFeatFunc(2);
189 }
190 
192 {
193  return { macro::CMacroFunction_Set3Partial::GetFuncName() };
194 }
195 
196 // CSetBothPartialTreeItemData
198  : CEditFeatLocTreeItemData("Set both ends partial in feature locations",
199  macro::CMacroFunction_SetBothPartials::GetFuncName(),
201 {
202  m_BothPartialMap.emplace("All", make_pair("all", kEmptyStr));
203  m_BothPartialMap.emplace("If both ends at end of sequence", make_pair("at-end", "when both ends of location are at end of sequence"));
204 }
205 
207 {
208  string descr = "Set both ends partial";
209  auto it = m_BothPartialMap.find(m_Args[1]->GetValue());
210  if (it != m_BothPartialMap.end()) {
211  descr += it->second.second;
212  }
213 
214  if (m_Args[2]->GetValue() == "true") {
215  descr += ", extend both ends of feature to end of sequence";
216  }
217  return descr + x_CommonEditFeatLocDescr(3);
218 }
219 
221 {
222  return x_CommonEditFeatLocVars(2);
223 }
224 
226 {
227  NMItemData::UpdateConstraintsForFeatures(constraints, m_Args[0]->GetValue());
228  string function = macro::CMacroFunction_SetBothPartials::GetFuncName();
229  auto it = m_BothPartialMap.find(m_Args[1]->GetValue());
230  if (it != m_BothPartialMap.end()) {
231  function += "(\"" + it->second.first + "\"";
232  }
233  return function + x_CommonEditFeatFunc(2);
234 }
235 
237 {
238  return { macro::CMacroFunction_SetBothPartials::GetFuncName() };
239 }
240 
241 
242 // CClear5PartialTreeItemData
244  : CEditFeatLocTreeItemData("Clear 5' end partial in feature locations",
245  macro::CMacroFunction_Clear5Partial::GetFuncName(),
247 {
248  m_5PartialMap.emplace("All", make_pair("all", kEmptyStr));
249  m_5PartialMap.emplace("If not at 5' end", make_pair("not-at-end", "when 5' end of feature is not at end of sequence"));
250  m_5PartialMap.emplace("If good start codon", make_pair("good-start", "when coding region has start codon"));
251 }
252 
254 {
255  string descr = "Clear 5' partial ";
256  auto it = m_5PartialMap.find(m_Args[1]->GetValue());
257  if (it != m_5PartialMap.end()) {
258  descr += it->second.second;
259  }
260  return descr + x_CommonEditFeatLocDescr(2);
261 }
262 
264 {
265  return x_CommonEditFeatLocVars(2);
266 }
267 
269 {
270  NMItemData::UpdateConstraintsForFeatures(constraints, m_Args[0]->GetValue());
271  string function = macro::CMacroFunction_Clear5Partial::GetFuncName();
272  auto it = m_5PartialMap.find(m_Args[1]->GetValue());
273  if (it != m_5PartialMap.end()) {
274  function += "(\"" + it->second.first + "\"";
275  }
276  return function + x_CommonEditFeatFunc(2);
277 }
278 
280 {
281  return { macro::CMacroFunction_Clear5Partial::GetFuncName() };
282 }
283 
284 
285 // CClear3PartialTreeItemData
287  : CEditFeatLocTreeItemData("Clear 3' end partial in feature locations",
288  macro::CMacroFunction_Clear3Partial::GetFuncName(),
290 {
291  m_3PartialMap.emplace("All", make_pair("all", kEmptyStr));
292  m_3PartialMap.emplace("If not at 3' end", make_pair("not-at-end", "when 3' end of feature is not at end of sequence"));
293  m_3PartialMap.emplace("If good stop codon", make_pair("good-end", "when coding region has stop codon"));
294 }
295 
297 {
298  string descr = "Clear 3' partial ";
300  if (it != m_3PartialMap.end()) {
301  descr += it->second.second;
302  }
303  return descr + x_CommonEditFeatLocDescr(2);
304 }
305 
307 {
308  return x_CommonEditFeatLocVars(2);
309 }
310 
312 {
314  string function = macro::CMacroFunction_Clear3Partial::GetFuncName();
316  if (it != m_3PartialMap.end()) {
317  function += "(\"" + it->second.first + "\"";
318  }
319  return function + x_CommonEditFeatFunc(2);
320 }
321 
323 {
324  return { macro::CMacroFunction_Clear3Partial::GetFuncName() };
325 }
326 
327 // CClearBothPartialTreeItemData
329  : CEditFeatLocTreeItemData("Clear both ends partial in feature locations",
330  macro::CMacroFunction_RemoveBothPartials::GetFuncName(),
332 {
333  m_BothPartialMap.emplace("All", make_pair("all", kEmptyStr));
334  m_BothPartialMap.emplace("If both ends not at end of sequence", make_pair("not-at-end", "when both ends of feature are not at end of sequence"));
335 }
336 
338 {
339  string descr = "Clear both ends partial ";
341  if (it != m_BothPartialMap.end()) {
342  descr += it->second.second;
343  }
344  return descr + x_CommonEditFeatLocDescr(2);
345 }
346 
348 {
349  return x_CommonEditFeatLocVars(2);
350 }
351 
353 {
355  string function = macro::CMacroFunction_RemoveBothPartials::GetFuncName();
357  if (it != m_BothPartialMap.end()) {
358  function += "(\"" + it->second.first + "\"";
359  }
360  return function + x_CommonEditFeatFunc(2);
361 }
362 
364 {
365  return { macro::CMacroFunction_RemoveBothPartials::GetFuncName() };
366 }
367 
368 
369 
370 // CConvertStrandTreeItemData
372  : CEditFeatLocTreeItemData("Edit feature location strand",
373  macro::CMacroFunction_ConvertLocStrand::GetFuncName(),
375 {
376 }
377 
379 {
380  string from_strand = m_ArgList[NMacroArgs::kStrandFrom].GetValue();
381  string to_strand = m_ArgList[NMacroArgs::kStrandTo].GetValue();
382  from_strand[0] = tolower((unsigned char)from_strand[0]);
383  to_strand[0] = tolower((unsigned char)to_strand[0]);
384 
385  string descr = "Convert " + from_strand +" to " + to_strand;
386  return descr + x_CommonEditFeatLocDescr(3);
387 }
388 
390 {
391  return x_CommonEditFeatLocVars(3);
392 }
393 
395 {
397 
398  string from_strand = m_ArgList[NMacroArgs::kStrandFrom].GetValue();
399  string to_strand = m_ArgList[NMacroArgs::kStrandTo].GetValue();
400  from_strand[0] = tolower((unsigned char)from_strand[0]);
401  to_strand[0] = tolower((unsigned char)to_strand[0]);
402 
403  NMItemData::WrapInQuotes(from_strand);
404  NMItemData::WrapInQuotes(to_strand);
405 
406  string function = macro::CMacroFunction_ConvertLocStrand::GetFuncName();
407  function += "(" + from_strand + ", " + to_strand + x_CommonEditFeatFunc(3);
408  return function;
409 }
410 
412 {
413  return { macro::CMacroFunction_ConvertLocStrand::GetFuncName() };
414 }
415 
416 // CConvertLocTypeTreeItemData
418  : CEditFeatLocTreeItemData("Convert feature location type",
419  macro::CMacroFunction_ConvertLocType::GetFuncName(),
421 {
422 }
423 
425 {
426  string type = m_ArgList[NMacroArgs::kLocType].GetValue();
427  type[0] = tolower((unsigned char)type[0]);
428 
429  return "Convert location to " + type + x_CommonEditFeatLocDescr(2);
430 }
431 
433 {
434  return x_CommonEditFeatLocVars(2);
435 }
436 
438 {
440 
441  string type = m_ArgList[NMacroArgs::kLocType].GetValue();
442  type[0] = tolower((unsigned char)type[0]);
443  NStr::ReplaceInPlace(type, " ", "-");
445 
446  string function = macro::CMacroFunction_ConvertLocType::GetFuncName();
447  function += "(" + type + x_CommonEditFeatFunc(2);
448  return function;
449 }
450 
452 {
453  return { macro::CMacroFunction_ConvertLocType::GetFuncName() };
454 }
455 
456 
457 // CExtendToSeqEndTreeItemData
459  : CEditFeatLocTreeItemData("Extend feature to end of sequence",
460  macro::CMacroFunction_Extend5Feature::GetFuncName(),
462  m_ActionType(type)
463 {
464 }
465 
467 {
468  string descr = "Extend ";
470  descr += "5'";
471  }
473  descr += "3'";
474  }
475  descr += " end of feature to end of sequence";
476  return descr + x_CommonEditFeatLocDescr(1);
477 }
478 
480 {
481  return x_CommonEditFeatLocVars(1);
482 }
483 
485 {
487 
488  string function;
490  function = macro::CMacroFunction_Extend5Feature::GetFuncName();
491  }
493  function = macro::CMacroFunction_Extend3Feature::GetFuncName();
494  }
495  function += "(" + NMacroArgs::kRetranslate + ", " + NMacroArgs::kAdjustGene + ");";
496  return function;
497 }
498 
500 {
502  return { macro::CMacroFunction_Extend5Feature::GetFuncName() };
503  }
505  return { macro::CMacroFunction_Extend3Feature::GetFuncName() };
506  }
507  return vector<string>{};
508 }
509 
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
map< string, pair< string, string > > m_3PartialMap
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
map< string, pair< string, string > > m_5PartialMap
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() const
map< string, pair< string, string > > m_BothPartialMap
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
CEditFeatLocTreeItemData(const string &description, const string &panel_name, const TArgumentsVector &arguments)
string x_CommonEditFeatLocVars(size_t index) const
string x_CommonEditFeatLocDescr(size_t index) const
virtual void x_AddParamPanel(wxWindow *parent)
string x_CommonEditFeatFunc(size_t index) const
const TArgumentsVector * m_Arguments
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
CExtendToSeqEndTreeItemData(EMActionType action_type)
virtual string GetMacroDescription() const
vector< string > GetFeatureTypes(bool for_removal=false, bool to_create=false, bool include_all=false) const
static CMacroEditorContext & GetInstance()
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() const
map< string, pair< string, string > > m_3PartialMap
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
map< string, pair< string, string > > m_5PartialMap
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual vector< string > GetFunctionNames() const
map< string, pair< string, string > > m_BothPartialMap
virtual string GetMacroDescription() const
virtual string GetFunction(TConstraints &constraints) const
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
void x_LoadPanel(wxWindow *parent, const string &panel_name, const TArgumentsVector &arguments)
unique_ptr< CMacroPanelLoader > m_Panel
constructed panel for specifying function arguments
vector< pair< string, string > > TConstraints
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
#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 & 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
int i
EMActionType
vector< macro::SArgMetaData > TArgumentsVector
USING_SCOPE(objects)
CTempString UpdateTargetForFeatures(const string &feature, const string &qualifier, bool for_removal=false)
void UpdateConstraintsForFeatures(TConstraints &constraints, const string &feature)
void WrapInQuotes(string &str)
const TArgumentsVector & GetConvertLocStrandArgs()
const string kStrandFrom
const string kLocType
const string kAdjustGene
const string kStrandTo
const string kPartialOption
const TArgumentsVector & GetSetPartialArgs()
const TArgumentsVector & GetExtendFeatToSeqEndArgs()
const TArgumentsVector & GetConvertLocTypeArgs()
const string kFeatType
const string kRetranslate
const TArgumentsVector & GetClearPartialArgs()
int tolower(Uchar c)
Definition: ncbictype.hpp:72
Definition: type.c:6
Modified on Thu May 02 14:34:18 2024 by modify_doxy.py rev. 669887