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

Go to the SVN repository for this file.

1 /* $Id: macro_apply_itemdata.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: Andrea Asztalos
27 
28  */
29 
30 
31 #include <ncbi_pch.hpp>
37 
45 
51 #include <wx/msgdlg.h>
52 
55 USING_SCOPE(macro);
57 
58 namespace {
59  string GetExistingTextVariables(const CArgumentList& args)
60  {
61  string variables;
62  variables = kExistingText + " = \"" + NMItemData::GetHandleOldValue(args[kExistingText].GetValue()) + "\"";
63  if (args[kDelimiter].GetEnabled()) {
64  variables += "\n" + kDelimiter + " = \"" + NMItemData::GetDelimiterChar(args[kDelimiter].GetValue()) + "\"";
65  }
66  return variables;
67  }
68 }
69 
70 // CApplyQualTreeItemData
72  : CMacroActionItemData(description, type)
73 {
74 }
75 
77 {
79 
80  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
81  m_Panel->SetControlValues(kField, fieldnames);
82 
83  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
84 }
85 
87 {
88  string descr = "Apply '" + m_ArgList[kNewValue].GetValue() + "' to ";
90  descr += "publication ";
91  }
92  descr += m_ArgList[kField].GetValue();
94  return descr;
95 }
96 
98 {
99  string variables;
100  variables += kNewValue + " = %" + m_ArgList[kNewValue].GetValue() + "%\n";
101  variables += GetExistingTextVariables(m_ArgList);
102  return variables;
103 }
104 
106 {
107  if (m_ArgList[kField].Empty()) return kEmptyStr;
108 
109  string function = CMacroFunction_SetStringQual::GetFuncName();
110  function += "(\"" + CMacroEditorContext::GetInstance().GetAsnPathToFieldName(m_ArgList[kField].GetValue(), m_FieldType, m_Target) + "\", ";
111  function += kNewValue + ", " + kExistingText;
112  if (m_ArgList[kDelimiter].GetEnabled()) {
113  function += ", " + kDelimiter;
114  }
115  function += ");";
116  return function;
117 }
118 
120 {
122 }
123 
124 // CApplyProteinQualTreeItemData
126  : CApplyQualTreeItemData("Apply new value to protein (CDS product) fields", EMacroFieldType::eProtein)
127 {
128 }
129 
131 {
133  args.push_back(GetOptionalArgs()[2]);
134  x_LoadPanel(parent, "SetStringProteinQual", args);
135 
136  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
137  m_Panel->SetControlValues(kField, fieldnames);
138 
139  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
140  m_Panel->GetArgumentList().Attach(NMItemData::OnProteinNameSingle);
141 }
142 
144 {
147  return descr;
148 }
149 
151 {
152  string function;
153 
154  bool update_mrna = m_ArgList[kUpdatemRNA].GetEnabled() && m_ArgList[kUpdatemRNA].IsTrue();
157  // place the constraint in the Do section
158  string rt_var = "obj";
159  function = NMItemData::GetResolveFuncForMultiValuedQual(path, rt_var, constraints, !update_mrna);
160 
161  if (function.empty()) {
163  function += "(\"" + path + "\", ";
164  }
165  else {
167  function += "(" + rt_var + ", ";
168  }
169  }
170  else {
172  function += "(\"" + path + "\", ";
173  }
174 
175  function += kNewValue + ", " + kExistingText;
176  if (m_ArgList[kDelimiter].GetEnabled()) {
177  function += ", " + kDelimiter;
178  }
179  function += ");";
180 
181  NMItemData::AppendUpdatemRNAFnc(update_mrna, function);
182  return function;
183 }
184 
186 {
187  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_SetStringQual::GetFuncName(), CMacroFunction_UpdatemRNAProduct::GetFuncName() };
188 }
189 
190 // CApplyBsrcQualTreeItemData
192  : CApplyQualTreeItemData("Apply new value to biosource qualifiers", EMacroFieldType::eBiosourceTextAll)
193 {
194 }
195 
196 const vector<string>& CApplyBsrcQualTreeItemData::GetKeywords() const
197 {
199 }
200 
202 {
203  // Note - the order of the arguments is important when editing a macro
205  copy(GetSetArgs().begin(), GetSetArgs().end(), back_inserter(args));
207 
209  m_Panel->SetControlValues(kField, fieldnames);
210 
211  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
212 }
213 
215 {
216  string descr;
217  descr = "Apply ";
218 
220  switch (m_FieldType) {
222  descr += "location '" + m_ArgList[kNewValue].GetValue() + "'";
223  break;
225  descr += "origin '" + m_ArgList[kNewValue].GetValue() + "'";
226  break;
229  descr += "'" + m_ArgList[kNewValue].GetValue() + "' to " + m_ArgList[kField].GetValue();
230  break;
231  default:
232  LOG_POST(Error << "Wrong biosource type selection");
233  return kEmptyStr;
234  }
236  return descr;
237 }
238 
240 {
242  return kEmptyStr;
243  }
244 
245  string field_name = m_ArgList[kField].GetValue();
246  string function;
248  if (NMacroUtil::IsStructVoucherPart(field_name)) {
249  string rt_var = "obj";
250  bool found_constraint = false;
251  string resolve_func = NMItemData::GetResolveFuncForSVPart(field_name, rt_var, constraints, found_constraint);
252  if (found_constraint) {
253  function += resolve_func;
254  }
255 
256  auto pos = field_name.find_last_of('-');
258  if (found_constraint) {
259  function += "(" + rt_var + ", ";
260  }
261  else {
262  function += "(\"" + field_name.substr(0, pos) + "\", ";
263  }
264  function += "\"" + field_name.substr(pos + 1) + "\", ";
265  }
266  else if (path.find(',') != NPOS) {
267  vector<string> tokens;
268  NStr::Split(path, ",", tokens);
269 
270  _ASSERT(tokens.size() == 2);
271  // it is either an orgmod or a soubsource modifier
272  string rt_var = "obj";
273  function = NMItemData::GetResolveFuncForQual(tokens[0], tokens[1], rt_var, constraints);
274 
276  function += "(" + rt_var + ", \"" + tokens[0] + "\", \"" + tokens[1] + "\", ";
277  }
278  else {
280  function += "(\"" + path + "\", ";
281  }
282 
283  function += kNewValue + ", " + kExistingText;
284  if (m_ArgList[kDelimiter].GetEnabled()) {
285  function += ", " + kDelimiter;
286  }
287  function += ");";
288 
289  return function;
290 }
291 
293 {
294  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_ApplyStrucVoucherPart::GetFuncName(),
297 }
298 
299 
300 // CApplyMolinfoQualTreeItemData
302  : CApplyQualTreeItemData("Apply new value to molinfo qualifiers", EMacroFieldType::eMolinfo)
303 {
304 }
305 
307 {
308  x_LoadPanel(parent, "SetStringQualMolinfo", GetSetArgs());
309 
310  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
311  m_Panel->SetControlValues(kField, fieldnames);
312 
313  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
314 }
315 
317 {
318  string descr = "Apply '";
320  descr += "' to " + m_ArgList[kField].GetValue();
322  return descr;
323 }
324 
326 {
327  string variables;
328  variables += kNewValue + " = %" + CMacroEditorContext::GetInstance().GetAsnMolinfoValue(m_ArgList[kField].GetValue(), m_ArgList[kNewValue].GetValue()) + "%\n";
329  variables += GetExistingTextVariables(m_ArgList);
330  return variables;
331 }
332 
333 // CApplyDBLinkQualTreeItemData
335  : CApplyQualTreeItemData("Apply new value to DBLink fields", EMacroFieldType::eDBLink)
336 {
337 }
338 
340 {
341  x_LoadPanel(parent, "SetDBLinkStringQual", GetSetArgs());
342 
343  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
344  m_Panel->SetControlValues(kField, fieldnames);
345 
346  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
347 }
348 
350 {
352  // if there is relevant constraint, change the target
353  const string& field = m_ArgList[kField].GetValue();
354  for (auto& it : constraints) {
355  if (it.second.find(field) != NPOS) {
356  new_target = CMacroBioData::sm_DBLink;
357  break;
358  }
359  }
360  m_Target = new_target;
361 }
362 
364 {
365  string function;
367  string rt_var;
368  bool found_constraint = false;
369  function = NMItemData::GetResolveFuncForDBLink(m_ArgList[kField].GetValue(), rt_var, constraints, found_constraint);
370  function += CMacroFunction_SetStringQual::GetFuncName() + "(";
371  if (found_constraint) {
372  function += rt_var;
373  }
374  else {
375  function += "\"" + rt_var + ".data.strs\"";
376  }
377  }
378  else {
379  function = CMacroFunction_AddDBLink::GetFuncName() + "(";
380  function += "\"" + m_ArgList[kField].GetValue() + "\"";
381  }
382 
383  function += ", " + kNewValue + ", " + kExistingText;
384  if (m_ArgList[kDelimiter].GetEnabled()) {
385  function += ", " + kDelimiter;
386  }
387  function += ");";
388 
389  return function;
390 }
391 
393 {
394  return { CMacroFunction_Resolve::GetFuncName(), CMacroFunction_SetStringQual::GetFuncName(), CMacroFunction_AddDBLink::GetFuncName() };
395 }
396 
397 
398 // CApplyPubQualTreeItemData
400  : CApplyQualTreeItemData("Apply new value to publication fields", EMacroFieldType::ePubdesc)
401 {
402 }
403 
405 {
406  x_LoadPanel(parent, "SetStringQualMolinfo", GetSetArgs());
407 
408  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
409  m_Panel->SetControlValues(kField, fieldnames);
410 
411  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
412 }
413 
415 {
416  string variables;
417  const string field = m_ArgList[kField].GetValue();
420  try {
422  if (date && date->IsStd()) {
423  const auto& std_date = date->GetStd();
424  if (std_date.IsSetYear() && std_date.IsSetMonth() && std_date.IsSetDay()) {
425  variables = "year = %" + NStr::IntToString(std_date.GetYear()) + "%\n";
426  variables += "month = %" + NStr::IntToString(std_date.GetMonth()) + "%\n";
427  variables += "day = %" + NStr::IntToString(std_date.GetDay()) + "%";
428  }
429  }
430  }
431  catch (const CException&) {}
432  }
437  variables = kNewValue + " = %" + m_ArgList[kNewValue].GetValue() + "%";
438  } else {
440  }
441  return variables;
442 }
443 
445 {
446  string function;
447  const string field = m_ArgList[kField].GetValue();
448  if (field.empty()) return kEmptyStr;
449 
451  switch (type) {
453  return CMacroFunction_SetPubPMID::GetFuncName() + "(" + kNewValue + ");";
455  return CMacroFunction_SetPubDate::GetFuncName() + "(year, month, day);";
457  return CMacroFunction_SetPubDateField::GetFuncName() + "(\"year\"," + kNewValue + ");";
459  return CMacroFunction_SetPubDateField::GetFuncName() + "(\"month\"," + kNewValue + ");";
461  return CMacroFunction_SetPubDateField::GetFuncName() + "(\"day\"," + kNewValue + ");";
463  return CMacroFunction_SetPubStatus::GetFuncName() + "(" + kNewValue + ");";
466  default:
467  break;
468  }
469 
471  string rt_var;
472  function = NMItemData::GetResolveFuncForPubQual(field, rt_var, constraints);
473  function += CMacroFunction_SetPubTitle::GetFuncName() + "(" + rt_var + ", ";
474  }
479  string rt_var = "obj";
480  function = NMItemData::GetResolveFuncForApplyAuthors(type, rt_var, constraints);
481 
483  function += "(" + rt_var + ", \"" + CMacroEditorContext::GetInstance().GetAsnPathToAuthorFieldName(field) + "\", ";
484  }
486  string rt_var = "obj";
487  function = NMItemData::GetResolveFuncForApplyAuthors(type, rt_var, constraints);
488 
489  function += CMacroFunction_SetPubAuthorMI::GetFuncName();
490  function += "(" + rt_var + ", ";
491  }
494  }
497  }
500  }
503  }
505  function = CMacroFunction_SetSerialNumber::GetFuncName() + "(";
506  }
508  function = CMacroFunction_SetPubCitation::GetFuncName() + "(";
509  }
510  else {
513  }
514 
515  function += kNewValue + ", " + kExistingText;
516  if (m_ArgList[kDelimiter].GetEnabled()) {
517  function += ", " + kDelimiter;
518  }
519  function += ");";
520  return function;
521 }
522 
524 {
525  vector<string> funcs{ CMacroFunction_SetPubPMID::GetFuncName(),
532  CMacroFunction_SetPubAuthorMI::GetFuncName(),
537  CMacroFunction_SetSerialNumber::GetFuncName(),
538  CMacroFunction_SetPubCitation::GetFuncName(),
540  };
541 
543  auto pub_fncs = x_GetPubFunctions();
544  funcs.reserve(funcs.size() + pub_fncs.size());
545  funcs.insert(funcs.end(), pub_fncs.begin(), pub_fncs.end());
546  }
547  return funcs;
548 }
549 
550 
552  : CMacroActionItemData("Apply new value to publication authors", EMacroFieldType::ePubAuthors)
553 {
555 }
556 
558 {
559  x_LoadPanel(parent, "AddAuthors", { GetSetArgs()[2] });
560  m_AuthorsPanel = dynamic_cast<CMacroAuthorNamesPanel*>(m_Panel->LoadCustomPanel(m_Type));
561 }
562 
564 {
565  string res;
566  if (!get<0>(names).empty()) {
567  if (!get<1>(names).empty()) { // first name
568  res += get<1>(names);
569  }
570  if (!get<2>(names).empty()) {
571  if (!res.empty())
572  res += " ";
573  res += get<2>(names);
574  }
575  if (!res.empty())
576  res += " ";
577  res += get<0>(names);
578 
579  if (!get<3>(names).empty()) {
580  res += " " + get<3>(names);
581  }
582  res = "'" + res + "'";
583  }
584  return res;
585 }
586 
588 {
589  string descr;
591  for (auto& it : authors) {
592  string author_name = s_GetNameForDescription(it);
593  if (author_name.empty())
594  continue;
595 
596  if (!descr.empty())
597  descr += ", ";
598  descr += author_name;
599  }
600  descr = "Apply " + descr + " to publication authors (";
601 
602  string existing_text = m_ArgList[kExistingText].GetValue();
603  if (NStr::EqualNocase(existing_text, "overwrite")) {
604  descr += "overwrite existing text";
605  }
606  else if (NStr::StartsWith(existing_text, "ignore", NStr::eNocase)) {
607  descr += "ignore new text when existing text is present";
608  }
609  else {
610  NStr::ToLower(existing_text);
611  descr += existing_text;
612  }
613  descr += ")";
614  return descr;
615 }
616 
618 {
619  string variables;
620  m_NumAuthors = 0;
622  for (unsigned int i = 0; i < authors.size(); ++i) {
623  string nr = NStr::IntToString(i + 1);
624  if (get<0>(authors[i]).empty()) {
625  continue;
626  }
627  variables += kLast + nr + " = %" + get<0>(authors[i]) + "%\n";
628  variables += kFirst + nr + " = %" + get<1>(authors[i]) + "%\n";
629  variables += kMiddle + nr + " = %" + get<2>(authors[i]) + "%\n";
630  variables += kSuffix + nr + " = %" + get<3>(authors[i]) + "%\n";
631  m_NumAuthors++;
632  }
633  if (!variables.empty()) {
634  variables.pop_back();
635  }
636  return variables;
637 }
638 
639 static string s_GetAddAuthorFunction(const string& nr, const string& existing_text)
640 {
642  func += "(" + CTempString(kLast) + nr + ", " + CTempString(kFirst) + nr + ", " + CTempString(kMiddle) + nr + ", " + CTempString(kSuffix) + nr;
643  func += ", \"" + NMItemData::GetHandleOldValue(existing_text) + "\");";
644  return func;
645 }
646 
648 {
649  if (m_NumAuthors == 0) return kEmptyStr;
650 
651  string function;
652  const string& existing_text = m_ArgList[kExistingText].GetValue();
653  if (NStr::EqualNocase(existing_text, "overwrite")) {
654  function = s_GetAddAuthorFunction(NStr::IntToString(1), existing_text);
655  for (unsigned i = 1; i < m_NumAuthors; ++i) {
656  if (!function.empty()) function += "\n";
657  function += s_GetAddAuthorFunction(NStr::IntToString(i+1), "append");
658  }
659  }
660  else if (NStr::EqualNocase(existing_text, "append")
661  || NStr::EqualNocase(existing_text, "prefix")) {
662  for (unsigned i = 0; i < m_NumAuthors; ++i) {
663  if (!function.empty()) function += "\n";
664  function += s_GetAddAuthorFunction(NStr::IntToString(i + 1), existing_text);
665  }
666  }
667  return function;
668 }
669 
671 {
673 }
674 
675 bool CApplyAuthorsTreeItemData::SetData(const vector<CFuncWithArgs>& func_info)
676 {
677  CAuth_list auth_list;
678  for (const auto& fn_it : func_info) {
679  CRef<CAuthor> author(new CAuthor);
680  const auto& args = fn_it.m_FArgs;
681  auto last_it = args.find(kLast);
682  if (last_it != args.end()) {
683  author->SetName().SetName().SetLast(last_it->second);
684  }
685  auto first_it = args.find(kFirst);
686  if (first_it != args.end()) {
687  author->SetName().SetName().SetFirst(first_it->second);
688  }
689  auto mi_it = args.find(kMiddle);
690  if (mi_it != args.end()) {
691  const string middle_init = mi_it->second;
692 
693  string initials = macro::CMacroFunction_AuthorFix::s_GetFirstNameInitials(author->GetName().GetName().GetFirst());
694  if (!NStr::IsBlank(middle_init)) {
695  initials.append(middle_init);
696  }
697  // don't add another period if one is already there
698  if (!NStr::EndsWith(initials, ".")) {
699  initials.append(".");
700  }
701  author->SetName().SetName().SetInitials(initials);
702  }
703  auto suffix_it = args.find(kSuffix);
704  if (suffix_it != args.end()) {
705  author->SetName().SetName().SetSuffix(suffix_it->second);
706  }
707  auth_list.SetNames().SetStd().push_back(author);
708  }
709 
710  m_AuthorsPanel->SetAuthors(auth_list);
711  return true;
712 }
713 
714 // CApplyStrCommQualTreeItemData
716  : CApplyQualTreeItemData("Apply new value to structured comment fields", EMacroFieldType::eStructComment)
717 {
718 }
719 
721 {
723  args.push_back(GetOptionalArgs()[5]);
724  x_LoadPanel(parent, "SetStringStrCommQual", args);
725 
726  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
727  m_Panel->SetControlValues(kField, fieldnames);
728  m_Panel->SetSelection(kField, 0);
729 
730  m_Panel->GetArgumentList().Attach(NMItemData::OnStructCommFieldChanged);
731  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
732 }
733 
735 {
736  string descr = "Apply '" + m_ArgList[kNewValue].GetValue() + "' to ";
739  return descr;
740 }
741 
743 {
744  string variables = CApplyQualTreeItemData::GetVariables();
745  if (NStr::EqualNocase(m_ArgList[kField].GetValue().get(), "Field") && m_ArgList[kStrCommField].GetShown()) {
746  variables += "\n" + kStrCommField + " = %" + m_ArgList[kStrCommField].GetValue() + "%";
747  }
748  return variables;
749 }
750 
752 {
753  string function;
754  string rt_var = "obj";
755  string field = m_ArgList[kField].GetValue();
756  if (NStr::EqualNocase(field, "Field")) {
757  function += CMacroFunction_SetStructCommField::GetFuncName();
758  function += "(" + kStrCommField + ", ";
759  }
760  else if (NStr::EqualNocase(field, "Database name")) {
762  function += "(";
763  }
764  else if (NStr::EqualNocase(field, "Field name")) {
765  function = NMItemData::GetResolveFuncForStrCommQual(field, kEmptyStr, rt_var, constraints);
767  function += "(\"" + rt_var + ".label.str\", ";
768  }
769 
770  function += kNewValue + ", " + kExistingText;
771  if (m_ArgList[kDelimiter].GetEnabled()) {
772  function += ", " + kDelimiter;
773  }
774  function += ");";
775  return function;
776 }
777 
779 {
780  return { CMacroFunction_SetStructCommField::GetFuncName(),
783  macro::CMacroFunction_Resolve::GetFuncName()
784  };
785 }
786 
787 // CApplyStructCommentTreeItemData
789  : CMacroActionItemData("Apply new structured comment"), m_Seqdesc(new CSeqdesc)
790 {
792 }
793 
795 {
796  TArgumentsVector args;
797  x_LoadPanel(parent, "AddStructuredComment", args);
798  m_StructCommentPanel = dynamic_cast<CStructuredCommentPanel*>(m_Panel->LoadCustomPanel(m_Type));
799 }
800 
802 {
803  CRef<CSeqdesc> desc(new CSeqdesc);
805  if (desc && desc->IsUser()) {
806  desc->SetUser().SetType().SetStr("StructuredComment");
807  }
808 
810  return "Apply new structured comment with '" + prefix + "' database name";
811 }
812 
813 static string s_GetFieldVar(unsigned int n)
814 {
815  static const char* s_field = "strcomm_field";
816  return s_field + NStr::UIntToString(n);
817 }
818 
819 static string s_GetValueVar(unsigned int n)
820 {
821  static const char* s_value = "new_value";
822  return s_value + NStr::UIntToString(n);
823 }
824 
826 {
827  string variables;
828  m_Index = 0;
829  m_Seqdesc.Reset(new CSeqdesc);
831  if (m_Seqdesc && m_Seqdesc->IsUser()) {
832  m_Seqdesc->SetUser().SetType().SetStr("StructuredComment");
833  }
834 
835  for (auto& it : m_Seqdesc->GetUser().GetData()) {
836  if (it->IsSetData() && it->GetData().IsStr() &&
837  it->IsSetLabel() && it->GetLabel().IsStr()) {
838  string fieldname = it->GetLabel().GetStr();
839 
842  string value = it->GetData().GetStr();
843  if (!variables.empty()) {
844  variables += "\n";
845  }
846  variables += s_GetFieldVar(++m_Index) + " = %" + fieldname + "%\n";
847  variables += s_GetValueVar(m_Index) + " = %" + value + "%";
848  }
849  }
850  }
851  return variables;
852 }
853 
855 {
856  string function;
858  if (prefix.empty()) return kEmptyStr;
859 
860  string rt_var = "obj";
861  function = rt_var + " = " + CMacroFunction_SetStructCommDb::GetFuncName();
862  function += "(\"" + prefix + "\", \"eAddQual\");";
863 
864  for (unsigned int i = 1; i <= m_Index; ++i) {
865  function += "\n" + CMacroFunction_SetStructCommField::GetFuncName();
866  function += "(" + rt_var + ", " + s_GetFieldVar(i) + ", " + s_GetValueVar(i) + ", \"eReplace\");";
867  }
868  return function;
869 }
870 
872 {
873  return { CMacroFunction_SetStructCommDb::GetFuncName(), CMacroFunction_SetStructCommField::GetFuncName() };
874 }
875 
876 bool CApplyStructCommentTreeItemData::SetData(const vector<CFuncWithArgs>& func_info)
877 {
879  return false;
880 
881  string dbname;
882  for (const auto& fn_it : func_info) {
884  auto dbname_it = fn_it.m_FArgs.find(kNewValue);
885  if (dbname_it != fn_it.m_FArgs.end()) {
886  dbname = dbname_it->second;
888  }
889  }
890  }
891 
892  CSeqdesc strcomm;
893  auto& user_obj = strcomm.SetUser();
894  user_obj.SetType().SetStr("StructuredComment");
895  if (!dbname.empty()) {
897  }
898 
899  for (const auto& fn_it : func_info) {
900  const auto& args = fn_it.m_FArgs;
901  if (NStr::EqualNocase(fn_it.m_FName, CMacroFunction_SetStructCommField::GetFuncName())) {
902  auto field_it = args.find(kStrCommField);
903  auto value_it = args.find(kNewValue);
904  if (field_it != args.end() && value_it != args.end()) {
905  string field_name = field_it->second;
906  string field_value = value_it->second;
909  if (dbname.empty()) {
911  user_obj.AddField(field_name, field_value);
912  }
913  }
914  else {
915  user_obj.AddField(field_name, field_value);
916  }
917  }
918  }
919  }
920 
921  if (!dbname.empty()) {
923  }
924 
926  return true;
927 }
928 
929 //CApplyFeatQualTreeItemData
931  : CApplyQualTreeItemData("Apply new value to feature qualifiers", EMacroFieldType::eFeatQualifiers)
932 {
933 }
934 
936 {
937  TArgumentsVector args(GetOptionalArgs().begin(), GetOptionalArgs().begin() + 3);
938  copy(GetSetArgs().begin() + 1, GetSetArgs().end(), back_inserter(args));
939  x_LoadPanel(parent, "SetStringFeatQual", args);
940 
941  vector<string> features = CMacroEditorContext::GetInstance().GetFeatureTypes();
942  m_Panel->SetControlValues(kFeatType, features);
943  vector<string> qualifiers = CMacroEditorContext::GetInstance().GetFeatQualifiers();
944  m_Panel->SetControlValues(kFeatQual, qualifiers);
945 
946  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
947  m_Panel->GetArgumentList().Attach(NMItemData::OnProteinNameSingle);
948 }
949 
951 {
953  bool modified = (new_target != m_Target);
954  m_Target = new_target;
955  m_SelectedField = m_ArgList[kFeatType].GetValue();
956  return modified;
957 }
958 
960 {
961  string descr;
962  descr = "Apply '" + m_ArgList[kNewValue].GetValue();
963  descr += "' to " + m_ArgList[kFeatType].GetValue() + " " + m_ArgList[kFeatQual].GetValue();
966  return descr;
967 }
968 
970 {
972 
973  string function;
974  bool update_mrna = m_ArgList[kUpdatemRNA].GetEnabled() && m_ArgList[kUpdatemRNA].IsTrue();
976 
979  string gene_field = m_ArgList[kFeatQual].GetValue();
980  NStr::ReplaceInPlace(gene_field, "-", " ");
981  if (!NStr::StartsWith(gene_field, "gene ")) {
982  gene_field = "gene " + gene_field;
983  }
985  NMItemData::WrapInQuotes(gene_field);
986  function += "(\"gene\", " + gene_field + ", ";
987  }
988  else {
990  // place the constraint in the Do section
991  string rt_var = "obj";
992  function = NMItemData::GetResolveFuncForMultiValuedQual(path, rt_var, constraints, !update_mrna);
993 
994  if (function.empty()) {
996  function += "(\"" + path + "\", ";
997  }
998  else {
1000  function += "(" + rt_var + ", ";
1001  }
1002  }
1003  else if (path.find(',') != NPOS) {
1004  vector<string> tokens;
1005  NStr::Split(path, ",", tokens);
1006 
1007  _ASSERT(tokens.size() == 2);
1008  string rt_var = "obj";
1010  function = NMItemData::GetResolveFuncForQual(tokens[0], m_ArgList[kFeatQual].GetValue(), rt_var, constraints);
1011 
1012  function += macro::CMacroFunction_AddorSetGbQual::GetFuncName();
1013  function += "(" + rt_var + ", \"" + tokens[0] + "\", \"" + m_ArgList[kFeatQual].GetValue() + "\", ";
1014  }
1015  else {
1016  function = NMItemData::GetResolveFuncForQual(tokens[0], tokens[1], rt_var, constraints);
1017 
1019  function += "(" + rt_var + ", \"" + tokens[0] + "\", \"" + tokens[1] + "\", ";
1020  }
1021  }
1022  else {
1024  function += "(\"" + path + "\", ";
1025  }
1026  }
1027 
1028  function += kNewValue + ", " + kExistingText;
1029  if (m_ArgList[kDelimiter].GetEnabled()) {
1030  function += ", " + kDelimiter;
1031  }
1032  function += ");";
1033 
1034  NMItemData::AppendUpdatemRNAFnc(update_mrna, function);
1035  return function;
1036 }
1037 
1039 {
1040  return { CMacroFunction_Resolve::GetFuncName(),
1044  CMacroFunction_UpdatemRNAProduct::GetFuncName()
1045  };
1046 }
1047 
1048 // CApplyRNAQualTreeItemData
1050  : CApplyQualTreeItemData("Apply new value to RNA qualifiers", EMacroFieldType::eRNA)
1051 {
1052 }
1053 
1055 {
1056  TArgumentsVector args(GetSetArgs());
1057  args.push_back(GetOptionalArgs()[3]);
1058  args.push_back(GetOptionalArgs()[4]);
1059  x_LoadPanel(parent, "SetStringRnaQual", args);
1060 
1061  vector<string> rnas = CMacroEditorContext::GetInstance().GetRNATypes();
1062  m_Panel->SetControlValues(kRNAType, rnas);
1063  m_Panel->SetSelection(kRNAType, 0);
1064  vector<string> class_types = CMacroEditorContext::GetInstance().GetncRNAClassTypes();
1065  m_Panel->SetControlValues(kncRNAClass, class_types);
1066  vector<string> fieldnames = CMacroEditorContext::GetInstance().GetFieldNames(m_FieldType);
1067  m_Panel->SetControlValues(kField, fieldnames);
1068 
1069  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
1070  m_Panel->GetArgumentList().Attach(NMItemData::OnRnaTypeChanged);
1071 }
1072 
1074 {
1076  bool modified = (new_target != m_Target);
1077  m_Target = new_target;
1078  m_SelectedField = m_ArgList[kRNAType].GetValue();
1079  return modified;
1080 }
1081 
1083 {
1084  string descr;
1085  descr = "Apply '" + m_ArgList[kNewValue].GetValue() + "' to";
1086  if (m_ArgList[kncRNAClass].GetEnabled() && !m_ArgList[kncRNAClass].Empty()) {
1087  descr += " " + m_ArgList[kncRNAClass].GetValue();
1088  }
1089  descr += " " + m_ArgList[kRNAType].GetValue() + " " + m_ArgList[kField].GetValue();
1091  return descr;
1092 }
1093 
1095 {
1097 
1098  string function;
1099  string field = m_ArgList[kField].GetValue();
1100  if (field.empty())
1101  return kEmptyStr;
1102 
1103  if (m_ArgList[kRNAType].GetValue().get() == "tRNA" && NMacroUtil::StringsAreEquivalent(field, "codons recognized")) {
1104  function = CMacroFunction_SetCodonsRecognized::GetFuncName();
1105  function += "(" + kNewValue + ");";
1106  return function;
1107  }
1108 
1109  if (NStr::StartsWith(field, "gene")) {
1111  NMItemData::WrapInQuotes(gene_field);
1113  function += "(\"gene\", " + gene_field + ", ";
1114  } else {
1115  string path = CMacroEditorContext::GetInstance().GetAsnPathToFieldName(m_ArgList[kRNAType].GetValue() + " " + field, m_FieldType);
1116  if (path.empty())
1117  // ncRNA class when RNA is not ncRNA
1118  // codons recognized when RNA is not tRNA
1119  return kEmptyStr;
1120 
1121  if (path.find(',') != NPOS) {
1122  vector<string> tokens;
1123  NStr::Split(path, ",", tokens);
1124 
1125  _ASSERT(tokens.size() == 2);
1126  string rt_var = "obj";
1127  function = NMItemData::GetResolveFuncForQual(tokens[0], tokens[1], rt_var, constraints);
1128 
1130  function += "(" + rt_var + ", \"" + tokens[0] + "\", \"" + tokens[1] + "\", ";
1131  }
1132  else if (path.find("::") != NPOS) {
1133  function = CMacroFunction_SetRnaProduct::GetFuncName();
1134  function += "(";
1135  }
1136  else {
1138  function += "(\"" + path + "\", ";
1139  }
1140  }
1141 
1142  function += kNewValue + ", " + kExistingText;
1143  if (m_ArgList[kDelimiter].GetEnabled()) {
1144  function += ", " + kDelimiter;
1145  }
1146  function += ");";
1147  return function;
1148 }
1149 
1151 {
1153  CMacroFunction_Resolve::GetFuncName(),
1155  CMacroFunction_SetRnaProduct::GetFuncName(),
1157  CMacroFunction_SetCodonsRecognized::GetFuncName()
1158  };
1159 }
1160 
1161 
1162 namespace {
1163 
1164  string GetGeneDescr(const CArgumentList& args)
1165  {
1166  if (!args[kGeneLocus].GetShown())
1167  return kEmptyStr;
1168 
1169  string descr;
1170  if (!args[kGeneLocus].Empty() || !args[kGeneDescr].Empty()) {
1171  descr += ", apply gene with ";
1172  if (!args[kGeneLocus].Empty()) {
1173  descr += "'" + args[kGeneLocus].GetValue() + "' gene locus ";
1174  }
1175  if (!args[kGeneDescr].Empty()) {
1176  descr += "'" + args[kGeneDescr].GetValue() + "' gene description";
1177  }
1178  }
1179  return descr;
1180  }
1181 
1182  string GetQualifierDescription(const CArgumentList& args, const string& qual, const string& val)
1183  {
1184  if (!args[qual].Empty()) {
1185  return " with '" + args[val].GetValue() + "' " + args[qual].GetValue();
1186  }
1187  return kEmptyStr;
1188  }
1189 
1190  string GetFeatLocation(const CArgumentList& args, const string& rt_var)
1191  {
1192  string loc_fnc = rt_var + " = ";
1193  if (args[kWholeSeq].IsTrue()) {
1195  }
1196  else {
1198  if (!args[kFromCoord].Empty() && !args[kToCoord].Empty()) {
1199  int from = NStr::StringToInt(args[kFromCoord].GetValue().get());
1200  int to = NStr::StringToInt(args[kToCoord].GetValue().get());
1201  if (from <= 0 || to <= 0 || from > to)
1202  return kEmptyStr;
1203 
1204  loc_fnc += "(" + args[kFromCoord].GetValue() + ", " + args[kToCoord].GetValue() + ", ";
1205  }
1206  }
1207  loc_fnc += kPartial5 + ", " + kPartial3 + ", " + kStrand + ");\n";
1208  return loc_fnc;
1209  }
1210 
1211  string GetQualifierForFunction(const CArgumentList& args, const string& qual, const string& val)
1212  {
1213  if (args[val].Empty())
1214  return kEmptyStr;
1215 
1216  const string feat_name = args[kFeatureType].GetValue();
1217  const string qualifier = args[qual].GetValue();
1218  if (NStr::EqualNocase(feat_name, "gene")) {
1219  if (qualifier == "allele") {
1220  return ", \"data.gene.allele\", " + val;
1221  }
1222  else if (qualifier == "gene_synonym") {
1223  return ", \"data.gene.syn\", " + val;
1224  }
1225  else if (qualifier == "locus_tag") {
1226  return ", \"data.gene.locus-tag\", " + val;
1227  }
1228  }
1229 
1230  return ", \"qual.qual\", \"" + qualifier + "\", \"qual.val\", " + val;
1231  }
1232 
1233  string GetApplyGeneFunction(const CArgumentList& args, const string& rt_var)
1234  {
1235  string applygene_func = CMacroFunction_ApplyGene::GetFuncName();
1236  applygene_func += "(" + rt_var;
1237  if (args[kGeneLocus].GetShown() && !args[kGeneLocus].Empty()) {
1238  applygene_func += ", \"data.gene.locus\", " + kGeneLocus;
1239  }
1240  if (args[kGeneDescr].GetShown() && !args[kGeneDescr].Empty()) {
1241  applygene_func += ", \"data.gene.desc\", " + kGeneDescr;
1242  }
1243  applygene_func += ");";
1244  return applygene_func;
1245  }
1246 }
1247 
1248 // CAddRNAFeatTreeItemData
1250  : CMacroActionItemData("Apply RNA feature to nucleotide sequences")
1251 {
1252 }
1253 
1255 {
1257 
1258  vector<string> fields = CMacroEditorContext::GetInstance().GetRNATypes();
1259  fields.erase(fields.begin());
1260  m_Panel->SetControlValues(kRNAType, fields);
1262  m_Panel->SetControlValues(kncRNAClass, fields);
1263 
1264  // select rRNA by default
1265  m_Panel->SetSelection(kRNAType, 3);
1267  m_Panel->SetControlValues(kRnaName, fields);
1268 
1269  m_Panel->GetArgumentList().Attach(NMItemData::OnRnaTypeChanged);
1270  m_Panel->GetArgumentList().Attach(NMItemData::OnControlsAddRNAPanelSelected);
1271 }
1272 
1274 {
1275  string descr = "Apply '" + m_ArgList[kRnaName].GetValue() + "'";
1276  if (m_ArgList[kncRNAClass].GetEnabled() && !m_ArgList[kncRNAClass].Empty()) {
1277  descr += " " + m_ArgList[kncRNAClass].GetValue();
1278  }
1279  descr += " " + m_ArgList[kRNAType].GetValue() + " feature";
1280  descr += GetGeneDescr(m_ArgList);
1281  return descr;
1282 }
1283 
1285 {
1286  string vars = x_GetVariables({ kPartial5, kPartial3, kStrand });
1287  if (m_ArgList[kInterval].IsTrue() &&
1288  !m_ArgList[kFromCoord].Empty() &&
1289  !m_ArgList[kToCoord].Empty()) {
1290  vars += x_GetVariables({ kFromCoord, kToCoord });
1291  }
1292  vars += x_GetVariables({ kRnaName, kAddRedundant });
1293  if (m_ArgList[kGeneLocus].GetShown() && !m_ArgList[kGeneLocus].Empty()) {
1294  vars += x_GetVariables({ kGeneLocus });
1295  }
1296  if (m_ArgList[kGeneDescr].GetShown() && !m_ArgList[kGeneDescr].Empty()) {
1297  vars += x_GetVariables({ kGeneDescr });
1298  }
1299  vars.pop_back();
1300  return vars;
1301 }
1302 
1304 {
1305  const string rt_var = "location";
1306  string function = GetFeatLocation(m_ArgList, rt_var);
1307  if (function.empty())
1308  return kEmptyStr;
1309 
1311  function += "(\"" + m_ArgList[kRNAType].GetValue() + "\", " + kRnaName + ", " + rt_var + ", " + kAddRedundant;
1312 
1313  if (m_ArgList[kRNAType].GetValue() == "ncRNA" && m_ArgList[kncRNAClass].GetEnabled()) {
1314  function += ", \"data.rna.ext.gen.class\", \"" + m_ArgList[kncRNAClass].GetValue() + "\"";
1315  }
1316 
1317  if (!m_ArgList[kComment].Empty()) {
1318  function += ", \"comment\", \"" + m_ArgList[kComment].GetValue() + "\"";
1319  }
1320  function += ");";
1321 
1322  string applygene_func = GetApplyGeneFunction(m_ArgList, rt_var);
1323  if (applygene_func.find(",") != NPOS) {
1324  function += "\n" + applygene_func;
1325 
1326  if (!m_ArgList[kAddRedundant].IsTrue()) {
1327  string constraint = CMacroFunction_NumberOfFeatures::GetFuncName();
1328  constraint += "(\"" + m_ArgList[kRNAType].GetValue() + "\") = 0";
1329  constraints.insert(constraints.begin(), make_pair(kEmptyStr, constraint));
1330  }
1331  }
1332  return function;
1333 }
1334 
1336 {
1341 }
1342 
1343 
1344 // CAddCDSFeatTreeItemData
1346  : CMacroActionItemData("Apply CDS feature to nucleotide sequences")
1347 {
1348 }
1349 
1351 {
1353 }
1354 
1356 {
1357  string descr = "Apply cds feature with '" + m_ArgList[kProteinName].GetValue() + "' product name";
1358  if (m_ArgList[kAddmRNA].IsTrue()) {
1359  descr += "(add mRNA)";
1360  }
1361  else {
1362  descr += "(do not add mRNA)";
1363  }
1364  descr += GetGeneDescr(m_ArgList);
1365  return descr;
1366 }
1367 
1369 {
1370  string vars = x_GetVariables({ kPartial5, kPartial3, kStrand });
1371  if (m_ArgList[kInterval].IsTrue() &&
1372  !m_ArgList[kFromCoord].Empty() &&
1373  !m_ArgList[kToCoord].Empty()) {
1374  vars += x_GetVariables({ kFromCoord, kToCoord });
1375  }
1377  if (m_ArgList[kCodonStart].GetValue().get() == "Best") {
1378  vars += kCodonStart + " = \"best\"\n";
1379  }
1380  else {
1381  vars += kCodonStart + " = " + m_ArgList[kCodonStart].GetValue() + "\n";
1382  }
1383  if (!m_ArgList[kGeneLocus].Empty()) {
1384  vars += x_GetVariables({ kGeneLocus });
1385  }
1386  if (!m_ArgList[kGeneDescr].Empty()) {
1387  vars += x_GetVariables({ kGeneDescr });
1388  }
1389  vars.pop_back();
1390  return vars;
1391 }
1392 
1394 {
1395  const string rt_var = "location";
1396  string function = GetFeatLocation(m_ArgList, rt_var);
1397  if (function.empty())
1398  return kEmptyStr;
1399 
1401  function += "(" + kProteinName + ", " + kProteinDescr;
1402  function += ", " + kCodonStart + ", " + rt_var;
1403  function += ", " + kAddRedundant + ", " + kAddmRNA;
1404 
1405  if (!m_ArgList[kComment].Empty()) {
1406  function += ", \"comment\", \"" + m_ArgList[kComment].GetValue() + "\"";
1407  }
1408  function += ");";
1409 
1410  string applygene_func = GetApplyGeneFunction(m_ArgList, rt_var);
1411  if (applygene_func.find(",") != NPOS) {
1412  function += "\n" + applygene_func;
1413 
1414  if (!m_ArgList[kAddRedundant].IsTrue()) {
1415  string constraint = CMacroFunction_NumberOfFeatures::GetFuncName();
1416  constraint += "(\"cds\") = 0";
1417  constraints.insert(constraints.begin(), make_pair(kEmptyStr, constraint));
1418  }
1419  }
1420  return function;
1421 }
1422 
1424 {
1429 }
1430 
1431 
1432 // CAddFeatureTreeItemData
1434  : CMacroActionItemData("Apply feature to nucleotide sequences", EMacroFieldType::eFeatQualifiers)
1435 {
1436 }
1437 
1439 {
1442 
1443  bool for_removal = false, to_create = true;
1444  vector<string> features = CMacroEditorContext::GetInstance().GetFeatureTypes(for_removal, to_create);
1445  m_Panel->SetControlValues(kFeatureType, features);
1446 }
1447 
1449 {
1450  string descr = "Apply " + m_ArgList[kFeatureType].GetValue() + " feature";
1451  descr += GetQualifierDescription(m_ArgList, kAddFeatQual1, kAddFeatVal1);
1452  descr += GetQualifierDescription(m_ArgList, kAddFeatQual2, kAddFeatVal2);
1453  descr += GetQualifierDescription(m_ArgList, kAddFeatQual3, kAddFeatVal3);
1454  descr += GetQualifierDescription(m_ArgList, kAddFeatQual4, kAddFeatVal4);
1455  descr += GetGeneDescr(m_ArgList);
1456  return descr;
1457 }
1458 
1460 {
1461  string vars = x_GetVariables({ kPartial5, kPartial3, kStrand });
1462  if (m_ArgList[kInterval].IsTrue() &&
1463  !m_ArgList[kFromCoord].Empty() &&
1464  !m_ArgList[kToCoord].Empty()) {
1465  vars += x_GetVariables({ kFromCoord, kToCoord });
1466  }
1467 
1468  vector<CTempString> args;
1469  if (!m_ArgList[kAddFeatVal1].Empty()) {
1470  args.push_back(kAddFeatVal1);
1471  }
1472  if (!m_ArgList[kAddFeatVal2].Empty()) {
1473  args.push_back(kAddFeatVal2);
1474  }
1475  if (!m_ArgList[kAddFeatVal3].Empty()) {
1476  args.push_back(kAddFeatVal3);
1477  }
1478  if (!m_ArgList[kAddFeatVal4].Empty()) {
1479  args.push_back(kAddFeatVal4);
1480  }
1481  if (!m_ArgList[kGeneLocus].Empty()) {
1482  args.push_back(kGeneLocus);
1483  }
1484  if (!m_ArgList[kGeneDescr].Empty()) {
1485  args.push_back(kGeneDescr);
1486  }
1487  vars += x_GetVariables(args);
1488  vars += x_GetVariables({ kAddRedundant });
1489  vars.pop_back();
1490  return vars;
1491 }
1492 
1494 {
1495  const string rt_var = "location";
1496  string function = GetFeatLocation(m_ArgList, rt_var);
1497  if (function.empty())
1498  return kEmptyStr;
1499 
1500  const string feat_type = m_ArgList[kFeatureType].GetValue();
1501  bool feat_is_gene = NStr::EqualNocase(feat_type, "gene");
1503  string asn_path_to_feature;
1504  if (feat_is_gene) {
1505  if (!m_ArgList[kGeneLocus].Empty()) {
1506  asn_path_to_feature = "\"data.gene.locus\", " + kGeneLocus;
1507  }
1508  else if (!m_ArgList[kGeneDescr].Empty()) {
1509  asn_path_to_feature = "\"data.gene.desc\", " + kGeneDescr;
1510  }
1511  else {
1512  asn_path_to_feature = "\"data.gene.locus\", \"\"";
1513  }
1514  }
1515  else {
1516  asn_path_to_feature = CMacroEditorContext::GetInstance().GetAsnPathToFeature(feat_type);
1517  }
1518 
1519  function += "(" + asn_path_to_feature + ", " + rt_var + ", " + kAddRedundant;
1520  if (feat_is_gene && (!m_ArgList[kGeneDescr].Empty() && !m_ArgList[kGeneLocus].Empty())) {
1521  function += ", \"data.gene.desc\", " + kGeneDescr;
1522  }
1523  if (!m_ArgList[kComment].Empty()) {
1524  function += ", \"comment\", \"" + m_ArgList[kComment].GetValue() + "\"";
1525  }
1526  function += GetQualifierForFunction(m_ArgList, kAddFeatQual1, kAddFeatVal1);
1527  function += GetQualifierForFunction(m_ArgList, kAddFeatQual2, kAddFeatVal2);
1528  function += GetQualifierForFunction(m_ArgList, kAddFeatQual3, kAddFeatVal3);
1529  function += GetQualifierForFunction(m_ArgList, kAddFeatQual4, kAddFeatVal4);
1530  function += ");";
1531 
1532  if (!feat_is_gene) {
1533  string applygene_func = GetApplyGeneFunction(m_ArgList, rt_var);
1534  if (applygene_func.find(",") != NPOS) {
1535  function += "\n" + applygene_func;
1536 
1537  if (!m_ArgList[kAddRedundant].IsTrue()) {
1538  string constraint = CMacroFunction_NumberOfFeatures::GetFuncName();
1539  constraint += "(\"" + m_ArgList[kFeatureType].GetValue() + "\") = 0";
1540  constraints.insert(constraints.begin(), make_pair(kEmptyStr, constraint));
1541  }
1542  }
1543  }
1544  return function;
1545 }
1546 
1548 {
1553 }
1554 
1555 // CApplyPmidToEntryTreeItemData
1557  : CMacroActionItemData("Apply PMID to the record and lookup publications by PMID")
1558 {
1559 }
1560 
1562 {
1563  x_LoadPanel(parent, CMacroFunction_ApplyPmidToEntry::GetFuncName(), GetApplyPmidArgs());
1564 }
1565 
1567 {
1568  return "Apply pmid " + m_ArgList[kNewValue].GetValue() + " and do PMID lookup";
1569 }
1570 
1572 {
1573  string function = CMacroFunction_ApplyPmidToEntry::GetFuncName();
1574  function += "(" + m_ArgList[kNewValue].GetValue();
1575  if (m_ArgList[kApplyMultiple].IsTrue()) {
1576  function += ", true";
1577  }
1578  function += ");";
1579  return function;
1580 }
1581 
1583 {
1584  return { CMacroFunction_ApplyPmidToEntry::GetFuncName() };
1585 }
1586 
1587 // CApplyDOIToEntryTreeItemData
1589  : CMacroActionItemData("Add publication identified by its DOI name")
1590 {
1591 }
1592 
1594 {
1595  x_LoadPanel(parent, CMacroFunction_ApplyDOIToEntry::GetFuncName(), GetApplyPmidArgs());
1596 }
1597 
1599 {
1600  return "Apply publication with DOI name " + m_ArgList[kNewValue].GetValue() + " and do DOI lookup";
1601 }
1602 
1604 {
1605  if (m_ArgList[kNewValue].Empty())
1606  return kEmptyStr;
1607 
1608  string function = CMacroFunction_ApplyDOIToEntry::GetFuncName();
1609  function += "(\"" + m_ArgList[kNewValue].GetValue() + "\"";
1610  if (m_ArgList[kApplyMultiple].IsTrue()) {
1611  function += ", true";
1612  }
1613  function += ");";
1614  return function;
1615 }
1616 
1618 {
1619  return { CMacroFunction_ApplyDOIToEntry::GetFuncName() };
1620 }
1621 
1622 // CApplyDOILookupTreeItemData
1624  : CMacroActionItemData("Lookup DOI number and replace unpublished references with the looked up article")
1625 {
1626 }
1627 
1629 {
1630  x_LoadPanel(parent, CMacroFunction_GlobalDOILookup::GetFuncName(), GetDOILookupArgs());
1631  m_Panel->GetArgumentList().Attach(NMItemData::OnDOILookupModeChanged);
1632 }
1633 
1635 {
1636  string descr;
1637  if (m_ArgList[kGlobalDoi].IsTrue()) {
1638  descr = "Look up publications by DOI name";
1639  }
1640  if (m_ArgList[kSameDoi].IsTrue()) {
1641  descr = "Look up DOI name '" + m_ArgList[kNewValue].GetValue() + "'";
1642  }
1643  return descr;
1644 }
1645 
1647 {
1648  string function;
1649  if (m_ArgList[kGlobalDoi].IsTrue()) {
1650  function = CMacroFunction_GlobalDOILookup::GetFuncName() + "();";
1651  }
1652  else if (m_ArgList[kSameDoi].IsTrue() && !m_ArgList[kNewValue].Empty()) {
1653  function = CMacroFunction_DOILookup::GetFuncName();
1654  function += "(\"" + m_ArgList[kNewValue].GetValue() + "\");";
1655  }
1656  return function;
1657 }
1658 
1660 {
1661  return { CMacroFunction_DOILookup::GetFuncName(), CMacroFunction_GlobalDOILookup::GetFuncName() };
1662 }
1663 
1664 
1665 // CApplyAutodefOptTreeItemData
1667  : CApplyQualTreeItemData("Apply new value to AutodefOptions field", EMacroFieldType::eNotSet)
1668 {
1669 }
1670 
1672 {
1673  TArgumentsVector args(GetSetArgs());
1674  x_LoadPanel(parent, CMacroFunction_SetAutodefOption::GetFuncName(), args);
1675 
1676  m_Panel->GetArgumentList().Attach(NMItemData::OnExistingTextChanged);
1677 }
1678 
1680 {
1681  string field = m_ArgList[kField].GetValue();
1682  string value = m_ArgList[kNewValue].GetValue();
1683  if (field.empty() || value.empty())
1684  return kEmptyStr;
1685 
1686  string function = CMacroFunction_SetAutodefOption::GetFuncName();
1687  function += "(\"" + field + "\", " + kNewValue + ", " + kExistingText;
1688 
1689  if (m_ArgList[kDelimiter].GetEnabled()) {
1690  function += ", " + kDelimiter;
1691  }
1692  function += ");";
1693  return function;
1694 }
1695 
1697 {
1698  return { CMacroFunction_SetAutodefOption::GetFuncName()};
1699 }
1700 
1701 // CApplyUnverifiedItemData
1703  : CMacroActionItemData("Apply Unverified user object to na sequences", EMacroFieldType::eNotSet)
1704 {
1705 }
1706 
1708 {
1710  x_LoadPanel(parent, CMacroFunction_AddUnverified::GetFuncName(), args);
1711 }
1712 
1714 {
1715  return "Apply Unverified " + x_GetField() + " user object";
1716 }
1717 
1719 {
1720  CTempString new_target = CMacroBioData::sm_SeqNa;
1721  // if there is relevant constraint, change the target
1722  m_Target = new_target;
1723 }
1724 
1726 {
1727  string field = x_GetField();
1728  if (field.empty())
1729  return kEmptyStr;
1730 
1731  return CMacroFunction_AddUnverified::GetFuncName() + "(\"" + field + "\");";
1732 }
1733 
1735 {
1736  if (m_ArgList[kUnverOrg].IsTrue()) {
1737  return "organism";
1738  }
1739  else if (m_ArgList[kUnverFeats].IsTrue()) {
1740  return "features";
1741  }
1742  else if (m_ArgList[kUnverMisassembled].IsTrue()) {
1743  return "misassembled";
1744  }
1745  else if (m_ArgList[kUnverContamination].IsTrue()) {
1746  return "contaminant";
1747  }
1748  return kEmptyStr;
1749 }
1750 
1752 {
1753  return { CMacroFunction_AddUnverified::GetFuncName() };
1754 }
1755 
1756 
1757 
1758 
User-defined methods of the data storage class.
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
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetFunctionNames() const
bool SetData(const vector< CFuncWithArgs > &func_info)
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
CMacroAuthorNamesPanel * m_AuthorsPanel
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual const vector< string > & GetKeywords() const
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() const
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual string GetFunction(TConstraints &constraints) const
virtual void x_AddParamPanel(wxWindow *parent)
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetMacroDescription() const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() 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 string GetMacroDescription() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
virtual void x_AddParamPanel(wxWindow *parent)
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetMacroDescription() const
virtual string GetFunction(TConstraints &constraints) const
virtual vector< string > GetFunctionNames() const
CApplyQualTreeItemData(const string &description, EMacroFieldType type)
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
virtual vector< string > GetFunctionNames() 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
bool SetData(const vector< CFuncWithArgs > &func_info)
virtual vector< string > GetFunctionNames() const
virtual string GetMacroDescription() const
virtual void x_AddParamPanel(wxWindow *parent)
virtual string GetFunction(TConstraints &constraints) const
CRef< objects::CSeqdesc > m_Seqdesc
CStructuredCommentPanel * m_StructCommentPanel
virtual void x_AddParamPanel(wxWindow *parent)
virtual vector< string > GetFunctionNames() const
virtual string GetFunction(TConstraints &constraints) const
virtual string GetMacroDescription() const
@Auth_list.hpp User-defined methods of the data storage class.
Definition: Auth_list.hpp:57
CAuthor –.
Definition: Author.hpp:59
static string MakeSuffixFromRoot(const string &root)
static string MakePrefixFromRoot(const string &root)
static void NormalizePrefix(string &prefix)
static string GetStructuredCommentPrefix(const CUser_object &user, bool normalize=true)
EMacroFieldType m_FieldType
for actions such as appply/edit/etc.
vector< string > x_GetPubFunctions() const
virtual void SetAuthors(const objects::CAuth_list &auth_list)
tuple< string, string, string, string > TNameTuple
TAuthorsVec GetAuthorNames() const
@end CMacroAuthorNamesPanel event handler declarations
vector< TNameTuple > TAuthorsVec
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)
vector< string > GetncRNAClassTypes(bool include_any=true) const
static CMacroEditorContext & GetInstance()
vector< string > GetFeatQualifiers() const
const vector< string > & GetBsrcKeywords() const
string GetAsnPathToFeature(const string &feat_name) const
string GetAsnPathToAuthorFieldName(const string &author_name)
string GetAsnMolinfoValue(const string &molinfo_field, const string &choice)
vector< string > GetRNAProductnames(const string &rna_type) const
vector< string > GetFieldNames(EMacroFieldType type) const
@ ePubFieldType_AuthorLastName
@ ePubFieldType_AuthorFirstName
@ ePubFieldType_AuthorConsortium
@ ePubFieldType_AuthorMiddleInitial
static EPubFieldType GetTypeForLabel(string label)
virtual void ChangeSeqdesc(const objects::CSeqdesc &desc)
static const string sm_StructuredCommentPrefix
virtual void UpdateSeqdesc(objects::CSeqdesc &desc)
static const string sm_StructuredCommentSuffix
static void s_AddPoundSigns(string &str)
static CRef< CDate > DateFromCollectionDate(const string &str) THROWS((CException))
Definition: SubSource.cpp:288
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
string x_GetVariables(const vector< CTempString > &args) const
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
constexpr const tuple_element< _Index, ct_const_tuple< _Types... > >::type & get(const ct_const_tuple< _Types... > &_Tuple) noexcept
Definition: const_tuple.hpp:97
const char * kComment
bool Empty(const CNcbiOstrstream &src)
Definition: fileutil.cpp:523
static const struct name_t names[]
string
Definition: cgiapp.hpp:687
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
static CTempString GetFuncName()
bool StringsAreEquivalent(const string &name1, const string &name2)
Definition: macro_util.cpp:397
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_SeqNa
static const char * sm_FuncVolume
class CMacroFunction_SetPubVolIssuePages SetPubVolume(newValue, existing_text, delimiter,...
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool IsStructVoucherPart(const string &field)
Definition: macro_util.cpp:826
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_DBLink
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool IsSatelliteSubfield(const string &field)
Definition: macro_util.cpp:903
bool IsMobileElementTSubfield(const string &field)
Definition: macro_util.cpp:908
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_Gene
static CTempString GetFuncName()
static CTempString GetFuncName()
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType & GetNCObject(void) const
Get object.
Definition: ncbiobj.hpp:1187
#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 int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
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
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5086
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5111
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
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5386
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:3396
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
void SetName(TName &value)
Assign a value to Name data member.
Definition: Author_.cpp:81
const TName & GetName(void) const
Get the Name member data.
Definition: Author_.hpp:352
void SetNames(TNames &value)
Assign a value to Names data member.
Definition: Auth_list_.cpp:149
bool IsStd(void) const
Check if variant Std is selected.
Definition: Date_.hpp:320
void SetType(TType &value)
Assign a value to Type data member.
const TFirst & GetFirst(void) const
Get the First member data.
Definition: Name_std_.hpp:469
const TName & GetName(void) const
Get the variant data.
Definition: Person_id_.cpp:137
const TStd & GetStd(void) const
Get the variant data.
Definition: Date_.cpp:109
const TUser & GetUser(void) const
Get the variant data.
Definition: Seqdesc_.cpp:384
TUser & SetUser(void)
Select the variant.
Definition: Seqdesc_.cpp:390
bool IsUser(void) const
Check if variant User is selected.
Definition: Seqdesc_.hpp:1122
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6929
int i
yy_size_t n
USING_SCOPE(objects)
static string s_GetFieldVar(unsigned int n)
static string s_GetValueVar(unsigned int n)
static string s_GetAddAuthorFunction(const string &nr, const string &existing_text)
static string s_GetNameForDescription(CMacroAuthorNamesPanel::TNameTuple names)
vector< macro::SArgMetaData > TArgumentsVector
CTempString UpdateTargetForFeatures(const string &feature, const string &qualifier, bool for_removal=false)
string GetResolveFuncForDBLink(const string &field, string &rt_var, TConstraints &constraints, bool &found_constraint)
void OnStructCommFieldChanged(CArgumentList &list, CArgument &arg)
bool MultipleValuesAllowed(const string &field)
void UpdateConstraintsForFeatures(TConstraints &constraints, const string &feature)
string GetStructCommQualDescr(const CArgumentList &arg_list)
string GetResolveFuncForSVPart(const string &field, const string &rt_var, TConstraints &constraints, bool &found_constraint)
string GetResolveFuncForMultiValuedQual(const string &field, 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 OnDOILookupModeChanged(CArgumentList &list, CArgument &arg)
void OnProteinNameSingle(CArgumentList &list, CArgument &arg)
bool IsGeneField(const string &field_name)
CTempString UpdateTargetForRnas(const string &rna_type)
string GetResolveFuncForApplyAuthors(CPubFieldType::EPubFieldType type, const string &rt_var, TConstraints &constraints)
void WrapInQuotes(string &str)
string GetResolveFuncForStrCommQual(const string &field, const string &field_name, const string &rt_var, TConstraints &constraints)
void OnControlsAddRNAPanelSelected(CArgumentList &list, CArgument &arg)
void OnExistingTextChanged(CArgumentList &list, CArgument &arg)
string GetHandleOldValue(const string &type)
EMacroFieldType GetSourceTypeInSinglePanel(const CArgumentList &arg_list)
void OnRnaTypeChanged(CArgumentList &list, CArgument &arg)
void UpdateConstraintsForRnas(TConstraints &constraints, const CArgumentList &arg_list)
string GetDelimiterChar(const string &del)
string GetResolveFuncForPubQual(const string &field, string &rt_var, TConstraints &constraints)
void AppendUpdatemRNAFnc(bool update_mrna, string &function)
string GetExistingTextDescr(const CArgumentList &arg_list)
const string kApplyMultiple
const string kGlobalDoi
const TArgumentsVector & GetApplyCDSArgs()
const string kAddRedundant
const string kLast
const string kSameDoi
const string kNewValue
const string kUnverFeats
const string kProteinDescr
const TArgumentsVector & GetApplyPmidArgs()
const string kAddFeatQual3
const string kToCoord
const string kUnverMisassembled
const string kFirst
const string kAddFeatVal2
const string kWholeSeq
const TArgumentsVector & GetUnverifiedArgs()
const string kCodonStart
const TArgumentsVector & GetSetArgs()
const TArgumentsVector & GetDOILookupArgs()
const string kProteinName
const string kAddFeatVal4
const string kFeatQual
const string kField
const string kPartial3
const string kAddFeatQual1
const string kUnverOrg
const string kSuffix
const string kStrand
const string kFromCoord
const string kRNAType
const string kncRNAClass
const TArgumentsVector & GetOptionalArgs()
const string kExistingText
const string kFeatType
const TArgumentsVector & GetApplyRNAArgs()
const TArgumentsVector & GetBsrcArgs()
const string kGeneLocus
const string kUnverContamination
const string kRnaName
const string kAddFeatQual2
const string kAddmRNA
const string kUpdatemRNA
const string kAddFeatQual4
const TArgumentsVector & GetApplyOtherFeatureArgs()
const string kPartial5
const string kAddFeatVal1
const string kInterval
const string kStrCommField
const string kGeneDescr
const string kFeatureType
const string kDelimiter
const string kAddFeatVal3
constexpr bool empty(list< Ts... >) noexcept
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
static const char * prefix[]
Definition: pcregrep.c:405
@ eNotSet
Definition: splign_app.cpp:550
Definition: type.c:6
#define _ASSERT
static const char * kMiddle
Modified on Mon Jul 22 05:05:15 2024 by modify_doxy.py rev. 669887