| 1 | // -*- Mode: C++; tab-width: 2; -*- |
| 2 | // vi: set ts=2: |
| 3 | // |
| 4 | // $Id: dockResult.h,v 1.2.16.2 2007/08/07 16:16:15 bertsch Exp $ |
| 5 | // |
| 6 | |
| 7 | #ifndef BALL_DOCKING_COMMON_DOCKRESULT_H |
| 8 | #define BALL_DOCKING_COMMON_DOCKRESULT_H |
| 9 | |
| 10 | #ifndef BALL_DATATYPE_OPTIONS_H |
| 11 | # include <BALL/DATATYPE/options.h> |
| 12 | #endif |
| 13 | |
| 14 | #ifndef BALL_DOCKING_COMMON_CONFORMATIONSET_H |
| 15 | # include <BALL/DOCKING/COMMON/conformationSet.h> |
| 16 | #endif |
| 17 | |
| 18 | namespace BALL |
| 19 | { |
| 20 | /** Result of a (re)docking calculation. |
| 21 | the used algorithm and its options, |
| 22 | the conformation set which was produced by the algorithm |
| 23 | and the scores, names and options of all scoring functions that were used for the ranking / reranking. |
| 24 | On the one hand it allows to recieve the scores of a certain scoring, |
| 25 | on the other hand it can return scores sorted by another scoring. |
| 26 | This offers a simple way to compare the different scores with each other |
| 27 | \ingroup Docking |
| 28 | */ |
| 29 | class BALL_EXPORT DockResult |
| 30 | { |
| 31 | public: |
| 32 | |
| 33 | /** @name Constructors and Destructors |
| 34 | */ |
| 35 | //@{ |
| 36 | |
| 37 | /** Default Constructor |
| 38 | */ |
| 39 | DockResult() |
| 40 | throw(); |
| 41 | |
| 42 | /** Constructor |
| 43 | */ |
| 44 | DockResult(const String& docking_algorithm, ConformationSet* conformation_set, |
| 45 | const Options& docking_options) |
| 46 | throw(); |
| 47 | |
| 48 | /** Copy constructor |
| 49 | */ |
| 50 | DockResult(const DockResult& dock_res) |
| 51 | throw(); |
| 52 | |
| 53 | /** Destructor |
| 54 | */ |
| 55 | virtual ~DockResult() |
| 56 | throw(); |
| 57 | |
| 58 | //@} |
| 59 | |
| 60 | /** @name Assignment |
| 61 | */ |
| 62 | //@{ |
| 63 | |
| 64 | /** Assignment operator |
| 65 | */ |
| 66 | const DockResult& operator = (const DockResult& dock_res) |
| 67 | throw(); |
| 68 | |
| 69 | //@} |
| 70 | |
| 71 | /** @name Accessors: inspectors and mutators |
| 72 | */ |
| 73 | //@{ |
| 74 | |
| 75 | /** Sets the conformation set. |
| 76 | */ |
| 77 | void setConformationSet(ConformationSet* conformation_set) |
| 78 | throw(); |
| 79 | |
| 80 | /** Get the docking algorithm. |
| 81 | */ |
| 82 | const String& getDockingAlgorithm() const |
| 83 | throw(); |
| 84 | |
| 85 | /** Get the options of the docking algorithm. |
| 86 | */ |
| 87 | const Options& getDockingOptions() const |
| 88 | throw(); |
| 89 | |
| 90 | /** Get the conformation set. |
| 91 | */ |
| 92 | const ConformationSet* getConformationSet() const |
| 93 | throw(); |
| 94 | |
| 95 | /** Get the conformation set. |
| 96 | */ |
| 97 | ConformationSet* getConformationSet() |
| 98 | throw(); |
| 99 | |
| 100 | /** Sets scoring flag by which all scores are sorted displayed |
| 101 | a negative index corresponds to sorting by snapshot index |
| 102 | @throws BALL::Exception::IndexOverflow |
| 103 | */ |
| 104 | void sortBy(Index scoring_index); |
| 105 | |
| 106 | /* Get the number of the scoring by which all scores are sorted displayed |
| 107 | */ |
| 108 | Index isSortedBy() const |
| 109 | throw(); |
| 110 | |
| 111 | /** Returns score i of the scoring j in respect of the current sorting |
| 112 | * indicated by the flag \link DockResult::sorted_by_ sorted_by_ \endlink. |
| 113 | * @throws BALL::Exception::IndexOverflow |
| 114 | */ |
| 115 | float operator()(Position i, Position j); |
| 116 | |
| 117 | /** Returns the scores of \link DockResult::Scoring_ scoring \endlink i. |
| 118 | @throws BALL::Exception::IndexOverflow |
| 119 | */ |
| 120 | const vector < ConformationSet::Conformation > getScores(Position i) const; |
| 121 | |
| 122 | /** Returns the name of scoring function of \link DockResult::Scoring_ scoring \endlink i. |
| 123 | @throws BALL::Exception::IndexOverflow |
| 124 | */ |
| 125 | const String& getScoringName(Position i) const; |
| 126 | |
| 127 | /** Returns the scoring function options of \link DockResult::Scoring_ scoring \endlink i. |
| 128 | @throws BALL::Exception::IndexOverflow |
| 129 | */ |
| 130 | const Options& getScoringOptions(Position i) const; |
| 131 | |
| 132 | /** Returns the number of scorings. |
| 133 | */ |
| 134 | Size numberOfScorings() const |
| 135 | throw(); |
| 136 | |
| 137 | /** Add a new Scoring_ to vector \link DockResult::scorings_ scorings_ \endlink. |
| 138 | * @param name name of the scoring function |
| 139 | * @param options options of the scoring function |
| 140 | * @param scores scores calculated by the scoring function |
| 141 | */ |
| 142 | void addScoring(const String& name, const Options& options, vector < ConformationSet::Conformation > scores) |
| 143 | throw(); |
| 144 | |
| 145 | /** Deletes Scoring_ i of vector \link DockResult::scorings_ scorings_ \endlink. |
| 146 | @throws BALL::Exception::IndexOverflow |
| 147 | */ |
| 148 | void deleteScoring(Position i); |
| 149 | |
| 150 | //@} |
| 151 | |
| 152 | /** @name Reading and writing |
| 153 | */ |
| 154 | //@{ |
| 155 | |
| 156 | /** Stores dock result in a file. |
| 157 | * Calls \link DockResult::writeDockResult writeDockResult(std::ostream& file) \endlink. |
| 158 | * @param filename name of the file |
| 159 | * @return true if writing was successful. |
| 160 | * @return false otherwise |
| 161 | */ |
| 162 | bool writeDockResult(const String& filename) |
| 163 | throw(); |
| 164 | |
| 165 | /** Stores dock result in an ostream. |
| 166 | * @param file ostream |
| 167 | * @return true if writing was successful. |
| 168 | * @return false otherwise |
| 169 | */ |
| 170 | bool writeDockResult(std::ostream& file) const |
| 171 | throw(); |
| 172 | |
| 173 | /** Reads dock result from a file. |
| 174 | * Calls \link DockResult::readDockResult readDockResult(std::istream& file) \endlink. |
| 175 | * @param filename name of the file |
| 176 | * @return true if reading was successful. |
| 177 | * @return false otherwise |
| 178 | */ |
| 179 | bool readDockResult(const String& filename) |
| 180 | throw(); |
| 181 | |
| 182 | /** Read dock result from an istream. |
| 183 | * @param file istream |
| 184 | * @return true if reading was successful. |
| 185 | * @return false otherwise |
| 186 | */ |
| 187 | bool readDockResult(std::istream& file) |
| 188 | throw(); |
| 189 | |
| 190 | /** Operator to write dock result into an ostream. |
| 191 | * Calls \link DockResult::writeDockResult writeDockResult(std::ostream& file)\endlink. |
| 192 | */ |
| 193 | friend std::ostream& operator <<(std::ostream& out, const DockResult& dock_res) |
| 194 | throw(); |
| 195 | |
| 196 | /** Operator to read dock result into an istream. |
| 197 | * Calls \link DockResult::readDockResult readDockResult(std::istream& file) \endlink. |
| 198 | */ |
| 199 | friend std::istream& operator >>(std::istream& in, DockResult& dock_res) |
| 200 | throw(); |
| 201 | |
| 202 | //@} |
| 203 | |
| 204 | protected: |
| 205 | |
| 206 | /** Nested class in DockResult. |
| 207 | * This class contains information about the scoring: |
| 208 | * name of the scoring function, |
| 209 | * options of the function and |
| 210 | * scores |
| 211 | */ |
| 212 | class Scoring_ |
| 213 | { |
| 214 | public: |
| 215 | |
| 216 | /** Default Constructor |
| 217 | */ |
| 218 | Scoring_() throw(); |
| 219 | |
| 220 | /** Copy constructor |
| 221 | */ |
| 222 | Scoring_(const Scoring_& scoring) |
| 223 | throw(); |
| 224 | |
| 225 | /** Constructor |
| 226 | */ |
| 227 | Scoring_(const String& name, const Options& options, const vector<float>& scores, const vector<Index>& snapshot_order) throw(); |
| 228 | |
| 229 | /** Destructor |
| 230 | */ |
| 231 | ~Scoring_() throw(); |
| 232 | |
| 233 | /** Assignment operator |
| 234 | */ |
| 235 | const Scoring_& operator = (const Scoring_& scoring) |
| 236 | throw(); |
| 237 | |
| 238 | /** Name of scoring function |
| 239 | */ |
| 240 | String name_; |
| 241 | /** options of scoring function |
| 242 | */ |
| 243 | Options options_; |
| 244 | /** Vector of scores |
| 245 | * The score at position i belongs to the snapshot i |
| 246 | */ |
| 247 | vector<float> scores_; |
| 248 | /** Vector of snapshot indices |
| 249 | * The indices are sorted by their scores |
| 250 | */ |
| 251 | vector<Index> snapshot_order_; |
| 252 | }; |
| 253 | |
| 254 | /** |
| 255 | * Nested class in DockResult. |
| 256 | * This class is needed for the sorting of the vector of Conformations |
| 257 | * in \link DockResult::addScoring addScoring(const String& name, const Options& options, const vector < ConformationSet::Conformation > & scores)\endlink. |
| 258 | * The vector should be sorted by the score values. |
| 259 | */ |
| 260 | class Compare_ |
| 261 | { |
| 262 | public: |
| 263 | |
| 264 | /** Default constructor |
| 265 | */ |
| 266 | Compare_() throw(); |
| 267 | |
| 268 | /** Destructor |
| 269 | */ |
| 270 | ~Compare_() throw(); |
| 271 | |
| 272 | /** Operator () |
| 273 | */ |
| 274 | //bool operator() (const std::pair<Index, float>& a, const std::pair<Index, float>& b) const |
| 275 | bool operator() (const ConformationSet::Conformation& a, const ConformationSet::Conformation& b) const |
| 276 | throw(); |
| 277 | }; |
| 278 | |
| 279 | /** Name of docking algorithm |
| 280 | */ |
| 281 | String docking_algorithm_; |
| 282 | /** Options of the docking algorithm |
| 283 | */ |
| 284 | Options docking_options_; |
| 285 | /** Conformation set which was produced by the docking algorithm. |
| 286 | */ |
| 287 | ConformationSet* conformation_set_; |
| 288 | /** Vector contains name, options and scores of each scoring function. |
| 289 | * The scores of each scoring are sorted. |
| 290 | */ |
| 291 | vector<Scoring_> scorings_; |
| 292 | /** Flag that indicated by which scoring all scorings are sorted |
| 293 | -1 corresponds to a sorting by snapshot index |
| 294 | It is needed for the operator(i, j) |
| 295 | */ |
| 296 | Index sorted_by_; |
| 297 | }; |
| 298 | |
| 299 | std::ostream& operator <<(std::ostream& out, const DockResult& dock_res) |
| 300 | throw(); |
| 301 | |
| 302 | std::istream& operator >>(std::istream& in, DockResult& dock_res) |
| 303 | throw(); |
| 304 | } |
| 305 | #endif |