NCBI C++ ToolKit
seqgraphic_job.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_JOB__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_JOB__HPP
3 
4 /* $Id: seqgraphic_job.hpp 44110 2019-10-28 21:45:38Z shkeda $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Vlad Lebedev, Liangshou Wu
30  *
31  * File Description:
32  *
33  */
34 
35 
36 
37 #include <gui/gui.hpp>
38 #include <objmgr/bioseq_handle.hpp>
40 #include <gui/objutils/utils.hpp>
43 #include <gui/opengl/gltypes.hpp>
44 
46 
47 ///////////////////////////////////////////////////////////////////////////////
48 /// CSeqGraphicJob -- the base class of seqgraphic job for handling the job
49 /// status such as reporting the progress and returning the result.
50 ///
52  : public CJobCancelable
54 {
55 public:
56  typedef int TJobToken;
57 
58  /// List of annotations with the corresponding titles
60 
61  CSeqGraphicJob(const string& desc = kEmptyStr);
62 
63  virtual ~CSeqGraphicJob(){};
64 
65  void SetToken(TJobToken token);
66 
67  /// @name IAppJob implementation
68  /// @{
69  virtual EJobState Run();
71  virtual CRef<CObject> GetResult();
73  virtual string GetDescr() const;
74  /// @}
75 
76  /// @name ISeqTaskProgressCallback implementation.
77  /// @{
78  virtual void SetTaskName(const string& name);
79  virtual void SetTaskCompleted(int completed);
80  virtual void AddTaskCompleted(int delta);
81  virtual void SetTaskTotal(int total);
82  virtual bool StopRequested() const;
83  /// @}
84 
85 protected:
86  /// method truly doing the job.
87  virtual EJobState x_Execute() = 0;
88 
89  /// @name Job results and status.
90  /// @{
93  string m_Desc; ///< Job description or name
94  /// @}
95 
96  TJobToken m_Token; ///< Job token recognizable by job listener
97 
98 private:
99  CFastMutex m_Mutex; ///< mutex for guarding state access
100  int m_TaskTotal; ///< Total amount of task for a job
101  int m_TaskCompleted; ///< The amount of task finished
102  string m_TaskName;
103 };
104 
105 
106 ///////////////////////////////////////////////////////////////////////////////
107 /// CSGAnnotJob -- Job based on SAnnotSelector for loading data using
108 /// ObjectManager.
109 ///
110 
112  class CMappedGraph;
114 
116 {
117 public:
118  typedef struct { double min; double max; } TAxisLimits;
119 
121  {
122  SGraphObject(TSeqPos start, TSeqPos stop, float window,
124  const string& desc, const string& annot_name)
125  : m_Map(start, stop, window, func, std::numeric_limits<CHistogramGlyph::TDataType>::min())
126  , m_Max(std::numeric_limits<double>::min())
127  , m_Min(std::numeric_limits<double>::max())
128  , m_Desc(desc)
129  , m_AnnotName(annot_name)
130  {
131  m_Map.SetMax(m_Max);
132  m_Map.SetMin(m_Min);
133  }
134 
136  double m_Max;
137  double m_Min;
138  string m_Desc;
139  string m_AnnotName;
140  };
141 
142  CSGAnnotJob (const string& desc, objects::CBioseq_Handle handle,
143  const objects::SAnnotSelector& sel, const TSeqRange& range);
144 
145  void SetGraphLevel(int level);
146  int GetGraphLevel() const;
147 
148  objects::CScope& GetScope(void) const;
149 
150 protected:
151  IAppJob::EJobState x_LoadCoverageGraph(CSeqGlyph::TObjects& glyphs,
152  int level, TModelUnit window, const string& title, bool fixed_scale, const TAxisLimits& y_limits);
153 
154  IAppJob::EJobState x_CreateHistFromGraph(CSeqGlyph::TObjects& glyphs,
155  const objects::SAnnotSelector& sel, TModelUnit window, bool fixed_scale, const TAxisLimits& y_limits);
156 
157  template <typename TGraphType>
159  const objects::CMappedGraph& gr,
160  const TGraphType& graph,
161  double& g_max, double& g_min,
162  bool fixed_scale);
163 
164  void x_AddGraphObject(map<string, SGraphObject>& d_maps,
165  const objects::CMappedGraph& gr,
166  TModelUnit window,
167  bool fixed_scale);
168 
169  /// Get a name for a graph.
170  /// We should favor title over annotation name.
171  string x_GetGraphName(const objects::CMappedGraph& gr) const;
172 
173  /// Check the graph type.
174  /// @return true only if the given graph is a percentile graph
175  /// and not a 100 percentile.
176  /// A percentile graph is indicated in seq-annot::desc asn
177  /// as a user-object:
178  /// Seq-annot ::= {
179  /// desc {
180  /// user {
181  /// type str "AnnotationTrack",
182  /// data {
183  /// {
184  /// label str "StatisticsType",
185  /// data str "Percentiles"
186  /// }
187  /// }
188  /// }
189  /// },
190  /// And the specific percentile is indicated in seq-graph::comment
191  /// data graph {
192  /// {
193  /// title "Feature density graph",
194  /// comment "90%",
195  /// ...
196  /// }
197  /// }
198  bool x_PercentileButNotMax(const objects::CMappedGraph& gr) const;
199 
200 protected:
201  objects::CBioseq_Handle m_Handle; ///< target sequence
202  objects::SAnnotSelector m_Sel; ///< our annotation selector
203  TSeqRange m_Range; ///< target range
204  int m_GraphLevel; ///< coverate graph level
205 };
206 
207 
208 ///////////////////////////////////////////////////////////////////////////////
209 /// CSeqGraphicJob inline methods
210 ///
211 inline
213 { m_Token = token; }
214 
215 ///////////////////////////////////////////////////////////////////////////////
216 /// CSGAnnotJob inline methods
217 ///
218 inline
219 objects::CScope& CSGAnnotJob::GetScope(void) const
220 { return m_Handle.GetScope(); }
221 
222 inline
224 { m_GraphLevel = level; }
225 
226 inline
228 { return m_GraphLevel; }
229 
230 
232 
233 #endif // GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_JOB__HPP
CFastMutex –.
Definition: ncbimtx.hpp:667
Base class to build jobs with cancel functionality.
CMappedGraph –.
Definition: graph_ci.hpp:61
objects::SAnnotSelector m_Sel
our annotation selector
objects::CScope & GetScope(void) const
CSGAnnotJob inline methods.
void x_AddGraphToMap(CDensityMap< float > &the_map, const objects::CMappedGraph &gr, const TGraphType &graph, double &g_max, double &g_min, bool fixed_scale)
int m_GraphLevel
coverate graph level
int GetGraphLevel() const
TSeqRange m_Range
target range
void SetGraphLevel(int level)
objects::CBioseq_Handle m_Handle
target sequence
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
CSeqGraphicJob – the base class of seqgraphic job for handling the job status such as reporting the p...
virtual ~CSeqGraphicJob()
CRef< CObject > m_Result
string m_Desc
Job description or name.
CFastMutex m_Mutex
mutex for guarding state access
int m_TaskTotal
Total amount of task for a job.
map< string, string > TAnnotNameTitleMap
List of annotations with the corresponding titles.
int m_TaskCompleted
The amount of task finished.
void SetToken(TJobToken token)
CSeqGraphicJob inline methods.
TJobToken m_Token
Job token recognizable by job listener.
CRef< CAppJobError > m_Error
virtual EJobState x_Execute()=0
method truly doing the job.
Task clients implement this callback interface.
Definition: utils.hpp:107
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
virtual void SetTaskName(const string &name)=0
virtual void SetTaskCompleted(int completed)=0
set total finished task number.
virtual void SetTaskTotal(int total)=0
virtual bool StopRequested() const =0
virtual void AddTaskCompleted(int delta)=0
set to add newly finished task number.
GLdouble TModelUnit
Definition: gltypes.hpp:48
virtual CConstIRef< IAppJobProgress > GetProgress()=0
return progress object, the function shall be synchronized internally.
virtual CConstIRef< IAppJobError > GetError()=0
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual CRef< CObject > GetResult()=0
Returns the Job Result.
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.
#define numeric_limits
Pre-declaration of the "numeric_limits<>" template Forcibly overrides (using preprocessor) the origin...
Definition: ncbi_limits.hpp:92
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
range(_Ty, _Ty) -> range< _Ty >
T max(T x_, T y_)
T min(T x_, T y_)
Int4 delta(size_t dimension_, const Int4 *score_)
CHistogramGlyph::TMap m_Map
SGraphObject(TSeqPos start, TSeqPos stop, float window, CHistogramGlyph::TMap::accum_functor *func, const string &desc, const string &annot_name)
TEMPLATE binary functor base struct.
Definition: density_map.hpp:59
CScope & GetScope()
Modified on Wed Sep 04 15:06:55 2024 by modify_doxy.py rev. 669887