similarityMatrix.h 2.32 KB
Newer Older
Mikaël Salson's avatar
Mikaël Salson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#ifndef SIMILARITY_MATRIX_H
#define SIMILARITY_MATRIX_H

#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

#define LIMIT_DISPLAY 15

class SimilarityMatrix {
 private:
  int n;                        /* Number of sequences */
  vector<string> labels;        /* Label of each sequence */
  vector<string> descriptions;  /* Description of each sequence */
  float **scores;               /* Array of scores */
  float minV, maxV;

 public:
  SimilarityMatrix(int n);
  ~SimilarityMatrix();

  // Queries
  
  /**
   * @return description of i-th sequence
   */
  string description(int i) const;

  /**
   * @return label of i-th sequence
   */
  string label(int i) const;

  /**
   * @return maximal score
   */ 
  float max() const;

  /**
   * @return minimal score
   */
  float min() const;

  /**
   * @return the number of sequences considered
   */
  int size() const;

  /**
   * @return percentage of similarity between sequence i and j.
   *         Indexes start at 0
   */
  float operator()(int i, int j) const;

  // Commands
  /**
   *@post description(i) == description
   */ 
  void setDescription(int i, string description);

  /**
   * @post label(i) == label
   */
  void setLabel(int i, string label);

  /**
   * @post *this(i, j) == score
   */
  void setScore(int i, int j, float score);

};

class OutputSimilarityMatrix {
 public:
  SimilarityMatrix &matrix;
 private:
  float sim;
Mikaël Salson's avatar
Mikaël Salson committed
80
  int max_display;
Mikaël Salson's avatar
Mikaël Salson committed
81 82

 public:
Mikaël Salson's avatar
Mikaël Salson committed
83 84 85 86 87 88
  /**
   * @param m: the matrix to be displayed
   * @param sim: the level of similarity above which we display the values in a secial way
   * @param max_display: the maximal number of rows or cols to display
   */
  OutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
Mikaël Salson's avatar
Mikaël Salson committed
89 90

  float similarity() const;
Mikaël Salson's avatar
Mikaël Salson committed
91 92

  int maxDisplayed() const;
Mikaël Salson's avatar
Mikaël Salson committed
93 94 95 96
};

class RawOutputSimilarityMatrix: public OutputSimilarityMatrix {
 public:
Mikaël Salson's avatar
Mikaël Salson committed
97
  RawOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
Mikaël Salson's avatar
Mikaël Salson committed
98 99 100 101
}; 

class HTMLOutputSimilarityMatrix: public OutputSimilarityMatrix {
 public:
Mikaël Salson's avatar
Mikaël Salson committed
102
  HTMLOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
Mikaël Salson's avatar
Mikaël Salson committed
103 104 105 106 107 108 109
  
}; 

ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &matrix);
ostream &operator<<(ostream &out, const HTMLOutputSimilarityMatrix &matrix);

#endif