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

Go to the SVN repository for this file.

1 /* $Id: vcf_search_tool.cpp 45888 2021-01-05 23:24:02Z rudnev $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 #include "vcf_search_tool.hpp"
36 
37 #include <corelib/ncbitime.hpp>
38 
42 
43 #include <gui/objutils/label.hpp>
44 #include <gui/objutils/utils.hpp>
46 
48 
49 #include <objmgr/util/sequence.hpp>
50 #include <objmgr/seq_map_ci.hpp>
51 
53 
54 #include <wx/sizer.h>
55 #include <wx/stattext.h>
56 #include <wx/choice.h>
57 #include <wx/srchctrl.h>
58 
59 
60 #define ID_COMBOBOX 10003
61 #define ID_TEXT 11414
62 
63 
66 
67 ///////////////////////////////////////////////////////////////////////////////
68 /// IDMSearchTool
70 {
71 }
72 
73 
75 {
76  static string name("VCF Search");
77  return name;
78 }
79 
80 
82 {
83  return new CVcfSearchTool();
84 }
85 
86 
88 {
89  return "";
90 }
91 
92 
94 {
95  CIRef<IDMSearchForm> form(new CVcfSearchForm(*this));
96  return form;
97 }
98 
99 
101 {
102  bool isCompatible(false);
103  ISeqLocSearchContext* sl_ctx = dynamic_cast<ISeqLocSearchContext*>(context);
104  if(sl_ctx) {
105  CVcfTrackData* vcf_data(dynamic_cast<CVcfTrackData*>(sl_ctx->GetNonAsnData()));
106  isCompatible = vcf_data != NULL;
107  }
108 // LOG_POST(Info << "CVcfSearchTool::IsCompatible(): " << isCompatible << ":" << " for " << context << " " << context->GetDMContextName());
109 
110  return isCompatible;
111 }
112 
113 
115 {
117  CVcfSearchQuery* f_query = dynamic_cast<CVcfSearchQuery*>(&query);
118  if(f_query) {
119  job.Reset(new CVcfSearchJob(*f_query));
120  }
121  return job;
122 }
123 
124 
125 
127 {
128  return "search_tool::vcf_search_tool";
129 }
130 
132 {
133  return "Datamining Tool - VCF search";
134 }
135 
136 
137 ///////////////////////////////////////////////////////////////////////////////
138 /// CVcfSearchQuery
139 CVcfSearchQuery::CVcfSearchQuery(vector<ISeqLocSearchContext*> VcfContexts, const string& ids)
140  : m_VcfContexts(VcfContexts),
141  m_Ids(ids)
142 {
143 }
144 
145 
146 ///////////////////////////////////////////////////////////////////////////////
147 /// CVcfSearchForm
148 
150 : m_Tool(&tool)
151 {
152 }
153 
154 
156 {
157  x_CreateWidgets();
158 }
159 
160 
162 {
164 
165 
166 
167  // x_UpdateData(eDDX_Set);
168 }
169 
170 
172 {
174 }
175 
176 
178 {
179 // CSearchFormBase::x_CreateWidgets(2, 3, true);
180 }
181 
182 
184 {
185  return m_Tool.GetPointer();
186 
187 }
188 
189 
190 wxSizer * CVcfSearchForm::GetWidget(wxWindow * parent)
191 {
192  if (!m_Sizer) {
193  wxFlexGridSizer * sz = new wxFlexGridSizer(1, 4, 0, 0);
194  sz->AddGrowableCol(3);
195  m_Sizer = sz;
196 
197  m_Sizer->Add(new wxStaticText( parent, wxID_STATIC, wxT("Search Context:"), wxDefaultPosition, wxDefaultSize, 0 ),
198  0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
199 
200  m_DbCombo = new wxChoice(parent, ID_COMBOBOX,
201  wxDefaultPosition, wxDefaultSize,
202  0, (const wxString*)NULL);
203 
204  m_Sizer->Add(m_DbCombo,1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
205 
206  m_Sizer->Add(new wxStaticText( parent, wxID_STATIC, wxT("Search Expression:"), wxDefaultPosition, wxDefaultSize, 0 ),
207  0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
208 
209  m_Text = new CSearchControl(parent, ID_TEXT, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
210  m_Sizer->Add(m_Text,1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
211 
212  }
213  return m_Sizer;
214 }
215 
217 {
219 }
220 
222 {
224 
225  vector<ISeqLocSearchContext*> VcfContexts;
226  for( size_t i = 0; i < m_Contexts.size(); i++ ) {
227  if (m_DbCombo->GetSelection() != 0 &&
228  m_DbCombo->GetSelection() != int(i + 1)) {
229  continue;
230  }
231  ISeqLocSearchContext* seq_ctx =
232  dynamic_cast<ISeqLocSearchContext*>(m_Contexts[i]);
233  VcfContexts.push_back(seq_ctx);
234  }
235 
236  ref = new CVcfSearchQuery(VcfContexts, ToStdString(m_Text->GetValue()));
237  return ref;
238 }
239 
240 
241 ///////////////////////////////////////////////////////////////////////////////
242 /// CVcfSearchJob
243 
245 : m_Query(&query)
246 {
247  m_Descr = "Search for VCF variant with ID \"" + m_Query->GetIds() + "\"";
248 }
249 
250 
252 {
253  m_Error.Reset();
254 
255  if (m_Query->GetIds().empty()) {
256  m_Error = new CAppJobError("No sequence ids are provided.");
257  }
258  return m_Error ? false : true;
259 }
260 
261 
263 {
265 }
266 
267 
269 {
270  CStopWatch sw;
271  sw.Start();
272  {
273  CMutexGuard Guard(m_Mutex);
274  m_ProgressStr = "Loading data." ;
275  }
276  const vector<ISeqLocSearchContext*>& vcf_contexts(m_Query->GetVcfContexts());
277  string ids = m_Query->GetIds();
278  CObjectList * obj_list = m_TempResult->GetObjectList();
279 
280  for(auto vcf_context: vcf_contexts) {
281  if(IsCanceled()) {
282  break;
283  }
284  INonAsnTrackData* NonAsnData(vcf_context->GetNonAsnData());
285  if(NonAsnData) {
286  list<CRef<CObject>> results;
287  CRef<CScope> scope(vcf_context->GetSearchScope());
288  NonAsnData->DoSearch(vcf_context->GetSearchLoc()->GetId(), ids, results);
289  for(auto result: results) {
290  obj_list->AddRow(result.GetPointer(), scope.GetPointer());
291  }
292  }
293  }
294  return IsCanceled() ? eCanceled : eCompleted;
295 }
296 
297 
#define false
Definition: bool.h:36
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CObjectList * GetObjectList()
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
int AddRow(CObject *obj, objects::CScope *scope)
CRef –.
Definition: ncbiobj.hpp:618
CSearchControl.
virtual void UpdateContexts()
updates m_ContextCombo
CSearchControl * m_Text
void UpdateContextCombo(wxChoice *combo)
CRef< CDMSearchResult > m_TempResult
holds temporary results, guarded by Mutex
string m_Descr
human-readable description of the Job
virtual void x_SetupColumns(CObjectList &obj_list)
add custom columns if needed
CMutex m_Mutex
synchronizes access to the Job members
CRef< CAppJobError > m_Error
CStopWatch –.
Definition: ncbitime.hpp:1938
CVcfSearchJob.
CVcfSearchQuery.
CVcfSearchTool.
virtual void Init()
IDMSearchQuery - abstract data mining query.
IDMSearchTool interface representing a single search tool in Data Mining Service.
IDataMiningContext IDataMiningContext represents an abstract context for a Search.
ISeqlocSearchContext.
virtual INonAsnTrackData * GetNonAsnData()
IUITool represents an abstract algorithm that is bound to a UI component.
Definition: ui_tool.hpp:59
#define NULL
Definition: ncbistd.hpp:225
virtual void DoSearch(const objects::CSeq_id *seq_id, const string &sSearchTerm, list< CRef< CObject >> &results) const =0
virtual CIRef< IDMSearchQuery > ConstructQuery()
virtual void Create()
wxChoice * m_DbCombo
string GetIds() const
CVcfSearchForm(CVcfSearchTool &tool)
CVcfSearchForm.
virtual void Update()
CRef< CVcfSearchQuery > m_Query
virtual void x_CreateWidgets()
virtual void Init()
virtual void x_SetupColumns(CObjectList &obj_list)
add custom columns if needed
virtual CRef< CSearchJobBase > x_CreateJob(IDMSearchQuery &query)
implementing CSearchToolBase pure virtual function
CRef< CVcfSearchTool > m_Tool
virtual wxSizer * GetWidget(wxWindow *parent)
return a widget associated with the form; the form controls the lifetime of the widget (do not delete...
virtual string GetDescription() const
returns a detailed description of the method that is used in UI
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual IDMSearchTool * x_GetTool()
CVcfSearchJob(CVcfSearchQuery &query)
CVcfSearchJob.
virtual string GetName() const
returns unique name of the method that is used in UI to identify it
CVcfSearchQuery(vector< ISeqLocSearchContext * > VcfContexts, const string &ids)
CVcfSearchQuery.
virtual CIRef< IDMSearchForm > CreateSearchForm()
factory method for creating a form representing the tool
virtual EJobState x_DoSearch()
performs searching, assuming that params are correct; Implement in derived classes
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsCompatible(IDataMiningContext *context)
retuns true if the tool is compatible with the provided Search Context
const vector< ISeqLocSearchContext * > & GetVcfContexts() const
virtual bool x_ValidateParams()
returns true if Job params are correct, implement in derived classes
virtual IUITool * Clone() const
CVcfSearchTool()
IDMSearchTool.
virtual void UpdateContexts()
updates m_ContextCombo
virtual bool IsCanceled() const override
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
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
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2765
static CStopWatch sw
int i
#define wxT(x)
Definition: muParser.cpp:41
Defines: CTimeFormat - storage class for time format.
static string query
else result
Definition: token2.c:20
USING_SCOPE(objects)
#define ID_TEXT
#define ID_COMBOBOX
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Feb 28 07:11:28 2024 by modify_doxy.py rev. 669887