24 #ifndef OST_SEQ_ALG_DISTANCE_MAP_HH
25 #define OST_SEQ_ALG_DISTANCE_MAP_HH
36 namespace ost {
namespace seq {
namespace alg {
42 template <
typename Pair>
44 typename Pair::first_type operator()(
const typename Pair::first_type& x,
51 template <
typename Pair>
53 bool operator()(
const Pair& x,
const Pair& y)
const {
54 return (x.first < y.first);
70 values_.push_back(std::make_pair(dist,index));
74 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
75 Real sum = std::accumulate(values_.begin(), values_.end(), 0.0,
76 sum_first<FloatArray::value_type>());
77 return sum/values_.size();
81 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
82 return *std::min_element(values_.begin(), values_.end(),
83 CompareFirst<FloatArray::value_type>());
87 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
88 return *std::max_element(values_.begin(), values_.end(),
89 CompareFirst<FloatArray::value_type>());
93 if (values_.size() != 0) {
94 if (values_.size() > index) {
95 return values_[index];
97 std::stringstream error_message;
98 error_message <<
"size of distances data vector: " << values_.size()
99 <<
" is smaller than requested: " << index+1;
108 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
109 const Real avg = this->GetAverage();
110 return this->do_get_stddev(avg);
114 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
115 const Real avg = this->GetAverage();
116 const Real weight = std::exp(avg/(-2*sigma));
117 return this->do_get_stddev(avg) * weight;
121 if (values_.empty())
throw IntegrityError(
"List of distances empty!");
122 const Real avg = this->GetAverage();
123 return this->do_get_stddev(avg) / avg;
131 Real do_get_stddev(
Real avg)
const {
133 for (FloatArray::const_iterator i = values_.begin(),
134 e = values_.end(); i != e; ++i) {
135 const Real diff = i->first - avg;
138 return std::sqrt(var/values_.size());
153 : dist_(nresidues), num_structures_(num_structures) { }
156 dist_(i ,j).Add(distance,index);
169 uint num_structures_;
std::pair< Real, int > GetMax() const
boost::shared_ptr< DistanceMap > DistanceMapPtr
Real GetWeightedStdDev(Real sigma) const
#define DLLEXPORT_OST_SEQ_ALG
void AddDistance(uint i, uint j, Real distance, int index)
const Distances & GetDistances(uint i, uint j) const
DistanceMapPtr DLLEXPORT_OST_SEQ_ALG CreateDistanceMap(const seq::AlignmentHandle &alignment)
create distance map from a multiple sequence alignment.
bool operator==(const Distances &rhs) const
std::pair< Real, int > GetDataElement(uint index) const
Real GetNormStdDev() const
std::vector< std::pair< Real, int > > FloatArray
triangular matrix template
bool operator!=(const Distances &rhs) const
void Add(Real dist, int index)
std::pair< Real, int > GetMin() const
uint GetNumStructures() const
representation of a multiple sequence alignemnt consisting of two or more sequences ...
Container for a pair wise distance for each structure. Each structure is identified by its index in t...
DistanceMap(uint nresidues, uint num_structures)