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

Go to the SVN repository for this file.

1 /* $Id: blast_search_task.cpp 40209 2018-01-08 20:35:14Z joukovv $
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  */
29 
30 #include <ncbi_pch.hpp>
31 
36 
37 #include <wx/msgdlg.h>
38 
39 
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 /// CBlastSearchTask
45 
48  const string& tool_name)
49 : m_SrvLocator(srv_locator),
50  m_NetBlastDS(&ds),
51  m_ToolName(tool_name),
52  m_Command(eInvalid),
53  m_Stage(eInvalid)
54 {
55 }
56 
57 
59 {
60 }
61 
62 
64 {
65  size_t n = params.GetSeqLocs().size();
66  m_Descr = m_ToolName + " - ";
67 
68  string title = params.GetJobTitle();
69  if(title.empty()) {
71  m_Descr += (n ==1) ? " sequence" : " sequences";
72  } else {
73  m_Descr += title;
74  }
75 
77 
79 
80  // create the first task in this sequence
81  CAppJobTask* jtask = new CAppJobTask(*m_SubmittingJob, true);
82  jtask->SetReportErrors( false );
83  m_CurrTask.Reset( jtask );
84 
85  m_Stage = eSubmit;
86 }
87 
88 
90 {
91  size_t n =descriptors.size();
93  m_Descr += (n ==1) ? " sequence" : " sequences";
94 
96 
97  x_InitMonitoringStage(descriptors);
98 }
99 
100 
101 void CBlastSearchTask::Init_RetrieveRID(const vector<string>& RIDs)
102 {
103  m_Descr = m_ToolName + " - retrieving ";
104  size_t n = RIDs.size();
106  m_Descr += (n == 1) ? " RID" : " RIDs";
107 
109  m_Stage = eMonitor;
110 
111  // create a loading job and a wrapping child task
113  // Get project scope here and pass it to loading job to check local sequences
114  // for duplicates
115  CScope *scope = 0;
116  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
117  if (ws) {
118  auto project_id = m_LoadingOptions.GetTargetProjectId();
119  CGBProjectHandle* project = ws->GetProjectFromId(project_id);
120  if (project) {
121  scope = project->GetScope();
122  }
123  }
124  m_LoadingJob.Reset(new CNetBlastLoadingJob(*m_NetBlastDS, &RIDs, scope));
125  //m_Descr = task->GetDescr();
126 
127  //CSelectProjectOptions options;
129  m_Stage = eRetrieve;
130 }
131 
132 
133 /// preapres App Job for monitoring stage of the task
135 {
136  m_Descr += " (";
137 
138  size_t i;
139  for (i = 0; i < descriptors.size(); ++i) {
140  if (i > 0)
141  m_Descr += ",";
142  m_Descr += descriptors[i]->GetRID();
143  if (i == 2)
144  break;
145  }
146 
147  if (i < descriptors.size())
148  m_Descr += ", ...";
149 
150  m_Descr += ")";
151 
155 
156  m_CurrTask.Reset(new CAppJobTask(*m_MonitoringJob, true, "", 5, "Scheduler"));
157  m_Stage = eMonitor;
158 }
159 
161 {
162  m_LoadingOptions = options;
163 
165  if (task)
166  task->SetOptions(options);
167 
168  if(m_MonitoringJob) {
170  }
171 }
172 
173 /// overriding CAppTask::GetStatusText()
175 {
176  switch(m_Stage) {
177  case eSubmit:
178  return "Submitting results to NCBI Net BLAST server";
179 
180  case eMonitor:
181  return "Executing BLAST jobs remotely on NCBI Net BLAST server";
182 
183  case eRetrieve:
184  return "Retrieving results from NCBI Net BLAST server";
185 
186  case eFinished:
187  return "Finished";
188 
189  default:
190  _ASSERT(false); // unexpected
191  return "Bug";
192  }
193 }
194 
195 
197 {
198  return m_CurrTask;
199 }
200 
201 
203 {
204  //LOG_POST("CBlastSearchTask::x_NextSubTask() " << m_Stage);
205  switch(m_Stage) {
206  case eSubmit: {{
207  // next stage - Monitoring
208  if(m_SubmittingJob) {
209  TDescriptors descriptors;
210  m_SubmittingJob->GetDescriptors(descriptors);
211 
212  if( ! descriptors.empty()) {
213  x_InitMonitoringStage(descriptors);
214  } else {
215  m_CurrTask.Reset();
216  m_Stage = eFinished;
217  }
218  break;
219  }
220  }}
221  case eMonitor:
222  m_CurrTask.Reset();
223  if(m_MonitoringJob) {
224  m_Stage = eFinished;
225  }
226  break;
227 
228  case eRetrieve:
229  m_CurrTask.Reset();
230  m_Stage = eFinished;
231  break;
232 
233  default:
234  _ASSERT(false); // invalid
235  break;
236  }
237 
238  return m_CurrTask;
239 }
240 
241 
243 {
245 
246  if(state == eCompleted) {
247  switch(m_Stage) {
248  case eSubmit: {{
249  vector<string> errors;
250  m_SubmittingJob->GetErrors(errors);
251  if( ! errors.empty()) {
252  x_ReportErrors(errors);
253  }
254  break;
255  }}
256  case eRetrieve: {{
257  vector<string> errors;
258  m_LoadingJob->GetErrors(errors);
259  if( ! errors.empty()) {
260  x_ReportErrors(errors);
261  }
262  break;
263  }}
264  default:
265  break;
266  }
267  }
268  return state;
269 }
270 
271 
272 void CBlastSearchTask::x_ReportErrors(vector<string>& errors)
273 {
274  // report errors interactively
275  // TODO this probably should be done via Event Logging service
276  // format the message
277  size_t n = errors.size();
278  string msg = NStr::NumericToString(n) + ((n == 1) ? " RID" : " RIDs");
279  msg += " cannot be retrieved for the following reasons:";
280  for( size_t i = 0; i < n; i++) {
281  msg += "\n " + errors[i];
282  }
283 
284  string title = (n == 1) ? "Error in" : "Errors in";
285  title += m_ToolName;
286 
287  wxMessageBox(ToWxString(msg), ToWxString(title));
288 }
289 
290 
USING_SCOPE(objects)
CAppJobTask CAppJobTask is an adapter that allows for running IAppJobs as Tasks in App Task Service.
string m_Descr
task description
CBLASTParams - save user-specified parameters and preferences.
virtual ETaskState x_RunCurrentSubTask()
runs the current subtask; one may override this function in order to perform special pre-execution or...
CDataLoadingAppTask - a task that executes CDataLoadingAppJob.
void SetOptions(const CSelectProjectOptions &options)
virtual CScope * GetScope() const
CNetBlastLoadingJob - an application job for loading RIDs from NCBI Net BLAST server.
Definition: blast_jobs.hpp:171
CNetBlastSubmittingJob.
Definition: blast_jobs.hpp:67
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
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
void SetReportErrors(bool report)
enabled / disbale error reporting for failed Jobs
ETaskState
List of task states defining the task management FSM.
Definition: app_task.hpp:87
@ eCompleted
successfully finished
Definition: app_task.hpp:92
void GetErrors(vector< string > &errors) const
Definition: blast_jobs.cpp:517
virtual CIRef< IAppTask > x_NextSubTask()
prepares the next subtask (makes it current), this function is used for iterating subtasks.
ECommand m_Command
the command associated with the task
void x_ReportErrors(vector< string > &errors)
TConstScopedObjects & GetSeqLocs()
vector< CRef< CNetBlastJobDescriptor > > TDescriptors
virtual string GetStatusText() const
overriding CAppTask::GetStatusText()
virtual ETaskState x_RunCurrentSubTask()
runs the current subtask; one may override this function in order to perform special pre-execution or...
virtual void Init_Monitoring(TDescriptors &descriptors)
setup the task for monitoring BLAST jobs and for retrieving results
virtual CIRef< IAppTask > x_GetCurrentSubTask()
returns a references to the current subtask
CIRef< IAppTask > m_CurrTask
virtual void Init_RetrieveRID(const vector< string > &RIDs)
setup the task for retrieving results
virtual void SetLoadingOptions(CSelectProjectOptions &options)
define how the task results shall be handled
virtual void SetLoadingOptions(CSelectProjectOptions &options)
Definition: blast_jobs.cpp:279
CSelectProjectOptions m_LoadingOptions
string m_ToolName
name of the tool that launched the task; used in UI
virtual void Init_SubmitSearch(const CBLASTParams &params)
setup the task for submitting and monitoring BLAST jobs, and for retrieving results
void GetDescriptors(TDescriptors &descriptors)
Definition: blast_jobs.cpp:241
void x_InitMonitoringStage(TDescriptors &descriptors)
preapres App Job for monitoring stage of the task
ECommand m_Stage
defines the current stage of the task
IServiceLocator * m_SrvLocator
CRef< CNetBlastLoadingJob > m_LoadingJob
void GetErrors(vector< string > &errors) const
Definition: blast_jobs.cpp:247
CRef< CNetBlastSubmittingJob > m_SubmittingJob
CRef< CNetBLASTUIDataSource > m_NetBlastDS
CRef< CNetBlastMonitoringJob > m_MonitoringJob
CBlastSearchTask(IServiceLocator *srv_locator, CNetBLASTUIDataSource &ds, const string &tool_name)
CBlastSearchTask.
@ eFinished
only retrieve resutlts
@ eMonitor
submit request, monitor and retrieve results
@ eRetrieve
monitor and retrieve resutlts
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
int i
yy_size_t n
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sat Apr 20 12:18:49 2024 by modify_doxy.py rev. 669887