41 #include <wx/progdlg.h>
42 #include <wx/evtloop.h>
52 : m_Table(
table), m_Seh(entry), m_id_guesser(id_guesser), m_ColProperties(column_properties),
53 m_ConstrField(constraint_field), m_StrConstraint(string_constraint),
54 m_CmdProccessor(cmd_processor)
86 const char* kMatchString =
"match ";
90 string adjust_field = field_name;
96 size_t pos = adjust_field.find(
' ');
97 if (pos != string::npos) {
98 adjust_field = adjust_field.substr(pos + 1, string::npos);
106 switch (guess_field_type) {
109 vector<CFieldNamePanel::EFieldType> guess_preference;
118 for (
auto& it : guess_preference) {
119 if (s_GetFieldType(field_name, it)) {
120 guess_field_type = it;
196 auto field_type = s_GuessFieldType(field_name);
199 s_GetFieldType(field_name, field_type);
210 string field(field_name);
211 size_t pos = field_name.find(
' ');
212 if (pos != string::npos) {
213 field = field_name.substr(0, pos);
221 else if (
NStr::StartsWith(field_name,
"CDS") || field_name ==
"codon-start") {
248 if (field_name.find(
"snRNA ") != string::npos) {
251 else if (field_name.find(
"scRNA ") != string::npos) {
254 else if (field_name.find(
"snoRNA ") != string::npos) {
270 string s_GetPropFromMetaInfo(
const string& meta_string,
const string& prop_name)
274 string tag =
"&" + prop_name +
"=";
276 size_t tag_idx = meta_string.find(
tag);
277 if (tag_idx != string::npos) {
280 size_t tag_end_idx = meta_string.find_first_of(
"&", tag_idx + 1);
281 size_t start_idx = tag_idx +
string(
tag).length();
283 if (tag_end_idx == string::npos) {
284 value = meta_string.substr(start_idx, meta_string.length() - start_idx);
287 value = meta_string.substr(start_idx, tag_end_idx - start_idx);
294 edit::EExistingText s_GetExistingTextInstructionFromText(
const string& update_rule,
const string& separator)
335 else if (
NStr::Equal(update_rule,
"add_new_qual")) {
345 bool s_IsSequenceIDField(
const string& field)
355 for (
int row = 0; row <
m_Table->GetNum_rows(); row++) {
369 if (seen_id.
find(id_value) != seen_id.
end()) {
370 duplicate_id.
insert(id_value);
375 if (!duplicate_id.
empty()) {
377 report->SetTitle(
wxT(
"Duplicate row ids"));
387 if (!wxEventLoopBase::GetActive() || !wxEventLoopBase::GetActive()->IsYielding())
389 bool modified =
false;
395 bool desc_present =
false;
415 wxGenericProgressDialog progress(
"Applying table values", wxEmptyString);
418 for (
int row = 0; row <
m_Table->GetNum_rows(); row++) {
435 for (
auto &seh : sehs)
440 it->SetTopSeqEntry(seh);
447 it->ResetChangedDescriptors();
448 it->ResetChangedFeatures();
454 progress.Update(100*row/
m_Table->GetNum_rows());
455 if (!wxEventLoopBase::GetActive() || !wxEventLoopBase::GetActive()->IsYielding())
473 for (
size_t col_num = 0; col_num <
m_Table->GetColumns().
size(); col_num++) {
500 for (
size_t col_num = 0; col_num <
m_Table->GetColumns().
size(); col_num++) {
501 if (col_num != id_col_num) {
503 if (
m_Table->GetColumns()[col_num]->IsSetHeader()
504 &&
m_Table->GetColumns()[col_num]->GetHeader().IsSetTitle()) {
505 field_name =
m_Table->GetColumns()[col_num]->GetHeader().GetTitle();
509 if (!field_name.empty()) {
511 int field_subtype = s_GetSubtype(field_name, field_type);
512 field_name = s_AdjustFieldName(field_name, field_type);
526 for (
size_t col_num = 0; col_num <
m_Table->GetColumns().
size(); col_num++) {
527 if (col_num != id_col_num) {
528 if (col_num < m_ColProperties->GetData().
size()) {
532 string ur = s_GetPropFromMetaInfo(col_meta_info,
"update_rule");
533 string ts = s_GetPropFromMetaInfo(col_meta_info,
"text_separator");
534 m_ExistingText.push_back(s_GetExistingTextInstructionFromText(ur, ts));
535 string blanks = s_GetPropFromMetaInfo(col_meta_info,
"blanks");
566 auto it = value_to_sehs.find(id_value);
567 if (it != value_to_sehs.end())
575 value_to_sehs.clear();
576 if (s_IsSequenceIDField(id_field_name))
578 id_field_name =
"Local ID";
590 for (
auto &fh : feathdlesmap) {
593 id_action->SetTopSeqEntry(bseh);
596 const vector<string>& values = id_action->GetChangedValues();
597 for (
auto v : values)
598 value_to_sehs[v].insert(bseh);
599 id_action->ResetChangedValues();
602 if (!descrmap.
empty()) {
605 if (descrmap.
find(&*desc_iter) != descrmap.
end()) {
607 id_action->SetTopSeqEntry(bseh);
609 const vector<string>& values = id_action->GetChangedValues();
610 for (
auto v : values)
611 value_to_sehs[v].insert(bseh);
612 id_action->ResetChangedValues();
627 int constr_field_subtype = -1;
631 constr_field_subtype = s_GetSubtype(
m_ConstrField, constr_field_type);
636 TEditingActionVec::iterator iter =
m_ActionList.begin();
637 for (
size_t col_num = 0; col_num <
m_Table->GetColumns().
size() && rval && iter !=
m_ActionList.end(); col_num++) {
638 if (col_num != id_col_num) {
640 if (
m_Table->GetColumns()[col_num]->IsSetHeader()
641 &&
m_Table->GetColumns()[col_num]->GetHeader().IsSetTitle()) {
642 field_name =
m_Table->GetColumns()[col_num]->GetHeader().GetTitle();
645 if (!field_name.empty()) {
647 int field_subtype = s_GetSubtype(field_name, field_type);
648 field_name = s_AdjustFieldName(field_name, field_type);
655 if (!field_constraint) {
658 constraint = field_constraint;
665 if (!idfield_constraint) {
669 *constraint += idfield_constraint;
672 constraint = idfield_constraint;
676 if (constraint && *iter) {
677 (*iter)->SetConstraint(constraint);
693 vector<edit::EExistingText>::iterator existing_text_it =
m_ExistingText.begin();
697 if (col_num < id_col_num) {
698 new_val =
m_Table->GetColumns()[col_num]->GetData().GetString()[row];
701 new_val =
m_Table->GetColumns()[col_num + 1]->GetData().GetString()[row];
706 if (new_val.empty()) {
718 else if (!new_val.empty()) {
719 (*action)->SetExistingText(*existing_text_it);
720 (*action)->Apply(new_val);
User-defined methods of the data storage class.
void AddCommand(IEditCommand &command)
static string AutoMatchRNA(string field_name)
static string AutoMatchFeat(string field_name)
static string AutoMatchSrc(string field_name)
static string AutoMatchMolInfo(string field_name)
static string AutoMatchMisc(string field_name)
static string AutoMatchPub(string field_name)
static string AutoMatchDBLink(string field_name)
static string AutoMatchCGP(string field_name)
@ eFieldType_BankITComment
@ eFieldType_StructuredComment
void SetText(const wxString &text)
implements special composite command, which does not call to its internal commands when run the very ...
CRef< objects::edit::CStringConstraint > m_StrConstraint
TEditingActionVec m_ActionList
void x_GetIdColumnProps(size_t id_col_num)
CRef< objects::CSeq_table > m_Table
bool x_SetConstraints(size_t id_col_num, CRef< edit::CStringConstraint > id_constraint)
objects::CSeq_entry_Handle m_Seh
CFieldNamePanel::EFieldType m_IdFieldType
ICommandProccessor * m_CmdProccessor
vector< bool > m_EraseIfBlank
bool x_ApplyRowToEntry(int row, size_t id_col_num, CRef< CMacroCmdComposite > apply_cmd)
void x_CreateEditingActions(size_t id_col_num)
void x_InterpretColumnProperties(size_t id_col_num)
void x_SetTopSeqEntryForActions(const string &id_value, set< CSeq_entry_Handle > &sehs, const map< string, set< CSeq_entry_Handle > > &value_to_sehs)
static void s_GetValueToSehMap(objects::CSeq_entry_Handle seh, map< string, set< CSeq_entry_Handle > > &value_to_sehs, string id_field_name, CFieldNamePanel::EFieldType id_field_type, int id_subtype)
bool x_ApplyMiscSeqTableToSeqEntry(CRef< CMacroCmdComposite > apply_cmd)
vector< objects::edit::EExistingText > m_ExistingText
CMiscSeqTable(CRef< objects::CSeq_table > table, objects::CSeq_entry_Handle entry, edit::CSeqIdGuesser &id_guesser, CRef< objects::CUser_object > column_properties, const string &constraint_field=kEmptyStr, CRef< objects::edit::CStringConstraint > string_constraint=CRef< edit::CStringConstraint >(NULL), ICommandProccessor *cmd_processor=NULL)
void x_CheckDuplicateIds(CRef< CSeqTable_column > id_col)
CRef< objects::CUser_object > m_ColProperties
edit::CSeqIdGuesser & m_id_guesser
static CRef< CCmdComposite > GetPropagateUpCommand(objects::CSeq_entry_Handle seh)
static CRef< CCmdComposite > GetPropagateDownCommand(objects::CSeq_entry_Handle seh)
@ eSubtype_mat_peptide_aa
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
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_iterator end() const
const_iterator find(const key_type &key) const
iterator_bool insert(const value_type &val)
const_iterator find(const key_type &key) const
const_iterator end() const
CRef< CEditingActionConstraint > CreateEditingActionConstraint(const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, const string &const_field, CFieldNamePanel::EFieldType const_field_type, int const_subtype, string &const_ncRNA_class, CRef< CConstraintMatcher >constraint)
CIRef< IEditingAction > CreateAction(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class=kEmptyStr, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
const char * kDefinitionLineLabel
const char * kFieldTypeSeqId
const char * kBankITComment
const char * kSequenceIdColLabel
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
const string & GetMsg(void) const
Get message string.
#define NCBI_RETHROW_SAME(prev_exception, message)
Generic macro to re-throw the same exception.
virtual void Execute()
Do the editing action.
virtual void Unexecute()
Undo (opposite to Execute())
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
@ eContent
Untagged human-readable accession or the like.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CScope & GetScope(void) const
Get scope this handle belongs to.
@ fIncludeGivenEntry
Include the top (given) entry.
@ fRecursive
Iterate recursively.
TObjectType & GetObject(void)
Get object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
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.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
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.
@ eNocase
Case insensitive compare.
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
bool IsId(void) const
Check if variant Id is selected.
const TTitle & GetTitle(void) const
Get the Title member data.
bool IsString(void) const
Check if variant String is selected.
const THeader & GetHeader(void) const
Get the Header member data.
bool IsInt(void) const
Check if variant Int is selected.
const TInt & GetInt(void) const
Get the variant data.
const TString & GetString(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
const TId & GetId(void) const
Get the variant data.
@ e_not_set
No variant selected.
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines NCBI C++ exception handling.
bool QualifierNamesAreEquivalent(string name1, string name2)
@ eExistingText_append_semi
@ eExistingText_append_space
@ eExistingText_prefix_colon
@ eExistingText_append_none
@ eExistingText_leave_old
@ eExistingText_prefix_none
@ eExistingText_prefix_space
@ eExistingText_append_colon
@ eExistingText_prefix_comma
@ eExistingText_append_comma
@ eExistingText_prefix_semi
@ eExistingText_replace_old