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);
216 static int GetIndex(
char ch);
218 Real GetFreq(
char ch)
const;
220 void SetFreq(
char ch,
Real freq);
223 return !memcmp(freq_, rhs.freq_,
sizeof(freq_));
233 Real GetEntropy()
const;
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 "
326 Real GetAverageEntropy()
const;
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];
432 void Save(
const String& filename)
const;
440 size_t size()
const {
return data_.size(); }
442 std::vector<String> GetNames()
const;
445 std::map<String, ProfileHandlePtr> data_;
#define DLLEXPORT_OST_SEQ
bool operator==(const ProfileHandle &other) const
HMMDataPtr GetHMMData() const
void SetSequence(const String &seq)
const ProfileColumn & operator[](size_t index) const
ProfileColumn & operator[](size_t index)
bool operator!=(const HMMData &rhs) const
void AddColumn(const ProfileColumn &c, char olc='X')
ProfileColumnList::const_iterator columns_end() const
ProfileColumn(const ProfileColumn &rhs)
HMMData(const HMMData &rhs)
const ProfileColumn & GetNullModel() const
friend std::ofstream & operator<<(std::ofstream &os, HMMData &dat)
boost::shared_ptr< HMMData > HMMDataPtr
bool operator==(const HMMData &rhs) const
const std::vector< ProfileColumn > & GetColumns() const
const ProfileColumn & back() const
friend std::ifstream & operator>>(std::ifstream &is, ProfileHandle &prof)
String GetSequence() const
ProfileColumnList::iterator columns_begin()
ProfileColumn()
Construct a profile with all frequencies set to 0.
T Extract(const info::InfoGroup &g, const String &n)
Convenience function to extract a value from an item.
std::vector< ProfileColumn > ProfileColumnList
ProfileHandle()
Constructs an empty profile handle (sequence = '', 0 columns).
ProfileColumn & at(size_t index)
friend std::ifstream & operator>>(std::ifstream &is, ProfileColumn &col)
Provides a profile for a sequence.
void SetNullModel(const ProfileColumn &null_model)
ProfileColumnList::const_iterator columns_begin() const
boost::shared_ptr< ProfileDB > ProfileDBPtr
bool operator==(const ProfileColumn &rhs) const
ProfileColumnList::iterator columns_end()
std::vector< ProfileHandlePtr > ProfileHandleList
boost::shared_ptr< ProfileHandle > ProfileHandlePtr
bool operator!=(const ProfileHandle &other) const
friend std::ofstream & operator<<(std::ofstream &os, ProfileColumn &col)
const ProfileColumn & at(size_t index) const
HMMData & operator=(const HMMData &rhs)
friend std::ifstream & operator>>(std::ifstream &is, HMMData &dat)
void SetNeff_I(Real neff)
bool operator!=(const ProfileColumn &rhs) const
Real GetTransProb(HMMTransition transition) const
void SetNeff_D(Real neff)
Defines profile of 20 frequencies for one residue.
void SetProb(HMMTransition transition, Real prob)
Contains a DB of profiles (identified by a unique name (String)).
Real GetProb(HMMTransition transition) const
const Real * freqs_begin() const
void SetHMMData(HMMDataPtr p)
const Real * freqs_end() const
friend std::ofstream & operator<<(std::ofstream &os, ProfileHandle &prof)