IntaRNA 3.4.1
RNA-RNA interaction prediction | C++ API
Loading...
Searching...
No Matches
OutputHandlerCsv.h
Go to the documentation of this file.
1
2#ifndef INTARNA_OUTPUTHANDLERCSV_H_
3#define INTARNA_OUTPUTHANDLERCSV_H_
4
5#include "IntaRNA/general.h"
6
10
11#include <iterator>
12#include <list>
13#include <map>
14#include <numeric>
15#include <utility>
16
17#include <boost/algorithm/string.hpp>
18
19namespace IntaRNA {
20
25{
26
27public:
28
30 static const std::string notAvailable;
31
32
90
92 typedef std::list<ColType> ColTypeList;
93
96
100 static
101 const std::map<ColType,std::string> &
103
104protected:
105
107 static std::map<ColType,std::string> colType2string;
108
112 static
113 void
115 if (colType2string.empty()) {
116 // fill container : ensure strings are non-redundant!
117 colType2string[id1] = "id1";
118 colType2string[id2] = "id2";
119 colType2string[seq1] = "seq1";
120 colType2string[seq2] = "seq2";
121 colType2string[start1] = "start1";
122 colType2string[end1] = "end1";
123 colType2string[start2] = "start2";
124 colType2string[end2] = "end2";
125 colType2string[subseq1] = "subseq1";
126 colType2string[subseq2] = "subseq2";
127 colType2string[subseqDP] = "subseqDP";
128 colType2string[subseqDB] = "subseqDB";
129 colType2string[hybridDP] = "hybridDP";
130 colType2string[hybridDB] = "hybridDB";
131 colType2string[hybridDPfull] = "hybridDPfull";
132 colType2string[hybridDBfull] = "hybridDBfull";
133 colType2string[bpList] = "bpList";
134 colType2string[E] = "E";
135 colType2string[Etotal] = "Etotal";
136 colType2string[ED1] = "ED1";
137 colType2string[ED2] = "ED2";
138 colType2string[Pu1] = "Pu1";
139 colType2string[Pu2] = "Pu2";
140 colType2string[E_init] = "E_init";
141 colType2string[E_loops] = "E_loops";
142 colType2string[E_dangleL] = "E_dangleL";
143 colType2string[E_dangleR] = "E_dangleR";
144 colType2string[E_endL] = "E_endL";
145 colType2string[E_endR] = "E_endR";
146 colType2string[E_hybrid] = "E_hybrid";
147 colType2string[E_norm] = "E_norm";
148 colType2string[E_hybridNorm] = "E_hybridNorm";
149 colType2string[E_add] = "E_add";
150 colType2string[w] = "w";
151 colType2string[seedStart1] = "seedStart1";
152 colType2string[seedEnd1] = "seedEnd1";
153 colType2string[seedStart2] = "seedStart2";
154 colType2string[seedEnd2] = "seedEnd2";
155 colType2string[seedE] = "seedE";
156 colType2string[seedED1] = "seedED1";
157 colType2string[seedED2] = "seedED2";
158 colType2string[seedPu1] = "seedPu1";
159 colType2string[seedPu2] = "seedPu2";
160 colType2string[Eall] = "Eall";
161 colType2string[Eall1] = "Eall1";
162 colType2string[Eall2] = "Eall2";
163 colType2string[EallTotal] = "EallTotal";
164 colType2string[Zall] = "Zall";
165 colType2string[Zall1] = "Zall1";
166 colType2string[Zall2] = "Zall2";
167 colType2string[P_E] = "P_E";
168 colType2string[RT] = "RT";
169 // ensure filling is complete
170 for (size_t i=0; i<ColTypeNumber; i++) {
171 if ( colType2string.find( static_cast<ColType>(i) ) == colType2string.end() ) {
172 throw std::runtime_error("OutputHandlerCsv::initColType2string() : ColType "+toString(i)+" without string representative");
173 }
174 }
175 }
176 }
177
178public:
179
194 , std::ostream & out
195 , const InteractionEnergy & energy
196 , const ColTypeList columns
197 , const std::string& colSep = ";"
198 , const bool printHeader = false
199 , const std::string& listSep = ":"
200 );
201
206
213 virtual
214 void
215 add( const Interaction & interaction );
216
223 static
224 std::string
225 list2string( const ColTypeList & colTypes, const std::string & sep );
226
239 static
241 string2list( const std::string & listString );
242
249 static
250 bool
251 needsZall( const ColTypeList & colTypes );
252
259 static
260 bool
261 needBPs( const ColTypeList & colTypes );
262
269 static
270 std::string
271 getHeader( const ColTypeList & colTypes, const std::string& colSep );
272
273
274protected:
275
277 using OutputHandler::Z;
278
280 std::ostream & out;
281
284
286 const std::list< ColType > columns;
287
289 std::string colSep;
290
292 std::string listSep;
293
294
295
296};
297
298
300
301inline
302const std::map<OutputHandlerCsv::ColType,std::string> &
308
310
311inline
312std::string
314list2string( const ColTypeList & colTypes, const std::string & sep )
315{
316 // init string encodings
318
319 // lamda function to add next column to list
320 auto addCol = [&](std::string a, ColType b) {
321 return std::move(a) + sep + colType2string[b];
322 };
323
324 // generate full list
325 return std::accumulate(std::next(colTypes.begin())
326 , colTypes.end()
327 , colType2string[*(colTypes.begin())] // start with first element
328 , addCol);
329}
330
332
333inline
337string2list( const std::string & stringEncoding )
338{
339 // init string encodings
341
342 ColTypeList list;
343 // empty string : give full list
344 if (stringEncoding.empty() || stringEncoding == "*") {
345 // generate list of all types
346 for (size_t c = 0; c < (size_t)ColTypeNumber; c++) {
347 list.push_back( static_cast<ColType>(c) );
348 }
349 }
350 else {
351 // find split position
352 size_t startPos = 0, splitPos = std::string::npos;
353 while (startPos != splitPos) {
354 splitPos = stringEncoding.find(',',startPos);
355 // get current type string
356 std::string curTypeString = stringEncoding.substr(startPos,splitPos-(splitPos==std::string::npos?0:startPos));
357 // trim leading/trailing whitespaces
358 boost::trim(curTypeString);
359 // try to find type encoding
360 bool notFound = true;
361 for (auto it = colType2string.begin(); notFound && it != colType2string.end(); it++ ) {
362 // check if type found (case insensitive for being user friendly
363 if ( boost::iequals( it->second, curTypeString) ) {
364 list.push_back( it->first );
365 notFound = false;
366 }
367 }
368 // check if error to be raised
369 if (notFound) {
370 throw std::runtime_error("OutputHandlerCsv::string2list("+stringEncoding+") contains unsupported ColType encoding '"+curTypeString+"'");
371 }
372 // update start of next interval encoding to parse
373 startPos = splitPos + (splitPos != std::string::npos ? 1 : 0);
374 }
375 }
376 return list;
377}
378
380
381inline
382bool
384needsZall( const ColTypeList & colTypes )
385{
386 for ( const auto& type : colTypes ) {
387 // check if type requires Zall computation
388 switch ( type ) {
389 case Eall:
390 case EallTotal:
391 case Zall:
392 case P_E:
393 return true;
394 default: // ignore all other types
395 break;
396 }
397 }
398 return false;
399}
400
402
403inline
404bool
406needBPs( const ColTypeList & colTypes )
407{
408 for ( const auto& type : colTypes ) {
409 // check if type requires Zall computation
410 switch ( type ) {
411 case hybridDB:
412 case hybridDBfull:
413 case hybridDP:
414 case hybridDPfull:
415 case bpList:
416 return true;
417 default: // ignore all other types
418 break;
419 }
420 }
421 return false;
422}
423
425
426inline
427std::string
429getHeader( const OutputHandlerCsv::ColTypeList & colList, const std::string& colSep )
430{
431 // return string
432 return list2string( colList, colSep ) + "\n";
433}
434
436
437} // namespace
438
439#endif /* OUTPUTHANDLERCSV_H_ */
Definition InteractionEnergy.h:20
Definition Interaction.h:28
Definition OutputConstraint.h:19
Definition OutputHandlerCsv.h:25
static ColTypeList string2list(const std::string &listString)
Definition OutputHandlerCsv.h:337
static const ColTypeList colTypeNumericSort
list of ColTypes that have to be sorted numerically
Definition OutputHandlerCsv.h:95
std::ostream & out
the output stream to write to
Definition OutputHandlerCsv.h:280
static std::string getHeader(const ColTypeList &colTypes, const std::string &colSep)
Definition OutputHandlerCsv.h:429
std::list< ColType > ColTypeList
list of ColTypes
Definition OutputHandlerCsv.h:92
virtual void add(const Interaction &interaction)
const InteractionEnergy & energy
the interaction energy function used for interaction computation
Definition OutputHandlerCsv.h:283
static const std::string notAvailable
string to encode not available values
Definition OutputHandlerCsv.h:30
static bool needsZall(const ColTypeList &colTypes)
Definition OutputHandlerCsv.h:384
ColType
the column types supported
Definition OutputHandlerCsv.h:34
@ Etotal
overall energy of the interaction including the intra-molecular ensemble energies (E+Eall1+Eall2)
Definition OutputHandlerCsv.h:53
@ seq2
full second sequence
Definition OutputHandlerCsv.h:38
@ P_E
probability of mfe within interaction ensemble (outConstraint.needZall)
Definition OutputHandlerCsv.h:86
@ start1
start index of hybrid in seq1
Definition OutputHandlerCsv.h:43
@ hybridDPfull
hybrid in VRNA dot-bracket notation for full sequence lengths
Definition OutputHandlerCsv.h:49
@ end1
end index of hybrid in seq1
Definition OutputHandlerCsv.h:44
@ E_hybridNorm
length normalized energy of hybridization only = E_hybrid / ln(length(seq1)*length(seq2))
Definition OutputHandlerCsv.h:66
@ E_init
initiation energy
Definition OutputHandlerCsv.h:58
@ E_loops
sum of loop energies (excluding E_init)
Definition OutputHandlerCsv.h:59
@ seedEnd1
end index of the seed in seq1
Definition OutputHandlerCsv.h:69
@ hybridDBfull
hybrid in dot-bar notation for full sequence lengths
Definition OutputHandlerCsv.h:50
@ seedEnd2
end index of the seed in seq2
Definition OutputHandlerCsv.h:71
@ Eall
ensemble energy of all interactions (outConstraint.needZall)
Definition OutputHandlerCsv.h:79
@ start2
start index of hybrid in seq2
Definition OutputHandlerCsv.h:45
@ Eall2
ensemble energy of all intra-molecular structures of seq2
Definition OutputHandlerCsv.h:81
@ seedE
overall energy of the seed only (including accessibility etc)
Definition OutputHandlerCsv.h:72
@ seedED2
ED value of seq2 of the seed only (excluding rest)
Definition OutputHandlerCsv.h:74
@ w
Boltzmann weight of the interaction energy.
Definition OutputHandlerCsv.h:77
@ seq1
full first sequence
Definition OutputHandlerCsv.h:37
@ ED1
ED value of seq1.
Definition OutputHandlerCsv.h:54
@ hybridDB
hybrid in dot-bar notation
Definition OutputHandlerCsv.h:48
@ seedStart2
start index of the seed in seq2
Definition OutputHandlerCsv.h:70
@ subseq2
interacting subsequence of second sequence
Definition OutputHandlerCsv.h:40
@ hybridDP
hybrid in VRNA dot-bracket notation
Definition OutputHandlerCsv.h:47
@ ColTypeNumber
number of column types
Definition OutputHandlerCsv.h:88
@ E_dangleL
dangling end contribution of base pair (start1,end2)
Definition OutputHandlerCsv.h:60
@ seedStart1
start index of the seed in seq1
Definition OutputHandlerCsv.h:68
@ Pu2
probability to be accessible for seq2
Definition OutputHandlerCsv.h:57
@ bpList
list of hybrid base pairs like (1,3),(4,2),...
Definition OutputHandlerCsv.h:51
@ Zall1
partition function of all intra-molecular structures of seq1
Definition OutputHandlerCsv.h:83
@ seedED1
ED value of seq1 of the seed only (excluding rest)
Definition OutputHandlerCsv.h:73
@ EallTotal
total ensemble energy (Eall+Eall1+Eall2) of all interactions including the intra-molecular ensemble e...
Definition OutputHandlerCsv.h:85
@ id1
id of first sequence
Definition OutputHandlerCsv.h:35
@ Eall1
ensemble energy of all intra-molecular structures of seq1
Definition OutputHandlerCsv.h:80
@ seedPu1
probability of seed region to be accessible for seq1
Definition OutputHandlerCsv.h:75
@ E_hybrid
energy of hybridization only = E - ED1 - ED2
Definition OutputHandlerCsv.h:64
@ seedPu2
probability of seed region to be accessible for seq2
Definition OutputHandlerCsv.h:76
@ E_endR
penalty of closing base pair (end1,start2)
Definition OutputHandlerCsv.h:63
@ Zall
partition function of all interactions (outConstraint.needZall)
Definition OutputHandlerCsv.h:82
@ subseq1
interacting subsequence of first sequence
Definition OutputHandlerCsv.h:39
@ Zall2
partition function of all intra-molecular structures of seq2
Definition OutputHandlerCsv.h:84
@ E_add
user provided energy shift
Definition OutputHandlerCsv.h:67
@ ED2
ED value of seq2.
Definition OutputHandlerCsv.h:55
@ Pu1
probability to be accessible for seq1
Definition OutputHandlerCsv.h:56
@ subseqDP
hybrid subsequences compatible with hybridDP
Definition OutputHandlerCsv.h:41
@ E
overall interaction energy
Definition OutputHandlerCsv.h:52
@ RT
the scaled temperature used for Boltzmann weight computation
Definition OutputHandlerCsv.h:87
@ E_norm
length normalized energy = E/ln(length(seq1)*length(seq2))
Definition OutputHandlerCsv.h:65
@ id2
id of second sequence
Definition OutputHandlerCsv.h:36
@ end2
end index of hybrid in seq2
Definition OutputHandlerCsv.h:46
@ E_dangleR
dangling end contribution of base pair (end1,start2)
Definition OutputHandlerCsv.h:61
@ subseqDB
hybrid subsequences compatible with hybridDB
Definition OutputHandlerCsv.h:42
@ E_endL
penalty of closing base pair (start1,end2)
Definition OutputHandlerCsv.h:62
std::string colSep
the column separator to be used
Definition OutputHandlerCsv.h:289
std::string listSep
the list separator to be used within single columns
Definition OutputHandlerCsv.h:292
static void initColType2string()
Definition OutputHandlerCsv.h:114
static std::map< ColType, std::string > colType2string
mapping of ColTypes to according strings
Definition OutputHandlerCsv.h:107
static const std::map< ColType, std::string > & getColType2string()
Definition OutputHandlerCsv.h:304
static std::string list2string(const ColTypeList &colTypes, const std::string &sep)
Definition OutputHandlerCsv.h:314
OutputHandlerCsv(const OutputConstraint &outConstraint, std::ostream &out, const InteractionEnergy &energy, const ColTypeList columns, const std::string &colSep=";", const bool printHeader=false, const std::string &listSep=":")
const std::list< ColType > columns
the sequence of columns to be reported
Definition OutputHandlerCsv.h:286
static bool needBPs(const ColTypeList &colTypes)
Definition OutputHandlerCsv.h:406
Definition OutputHandler.h:20
const OutputConstraint outConstraint
the output constraints to be applied
Definition OutputHandler.h:103
Z_type Z
overall partition function for the sequences provided in Z_energy
Definition OutputHandler.h:109
#define toString(x)
Definition general.h:60
Definition Accessibility.h:13