NCBI C++ Toolkit Cross Reference

  C++/include/gui/packages/pkg_sequence_edit/subprep_util.hpp


/* $Id: subprep_util.hpp 28241 2013-06-03 12:41:17Z bollin $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Colleen Bollin */ #ifndef _SUBPREP_UTIL_H_ #define _SUBPREP_UTIL_H_ #include <corelib/ncbistd.hpp> #include <objmgr/seq_entry_handle.hpp> #include <objects/seqfeat/OrgMod.hpp> #include <objects/seqfeat/SubSource.hpp> #include <objects/seqtable/Seq_table.hpp> #include <objects/seqtable/SeqTable_column.hpp> #include <objects/seqtable/SeqTable_multi_data.hpp> #include <objects/seqtable/SeqTable_column_info.hpp> #include <gui/widgets/wx/wx_utils.hpp> #include <gui/widgets/grid_widget/grid_widget.hpp> #include <gui/packages/pkg_sequence_edit/srcedit_util.hpp> #include <gui/packages/pkg_sequence_edit/seqtable_util.hpp> #include <gui/packages/pkg_sequence_edit/featedit_util.hpp> #include <gui/objutils/table_data.hpp> #include <gui/objutils/cmd_composite.hpp> BEGIN_NCBI_SCOPE const string kSubmissionPreparationToolVersion = "1.0"; typedef pair<CSourceRequirements::EWizardType, string> TWizardName; typedef vector<TWizardName> TWizardNameList; TWizardNameList GetWizardNameList(); CSourceRequirements::EWizardType GetWizardTypeFromName(string wizard_name); void FixTableAfterImport (CRef<objects::CSeq_table> input_table); string FindBadRows (CRef<objects::CSeq_table> src, CRef<objects::CSeq_table> dst, objects::CSeq_entry_Handle seh); CRef<objects::CSeqTable_column> FindSeqIDColumn(const objects::CSeq_table& table); int FindRowForSeqId (CRef<objects::CSeqTable_column> id_col, CRef<objects::CSeq_id> id); int CountColumnRowConflicts (CRef<objects::CSeqTable_column> dst_id, CRef<objects::CSeqTable_column> dst_col, CRef<objects::CSeqTable_column> src_id, CRef<objects::CSeqTable_column> src_col); int CountTableColumnConflicts (CRef<objects::CSeq_table> dst, const objects::CSeq_table& src); void DeleteTableRow (CRef<objects::CSeq_table> table, int row); int CombineTables (CRef<objects::CSeq_table> dst, const objects::CSeq_table& src); bool SaveTableFile (wxWindow *parent, wxString& save_file_dir, wxString& save_file_name, CRef<objects::CSeq_table> values_table); bool AreAllColumnValuesTheSame(CRef<objects::CSeqTable_column> col, string default_val = ""); bool AreAnyColumnValuesMissing(CRef<objects::CSeqTable_column> col); bool AreAnyColumnValuesPresent(CRef<objects::CSeqTable_column> col, string default_val = ""); bool DoesColumnHaveValue(CRef<objects::CSeqTable_column> col, string val); bool AddSeqEntryToSeqEntry(const objects::CSeq_entry* entry, objects::CSeq_entry_Handle seh, CRef<CCmdComposite> cmd, bool& has_nuc, bool& has_prot); string CheckFeatureAnnotation (objects::CSeq_entry_Handle entry, bool& is_ok); int AddFeatureToSeqTable (const objects::CSeq_feat& f, CRef<objects::CSeq_table> table); CRef<objects::CSeq_table> GetFeaturesFromSeqEntry(objects::CSeq_entry_Handle entry, const objects::CSeq_feat& feat, const TFeatureSeqTableColumnList& reqs); void MergeStringVectors (vector<string>& problems, vector<string> add); void RemoveProblemsColumn (CRef<objects::CSeq_table> values_table); void AddProblemsColumnToFeatureSeqTable(CRef<objects::CSeq_table> table, const TFeatureSeqTableColumnList& reqs, const TFeatureSeqTableColumnList& opts); CRef<CCmdComposite> AddFeatureSeqTableToSeqEntry(CRef<objects::CSeq_table> table, objects::CSeq_entry_Handle entry, objects::CSeqFeatData::ESubtype subtype, const TFeatureSeqTableColumnList& reqs, const TFeatureSeqTableColumnList& opts); bool HasLocalIntFeatureId (const objects::CSeq_feat& feat); CRef<CCmdComposite> RemoveMatchingFeaturesWithoutLocalIntFeatureIdsFromSeqEntry(objects::CSeq_entry_Handle entry, const objects::CSeq_feat &feat, const TFeatureSeqTableColumnList& reqs); CRef<CFeatureSeqTableColumnBase> GetColumnRuleForFeatureSeqTable(CRef<objects::CSeqTable_column> col, const TFeatureSeqTableColumnList& reqs, const TFeatureSeqTableColumnList& opts); vector<string> GetTrueFalseList(); bool IsSynonymForTrue(const string& val); bool IsSynonymForFalse(const string& val); bool IsTrueFalseList(const vector<string>& choices); wxString GetAsnSqnExtensions(); const string kWizardLabel = "NCBIWizard"; bool IsWizardObject(const objects::CUser_object& user); CRef<objects::CUser_object> MakeWizardObject (); string GetFieldFromWizardObject (const objects::CUser_object& user, string field_name); void SetWizardFieldInSeqEntryNoUndo(objects::CSeq_entry_Handle entry, string field_name, string value); CRef<objects::CUser_object> MakeBankItSubmissionObject (); bool IsBankItSubmissionObject(const objects::CUser_object& user); string GetDescAlternateEmailAddress(const objects::CSeqdesc& desc); string GetAlternateEmailAddress(objects::CSeq_entry_Handle entry); void SetUserAlternateEmailAddress(objects::CUser_object& u, string alt_email); void SetAlternateEmailAddress(objects::CSeq_entry_Handle entry, string alt_email); bool IsValidEmail(string email); CRef<objects::CSeq_table> GetIdsFromSeqEntry(const objects::CSeq_entry& entry); void AddIdsFromSeqEntryToTable (const objects::CSeq_entry& entry, CRef<objects::CSeq_table> table); CRef<objects::CSeqTable_column> GetSeqIdProblems(CRef<objects::CSeq_table> new_ids, CRef<objects::CSeq_table> old_ids, size_t max_len); string SummarizeIdProblems(CRef<objects::CSeqTable_column> problems); CRef<objects::CSeqTable_column> GetReplacementSeqIds (CRef<objects::CSeq_table> new_ids, CRef<objects::CSeq_table> old_ids, size_t max_len); void ApplyReplacementIds(objects::CSeq_entry& entry, CRef<objects::CSeq_table> table); vector<string> FindNonUniqueStrings(const vector<string>& values); vector<string> SortUniqueStrings(const vector<string>& values); bool AlreadyHasFeature(objects::CBioseq_Handle bh, string key, string comment); bool AlreadyHasFeature(objects::CBioseq_Handle bh, objects::CSeqFeatData::ESubtype subtype); const int kSkipColumns = 1; const string kNewId = "New Sequence ID"; const string kMoleculeType = "Molecule Type"; const string kDefaultMoleculeType = "Genomic DNA"; static const string kTopology = "Topology"; static const string kLocation = "Location"; class CSeqTableGrid : public wxGridTableBase { public: CSeqTableGrid(CRef<objects::CSeq_table> values_table) : m_ValuesTable(values_table) {} virtual ~CSeqTableGrid() {} virtual int GetNumberRows() { return m_ValuesTable->GetNum_rows(); } virtual int GetNumberCols() { return m_ValuesTable->GetColumns().size() - 1; } virtual bool IsEmptyCell( int row, int col ) { return false; } virtual wxString GetValue( int row, int col ) { size_t pos = col + 1; size_t row_num = row; if (m_ValuesTable->GetColumns().size() > pos && m_ValuesTable->GetColumns()[pos]->GetData().GetSize() > row_num) { CRef<objects::CSeqTable_column> column = m_ValuesTable->GetColumns()[pos]; string val = ""; if (column->GetData().IsString()) { val = column->GetData().GetString()[row_num]; } else if (column->GetData().IsId()) { column->GetData().GetId()[row]->GetLabel(&val, objects::CSeq_id::eContent); } else if (column->GetData().IsInt()) { val = NStr::NumericToString(column->GetData().GetInt()[row_num]); } return ToWxString(val); } else { return ToWxString (""); } } virtual void SetValue( int vis_row, int vis_col, const wxString& value ) { size_t vcol = vis_col + 1; size_t vrow = vis_row; if (m_ValuesTable->GetColumns().size() > vcol) { CRef<objects::CSeqTable_column> col = m_ValuesTable->GetColumns()[vcol]; if (col->GetData().IsString()) { while (col->GetData().GetSize() <= vrow) { col->SetData().SetString().push_back(""); } col->SetData().SetString()[vrow] = ToStdString(value); } else if (col->GetData().IsInt()) { col->SetData().SetInt()[vrow] = NStr::StringToInt(ToStdString(value)); } else { col->SetData().SetString()[vrow] = ToStdString(value); } } } /* // Overriding these is optional // virtual void SetView( wxGrid *grid ) { m_view = grid; } virtual wxGrid * GetView() const { return m_view; } virtual void Clear() {} virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); virtual bool AppendRows( size_t numRows = 1 ); virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); */ virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ) { size_t skip = 0; objects::CSeq_table::TColumns::iterator it = m_ValuesTable->SetColumns().begin(); while (it != m_ValuesTable->SetColumns().end() && skip < pos + 1) { it++; skip++; } for (size_t i = 0; i < numCols; i++) { CRef< objects::CSeqTable_column > last_col(new objects::CSeqTable_column()); last_col->SetData().SetString(); m_ValuesTable->SetColumns().insert(it, last_col); } if ( GetView() ) { wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_COLS_INSERTED, pos, numCols ); GetView()->ProcessTableMessage( msg ); } return true; } virtual bool AppendCols( size_t numCols = 1 ) { for (size_t i = 0; i < numCols; i++) { CRef< objects::CSeqTable_column > last_col(new objects::CSeqTable_column()); last_col->SetData().SetString(); m_ValuesTable->SetColumns().push_back (last_col); } if ( GetView() ) { wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_COLS_APPENDED, numCols, numCols ); GetView()->ProcessTableMessage( msg ); } return true; } virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ) { if (pos+numCols < m_ValuesTable->SetColumns().size()) { m_ValuesTable->SetColumns().erase(m_ValuesTable->SetColumns().begin()+pos,m_ValuesTable->SetColumns().begin()+pos+numCols); if ( GetView() ) { wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_COLS_DELETED, pos, numCols ); GetView()->ProcessTableMessage( msg ); } } return true; } virtual wxString GetRowLabelValue( int row ) { CRef<objects::CSeqTable_column> id_col = FindSeqTableColumnByName (m_ValuesTable, kSequenceIdColLabel); string label = ""; size_t r = row; if (id_col && id_col->GetData().GetSize() > r) { id_col->GetData().GetId()[r]->GetLabel (&label, objects::CSeq_id::eContent); } else { label = NStr::NumericToString(r + 1); } return ToWxString (label); } virtual wxString GetColLabelValue( int col ) { wxString label; size_t c = col + 1; if (m_ValuesTable->GetColumns().size() > c) { CRef<objects::CSeqTable_column> column = m_ValuesTable->GetColumns()[c]; if (column->IsSetHeader()) { if (column->GetHeader().IsSetTitle()) { label = column->GetHeader().GetTitle(); } else if (column->GetHeader().IsSetField_name()) { label = column->GetHeader().GetField_name(); } } } return label; } virtual void SetColLabelValue( int col, const wxString& label) { size_t c = col + 1; if (m_ValuesTable->GetColumns().size() > c) { m_ValuesTable->SetColumns()[c]->SetHeader().SetTitle(ToStdString(label)); } } CRef<objects::CSeq_table> GetValuesTable(void) { return m_ValuesTable; } CConstRef<objects::CSeq_table> GetValuesTable(void) const { return m_ValuesTable; } private: CRef<objects::CSeq_table> m_ValuesTable; }; END_NCBI_SCOPE #endif // _SUBPREP_UTIL_H_

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.