OpenStructure
variance_map.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 /*
21  Author: Gerardo Tauriello, Juergen Haas
22  */
23 
24 #ifndef OST_SEQ_ALG_VARIANCE_MAP_HH
25 #define OST_SEQ_ALG_VARIANCE_MAP_HH
26 
27 #include <algorithm>
28 
30 #include <ost/tri_matrix.hh>
31 #include <ost/integrity_error.hh>
34 
35 namespace ost { namespace seq { namespace alg {
36 
37 class VarianceMap;
38 class Dist2Mean;
39 class MeanlDDT;
40 typedef boost::shared_ptr<VarianceMap> VarianceMapPtr;
41 typedef boost::shared_ptr<Dist2Mean> Dist2MeanPtr;
42 typedef boost::shared_ptr<MeanlDDT> MeanlDDTPtr;
43 
48 public:
49  // all values initialized to 0 in constructor!
50  VarianceMap(int nresidues): TriMatrix<Real>(nresidues, 0) { }
51 
52  Real Min() {
53  if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
54  std::vector<Real>& data = this->Data();
55  return *std::min_element(data.begin(), data.end());
56  }
57 
58  Real Max() {
59  if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
60  std::vector<Real>& data = this->Data();
61  return *std::max_element(data.begin(), data.end());
62  }
63 
64  void ExportDat(const String& file_name);
65  void ExportCsv(const String& file_name);
66  void ExportJson(const String& file_name);
68 };
69 
73 public:
74  // all values initialized to 0 in constructor!
75  Dist2Mean(uint num_residues, uint num_structures)
76  : num_residues_(num_residues), num_structures_(num_structures)
77  , values_(num_residues * num_structures, 0) { }
78 
79  void Set(uint i_res, uint i_str, Real val) {
80  values_[GetIndex(i_res, i_str)] = val;
81  }
82 
83  Real Get(uint i_res, uint i_str) const {
84  return values_[GetIndex(i_res, i_str)];
85  }
86 
87  Real& operator()(uint i_res, uint i_str) {
88  return values_[GetIndex(i_res, i_str)];
89  }
90  Real operator()(uint i_res, uint i_str) const {
91  return values_[GetIndex(i_res, i_str)];
92  }
93 
94  std::vector<Real>& Data() { return values_; }
95 
96  uint GetNumResidues() const { return num_residues_; }
97  uint GetNumStructures() const { return num_structures_; }
98 
99  void Add(uint i_res, uint i_str, Real val) {
100  values_[GetIndex(i_res, i_str)] += val;
101  }
102 
103  void DivideBy(Real val) {
104  for (uint i = 0; i < values_.size(); ++i) values_[i] /= val;
105  }
106 
107  void ExportDat(const String& file_name);
108  void ExportCsv(const String& file_name);
109  void ExportJson(const String& file_name);
111 
112 private:
113  uint GetIndex(uint i_res, uint i_str) const {
114  assert(i_res < num_residues_);
115  assert(i_str < num_structures_);
116  return (i_res * num_structures_ + i_str);
117  }
118 
119  uint num_residues_;
120  uint num_structures_;
121  std::vector<Real> values_;
122 };
123 
124 
126 public:
127  // all values initialized to 0 in constructor!
128  MeanlDDT(uint num_residues, uint num_structures)
129  : num_residues_(num_residues), num_structures_(num_structures)
130  , values_(num_residues * num_structures, 0) { }
131 
132  void Set(uint i_res, uint i_str, Real val) {
133  values_[GetIndex(i_res, i_str)] = val;
134  }
135 
136  Real Get(uint i_res, uint i_str) const {
137  return values_[GetIndex(i_res, i_str)];
138  }
139 
140  Real& operator()(uint i_res, uint i_str) {
141  return values_[GetIndex(i_res, i_str)];
142  }
143  Real operator()(uint i_res, uint i_str) const {
144  return values_[GetIndex(i_res, i_str)];
145  }
146 
147  std::vector<Real>& Data() { return values_; }
148 
149  uint GetNumResidues() const { return num_residues_; }
150  uint GetNumStructures() const { return num_structures_; }
151 
152  void ExportDat(const String& file_name);
153  void ExportCsv(const String& file_name);
154  void ExportJson(const String& file_name);
156 
157 private:
158  uint GetIndex(uint i_res, uint i_str) const {
159  assert(i_res < num_residues_);
160  assert(i_str < num_structures_);
161  return (i_res * num_structures_ + i_str);
162  }
163 
164  uint num_residues_;
165  uint num_structures_;
166  std::vector<Real> values_;
167 };
168 
174 CreateVarianceMap(const DistanceMapPtr dmap, Real sigma=25);
175 
181 
184 
185 }}}
186 
187 #endif
triangular matrix template
Definition: tri_matrix.hh:13
Container for distances to mean for N structures. Main functionality: Get/Set, ExportXXX.
Definition: variance_map.hh:72
std::vector< Real > & Data()
Definition: variance_map.hh:94
uint GetNumStructures() const
Definition: variance_map.hh:97
void ExportCsv(const String &file_name)
Real operator()(uint i_res, uint i_str) const
Definition: variance_map.hh:90
Real & operator()(uint i_res, uint i_str)
Definition: variance_map.hh:87
void Set(uint i_res, uint i_str, Real val)
Definition: variance_map.hh:79
void ExportJson(const String &file_name)
void Add(uint i_res, uint i_str, Real val)
Definition: variance_map.hh:99
uint GetNumResidues() const
Definition: variance_map.hh:96
Real Get(uint i_res, uint i_str) const
Definition: variance_map.hh:83
void ExportDat(const String &file_name)
Dist2Mean(uint num_residues, uint num_structures)
Definition: variance_map.hh:75
std::vector< Real > & Data()
uint GetNumStructures() const
void ExportCsv(const String &file_name)
Real operator()(uint i_res, uint i_str) const
Real & operator()(uint i_res, uint i_str)
void Set(uint i_res, uint i_str, Real val)
void ExportJson(const String &file_name)
uint GetNumResidues() const
MeanlDDT(uint num_residues, uint num_structures)
Real Get(uint i_res, uint i_str) const
void ExportDat(const String &file_name)
Container for variances for each entry in a distance map. Main functionality: Get/Set,...
Definition: variance_map.hh:47
void ExportCsv(const String &file_name)
void ExportJson(const String &file_name)
void ExportDat(const String &file_name)
VarianceMap(int nresidues)
Definition: variance_map.hh:50
unsigned int uint
Definition: base.hh:29
float Real
Definition: base.hh:44
std::string String
Definition: base.hh:54
boost::shared_ptr< VarianceMap > VarianceMapPtr
Definition: variance_map.hh:39
Dist2MeanPtr DLLEXPORT_OST_SEQ_ALG CreateDist2Mean(const DistanceMapPtr dmap)
boost::shared_ptr< DistanceMap > DistanceMapPtr
boost::shared_ptr< MeanlDDT > MeanlDDTPtr
Definition: variance_map.hh:42
VarianceMapPtr DLLEXPORT_OST_SEQ_ALG CreateVarianceMap(const DistanceMapPtr dmap, Real sigma=25)
MeanlDDTPtr DLLEXPORT_OST_SEQ_ALG CreateMeanlDDTHA(const DistanceMapPtr dmap)
boost::shared_ptr< Dist2Mean > Dist2MeanPtr
Definition: variance_map.hh:41
Definition: base.dox:1
#define DLLEXPORT_OST_SEQ_ALG