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 {
57 memset(freq_, 0,
sizeof(freq_));
61 memcpy(freq_, rhs.freq_,
sizeof(freq_));
64 memcpy(freq_, rhs.freq_,
sizeof(freq_));
72 static int GetIndex(
char ch);
74 Real GetFreq(
char ch)
const;
76 void SetFreq(
char ch,
Real freq);
79 return !memcmp(freq_, rhs.freq_,
sizeof(freq_));
89 Real GetEntropy()
const;
101 for (
uint i = 0; i < 20; ++i) {
102 data[i] =
static_cast<int16_t>(col.freq_[i]*10000);
104 os.write(reinterpret_cast<char*>(data),
sizeof(data));
110 is.read(reinterpret_cast<char*>(data),
sizeof(data));
112 for (
uint i = 0; i < 20; ++i) {
113 col.freq_[i] = data[i] * 0.0001;
136 const std::vector<ProfileColumn>&
GetColumns()
const {
return columns_; }
141 null_model_ = null_model;
147 if (seq.length() != columns_.size()) {
148 throw Error(
"ProfileHandle - Inconsistency between number of columns and "
160 Real GetAverageEntropy()
const;
169 columns_.push_back(c);
175 void clear() { seq_ =
""; columns_.clear(); }
177 size_t size()
const {
return columns_.size(); }
179 bool empty()
const {
return columns_.empty(); }
190 return seq_ == other.seq_ &&
191 columns_ == other.columns_ &&
192 null_model_ == other.null_model_;
196 return !(other == (*this));
200 ProfileColumnList::iterator
columns_end() {
return columns_.end(); }
202 return columns_.begin();
205 return columns_.end();
213 os << prof.null_model_;
216 os.write(reinterpret_cast<char*>(&size),
sizeof(
uint32_t));
218 if (prof.seq_.length() != size) {
219 throw Error(
"ProfileHandle - Inconsistency between number of columns and "
222 os.write(prof.seq_.c_str(), size);
224 for(
uint i = 0; i < size; ++i){
225 os << prof.columns_[i];
233 is >> prof.null_model_;
236 is.read(reinterpret_cast<char*>(&size),
sizeof(
uint32_t));
238 std::vector<char> tmp_buf(size);
239 is.read(&tmp_buf[0], size);
240 prof.seq_.assign(&tmp_buf[0], size);
242 prof.columns_.resize(size);
243 for(
uint i = 0; i < size; ++i){
244 is >> prof.columns_[i];
261 void Save(
const String& filename)
const;
269 size_t size()
const {
return data_.size(); }
271 std::vector<String> GetNames()
const;
274 std::map<String, ProfileHandlePtr> data_;
#define DLLEXPORT_OST_SEQ
bool operator==(const ProfileHandle &other) const
void SetSequence(const String &seq)
const ProfileColumn & operator[](size_t index) const
ProfileColumn & operator[](size_t index)
void AddColumn(const ProfileColumn &c, char olc='X')
ProfileColumnList::const_iterator columns_end() const
ProfileColumn(const ProfileColumn &rhs)
const ProfileColumn & GetNullModel() const
const std::vector< ProfileColumn > & GetColumns() 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
bool operator!=(const ProfileColumn &rhs) const
Defines profile of 20 frequencies for one residue.
Contains a DB of profiles (identified by a unique name (String)).
const Real * freqs_begin() const
const Real * freqs_end() const
friend std::ofstream & operator<<(std::ofstream &os, ProfileHandle &prof)