84 if (it.m_CreateProteins) {
87 macros.push_back(script);
102 if (it->IsSetLabel() && it->GetLabel().IsStr()) {
103 column = it->GetLabel().GetStr().substr(
string(
"Column.").length(),
NPOS);
110 if (it->IsSetData() && it->GetData().IsStr()) {
111 string col_meta_info = it->GetData().GetStr();
113 if (skipped ==
"true") {
124 _ASSERT(!qualifier_type.empty());
136 string iterator =
x_GetIterator(qualifier_type, field_type, qualifier,
true);
138 [field_type, &iterator](
const SOneMacroData& elem){ return elem.m_Fieldtype == field_type; });
141 if (it->m_Iterator.empty()) {
142 it->m_Iterator = iterator;
144 it->m_Values.emplace_back(qualifier,
column);
145 it->m_ColumnInfo.push_back(col_meta_info);
161 string macro_script =
"MACRO TableReaderMacro \"Description\"\n";
162 macro_script +=
"VAR\n";
166 macro_script +=
x_GetVariables(del_options, list_update_mrna) +
"\n";
167 macro_script +=
"FOR EACH " +
data.m_Iterator +
"\n";
173 vector<string> pure_constraints;
174 pure_constraints.reserve(constraints.size());
175 for (
auto p : constraints) {
176 pure_constraints.push_back(p.second);
178 macro_script +=
"WHERE " +
NStr::Join(pure_constraints,
" AND ") +
"\n";
179 macro_script +=
"DO\n" + do_function +
"\nDONE\n";
180 macro_script +=
"---------------------------------------------------\n";
186 string macro_script =
"MACRO CreateProtFeats \"Create full length protein features\"\n";
187 macro_script +=
"FOR EACH TSEntry\n";
188 macro_script +=
"DO\n" + macro::CMacroFunction_CreateProteinFeats::GetFuncName() +
"();\nDONE\n";
189 macro_script +=
"---------------------------------------------------\n";
202 if (list_update_mrna) {
210 const string& qualifier,
bool apply)
212 if (qual_type.empty())
216 return macro::CMacroBioData::sm_BioSource;
224 return macro::CMacroBioData::sm_SeqNa;
229 return macro::CMacroBioData::sm_Seq;
232 return macro::CMacroBioData::sm_MolInfo;
237 return macro::CMacroBioData::sm_StrComm;
241 return macro::CMacroBioData::sm_Pubdesc;
245 return macro::CMacroBioData::sm_SeqNa;
254 vector<string> tokens;
256 if (tokens.size() == 2) {
261 return macro::CMacroBioData::sm_SeqFeat;
266 string rna_type, ncRNA_class, rna_qual;
277 if (del ==
"\t") del =
"\\t";
282 vector<string> tokens;
284 if (tokens.size() == 2) {
292 string rna_type, ncRNA_class, rna_qual;
299 if (path.find(
',') !=
NPOS) {
300 vector<string> tokens;
302 path =
"\"" + tokens[0] +
"\", \"" + tokens[1] +
"\"";
304 else if (path.find(
'(') !=
NPOS) {
308 path =
"\"" + path +
"\"";
317 if (
data.m_Iterator == macro::CMacroBioData::sm_MolInfo) {
318 constraint = macro::CMacroFunction_GetSeqdesc::sm_BsrcForMolinfo +
string(
"(") + path +
")";
320 else if (
data.m_Iterator == macro::CMacroBioData::sm_StrComm ||
321 data.m_Iterator == macro::CMacroBioData::sm_Pubdesc) {
322 constraint = macro::CMacroFunction_GetSeqdesc::sm_BsrcForSeqdesc +
string(
"(") + path +
")";
324 else if (
data.m_Iterator == macro::CMacroBioData::sm_Seq ||
325 data.m_Iterator == macro::CMacroBioData::sm_SeqNa) {
326 constraint = macro::CMacroFunction_GetSeqdesc::sm_BsrcForSeq +
string(
"(") + path +
")";
329 constraint = macro::CMacroFunction_GetSeqdesc::sm_BsrcForFeat +
string(
"(") + path +
")";
331 else if (
data.m_Iterator == macro::CMacroBioData::sm_BioSource) {
341 if (
data.m_Iterator == macro::CMacroBioData::sm_MolInfo) {
343 constraint =
CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) +
"(" + path +
")";
346 else if (
data.m_Iterator == macro::CMacroBioData::sm_Seqdesc) {
348 constraint =
CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) +
"(" + path +
")";
353 constraint =
CTempString(macro::CMacroFunction_GetSequence::sm_SeqForFeat) +
"(" + path +
")";
356 constraint =
CTempString(macro::CMacroFunction_GetSeqdesc::sm_MolinfoForFeat) +
"(" + path +
")";
359 else if (
data.m_Iterator == macro::CMacroBioData::sm_BioSource) {
361 constraint =
CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) +
"(" + path +
")";
364 constraint =
CTempString(macro::CMacroFunction_GetSeqdesc::sm_MolinfoForBsrc) +
"(" + path +
")";
367 else if (
data.m_Iterator == macro::CMacroBioData::sm_Seq ||
368 data.m_Iterator == macro::CMacroBioData::sm_SeqNa ||
369 data.m_Iterator == macro::CMacroBioData::sm_SeqAa) {
375 constraint = macro::CMacroFunction_GetDBLink::GetFuncName() +
"(\"" +
m_MatchField.
m_GUIName +
"\")";
379 constraint = macro::CMacroFunction_StructCommDatabase::GetFuncName() +
"()";
382 constraint = macro::CMacroFunction_StructCommFieldname::GetFuncName() +
"()";
389 constraint = macro::CMacroFunction_StructCommField::GetFuncName();
390 constraint +=
"(\"" + field_name +
"\")";
398 if (!constraint.empty()) {
412 string field_in_macro;
414 if (field_name_panel) {
415 string field_name = field_name_panel->
GetFieldName(
false);
420 if (!str_constraint.empty()) {
421 constraints.emplace_back(field_in_macro, str_constraint);
449 string first_field =
data.m_Values.front().first;
450 string feat_type, feat_qual;
455 bool update_mrna =
false;
457 data.m_Iterator, update_mrna,
data.m_ColumnInfo);
461 string first_field =
data.m_Values.front().first;
462 vector<string> tokens;
464 if (tokens.size() == 2) {
467 bool update_mrna =
false;
469 data.m_Iterator, update_mrna,
data.m_ColumnInfo);
472 string first_field =
data.m_Values.front().first;
473 string rna_type, ncRNA_class, rna_qual;
479 rna_type,
data.m_ColumnInfo);
482 if (
data.m_Iterator == macro::CMacroBioData::sm_Protein &&
485 for (
auto&& it :
data.m_Values) {
491 data.m_CreateProteins =
true;
500 if (macros.empty()) {
501 LOG_POST(
Info <<
"List of macros generated by Table Reader is empty");
508 bool apply_pmid =
false;
509 for (
auto& it : macros) {
510 if (it.find(macro::CMacroFunction_SetPubPMID::GetFuncName()) !=
NPOS)
522 auto start = chrono::steady_clock::now();
523 macro::CMacroEngine macro_engine;
524 bool data_updated =
false;
526 string ignored_lines;
528 for (
auto&& it : macros) {
532 LOG_POST(
Info <<
"Parsing the macro for Table Reader has failed");
536 macro::CMacroBioData bio_data(entry);
538 macro_engine.Exec(*macro_rep, bio_data, macro_cmd,
true);
540 catch (
const macro::CMacroExecException& e) {
542 if (e.GetErrCode() == macro::CMacroExecException::eMultipleEntries) {
547 string msg = e.ReportAll();
548 size_t pos =
msg.find(
"'");
549 size_t end_pos =
msg.find(
" ([Error]");
550 if (pos !=
NPOS && end_pos !=
NPOS) {
551 msg =
msg.substr(pos, end_pos - pos);
554 report->SetTitle(
wxT(
"Duplicate row ids"));
562 LOG_POST(
Info <<
"Execution of the macro has failed at " <<
563 macro_rep->GetTitle() <<
" step:\n" << err.
ReportAll());
567 const auto& macro_stat = macro_engine.GetStatistics();
568 const auto& report = macro_stat.GetMacroReport();
569 if (!report.GetLog().empty()) {
570 report_all += report.GetName() +
":\n" + report.GetLog() +
"\n";
573 const auto& logs = macro_stat.GetFunctionsLog();
575 report_all += report.GetName() +
":\n";
577 for (
const auto& it : logs) {
578 report_all += it->Print() +
"\n";
582 if (!report.GetErrorLog().empty()) {
583 report_all +=
"\nERRORS:\n" + report.GetErrorLog();
586 const auto& unmatched = macro_stat.GetUnmatchedTableEntries();
587 if (!unmatched.empty()) {
588 _ASSERT(unmatched.size() == 1);
589 string temp = unmatched.front().first;
590 int count = unmatched.front().second;
592 size_t nl_pos = temp.find(
"\n");
594 temp = temp.substr(nl_pos + 1);
595 nl_pos = temp.find(
"\n");
596 string value = temp.substr(0, nl_pos);
598 if (!ignored_lines.empty()) {
599 ignored_lines +=
"\n";
601 ignored_lines +=
value;
608 data_updated |= macro_stat.HasDataUpdated();
623 cmd_processor->
Execute(macro_cmd);
625 auto stop = chrono::steady_clock::now();
626 chrono::duration<double> elapsed = stop - start;
627 LOG_POST(
Info <<
"Total time spent on executing the macro is: " << elapsed.count() <<
" seconds.");
637 NcbiInfoBox(
"Table was applied successfully. No data change has occurred.");
639 else if (!ignored_lines.empty()) {
640 NcbiInfoBox(
"No matches were found for these values present in the table:\n" + ignored_lines);
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const string &target, bool update_mrna, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const string &target, bool update_mrna, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const string &target_rna_type, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetFunction(const TStringPairsVector &values, TConstraints &constraints, bool del_enabled, const vector< string > &column_info={})
static string s_GetMatchFieldConstraint(const SFieldFromTable &match_field, const string &delimiter, EMacroFieldType field_type, const string &target=kEmptyStr)
static string s_GetMacroFieldName(const string &field_name, const string &target, const string &selected_field=kEmptyStr)
void AddCommand(IEditCommand &command)
CFieldNamePanel * GetFieldNamePanel(void)
string GetMacroStringConstraint(const string &field_name)
static string s_GetMacroFieldName(const string &feature, const string &qualifier, const string &target, const string &selected_field=kEmptyStr)
static string AutoMatch(string field_name)
virtual string GetFieldName(const bool subfield=false)=0
Returns the name of the field as selected in the panel.
virtual string GetMacroFieldName(const string &target, const string &selected_field=kEmptyStr)
static bool IsFeature(const string &target)
void SetText(const wxString &text)
implements special composite command, which does not call to its internal commands when run the very ...
string GetAsnPathToFieldName(const string &field, EMacroFieldType type, const string &target=kEmptyStr)
static CMacroEditorContext & GetInstance()
static CRef< CCmdComposite > GetPropagateUpCommand(objects::CSeq_entry_Handle seh)
static CRef< CCmdComposite > GetPropagateDownCommand(objects::CSeq_entry_Handle seh)
static string s_GetMacroFieldName(const string &rna_type, const string &qual_field, const string &target, const string &selected_field=kEmptyStr)
TVecMacroNames CreateMacros(const wxString &filename, CRef< objects::CUser_object > column_properties, const SColumnDelimiters &del_options, CConstraintPanel *panel=nullptr, bool test=false)
CMacroWorker::TVecMacroNames TVecMacroNames
SFieldFromTable m_MatchField
TStringPairsVector x_GetStringConstraint(const string &target)
static bool s_LooksLikeHeader(const string &value)
vector< SOneMacroData > m_MacroVec
string x_GetFunction(SOneMacroData &data, TStringPairsVector &constraints)
CConstraintPanel * m_ConstraintPnl
void x_GatherValuesAndMatchField()
void x_GetMatchFieldConstraint(const SOneMacroData &data, const string &delimiter, TStringPairsVector &constraints)
string x_GetVariables(const SColumnDelimiters &del_options, bool list_update_mrna=false) const
string x_GetCreateProtFeatsMacro()
EMacroFieldType m_MatchFieldType
CConstRef< objects::CUser_object > m_ColProperties
string x_GetIterator(const string &qual_type, EMacroFieldType &field_type, const string &qualifier, bool apply=false)
string x_GetMacro(SOneMacroData &data, const SColumnDelimiters &del_options)
bool RunMacro(const TVecMacroNames ¯os, objects::CSeq_entry_Handle entry, ICommandProccessor *cmd_processor)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
const char * kStructCommFieldName
const char * kFieldTypeSeqId
const char * kStructCommDBName
const char * kStructCommFieldValuePair
#define test(a, b, c, d, e)
static const char * column
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
void Info(CExceptionArgs_Base &args)
bool StringsAreEquivalent(const string &name1, const string &name2)
virtual void Execute()
Do the editing action.
virtual void Unexecute()
Undo (opposite to Execute())
EDialogReturnValue NcbiInfoBox(const string &message, const string &title="Info")
specialized Message Box function for reporting general information messages
#define MSerial_AsnText
I/O stream manipulators –.
void Reset(void)
Reset reference object.
TObjectType & GetObject(void) const
Get object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static bool StringToBool(const CTempString str)
Convert string to bool.
vector< pair< string, string > > TStringPairsVector
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.
static const string BoolToString(bool value)
Convert bool to string.
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
@ eNocase
Case insensitive compare.
Macro engine for macro execution.
Functions used in the DO/DONE section affecting the top seq-entry.
void UpdateConstraintsForDualCdsGeneProt(TConstraints &constraints, const string &src_feat)
CTempString UpdateTargetForFeatures(const string &feature, const string &qualifier, bool for_removal=false)
void UpdateConstraintsForFeatures(TConstraints &constraints, const string &feature)
void GetRNASpecificFieldsForTableReader(const string &field_name, string &rna_type, string &ncRNA_type, string &rna_qual)
CTempString UpdateTargetForRnas(const string &rna_type)
void UpdateConstraintsForRnas(TConstraints &constraints, const CArgumentList &arg_list)
CTempString UpdateTargetForCdsGeneProt(const string &fieldname)
void GetFeatureAndField(const string &field_name, string &feature, string &field)
string GetPropertyFromInfo(const string &info, const string &property)
const string kConvertMulti
const string kMultipleSpsOnly
constexpr bool empty(list< Ts... >) noexcept
const GenericPointer< typename T::ValueType > T2 value
static const char delimiter[]
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
bool m_Merge_first_two_cols
bool m_Multiple_spaces_only
EMacroFieldType m_Fieldtype
TStringPairsVector m_Values
vector< string > m_ColumnInfo
wxString GetAbsolutePath(const wxString &localpath)
string ToStdString(const wxString &s)