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

Go to the SVN repository for this file.

1 /* $Id: raw_seq_to_delta_by_n.cpp 47378 2023-02-27 20:09:44Z asztalos $
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 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34 
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38 
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42 
43 #include <wx/hyperlink.h>
44 
45 ////@begin includes
46 ////@end includes
47 
48 #include <objects/seq/Seq_gap.hpp>
49 #include <objects/seq/Seq_ext.hpp>
54 #include <objmgr/bioseq_ci.hpp>
57 
61 
62 
63 ////@begin XPM images
64 ////@end XPM images
65 
68 
69 
70 IMPLEMENT_DYNAMIC_CLASS( CRawSeqToDeltaByN, wxDialog )
71 
72 
73 
74 BEGIN_EVENT_TABLE( CRawSeqToDeltaByN, wxDialog )
76 
77 
78 /*!
79  * CRawSeqToDeltaByN constructors
80  */
81 
83 {
84  Init();
85 }
86 
88  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
89 {
90  Init();
91  Create(parent, id, caption, pos, size, style);
92 }
93 
94 
95 /*!
96  * CRawSeqToDeltaByN creator
97  */
98 
99 bool CRawSeqToDeltaByN::Create( wxWindow* parent,
100  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
101 {
102 ////@begin CRawSeqToDeltaByN creation
103  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
104  wxDialog::Create( parent, id, caption, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CRawSeqToDeltaByN creation
113 
114  return true;
115 }
116 
117 
118 /*!
119  * CRawSeqToDeltaByN destructor
120  */
121 
123 {
124 ////@begin CRawSeqToDeltaByN destruction
125 ////@end CRawSeqToDeltaByN destruction
126 }
127 
128 
129 /*!
130  * Member initialisation
131  */
132 
134 {
135  m_Panel = nullptr;
136 }
137 
138 
139 /*!
140  * Control creation for CRawSeqToDeltaByN
141  */
142 
144 {
145 ////@begin CRawSeqToDeltaByN content construction
146  CRawSeqToDeltaByN* itemDialog1 = this;
147 
148  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
149  itemDialog1->SetSizer(itemBoxSizer2);
150 
151  m_Panel = new CRawSeqToDeltaByNPanel(itemDialog1);
152  itemBoxSizer2->Add(m_Panel, 0, wxALIGN_CENTER_HORIZONTAL, 0);
153 
154  wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL);
155  itemBoxSizer2->Add(itemBoxSizer21, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
156 
157  wxButton* itemButton5 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
158  itemBoxSizer21->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
159 
160  wxButton* itemButton6 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
161  itemBoxSizer21->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  wxHyperlinkCtrl* itemHyperlinkCtrl = new wxHyperlinkCtrl( itemDialog1, wxID_HELP, _("Help"), wxT("https://www.ncbi.nlm.nih.gov/tools/gbench/manual9/#add-assembly-gaps"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE );
164  itemHyperlinkCtrl->SetForegroundColour(wxColour(192, 192, 192));
165  itemBoxSizer21->Add(itemHyperlinkCtrl, 0, wxALIGN_CENTER_VERTICAL, 5);
166 ////@end CRawSeqToDeltaByN content construction
167 
168 }
169 
170 /*!
171  * Should we show tooltips?
172  */
173 
175 {
176  return true;
177 }
178 
179 /*!
180  * Get bitmap resources
181  */
182 
183 wxBitmap CRawSeqToDeltaByN::GetBitmapResource( const wxString& name )
184 {
185  // Bitmap retrieval
186 ////@begin CRawSeqToDeltaByN bitmap retrieval
187  wxUnusedVar(name);
188  return wxNullBitmap;
189 ////@end CRawSeqToDeltaByN bitmap retrieval
190 }
191 
192 /*!
193  * Get icon resources
194  */
195 
196 wxIcon CRawSeqToDeltaByN::GetIconResource( const wxString& name )
197 {
198  // Icon retrieval
199 ////@begin CRawSeqToDeltaByN icon retrieval
200  wxUnusedVar(name);
201  return wxNullIcon;
202 ////@end CRawSeqToDeltaByN icon retrieval
203 }
204 
205 void CRawSeqToDeltaByN::apply(CSeq_entry_Handle tse, ICommandProccessor* cmdProcessor, string title)
206 {
207  NRawToDeltaSeq::SGapRequestInfo request;
208  m_Panel->GetMinMax(request.min_known, request.max_known, request.min_unknown, request.max_unknown);
209  m_Panel->GetAssemblyParams(request.is_assembly_gap, request.gap_type, request.linkage, request.linkage_evidence);
210 
211  if (tse) {
212  bool remove_alignment = false;
213  int count = 0;
214  request.adjust_cds = m_Panel->GetAdjustCDS();
215  request.keep_gap_length = m_Panel->GetKeepGapLength();
217  NRawToDeltaSeq::ConvertRawToDeltaByNsCommand(tse, request, remove_alignment, count);
218 
219  if (cmd) {
220  if (remove_alignment) {
221  int answer = wxMessageBox(_("Affected alignments will be removed, proceed?"), _("Remove alignments"), wxYES_NO | wxICON_QUESTION);
222  if (answer == wxYES) {
223  cmdProcessor->Execute(cmd.GetPointer());
224  }
225  }
226  else {
227  cmdProcessor->Execute(cmd.GetPointer());
228  }
229 
230  }
231  }
232 }
233 
234 
236 {
237  if (tse)
238  {
239  CScope &scope = tse.GetScope();
240  CRef<CCmdComposite> composite(new CCmdComposite("Delta Seq To Raw"));
241  bool alignment_affected = false;
242  for (CBioseq_CI bi(tse, CSeq_inst::eMol_na); bi; ++bi)
243  {
244  CBioseq_Handle bsh = *bi;
245  CRef<CBioseq> bseq( new CBioseq );
246  bseq->Assign(*bsh.GetCompleteBioseq());
247 
248  CSeq_inst& inst = bseq->SetInst();
249 
250  if (!inst.IsSetRepr() || inst.GetRepr() != CSeq_inst::eRepr_delta || !inst.IsSetExt())
251  {
252  continue;
253  }
254 
255  string iupacna;
256  NON_CONST_ITERATE(CSeq_ext::TDelta::Tdata, it, inst.SetExt().SetDelta().Set())
257  {
258  if ((*it)->IsLiteral())
259  {
260  if ((*it)->GetLiteral().IsSetSeq_data())
261  {
262  string str;
263  switch((*it)->GetLiteral().GetSeq_data().Which())
264  {
266  str = (*it)->GetLiteral().GetSeq_data().GetIupacna();
267  break;
269  CSeqConvert::Convert((*it)->GetLiteral().GetSeq_data().GetNcbi2na().Get(), CSeqUtil::e_Ncbi2na, 0, (*it)->GetLiteral().GetLength(), str, CSeqUtil::e_Iupacna);
270  break;
272  CSeqConvert::Convert((*it)->GetLiteral().GetSeq_data().GetNcbi4na().Get(), CSeqUtil::e_Ncbi4na, 0, (*it)->GetLiteral().GetLength(), str, CSeqUtil::e_Iupacna);
273  break;
275  CSeqConvert::Convert((*it)->GetLiteral().GetSeq_data().GetNcbi8na().Get(), CSeqUtil::e_Ncbi8na, 0, (*it)->GetLiteral().GetLength(), str, CSeqUtil::e_Iupacna);
276  break;
277  default:
278  break;
279  }
280  iupacna += str;
281  }
282 
283  if (!(*it)->GetLiteral().IsSetSeq_data() || (*it)->GetLiteral().GetSeq_data().IsGap())
284  {
285  TSeqPos length = (*it)->GetLiteral().GetLength();
286  iupacna += string(length,'N');
287  }
288  }
289  }
290 
292  inst.SetSeq_data().SetIupacna() = CIUPACna(iupacna);
293  inst.ResetExt();
295  composite->AddCommand(*cmd);
296  }
297 
298  cmdProcessor->Execute(composite.GetPointer());
299  }
300 }
301 
302 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
void AddCommand(IEditCommand &command)
CIUPACna –.
Definition: IUPACna.hpp:66
void GetMinMax(long &min_known, long &max_known, long &min_unknown, long &max_unknown)
void GetAssemblyParams(bool &is_assembly_gap, int &gap_type, int &linkage, int &linkage_evidence)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Add Assembly Gaps To Sequence"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 100), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CRawSeqToDeltaByN()
Constructors.
void apply(objects::CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor, string title)
static bool ShowToolTips()
Should we show tooltips?
void Init()
Initialises member variables.
static void DeltaSeqToRaw(objects::CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CRawSeqToDeltaByNPanel * m_Panel
CScope –.
Definition: scope.hpp:92
static SIZE_TYPE Convert(const CTempString &src, TCoding src_coding, TSeqPos pos, TSeqPos length, string &dst, TCoding dst_coding)
@ e_Ncbi8na
Definition: sequtil.hpp:52
@ e_Iupacna
Definition: sequtil.hpp:47
@ e_Ncbi4na
Definition: sequtil.hpp:50
@ e_Ncbi2na
Definition: sequtil.hpp:48
CSeq_entry_Handle –.
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
CRef< CCmdComposite > ConvertRawToDeltaByNsCommand(const objects::CSeq_entry_Handle &seh, const SGapRequestInfo &request, bool &remove_alignments, int &count)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
string
Definition: cgiapp.hpp:687
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.
CScope & GetScope(void) const
Get scope this handle belongs to.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TRepr GetRepr(void) const
Get the Repr member data.
Definition: Seq_inst_.hpp:565
void SetExt(TExt &value)
Assign a value to Ext data member.
Definition: Seq_inst_.cpp:147
bool IsSetRepr(void) const
Check if a value has been assigned to Repr data member.
Definition: Seq_inst_.hpp:546
bool IsSetExt(void) const
extensions for special types Check if a value has been assigned to Ext data member.
Definition: Seq_inst_.hpp:826
void SetInst(TInst &value)
Assign a value to Inst data member.
Definition: Bioseq_.cpp:86
void SetRepr(TRepr value)
Assign a value to Repr data member.
Definition: Seq_inst_.hpp:574
list< CRef< CDelta_seq > > Tdata
Definition: Delta_ext_.hpp:89
void SetSeq_data(TSeq_data &value)
Assign a value to Seq_data data member.
Definition: Seq_inst_.cpp:130
void ResetExt(void)
Reset Ext data member.
Definition: Seq_inst_.cpp:142
@ eRepr_delta
sequence made by changes (delta) to others
Definition: Seq_inst_.hpp:100
@ eRepr_raw
continuous sequence
Definition: Seq_inst_.hpp:94
@ e_Ncbi2na
2 bit nucleic acid code
Definition: Seq_data_.hpp:106
@ e_Iupacna
IUPAC 1 letter nuc acid code.
Definition: Seq_data_.hpp:104
@ e_Ncbi8na
8 bit extended nucleic acid code
Definition: Seq_data_.hpp:108
@ e_Ncbi4na
4 bit nucleic acid code
Definition: Seq_data_.hpp:107
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(objects)
static const char * str(char *buf, int n)
Definition: stats.c:84
Modified on Fri Dec 01 04:50:06 2023 by modify_doxy.py rev. 669887