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

Go to the SVN repository for this file.

1 /* $Id: apply_gcode.cpp 43146 2019-05-21 17:51:17Z filippov $
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 
30 #include <ncbi_pch.hpp>
34 #include <objmgr/feat_ci.hpp>
41 
42 #include <wx/button.h>
43 #include <wx/sizer.h>
44 
47 
48 
49 /*!
50  * CApplyGCode type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( CApplyGCode, wxDialog )
54 
55 
56 /*!
57  * CApplyGCode event table definition
58  */
59 
60 BEGIN_EVENT_TABLE( CApplyGCode, wxDialog )
61 
62 ////@begin CApplyGCode event table entries
63 ////@end CApplyGCode event table entries
64 
66 
67 
68 /*!
69  * CApplyGCode constructors
70  */
71 
73 {
74  Init();
75 }
76 
77 CApplyGCode::CApplyGCode( wxWindow* parent, objects::CSeq_entry_Handle seh,
78  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
79 : m_TopSeqEntry(seh)
80 {
81  Init();
82  Create(parent, id, caption, pos, size, style);
83 }
84 
85 
86 /*!
87  * CVectorTrimDlg creator
88  */
89 
90 bool CApplyGCode::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
91 {
92 ////@begin CApplyGCode creation
93  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
94  wxDialog::Create( parent, id, caption, pos, size, style );
95 
97  if (GetSizer())
98  {
99  GetSizer()->SetSizeHints(this);
100  }
101  Centre();
102 ////@end CApplyGCode creation
103 
104  return true;
105 }
106 
107 
108 /*!
109  * CApplyGCode destructor
110  */
111 
113 {
114 ////@begin CApplyGCode destruction
115 ////@end CApplyGCode destruction
116 }
117 
118 
119 /*!
120  * Member initialisation
121  */
122 
124 {
127  m_GenCodes.push_back(pair<string,int>((*it)->GetName(), (*it)->GetId()));
128  }
129 
130 
131 /* m_GenCodes.push_back(pair<string,int>("Standard", 1 ));
132  m_GenCodes.push_back(pair<string,int>("Vertebrate Mitochondrial", 2 ));
133  m_GenCodes.push_back(pair<string,int>("Yeast Mitochondrial", 3 ));
134  m_GenCodes.push_back(pair<string,int>("Mold Mitochondrial, etc.", 4 ));
135  m_GenCodes.push_back(pair<string,int>("Invertebrate Mitochondrial", 5 ));
136  m_GenCodes.push_back(pair<string,int>("Ciliate Nuclear, etc.", 6 ));
137  m_GenCodes.push_back(pair<string,int>("Echinoderm Mitochondrial, etc.", 9 ));
138  m_GenCodes.push_back(pair<string,int>("Euplotid Nuclear", 10 ));
139  m_GenCodes.push_back(pair<string,int>("Bacterial, Archaeal and Plant Plastid", 11 ));
140  m_GenCodes.push_back(pair<string,int>("Alternative Yeast Nuclear", 12 ));
141  m_GenCodes.push_back(pair<string,int>("Ascidian Mitochondrial", 13 ));
142  m_GenCodes.push_back(pair<string,int>("Alternative Flatworm Mitochondrial", 14 ));
143  m_GenCodes.push_back(pair<string,int>("Blepharisma Macronuclear", 15 ));
144  m_GenCodes.push_back(pair<string,int>("Chlorophycean Mitochondrial", 16 ));
145  m_GenCodes.push_back(pair<string,int>("Trematode Mitochondrial", 21 ));
146  m_GenCodes.push_back(pair<string,int>("Scenedesmus obliquus Mitochondrial", 22 ));
147  m_GenCodes.push_back(pair<string,int>("Thraustochytrium Mitochondrial", 23 ));
148  m_GenCodes.push_back(pair<string,int>("Pterobranchia Mitochondrial", 24 ));
149  m_GenCodes.push_back(pair<string,int>("Candidate Division SR1 and Gracilibacteria", 25 ));
150 */
151 }
152 
153 
154 /*!
155  * Control creation for CApplyGCode
156  */
157 
159 {
160  CApplyGCode* itemDialog1 = this;
161 
162  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
163  itemDialog1->SetSizer(itemBoxSizer2);
164 
165  wxArrayString codes;
166  codes.Add(wxEmptyString);
167  for (size_t i = 0; i < m_GenCodes.size(); i++)
168  {
169  wxString str;
170  str << m_GenCodes[i].second << " " << m_GenCodes[i].first;
171  codes.Add(str);
172  }
173 
174  m_Code = new wxChoice( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, codes, 0 );
175  m_Code->SetSelection(0);
176  itemBoxSizer2->Add(m_Code, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
177 
178  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
179  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
180 
181  wxButton* itemButton13 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
182  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
183 
184  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
185  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
186 }
187 
188 
189 /*!
190  * Should we show tooltips?
191  */
192 
194 {
195  return true;
196 }
197 
198 /*!
199  * Get bitmap resources
200  */
201 
202 wxBitmap CApplyGCode::GetBitmapResource( const wxString& name )
203 {
204  // Bitmap retrieval
205 ////@begin CVectorTrimDlg bitmap retrieval
206  wxUnusedVar(name);
207  return wxNullBitmap;
208 ////@end CVectorTrimDlg bitmap retrieval
209 }
210 
211 /*!
212  * Get icon resources
213  */
214 
215 wxIcon CApplyGCode::GetIconResource( const wxString& name )
216 {
217  // Icon retrieval
218 ////@begin CVectorTrimDlg icon retrieval
219  wxUnusedVar(name);
220  return wxNullIcon;
221 ////@end CVectorTrimDlg icon retrieval
222 }
223 
225 {
226  CRef<CCmdComposite> cmd(new CCmdComposite("Batch Apply Genetic Code"));
228  return cmd;
229 }
230 
232 {
233  x_ApplyToDescriptors(*(m_TopSeqEntry.GetCompleteSeq_entry()), composite);
234  for (CFeat_CI feat_it(m_TopSeqEntry, SAnnotSelector(CSeqFeatData::e_Biosrc)); feat_it; ++feat_it) {
235  CRef<CSeq_feat> new_feat(new CSeq_feat());
236  new_feat->Assign(feat_it->GetOriginalFeature());
237  x_ApplyToBioSource(new_feat->SetData().SetBiosrc());
238  CRef<CCmdChangeSeq_feat> cmd(new CCmdChangeSeq_feat(*feat_it, *new_feat));
239  composite->AddCommand(*cmd);
240  }
241 }
242 
244 {
245  CScope& scope = m_TopSeqEntry.GetScope();
247  if ((*it)->IsSource()) {
248  const CSeqdesc& orig_desc = **it;
249  CRef<CSeqdesc> new_desc(new CSeqdesc);
250  new_desc->Assign(orig_desc);
251  x_ApplyToBioSource(new_desc->SetSource());
252  CRef<CCmdChangeSeqdesc> cmd(new CCmdChangeSeqdesc(scope.GetSeq_entryHandle(se), orig_desc, *new_desc));
253  composite->AddCommand(*cmd);
254  }
255  }
256 
257  if (se.IsSet()) {
259  x_ApplyToDescriptors(**it, composite);
260  }
261  }
262 }
263 
265 {
266  int id = 0;
267  if (m_Code->GetSelection() > 0)
268  {
269  id = m_GenCodes[m_Code->GetSelection() - 1].second;
270  }
271 
272  if (biosource.IsSetGenome())
273  {
274  switch (biosource.GetGenome())
275  {
278  {
279  biosource.SetOrg().SetOrgname().SetMgcode() = id;
280  if (id == 0)
281  biosource.SetOrg().SetOrgname().ResetMgcode();
282  break;
283  }
292  {
293  biosource.SetOrg().SetOrgname().SetPgcode() = id;
294  if (id == 0)
295  biosource.SetOrg().SetOrgname().ResetPgcode();
296  break;
297  }
298  default: {
299  biosource.SetOrg().SetOrgname().SetGcode() = id;
300  if (id == 0)
301  biosource.SetOrg().SetOrgname().ResetGcode();
302  break;
303  }
304  }
305  }
306  else
307  {
308  biosource.SetOrg().SetOrgname().SetGcode() = id;
309  if (id == 0)
310  biosource.SetOrg().SetOrgname().ResetGcode();
311  }
312 }
313 
USING_SCOPE(objects)
void x_FindBioSource(CRef< CCmdComposite > composite)
void CreateControls()
Creates the controls and sizers.
CRef< CCmdComposite > GetCommand()
void Init()
Initialises member variables.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Batch Apply Genetic Code"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
Definition: apply_gcode.cpp:90
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
objects::CSeq_entry_Handle m_TopSeqEntry
Definition: apply_gcode.hpp:86
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
~CApplyGCode()
Destructor.
static bool ShowToolTips()
Should we show tooltips?
wxChoice * m_Code
Definition: apply_gcode.hpp:88
vector< pair< string, int > > m_GenCodes
Definition: apply_gcode.hpp:87
CApplyGCode()
Constructors.
Definition: apply_gcode.cpp:72
void x_ApplyToBioSource(objects::CBioSource &biosource)
void x_ApplyToDescriptors(const objects::CSeq_entry &se, CCmdComposite *composite)
void AddCommand(IEditCommand &command)
CFeat_CI –.
Definition: feat_ci.hpp:64
static const CGenetic_code_table & GetCodeTable(void)
CScope –.
Definition: scope.hpp:92
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TGenome GetGenome(void) const
Get the Genome member data.
Definition: BioSource_.hpp:422
bool IsSetGenome(void) const
Check if a value has been assigned to Genome data member.
Definition: BioSource_.hpp:397
void SetOrg(TOrg &value)
Assign a value to Org data member.
Definition: BioSource_.cpp:108
list< CRef< CGenetic_code > > Tdata
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const Tdata & Get(void) const
Get the member data.
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
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
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
Utility macros and typedefs for exploring NCBI objects from seqset.asn.
#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.
SAnnotSelector –.
Modified on Fri Sep 20 14:57:07 2024 by modify_doxy.py rev. 669887