IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
OutputHandler.h
Go to the documentation of this file.
1
2#ifndef INTARNA_OUTPUTHANDLER_H_
3#define INTARNA_OUTPUTHANDLER_H_
4
5#include "IntaRNA/general.h"
10#include <string>
11#include <exception>
12
13namespace IntaRNA {
14
23
24public:
25
31
35 virtual ~OutputHandler();
36
37
49 virtual
50 void
51 add( const Interaction & interaction ) = 0;
52
57 virtual
58 size_t
59 reported() const;
60
61
67 static
68 std::string
69 reverse( const std::string & str );
70
80 virtual
81 void
82 incrementZ( const Z_type subZ );
83
90 virtual
91 Z_type
92 getZ() const;
93
98 const OutputConstraint &
99 getOutputConstraint() const;
100
101
105 virtual void setExactPartition(bool exact);
107 bool usesExactPartition() const;
109 bool hasNonzeroZ() const;
110
111protected:
113 bool exactPartition = false;
114
117
120
123
124};
125
126
130
131inline
133 : outConstraint(outConstraint)
134 , reportedInteractions(0)
135 , Z(0)
136{
137}
138
140
141inline
144
146
147inline
148std::string
150reverse( const std::string & str )
151{
152 return std::string(str.rbegin(), str.rend());
153}
154
156
157inline
158size_t
160reported() const
161{
163}
164
166
167inline
168Z_type
170getZ() const
171{
172 return Z;
173}
174
176
177inline
178const OutputConstraint &
181{
182 return outConstraint;
183}
184
186
187inline
188void
190incrementZ( const Z_type subZ )
191{
192#if INTARNA_IN_DEBUG_MODE
193 if (std::numeric_limits<Z_type>::max() - subZ <= Z) {
194 LOG(WARNING) <<"OutputHandler::incrementZ() : partition function overflow! Recompile with larger partition function data type!";
195 }
196#endif
197 // Capture range failures within the OpenMP structured block.
198 std::exception_ptr failure;
199#if INTARNA_MULITHREADING
200 #pragma omp critical(intarna_omp_outputHandlerIncrementZ)
201#endif
202 {
203 try { Z = exactPartition ? PartitionArithmetic::add(Z,subZ) : Z+subZ; }
204 catch (...) { failure=std::current_exception(); }
205 }
206 if (failure) std::rethrow_exception(failure);
207}
208
210
211inline void OutputHandler::setExactPartition(bool exact) { exactPartition=exact; }
213inline bool OutputHandler::hasNonzeroZ() const { return exactPartition ? getZ()!=0 : !Z_equal(getZ(),Z_type(0)); }
214
215} // namespace
216
217#endif /* OUTPUTHANDLER_H_ */
Definition Interaction.h:28
Definition OutputConstraint.h:19
Definition OutputHandler.h:22
static std::string reverse(const std::string &str)
Definition OutputHandler.h:150
OutputHandler(const OutputConstraint &outConstraint)
Definition OutputHandler.h:132
const OutputConstraint outConstraint
the output constraints to be applied
Definition OutputHandler.h:116
bool usesExactPartition() const
Definition OutputHandler.h:212
const OutputConstraint & getOutputConstraint() const
Definition OutputHandler.h:180
virtual void incrementZ(const Z_type subZ)
Definition OutputHandler.h:190
virtual Z_type getZ() const
Definition OutputHandler.h:170
virtual ~OutputHandler()
Definition OutputHandler.h:142
bool exactPartition
scoped to a supported sequence-pair ensemble, legacy outputs default false
Definition OutputHandler.h:113
bool hasNonzeroZ() const
Definition OutputHandler.h:213
Z_type Z
overall partition function for the sequences provided in Z_energy
Definition OutputHandler.h:122
virtual void setExactPartition(bool exact)
Definition OutputHandler.h:211
virtual void add(const Interaction &interaction)=0
size_t reportedInteractions
number of reported interactions
Definition OutputHandler.h:119
virtual size_t reported() const
Definition OutputHandler.h:160
static Z_type add(const Z_type a, const Z_type b)
Definition PartitionArithmetic.h:30
#define Z_equal(e1, e2)
check if two energies are equal according to some epsilon
Definition general.h:154
Definition Accessibility.h:13
double Z_type
type for probabilities, RT and Boltzmann values
Definition general.h:88