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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_UTILS__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_UTILS__HPP
3 
4 /* $Id: seqgraphic_utils.hpp 42838 2019-04-19 17:24:56Z 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  * Author: Liangshou Wu, Dmitry Rudnev
30  *
31  */
32 
33  /**
34  * File Description:
35  */
36 
37 #include <corelib/ncbistr.hpp>
38 #include <corelib/ncbitime.hpp>
39 #include <corelib/ncbiobj.hpp>
42 #include <gui/gui_export.h>
43 
44 
46 
48 class CSeq_annot_Handle;
49 class CSeq_id;
50 class CScope;
51 class CBioseq_Handle;
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 /// Utility classes for sequence graphical view rendering.
56 ///
57 
59 {
60 public:
61  static bool IsChromosome(const objects::CBioseq_Handle& handle,
62  objects::CScope& scope);
63 
64  static bool IsSegSet(const objects::CBioseq_Handle& handle,
65  objects::CScope& scope);
66 
67  static bool IsmRNA(const objects::CBioseq_Handle& handle,
68  objects::CScope& scope);
69 
70  static bool IsRefSeq(const objects::CBioseq_Handle& handle);
71  static bool IsRefSeq(const string& seqid);
72  static bool IsRefSeq(const objects::CSeq_id& seqid);
73 
74  static bool IsMitochondrion(const objects::CBioseq_Handle& handle);
75  static bool IsPlastid(const objects::CBioseq_Handle& handle);
76 
77  static bool IsMainFeature(int type, int subtype);
78 
79  static bool GetFeatFetchDepth(const objects::CBioseq_Handle& handle,
80  objects::CScope& scope, int& depth);
81 
82 };
83 
84 
85 /////////////////////////////////////////////////////////////////////////////
86 /// Helper classes for reporting times.of various steps executed by the CGI
87 ///
89 {
90 public:
91  CTimeReporterEntry(const string& sTimerName)
92  : m_sTimerName(sTimerName)
93  , m_TimeDelta(0.0) {}
94  const string& GetTimerName() { return m_sTimerName; }
95  CStopWatch& GetStopWatch() { return m_StopWatch; }
96 
97  // Add/change reported time value directly (instead of using start/stop)
98  // Useful, for example, to sum up timers running in multiple threads.
99  double GetTimeDelta() const { return m_TimeDelta; }
100  void SetTimeDelta(double delta) { m_TimeDelta = delta; }
101 
102 private:
103  string m_sTimerName;
105  double m_TimeDelta;
106 };
107 
109 {
110 public:
111 
112  typedef list<CRef<CTimeReporterEntry> > TTimeReporterEntries;
114  {
115  //ERR_POST("<<<< ctor, m_Timer: " << this);
116  ResetAll();
117  //ERR_POST(">>>> ctor, m_Timer: " << this);
118  }
119 
120  virtual ~CTimeReporter() {
121  //ERR_POST("==== destructor, m_Timer: " << this);
122  }
123 
124  void Start(const string& sTimerName)
125  {
126  //ERR_POST("<<<< starting timer called " << sTimerName << ", m_Timer: " << this);
127  x_FindOrCreate(sTimerName)->GetStopWatch().Start();
128  //ERR_POST(">>>> started timer called " << sTimerName << ", m_Timer: " << this);
129  }
130 
131  void Stop(const string& sTimerName)
132  {
133  //ERR_POST("<<<< stopping timer called " << sTimerName << ", m_Timer: " << this);
134  x_FindOrCreate(sTimerName)->GetStopWatch().Stop();
135  //ERR_POST(">>>> stopped timer called " << sTimerName << ", m_Timer: " << this);
136  }
137 
138  double GetTime(const string& sTimerName) {
139  NON_CONST_ITERATE(TTimeReporterEntries, iEntries, m_Entries) {
140  if((*iEntries)->GetTimerName() == sTimerName) {
141  double elapsed((*iEntries)->GetStopWatch().Elapsed() +
142  (*iEntries)->GetTimeDelta());
143 
144  return elapsed;
145  }
146  }
147 
148  return 0.0;
149  }
150 
151  // Add a specified value to the current timer
152  void AddTime(const string& sTimerName, double add_time) {
153  CRef<CTimeReporterEntry> entry = x_FindOrCreate(sTimerName);
154  entry->SetTimeDelta(entry->GetTimeDelta() + add_time);
155  }
156 
157  void ResetAll() {
158  //ERR_POST("<<<< resetting all timers, m_Timer: " << this);
159  m_Entries.clear();
160  m_SW.Restart();
161  //ERR_POST(">>>> done resetting all timers, m_Timer: " << this);
162  }
163 
164  virtual void Write(CNcbiOstream& os)
165  {
166  os << fixed << setprecision(5);
167  os << "\"Time\":{\n";
168  // length of the JSON structure so the parsing script can know how many lines to take into account
169  os << " \"Number of lines\":" << m_Entries.size() + 4 << "," << endl;
170  NON_CONST_ITERATE(TTimeReporterEntries, iEntries, m_Entries) {
171  double Elapsed((*iEntries)->GetStopWatch().Elapsed() +
172  (*iEntries)->GetTimeDelta());
173  os << " \"" << (*iEntries)->GetTimerName() << "\":" << Elapsed << "," << endl;
174  }
175  os << " \"Total time\":" << m_SW.Elapsed() << "" << endl;
176  os << "}";
177  }
178 private:
181 
182  CRef<CTimeReporterEntry> x_FindOrCreate(const string& sTimerName)
183  {
184  //ERR_POST("<<<< looking for timer called " << sTimerName << ", m_Timer: " << this);
185  NON_CONST_ITERATE(TTimeReporterEntries, iEntries, m_Entries) {
186  if((*iEntries)->GetTimerName() == sTimerName) {
187  //ERR_POST(">>>> Timer found" << ", m_Timer: " << this);
188  return *iEntries;
189  }
190  }
191  CRef<CTimeReporterEntry> pNewEntry(new CTimeReporterEntry(sTimerName));
192  m_Entries.push_back(pNewEntry);
193  //ERR_POST(">>>> Timer created" << ", m_Timer: " << this);
194  return pNewEntry;
195  }
196 };
197 
198 
199 /// class combining functionality of CPerfLogGuard and a timer from CPerfLogGuard
200 /// with both log performance data to perf log and keep track of the timers for JSON reporting
202 {
203 public:
205  : m_TimeReporter(timer)
206  , m_TimerName(NStr::JsonEncode(sTimerName))
207  , m_PerfLogGuard(m_TimerName, state)
208  {
209  m_TimeReporter.Start(m_TimerName);
210  }
211 
212  ~CTimerPerfLogGuard() { m_TimeReporter.Stop(m_TimerName); }
213 
214  void AddParameter(CTempString name, CTempString value) { m_PerfLogGuard.AddParameter(name, NStr::JsonEncode(value)); }
215  void Stop(CRequestStatus::ECode status) { m_TimeReporter.Stop(m_TimerName); m_PerfLogGuard.Post(status); }
216  void Suspend() { m_PerfLogGuard.Suspend(); m_TimeReporter.Stop(m_TimerName); }
217  void Start() { m_PerfLogGuard.Start(); m_TimeReporter.Start(m_TimerName); }
218 
219 private:
221  string m_TimerName;
223 };
224 
225 
226 #ifdef VERBOSE_PERFLOG
227 #define START_VERBOSE_PERFLOG(id, msg, reporter) CTimerPerfLogGuard perfLog##id((msg), reporter)
228 #define START_VERBOSE_PERFLOG_COUNTED(id, msg, reporter) static size_t perf_count##id(0); CTimerPerfLogGuard perfLog##id(string(msg) + " " + NStr::NumericToString(++perf_count##id), reporter)
229 #define ADD_VERBOSE_PERFLOG_DESC(id, desc) perfLog##id.AddParameter("description", (desc))
230 #define STOP_VERBOSE_PERFLOG(id) perfLog##id.Stop(CRequestStatus::e200_Ok)
231 #else
232 #define START_VERBOSE_PERFLOG(id, msg)
233 #define START_VERBOSE_PERFLOG_COUNTED(id, msg)
234 #define ADD_VERBOSE_PERFLOG_DESC(id, desc)
235 #define STOP_VERBOSE_PERFLOG(id)
236 #endif
237 
238 
239 
241 
242 #endif // GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_UTILS__HPP
CBioseq_Handle –.
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
Utility classes for sequence graphical view rendering.
static bool IsMainFeature(int type, int subtype)
CScope –.
Definition: scope.hpp:92
CSeq_annot_Handle –.
CStopWatch –.
Definition: ncbitime.hpp:1938
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Helper classes for reporting times.of various steps executed by the CGI.
CTimeReporterEntry(const string &sTimerName)
void SetTimeDelta(double delta)
const string & GetTimerName()
CStopWatch & GetStopWatch()
double GetTimeDelta() const
void Stop(const string &sTimerName)
void Start(const string &sTimerName)
list< CRef< CTimeReporterEntry > > TTimeReporterEntries
CRef< CTimeReporterEntry > x_FindOrCreate(const string &sTimerName)
virtual void Write(CNcbiOstream &os)
TTimeReporterEntries m_Entries
void AddTime(const string &sTimerName, double add_time)
double GetTime(const string &sTimerName)
virtual ~CTimeReporter()
class combining functionality of CPerfLogGuard and a timer from CPerfLogGuard with both log performan...
CLogPerformance m_PerfLogGuard
void AddParameter(CTempString name, CTempString value)
void Stop(CRequestStatus::ECode status)
CTimeReporter & m_TimeReporter
CTimerPerfLogGuard(const string &sTimerName, CTimeReporter &timer, CPerfLogger::EStart state=CPerfLogger::eStart)
NStr –.
Definition: ncbistr.hpp:243
The NCBI C++ standard methods for dealing with std::string.
static unsigned char depth[2 *(256+1+29)+1]
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
EStart
If to start the timing immediately.
Definition: perf_log.hpp:83
@ eStart
Call Start() immediately after creating.
Definition: perf_log.hpp:84
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static string JsonEncode(const CTempString str, EJsonEncode encoding=eJsonEnc_UTF8)
Encode a string for JSON.
Definition: ncbistr.cpp:4634
#define NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
Defines to provide correct exporting from DLLs in Windows.
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
bool IsMitochondrion(CBioseq_Handle bsh)
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Defines: CTimeFormat - storage class for time format.
Int4 delta(size_t dimension_, const Int4 *score_)
Defines CRequestStatus class for NCBI C++ diagnostic API.
Definition: type.c:6
Modified on Sun Apr 14 05:27:14 2024 by modify_doxy.py rev. 669887