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

Go to the SVN repository for this file.

1  /* $Id: withdraw_sequences.cpp 43728 2019-08-23 17:19:12Z 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>
31 
32 ////@begin includes
33 ////@end includes
34 #include <sstream>
35 
36 #include <objmgr/scope.hpp>
37 #include <objmgr/feat_ci.hpp>
38 #include <objmgr/seqdesc_ci.hpp>
43 #include <gui/objutils/utils.hpp>
46 
47 #include <wx/button.h>
48 #include <wx/statbox.h>
49 #include <wx/stattext.h>
50 
51 ////@begin XPM images
52 ////@end XPM images
53 
54 
55 
57 
58 
59 
60 IMPLEMENT_DYNAMIC_CLASS( CWithdrawSequences, wxDialog )
61 
62 
63 /*!
64  * CWithdrawSequences event table definition
65  */
66 
67 BEGIN_EVENT_TABLE( CWithdrawSequences, wxDialog )
68 
70 
71 
72 /*!
73  * CWithdrawSequences constructors
74  */
75 
77 {
78  Init();
79 }
80 
81 CWithdrawSequences::CWithdrawSequences( wxWindow* parent, objects::CSeq_entry_Handle seh,
82  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
83 {
84  this->m_TopSeqEntry = seh;
85  m_SetSeq.clear();
86  ReadBioseq(*(m_TopSeqEntry.GetCompleteSeq_entry()));
87  Init();
88  Create(parent, id, caption, pos, size, style);
89 }
90 
91 
92 /*!
93  * CVectorTrimDlg creator
94  */
95 
96 bool CWithdrawSequences::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CWithdrawSequences creation
99  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
100  wxDialog::Create( parent, id, caption, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CWithdrawSequences creation
109 
110  SetSize(wxSize(280, 550));
111  return true;
112 }
113 
114 
115 /*!
116  * CWithdrawSequences destructor
117  */
118 
120 {
121 ////@begin CWithdrawSequences destruction
122 ////@end CWithdrawSequences destruction
123 }
124 
125 
126 /*!
127  * Member initialisation
128  */
129 
131 {
132 }
133 
134 
135 /*!
136  * Control creation for CWithdrawSequences
137  */
138 
140 {
141  CWithdrawSequences* itemDialog1 = this;
142 
143  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
144  itemDialog1->SetSizer(itemBoxSizer2);
145 
146  m_IDPanel = new CIDSubpanel( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
147  itemBoxSizer2->Add(m_IDPanel, 1, wxGROW|wxALL, 5);
148 
149  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
150  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
151 
152  wxButton* itemButton13 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
153  itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
154 
155  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
156  itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
157 }
158 
159 
160 
161 /*!
162  * Should we show tooltips?
163  */
164 
166 {
167  return true;
168 }
169 
170 /*!
171  * Get bitmap resources
172  */
173 
174 wxBitmap CWithdrawSequences::GetBitmapResource( const wxString& name )
175 {
176  // Bitmap retrieval
177  wxUnusedVar(name);
178  return wxNullBitmap;
179 }
180 
181 /*!
182  * Get icon resources
183  */
184 
185 wxIcon CWithdrawSequences::GetIconResource( const wxString& name )
186 {
187  // Icon retrieval
188  wxUnusedVar(name);
189  return wxNullIcon;
190 }
191 
193 {
194  CRef<CCmdComposite> cmd( new CCmdComposite("Withdraw Sequences") );
195  vector< vector<int> > & subsets = GetSubsets();
196  if (this->m_TopSeqEntry && !subsets.empty() && !subsets.front().empty())
197  {
198  int i = subsets.front().front();
199  CBioseq_set_Handle grandparent = this->m_SetSeq[i].grandparent;
200  CBioseq_set_Handle parent = this->m_SetSeq[i].parent;
201 
202  CRef<objects::CBioseq_set> changed_set(new objects::CBioseq_set());
203  if (grandparent != parent)
204  {
205  changed_set->Assign(*grandparent.GetCompleteBioseq_set());
206  }
207  else
208  {
209  CRef<CSeq_entry> new_se(new CSeq_entry());
210  CRef<CBioseq_set> bss(new CBioseq_set());
211  bss->Assign(*parent.GetCompleteBioseq_set());
212  new_se->SetSet(*bss);
213  changed_set->SetSeq_set().push_back(new_se);
214  changed_set->SetClass(CBioseq_set::eClass_genbank);
215 
216  CRef<CSeqdesc> user_object( new CSeqdesc );
217  CSeqdesc_Base::TUser& user = user_object->SetUser();
218  user.SetType().SetStr("GbenchModification");
219  CRef<CUser_field> method = user.SetFieldRef("method");
220  method->SetValue("WithdrawSequences");
221  changed_set->SetDescr().Set().push_back( user_object );
222  }
223 
224  for (unsigned int s = 0; s < subsets.size(); s++)
225  {
226  PopulateSet(*changed_set, subsets[s]);
227  }
228  CCmdChangeBioseqSet *set_cmd = new CCmdChangeBioseqSet(grandparent, *changed_set);
229  cmd->AddCommand(*set_cmd);
230  }
231  return cmd;
232 }
233 
234 void CWithdrawSequences::PopulateSet(CBioseq_set& changed_set, const vector<int> &subset)
235 {
236  if (changed_set.CanGetSeq_set())
237  {
238  for ( unsigned int j = 0; j < subset.size(); j++)
239  {
240  int i = subset[j];
241  CRef<CSeq_entry> se(new CSeq_entry());
242  se->Assign(*m_SetSeq[i].entry.GetCompleteSeq_entry());
243  TakeFromSet(changed_set,se);
244  CopyDescrToEntry(*m_SetSeq[i].parent.GetCompleteBioseq_set(), *se);
245  changed_set.SetSeq_set().push_back(se);
246  }
247  }
248 }
249 
251 {
252  if (source.IsSetDescr())
253  {
254  bool title_present = false;
255  if (target.IsSetDescr())
256  {
257  for (CSeq_descr::Tdata::const_iterator desc = target.GetDescr().Get().begin(); desc != target.GetDescr().Get().end(); ++desc)
258  {
259  if ((*desc)->IsTitle() && !(*desc)->GetTitle().empty())
260  {
261  title_present = true;
262  break;
263  }
264  }
265  }
266  for (CSeq_descr::Tdata::const_iterator desc = source.GetDescr().Get().begin(); desc != source.GetDescr().Get().end(); ++desc)
267  {
268  if (title_present && (*desc)->IsTitle())
269  continue;
270  target.SetDescr().Set().push_back(*desc);
271  }
272  }
273 
274 
275 }
276 
278 {
279  vector<string> names;
280  vector< vector<int> > & subsets = GetSubsets();
281  for (unsigned int s = 0; s < subsets.size(); s++)
282  {
283  for ( unsigned int j = 0; j < subsets[s].size(); j++)
284  {
285  int i = subsets[s][j];
286  CConstRef<CSeq_entry> se = m_SetSeq[i].entry.GetCompleteSeq_entry();
287  if (se->IsSeq())
288  {
290  {
291  string name;
292  (*id)->GetLabel(&name);
293  names.push_back(name);
294  }
295  }
296  else if (se->IsSet() && se->GetSet().CanGetClass() && se->GetSet().GetClass() == CBioseq_set::eClass_nuc_prot )
297  {
299  {
300  string name;
301  (*id)->GetLabel(&name);
302  names.push_back(name);
303  }
304  }
305  }
306  }
307  return names;
308 }
309 
CBioseq_set_Handle –.
const CBioseq & GetNucFromNucProtSet(void) const
Definition: Bioseq_set.cpp:227
void TakeFromSet(objects::CBioseq_set &changed_set, CRef< objects::CSeq_entry > se)
void ReadBioseq(const objects::CSeq_entry &se)
vector< SSetSeqRecord > m_SetSeq
objects::CSeq_entry_Handle m_TopSeqEntry
Definition: Seq_entry.hpp:56
const CSeq_descr & GetDescr(void) const
Definition: Seq_entry.cpp:120
void SetDescr(CSeq_descr &value)
Definition: Seq_entry.cpp:134
bool IsSetDescr(void) const
Definition: Seq_entry.cpp:106
CUser_field & SetValue(int value)
set a data field to a given value Int8 and TGi values can be stored into 'str' field if the value doe...
Definition: User_field.hpp:283
CRef< CUser_field > SetFieldRef(const string &str, const string &delim=".", const string &obj_subtype=kEmptyStr, NStr::ECase use_case=NStr::eCase)
static bool ShowToolTips()
Should we show tooltips?
~CWithdrawSequences()
Destructor.
CRef< CCmdComposite > GetCommand()
CWithdrawSequences()
Constructors.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void PopulateSet(CBioseq_set &new_set, const vector< int > &subset)
void CopyDescrToEntry(const CBioseq_set &source, CSeq_entry &target)
vector< vector< int > > & GetSubsets()
void Init()
Initialises member variables.
void CreateControls()
Creates the controls and sizers.
vector< string > GetNames()
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool Create(wxWindow *parent, wxWindowID id=11300, const wxString &caption=_("Withdraw Sequences"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static const struct name_t names[]
static void Init(void)
Definition: cursor6.c:76
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetType(TType &value)
Assign a value to Type data member.
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
bool CanGetSeq_set(void) const
Check if it is safe to call GetSeq_set method.
TClass GetClass(void) const
Get the Class member data.
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 CanGetClass(void) const
Check if it is safe to call GetClass method.
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
@ eClass_genbank
converted genbank
const Tdata & Get(void) const
Get the member data.
Definition: Seq_descr_.hpp:166
TUser & SetUser(void)
Select the variant.
Definition: Seqdesc_.cpp:390
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
Definition: pointer.h:1149
#define FOR_EACH_SEQID_ON_BIOSEQ(Itr, Var)
FOR_EACH_SEQID_ON_BIOSEQ EDIT_EACH_SEQID_ON_BIOSEQ.
Definition: seq_macros.hpp:308
static static static wxID_ANY
Modified on Wed Apr 24 14:15:57 2024 by modify_doxy.py rev. 669887