1
//////////////////////////////////////////////////////////////
4
// save the Base Pairing Probability Matrix for each sequences
5
//////////////////////////////////////////////////////////////
7
#ifndef __BBPMatrix_HPP__
8
#define __BBPMatrix_HPP__
12
#include "SparseMatrix.h"
13
#include "McCaskill.hpp"
24
int seqLength; // sequence length;
25
float cutOff; // the threshold of probability
29
SparseMatrix bppMat; // base pairing probability matrix 1-origin(1..seqLength)
30
BPPMatrix(int bppmode, const string &seq, int seqLength, float inCutOff = 0.0001) : seqLength (seqLength), cutOff(inCutOff) {
31
if( bppmode == 'r' ) // by katoh
33
else if( bppmode == 'w' )
34
setandwriteBPPMatrix(seq);
38
BPPMatrix(int seqLength, float inCutOff, const Trimat<float> & tmpBppMat) : seqLength(seqLength), cutOff(inCutOff) {
39
bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
43
void setBPPMatrix(const string &seq) {
44
const char *tmpSeq = seq.c_str();
45
McCaskill mc(seqLength, &tmpSeq[1]);
46
mc.calcPartitionFunction();
47
Trimat<float> tmpBppMat(seqLength + 1);
49
for (int i = 0; i < seqLength; i++) {
50
for(int j = i; j < seqLength; j++) {
51
tmpBppMat.ref(i+1, j+1) = mc.getProb(i,j);
54
bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
57
void setandwriteBPPMatrix(const string &seq) { // by katoh
58
const char *tmpSeq = seq.c_str();
59
McCaskill mc(seqLength, &tmpSeq[1]);
60
mc.calcPartitionFunction();
61
Trimat<float> tmpBppMat(seqLength + 1);
64
fprintf( stdout, ">\n" );
65
for (int i = 0; i < seqLength; i++) {
66
for(int j = i; j < seqLength; j++) {
67
tmpbp = mc.getProb(i,j);
69
fprintf( stdout, "%d %d %50.40f\n", i, j, tmpbp );
70
tmpBppMat.ref(i+1, j+1) = tmpbp;
73
bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
76
void readBPPMatrix(const string &seq) { // by katoh
77
const char *tmpSeq = seq.c_str();
82
static FILE *bppfp = NULL;
87
bppfp = fopen( "_bpp", "r" );
90
fprintf( stderr, "Cannot open _bpp.\n" );
95
Trimat<float> tmpBppMat(seqLength + 1);
96
fgets( oneline, 999, bppfp );
97
if( oneline[0] != '>' )
99
fprintf( stderr, "Format error\n" );
104
onechar = getc( bppfp );
105
ungetc( onechar, bppfp );
106
if( onechar == '>' || onechar == EOF ) break;
108
fgets( oneline, 999, bppfp );
109
sscanf( oneline, "%d %d %f", &posi, &posj, &prob );
110
// fprintf( stderr, "%d %d -> %f\n", posi, posj, prob );
111
tmpBppMat.ref(posi+1, posj+1) = prob;
114
bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
117
float GetProb(int i, int j) {
118
return bppMat.GetValue(i,j);
121
float GetLength() const {
125
void updateBPPMatrix(const Trimat<float> &inbppMat) {
126
bppMat.SetSparseMatrix(seqLength, seqLength, inbppMat, cutOff);
130
#endif // __BPPMatrix_HPP__