OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2016 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 typedef boost::shared_ptr<VarianceMap> VarianceMapPtr;
40 typedef boost::shared_ptr<Dist2Mean> Dist2MeanPtr;
41 
46 public:
47  // all values initialized to 0 in constructor!
48  VarianceMap(int nresidues): TriMatrix<Real>(nresidues, 0) { }
49 
50  Real Min() {
51  if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
52  std::vector<Real>& data = this->Data();
53  return *std::min_element(data.begin(), data.end());
54  }
55 
56  Real Max() {
57  if (this->GetSize() == 0) throw IntegrityError("Matrix empty");
58  std::vector<Real>& data = this->Data();
59  return *std::max_element(data.begin(), data.end());
60  }
61 
62  void ExportDat(const String& file_name);
63  void ExportCsv(const String& file_name);
64  void ExportJson(const String& file_name);
65  String GetJsonString();
66 };
67 
71 public:
72  // all values initialized to 0 in constructor!
73  Dist2Mean(uint num_residues, uint num_structures)
74  : num_residues_(num_residues), num_structures_(num_structures)
75  , values_(num_residues * num_structures, 0) { }
76 
77  void Set(uint i_res, uint i_str, Real val) {
78  values_[GetIndex(i_res, i_str)] = val;
79  }
80 
81  Real Get(uint i_res, uint i_str) const {
82  return values_[GetIndex(i_res, i_str)];
83  }
84 
85  Real& operator()(uint i_res, uint i_str) {
86  return values_[GetIndex(i_res, i_str)];
87  }
88  Real operator()(uint i_res, uint i_str) const {
89  return values_[GetIndex(i_res, i_str)];
90  }
91 
92  std::vector<Real>& Data() { return values_; }
93 
94  uint GetNumResidues() const { return num_residues_; }
95  uint GetNumStructures() const { return num_structures_; }
96 
97  void Add(uint i_res, uint i_str, Real val) {
98  values_[GetIndex(i_res, i_str)] += val;
99  }
100 
101  void DivideBy(Real val) {
102  for (uint i = 0; i < values_.size(); ++i) values_[i] /= val;
103  }
104 
105  void ExportDat(const String& file_name);
106  void ExportCsv(const String& file_name);
107  void ExportJson(const String& file_name);
108  String GetJsonString();
109 
110 private:
111  uint GetIndex(uint i_res, uint i_str) const {
112  assert(i_res < num_residues_);
113  assert(i_str < num_structures_);
114  return (i_res * num_structures_ + i_str);
115  }
116 
117  uint num_residues_;
118  uint num_structures_;
119  std::vector<Real> values_;
120 };
121 
127 CreateVarianceMap(const DistanceMapPtr dmap, Real sigma=25);
128 
133 CreateDist2Mean(const DistanceMapPtr dmap);
134 
135 }}}
136 
137 #endif
boost::shared_ptr< VarianceMap > VarianceMapPtr
Definition: variance_map.hh:38
Dist2Mean(uint num_residues, uint num_structures)
Definition: variance_map.hh:73
std::vector< Real > & Data()
Definition: variance_map.hh:92
Dist2MeanPtr DLLEXPORT_OST_SEQ_ALG CreateDist2Mean(const DistanceMapPtr dmap)
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
Container for distances to mean for N structures. Main functionality: Get/Set, ExportXXX.
Definition: variance_map.hh:70
boost::shared_ptr< DistanceMap > DistanceMapPtr
Real Get(uint i_res, uint i_str) const
Definition: variance_map.hh:81
Real operator()(uint i_res, uint i_str) const
Definition: variance_map.hh:88
uint GetNumStructures() const
Definition: variance_map.hh:95
#define DLLEXPORT_OST_SEQ_ALG
triangular matrix template
Definition: tri_matrix.hh:13
void Set(uint i_res, uint i_str, Real val)
Definition: variance_map.hh:77
uint GetNumResidues() const
Definition: variance_map.hh:94
boost::shared_ptr< Dist2Mean > Dist2MeanPtr
Definition: variance_map.hh:40
void Add(uint i_res, uint i_str, Real val)
Definition: variance_map.hh:97
VarianceMapPtr DLLEXPORT_OST_SEQ_ALG CreateVarianceMap(const DistanceMapPtr dmap, Real sigma=25)
Container for variances for each entry in a distance map. Main functionality: Get/Set, Min, Max, ExportXXX Get/Set and GetSize taken from TriMatrix.
Definition: variance_map.hh:45
VarianceMap(int nresidues)
Definition: variance_map.hh:48
unsigned int uint
Definition: base.hh:29
Real & operator()(uint i_res, uint i_str)
Definition: variance_map.hh:85