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

Go to the SVN repository for this file.

1 /* $Id: feature_panel_ds.cpp 46174 2021-01-28 02:26:06Z evgeniev $
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: Liangshou Wu
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
33 
34 #include <gui/utils/app_job.hpp>
38 
40 #include <corelib/ncbitime.hpp>
41 #include <corelib/perf_log.hpp>
43 
45 
48 
49 ///////////////////////////////////////////////////////////////////////////////
50 /// CTrackInitializationJob
51 ///////////////////////////////////////////////////////////////////////////////
53  public CJobCancelable
54 {
55 public:
57 
58  CTrackInitializationJob(const string& desc, const ILayoutTrackFactory* factory,
59  CTrackContainer* parent, CTempTrackProxy* params,
60  const CObject& obj, objects::CScope& scope,
61  ISGDataSourceContext* ds_context, CRenderingContext* r_cntx,
62  const ILayoutTrackFactory::SExtraParams& extra_param,
63  const TAnnotMetaDataList& src_annots);
64 
66 
67  /// @name IAppJob implementation
68  /// @{
69  virtual EJobState Run();
71  virtual CRef<CObject> GetResult();
73  virtual string GetDescr() const;
74  /// @}
75 
76 private:
77  /// @name Job results and status.
78  /// @{
81  string m_Desc;
82  /// @}
83 
90 };
91 
92 
93 ///////////////////////////////////////////////////////////////////////////////
94 /// CAnnotMetaDataJob
95 ///////////////////////////////////////////////////////////////////////////////
97 {
98 public:
99  CAnnotMetaDataJob(const string& desc,
100  CBioseq_Handle handle,
101  const string& assembly,
102  const string& tms_context);
103 
104  virtual ~CAnnotMetaDataJob() {}
105 
106  /// @name IAppJob implementation
107  /// @{
108  virtual EJobState Run();
110  virtual CRef<CObject> GetResult();
112  virtual string GetDescr() const;
113  /// @}
114 
115 private:
116  /// @name Job results and status.
117  /// @{
120  string m_Desc;
121  /// @}
122 
123  objects::CBioseq_Handle m_Handle; ///< target sequence
124  string m_Assembly;
125  string m_TMSContext;
126 };
127 
128 
129 ///////////////////////////////////////////////////////////////////////////////
130 /// CGetAssembliesJob
131 ///////////////////////////////////////////////////////////////////////////////
133 {
134 public:
135  CGetAssembliesJob(const string& seqAcc) : m_SeqAcc(seqAcc)
136  {
138  }
139 
140  /// @name IAppJob implementation
141  /// @{
142  virtual EJobState Run()
143  {
144  while (!CAssemblyCache::GetInstance().GetAssemblies(m_SeqAcc, m_Result->m_Assemblies)) {
145  if (IsCanceled())
146  return eCanceled;
147  SleepMilliSec(500);
148  }
149  return eCompleted;
150  }
154  virtual string GetDescr() const { return m_Desc; }
155  /// @}
156 
157 private:
158  /// @name Job results and status.
159  /// @{
162  string m_Desc;
163  /// @}
164 
165  string m_SeqAcc;
166 };
167 
168 
169 ///////////////////////////////////////////////////////////////////////////////
170 /// CSeqGraphicJob implementation
171 ///////////////////////////////////////////////////////////////////////////////
173  const ILayoutTrackFactory* factory, CTrackContainer* parent,
174  CTempTrackProxy* params, const CObject& obj, objects::CScope& scope,
175  ISGDataSourceContext* ds_context, CRenderingContext* r_cntx,
176  const ILayoutTrackFactory::SExtraParams& extra_param,
177  const TAnnotMetaDataList& src_annots)
178  : m_Desc(desc)
179  , m_Factory(factory)
180  , m_ScopedObj(&obj, &scope)
181  , m_DSContext(ds_context)
182  , m_RenderingCntx(r_cntx)
183  , m_ExtraParam(extra_param)
184 {
185  m_SrcAnnots = src_annots;
187  m_Result->m_ParentTrack = parent;
188  m_Result->m_TrackParams.Reset(params);
189  m_Result->m_Desc = desc;
190 }
191 
193 {
194  CLogPerformance perfLog("CTrackInitializationJob");
195  perfLog << "Name: " << m_Result->m_TrackParams->GetName();
196  perfLog << ", Source: " << m_Result->m_TrackParams->GetSource();
197  perfLog << ", Category: " << m_Result->m_TrackParams->GetCategory();
198  if (!m_Result->m_TrackParams->GetSubcategory().empty())
199  perfLog << ", Subcategory: " << m_Result->m_TrackParams->GetSubcategory();
200 
201  m_Error.Reset();
202 
204  try {
205  // get a table of annot/track title correspondences
206  for (auto& i : m_Result->m_TrackParams->GetChildren()) {
207  if (CSeqUtils::IsNAA(i->GetSource()) && !i->GetDisplayName().empty()) {
208  m_ExtraParam.m_AnnotNameTitleMap[i->GetSource()] = i->GetDisplayName();
209  }
210  }
212 
213  m_Result->m_Tracks =
214  m_Factory->CreateTracks(m_ScopedObj, m_DSContext,
216 
217  result = eCompleted;
218  } NCBI_CATCH("CTrackInitializationJob::Run()");
219 
220  if (result == eFailed) {
221  m_Error.Reset(new CAppJobError("failed on initializing " + m_Factory->GetThisTypeInfo().GetDescr()));
222  }
223  else {
224  perfLog.Post(CRequestStatus::e200_Ok);
225  }
226  //LOG_POST( Info << "CTrackInitializationJob::Run() completed job" );
227 
228  return result;
229 }
230 
232 {
234 }
235 
237 {
239 }
240 
242 {
244 }
245 
247 {
248  return m_Desc;
249 }
250 
251 
252 
253 ///////////////////////////////////////////////////////////////////////////////
254 /// CAnnotMetaDataJob implementation
255 ///////////////////////////////////////////////////////////////////////////////
257  CBioseq_Handle handle,
258  const string& assembly,
259  const string& tms_context)
260  : m_Desc(desc)
261  , m_Handle(handle)
262  , m_Assembly(assembly)
263  , m_TMSContext(tms_context)
264 {
266 }
267 
268 
270 {
271  m_Error.Reset();
272  // if the sequence accession is local or not recognizable, don't try to query TMS/Eutils at all
274  try {
275  CConstRef<CSeq_id> seq_id = m_Handle.GetSeqId();
276  string accession = seq_id->GetSeqIdString(true);
277 
278  vector<CRef<CAnnotMetaData> > tmsTracks;
279  CStopWatch sw;
280  sw.Start();
281  CTMSUtils::GetTrackMetaData(tmsTracks, accession, m_Assembly, m_TMSContext);
282  sw.Stop();
283  string info = "Timing: " + sw.AsSmartString(CTimeSpan::eSSP_Millisecond)
284  + ". TMS tracks via seqconfig.cgi for " + accession + ". Assembly " + m_Assembly + ".";
285  LOG_POST(Info << info);
286 
287  LOG_POST(Info << "TMS tracks: " << tmsTracks.size() << ".");
288  for (auto i : tmsTracks) {
289  m_Result->m_Annots[i->m_Name] = i;
290  }
291 
292  if (m_Result->m_Annots.empty()) {
294  if (IsCanceled()) return eCanceled;
295  sw.Start();
296  CNAUtils na_util(*seq_id, m_Handle.GetScope());
297  na_util.GetAllNAMetaData(annots, "", x_GetICanceled());
298  sw.Stop();
299  if (IsCanceled()) return eCanceled;
300  string info = "Timing: " + sw.AsSmartString(CTimeSpan::eSSP_Millisecond)
301  + ". Eutils NA tracks for " + accession + ".";
302  LOG_POST(Info << info);
303  LOG_POST(Info << "EUtils tracks: " << annots.size() << ".");
304  int count = 0;
305  if (!m_Result->m_Annots.empty()) {
306  for (auto& i : m_Result->m_Annots) {
307  if (annots.find(i.first) == annots.end()) {
308  ++count;
309  if (count <= 10) {
310  LOG_POST(Info << "TMS ann not found in EUtils: " << i.first);
311  }
312  }
313  }
314  LOG_POST(Info << "Total TMS annots not found in Eutils: " << count);
315  }
316 
317  count = 0;
318  for (auto& i : annots) {
319  if (m_Result->m_Annots.find(i.first) == m_Result->m_Annots.end()) {
320  ++count;
321  m_Result->m_Annots[i.first] = i.second;
322 
323  if (count <= 10) {
324  LOG_POST(Info << "EUtils ann not found in TMS: " << i.first);
325  }
326  }
327  }
328  LOG_POST(Info << "Total Eutils annots not found in TMS: " << count);
329  }
330 
331  LOG_POST(Info << "Time for retrieving NA meta-data: "
332  << sw.Elapsed() << " seconds");
333 
334  } catch (std::exception& e) {
335  string id_str;
336  m_Handle.GetSeqId()->GetLabel(&id_str);
337  LOG_POST( Info << "CAnnotMetaDataJob::Run() failed to get meta data for "
338  << id_str << ", Details: "
339  << e.what());
340 
341  // maybe there is no such thing as named annotation for
342  // the given sequence type, such as a local sequence.
343  // So we won't consider it as failed
344  }
345  }
346  return eCompleted;
347 }
348 
349 
351 {
353 }
354 
355 
357 {
359 }
360 
361 
363 {
365 }
366 
367 
369 {
370  return m_Desc;
371 }
372 
373 
374 ///////////////////////////////////////////////////////////////////////////////
375 /// CFeaturePanelDS
376 ///////////////////////////////////////////////////////////////////////////////
377 
379  : CSGGenBankDS(scope, id)
380  , m_RenderingCntx(NULL)
381  , m_UseEUtils(false)
382  , m_MetaDataJob(-1)
383 {}
384 
385 
387 {
389 }
390 
391 void CFeaturePanelDS::SetAssembly(const string& assembly)
392 {
393  m_Assembly = assembly;
395 }
396 
397 void CFeaturePanelDS::SetTMSContext(const string& tms_context)
398 {
399  m_TMSContext = tms_context;
401 }
402 
404 {
405  m_UseEUtils = use;
407 }
408 
410 {
412  return false;
413  return (m_MetaDataJob == -1);
414 }
415 
417 {
418  if (m_MetaDataJob > -1) {
420  try {
421  disp.DeleteJob(m_MetaDataJob);
422  } catch(CAppJobException& e) {
423  switch(e.GetErrCode()) {
426  /// this is fine - job probably already finished
427  break;
428  default:
429  // something wrong
430  LOG_POST(Error << "CSGGenBankDS::DeleteAllJobs() "
431  << "Error canceling job");
432  LOG_POST(e.ReportAll());
433  }
434  }
435  m_MetaDataJob = -1;
436  }
437 }
438 
439 
441 {
442  if (m_MetaDataJob > -1) {
443  m_MetaDataJob = -1;
444  }
445 }
446 
447 
448 void CFeaturePanelDS::CreateTrack(const string& desc,
449  const ILayoutTrackFactory* factory,
450  CTrackContainer* parent,
451  CTempTrackProxy* params,
452  const ILayoutTrackFactory::SExtraParams& extra_param)
453 {
454  CConstRef<CSeq_id> seq_id = m_Handle.GetSeqId();
455 
457  new CTrackInitializationJob(desc, factory, parent, params,
458  *seq_id, GetScope(), m_DSContext, m_RenderingCntx,
459  extra_param, TAnnotMetaDataList()));
460  x_LaunchJob(*job, -1);
461 }
462 
463 
464 void CFeaturePanelDS::GetAnnotMetaData(const string& desc)
465 {
467  if (m_Background) {
468  TJobID job_id = x_BackgroundJob(*job, -1, "ObjManagerEngine");
469  if (job_id > -1) {
470  m_MetaDataJob = job_id;
471  }
472  } else {
473  x_ForegroundJob(*job);
474  }
475 }
476 
477 
478 void CFeaturePanelDS::GetAssemblies(const string& seqAcc)
479 {
481  if (m_Background) {
482  TJobID job_id = x_BackgroundJob(*job, -1, "ObjManagerEngine");
483  if (job_id > -1) {
484  m_MetaDataJob = job_id;
485  }
486  }
487  else {
488  x_ForegroundJob(*job);
489  }
490 }
491 
492 
493 ///////////////////////////////////////////////////////////////////////////////
494 /// CSGFeatureDSType
495 ///////////////////////////////////////////////////////////////////////////////
496 
499 {
500  const CSeq_id& id = dynamic_cast<const CSeq_id&>(object.object.GetObject());
501  return new CFeaturePanelDS(object.scope.GetObject(), id);
502 }
503 
505 {
506  static string sid("seqgraphic_feature_panel_ds_type");
507  return sid;
508 }
509 
511 {
512  static string slabel("Graphical View Feature Panel Data Source Type");
513  return slabel;
514 }
515 
517 {
518  return false;
519 }
520 
521 
CAnnotMetaDataJobResult.
TAnnotMetaDataList m_Annots
CAnnotMetaDataJob.
CAnnotMetaDataJob(const string &desc, CBioseq_Handle handle, const string &assembly, const string &tms_context)
CAnnotMetaDataJob implementation.
CRef< CAnnotMetaDataJobResult > m_Result
virtual CRef< CObject > GetResult()
Returns the Job Result.
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
CRef< CAppJobError > m_Error
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
objects::CBioseq_Handle m_Handle
target sequence
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
CAppJobDispatcher.
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
IAppJobListener Interface for components that need to be notified about changes in Jobs.
static CAssemblyCache & GetInstance()
CBioseq_Handle –.
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsSharable() const
check if the data source can be shared.
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual ISGDataSource * CreateDS(SConstScopedObject &object) const
create an instance of the layout track type using default settings.
CFeaturePanelDS.
void SetTMSContext(const string &tms_context)
void CreateTrack(const string &desc, const ILayoutTrackFactory *factory, CTrackContainer *parent, CTempTrackProxy *params, const ILayoutTrackFactory::SExtraParams &extra_param)
CIRef< ISGDataSourceContext > m_DSContext
CRenderingContext * m_RenderingCntx
CFeaturePanelDS(objects::CScope &scope, const objects::CSeq_id &id)
TJobID m_MetaDataJob
job id for annot meta-data job id.
void GetAssemblies(const string &seqAcc)
virtual bool AllJobsFinished() const
ILayoutTrackFactory::TAnnotMetaDataList TAnnotMetaDataList
void SetUseEUtils(bool use)
void SetAssembly(const string &assembly)
void GetAnnotMetaData(const string &desc)
retrieve a list of annotations with their meta data.
CAnnotMetaDataJobResult.
list< CRef< objects::CGC_Assembly > > m_Assemblies
CGetAssembliesJob.
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
virtual CRef< CObject > GetResult()
Returns the Job Result.
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
CRef< CAppJobError > m_Error
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
CGetAssembliesJob(const string &seqAcc)
CRef< CGetAssembliesJobResult > m_Result
Base class to build jobs with cancel functionality.
void Post(CRequestStatus::ECode status=CRequestStatus::e200_Ok)
CObject –.
Definition: ncbiobj.hpp:180
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
TJobID x_LaunchJob(IAppJob &job, int report_period=1, const string &pool="ObjManagerEngine")
Launch either a background or foreground job.
CAppJobDispatcher::TJobID TJobID
objects::CScope & GetScope(void) const
Get the scope from the handle.
virtual bool AllJobsFinished() const
void x_ForegroundJob(IAppJob &job)
objects::CBioseq_Handle m_Handle
TJobID x_BackgroundJob(IAppJob &job, int report_period, const string &pool)
Jobs on thread pool.
CScope –.
Definition: scope.hpp:92
CStopWatch –.
Definition: ncbitime.hpp:1937
File Description:
const string & GetCategory() const
const string & GetTrackProfile() const
const TTrackProxies & GetChildren() const
const string & GetName() const
const string & GetSource() const
const string & GetSubcategory() const
CTrackContainer - a track container in the form of layout track.
CTrackInitJobResult.
CTrackContainer * m_ParentTrack
ILayoutTrackFactory::TTrackMap m_Tracks
CRef< CTempTrackProxy > m_TrackParams
CTrackInitializationJob.
CConstIRef< ILayoutTrackFactory > m_Factory
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
virtual CRef< CObject > GetResult()
Returns the Job Result.
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
CIRef< ISGDataSourceContext > m_DSContext
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
CRef< CTrackInitJobResult > m_Result
ILayoutTrackFactory::SExtraParams m_ExtraParam
ILayoutTrackFactory::TAnnotMetaDataList TAnnotMetaDataList
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
TAnnotMetaDataList m_SrcAnnots
CTrackInitializationJob(const string &desc, const ILayoutTrackFactory *factory, CTrackContainer *parent, CTempTrackProxy *params, const CObject &obj, objects::CScope &scope, ISGDataSourceContext *ds_context, CRenderingContext *r_cntx, const ILayoutTrackFactory::SExtraParams &extra_param, const TAnnotMetaDataList &src_annots)
CSeqGraphicJob implementation.
CRenderingContext * m_RenderingCntx
SConstScopedObject m_ScopedObj
CRef< CAppJobError > m_Error
ILayoutTrackFactory.
ISGDSManager is seqgraphic data source manage that serves as an data source context.
File Description:
size_type size() const
Definition: map.hpp:148
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
USING_SCOPE(objects)
#define false
Definition: bool.h:36
#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
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static bool IsNAA(const string &annot, bool isStrict=false)
check if a given annotation is a named annotation accession[.version][number] when isSctrict == false...
Definition: utils.cpp:796
void GetAllNAMetaData(TNAMetaDataSet &md_set, const string &context="", ICanceled *canceledCallback=0) const
Get meta-data for a given NAA associated with seq_id.
Definition: na_utils.cpp:589
static bool isQuasiLocal(const objects::CBioseq_Handle &handle)
check that a given accession is either local or unrecognizable this can be important to avoid unneces...
Definition: utils.cpp:1111
static void GetTrackMetaData(vector< CRef< CAnnotMetaData > > &data, const string &accession, const string &assembly, const string &context)
Definition: tms_utils.cpp:184
virtual CConstIRef< IAppJobProgress > GetProgress()=0
return progress object, the function shall be synchronized internally.
ICanceled * x_GetICanceled()
static CAppJobDispatcher & GetInstance()
virtual CConstIRef< IAppJobError > GetError()=0
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual bool IsCanceled() const override
virtual CRef< CObject > GetResult()=0
Returns the Job Result.
bool DeleteJob(TJobID job_id)
when a Job is deleted the listener is not notified
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
virtual string GetDescr() const =0
Returns a human readable description of the Job (optional)
virtual EJobState Run()=0
Function that does all the useful work, called by the Engine.
@ eEngine_UnknownJob
the job is not registered in the Engine
@ eUnknownJob
Job record lost.
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
string GetSeqIdString(bool with_version=false) const
Return seqid string with optional version for text seqid type.
Definition: Seq_id.cpp:2145
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
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2775
void Stop(void)
Suspend the timer.
Definition: ncbitime.hpp:2792
string AsSmartString(CTimeSpan::ESmartStringPrecision precision, ERound rounding, CTimeSpan::ESmartStringZeroMode zero_mode=CTimeSpan::eSSZ_SkipZero) const
Transform elapsed time to "smart" string.
Definition: ncbitime.hpp:2850
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2764
@ eSSP_Millisecond
Definition: ncbitime.hpp:1511
#define NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
static CStopWatch sw
int i
static MDB_envinfo info
Definition: mdb_load.c:37
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines: CTimeFormat - storage class for time format.
Defines NCBI C++ API for timing-and-logging, classes, and macros.
extra parameter for initializing a track.
string m_TrackProfile
Track setting profile for additionial parameters.
TAnnotNameTitleMap m_AnnotNameTitleMap
map of known correspondencies between annots and full titles
else result
Definition: token2.c:20
Modified on Wed Jun 19 17:00:41 2024 by modify_doxy.py rev. 669887