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

Go to the SVN repository for this file.

1 /* $Id: advanced_cleanup_tool.cpp 47080 2022-07-22 18:11:54Z 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: Roman Katargin
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <gui/objutils/label.hpp>
33 
36 
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 /// CAdvancedCleanupTool
43 : CAlgoToolManagerBase("Advanced Cleanup",
44  "",
45  "Remove redundant elements from alignments",
46  "Remove redundant elements from alignments",
47  "https://www.ncbi.nlm.nih.gov/tools/gbench/",
48  "Alignment Creation"),
49  m_Panel()
50 {
51 }
52 
54 {
55  return "advanced_cleanup_tool";
56 }
57 
58 
60 {
61  return "Advanced Cleanup Tool";
62 }
63 
65 {
67 
68  m_Panel = NULL;
69 }
70 
72 {
73  m_Panel = NULL;
75 }
76 
78 {
79  if (m_Panel == NULL) {
81 
83  wxDefaultPosition, wxSize(0, 0), SYMBOL_CADVANCEDCLEANUPPARAMSPANEL_STYLE);
86 
87  m_Panel->SetRegistryPath(m_RegPath + ".ParamsPanel");
89  }
90  return true;
91 }
92 
94 {
95  return true;
96 }
97 
99 {
100  m_Params.m_Objects.clear();
101  m_Alignments.clear();
102  ITERATE(vector<TConstScopedObjects>, it, m_InputObjects) {
103  ITERATE(TConstScopedObjects, it2, *it) {
104  const CSeq_align* align = dynamic_cast<const CSeq_align*>(it2->object.GetPointerOrNull());
105  if (align) m_Alignments.push_back(*it2);
106  }
107  }
108 
109  if (m_Alignments.empty())
110  x_ConvertInputObjects(CSeq_align::GetTypeInfo(), m_Alignments);
111 }
112 
114 {
116  panel->Create(m_ParentWindow);
117  return panel;
118 }
119 
121 {
122  return m_Panel;
123 }
124 
126 {
127  return &m_Params;
128 }
129 
130 ///////////////////////////////////////////////////////////////////////////////
131 /// CAdvancedCleanupJob
133 {
134 public:
136 
137 protected:
138  virtual void x_CreateProjectItems();
139 
140 protected:
142 };
143 
145 {
146  if (m_Panel) m_Params = m_Panel->GetData();
147  return new CAdvancedCleanupJob(m_Params);
148 }
149 
151  : m_Params(params)
152 {
153  m_Descr = "Advanced Cleanup Job";
154 }
155 
157 {
158  list< CRef< CSeq_align > > input_aligns, cleaned_aligns;
159 
160  CRef<CScope> scope;
161  for (auto& o : m_Params.GetObjects()) {
162  const CSeq_align* seq_align = dynamic_cast<const CSeq_align*>(o.object.GetPointer());
163  if (seq_align) {
164  if (!scope)
165  scope = o.scope;
166  input_aligns.emplace_back(const_cast<CSeq_align*>(seq_align));
167  }
168  }
169 
170  if (input_aligns.empty()) {
171  LOG_POST(Error << "Advanced Cleanup. Input alignments list is empty");
172  return;
173  }
174 
176 
177  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions());
179  CNcbiArguments argv(0, nullptr);
180  unique_ptr<CArgs> args(arg_desc->CreateArgs(argv));
181  cleanup.SetParams(*args);
182 
183  cleanup.SetScope(scope);
184 
186  switch (m_Params.GetQueryTpe()) {
189  break;
191  queryType = CAdvancedAlignCleanup::eRna;
192  break;
195  break;
196  default:
197  queryType = CAdvancedAlignCleanup::eInfer;
198  break;
199  };
200 
202  switch (m_Params.GetSplignDirection()) {
205  break;
208  break;
209  default :
211  break;
212  };
213 
214  cleanup.Cleanup(input_aligns, cleaned_aligns, queryType, m_Params.GetInvokeBest(), false, splignDir);
215 
216  if (cleaned_aligns.empty())
217  return;
218 
219  CRef<CSeq_annot> annot(new CSeq_annot());
220  auto& seqannot_align = annot->SetData().SetAlign();
221  for (auto& a : cleaned_aligns)
222  seqannot_align.push_back(a);
224 
225  string name("Cleaned Alignment: ");
226  CLabel::GetLabel(*annot, &name, CLabel::eDefault, &*scope);
227  if (!name.empty()) {
228  annot->SetNameDesc(name);
229  annot->SetTitleDesc(name);
230  }
231 
232  CRef<CProjectItem> pitem(new CProjectItem());
233 
234  pitem->SetItem().SetAnnot(*annot);
235  pitem->SetLabel(name);
236 
237  AddProjectItem(*pitem);
238 }
239 
#define SYMBOL_CADVANCEDCLEANUPPARAMSPANEL_STYLE
USING_SCOPE(ncbi::objects)
static void SetupArgDescriptions(CArgDescriptions &arg_desc)
CAdvancedCleanupJob.
virtual void x_CreateProjectItems()
override this function in derived classes and populate m_Items.
CAdvancedCleanupParams m_Params
CAdvancedCleanupJob(const CAdvancedCleanupParams &params)
virtual void SetRegistryPath(const string &path)
CAlgoToolManagerParamsPanel.
void SetObjects(TConstScopedObjects *objects)
void SetData(const CAdvancedCleanupParams &data)
bool Create(wxWindow *parent, wxWindowID id=ID_CADVANCEDCLEANUPPARAMSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
TConstScopedObjects GetObjects() const
CAlgoToolManagerBase This is base class for simple algorithmic tool managers.
virtual void InitUI()
override this function in a derived class and initialize extra members
string m_RegPath
registry path to the settings
wxWindow * m_ParentWindow
a window that will serve as a parent for our panels
virtual void CleanUI()
override this function in a derived class and clean extra members
void x_ConvertInputObjects(const CTypeInfo *typeInfo, map< string, TConstScopedObjects > &results)
vector< TConstScopedObjects > m_InputObjects
original input objects, the tool needs to select a subset of objects that can serve as valid input
CAlgoToolManagerParamsPanel.
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CDataLoadingAppJob - a base class for Jobs loading data into projects.
void AddProjectItem(objects::CProjectItem &item)
CNcbiArguments –.
Definition: ncbienv.hpp:236
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetCreateDate(const CTime &dt)
Definition: Seq_annot.cpp:121
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
CTime –.
Definition: ncbitime.hpp:296
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
static void cleanup(void)
Definition: ct_dynamic.c:30
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual bool x_CreateParamsPanelIfNeeded()
returns / creates Parameters panel, override in derived classes see cpp file for example
virtual IRegSettings * x_GetParamsAsRegSetting()
return a pointer to Parameters object as IRegSettings interface
CAdvancedCleanupParamsPanel * m_Panel
virtual void CleanUI()
override this function in a derived class and clean extra members
TConstScopedObjects m_Alignments
virtual bool x_ValidateParams()
validates user input in Parameters panel, report errors if any
virtual CAlgoToolManagerParamsPanel * x_GetParamsPanel()
returns a pointer to the parameters panel, override in derived classes
virtual void x_SelectCompatibleInputObjects()
virtual void InitUI()
override this function in a derived class and initialize extra members
CAdvancedCleanupParams m_Params
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual wxPanel * GetMaxPanel()
Return the panel that occupies max size on display, to calculate dialog window size.
virtual CDataLoadingAppJob * x_CreateLoadingJob()
factory method for creating the job that executes the tool algorithm override in derived classes
CAdvancedCleanupTool()
CAdvancedCleanupTool.
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
string m_Descr
mutex to sync our internals
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eDefault
Definition: label.hpp:73
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
void SetLabel(const TLabel &value)
Assign a value to Label data member.
void SetItem(TItem &value)
Assign a value to Item data member.
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_annot_.cpp:244
unsigned int a
Definition: ncbi_localip.c:102
static static static wxID_ANY
Modified on Wed Apr 17 13:10:07 2024 by modify_doxy.py rev. 669887