Commit 9ac1b0d5 authored by Marc Duez's avatar Marc Duez

vidjil.cpp/cluster-junction.cpp : output clusters

parent 286b61f3
......@@ -24,7 +24,11 @@
return lh.second>rh.second;
}
comp_matrix::comp_matrix(WindowsStorage &ws):windows(ws){}
comp_matrix::comp_matrix(WindowsStorage &ws):windows(ws)
{
matrix_size = windows.size();
if (matrix_size > JUNCTION_LIMIT) matrix_size = JUNCTION_LIMIT;
}
void comp_matrix::compare(ostream &out, Cost cluster_cost)
{
......@@ -43,15 +47,18 @@ void comp_matrix::compare(ostream &out, Cost cluster_cost)
int c1=0;
int c2=0;
size_t i = 0;
for (mjs::const_iterator it0 = windows.getMap().begin();
it0 != windows.getMap().end(); ++it0 )
(it0 != windows.getMap().end()) & (i<matrix_size); ++it0 )
{
i++;
j1=it0->first;
size_t k = 0;
for (mjs::const_iterator it1 = it0;
it1 != windows.getMap().end(); ++it1 )
(it1 != windows.getMap().end()) & (k<matrix_size); ++it1 )
{
k++;
j2=it1->first;
DynProg dp = DynProg(j1, j2, DynProg::Local, compareCost);
int score=dp.compute();
......@@ -69,7 +76,8 @@ void comp_matrix::compare(ostream &out, Cost cluster_cost)
}
void comp_matrix::load(string file){
m = alloc_matrix(windows.size());
char* tampon=(char*)malloc(windows.size()*sizeof(char));
......@@ -125,27 +133,32 @@ list<list<junction> > comp_matrix::cluster(string forced_edges, int w, ostream
int c1=0;
int c2=0;
size_t i = 0;
for (mjs::const_iterator ite = windows.getMap().begin();
ite != windows.getMap().end(); ++ite )
(ite != windows.getMap().end()) & (i<matrix_size); ++ite )
{
i++;
n_j++;
list <string> voisins ;
j1=ite->first;
neighbor[j1]=voisins;
}
i = 0;
for (mjs::const_iterator it0 = windows.getMap().begin();
it0 != windows.getMap().end(); ++it0 )
(it0 != windows.getMap().end()) & (i<matrix_size); ++it0 )
{
i++;
j1=it0->first;
int k=it0->second.size();
count[j1]=k;
n_j2+=k;
size_t j = 0;
for (mjs::const_iterator it1 = windows.getMap().begin();
it1 != windows.getMap().end(); ++it1 )
(it1 != windows.getMap().end()) & (j<matrix_size); ++it1 )
{
j++;
j2=it1->first;
int distance = (int)m[c2][c1];
......@@ -213,9 +226,11 @@ list<list<junction> > comp_matrix::cluster(string forced_edges, int w, ostream
int noise = 0;
int nb_comp = 0 ;
i = 0;
for (mjs::const_iterator it0 = windows.getMap().begin();
it0 != windows.getMap().end(); ++it0 )
(it0 != windows.getMap().end()) & (i<matrix_size); ++it0 )
{
i++;
j1=it0->first;
if(visit[j1]==false && clust[j1]==false){
......@@ -382,6 +397,27 @@ void comp_matrix::stat_cluster( list<list<junction> > cluster, ostream &out )
}
JsonArray comp_matrix::toJson(list<list<junction> > clusterList)
{
JsonArray result;
for (list <list <string> >::iterator it = clusterList.begin();
it != clusterList.end(); ++it )
{
JsonArray cluster;
list<string> li=*it;
for (list<string>::iterator it2 = li.begin();
it2 != li.end(); ++it2 )
{
cluster.add(*it2);
}
result.add(cluster);
}
return result;
}
char **comp_matrix::alloc_matrix(size_t s) {
char **matrix = (char**)malloc(s*sizeof(char*));
for (size_t i=0;i<s;i++){
......
......@@ -9,10 +9,12 @@
#include <ctime>
#include "dynprog.h"
#include "windows.h"
#include "json.h"
using namespace std ;
#define SIMILAR_JUNCTIONS_THRESHOLD 1
#define JUNCTION_LIMIT 500
class comp_matrix {
......@@ -22,6 +24,7 @@ class comp_matrix {
map <string, int> count;
int n_j;
int n_j2;
size_t matrix_size;
/**
* create new distance matrix
......@@ -65,6 +68,9 @@ class comp_matrix {
void del();
void stat_cluster( list<list<junction> > cluster, ostream &out=cout);
JsonArray toJson( list<list<junction> > cluster);
private:
......
......@@ -909,14 +909,13 @@ int main (int argc, char **argv)
cout << " ! No windows with current parameters." << endl;
}
list <list <junction> > clones_windows;
comp_matrix comp=comp_matrix(*windowsStorage);
if (command == CMD_CLONES) {
//////////////////////////////////
//$$ Clustering
list <list <junction> > clones_windows;
comp_matrix comp=comp_matrix(*windowsStorage);
if (epsilon || forced_edges.size())
{
cout << "Cluster similar windows" << endl ;
......@@ -1278,6 +1277,11 @@ int main (int argc, char **argv)
json->add("reads", *json_reads);
json->add("germline", germline_system);
json->add("clones", jsonSortedWindows);
if (epsilon || forced_edges.size()){
JsonArray json_clusters = comp.toJson(clones_windows);
json->add("clusters", json_clusters );
}
//Added edges in the json output file
//json->add("links", jsonLevenshtein);
......
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