24 #ifndef OST_SEQ_PROFILE_HANDLE_HH
25 #define OST_SEQ_PROFILE_HANDLE_HH
36 #include <boost/shared_ptr.hpp>
38 namespace ost {
namespace seq {
59 memset(trans_, 0, 7*
sizeof(
Real));
69 memcpy(trans_, rhs.trans_, 7*
sizeof(
Real));
71 neff_i_ = rhs.neff_i_;
72 neff_d_ = rhs.neff_d_;
76 return trans_[transition];
80 trans_[transition] = prob;
108 return (!memcmp(trans_, rhs.trans_,
sizeof(trans_)) &&
109 neff_ == rhs.neff_ &&
110 neff_i_ == rhs.neff_i_ &&
111 neff_d_ == rhs.neff_d_);
116 memcpy(trans_, rhs.trans_, 7*
sizeof(
Real));
118 neff_i_ = rhs.neff_i_;
119 neff_d_ = rhs.neff_d_;
126 for (
uint i = 0; i < 7; ++i) {
127 p_data[i] =
static_cast<int16_t>(dat.trans_[i]*10000);
129 os.write(
reinterpret_cast<char*
>(p_data), 7*
sizeof(
int16_t));
132 neff_data[0] = dat.neff_;
133 neff_data[1] = dat.neff_i_;
134 neff_data[2] = dat.neff_d_;
135 os.write(
reinterpret_cast<char*
>(neff_data), 3*
sizeof(float));
143 is.read(
reinterpret_cast<char*
>(p_data), 7*
sizeof(
int16_t));
144 for (
uint i = 0; i < 7; ++i) {
145 dat.trans_[i] = p_data[i] * 0.0001;
149 is.read(
reinterpret_cast<char*
>(neff_data), 3*
sizeof(
float));
150 dat.neff_ = neff_data[0];
151 dat.neff_i_ = neff_data[1];
152 dat.neff_d_ = neff_data[2];
173 memset(freq_, 0,
sizeof(freq_));
177 memcpy(freq_, rhs.freq_,
sizeof(freq_));
184 memcpy(freq_, rhs.freq_,
sizeof(freq_));
188 }
else if(hmm_data_) {
203 throw Error(
"ProfileColumn has no HMM data set!");
210 throw Error(
"ProfileColumn has no HMM data set!");
212 return hmm_data_->GetProb(transition);
223 return !memcmp(freq_, rhs.freq_,
sizeof(freq_));
245 for (
uint i = 0; i < 20; ++i) {
246 data[i] =
static_cast<int16_t>(col.freq_[i]*10000);
248 os.write(
reinterpret_cast<char*
>(data),
sizeof(data));
251 bool has_hmm_data =
true;
252 os.write(
reinterpret_cast<char*
>(&has_hmm_data), 1);
253 os << *col.hmm_data_;
255 bool has_hmm_data =
false;
256 os.write(
reinterpret_cast<char*
>(&has_hmm_data), 1);
264 is.read(
reinterpret_cast<char*
>(data),
sizeof(data));
266 for (
uint i = 0; i < 20; ++i) {
267 col.freq_[i] = data[i] * 0.0001;
271 is.read(
reinterpret_cast<char*
>(&has_hmm_data), 1);
273 is >> *col.hmm_data_;
298 const std::vector<ProfileColumn>&
GetColumns()
const {
return columns_; }
303 null_model_ = null_model;
309 if (seq.length() != columns_.size()) {
310 throw Error(
"ProfileHandle - Inconsistency between number of columns and "
335 columns_.push_back(c);
341 void clear() { seq_ =
""; columns_.clear(); }
343 size_t size()
const {
return columns_.size(); }
345 bool empty()
const {
return columns_.empty(); }
360 return seq_ == other.seq_ &&
361 columns_ == other.columns_ &&
362 null_model_ == other.null_model_;
366 return !(other == (*this));
370 ProfileColumnList::iterator
columns_end() {
return columns_.end(); }
372 return columns_.begin();
375 return columns_.end();
383 os << prof.null_model_;
386 os.write(
reinterpret_cast<char*
>(&size),
sizeof(
uint32_t));
388 if (prof.seq_.length() != size) {
389 throw Error(
"ProfileHandle - Inconsistency between number of columns and "
392 os.write(prof.seq_.c_str(), size);
394 for(
uint i = 0; i < size; ++i){
395 os << prof.columns_[i];
403 is >> prof.null_model_;
406 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
uint32_t));
408 std::vector<char> tmp_buf(size);
409 is.read(&tmp_buf[0], size);
410 prof.seq_.assign(&tmp_buf[0], size);
412 prof.columns_.resize(size);
413 for(
uint i = 0; i < size; ++i){
414 is >> prof.columns_[i];
440 size_t size()
const {
return data_.size(); }
445 std::map<String, ProfileHandlePtr> data_;
HMMData & operator=(const HMMData &rhs)
HMMData(const HMMData &rhs)
void SetNeff_D(Real neff)
bool operator==(const HMMData &rhs) const
Real GetProb(HMMTransition transition) const
bool operator!=(const HMMData &rhs) const
friend std::ifstream & operator>>(std::ifstream &is, HMMData &dat)
void SetNeff_I(Real neff)
friend std::ofstream & operator<<(std::ofstream &os, HMMData &dat)
void SetProb(HMMTransition transition, Real prob)
Defines profile of 20 frequencies for one residue.
const Real * freqs_end() const
Real GetScore(const ProfileColumn &other, const ProfileColumn &null_model) const
Get column score as in Soeding-2005.
friend std::ofstream & operator<<(std::ofstream &os, ProfileColumn &col)
static ProfileColumn BLOSUMNullModel()
static ProfileColumn HHblitsNullModel()
ProfileColumn(const ProfileColumn &rhs)
void SetHMMData(HMMDataPtr p)
Real GetFreq(char ch) const
static int GetIndex(char ch)
Translate one-letter-code to index (0-indexing).
const Real * freqs_begin() const
bool operator==(const ProfileColumn &rhs) const
friend std::ifstream & operator>>(std::ifstream &is, ProfileColumn &col)
void SetFreq(char ch, Real freq)
HMMDataPtr GetHMMData() const
ProfileColumn()
Construct a profile with all frequencies set to 0.
Real GetTransProb(HMMTransition transition) const
bool operator!=(const ProfileColumn &rhs) const
Real GetEntropy() const
Get entropy for this column.
Contains a DB of profiles (identified by a unique name (String)).
static ProfileDBPtr Load(const String &filename)
void AddProfile(const String &name, ProfileHandlePtr prof)
std::vector< String > GetNames() const
ProfileHandlePtr GetProfile(const String &name) const
void Save(const String &filename) const
Saves all profiles in DB with limited accuracy of internal data. Binary format with fixed-width integ...
Provides a profile for a sequence.
void AddColumn(const ProfileColumn &c, char olc='X')
ProfileColumnList::iterator columns_end()
bool operator==(const ProfileHandle &other) const
void SetNullModel(const ProfileColumn &null_model)
bool operator!=(const ProfileHandle &other) const
const ProfileColumn & GetNullModel() const
ProfileColumnList::iterator columns_begin()
Real GetAverageEntropy() const
Compute average entropy over all columns.
const ProfileColumn & at(size_t index) const
ProfileColumnList::const_iterator columns_begin() const
ProfileColumnList::const_iterator columns_end() const
const ProfileColumn & operator[](size_t index) const
ProfileColumn & at(size_t index)
Real GetAverageScore(const ProfileHandle &other, uint offset=0) const
Compute score comparing columns other[i] and this->at(i+offset) Column score as in Soeding-2005,...
friend std::ifstream & operator>>(std::ifstream &is, ProfileHandle &prof)
void SetSequence(const String &seq)
ProfileHandle()
Constructs an empty profile handle (sequence = '', 0 columns).
const std::vector< ProfileColumn > & GetColumns() const
ProfileColumn & operator[](size_t index)
const ProfileColumn & back() const
ProfileHandlePtr Extract(uint from, uint to) const
Extract subset of profile for columns from until to-1 (0-indexing). Null model is copied from this pr...
String GetSequence() const
friend std::ofstream & operator<<(std::ofstream &os, ProfileHandle &prof)
boost::shared_ptr< HMMData > HMMDataPtr
std::vector< ProfileColumn > ProfileColumnList
boost::shared_ptr< ProfileHandle > ProfileHandlePtr
boost::shared_ptr< ProfileDB > ProfileDBPtr
std::vector< ProfileHandlePtr > ProfileHandleList
#define DLLEXPORT_OST_SEQ