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

Go to the SVN repository for this file.

1 /* $Id: bulk_other_add_panel.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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
34 #include <objmgr/bioseq_ci.hpp>
35 
36 ////@begin includes
37 ////@end includes
38 
41 //#include <gui/packages/pkg_sequence_edit/featedit_util.hpp>
43 #include <gui/objutils/utils.hpp>
46 #include <wx/stattext.h>
47 
48 ////@begin XPM images
49 ////@end XPM images
50 
52 
54 
55 /*!
56  * CBulkOtherAddPanel type definition
57  */
58 
59 IMPLEMENT_DYNAMIC_CLASS( CBulkOtherAddPanel, CBulkCmdPanel )
60 
61 
62 /*!
63  * CBulkOtherAddPanel event table definition
64  */
65 
66 BEGIN_EVENT_TABLE( CBulkOtherAddPanel, CBulkCmdPanel )
67 
68 ////@begin CBulkOtherAddPanel event table entries
70 
71 ////@end CBulkOtherAddPanel event table entries
72 
74 
75 
76 /*!
77  * CBulkOtherAddPanel constructors
78  */
79 
81 {
82  Init();
83 }
84 
85 CBulkOtherAddPanel::CBulkOtherAddPanel( wxWindow* parent, CSeq_entry_Handle seh, string key, bool add_location_panel, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86  : m_TopSeqEntry(seh), m_DefaultKey(key), CBulkCmdPanel(add_location_panel)
87 {
88  Init();
89  Create(parent, id, pos, size, style);
90 }
91 
92 
93 /*!
94  * CBulkOtherAddPanel creator
95  */
96 
97 bool CBulkOtherAddPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
98 {
99 ////@begin CBulkOtherAddPanel creation
100  CBulkCmdPanel::Create( parent, id, pos, size, style );
101 
102  CreateControls();
103  if (GetSizer())
104  {
105  GetSizer()->SetSizeHints(this);
106  }
107  Centre();
108 ////@end CBulkOtherAddPanel creation
109  return true;
110 }
111 
112 
113 /*!
114  * CBulkOtherAddPanel destructor
115  */
116 
118 {
119 ////@begin CBulkOtherAddPanel destruction
120 ////@end CBulkOtherAddPanel destruction
121 }
122 
123 
124 /*!
125  * Member initialisation
126  */
127 
129 {
130 ////@begin CBulkOtherAddPanel member initialisation
133  m_Locus = NULL;
134  m_GeneDesc = NULL;
135  m_Comment = NULL;
136  m_Location = NULL;
137 ////@end CBulkOtherAddPanel member initialisation
139  m_QualFeat.Reset(new CSeq_feat());
140  m_QualFeat->SetData().SetImp().SetKey("misc_feature");
141 }
142 
143 
144 /*!
145  * Control creation for CBulkOtherAddPanel
146  */
147 
149 {
150 ////@begin CBulkOtherAddPanel content construction
151  CBulkOtherAddPanel* itemCBulkCmdPanel1 = this;
152 
153  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
154  itemCBulkCmdPanel1->SetSizer(itemBoxSizer2);
155 
156  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
157  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxALL, 5);
158 
159  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
160  itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
161 
162  wxStaticText* itemStaticText5 = new wxStaticText( itemCBulkCmdPanel1, wxID_STATIC, _("Feature Type"), wxDefaultPosition, wxDefaultSize, 0 );
163  itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
164 
165  wxArrayString m_FeatureTypeStrings;
166  m_FeatureType = new wxListBox( itemCBulkCmdPanel1, ID_FEATURE_TYPE_LISTBOX, wxDefaultPosition, wxDefaultSize, m_FeatureTypeStrings, wxLB_SINGLE );
167  itemBoxSizer4->Add(m_FeatureType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
168 
169  m_GBQualSizer = new wxBoxSizer(wxVERTICAL);
170  itemBoxSizer3->Add(m_GBQualSizer, 0, wxGROW|wxALL, 5);
171 
172  wxFlexGridSizer* itemFlexGridSizer8 = new wxFlexGridSizer(0, 2, 0, 0);
173  itemBoxSizer2->Add(itemFlexGridSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
174 
175  wxStaticText* itemStaticText9 = new wxStaticText( itemCBulkCmdPanel1, wxID_STATIC, _("Gene Symbol"), wxDefaultPosition, wxDefaultSize, 0 );
176  itemFlexGridSizer8->Add(itemStaticText9, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
177 
178  m_Locus = new wxTextCtrl( itemCBulkCmdPanel1, ID_TEXTCTRL11, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
179  itemFlexGridSizer8->Add(m_Locus, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
180 
181  wxStaticText* itemStaticText11 = new wxStaticText( itemCBulkCmdPanel1, wxID_STATIC, _("Gene Description"), wxDefaultPosition, wxDefaultSize, 0 );
182  itemFlexGridSizer8->Add(itemStaticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
183 
184  m_GeneDesc = new wxTextCtrl( itemCBulkCmdPanel1, ID_TEXTCTRL12, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
185  itemFlexGridSizer8->Add(m_GeneDesc, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
186 
187  wxStaticText* itemStaticText13 = new wxStaticText( itemCBulkCmdPanel1, wxID_STATIC, _("Comment"), wxDefaultPosition, wxDefaultSize, 0 );
188  itemFlexGridSizer8->Add(itemStaticText13, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190  m_Comment = new wxTextCtrl( itemCBulkCmdPanel1, ID_TEXTCTRL14, wxEmptyString, wxDefaultPosition, wxSize(300, 70), wxTE_MULTILINE );
191  itemFlexGridSizer8->Add(m_Comment, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
192 
194  {
195  m_Location = new CBulkLocationPanel( itemCBulkCmdPanel1, ID_WINDOW1, wxDefaultPosition, wxSize(100, 100), wxSIMPLE_BORDER );
196  itemBoxSizer2->Add(m_Location, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
197  }
198 
199  itemBoxSizer2->Add(500, 0, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
200 
201 ////@end CBulkOtherAddPanel content construction
202 
203  x_ListFeatures();
204 
205  m_GBQualPanel = new CGBQualPanel (this, *m_QualFeat);
206  m_GBQualSizer->Add(m_GBQualPanel, 1, wxGROW|wxALL, 0);
207  x_ChangeFeatureType("Gene");
208 
209 }
210 
211 static bool s_IsRNAFeature(int feat_subtype)
212 {
213  if (feat_subtype == CSeqFeatData::eSubtype_preRNA
214  || feat_subtype == CSeqFeatData::eSubtype_mRNA
215  || feat_subtype == CSeqFeatData::eSubtype_tRNA
216  || feat_subtype == CSeqFeatData::eSubtype_rRNA
217  || feat_subtype == CSeqFeatData::eSubtype_otherRNA
218  || feat_subtype == CSeqFeatData::eSubtype_misc_RNA
219  || feat_subtype == CSeqFeatData::eSubtype_precursor_RNA
220  || feat_subtype == CSeqFeatData::eSubtype_ncRNA
221  || feat_subtype == CSeqFeatData::eSubtype_tmRNA) {
222  return true;
223  }
224  return false;
225 }
226 
228 {
229  vector<string> listed_feat;
230  set<string> existing;
231  map<pair<int,int>,string> types;
232 
233  listed_feat.push_back("Gene");
234  listed_feat.push_back("misc_feature");
235  existing.insert(listed_feat[0]);
236  existing.insert(listed_feat[1]);
237 
238  vector<const CFeatListItem *> featlist = GetSortedFeatList(m_TopSeqEntry);
239  ITERATE(vector<const CFeatListItem *>, feat_it, featlist) {
240  const CFeatListItem& item = **feat_it;
241  string desc = item.GetDescription();
242  int feat_type = item.GetType();
244  if (feat_type == CSeqFeatData::e_Imp
246  && !CSeqFeatData::IsRegulatory(feat_subtype)) {
247  types[pair<int,int>(feat_type,feat_subtype)] = desc;
248  if (existing.find(desc) == existing.end()) {
249  existing.insert(desc);
250  listed_feat.push_back(desc);
251  }
252  }
253  }
254 
255  m_FeatureType->Clear();
256  for (size_t i = 0; i < listed_feat.size(); ++i) {
257  m_FeatureType->Append(ToWxString(listed_feat[i]));
258  }
259 
260  if (find(listed_feat.begin(), listed_feat.end(), m_DefaultKey) != listed_feat.end()) {
261  m_FeatureType->SetStringSelection(ToWxString(m_DefaultKey));
262  m_QualFeat->SetData().SetImp().SetKey(m_DefaultKey);
263  }
264 
265 }
266 
267 /*!
268  * Should we show tooltips?
269  */
270 
272 {
273  return true;
274 }
275 
276 /*!
277  * Get bitmap resources
278  */
279 
280 wxBitmap CBulkOtherAddPanel::GetBitmapResource( const wxString& name )
281 {
282  // Bitmap retrieval
283 ////@begin CBulkOtherAddPanel bitmap retrieval
284  wxUnusedVar(name);
285  return wxNullBitmap;
286 ////@end CBulkOtherAddPanel bitmap retrieval
287 }
288 
289 /*!
290  * Get icon resources
291  */
292 
293 wxIcon CBulkOtherAddPanel::GetIconResource( const wxString& name )
294 {
295  // Icon retrieval
296 ////@begin CBulkOtherAddPanel icon retrieval
297  wxUnusedVar(name);
298  return wxNullIcon;
299 ////@end CBulkOtherAddPanel icon retrieval
300 }
301 
303 {
304  string key = ToStdString(m_FeatureType->GetStringSelection());
305 
306  if (NStr::IsBlank(key)) {
308  return empty;
309  }
310  CRef<CCmdComposite> cmd (new CCmdComposite("Bulk Add Other Feature"));
311 
312  objects::CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na);
313  for ( ; b_iter ; ++b_iter ) {
314  AddOneCommand(*b_iter, cmd);
315  }
316 
317  return cmd;
318 }
319 
321 {
322 
323  string key = ToStdString(m_FeatureType->GetStringSelection());
324  string comment = ToStdString(m_Comment->GetValue());
325  string gene_symbol = ToStdString(m_Locus->GetValue());
326  string gene_desc = ToStdString(m_GeneDesc->GetValue());
329 
330  objects::CSeq_entry_Handle seh = bsh.GetSeq_entry_Handle();
331  if (!ShouldAddToExisting() && AlreadyHasFeature(bsh, key, comment)) {
332  return;
333  }
335  if (!loc) {
336  return;
337  }
338  if (!NStr::EqualNocase(key, "Gene")) {
339  CRef<objects::CSeq_feat> feat(new objects::CSeq_feat());
340  feat->SetData().SetImp().SetKey(key);
341  if (!NStr::IsBlank(comment)) {
342  feat->SetComment(comment);
343  }
344  feat->SetLocation().Assign(*loc);
345  if (feat->GetLocation().IsPartialStart(objects::eExtreme_Biological)
346  || feat->GetLocation().IsPartialStop(objects::eExtreme_Biological)) {
347  feat->SetPartial(true);
348  }
349  x_AddQuals(*feat);
350  cmd->AddCommand(*CRef<CCmdCreateFeat>(new CCmdCreateFeat(seh, *feat)));
351  }
352  if (!NStr::IsBlank(gene_symbol) || !NStr::IsBlank(gene_desc) || NStr::EqualNocase(key, "Gene")) {
353  // create gene feature
354  CRef<objects::CSeq_feat> new_gene(new objects::CSeq_feat());
355  new_gene->SetData().SetGene().SetLocus(gene_symbol);
356  if (!NStr::IsBlank(gene_desc)) {
357  new_gene->SetData().SetGene().SetDesc(gene_desc);
358  }
359  if (NStr::EqualNocase(key, "Gene") && !NStr::IsBlank(comment)) {
360  new_gene->SetComment(comment);
361  }
362  new_gene->SetLocation().Assign(*loc);
363  if (new_gene->GetLocation().IsPartialStart(objects::eExtreme_Biological)
364  || new_gene->GetLocation().IsPartialStop(objects::eExtreme_Biological)) {
365  new_gene->SetPartial(true);
366  }
367  x_AddGeneQuals(*new_gene);
368  cmd->AddCommand(*CRef<CCmdCreateFeat>(new CCmdCreateFeat(seh, *new_gene)));
369  }
370 }
371 
373 {
374  string key = ToStdString(m_FeatureType->GetStringSelection());
375  if (NStr::IsBlank(key)) {
376  return "You must select feature type!";
377  }
378  objects::CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na);
379  for ( ; b_iter ; ++b_iter ) {
380  objects::CSeq_entry_Handle seh = b_iter->GetSeq_entry_Handle();
381  CRef<objects::CSeq_loc> loc = GetLocForBioseq(*(b_iter->GetCompleteBioseq()));
382  if (!loc) {
383  return "You must specify valid location values!";
384  }
385  }
386  return "Unknown error";
387 }
388 
389 
391 {
394  if (NStr::EqualNocase(key, "Gene")) {
395  m_QualFeat->SetData().SetGene();
396  m_QualFeat->ResetQual();
397  } else {
398  m_QualFeat->SetData().SetImp().SetKey(key);
399  }
400  while (m_GBQualSizer->GetItemCount() > 0) {
401  int pos = 0;
402  m_GBQualSizer->GetItem(pos)->DeleteWindows();
403  m_GBQualSizer->Remove(pos);
404  }
405  m_GBQualPanel = new CGBQualPanel (this, *m_QualFeat);
406  m_GBQualSizer->Add(m_GBQualPanel, 1, wxGROW|wxALL, 0);
408 // if (NStr::EqualNocase(key, "Gene")) {
409 // m_GBQualPanel->Show(false);
410 // }
411  Layout();
412 }
413 
414 
415 /*!
416  * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_FEATURE_TYPE_LISTBOX
417  */
418 
420 {
421  string key = ToStdString(m_FeatureType->GetStringSelection());
423 }
424 
425 
426 void CBulkOtherAddPanel::x_AddQuals(objects::CSeq_feat& feat)
427 {
428  if (m_QualFeat && m_QualFeat->IsSetQual()) {
429  ITERATE(CSeq_feat::TQual, it, m_QualFeat->GetQual()) {
430  CRef<CGb_qual> q(new CGb_qual());
431  q->Assign(**it);
432  feat.SetQual().push_back(q);
433 
434  if ( NStr::EqualNocase(q->GetQual(), "mobile_element_type") && feat.IsSetData() && feat.GetData().IsImp()
435  && feat.GetData().GetImp().IsSetKey() && feat.GetData().GetImp().GetKey() == "repeat_region" )
436  {
437  feat.SetData().SetImp().SetKey("mobile_element");
438  }
439  }
440  }
441 }
442 
443 void CBulkOtherAddPanel::x_AddGeneQuals(objects::CSeq_feat& gene)
444 {
445  if (m_QualFeat && m_QualFeat->IsSetQual())
446  {
447  ITERATE(CSeq_feat::TQual, it, m_QualFeat->GetQual())
448  {
449  string val = (*it)->GetVal();
450  string qual = (*it)->GetQual();
451  if (qual == "locus")
452  gene.SetData().SetGene().SetLocus(val);
453  if (qual == "locus_tag")
454  gene.SetData().SetGene().SetLocus_tag(val);
455  if (qual == "allele")
456  gene.SetData().SetGene().SetAllele(val);
457  if (qual == "map")
458  gene.SetData().SetGene().SetMaploc(val);
459  if (qual == "gene_synonym")
460  gene.SetData().SetGene().SetSyn().push_back(val);
461  }
462  }
463 }
464 
465 
467 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
static bool s_IsRNAFeature(int feat_subtype)
USING_SCOPE(ncbi::objects)
#define ID_TEXTCTRL11
#define ID_FEATURE_TYPE_LISTBOX
#define ID_TEXTCTRL14
#define ID_TEXTCTRL12
#define ID_WINDOW1
CBioseq_Handle –.
CBulkLocationPanel * m_Location
virtual bool ShouldAddToExisting()
virtual CRef< objects::CSeq_loc > GetLocForBioseq(const objects::CBioseq &bioseq)
virtual CRef< CCmdComposite > GetCommand()
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual void AddOneCommand(const objects::CBioseq_Handle &bsh, CRef< CCmdComposite > cmd)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnFeatureTypeListboxSelected(wxCommandEvent &event)
wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_FEATURE_TYPE_LISTBOX
CBulkOtherAddPanel()
Constructors.
void Init()
Initialises member variables.
CRef< objects::CSeq_feat > m_QualFeat
void x_AddGeneQuals(objects::CSeq_feat &gene)
virtual string GetErrorMessage()
void x_ChangeFeatureType(const string &key)
static bool ShowToolTips()
Should we show tooltips?
objects::CSeq_entry_Handle m_TopSeqEntry
void x_AddQuals(objects::CSeq_feat &feat)
CFeatListItem - basic configuration data for one "feature" type.
int GetSubtype() const
string GetDescription() const
int GetType() const
static bool s_IsRarelyUsedOrDiscouragedFeatureType(int subtype)
virtual bool TransferDataToWindow()
virtual bool TransferDataFromWindow()
void PopulateGBQuals(objects::CSeq_feat &seq_feat)
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
static bool IsRegulatory(ESubtype subtype)
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#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 struct type types[]
Definition: type.c:22
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
vector< const objects::CFeatListItem * > GetSortedFeatList(objects::CSeq_entry_Handle seh, size_t max=numeric_limits< size_t >::max())
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CConstRef< CBioseq > GetCompleteBioseq(void) const
Get the complete bioseq.
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
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
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
vector< CRef< CGb_qual > > TQual
Definition: Seq_feat_.hpp:117
const TQual & GetQual(void) const
Get the Qual member data.
Definition: Gb_qual_.hpp:212
END_EVENT_TABLE()
int i
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
bool AlreadyHasFeature(objects::CBioseq_Handle bh, string key, string comment)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sun Apr 14 05:26:24 2024 by modify_doxy.py rev. 669887