-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_cbust_pssm.cpp
65 lines (60 loc) · 1.64 KB
/
get_cbust_pssm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Read a position specific weight/count/score matrix in eFASTA format
#include "get_cbust_pssm.hpp"
#include <istream>
#include <sstream>
// Industrial strength PSSM reader
// (alphsize could be figured out from the number of entries per line...)
std::istream &cb::get_cbust_pssm(
std::istream &strm, mcf::matrix<float> &mat, std::string &title,
float &weight, float &gap,
unsigned alphsize) // not allowed to repeat the default argument?
{
std::string t;
float w = 1; // default weight, if none is supplied
float g = -1; // dummy value for gap if none is supplied
mcf::matrix<float> m(0, alphsize);
char c = 0;
bool titflag = false; // have we read a title line yet?
while (strm >> c) {
if (c == '>') {
if (titflag || m.rows() != 0) {
strm.unget();
break;
} else {
std::getline(strm, t);
titflag = true;
w = 1; // reset weight to default
}
} else if (c == '#') {
std::string temp;
std::getline(strm, temp);
std::istringstream is(temp);
is >> temp;
if (temp == "WEIGHT")
is >> w;
else if (temp == "GAP")
is >> g;
} else {
strm.unget();
std::vector<float> v;
for (unsigned i = 0; i < alphsize; ++i) {
float d;
strm >> d;
v.push_back(d);
}
if (!strm)
return strm; // failed to read alphsize doubles
m.push_row(v.begin());
}
}
// if reached EOF but read something, clear the stream state:
if (strm.eof() && (titflag || m.rows() != 0))
strm.clear();
if (strm) {
title = t;
weight = w;
gap = g;
mat = m;
}
return strm;
}