00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OST_SEQ_ALG_VARIANCE_MAP_HH
00025 #define OST_SEQ_ALG_VARIANCE_MAP_HH
00026
00027 #include <algorithm>
00028
00029 #include <ost/seq/alignment_handle.hh>
00030 #include <ost/tri_matrix.hh>
00031 #include <ost/integrity_error.hh>
00032 #include <ost/seq/alg/module_config.hh>
00033 #include <ost/seq/alg/distance_map.hh>
00034
00035 namespace ost { namespace seq { namespace alg {
00036
00037 class VarianceMap;
00038 class Dist2Mean;
00039 typedef boost::shared_ptr<VarianceMap> VarianceMapPtr;
00040 typedef boost::shared_ptr<Dist2Mean> Dist2MeanPtr;
00041
00045 class DLLEXPORT_OST_SEQ_ALG VarianceMap: public TriMatrix<Real> {
00046 public:
00047
00048 VarianceMap(int nresidues): TriMatrix<Real>(nresidues, 0) { }
00049
00050 Real Min() {
00051 if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
00052 std::vector<Real>& data = this->Data();
00053 return *std::min_element(data.begin(), data.end());
00054 }
00055
00056 Real Max() {
00057 if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
00058 std::vector<Real>& data = this->Data();
00059 return *std::max_element(data.begin(), data.end());
00060 }
00061
00062 void ExportDat(const String& file_name);
00063 void ExportCsv(const String& file_name);
00064 void ExportJson(const String& file_name);
00065 String GetJsonString();
00066 };
00067
00070 class DLLEXPORT_OST_SEQ_ALG Dist2Mean {
00071 public:
00072
00073 Dist2Mean(uint num_residues, uint num_structures)
00074 : num_residues_(num_residues), num_structures_(num_structures)
00075 , values_(num_residues * num_structures, 0) { }
00076
00077 void Set(uint i_res, uint i_str, Real val) {
00078 values_[GetIndex(i_res, i_str)] = val;
00079 }
00080
00081 Real Get(uint i_res, uint i_str) const {
00082 return values_[GetIndex(i_res, i_str)];
00083 }
00084
00085 Real& operator()(uint i_res, uint i_str) {
00086 return values_[GetIndex(i_res, i_str)];
00087 }
00088 Real operator()(uint i_res, uint i_str) const {
00089 return values_[GetIndex(i_res, i_str)];
00090 }
00091
00092 std::vector<Real>& Data() { return values_; }
00093
00094 uint GetNumResidues() const { return num_residues_; }
00095 uint GetNumStructures() const { return num_structures_; }
00096
00097 void Add(uint i_res, uint i_str, Real val) {
00098 values_[GetIndex(i_res, i_str)] += val;
00099 }
00100
00101 void DivideBy(Real val) {
00102 for (uint i = 0; i < values_.size(); ++i) values_[i] /= val;
00103 }
00104
00105 void ExportDat(const String& file_name);
00106 void ExportCsv(const String& file_name);
00107 void ExportJson(const String& file_name);
00108 String GetJsonString();
00109
00110 private:
00111 uint GetIndex(uint i_res, uint i_str) const {
00112 assert(i_res < num_residues_);
00113 assert(i_str < num_structures_);
00114 return (i_res * num_structures_ + i_str);
00115 }
00116
00117 uint num_residues_;
00118 uint num_structures_;
00119 std::vector<Real> values_;
00120 };
00121
00126 VarianceMapPtr DLLEXPORT_OST_SEQ_ALG
00127 CreateVarianceMap(const DistanceMapPtr dmap, Real sigma=25);
00128
00132 Dist2MeanPtr DLLEXPORT_OST_SEQ_ALG
00133 CreateDist2Mean(const DistanceMapPtr dmap);
00134
00135 }}}
00136
00137 #endif