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

Go to the SVN repository for this file.

1 /* $Id: group_alignments_tool_manager.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: Mike DiCuccio
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <serial/typeinfo.hpp>
35 
38 
39 #include <gui/objutils/label.hpp>
41 
45 
46 
49 
50 
52 : CAlgoToolManagerBase("Group Alignments",
53  "",
54  "Group alignments according to sequence properties",
55  "Group alignments according to sequence properties",
56  "https://www.ncbi.nlm.nih.gov/tools/gbench/",
57  "Alignment Creation"),
58  m_ParamsPanel(NULL)
59 {
60 }
61 
62 
64 {
65  return "group_alignments_tool_manager";
66 }
67 
68 
70 {
71  return "Group Alignments Tool";
72 }
73 
74 
76 {
78 
80 }
81 
82 
84 {
86 
88 }
89 
90 
92 {
93  if(m_ParamsPanel == NULL) {
95 
97  m_ParamsPanel->Hide(); // to reduce flicker
100 
101  m_ParamsPanel->SetRegistryPath(m_RegPath + ".ParamsPanel");
103  }
104  return true;
105 }
106 
107 
109 {
112 }
113 
114 
116 {
117  string err;
118  if(m_Params.m_Alignments.size() == 0) {
119  err = "Please select at least one set of alignments!";
120  }
121  if( ! err.empty()) {
123  return false;
124  }
125  return true;
126 }
127 
128 
129 /// select only Seq-aligns
131 {
132  m_Params.m_Alignments.clear();
133  m_Alignments.clear();
134  ITERATE(vector<TConstScopedObjects>, it, m_InputObjects) {
135  ITERATE(TConstScopedObjects, it2, *it) {
136  const CSeq_align* align = dynamic_cast<const CSeq_align*>(it2->object.GetPointerOrNull());
137  if (align) m_Alignments.push_back(*it2);
138  }
139  }
140 
141  if (m_Alignments.empty()) {
142  x_ConvertInputObjects(CSeq_align::GetTypeInfo(), m_Alignments);
143  }
144 }
145 
146 
148 {
149  return m_ParamsPanel;
150 }
151 
152 
154 {
155  return &m_Params;
156 }
157 
158 
160 {
162  return job;
163 }
164 
165 
166 ///////////////////////////////////////////////////////////////////////////////
167 /// CGroupAlignmentsJob
168 
170 : m_Params(params)
171 {
172  CFastMutexGuard lock(m_Mutex);
173 
174  m_Descr = "Categorizing alignments"; //TODO
175 }
176 
177 
178 static string s_GetAnnotName(const CSeq_annot& annot)
179 {
180  /// determine a base name for the annotation
181  string annot_name;
182  if (annot.IsSetDesc()) {
183  ITERATE (CSeq_annot::TDesc::Tdata, iter, annot.GetDesc().Get()) {
184  const CAnnotdesc& desc = **iter;
185  if ( !desc.IsName() ) {
186  continue;
187  }
188 
189  annot_name = desc.GetName();
190  break;
191  }
192  }
193 
194  return annot_name;
195 }
196 
197 
199 {
201 
202  ///
203  /// assure we're all in one scope
204  ///
205  CRef<CScope> scope;
206  {{
207  ITERATE (TConstScopedObjects, iter, aligns) {
208  if ( !scope ) {
209  scope.Reset(const_cast<CScope*>(&*iter->scope));
210  } else if (scope != &*iter->scope) {
211  scope.Reset();
213  "All alignments must be within the same project");
214  }
215  }
216  }}
217 
218  ///
219  /// begin by seeding all our alignments in one annotation
220  /// we will iteratively operate on this list of annotations
221  /// performing all subdivision steps
222  ///
223  list< CRef<CSeq_annot> > annots;
224  {{
225  CRef<CSeq_annot> annot(new CSeq_annot);
226  ITERATE (TConstScopedObjects, iter, aligns) {
227  CObject* obj = const_cast<CObject*>(&*iter->object);
228  CRef<CSeq_align> align(dynamic_cast<CSeq_align*>(obj));
229  if (align) {
230  annot->SetData().SetAlign().push_back(align);
231  }
232  }
233 
234  annots.push_back(annot);
235  }}
236 
237  CAlignGroup annot_group;
238 
239  ///
240  /// group by sequence IDs
241  ///
242  if (m_Params.m_GroupBySeqId) {
243  list< CRef<CSeq_annot> > annots_out;
244  ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
245  const CSeq_annot& annot = **iter;
246  annot_group.GroupBySeqIds(annot.GetData().GetAlign(),
247  annots_out,
248  s_GetAnnotName(annot),
249  *scope);
250  }
251  annots.swap(annots_out);
252  }
253 
254  ///
255  /// group by sequence strands
256  ///
258  list< CRef<CSeq_annot> > annots_out;
259  ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
260  const CSeq_annot& annot = **iter;
261  annot_group.GroupByStrand(annot.GetData().GetAlign(),
262  annots_out,
263  s_GetAnnotName(annot),
264  *scope);
265  }
266  annots.swap(annots_out);
267  }
268 
269  ///
270  /// group by tax-ids
271  /// there is a choice here; group by all tax-ids supercedes group by same tax-id
272  ///
273  if (m_Params.m_GroupByTaxId) {
274  list< CRef<CSeq_annot> > annots_out;
275  ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
276  const CSeq_annot& annot = **iter;
277  annot_group.GroupByTaxIds(annot.GetData().GetAlign(),
278  annots_out,
279  s_GetAnnotName(annot),
280  *scope);
281  }
282  annots.swap(annots_out);
283  } else if (m_Params.m_GroupByLikeTaxId) {
284  list< CRef<CSeq_annot> > annots_out;
285  ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
286  const CSeq_annot& annot = **iter;
287  annot_group.GroupByLikeTaxIds(annot.GetData().GetAlign(),
288  annots_out,
289  s_GetAnnotName(annot),
290  *scope);
291  }
292  annots.swap(annots_out);
293  }
294 
295  ///
296  /// sequence type subdivisions
297  ///
298 
304  if (m_Params.m_GroupByEST) {
306  }
309  }
312  }
315  }
316  if (m_Params.m_GroupByWGS) {
318  }
319  if (m_Params.m_GroupByHTGS) {
321  }
324  }
325 
326  list< CRef<CSeq_annot> > annots_out;
327  ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
328  const CSeq_annot& annot = **iter;
329  annot_group.GroupBySequenceType(annot.GetData().GetAlign(),
330  annots_out,
331  s_GetAnnotName(annot),
332  *scope,
333  flags);
334  }
335  annots.swap(annots_out);
336  }
337 
338  ///
339  /// final packaging and reporting
340  ///
341  if (annots.size()) {
342  NON_CONST_ITERATE (list< CRef<CSeq_annot> >, iter, annots) {
343  CSeq_annot& annot = **iter;
345 
346  /// encode the name correctly
347  /// we previously used the 'name' not for a temporary computation
348  /// we make this the real 'name' that the object manager will understand
349  string name;
350  string tag = annot.GetName();
351  annot.ResetName();
352  CLabel::GetLabel(annot, &name, CLabel::eDefault, &*scope);
353  if ( !name.empty() ) {
354  name += ": ";
355  }
356  name += tag;
357  annot.SetNameDesc(name);
358 
359  /// now create a Project Item for the data
360  CRef<CProjectItem> item(new CProjectItem());
361  item->SetItem().SetAnnot(annot);
362  item->SetLabel(name);
363 
364  AddProjectItem(*item);
365  }
366  }
367 }
368 
369 
371 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAlgoToolManagerBase This is base class for simple algorithmic tool managers.
CUIObject m_Descriptor
describes the Manager's UI properties
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
SProjectSelectorParams m_ProjectParams
CAlgoToolManagerParamsPanel.
void GroupBySequenceType(const TAlignList &aligns, TAnnotList &align_groups, const string &annot_base_name, objects::CScope &scope, TSequenceFlags flags=fSequenceDefaults)
Group alignments into sequence-related categories.
void GroupByLikeTaxIds(const TAlignList &aligns, TAnnotList &align_groups, const string &annot_base_name, objects::CScope &scope)
Separate a set of alignments into groups that describe how the alignments relate taxonomically.
Definition: align_group.cpp:97
void GroupByTaxIds(const TAlignList &aligns, TAnnotList &align_groups, const string &annot_base_name, objects::CScope &scope)
Separate a set of alignments into groups that describe how the alignments relate taxonomically.
Definition: align_group.cpp:56
void GroupBySeqIds(const TAlignList &aligns, TAnnotList &align_groups, const string &annot_base_name, objects::CScope &scope, TSeqIdFlags flags=0)
Group alignments into bins for each set of seq-ids.
void GroupByStrand(const TAlignList &aligns, TAnnotList &align_groups, const string &annot_base_name, objects::CScope &scope)
Group alignments into bins for each set of strands.
CAnnotdesc –.
Definition: Annotdesc.hpp:66
CDataLoadingAppJob - a base class for Jobs loading data into projects.
void AddProjectItem(objects::CProjectItem &item)
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
CScope –.
Definition: scope.hpp:92
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetCreateDate(const CTime &dt)
Definition: Seq_annot.cpp:121
CTime –.
Definition: ncbitime.hpp:296
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
static uch flags
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
virtual IRegSettings * x_GetParamsAsRegSetting()
return a pointer to Parameters object as IRegSettings interface
virtual void x_InitProjectParams()
init m_ProjectParams, in particular can select target project based on the tool input
virtual bool x_ValidateParams()
validates user input in Parameters panel, report errors if any
virtual CDataLoadingAppJob * x_CreateLoadingJob()
factory method for creating the job that executes the tool algorithm override in derived classes
CGroupAlignmentsParamsPanel * m_ParamsPanel
virtual void x_CreateProjectItems()
override this function in derived classes and populate m_Items.
void SetParams(SGroupAlignmentsParams *params, TConstScopedObjects *objects)
virtual void SetRegistryPath(const string &path)
CAlgoToolManagerParamsPanel.
virtual void CleanUI()
override this function in a derived class and clean extra members
virtual void InitUI()
override this function in a derived class and initialize extra members
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
void x_SelectCompatibleInputObjects()
select only Seq-aligns
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
CGroupAlignmentsJob(const SGroupAlignmentsParams &params)
CGroupAlignmentsJob.
bool Create(wxWindow *parent, wxWindowID id=ID_CGROUPALIGNMENTSPARAMSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
virtual CAlgoToolManagerParamsPanel * x_GetParamsPanel()
returns a pointer to the parameters panel, override in derived classes
virtual bool x_CreateParamsPanelIfNeeded()
returns / creates Parameters panel, override in derived classes see cpp file for example
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
string m_Descr
mutex to sync our internals
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
CFastMutex m_Mutex
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eDefault
Definition: label.hpp:73
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
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
USING_SCOPE(objects)
static string s_GetAnnotName(const CSeq_annot &annot)
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
const Tdata & Get(void) const
Get the member data.
const TName & GetName(void) const
Get the Name member data.
Definition: Seq_annot_.hpp:805
const TDesc & GetDesc(void) const
Get the Desc member data.
Definition: Seq_annot_.hpp:852
bool IsSetDesc(void) const
used only for stand alone Seq-annots Check if a value has been assigned to Desc data member.
Definition: Seq_annot_.hpp:840
void ResetName(void)
Reset Name data member.
Definition: Seq_annot_.cpp:212
const TAlign & GetAlign(void) const
Get the variant data.
Definition: Seq_annot_.hpp:641
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
const TName & GetName(void) const
Get the variant data.
Definition: Annotdesc_.hpp:501
bool IsName(void) const
Check if variant Name is selected.
Definition: Annotdesc_.hpp:495
list< CRef< CAnnotdesc > > Tdata
const char * tag
void SelectProjectByObjects(TConstScopedObjects &objects, CProjectService *srv)
is all objects belong to the same project - selects the project
Modified on Sun Apr 14 05:26:42 2024 by modify_doxy.py rev. 669887