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

Go to the SVN repository for this file.

1 /* $Id: create_protein_id.cpp 40575 2018-03-14 14:55:43Z bollin $
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>
35 #include <objmgr/feat_ci.hpp>
36 #include <objmgr/util/sequence.hpp>
40 
41 
42 // For compilers that support precompilation, includes "wx/wx.h".
43 #include "wx/wxprec.h"
44 
45 #ifdef __BORLANDC__
46 #pragma hdrstop
47 #endif
48 
49 #ifndef WX_PRECOMP
50 #include "wx/wx.h"
51 #endif
52 
53 #include <wx/textdlg.h>
54 
56 
57 
58 
61 
62 void CCreateProteinId::apply(objects::CSeq_entry_Handle tse, ICommandProccessor* cmdProcessor, wxWindow *parent)
63 {
64  if (!tse)
65  return;
66 
67  string existing_db;
68  for (CBioseq_CI b_iter(tse, CSeq_inst::eMol_aa); b_iter; ++b_iter)
69  {
70  FOR_EACH_SEQID_ON_BIOSEQ(id_it, *b_iter->GetBioseqCore())
71  {
72  if ((*id_it)->IsGeneral() && (*id_it)->GetGeneral().IsSetDb() &&
73  (*id_it)->GetGeneral().GetDb() != "TMSMART" && (*id_it)->GetGeneral().GetDb() != "BankIt" && (*id_it)->GetGeneral().GetDb() != "NCBIFILE")
74  {
75  existing_db = (*id_it)->GetGeneral().GetDb();
76  break;
77  }
78  }
79  if (!existing_db.empty())
80  break;
81  }
82 
83  string dbname = wxGetTextFromUser(_("Database"),_("Create Protein IDs"), wxString(existing_db), parent).ToStdString();
84 
85  if (dbname.empty())
86  return;
87 
88  CRef<CCmdComposite> cmd(new CCmdComposite("Create Protein Ids"));
89 
90  for (CFeat_CI feat_ci(tse, CSeqFeatData::e_Cdregion); feat_ci; ++feat_ci)
91  {
92 
93  CConstRef<CSeq_feat> gene = sequence::GetBestGeneForCds(*feat_ci->GetSeq_feat(), tse.GetScope());
94 
95  if (gene && gene->GetData().GetGene().IsSetLocus_tag())
96  {
97  string locus_tag = gene->GetData().GetGene().GetLocus_tag();
98  if (locus_tag.empty())
99  continue;
100  create_protein_ids(feat_ci->GetSeq_feat_Handle(), dbname, locus_tag, feat_ci->GetScope(), cmd);
101  }
102  }
103 
104  cmdProcessor->Execute(cmd);
105 }
106 
107 void CCreateProteinId::create_protein_ids(CSeq_feat_Handle fh, const string &dbname, const string &locus_tag, CScope &scope, CRef<CCmdComposite> cmd)
108 {
109  const CSeq_feat &orig_feat = *fh.GetSeq_feat();
110  CRef<CSeq_feat> new_feat(new CSeq_feat());
111  new_feat->Assign(orig_feat);
112  CSeq_loc &loc = new_feat->SetProduct();
113 
114  CRef<CSeq_id> id(new CSeq_id);
115  id->SetGeneral().SetDb(dbname);
116  id->SetGeneral().SetTag().SetStr(locus_tag);
117 
118  if (!fh.IsSetProduct())
119  return;
120  CBioseq_Handle prot_bsh = scope.GetBioseqHandle(fh.GetProduct());
121  if (!prot_bsh || !prot_bsh.IsProtein())
122  return;
123 
124  CRef<CSeq_entry> new_prot(new CSeq_entry);
125  CRef<CBioseq> new_seq(new CBioseq);
126  new_seq->Assign(*prot_bsh.GetBioseqCore());
127  bool skip = false;
128  FOR_EACH_SEQID_ON_BIOSEQ(id_it, *new_seq)
129  {
130  if ((*id_it)->IsGeneral() && (*id_it)->GetGeneral().IsSetDb() &&
131  (*id_it)->GetGeneral().GetDb() != "TMSMART" && (*id_it)->GetGeneral().GetDb() != "BankIt" && (*id_it)->GetGeneral().GetDb() != "NCBIFILE")
132  {
133  skip = true;
134  break;
135  }
136  }
137  if (skip)
138  return;
139  CRef<CSeq_id> old_id;
140  EDIT_EACH_SEQID_ON_BIOSEQ(id_it, *new_seq)
141  {
142  if ((*id_it)->IsLocal())
143  {
144  old_id = *id_it;
145  *id_it = id;
146  break;
147  }
148  }
149 
150  if (!old_id)
151  new_seq->SetId().push_back(id);
152  else
153  {
154  EDIT_EACH_SEQANNOT_ON_BIOSEQ(annot, *new_seq)
155  {
156  EDIT_EACH_SEQFEAT_ON_SEQANNOT(prot_feat, **annot)
157  {
158  if ((*prot_feat)->IsSetData() && (*prot_feat)->GetData().IsProt() && (*prot_feat)->GetLocation().GetId()->IsLocal() && (*prot_feat)->GetLocation().GetId()->Match(*old_id))
159  {
160  (*prot_feat)->SetLocation().SetId(*id);
161  }
162  }
163  }
164 
165  if (loc.GetId()->IsLocal() && loc.GetId()->Match(*old_id))
166  {
167  loc.SetId(*id);
168  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(fh, *new_feat)));
169  }
170  }
171  new_prot->SetSeq(*new_seq);
172  cmd->AddCommand(*CRef<CCmdChangeSeqEntry>(new CCmdChangeSeqEntry(prot_bsh.GetSeq_entry_Handle(), new_prot)));
173 }
174 
175 void CCreateLocusTagGene::apply(objects::CSeq_entry_Handle tse, ICommandProccessor* cmdProcessor, wxWindow *parent)
176 {
177  if (!tse)
178  return;
179 
180 // string prefix = wxGetTextFromUser(_("Prefix"),_("Create locus-tag genes"), wxEmptyString, parent).ToStdString();
181  CCreateLocusTagGenesDlg dlg(parent);
182  if (dlg.ShowModal() != wxID_OK)
183  return;
184  string prefix = dlg.GetPrefix();
185 
186  if (prefix.empty())
187  return;
188  bool create_protein_ids = dlg.GetCreateProtIds();
189  string dbname = dlg.GetDatabase();
190  if (dbname.empty())
191  create_protein_ids = false;
192 
193  CRef<CCmdComposite> cmd(new CCmdComposite("Create locus-tag genes"));
194  int count = 5;
195  for (CFeat_CI feat_ci(tse, CSeqFeatData::e_Cdregion); feat_ci; ++feat_ci)
196  {
197 
198  CNcbiOstrstream ss;
199  ss << prefix << "_" << std::setw(4) << std::setfill('0') << count;
200  string locus_tag = CNcbiOstrstreamToString(ss);
201 
202  CConstRef<CSeq_feat> gene = sequence::GetBestGeneForCds(*feat_ci->GetSeq_feat(), tse.GetScope());
203  if (gene)
204  {
205  if (gene->GetData().GetGene().IsSetLocus_tag())
206  continue;
207 
208  CRef<CSeq_feat> new_feat(new CSeq_feat());
209  new_feat->Assign(*gene);
210  new_feat->SetData().SetGene().SetLocus_tag(locus_tag);
211  CSeq_feat_Handle fh = tse.GetScope().GetSeq_featHandle(*gene);
212  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(fh, *new_feat)));
213  count += 5;
214  }
215  else
216  {
217  CRef<CSeq_feat> new_feat(new CSeq_feat());
218  new_feat->SetData().SetGene().SetLocus_tag(locus_tag);
219  CRef<CSeq_loc> loc(new CSeq_loc);
220  loc->Assign(feat_ci->GetLocation());
221  new_feat->SetLocation(*loc);
222  if (feat_ci->IsSetPartial() && feat_ci->GetPartial()) {
223  new_feat->SetPartial(true);
224  }
225  CBioseq_Handle bsh = tse.GetScope().GetBioseqHandle(feat_ci->GetLocation());
227  cmd->AddCommand(*CRef<CCmdCreateFeat>(new CCmdCreateFeat(seh, *new_feat)));
228  count += 5;
229  }
230 
231  if (create_protein_ids)
232  CCreateProteinId::create_protein_ids(feat_ci->GetSeq_feat_Handle(), dbname, locus_tag, feat_ci->GetScope(), cmd);
233  }
234 
235  cmdProcessor->Execute(cmd);
236 }
237 
238 
239 /*
240  * CCreateLocusTagGenesDlg type definition
241  */
242 
243 IMPLEMENT_DYNAMIC_CLASS( CCreateLocusTagGenesDlg, wxDialog )
244 
245 
246 /*
247  * CCreateLocusTagGenesDlg event table definition
248  */
249 
250 BEGIN_EVENT_TABLE( CCreateLocusTagGenesDlg, wxDialog )
251 
252 ////@begin CCreateLocusTagGenesDlg event table entries
253 ////@end CCreateLocusTagGenesDlg event table entries
254 
256 
257 
258 /*
259  * CCreateLocusTagGenesDlg constructors
260  */
261 
263 {
264  Init();
265 }
266 
267 CCreateLocusTagGenesDlg::CCreateLocusTagGenesDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
268 {
269  Init();
270  Create(parent, id, caption, pos, size, style);
271 }
272 
273 
274 /*
275  * CCreateLocusTagGenesDlg creator
276  */
277 
278 bool CCreateLocusTagGenesDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
279 {
280 ////@begin CCreateLocusTagGenesDlg creation
281  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
282  wxDialog::Create( parent, id, caption, pos, size, style );
283 
284  CreateControls();
285  if (GetSizer())
286  {
287  GetSizer()->SetSizeHints(this);
288  }
289  Centre();
290 ////@end CCreateLocusTagGenesDlg creation
291  return true;
292 }
293 
294 
295 /*
296  * CCreateLocusTagGenesDlg destructor
297  */
298 
300 {
301 ////@begin CCreateLocusTagGenesDlg destruction
302 ////@end CCreateLocusTagGenesDlg destruction
303 }
304 
305 
306 /*
307  * Member initialisation
308  */
309 
311 {
312 ////@begin CCreateLocusTagGenesDlg member initialisation
313  m_Prefix = NULL;
315  m_Database = NULL;
316 ////@end CCreateLocusTagGenesDlg member initialisation
317 }
318 
319 
320 /*
321  * Control creation for CCreateLocusTagGenesDlg
322  */
323 
325 {
326 ////@begin CCreateLocusTagGenesDlg content construction
327  // Generated by DialogBlocks, 02/09/2015 10:52:05 (unregistered)
328 
329  CCreateLocusTagGenesDlg* itemDialog1 = this;
330 
331  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
332  itemDialog1->SetSizer(itemBoxSizer2);
333 
334  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
335  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_LEFT|wxALL, 5);
336 
337  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Prefix"), wxDefaultPosition, wxDefaultSize, 0 );
338  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
339 
340  m_Prefix = new wxTextCtrl( itemDialog1, ID_CREATE_LOCUSTAG_GENE_PREFIX, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
341  itemBoxSizer3->Add(m_Prefix, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
342 
343  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
344  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_LEFT|wxALL, 5);
345 
346  m_CreateProtIds = new wxCheckBox( itemDialog1, ID_CREATE_LOCUSTAG_GENES_PROT_ID, _("Also create protein IDs"), wxDefaultPosition, wxDefaultSize, 0 );
347  m_CreateProtIds->SetValue(false);
348  itemBoxSizer6->Add(m_CreateProtIds, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
349 
350  wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxHORIZONTAL);
351  itemBoxSizer2->Add(itemBoxSizer8, 0, wxALIGN_LEFT|wxALL, 5);
352 
353  wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, wxID_STATIC, _("Database"), wxDefaultPosition, wxDefaultSize, 0 );
354  itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
355 
356  m_Database = new wxTextCtrl( itemDialog1, ID_CREATE_LOCUSTAG_GENE_DATABASE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
357  itemBoxSizer8->Add(m_Database, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
358 
359  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
360  itemBoxSizer2->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
361 
362  wxButton* itemButton12 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
363  itemBoxSizer11->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
364 
365  wxButton* itemButton13 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
366  itemBoxSizer11->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
367 
368 ////@end CCreateLocusTagGenesDlg content construction
369 }
370 
371 
372 /*
373  * Should we show tooltips?
374  */
375 
377 {
378  return true;
379 }
380 
381 /*
382  * Get bitmap resources
383  */
384 
385 wxBitmap CCreateLocusTagGenesDlg::GetBitmapResource( const wxString& name )
386 {
387  // Bitmap retrieval
388 ////@begin CCreateLocusTagGenesDlg bitmap retrieval
389  wxUnusedVar(name);
390  return wxNullBitmap;
391 ////@end CCreateLocusTagGenesDlg bitmap retrieval
392 }
393 
394 /*
395  * Get icon resources
396  */
397 
398 wxIcon CCreateLocusTagGenesDlg::GetIconResource( const wxString& name )
399 {
400  // Icon retrieval
401 ////@begin CCreateLocusTagGenesDlg icon retrieval
402  wxUnusedVar(name);
403  return wxNullIcon;
404 ////@end CCreateLocusTagGenesDlg icon retrieval
405 }
406 
407 
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
static void apply(CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor, wxWindow *parent)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
static bool ShowToolTips()
Should we show tooltips?
CCreateLocusTagGenesDlg()
Constructors.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("Create locus-tag genes"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
static void create_protein_ids(CSeq_feat_Handle fh, const string &dbname, const string &locus_tag, CScope &scope, CRef< CCmdComposite > cmd)
static void apply(CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor, wxWindow *parent)
CFeat_CI –.
Definition: feat_ci.hpp:64
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
USING_SCOPE(objects)
#define ID_CREATE_LOCUSTAG_GENE_PREFIX
#define ID_CREATE_LOCUSTAG_GENES_PROT_ID
#define ID_CREATE_LOCUSTAG_GENE_DATABASE
#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
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
bool Match(const CSeq_id &sid2) const
Match() - TRUE if SeqIds are equivalent.
Definition: Seq_id.hpp:1065
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Override Assign() to incorporate cache invalidation.
Definition: Seq_loc.cpp:337
void SetId(CSeq_id &id)
set the 'id' field in all parts of this location
Definition: Seq_loc.cpp:3474
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
CMappedFeat GetBestGeneForCds(const CMappedFeat &cds_feat, CFeatTree *feat_tree=0, const SAnnotSelector *base_sel=0, CFeatTree::EBestGeneType lookup_type=CFeatTree::eBestGene_TreeOnly)
Definition: feature.cpp:3321
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
TBioseqCore GetBioseqCore(void) const
Get bioseq core structure.
virtual CConstRef< CSeq_feat > GetSeq_feat(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
virtual const CSeq_loc & GetProduct(void) const
bool IsSetProduct(void) const
bool IsProtein(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
CScope & GetScope(void) const
Get scope this handle belongs to.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsSetLocus_tag(void) const
systematic gene name (e.g., MI0001, ORF0069) Check if a value has been assigned to Locus_tag data mem...
Definition: Gene_ref_.hpp:781
const TLocus_tag & GetLocus_tag(void) const
Get the Locus_tag member data.
Definition: Gene_ref_.hpp:793
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
void SetPartial(TPartial value)
Assign a value to Partial data member.
Definition: Seq_feat_.hpp:971
void SetProduct(TProduct &value)
Assign a value to Product data member.
Definition: Seq_feat_.cpp:110
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TGene & GetGene(void) const
Get the variant data.
bool IsLocal(void) const
Check if variant Local is selected.
Definition: Seq_id_.hpp:775
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
TId & SetId(void)
Assign a value to Id data member.
Definition: Bioseq_.hpp:296
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6929
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
static const char * prefix[]
Definition: pcregrep.c:405
Utility macros and typedefs for exploring NCBI objects from seq.asn.
#define FOR_EACH_SEQID_ON_BIOSEQ(Itr, Var)
FOR_EACH_SEQID_ON_BIOSEQ EDIT_EACH_SEQID_ON_BIOSEQ.
Definition: seq_macros.hpp:308
#define EDIT_EACH_SEQFEAT_ON_SEQANNOT(Itr, Var)
Definition: seq_macros.hpp:413
#define EDIT_EACH_SEQANNOT_ON_BIOSEQ(Itr, Var)
Definition: seq_macros.hpp:266
#define EDIT_EACH_SEQID_ON_BIOSEQ(Itr, Var)
Definition: seq_macros.hpp:311
Modified on Mon Jul 15 05:36:19 2024 by modify_doxy.py rev. 669887