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

Go to the SVN repository for this file.

1 /* $Id: discrepancy.hpp 100085 2023-06-14 14:03:13Z asztalos $
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: Sema
27  * Created: 01/29/2015
28  */
29 
30 #ifndef _MISC_DISCREPANCY_DISCREPANCY_H_
31 #define _MISC_DISCREPANCY_DISCREPANCY_H_
32 
33 #include <corelib/ncbiobj.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <util/compile_time.hpp>
36 
37 #define NEW_DISCREPANCY_API
38 
40 
41 class CSerialObject;
42 class CObjectIStream;
43 
45 class CSuspect_rule_set;
46 class CSuspect_rule;
47 class CScope;
48 class CSeq_feat;
49 
51 
53 
54 #include "testnames.inc"
55 
56 enum class eTestTypes
57 {
58  SEQUENCE,
59  FEAT,
60  STRING,
61  SEQ_SET,
62  DESC,
63  BIOSRC,
64  AUTHORS,
65  SUBMIT,
66  PUBDESC,
68 };
69 
70 using TTestNamesSet = ct::const_bitset<static_cast<size_t>(eTestNames::max_test_names), eTestNames>;
71 template<eTestTypes _type>
72 using TTypeTag = std::integral_constant<eTestTypes, _type>;
73 
75 {
76 public:
77  enum EType {
83  eType_string
84  };
85  virtual ~CReportObj(){}
86 
87  virtual string GetBioseqLabel() const = 0;
88  virtual string GetText() const = 0;
89  virtual string GetPath() const = 0;
90  virtual string GetFeatureType() const = 0;
91  virtual string GetProductName() const = 0;
92  virtual string GetLocation() const = 0;
93  virtual string GetLocusTag() const = 0;
94  virtual string GetShort() const = 0;
95  virtual EType GetType() const = 0;
96  virtual bool CanAutofix() const = 0;
97  virtual bool IsFixed() const = 0;
98  virtual void SetMoreInfo(CObject* data) = 0;
99 };
100 typedef vector<CRef<CReportObj> > TReportObjectList;
101 
102 
104 {
105 public:
106  CAutofixReport(const string&s, unsigned int n) : S(s), N(n) {}
107  void AddSubitems(const vector<CRef<CAutofixReport>>& v) { copy(v.begin(), v.end(), back_inserter(V)); }
108  string GetS() const { return S; }
109  unsigned int GetN() const { return N; }
110  const vector<CRef<CAutofixReport>>& GetSubitems() { return V; }
111 protected:
112  string S;
113  unsigned int N;
114  vector<CRef<CAutofixReport>> V;
115 };
116 
117 
119 {
120 public:
121  enum ESeverity {
122  eSeverity_info = 0,
123  eSeverity_warning = 1,
124  eSeverity_error = 2
125  };
126  virtual ~CReportItem(){}
127 
128  virtual string_view GetTitle() const = 0;
129  virtual string GetStr() const = 0;
130  virtual string GetMsg() const = 0;
131  virtual string GetXml() const = 0;
132  virtual string GetUnit() const = 0;
133  virtual size_t GetCount() const = 0;
134  virtual TReportObjectList GetDetails() const = 0;
135  virtual vector<CRef<CReportItem> > GetSubitems() const = 0;
136  virtual bool CanAutofix() const = 0;
137  virtual ESeverity GetSeverity() const = 0;
138  virtual bool IsFatal() const = 0;
139  virtual bool IsInfo() const = 0;
140  virtual bool IsExtended() const = 0;
141  virtual bool IsSummary() const = 0;
142  virtual bool IsReal() const = 0;
143 
144  /// @deprecated
145  /// use CReportItemFactory::Create() function
147  static CRef<CReportItem> CreateReportItem(const string& test, const CReportObj& obj, const string& msg, bool autofix = false);
148 };
149 typedef vector<CRef<CReportItem> > TReportItemList;
150 
151 
153 {
154 public:
155  static CRef<CReportItem> Create(const string& test_name, const string& name, const CReportObj& main_obj, const TReportObjectList& report_objs, bool autofix = false);
156 };
157 
159 {
160 public:
161  virtual ~CDiscrepancyCase(){}
162  virtual eTestNames GetName() const = 0;
163  virtual string_view GetSName() const = 0;
164  virtual eTestTypes GetType() const = 0;
165  virtual string_view GetDescription() const = 0;
166  virtual const TReportItemList& GetReport() const = 0;
167  virtual TReportObjectList GetObjects() const = 0;
168 };
169 
171 {
172 public:
173  virtual void OutputText(CNcbiOstream& out, unsigned short flags, char group = 0) = 0;
174  virtual void OutputXML(CNcbiOstream& out, unsigned short flags) = 0;
175  virtual void Merge(CDiscrepancyProduct& other) = 0;
176  virtual void Summarize() = 0;
177 };
178 
180 
181 
183 {
184 protected:
186 public:
187  virtual ~CDiscrepancySet(){}
188 
189  virtual CRef<CDiscrepancyProduct> RunTests(const TTestNamesSet& testnames, const CSerialObject& object, const string& filename) = 0;
191 
192  virtual unsigned Summarize() = 0;
194  virtual void ParseStream(CObjectIStream& stream, const string& fname, bool skip, const string& default_header = kEmptyStr) = 0;
195  virtual void AddTest(eTestNames name) = 0;
196  NCBI_DEPRECATED virtual void AddTest(string_view name) = 0;
197  virtual void ParseStrings(const string& fname) = 0;
198  NCBI_DEPRECATED virtual void Push(const CSerialObject& root, const string& fname = kEmptyStr) = 0;
199  NCBI_DEPRECATED virtual void Parse() = 0;
200  virtual TDiscrepancyCaseMap GetTests() const = 0;
201  NCBI_DEPRECATED virtual void Autofix(TReportObjectList& tofix, map<string, size_t>& rep, const string& default_header = kEmptyStr) = 0;
202 #if 0
203  template<typename Container>
204  bool AddTests(const Container& cont)
205  {
206  bool success = true;
207  for_each(cont.begin(), cont.end(), [this, &success](const string& test_name) { success &= this->AddTest(test_name); });
208  return success;
209  }
210 
211  virtual void Parse(const CSerialObject& root, const string& fname = kEmptyStr) { Push(root, fname); Parse(); }
212  virtual void TestString(const string& str) = 0;
213  virtual void OutputText(CNcbiOstream& out, unsigned short flags, char group = 0) = 0;
214  virtual void OutputXML(CNcbiOstream& out, unsigned short flags) = 0;
215 #endif
216 
217  enum EOutput {
218  eOutput_Summary = 1 << 0, // only summary
219  eOutput_Fatal = 1 << 1, // print FATAL
220  eOutput_Ext = 1 << 2, // extended output
221  eOutput_Files = 1 << 3 // print file name
222  };
223 
224  void SetUserData(void* p){ m_UserData = p; }
225  void* GetUserData() const { return m_UserData; }
226 
227  static void SetGui(bool b){ m_Gui = b; }
228  static bool IsGui() { return m_Gui; }
229 
230  const string& GetLineage() const { return m_Lineage; }
231  void SetLineage(const string& s) { m_Lineage = s; }
232 
233  //float GetSesameStreetCutoff() const { return m_SesameStreetCutoff; }
234  //void SetSesameStreetCutoff(float f){ m_SesameStreetCutoff = f; }
235 
236  virtual void SetSuspectRules(const string& name, bool read = true) = 0;
237  static CRef<CDiscrepancySet> New(objects::CScope& scope);
238  static string Format(const string& str, unsigned int count);
239  virtual const CSerialObject* FindObject(CReportObj& obj, bool alt = false) = 0;
240 
241 protected:
242  string m_Lineage;
243  //float m_SesameStreetCutoff = 0.75;
244  static std::atomic<bool> m_Gui;
245  void* m_UserData = nullptr;
246 };
247 
248 
249 // This is GUI structure, consider moving to it to appropriate location
251 {
252 public:
253  CDiscrepancyGroup(const string& name = "", const string& test = "");// : m_Name(name), m_Test(test) {}
254  void Add(CRef<CDiscrepancyGroup> child) { m_List.push_back(child); }
255  TReportItemList Collect(TDiscrepancyCaseMap& tests, bool all = true) const;
256  const CDiscrepancyGroup& operator[](size_t n) const { return *m_List[n]; }
257 
258 protected:
259  string m_Name;
260  eTestNames m_Test;
261  vector<CRef<CDiscrepancyGroup> > m_List;
262 };
263 
264 
265 enum EGroup {
266  eAll = 0,
267  eDisc = 1,
270  eSmart = 8,
271  eBig = 16,
272  eTSA = 32,
273  eFatal = 64,
274  eAutofix = 128,
275 };
276 typedef unsigned short TGroup;
277 
278 
279 NCBI_DISCREPANCY_EXPORT eTestNames GetDiscrepancyCaseName(string_view);
280 NCBI_DISCREPANCY_EXPORT string_view GetDiscrepancyCaseName(eTestNames name);
281 NCBI_DISCREPANCY_EXPORT string_view GetDiscrepancyDescr(eTestNames name);
284 NCBI_DISCREPANCY_EXPORT vector<string_view> GetDiscrepancyAliases(eTestNames name);
285 
286 NCBI_DEPRECATED NCBI_DISCREPANCY_EXPORT string_view GetDiscrepancyDescr(string_view name);
289 
290 NCBI_DISCREPANCY_EXPORT bool IsShortrRNA(const objects::CSeq_feat& f, objects::CScope* scope);
291 
292 typedef std::function < CRef<objects::CSeq_feat>() > GetFeatureFunc;
293 NCBI_DISCREPANCY_EXPORT string FixProductName(const objects::CSuspect_rule* rule, objects::CScope& scope, string& prot_name, GetFeatureFunc get_mrna, GetFeatureFunc get_cds);
294 
297 
298 NCBI_DISCREPANCY_EXPORT std::ostream& operator<<(std::ostream& str, NDiscrepancy::eTestNames name);
299 
301 
303 
304 
305 #endif // _MISC_DISCREPANCY_DISCREPANCY_H_
string GetS() const
CAutofixReport(const string &s, unsigned int n)
vector< CRef< CAutofixReport > > V
const vector< CRef< CAutofixReport > > & GetSubitems()
unsigned int N
void AddSubitems(const vector< CRef< CAutofixReport >> &v)
unsigned int GetN() const
CConstRef –.
Definition: ncbiobj.hpp:1266
virtual string_view GetDescription() const =0
virtual eTestTypes GetType() const =0
virtual string_view GetSName() const =0
virtual const TReportItemList & GetReport() const =0
virtual ~CDiscrepancyCase()
virtual TReportObjectList GetObjects() const =0
virtual eTestNames GetName() const =0
const CDiscrepancyGroup & operator[](size_t n) const
vector< CRef< CDiscrepancyGroup > > m_List
void Add(CRef< CDiscrepancyGroup > child)
virtual void OutputXML(CNcbiOstream &out, unsigned short flags)=0
virtual void Merge(CDiscrepancyProduct &other)=0
virtual void Summarize()=0
virtual void OutputText(CNcbiOstream &out, unsigned short flags, char group=0)=0
virtual CRef< CDiscrepancyProduct > RunTests(const TTestNamesSet &testnames, const CSerialObject &object, const string &filename)=0
virtual void AddTest(eTestNames name)=0
virtual void Autofix(TReportObjectList &tofix, map< string, size_t > &rep, const string &default_header=kEmptyStr)=0
static bool IsGui()
virtual unsigned Summarize()=0
void * GetUserData() const
virtual void Parse()=0
virtual void ParseStream(CObjectIStream &stream, const string &fname, bool skip, const string &default_header=kEmptyStr)=0
void SetLineage(const string &s)
void SetUserData(void *p)
virtual void AddTest(string_view name)=0
virtual void Push(const CSerialObject &root, const string &fname=kEmptyStr)=0
virtual map< string, size_t > Autofix()=0
static std::atomic< bool > m_Gui
virtual void SetSuspectRules(const string &name, bool read=true)=0
const string & GetLineage() const
static void SetGui(bool b)
virtual void ParseStrings(const string &fname)=0
virtual ~CDiscrepancySet()
virtual CRef< CDiscrepancyProduct > GetProduct()=0
virtual const CSerialObject * FindObject(CReportObj &obj, bool alt=false)=0
virtual TDiscrepancyCaseMap GetTests() const =0
CObjectIStream –.
Definition: objistr.hpp:93
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
virtual string_view GetTitle() const =0
virtual vector< CRef< CReportItem > > GetSubitems() const =0
virtual bool IsExtended() const =0
virtual bool IsSummary() const =0
virtual string GetStr() const =0
virtual string GetXml() const =0
virtual string GetUnit() const =0
virtual ESeverity GetSeverity() const =0
virtual TReportObjectList GetDetails() const =0
virtual bool CanAutofix() const =0
virtual ~CReportItem()
virtual string GetMsg() const =0
virtual bool IsInfo() const =0
virtual bool IsFatal() const =0
virtual bool IsReal() const =0
virtual size_t GetCount() const =0
virtual string GetFeatureType() const =0
virtual string GetBioseqLabel() const =0
virtual string GetLocation() const =0
virtual string GetPath() const =0
virtual string GetProductName() const =0
virtual bool IsFixed() const =0
virtual ~CReportObj()
Definition: discrepancy.hpp:85
@ eType_submit_block
Definition: discrepancy.hpp:82
virtual bool CanAutofix() const =0
virtual string GetLocusTag() const =0
virtual EType GetType() const =0
virtual void SetMoreInfo(CObject *data)=0
virtual string GetShort() const =0
virtual string GetText() const =0
CScope –.
Definition: scope.hpp:92
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Base class for all serializable objects.
Definition: serialbase.hpp:150
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
bool IsShortrRNA(const objects::CSeq_feat &f, objects::CScope *scope)
vector< CRef< CReportItem > > TReportItemList
vector< CRef< CReportObj > > TReportObjectList
eTestTypes
Definition: discrepancy.hpp:57
TGroup GetDiscrepancyGroup(eTestNames name)
CConstRef< objects::CSuspect_rule_set > GetProductRules(const string &name="")
eTestNames GetDiscrepancyCaseName(string_view)
vector< string_view > GetDiscrepancyAliases(eTestNames name)
EGroup
@ eFatal
@ eAll
@ eTSA
@ eBig
@ eAutofix
@ eDisc
@ eOncaller
@ eSubmitter
@ eSmart
unsigned short TGroup
TTestNamesSet GetDiscrepancyTests(TGroup group)
CConstRef< objects::CSuspect_rule_set > GetOrganelleProductRules(const string &name="")
std::ostream & operator<<(std::ostream &str, NDiscrepancy::eTestNames name)
std::integral_constant< eTestTypes, _type > TTypeTag
Definition: discrepancy.hpp:72
NCBI_DISCREPANCY_EXPORT vector< string > GetDiscrepancyNames(TGroup group=EGroup::eAll)
string FixProductName(const objects::CSuspect_rule *rule, objects::CScope &scope, string &prot_name, GetFeatureFunc get_mrna, GetFeatureFunc get_cds)
map< eTestNames, CRef< CDiscrepancyCase > > TDiscrepancyCaseMap
string_view GetDiscrepancyDescr(eTestNames name)
std::function< CRef< objects::CSeq_feat >) > GetFeatureFunc
std::ofstream out("events_result.xml")
main entry point for tests
#define S(s)
#define test(a, b, c, d, e)
Definition: numeric.c:170
static const char * str(char *buf, int n)
Definition: stats.c:84
static DbTestEntry * tests
Definition: testodbc.c:388
static FILE * f
Definition: readconf.c:23
static char test_name[128]
Definition: utf8_2.c:34
char data[12]
Definition: iconv.c:80
#define NCBI_DEPRECATED
#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
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_DISCREPANCY_EXPORT
Definition: ncbi_export.h:945
yy_size_t n
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Format
Definition: njn_ioutil.hpp:52
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
#define count
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define N
Definition: crc32.c:57
Modified on Fri Sep 20 14:58:10 2024 by modify_doxy.py rev. 669887