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

Go to the SVN repository for this file.

1 /* $Id: macro_parse_itemdata.cpp 47217 2022-11-14 18:28:28Z 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>
37 
41 
44 USING_SCOPE(macro);
46 
47 // CParseQualTreeItemData
49  : CMacroActionItemData(description, type)
50 {
51  m_IncludeLeft = make_pair("include_left", false);
52  m_IncludeRight = make_pair("include_right", false);
53  m_CaseSensitive = make_pair("case_sensitive_parse", true);
54 }
55 
57 {
60 
61  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
62  m_Panel->SetControlValues(kFromField, fieldnames);
63  m_Panel->SetControlValues(kToField, fieldnames);
64 
65  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
66  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
67  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
68  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
69 }
70 
72 {
73  string descr = x_GetParsedTextDescription();
74  descr += " from " + m_ArgList[kFromField].GetValue() + " to " + m_ArgList[kToField].GetValue();
76  return descr;
77 }
78 
80 {
81  string descr;
82  descr = "Parse";
83 
84  if (x_ParseEntireText()) {
85  descr += " entire text";
86  }
87  else {
88  descr += " text";
89  if (m_ArgList[kJustAfter].IsTrue()) {
90  descr += " just after";
91  }
92  else if (m_ArgList[kStartAt].IsTrue()) {
93  descr += " starting with";
94  }
95 
96  if (m_ArgList[kTextLeft].IsTrue() && !m_ArgList[kDelLeft].Empty()) {
97  descr += " '" + m_ArgList[kDelLeft].GetValue() + "'";
98  }
99  else if (m_ArgList[kDigitsLeft].IsTrue()) {
100  descr += " 'numbers'";
101  }
102  else if (m_ArgList[kLetterLeft].IsTrue()) {
103  descr += " 'letters'";
104  }
105 
106  if (!NStr::EndsWith(descr, " text")) {
107  descr += ",";
108  }
109 
110  if (m_ArgList[kUpTo].IsTrue()) {
111  descr += " up to";
112  }
113  else if (m_ArgList[kInclude].IsTrue()) {
114  descr += " up to and including";
115  }
116 
117  if (m_ArgList[kTextRight].IsTrue() && !m_ArgList[kDelRight].Empty()) {
118  descr += " '" + m_ArgList[kDelRight].GetValue() + "'";
119  }
120  else if (m_ArgList[kDigitsRight].IsTrue()) {
121  descr += " 'numbers'";
122  }
123  else if (m_ArgList[kLetterRight].IsTrue()) {
124  descr += " 'letters'";
125  }
126  }
127  return descr;
128 }
129 
131 {
132  string variables;
133  variables += kCapChange + " = \"" + NMItemData::GetCapitalizationTypeFromChoice(m_ArgList[kCapChange].GetValue()) + "\"\n";
134  variables += kExistingText + " = \"" + NMItemData::GetHandleOldValue(m_ArgList[kExistingText].GetValue()) + "\"";
135  if (m_ArgList[kDelimiter].GetEnabled()) {
136  variables += "\n" + kDelimiter + " = \"" + NMItemData::GetDelimiterChar(m_ArgList[kDelimiter].GetValue()) + "\"";
137  }
138 
139  if (!x_ParseEntireText()) {
140  if (m_ArgList[kJustAfter].IsTrue()) {
141  m_IncludeLeft.second = false;
142  }
143  else if (m_ArgList[kStartAt].IsTrue()) {
144  m_IncludeLeft.second = true;
145  }
146 
147  variables += "\n" + m_IncludeLeft.first + " = " + NStr::BoolToString(m_IncludeLeft.second) + "\n";
148 
149  if (m_ArgList[kUpTo].IsTrue()) {
150  m_IncludeRight.second = false;
151  }
152  else if (m_ArgList[kInclude].IsTrue()) {
153  m_IncludeRight.second = true;
154 
155  }
156 
157  variables += m_IncludeRight.first + " = " + NStr::BoolToString(m_IncludeRight.second) + "\n";
158  variables += kRmvParse + " = " + m_ArgList[kRmvParse].GetValue() + "\n";
159  variables += kRmvLeft + " = " + m_ArgList[kRmvLeft].GetValue() + "\n";
160  variables += kRmvRight + " = " + m_ArgList[kRmvRight].GetValue() + "\n";
161 
162  m_CaseSensitive.second = !(m_ArgList[kCaseInsensParse].IsTrue());
163  variables += m_CaseSensitive.first + " = " + NStr::BoolToString(m_CaseSensitive.second) + "\n";
164 
165  variables += kWholeWordParse + " = " + m_ArgList[kWholeWordParse].GetValue();
166  }
167  return variables;
168 }
169 
170 pair<string, string> CParseQualTreeItemData::x_GetResolveFuncForMultValQuals(const string& field, const string& rt_var,
171  TConstraints& constraints, bool remove_constraint) const
172 {
174  string resolve_fnc, var_name = path;
175  NMItemData::WrapInQuotes(var_name);
176 
178  resolve_fnc = NMItemData::GetResolveFuncForMultiValuedQual(path, rt_var, constraints, remove_constraint);
179 
180  if (!resolve_fnc.empty()) {
181  var_name = rt_var;
182  }
183  } else if (path.find(',') != NPOS) {
184  vector<string> tokens;
185  NStr::Split(path, ",", tokens);
186 
187  _ASSERT(tokens.size() == 2);
188  var_name = tokens[1];
189  NMItemData::WrapInQuotes(var_name);
190  }
191 
192  return make_pair(resolve_fnc, var_name);
193 }
194 
196 {
198  return kEmptyStr;
199 
200  bool remove_constraint = true;
201  pair<string, string> source = x_GetResolveFuncForMultValQuals(m_ArgList[kFromField].GetValue(), "src", constraints, remove_constraint);
202  pair<string, string> dest = x_GetResolveFuncForMultValQuals(m_ArgList[kToField].GetValue(), "dest", constraints, remove_constraint);
203 
204  NMItemData::AddConstraintIgnoreNewText(dest.second, constraints, m_Panel->GetArgumentList());
205 
206  string function;
207  function += source.first;
208  function += dest.first;
209 
210  if (x_ParseEntireText()) {
211  // parse the entire text
212 
214  function += "(" + source.second + ", " + dest.second + ", " + kCapChange+ ", " + kExistingText;
215  if (m_ArgList[kDelimiter].GetEnabled()) {
216  function += ", " + kDelimiter;
217  }
218  function += ");";
219 
220  if (m_ArgList[kRmvParse].IsTrue()) {
221  function += "\n";
223  function += "(" + source.second + ");";
224  }
225  }
226  else {
227  string parsed_text = "text";
228  function += x_GetParsedTextFunction(source.second, parsed_text);
230  function += "(" + parsed_text + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
231  if (m_ArgList[kDelimiter].GetEnabled()) {
232  function += ", " + kDelimiter;
233  }
234  function += ");";
235  }
236 
237  return function;
238 }
239 
240 string CParseQualTreeItemData::x_GetParsedTextFunction(const string& src_field, const string& parsed_text) const
241 {
242  string parsed_fnc = parsed_text + " = " + CMacroFunction_ParsedText::GetFuncName();
243  parsed_fnc += "(" + src_field + ", ";
244  x_GetParsedTextFncCore(parsed_fnc);
245  return parsed_fnc;
246 }
247 
249 {
250  string left_del;
251  if (m_ArgList[kTextLeft].IsTrue()) {
252  left_del = m_ArgList[kDelLeft].GetValue();
253  }
254  else if (m_ArgList[kDigitsLeft].IsTrue()) {
255  left_del = "eDigits";
256  }
257  else if (m_ArgList[kLetterLeft].IsTrue()) {
258  left_del = "eLetters";
259  }
260 
261  NMItemData::WrapInQuotes(left_del);
262  parsed_fnc += left_del + ", " + m_IncludeLeft.first + ", ";
263 
264 
265  string right_del;
266  if (m_ArgList[kTextRight].IsTrue()) {
267  right_del = m_ArgList[kDelRight].GetValue();
268  }
269  else if (m_ArgList[kDigitsRight].IsTrue()) {
270  right_del = "eDigits";
271  }
272  else if (m_ArgList[kLetterRight].IsTrue()) {
273  right_del = "eLetters";
274  }
275 
276  NMItemData::WrapInQuotes(right_del);
277  parsed_fnc += right_del + ", " + m_IncludeRight.first + ", ";
278 
279  parsed_fnc += m_CaseSensitive.first + ", " + kWholeWordParse;
280  parsed_fnc += ", " + kRmvParse;
281  parsed_fnc += ", " + kRmvLeft;
282  parsed_fnc += ", " + kRmvRight;
283  parsed_fnc += ");\n";
284 }
285 
286 
288 {
289  bool empty_before = (m_ArgList[kTextLeft].IsTrue() && m_ArgList[kDelLeft].Empty()) &&
290  !m_ArgList[kDigitsLeft].IsTrue() &&
291  !m_ArgList[kLetterLeft].IsTrue();
292  bool empty_after = (m_ArgList[kTextRight].IsTrue() && m_ArgList[kDelRight].Empty()) &&
293  !m_ArgList[kDigitsRight].IsTrue() &&
294  !m_ArgList[kLetterRight].IsTrue();
295  return empty_before && empty_after;
296 }
297 
299 {
300  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_ParsedText::GetFuncName(),
303  };
304 }
305 
307 {
309 }
310 
311 
312 // CParseBsrcTreeItemData
314  : CParseQualTreeItemData("Parse text between biosource qualifiers", EMacroFieldType::eBiosourceText)
315 {
316 }
317 
318 const vector<string>& CParseBsrcTreeItemData::GetKeywords() const
319 {
321 }
322 
324 {
326  copy(GetParseArgs().begin(), GetParseArgs().end(), back_inserter(args));
327  x_LoadPanel(parent, "ParseStringSourceQual", args);
328 
330  m_Panel->SetControlValues(kFromField, fieldnames);
331  m_Panel->SetControlValues(kToField, fieldnames);
332 
333  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
334  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
335  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
336  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
337 }
338 
340 {
342  return kEmptyStr;
343 
344  //get the source field
345  string rt_var = "src";
348  string src_resolve_fnc, src_var_name = path;
349  NMItemData::WrapInQuotes(src_var_name);
350 
351  if (path.find(',') != NPOS) {
352  vector<string> tokens;
353  NStr::Split(path, ",", tokens);
354 
355  _ASSERT(tokens.size() == 2);
356  src_resolve_fnc = NMItemData::GetResolveFuncForQual(tokens[0], tokens[1], rt_var, constraints);
357 
358  if (!src_resolve_fnc.empty()) {
359  src_var_name = NMItemData::GetEditableFieldForPair(m_ArgList[kFromField].GetValue(), rt_var, false);
360  NMItemData::WrapInQuotes(src_var_name);
361  }
362  }
363 
364  // get the destination field
367 
368  NMItemData::AddConstraintIgnoreNewText(dest, constraints, m_Panel->GetArgumentList());
369 
370  if (dest.find(',') != NPOS) {
371  vector<string> tokens;
372  NStr::Split(dest, ",", tokens);
373  dest = m_ArgList[kToField].GetValue();
374  }
376 
377  string function;
378  function += src_resolve_fnc;
379 
380  if (x_ParseEntireText()) {
381  // parse the entire text
382 
384  function += "(" + src_var_name + ", " + dest + ", " + kCapChange + ", " + kExistingText;
385  if (m_ArgList[kDelimiter].GetEnabled()) {
386  function += ", " + kDelimiter;
387  }
388  function += ");";
389 
390  if (m_ArgList[kRmvParse].IsTrue()) {
391  function += "\n";
392  if (path.find(',') != NPOS) {
393  function += CMacroFunction_RemoveModifier::GetFuncName();
394  function += "(" + rt_var + ");";
395  }
396  else {
398  function += "(" + src_var_name + ");";
399  }
400  }
401  }
402  else {
403  string parsed_text = "text";
404  function += x_GetParsedTextFunction(src_var_name, parsed_text);
406  function += "(" + parsed_text + ", " + dest + ", " + kCapChange + ", " + kExistingText;
407  if (m_ArgList[kDelimiter].GetEnabled()) {
408  function += ", " + kDelimiter;
409  }
410  function += ");";
411  }
412 
413  return function;
414 }
415 
417 {
418  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_ParseStringQual::GetFuncName(),
419  CMacroFunction_RemoveModifier::GetFuncName(), CMacroFunction_RemoveQual::GetFuncName(),
421 }
422 
423 
424 // CParseToBsrcTreeItemData
426  : CParseQualTreeItemData("Parse text to biosource qualifiers", EMacroFieldType::eBiosourceText)
427 {
428 }
429 
430 const vector<string>& CParseToBsrcTreeItemData::GetKeywords() const
431 {
433 }
434 
436 {
438  copy(GetParseArgs().begin(), GetParseArgs().end(), back_inserter(args));
439  x_LoadPanel(parent, "ParseToStringSourceQual", args);
440 
442  m_Panel->SetControlValues(kFromField, fieldnames);
444  m_Panel->SetControlValues(kToField, fieldnames);
445 
446  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
447  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
448  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
449  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
450 }
451 
453 {
455  if (x_ParseEntireText()) {
456  string variables;
457  variables += kCapChange + " = \"" + NMItemData::GetCapitalizationTypeFromChoice(m_ArgList[kCapChange].GetValue()) + "\"\n";
458  variables += kExistingText + " = \"" + NMItemData::GetHandleOldValue(m_ArgList[kExistingText].GetValue()) + "\"";
459  if (m_ArgList[kDelimiter].GetEnabled()) {
460  variables += "\n" + kDelimiter + " = \"" + NMItemData::GetDelimiterChar(m_ArgList[kDelimiter].GetValue()) + "\"";
461  }
462  return variables;
463  }
465 }
466 
468 {
470  return kEmptyStr;
471 
472  //get the source field
474 
475  // get the destination field
478 
479  NMItemData::AddConstraintIgnoreNewText(dest, constraints, m_Panel->GetArgumentList());
480 
481  if (dest.find(',') != NPOS) {
482  vector<string> tokens;
483  NStr::Split(dest, ",", tokens);
484  dest = m_ArgList[kToField].GetValue();
485  }
487 
488  string function;
489  string rt_var;
490  if (x_ParseEntireText()) {
491  if (src_path == "localid") {
492  rt_var = "id";
493  function = rt_var + " = " + CMacroFunction_LocalID::GetFuncName() + "();\n";
494  }
495  else if (src_path == "defline") {
496  rt_var = "defline";
497  function = rt_var + " = " + string(CMacroFunction_GetSequence::sm_SeqForDescr);
498  function += "(\"descr..title\");\n";
499  }
501  }
502  else {
503  rt_var = "text";
504  NMItemData::WrapInQuotes(src_path);
505  function = x_GetParsedTextFunction(src_path, rt_var);
507  }
508 
509  function += "(" + rt_var + ", " + dest + ", " + kCapChange + ", " + kExistingText;
510  if (m_ArgList[kDelimiter].GetEnabled()) {
511  function += ", " + kDelimiter;
512  }
513  function += ");";
514 
515  return function;
516 }
517 
519 {
520  return { CMacroFunction_ParsedText::GetFuncName(), CMacroFunction_LocalID::GetFuncName(),
523 }
524 
526 {
528 }
529 
530 // CParseToDBLinkTreeItemData
532  : CParseQualTreeItemData("Parse text to DBLink field", EMacroFieldType::eDBLink)
533 {
534 }
535 
537 {
539  x_LoadPanel(parent, CMacroFunction_ParseToDBLink::GetFuncName(), args);
540 
542  m_Panel->SetControlValues(kFromField, fieldnames);
544  m_Panel->SetControlValues(kToField, fieldnames);
545 
546  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
547  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
548  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
549  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
550 }
551 
553 {
555  if (src_path == "localid" && x_ParseEntireText()) {
556  string variables;
557  variables += kCapChange + " = \"" + NMItemData::GetCapitalizationTypeFromChoice(m_ArgList[kCapChange].GetValue()) + "\"\n";
558  variables += kExistingText + " = \"" + NMItemData::GetHandleOldValue(m_ArgList[kExistingText].GetValue()) + "\"";
559  if (m_ArgList[kDelimiter].GetEnabled()) {
560  variables += "\n" + kDelimiter + " = \"" + NMItemData::GetDelimiterChar(m_ArgList[kDelimiter].GetValue()) + "\"";
561  }
562  return variables;
563  }
565 }
566 
568 {
570  return kEmptyStr;
571 
572  //get the source field
574 
575  // get the destination field
577 
578  NMItemData::AddConstraintIgnoreNewText(dest, constraints, m_Panel->GetArgumentList());
579 
580  if (dest.find(',') != NPOS) {
581  vector<string> tokens;
582  NStr::Split(dest, ",", tokens);
583  dest = m_ArgList[kToField].GetValue();
584  }
586 
587  string function;
588  string rt_var;
589  if (x_ParseEntireText()) {
590  if (src_path == "localid") {
591  rt_var = "id";
592  function = rt_var + " = " + CMacroFunction_LocalID::GetFuncName() + "();\n";
593  }
594  else if (src_path == "defline") {
595  rt_var = "\"descr..title\"";
596  }
597  }
598  else {
599  rt_var = "text";
600  NMItemData::WrapInQuotes(src_path);
601  function = x_GetParsedTextFunction(src_path, rt_var);
602  }
603 
604  function += CMacroFunction_ParseToDBLink::GetFuncName();
605  function += "(" + rt_var + ", \"" + m_ArgList[kToField].GetValue() + "\", " + kCapChange + ", " + kExistingText;
606  if (m_ArgList[kDelimiter].GetEnabled()) {
607  function += ", " + kDelimiter;
608  }
609  function += ");";
610 
611  return function;
612 }
613 
615 {
616  return { CMacroFunction_ParseToDBLink::GetFuncName(),
618  CMacroFunction_LocalID::GetFuncName() };
619 }
620 
622 {
623  return { CMacroFunction_ParseToDBLink::GetFuncName() };
624 }
625 
626 
627 // CParseToCdsGeneProtTreeItemData
629  : CParseQualTreeItemData("Parse text to cds-gene-prot-mRNA qualifiers", EMacroFieldType::eCdsGeneProt)
630 {
631 }
632 
633 const vector<string>& CParseToCdsGeneProtTreeItemData::GetKeywords() const
634 {
636 }
637 
639 {
642 
644  m_Panel->SetControlValues(kFromField, fieldnames);
646  m_Panel->SetControlValues(kToField, fieldnames);
647 
648  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
649  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
650  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
651  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
652 }
653 
655 {
657  bool modified = (new_target != m_Target);
658  m_Target = new_target;
659  return modified;
660 }
661 
663 {
665  if (src_path == "localid" && x_ParseEntireText()) {
666  string variables;
667  variables += kCapChange + " = \"" + NMItemData::GetCapitalizationTypeFromChoice(m_ArgList[kCapChange].GetValue()) + "\"\n";
668  variables += kExistingText + " = \"" + NMItemData::GetHandleOldValue(m_ArgList[kExistingText].GetValue()) + "\"";
669  if (m_ArgList[kDelimiter].GetEnabled()) {
670  variables += "\n" + kDelimiter + " = \"" + NMItemData::GetDelimiterChar(m_ArgList[kDelimiter].GetValue()) + "\"";
671  }
672  return variables;
673  }
675 }
676 
678 {
680  return kEmptyStr;
681 
682  //get the source field
684 
685  string dest_feat = m_ArgList[kToField].GetValue(), dest_field;
686  NMItemData::GetFeatureAndField(m_ArgList[kToField].GetValue(), dest_feat, dest_field);
687  NMItemData::UpdateConstraintsForDualCdsGeneProt(constraints, dest_feat);
688 
689  // get the destination field
690  bool remove_constraint = true;
691  pair<string, string> dest = x_GetResolveFuncForMultValQuals(m_ArgList[kToField].GetValue(), "dest", constraints, remove_constraint);
692  NMItemData::AddConstraintIgnoreNewText(dest.second, constraints, m_Panel->GetArgumentList());
693 
694  string function;
695  string rt_var;
696  if (x_ParseEntireText()) {
697  if (src_path == "localid") {
698  rt_var = "id";
699  function = rt_var + " = " + CMacroFunction_LocalID::GetFuncName() + "();\n";
700  function += dest.first;
701  }
702  else if (src_path == "defline") {
703  rt_var = "defline";
704  function = rt_var + " = " + string(CMacroFunction_GetSequence::sm_SeqForFeat);
705  function += "(\"descr..title\");\n";
706  function += dest.first;
707  }
709  }
710  else {
711  rt_var = "text";
712  NMItemData::WrapInQuotes(src_path);
713  function = x_GetParsedTextFunction(src_path, rt_var);
714  function += dest.first;
716  }
717 
718  function += "(" + rt_var + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
719  if (m_ArgList[kDelimiter].GetEnabled()) {
720  function += ", " + kDelimiter;
721  }
722  function += ");";
723 
724  return function;
725 }
726 
728 {
731  CMacroFunction_Resolve::GetFuncName(),
733  CMacroFunction_LocalID::GetFuncName(),
735 }
736 
737 
738 // CParseProteinQualTreeItemData
740  : CParseQualTreeItemData("Parse protein (CDS product) fields", EMacroFieldType::eProtein)
741 {
742 }
743 
745 {
747  args.push_back(GetOptionalArgs()[2]);
748  x_LoadPanel(parent, "ParseStringProteinQual", args);
749 
750  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
751  m_Panel->SetControlValues(kFromField, fieldnames);
752  m_Panel->SetControlValues(kToField, fieldnames);
753 
754  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
755  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
756  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
757  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
758  m_Panel->GetArgumentList().Attach(NMItemData::OnProteinNameDouble);
759 }
760 
762 {
765  return descr;
766 }
767 
769 {
771  return kEmptyStr;
772 
773  bool update_mrna = m_ArgList[kUpdatemRNA].GetEnabled() && m_ArgList[kUpdatemRNA].IsTrue();
774  pair<string, string> source = x_GetResolveFuncForMultValQuals(m_ArgList[kFromField].GetValue(), "src", constraints, !update_mrna);
775  pair<string, string> dest = x_GetResolveFuncForMultValQuals(m_ArgList[kToField].GetValue(), "dest", constraints, !update_mrna);
776 
777  NMItemData::AddConstraintIgnoreNewText(dest.second, constraints, m_Panel->GetArgumentList());
778 
779  string function;
780  function += source.first;
781  function += dest.first;
782 
783  if (x_ParseEntireText()) {
784  // parse the entire text
785 
787  function += "(" + source.second + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
788  if (m_ArgList[kDelimiter].GetEnabled()) {
789  function += ", " + kDelimiter;
790  }
791  function += ");";
792 
793  if (m_ArgList[kRmvParse].IsTrue()) {
794  function += "\n";
796  function += "(" + source.second + ");";
797  }
798  }
799  else {
800  string parsed_text = "text";
801  function += x_GetParsedTextFunction(source.second, parsed_text);
803  function += "(" + parsed_text + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
804  if (m_ArgList[kDelimiter].GetEnabled()) {
805  function += ", " + kDelimiter;
806  }
807  function += ");";
808  }
809 
810  NMItemData::AppendUpdatemRNAFnc(update_mrna, function);
811  return function;
812 }
813 
815 {
816  return { CMacroFunction_Resolve::GetFuncName(),
821  CMacroFunction_UpdatemRNAProduct::GetFuncName() };
822 }
823 
824 
825 // CParseRNAQualTreeItemData
827  : CParseQualTreeItemData("Parse RNA qualifiers", EMacroFieldType::eRNA)
828 {
829 }
830 
832 {
834  args.push_back(GetOptionalArgs()[3]);
835  args.push_back(GetOptionalArgs()[4]);
836  x_LoadPanel(parent, "ParseStringRNAQual", args);
837 
838  vector<string> rnas = CMacroEditorContext::GetInstance().GetRNATypes();
839  m_Panel->SetControlValues(kRNAType, rnas);
840  m_Panel->SetSelection(kRNAType, 0);
841  vector<string> class_types = CMacroEditorContext::GetInstance().GetncRNAClassTypes();
842  m_Panel->SetControlValues(kncRNAClass, class_types);
843  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
844  m_Panel->SetControlValues(kFromField, fieldnames);
845  m_Panel->SetControlValues(kToField, fieldnames);
846 
847  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
848  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
849  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
850  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
851  m_Panel->GetArgumentList().Attach(NMItemData::OnRnaTypeChanged);
852 }
853 
855 {
857  bool modified = (new_target != m_Target);
858  m_Target = new_target;
859  m_SelectedField = m_ArgList[kRNAType].GetValue();
860  return modified;
861 }
862 
864 {
865  string descr = x_GetParsedTextDescription() + " from";
866 
867  if (m_ArgList[kncRNAClass].GetEnabled() && !m_ArgList[kncRNAClass].Empty()) {
868  descr += " " + m_ArgList[kncRNAClass].GetValue();
869  }
870  descr += " " + m_ArgList[kRNAType].GetValue() + " ";
871  if (m_ArgList[kRNAType].GetValue() == "any") {
872  descr += "RNA ";
873  }
874  descr += m_ArgList[kFromField].GetValue();
875  descr += " to " + m_ArgList[kToField].GetValue();
877  return descr;
878 }
879 
881 {
882  string from_field = m_ArgList[kFromField].GetValue();
883  string to_field = m_ArgList[kToField].GetValue();
884  const string rna_type = m_ArgList[kRNAType].GetValue();
885 
886  if (from_field.empty() || to_field.empty())
887  return kEmptyStr;
888 
889  if ((from_field == "ncRNA class" || to_field == "ncRNA class") && !NStr::EqualNocase(rna_type, "ncRNA"))
890  return kEmptyStr;
891 
892  if (from_field == "codons recognized")
893  return kEmptyStr;
894 
895  if (to_field == "codons recognized" && !NStr::EqualNocase(rna_type, "tRNA"))
896  return kEmptyStr;
897 
899 
900  string src_feat = "rna";
901  if (NStr::StartsWith(from_field, "gene")) {
902  src_feat = "gene";
903  }
904  else {
905  from_field = rna_type + " " + from_field;
906  }
907 
908  string dest_feat = "rna";
909  if (NStr::StartsWith(to_field, "gene")) {
910  dest_feat = "gene";
911  }
912  else {
913  to_field = rna_type + " " + to_field;
914  }
915 
916  string function;
917  bool remove_constraint = true;
918  string src_var = "src";
919  pair<string, string> source = NMItemData::GetResolveFuncForRNAQuals(from_field, src_var, constraints, remove_constraint);
920 
921  if (src_feat == dest_feat && src_feat == "rna") { // RNA -> RNA
922  pair<string, string> dest = NMItemData::GetResolveFuncForRNAQuals(to_field, "dest", constraints, remove_constraint);
923 
924  if (!source.first.empty())
925  function += source.first;
926  if (!dest.first.empty())
927  function += dest.first;
928 
929  if (x_ParseEntireText()) {
931  function += "(" + source.second + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
932  if (m_ArgList[kDelimiter].GetEnabled()) {
933  function += ", " + kDelimiter;
934  }
935  function += ");";
936 
937  if (m_ArgList[kRmvParse].IsTrue()) {
938  function += "\n";
939  if (source.second.find("::") != NPOS) {
940  function += CMacroFunction_RemoveRnaProduct::GetFuncName() + "();";
941  }
942  else {
943  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
944  if (!source.first.empty()) {
945  function += src_var;
946  }
947  else {
948  function += source.second;
949  }
950  function += ");";
951  }
952  }
953  }
954  else {
955  string parsed_text = "text";
956  function += x_GetParsedTextFunction(source.second, parsed_text);
957 
958  if (to_field == "tRNA codons recognized") {
959  function += CMacroFunction_SetCodonsRecognized::GetFuncName();
960  function += "(" + parsed_text + ");";
961  }
962  else {
964  function += "(" + parsed_text + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
965  if (m_ArgList[kDelimiter].GetEnabled()) {
966  function += ", " + kDelimiter;
967  }
968  function += ");";
969  }
970  }
971  }
972  else {
974 
975  NMItemData::AddConstraintIgnoreNewText(dest_path, constraints, m_Panel->GetArgumentList(), dest_feat);
976 
977  if (!source.first.empty())
978  function += source.first;
979 
980  if (dest_path.find(',') != NPOS) {
981  vector<string> tokens;
982  NStr::Split(dest_path, ",", tokens);
983 
984  _ASSERT(tokens.size() == 2);
985  dest_path = tokens[1];
986  }
987  NMItemData::WrapInQuotes(dest_path);
988  if (x_ParseEntireText()) {
990  function += "(\"" + src_feat + "\", " + source.second + ", \"" + dest_feat + "\", " + dest_path + ", ";
991  function += kCapChange + ", " + kExistingText;
992  if (m_ArgList[kDelimiter].GetEnabled()) {
993  function += ", " + kDelimiter;
994  }
995  function += ");";
996 
997  if (m_ArgList[kRmvParse].IsTrue()) {
998  function += "\n";
999  if (src_feat == "gene") {
1000  function += CMacroFunction_RmvRelFeatQual::GetFuncName();
1001  function += "(\"gene\", " + source.second + ");";
1002  }
1003  else {
1004  if (source.second.find("::") != NPOS) {
1005  function += CMacroFunction_RemoveRnaProduct::GetFuncName() + "();";
1006  }
1007  else {
1008  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
1009  if (!source.first.empty()) {
1010  function += src_var;
1011  }
1012  else {
1013  function += source.second;
1014  }
1015  function += ");";
1016  }
1017  }
1018  }
1019  }
1020  else {
1021  string parsed_text = "text";
1022  if (src_feat == "rna") { // RNA -> Gene
1023  function += x_GetParsedTextFunction(source.second, parsed_text);
1025  function += "(" + parsed_text + ", \"" + dest_feat + "\", " + dest_path + ", ";
1026  function += kCapChange + ", false, " + kExistingText;
1027  if (m_ArgList[kDelimiter].GetEnabled()) {
1028  function += ", " + kDelimiter;
1029  }
1030  function += ");";
1031  }
1032  else {
1033  function += parsed_text + " = " + CMacroFunction_ParsedTextFrom::GetFuncName();
1034  function += "(\"" + src_feat + "\", " + source.second + ", ";
1035  x_GetParsedTextFncCore(function);
1036 
1037  if (dest_feat == "rna") { // GENE -> RNA
1039  function += "(" + parsed_text + ", " + dest_path + ", " + kCapChange + ", " + kExistingText;
1040  if (m_ArgList[kDelimiter].GetEnabled()) {
1041  function += ", " + kDelimiter;
1042  }
1043  function += ");";
1044 
1045  }
1046  else if (dest_feat == "gene") { // GENE -> GENE
1048  function += "(" + parsed_text + ", \"" + dest_feat + "\", " + dest_path + ", ";
1049  function += kCapChange + ", false, " + kExistingText;
1050  if (m_ArgList[kDelimiter].GetEnabled()) {
1051  function += ", " + kDelimiter;
1052  }
1053  function += ");";
1054  }
1055  }
1056  }
1057  }
1058  return function;
1059 }
1060 
1062 {
1063  return { CMacroFunction_Resolve::GetFuncName(),
1067  CMacroFunction_RemoveRnaProduct::GetFuncName(),
1069  CMacroFunction_RmvRelFeatQual::GetFuncName(),
1073  CMacroFunction_SetCodonsRecognized::GetFuncName()};
1074 }
1075 
1077 {
1084  };
1085 }
1086 
1087 
1088 // CParseFeatQualTreeItemData
1090  : CParseQualTreeItemData("Parse feature qualifiers", EMacroFieldType::eFeatQualifiers)
1091 {
1092 }
1093 
1095 {
1097  args.push_back(GetOptionalArgs()[0]);
1098  args.push_back(GetOptionalArgs()[2]);
1099  x_LoadPanel(parent, "ParseStringFeatQual", args);
1100 
1101  vector<string> features = CMacroEditorContext::GetInstance().GetFeatureTypes();
1102  m_Panel->SetControlValues(kFeatType, features);
1103  vector<string> qualifiers = CMacroEditorContext::GetInstance().GetFeatQualifiers();
1104  m_Panel->SetControlValues(kFromField, qualifiers);
1105  m_Panel->SetControlValues(kToField, qualifiers);
1106 
1107  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
1108  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
1109  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
1110  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
1111  m_Panel->GetArgumentList().Attach(NMItemData::OnProductDouble);
1112 }
1113 
1115 {
1117  bool modified = (new_target != m_Target);
1118  m_Target = new_target;
1119  m_SelectedField = m_ArgList[kFeatType].GetValue();
1120  return modified;
1121 }
1122 
1124 {
1125  string descr = x_GetParsedTextDescription() + " from ";
1126  descr += m_ArgList[kFeatType].GetValue() + " " + m_ArgList[kFromField].GetValue();
1127  descr += " to " + m_ArgList[kToField].GetValue();
1130  return descr;
1131 }
1132 
1134 {
1135  string vars = CParseQualTreeItemData::GetVariables();
1136  string src_feat = m_ArgList[kFeatType].GetValue(), src_field = m_ArgList[kFromField].GetValue();
1137  string dest_feat = m_ArgList[kFeatType].GetValue(), dest_field = m_ArgList[kToField].GetValue();
1138 
1139  NMItemData::UpdateFeatureType(src_feat, src_field);
1140  NMItemData::UpdateFeatureType(dest_feat, dest_field);
1141  if (src_feat != dest_feat) {
1143  }
1144  return vars;
1145 }
1146 
1148 {
1150  return kEmptyStr;
1151 
1152  string src_feat = m_ArgList[kFeatType].GetValue(), src_field = m_ArgList[kFromField].GetValue();
1153  string dest_feat = m_ArgList[kFeatType].GetValue(), dest_field = m_ArgList[kToField].GetValue();
1154 
1155  if (src_feat.empty() || src_field.empty() || dest_field.empty()) return kEmptyStr;
1156 
1157  NMItemData::UpdateFeatureType(src_feat, src_field);
1158  NMItemData::UpdateFeatureType(dest_feat, dest_field);
1159  bool update_mrna = m_ArgList[kUpdatemRNA].GetEnabled() && m_ArgList[kUpdatemRNA].IsTrue();
1160 
1161  NMItemData::UpdateConstraintsForFeatures(constraints, src_feat);
1162 
1163  string function;
1164  string src_var = "src";
1165  pair<string, string> source = NMItemData::GetResolveFuncForSrcFeatQuals(src_feat, src_field, src_var, constraints, !update_mrna);
1166 
1167  if (src_feat == dest_feat) {
1168  pair<string, string> dest = NMItemData::GetResolveFuncForDestFeatQuals(dest_feat, dest_field, "dest", constraints, !update_mrna);
1169  string dest_path = CMacroEditorContext::GetInstance().GetAsnPathToFieldName(dest_feat, dest_field);
1170  NMItemData::AddConstraintIgnoreNewText(dest_path, constraints, m_Panel->GetArgumentList());
1171 
1172  if (!source.first.empty())
1173  function += source.first;
1174  if (!dest.first.empty())
1175  function += dest.first;
1176 
1177  if (x_ParseEntireText()) {
1179  function += "(" + source.second + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
1180  if (m_ArgList[kDelimiter].GetEnabled()) {
1181  function += ", " + kDelimiter;
1182  }
1183  function += ");";
1184 
1185  if (m_ArgList[kRmvParse].IsTrue()) {
1186  function += "\n";
1187  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
1188  if (!source.first.empty()) {
1189  function += src_var;
1190  }
1191  else {
1192  function += source.second;
1193  }
1194  function += ");";
1195  }
1196  }
1197  else {
1198  string parsed_text = "text";
1199  function += x_GetParsedTextFunction(source.second, parsed_text);
1201  function += "(" + parsed_text + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
1202  if (m_ArgList[kDelimiter].GetEnabled()) {
1203  function += ", " + kDelimiter;
1204  }
1205  function += ");";
1206  }
1207  NMItemData::AppendUpdatemRNAFnc(update_mrna, function);
1208  }
1209  else {
1210  string dest_path = CMacroEditorContext::GetInstance().GetAsnPathToFieldName(dest_feat, dest_field);
1211 
1212  NMItemData::AddConstraintIgnoreNewText(dest_path, constraints, m_Panel->GetArgumentList(), dest_feat);
1213 
1214  if (!source.first.empty())
1215  function += source.first;
1216 
1217  if (dest_path.find(',') != NPOS) {
1218  vector<string> tokens;
1219  NStr::Split(dest_path, ",", tokens);
1220 
1221  _ASSERT(tokens.size() == 2);
1222  dest_path = tokens[1];
1223  }
1224  if (x_ParseEntireText()) {
1226  function += "(" + source.second + ", \"" + dest_feat + "\", \"" + dest_path + "\", ";
1227  function += kCapChange + ", " + kUpdatemRNA + ", " + kExistingText;
1228  if (m_ArgList[kDelimiter].GetEnabled()) {
1229  function += ", " + kDelimiter;
1230  }
1231  function += ");";
1232 
1233  if (m_ArgList[kRmvParse].IsTrue()) {
1234  function += "\n";
1235  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
1236  if (!source.first.empty()) {
1237  function += src_var;
1238  }
1239  else {
1240  function += source.second;
1241  }
1242  function += ");";
1243  }
1244  }
1245  else {
1246  string parsed_text = "text";
1247  function += x_GetParsedTextFunction(source.second, parsed_text);
1249  function += "(" + parsed_text + ", \"" + dest_feat + "\", \"" + dest_path + "\", ";
1250  function += kCapChange + ", " + kUpdatemRNA + ", " + kExistingText;
1251  if (m_ArgList[kDelimiter].GetEnabled()) {
1252  function += ", " + kDelimiter;
1253  }
1254  function += ");";
1255  }
1256  }
1257  return function;
1258 }
1259 
1261 {
1262  return { CMacroFunction_Resolve::GetFuncName(),
1263  CMacroFunction_GeneQual::GetFuncName(),
1270  CMacroFunction_UpdatemRNAProduct::GetFuncName() };
1271 }
1272 
1274 {
1280 }
1281 
1282 // CParseCdsGeneProtTreeItemdata
1284  : CParseQualTreeItemData("Parse between CDS gene protein mRNA mat-peptide qualifiers", EMacroFieldType::eCdsGeneProt)
1285 {
1286 }
1287 
1289 {
1291  args.push_back(GetOptionalArgs()[2]);
1292  x_LoadPanel(parent, "ParseStringProteinQual", args);
1293 
1294  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
1295  m_Panel->SetControlValues(kFromField, fieldnames);
1296  m_Panel->SetControlValues(kToField, fieldnames);
1297 
1298  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
1299  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
1300  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
1301  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
1302  m_Panel->GetArgumentList().Attach(NMItemData::OnProteinNameDouble);
1303 }
1304 
1306 {
1308  bool modified = (new_target != m_Target);
1309  m_Target = new_target;
1310  return modified;
1311 }
1312 
1314 {
1317  return descr;
1318 }
1319 
1321 {
1322  string vars = CParseQualTreeItemData::GetVariables();
1323  string src_feat, src_field;
1324  NMItemData::GetFeatureAndField(m_ArgList[kFromField].GetValue(), src_feat, src_field);
1325  string dest_feat, dest_field;
1326  NMItemData::GetFeatureAndField(m_ArgList[kToField].GetValue(), dest_feat, dest_field);
1327  if (src_feat != dest_feat) {
1329  }
1330  return vars;
1331 }
1332 
1334 {
1336  return kEmptyStr;
1337 
1338  string src_feat, src_field;
1339  NMItemData::GetFeatureAndField(m_ArgList[kFromField].GetValue(), src_feat, src_field);
1340  string dest_feat, dest_field;
1341  NMItemData::GetFeatureAndField(m_ArgList[kToField].GetValue(), dest_feat, dest_field);
1342 
1343  bool update_mrna = m_ArgList[kUpdatemRNA].GetEnabled() && m_ArgList[kUpdatemRNA].IsTrue();
1344 
1345  NMItemData::UpdateConstraintsForDualCdsGeneProt(constraints, src_feat);
1346 
1347  string function;
1348  string src_var = "src";
1349  pair<string, string> source = NMItemData::GetResolveFuncForSrcCdsGeneProtQuals(m_ArgList[kFromField].GetValue(), src_var, constraints, !update_mrna);
1350 
1351  if (src_feat == dest_feat) {
1352  pair<string, string> dest = NMItemData::GetResolveFuncForDestCdsGeneProtQuals(m_ArgList[kToField].GetValue(), "dest", constraints, !update_mrna);
1353 
1355  NMItemData::AddConstraintIgnoreNewText(dest_path, constraints, m_Panel->GetArgumentList());
1356 
1357  if (!source.first.empty())
1358  function += source.first;
1359  if (!dest.first.empty())
1360  function += dest.first;
1361 
1362  if (x_ParseEntireText()) {
1364  function += "(" + source.second + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
1365  if (m_ArgList[kDelimiter].GetEnabled()) {
1366  function += ", " + kDelimiter;
1367  }
1368  function += ");";
1369 
1370  if (m_ArgList[kRmvParse].IsTrue()) {
1371  function += "\n";
1372  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
1373  if (!source.first.empty()) {
1374  function += src_var;
1375  }
1376  else {
1377  function += source.second;
1378  }
1379  function += ");";
1380  }
1381  }
1382  else {
1383  string parsed_text = "text";
1384  function += x_GetParsedTextFunction(source.second, parsed_text);
1386  function += "(" + parsed_text + ", " + dest.second + ", " + kCapChange + ", " + kExistingText;
1387  if (m_ArgList[kDelimiter].GetEnabled()) {
1388  function += ", " + kDelimiter;
1389  }
1390  function += ");";
1391  }
1392  NMItemData::AppendUpdatemRNAFnc(update_mrna, function);
1393  }
1394  else {
1396 
1397  NMItemData::AddConstraintIgnoreNewText(dest_path, constraints, m_Panel->GetArgumentList(), dest_feat);
1398 
1399  if (!source.first.empty())
1400  function += source.first;
1401 
1402  if (dest_path.find(',') != NPOS) {
1403  vector<string> tokens;
1404  NStr::Split(dest_path, ",", tokens);
1405 
1406  _ASSERT(tokens.size() == 2);
1407  dest_path = tokens[1];
1408  }
1409 
1410  if (x_ParseEntireText()) {
1412  function += "(" + source.second + ", \"" + dest_feat + "\", \"" + dest_path + "\", ";
1413  function += kCapChange + ", " + kUpdatemRNA + ", " + kExistingText;
1414  if (m_ArgList[kDelimiter].GetEnabled()) {
1415  function += ", " + kDelimiter;
1416  }
1417  function += ");";
1418 
1419  if (m_ArgList[kRmvParse].IsTrue()) {
1420  function += "\n";
1421  function += CMacroFunction_RemoveQual::GetFuncName() + "(";
1422  if (!source.first.empty()) {
1423  function += src_var;
1424  }
1425  else {
1426  function += source.second;
1427  }
1428  function += ");";
1429  }
1430  }
1431  else {
1432  string parsed_text = "text";
1433  function += x_GetParsedTextFunction(source.second, parsed_text);
1435  function += "(" + parsed_text + ", \"" + dest_feat + "\", \"" + dest_path + "\", ";
1436  function += kCapChange + ", " + kUpdatemRNA + ", " + kExistingText;
1437  if (m_ArgList[kDelimiter].GetEnabled()) {
1438  function += ", " + kDelimiter;
1439  }
1440  function += ");";
1441  }
1442  }
1443  return function;
1444 }
1445 
1447 {
1448  return { CMacroFunction_Resolve::GetFuncName(),
1455  CMacroFunction_UpdatemRNAProduct::GetFuncName() };
1456 }
1457 
1459 {
1465 }
1466 
1467 
1468 // CParseBsrcToStructCommTreeItemData
1470  : CParseQualTreeItemData("Parse from biosource qualifiers to structured comment fields", EMacroFieldType::eBiosourceText)
1471 {
1472 }
1473 
1475 {
1477  copy(GetParseArgs().begin(), GetParseArgs().end(), back_inserter(args));
1478  x_LoadPanel(parent, "ParseBsrcToStructCommQual", args);
1479 
1481  m_Panel->SetControlValues(kFromField, fieldnames);
1483  m_Panel->SetControlValues(kToField, fieldnames);
1484  m_Panel->SetSelection(kToField, 0);
1485 
1486  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
1487  m_Panel->GetArgumentList().Attach(NMItemData::OnRemoveFromParsedField);
1488  m_Panel->GetArgumentList().Attach(NMItemData::OnLeftDigitsLettersInParsePanels);
1489  m_Panel->GetArgumentList().Attach(NMItemData::OnRightDigitsLettersInParsePanels);
1490  m_Panel->GetArgumentList().Attach(NMItemData::OnStructCommFieldDblChanged);
1491 }
1492 
1494 {
1495  string descr = x_GetParsedTextDescription();
1496  descr += " from " + m_ArgList[kFromField].GetValue() + " to structured comment ";
1497  const string& to_field = m_ArgList[kToField].GetValue();
1498  if (NStr::EqualNocase(to_field, "Field")) {
1499  if (m_ArgList[kStrCommField].GetShown()) {
1500  descr += "field '" + m_ArgList[kStrCommField].GetValue() + "'";
1501  }
1502  }
1503  else if (NStr::EqualNocase(to_field, "Database name")) {
1504  descr += "database name";
1505  }
1506  else if (NStr::EqualNocase(to_field, "Field name")) {
1507  descr += "field names";
1508  }
1510  return descr;
1511 }
1512 
1514 {
1516 }
1517 
1519 {
1521  return kEmptyStr;
1522 
1523  //get the source field
1524  string rt_var = "src";
1527  string src_resolve_fnc, src_var_name = path;
1528  NMItemData::WrapInQuotes(src_var_name);
1529 
1530  if (path.find(',') != NPOS) {
1531  vector<string> tokens;
1532  NStr::Split(path, ",", tokens);
1533 
1534  _ASSERT(tokens.size() == 2);
1535  src_resolve_fnc = NMItemData::GetResolveFuncForQual(tokens[0], tokens[1], rt_var, constraints);
1536 
1537  if (!src_resolve_fnc.empty()) {
1538  src_var_name = NMItemData::GetEditableFieldForPair(m_ArgList[kFromField].GetValue(), rt_var, false);
1539  NMItemData::WrapInQuotes(src_var_name);
1540  }
1541  }
1542 
1543  // get the destination field
1544  const string& to_field = m_ArgList[kToField].GetValue();
1545  string dest_field_name = (m_ArgList[kStrCommField].GetShown()) ? m_ArgList[kStrCommField].GetValue() : kEmptyStr;
1548 
1549  string function;
1550  function += src_resolve_fnc;
1551 
1552  if (x_ParseEntireText()) {
1553  // parse the entire text
1554 
1556  function += "(" + src_var_name + ", " + dest;
1557  if (!dest_field_name.empty()) {
1558  NMItemData::WrapInQuotes(dest_field_name);
1559  function += ", " + dest_field_name;
1560  }
1561  function += ", " + kCapChange + ", " + kExistingText;
1562  if (m_ArgList[kDelimiter].GetEnabled()) {
1563  function += ", " + kDelimiter;
1564  }
1565  function += ");";
1566 
1567  if (m_ArgList[kRmvParse].IsTrue()) {
1568  function += "\n";
1569  if (path.find(',') != NPOS) {
1570  function += CMacroFunction_RemoveModifier::GetFuncName();
1571  function += "(" + rt_var + ");";
1572  }
1573  else {
1575  function += "(" + src_var_name + ");";
1576  }
1577  }
1578  }
1579  else {
1580  string parsed_text = "text";
1581  function += x_GetParsedTextFunction(src_var_name, parsed_text);
1583  function += "(" + parsed_text + ", " + dest;
1584  if (!dest_field_name.empty()) {
1585  NMItemData::WrapInQuotes(dest_field_name);
1586  function += ", " + dest_field_name;
1587  }
1588  function += ", " + kCapChange + ", " + kExistingText;
1589  if (m_ArgList[kDelimiter].GetEnabled()) {
1590  function += ", " + kDelimiter;
1591  }
1592  function += ");";
1593  }
1594 
1595  return function;
1596 }
1597 
1599 {
1600  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_ParseToStructComm::GetFuncName(),
1601  CMacroFunction_RemoveModifier::GetFuncName(), CMacroFunction_RemoveQual::GetFuncName(),
1603 }
1604 
1606 {
1608 }
1609 
1610 
1611 
EMacroFieldType m_FieldType
for actions such as appply/edit/etc.
vector< string > GetFeatureTypes(bool for_removal=false, bool to_create=false, bool include_all=false) const
vector< string > GetRNATypes() const
string GetAsnPathToFieldName(const string &field, EMacroFieldType type, const string &target=kEmptyStr)
const vector< string > & GetParseToBsrcKeywords() const
static string s_GetGUIMappedStructCommField(const string &value)
const vector< string > & GetParseToCdsGeneProtKeywords() const
vector< string > GetncRNAClassTypes(bool include_any=true) const
static CMacroEditorContext & GetInstance()
vector< string > GetFeatQualifiers() const
const vector< string > & GetBsrcKeywords() const
vector< string > GetFieldNames(EMacroFieldType type) const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
virtual const vector< string > & GetKeywords() const
virtual vector< string > GetMainFunctions() const
virtual string GetFunction(TConstraints &constraints) const
virtual const vector< string > & GetKeywords() const
virtual vector< string > GetFunctionNames() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetMainFunctions() const
virtual vector< string > GetFunctionNames() const
virtual vector< string > GetMainFunctions() const
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual vector< string > GetFunctionNames() const
string x_GetParsedTextFunction(const string &src_field, const string &parsed_text) const
pair< string, string > x_GetResolveFuncForMultValQuals(const string &field, const string &rt_var, TConstraints &constraints, bool remove_constraint) const
virtual string GetFunction(TConstraints &constraints) const
string x_GetParsedTextDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetMainFunctions() const
pair< string, bool > m_IncludeLeft
CParseQualTreeItemData(const string &description, EMacroFieldType type)
virtual string GetMacroDescription() const
void x_GetParsedTextFncCore(string &parsed_fnc) const
pair< string, bool > m_IncludeRight
pair< string, bool > m_CaseSensitive
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual vector< string > GetMainFunctions() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual const vector< string > & GetKeywords() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetMainFunctions() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual const vector< string > & GetKeywords() const
virtual string GetFunction(TConstraints &constraints) const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetFunctionNames() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetMainFunctions() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() 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
bool Empty(const CNcbiOstrstream &src)
Definition: fileutil.cpp:523
string
Definition: cgiapp.hpp:687
static CTempString GetFuncName()
static const char * sm_SeqForFeat
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_SeqForDescr
class CMacroFunction_Sequence_For_Seqdesc SEQUENCE_FOR_SEQDESC(field_name) SEQUENCE_FOR_SEQFEAT(field...
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
#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 list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
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:5432
#define NPOS
Definition: ncbistr.hpp:133
static const string BoolToString(bool value)
Convert bool to string.
Definition: ncbistr.cpp:2806
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:5414
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
vector< macro::SArgMetaData > TArgumentsVector
USING_SCOPE(objects)
pair< string, string > GetResolveFuncForDestCdsGeneProtQuals(const string &fieldname, const string &rt_var, TConstraints &constraints, bool remove_constraint)
void UpdateConstraintsForDualCdsGeneProt(TConstraints &constraints, const string &src_feat)
void OnRemoveFromParsedField(CArgumentList &list, CArgument &arg)
void OnRightDigitsLettersInParsePanels(CArgumentList &list, CArgument &arg)
void OnLeftDigitsLettersInParsePanels(CArgumentList &list, CArgument &arg)
void OnStructCommFieldDblChanged(CArgumentList &list, CArgument &arg)
bool MultipleValuesAllowed(const string &field)
void UpdateConstraintsForFeatures(TConstraints &constraints, const string &feature)
EMacroFieldType GetSourceTypeInDoublePanel(const CArgumentList &arg_list, EDirType dir)
string GetResolveFuncForMultiValuedQual(const string &field, const string &rt_var, TConstraints &constraints, bool remove_constraint)
pair< string, string > GetResolveFuncForRNAQuals(const string &fieldname, const string &rt_var, TConstraints &constraints, bool remove_constraint)
string GetResolveFuncForQual(const string &container, const string &field, const string &rt_var, TConstraints &constraints, bool remove_constraint=true)
Generates the definition of rt_var based on input "field".
string GetUpdatemRNADescription(const CArgument &arg)
void AddConstraintIgnoreNewText(const string &field, TConstraints &constraints, const CArgumentList &arg_list, const string &target=kEmptyStr)
CTempString UpdateTargetForDualFeatures(const string &feature, const string &from_field)
pair< string, string > GetResolveFuncForSrcCdsGeneProtQuals(const string &fieldname, const string &rt_var, TConstraints &constraints, bool remove_constraint)
CTempString UpdateTargetForRnas(const string &rna_type)
void WrapInQuotes(string &str)
string GetEditableFieldForPair(const string &field, const string &rt_var, bool is_feature)
void OnProteinNameDouble(CArgumentList &list, CArgument &arg)
string GetCapitalizationTypeFromChoice(const string &cap_change)
pair< string, string > GetResolveFuncForDestFeatQuals(const string &feature, const string &field, const string &rt_var, TConstraints &constraints, bool remove_constraint)
pair< string, string > GetResolveFuncForSrcFeatQuals(const string &feature, const string &field, const string &rt_var, TConstraints &constraints, bool remove_constraint)
void OnExistingTextChanged(CArgumentList &list, CArgument &arg)
string GetHandleOldValue(const string &type)
void OnRnaTypeChanged(CArgumentList &list, CArgument &arg)
void UpdateConstraintsForRnas(TConstraints &constraints, const CArgumentList &arg_list)
string GetDelimiterChar(const string &del)
void UpdateFeatureType(string &feature, const string &field)
CTempString UpdateTargetForCdsGeneProt(const string &fieldname)
void OnProductDouble(CArgumentList &list, CArgument &arg)
void AppendUpdatemRNAFnc(bool update_mrna, string &function)
void GetFeatureAndField(const string &field_name, string &feature, string &field)
string GetExistingTextDescr(const CArgumentList &arg_list)
string GetUpdatemRNAVar(const CArgumentList &arg_list)
const string kJustAfter
const string kWholeWordParse
const string kDigitsRight
const string kLetterRight
const string kTextLeft
const string kRmvLeft
const string kToField
const string kUpTo
const string kFromField
const string kDigitsLeft
const string kCapChange
const string kLetterLeft
const string kRNAType
const string kncRNAClass
const TArgumentsVector & GetOptionalArgs()
const TArgumentsVector & GetParseArgs()
const string kExistingText
const string kDelLeft
const string kFeatType
const string kDelRight
const string kRmvParse
const TArgumentsVector & GetDualBsrcArgs()
const string kTextRight
const string kInclude
const string kRmvRight
const string kUpdatemRNA
const string kCaseInsensParse
const string kStartAt
const string kStrCommField
const string kDelimiter
const CharType(& source)[N]
Definition: pointer.h:1149
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
Definition: type.c:6
#define _ASSERT
Modified on Wed Sep 04 15:00:05 2024 by modify_doxy.py rev. 669887