similarityMatrix.h 2.95 KB
Newer Older
Mikaël Salson's avatar
Mikaël Salson committed
1 2 3 4 5 6 7
#ifndef SIMILARITY_MATRIX_H
#define SIMILARITY_MATRIX_H

#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
8
#include "json.h"
9
#include "../lib/json_fwd.hpp"
10

Mikaël Salson's avatar
Mikaël Salson committed
11
using namespace std;
12
using json = nlohmann::json;
Mikaël Salson's avatar
Mikaël Salson committed
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 80 81 82 83

#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
84
  int max_display;
Mikaël Salson's avatar
Mikaël Salson committed
85 86

 public:
Mikaël Salson's avatar
Mikaël Salson committed
87 88 89 90 91 92
  /**
   * @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
93 94

  float similarity() const;
Mikaël Salson's avatar
Mikaël Salson committed
95 96

  int maxDisplayed() const;
Mikaël Salson's avatar
Mikaël Salson committed
97 98 99 100
};

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

class HTMLOutputSimilarityMatrix: public OutputSimilarityMatrix {
 public:
Mikaël Salson's avatar
Mikaël Salson committed
106
  HTMLOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
107 108 109 110 111 112 113 114 115 116 117 118 119 120

};

/*Class to export a similarity matrix*/
class JsonOutputSimilarityMatrix: public OutputSimilarityMatrix {
 public:
  JsonOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
};

/*Class to export a windows matrix*/
class JsonOutputWindowsMatrix: public OutputSimilarityMatrix {
 public:
  JsonOutputWindowsMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
};
Mikaël Salson's avatar
Mikaël Salson committed
121 122 123

ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &matrix);
ostream &operator<<(ostream &out, const HTMLOutputSimilarityMatrix &matrix);
124
json &operator<<(json &out, const JsonOutputSimilarityMatrix &matrix);
125
json &operator<<(json &out, const JsonOutputWindowsMatrix &matrix);
Mikaël Salson's avatar
Mikaël Salson committed
126 127

#endif