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

Go to the SVN repository for this file.

1 /* $Id: country_fixup.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: Igor Filippov
27  */
28 
29 #include <ncbi_pch.hpp>
30 
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include "wx/wxprec.h"
33 
34 #ifdef __BORLANDC__
35 #pragma hdrstop
36 #endif
37 
38 #ifndef WX_PRECOMP
39 #include "wx/wx.h"
40 #endif
41 
42 #include <objmgr/util/sequence.hpp>
50 
53 
55 {
56  if (!tse)
57  return CRef<CCmdComposite>();
58 
59  m_Seh = tse;
60  m_capitalize_after_colon = capitalize_after_colon;
61  string title = "Country Fixup Do Not Fix Capitalization After Colon";
63  title = "Country Fixup Fix Capitalization After Colon";
64  }
65 
66  m_invalid_countries.clear();
68  CRef<CCmdComposite> composite(new CCmdComposite(title));
69  x_ApplyToSeqAndFeat(composite);
70 
71  if (!m_invalid_countries.empty())
72  {
74  if (dlg.ShowModal() == wxID_OK)
75  {
77  composite.Reset(new CCmdComposite(title));
78  x_ApplyToSeqAndFeat(composite);
79  }
80  }
81  return composite;
82 }
83 
84 static string s_GetAccession(CBioseq_Handle bsh)
85 {
86  string accession;
87  if (bsh)
88  {
90  int version;
91  best.GetSeqId()->GetLabel(&accession, &version, CSeq_id::eContent);
92  }
93  return accession;
94 }
95 
97 {
98  x_ApplyToDescriptors(*(m_Seh.GetCompleteSeq_entry()), composite);
99 
100  CScope& scope = m_Seh.GetScope();
101  for (CFeat_CI feat_it(m_Seh, SAnnotSelector(CSeqFeatData::e_Biosrc)); feat_it; ++feat_it) {
102  m_accession = s_GetAccession(scope.GetBioseqHandle(feat_it->GetLocation()));
103  CRef<CSeq_feat> new_feat(new CSeq_feat());
104  new_feat->Assign(feat_it->GetOriginalFeature());
105  if (x_ApplyToBioSource(new_feat->SetData().SetBiosrc())) {
106  CRef<CCmdChangeSeq_feat> cmd(new CCmdChangeSeq_feat(*feat_it, *new_feat));
107  composite->AddCommand(*cmd);
108  }
109  }
110 }
111 
112 
114 {
115  CScope& scope = m_Seh.GetScope();
117  if ((*it)->IsSource()) {
118  const CSeqdesc& orig_desc = **it;
119  if (se.IsSeq()) {
121  }
122  CRef<CSeqdesc> new_desc(new CSeqdesc);
123  new_desc->Assign(orig_desc);
124  if (x_ApplyToBioSource(new_desc->SetSource())) {
126  CCmdChangeSeqdesc(scope.GetSeq_entryHandle(se), orig_desc, *new_desc));
127  composite->AddCommand(*cmd);
128  }
129  }
130  }
131 
132  if (se.IsSet()) {
134  x_ApplyToDescriptors(**it, composite);
135  }
136  }
137 }
138 
139 
141 {
142  bool modified = false;
143 
144  EDIT_EACH_SUBSOURCE_ON_BIOSOURCE(subsource, biosource)
145  if ((*subsource)->IsSetSubtype() &&
146  (*subsource)->IsSetName() &&
147  (*subsource)->GetSubtype() == CSubSource::eSubtype_country)
148  {
149  string country = (*subsource)->GetName();
150  string new_country = CCountries::CountryFixupItem(country, m_capitalize_after_colon);
151  if (!new_country.empty() && new_country != country)
152  {
153  (*subsource)->SetName(new_country);
154  modified = true;
155  }
156  else if (m_fixed_countries.find(country) != m_fixed_countries.end())
157  {
158  (*subsource)->SetName(m_fixed_countries[country]);
159  modified = true;
160  }
161  else if (!CCountries::IsValid(country))
162  {
163  m_invalid_countries.push_back(pair<string, string>(country, m_accession));
164  }
165  }
166 
167  return modified;
168 }
169 
170 
171 IMPLEMENT_DYNAMIC_CLASS( CBulkCountryEdit, wxDialog )
172 
173 BEGIN_EVENT_TABLE( CBulkCountryEdit, wxDialog )
174 
175  EVT_BUTTON( wxID_CANCEL, CBulkCountryEdit::OnClickCancel )
176 
178 
180 {
181  Init();
182 }
183 
184 
185 CBulkCountryEdit::CBulkCountryEdit( wxWindow* parent, const vector<pair<string,string> > &invalid_countries,
186  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
187  : m_invalid_countries(invalid_countries)
188 {
189  Init();
190  Create(parent, id, caption, pos, size, style);
191 }
192 
193 
194 bool CBulkCountryEdit::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
195 {
196  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
197  wxDialog::Create( parent, id, caption, pos, size, style );
198 
199  CreateControls();
200  if (GetSizer())
201  {
202  GetSizer()->SetSizeHints(this);
203  }
204  Centre();
205  return true;
206 }
207 
208 
210 {
211 }
212 
213 
214 /*!
215  * Member initialisation
216  */
217 
219 {
220  m_Grid=NULL;
221 }
222 
223 
225 {
226  CBulkCountryEdit* itemDialog1 = this;
227 
228  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
229  itemDialog1->SetSizer(itemBoxSizer2);
230 
231  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
232  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
233 
234  wxArrayString itemChoiceStrings, itemChoiceStringsWritable;
235 
236  CRef<CSeq_table> values_table = GetValuesTable();
237  CRef<CSeq_table> choices = GetChoices(values_table);
238  int glyph_col = GetCollapsible();
239  m_GridPanel = new CSeqTableGridPanel(this, values_table, choices, glyph_col);
240  itemBoxSizer3->Add(m_GridPanel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
242  CSeqTableGrid *gridAdapter = new CSeqTableGrid(values_table);
243  m_Grid->SetTable(gridAdapter, true);
244  m_Grid->AutoSizeColumns();
245  int l_height = m_Grid->GetColLabelSize();
246  m_Grid->SetColLabelSize( 2 * l_height );
247 
248  int pos = 0;
249  ITERATE (CSeq_table::TColumns, it, values_table->GetColumns())
250  {
251  if (pos > 0)
252  {
253  if ((*it)->IsSetHeader() && (*it)->GetHeader().IsSetTitle() )
254  {
255  string title = (*it)->GetHeader().GetTitle();
256  if (!title.empty())
257  {
258  itemChoiceStrings.Add(wxString(title));
259  if (!IsReadOnlyColumn(title))
260  itemChoiceStringsWritable.Add(wxString(title));
261  }
262  if (IsReadOnlyColumn(title))
263  m_GridPanel->MakeColumnReadOnly(pos - 1, true);
264  }
265  }
266  pos++;
267  }
268 
269  if (glyph_col >= 0 && glyph_col+1 < m_Grid->GetNumberCols())
270  {
271  m_GridPanel->InitColumnCollapse(glyph_col+1);
272  }
273 
274 
275  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
276  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
277 
278  m_StringConstraintPanel = new CStringConstraintSelect( itemDialog1, m_GridPanel, itemChoiceStrings, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
279  itemBoxSizer4->Add(m_StringConstraintPanel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 0);
280 
281  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
282  itemBoxSizer2->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
283 
284  m_AecrPanel = new CApplyEditconvertPanel( itemDialog1, m_GridPanel, itemChoiceStringsWritable, 0, true, wxID_ANY, wxDefaultPosition, wxSize(1128, 219));
285  itemBoxSizer5->Add(m_AecrPanel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 1);
286 
287  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
288  itemBoxSizer2->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
289 
290  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
291  itemBoxSizer13->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
292 
293  wxButton* itemButton15 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
294  itemBoxSizer13->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
295 }
296 
298 {
299 
302  id_col->SetHeader().SetTitle(kSequenceIdColLabel);
303 
304  CRef<CSeqTable_column> expand_col(new CSeqTable_column());
305  expand_col->SetHeader().SetTitle("");
306  expand_col->SetHeader().SetField_name("expand");
307  expand_col->SetData().SetString();
308 
309  CRef<CSeqTable_column> country_col(new CSeqTable_column());
310  country_col->SetHeader().SetTitle("Country");
311  country_col->SetHeader().SetField_name("country");
312  country_col->SetData().SetString();
313 
314  CRef<CSeqTable_column> accession_col(new CSeqTable_column());
315  accession_col->SetHeader().SetTitle("Accession");
316  accession_col->SetHeader().SetField_name("accession");
317  accession_col->SetData().SetString();
318 
319  // bogus column to include last, otherwise deletion of the previous column will not work
320  CRef<CSeqTable_column> bogus_col(new CSeqTable_column());
321  bogus_col->SetHeader().SetTitle("");
322  bogus_col->SetHeader().SetField_name("");
323  bogus_col->SetData().SetString();
324 
326  table->SetColumns().push_back(id_col);
327  table->SetColumns().push_back(expand_col);
328  table->SetColumns().push_back(country_col);
329  table->SetColumns().push_back(accession_col);
330  table->SetColumns().push_back(bogus_col);
331 
332  size_t row = 0;
333  for( vector<pair<string,string> >::const_iterator it = m_invalid_countries.begin(); it != m_invalid_countries.end(); ++it)
334  {
335  string country = it->first;
336  string accession = it->second;
337 
338  CRef<CSeq_id> id(new CSeq_id());
339  id->SetLocal().SetId(static_cast<CObject_id::TId>(row));
340 
341  id_col->SetData().SetId().push_back(id);
342  expand_col->SetData().SetString().push_back("");
343  country_col->SetData().SetString().push_back(country);
344  accession_col->SetData().SetString().push_back(accession);
345  bogus_col->SetData().SetString().push_back("");
346  row++;
347  }
348 
349  table->SetNum_rows(static_cast<CSeq_table::TNum_rows>(row));
350 
351  return table;
352 }
353 
354 
356 {
358  size_t row = 0;
359  for( vector<pair<string,string> >::const_iterator it = m_invalid_countries.begin(); it != m_invalid_countries.end(); ++it)
360  {
361  string country = it->first;
362  string accession = it->second;
363 
364  string new_country;
365  try
366  {
367  if (row < values_table->GetColumn("country").GetData().GetString().size())
368  new_country = values_table->GetColumn("country").GetData().GetString()[row];
369  } catch(CSeqTableException& ) {}
370 
371  if (new_country != country && !new_country.empty())
372  {
373  result[country] = new_country;
374  }
375  row++;
376  }
377 
378  return result;
379 }
380 
382 {
383  CRef<CSeq_table> values_table = m_GridPanel->GetValuesTable();
384  map<string,string> fixed_countries = GetValuesFromValuesTable(values_table);
385  return fixed_countries;
386 }
387 
389 {
390  return "Invalid operation in Bulk Country Edit";
391 }
392 
393 
394 /*!
395  * Should we show tooltips?
396  */
397 
399 {
400  return true;
401 }
402 
403 /*!
404  * Get bitmap resources
405  */
406 
407 wxBitmap CBulkCountryEdit::GetBitmapResource( const wxString& name )
408 {
409  // Bitmap retrieval
410 ////@begin CBulkCountryEdit bitmap retrieval
411  wxUnusedVar(name);
412  return wxNullBitmap;
413 ////@end CBulkCountryEdit bitmap retrieval
414 }
415 
416 /*!
417  * Get icon resources
418  */
419 
420 wxIcon CBulkCountryEdit::GetIconResource( const wxString& name )
421 {
422  // Icon retrieval
423 ////@begin CBulkCountryEdit icon retrieval
424  wxUnusedVar(name);
425  return wxNullIcon;
426 ////@end CBulkCountryEdit icon retrieval
427 }
428 
429 /*!
430  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
431  */
432 
433 
434 /*!
435  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
436  */
437 
438 void CBulkCountryEdit::OnClickCancel( wxCommandEvent& event )
439 {
440  bool modified = m_GridPanel->GetModified() | m_AecrPanel->GetModified();
441  if (modified)
442  {
443  wxMessageDialog dlg(this,_("Discard modifications?"), _("Attention"),wxOK|wxCANCEL|wxCENTRE);
444  if (dlg.ShowModal() == wxID_OK)
445  {
446  event.Skip();
447  }
448  }
449  else
450  event.Skip();
451 
452 }
453 
CBioseq_Handle –.
~CBulkCountryEdit()
Destructor.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Country Modifiers That Could Not Be Autocorrected"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CBulkCountryEdit()
Constructors.
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
void OnClickCancel(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
map< string, string > GetValuesFromValuesTable(CRef< objects::CSeq_table >)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool IsReadOnlyColumn(string column_name)
CSeqTableGridPanel * m_GridPanel
CApplyEditconvertPanel * m_AecrPanel
CStringConstraintSelect * m_StringConstraintPanel
vector< pair< string, string > > m_invalid_countries
string GetErrorMessage()
CRef< objects::CSeq_table > GetChoices(CRef< objects::CSeq_table > values_table)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CRef< objects::CSeq_table > GetValuesTable()
map< string, string > GetValues()
void AddCommand(IEditCommand &command)
static bool IsValid(const string &country)
Definition: SubSource.cpp:3304
static string CountryFixupItem(const string &input, bool capitalize_after_colon)
Definition: SubSource.cpp:4812
bool m_capitalize_after_colon
void x_ApplyToDescriptors(const objects::CSeq_entry &se, CCmdComposite *composite)
map< string, string > m_fixed_countries
void x_ApplyToSeqAndFeat(CCmdComposite *composite)
vector< pair< string, string > > m_invalid_countries
bool x_ApplyToBioSource(objects::CBioSource &biosource)
objects::CSeq_entry_Handle m_Seh
CRef< CCmdComposite > GetCommand(objects::CSeq_entry_Handle tse, bool capitalize_after_colon)
CFeat_CI –.
Definition: feat_ci.hpp:64
CScope –.
Definition: scope.hpp:92
Seq-loc and seq-align mapper exceptions.
void MakeColumnReadOnly(int pos, bool val=true)
wxGrid * GetGrid(void)
void InitColumnCollapse(int col)
CRef< objects::CSeq_table > GetValuesTable()
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const CSeqTable_column & GetColumn(CTempString column_name) const
Definition: Seq_table.cpp:65
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
USING_SCOPE(objects)
static string s_GetAccession(CBioseq_Handle bsh)
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
const char * kSequenceIdColLabel
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
CConstRef< CSeq_id > GetSeqId(void) const
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
CSeq_entry_Handle GetSeq_entryHandle(CDataLoader *loader, const TBlobId &blob_id, EMissing action=eMissing_Default)
Get Seq-entry handle by its blob-id, with possible loading.
Definition: scope.cpp:113
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TColumns & GetColumns(void) const
Get the Columns member data.
Definition: Seq_table_.hpp:433
void SetHeader(THeader &value)
Assign a value to Header data member.
vector< CRef< CSeqTable_column > > TColumns
Definition: Seq_table_.hpp:92
void SetData(TData &value)
Assign a value to Data data member.
const TString & GetString(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
static int version
Definition: mdb_load.c:29
const struct ncbi::grid::netcache::search::fields::SIZE size
#define EDIT_EACH_SUBSOURCE_ON_BIOSOURCE(Itr, Var)
static static static wxID_ANY
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define FOR_EACH_SEQDESC_ON_SEQENTRY(Itr, Var)
FOR_EACH_SEQDESC_ON_SEQENTRY EDIT_EACH_SEQDESC_ON_SEQENTRY.
#define row(bind, expected)
Definition: string_bind.c:73
SAnnotSelector –.
else result
Definition: token2.c:20
Modified on Wed Apr 17 13:10:56 2024 by modify_doxy.py rev. 669887