Commit 2153f604 authored by WebTogz's avatar WebTogz

core/similarityMatrix.cpp: exports matrices to .json

parent dfb62461
......@@ -19,6 +19,7 @@
#include "compare-all.h"
#include "tools.h"
#include "json.h"
SimilarityMatrix compare_all(list <Sequence> sequences, bool min_size,
list <string> sequence_names)
......
......@@ -6,9 +6,15 @@
#include "dynprog.h"
#include "fasta.h"
#include "similarityMatrix.h"
#include "windows.h"
SimilarityMatrix compare_all(list <Sequence> sequences, bool min_size,
list <string> sequence_names=list<string>());
// bool compare_all(list <Sequence> sequences, bool min_size=false, std::ostream out=std::cout);
/*Object to compare windows to build a distances matrix between windows
@param windowsStorage: The object which contains windows
@param theCost: The cost to add for the dynamic programming
@param nb_clones: The number of clones to take on board to build the matrix*/
SimilarityMatrix compare_windows(WindowsStorage &windowsStorage, const Cost theCost, int nb_clones);
// bool compare_all(list <Sequence> sequences, bool min_size=false, std::ostream out=std::cout);
......@@ -20,6 +20,7 @@
#include "similarityMatrix.h"
#include <cassert>
#include <limits>
#include <math.h>
SimilarityMatrix::SimilarityMatrix(int n):n(n),labels(n),descriptions(n) {
assert(n >= 0);
......@@ -106,7 +107,9 @@ int OutputSimilarityMatrix::maxDisplayed() const {
RawOutputSimilarityMatrix::RawOutputSimilarityMatrix(SimilarityMatrix &m, float sim, int max_display) : OutputSimilarityMatrix(m, sim, max_display) {}
JsonOutputSimilarityMatrix::JsonOutputSimilarityMatrix(SimilarityMatrix &m, float sim, int max_display) : OutputSimilarityMatrix(m, sim, max_display) {}
JsonOutputWindowsMatrix::JsonOutputWindowsMatrix(SimilarityMatrix &m, float sim, int max_display) : OutputSimilarityMatrix(m, sim, max_display) {}
ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &outputMatrix) {
SimilarityMatrix &matrix = outputMatrix.matrix;
......@@ -156,3 +159,44 @@ ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &outputMatrix)
return out;
}
/*Export a similarity matrix, for the edit distance distribution & DBSCAN algorithm
*/
JsonArray &operator<<(JsonArray &out, const JsonOutputSimilarityMatrix &outputMatrix) {
SimilarityMatrix &matrix = outputMatrix.matrix;
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix.size(); j++) {
if (i < j) {
//Creation of an edges objects array, which contains a source objet, a target object, and the length of the distance between them
JsonList lineEdge;
lineEdge.add("source", i);
lineEdge.add("target", j);
//100 - similarity -> distance
lineEdge.add("len", (100 - matrix(i,j)));
out.add(lineEdge);
}
}
}
return out;
}
/* Export Levenshtein distances matrix, for the edit distance distribution & DBSCAN algorithm
*/
JsonArray &operator<<(JsonArray &out, const JsonOutputWindowsMatrix &outputMatrix) {
SimilarityMatrix &matrix = outputMatrix.matrix;
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix.size(); j++) {
if (i < j) {
//Creation of an edges objects array, which contains a source objet, a target object, and the length of the distance between them
JsonList lineEdge;
lineEdge.add("source", i);
lineEdge.add("target", j);
//absolute value of the score -> distance
lineEdge.add("len", fabs(matrix(i,j)));
out.add(lineEdge);
}
}
}
return out;
}
......@@ -5,6 +5,8 @@
#include <string>
#include <iostream>
#include <iomanip>
#include "json.h"
using namespace std;
#define LIMIT_DISPLAY 15
......@@ -95,15 +97,29 @@ class OutputSimilarityMatrix {
class RawOutputSimilarityMatrix: public OutputSimilarityMatrix {
public:
RawOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
};
};
class HTMLOutputSimilarityMatrix: public OutputSimilarityMatrix {
public:
HTMLOutputSimilarityMatrix(SimilarityMatrix &m, float sim=100., int max_display = LIMIT_DISPLAY);
};
};
/*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);
};
ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &matrix);
ostream &operator<<(ostream &out, const HTMLOutputSimilarityMatrix &matrix);
JsonArray &operator<<(JsonArray &out, const JsonOutputSimilarityMatrix &matrix);
JsonArray &operator<<(JsonArray &out, const JsonOutputWindowsMatrix &matrix);
#endif
......@@ -91,12 +91,15 @@ pair <int, int> WindowsStorage::keepInterestingWindows(size_t min_reads_window)
it++;
}
}
sort_all_windows.clear();
return make_pair(removes, nb_reads);
}
void WindowsStorage::sort() {
for (map <junction, list<Sequence> >::const_iterator it = seqs_by_window.begin();
it != seqs_by_window.end(); ++it)
sort_all_windows.clear();
for (map <junction, list<Sequence> >::const_iterator it = seqs_by_window.begin();
it != seqs_by_window.end(); ++it)
{
sort_all_windows.push_back(make_pair(it->first, it->second.size()));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment