Commit ad077747 authored by Sebastien Carrere's avatar Sebastien Carrere

Travail sur histogrammes

Fix #93
Fix #98
Fix #99
parent ae36a16e
......@@ -112,6 +112,8 @@ sub __BuildClassCountJS
my $fh_out_xls = &GetStreamOut("$outdir/statistics_matrices/xls_files/$prefix.classes.count.xls");
print $fh_out_xls "##$prefix\n";
print $fh_out_xls "#Class\tcount\n";
my $rh_data = {'title' => $prefix, 'data' => [], 'path' => "xls_files/$prefix.xls", 'xaxis' => $xaxis, 'yaxis' => $yaxis};
......@@ -122,7 +124,7 @@ sub __BuildClassCountJS
foreach my $class (sort {$a <=> $b} keys %{$rh_classes})
{
print $fh_out_xls "$class\t" . "$class" . "\t" . $rh_classes->{$class} . "\n";
print $fh_out_xls "$class\t" . $rh_classes->{$class} . "\n";
}
$fh_out_xls->close;
......@@ -130,7 +132,7 @@ sub __BuildClassCountJS
push (@a_files, "xls_files/$prefix.classes.count.xls");
push (@a_titles, "$prefix");
push (@a_yaxis, $yaxis);
push (@a_startcolumn, 2);
push (@a_startcolumn, 1);
my $root_url = __GetLocalUrl();
......@@ -285,8 +287,8 @@ sub PrintDescriptiveStatisticsFiles
my $fh_stat = &GetStreamOut("$outdir/statistics_matrices/xls_files/$prefix.xls");
my %h_classes = ();
print $fh_stat join(" => ", '#Number of homology group', $ngroup) . "\n";
print $fh_stat join(" => ", '#Number of Proteome', $nproteome) . "\n\n";
print $fh_stat join("\t", '##Number of homology group', $ngroup) . "\n";
print $fh_stat join("\t", '##Number of Proteome', $nproteome) . "\n\n";
print $fh_stat join("\t", '#GROUP', 'Number') . "\n";
foreach my $k (sort __sort_by_by_group_number keys %{$rh_data})
{
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
......@@ -7,19 +6,48 @@
<script src="%ROOT_URL%/web/js/ext/highchart/highcharts.js"></script>
<script src="%ROOT_URL%/web/js/ext/highchart/exporting.js"></script>
<script src="%ROOT_URL%/web/js/ext/highchart/offline-exporting.js"></script>
<style type="text/css">
form { position: relative; }
input[type="range"] {
position: relative;
margin-left: 1em;
}
input[type="range"]:after, input[type="range"]:before {
position: absolute;
top: 1em;
color: #aaa;
}
input[type="range"]:before {
left:0em;
content: attr(min);
}
input[type="range"]:after {
right: 0em;
content: attr(max);
}
output {
position: absolute;
top: 35px; left: 70px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
function BuildHistogram() {
var RA_FILES = ['%FILE_LIST%'];
var RA_TITLES = ['%TITLE_LIST%'];
var RA_YAXIS = ['%YAXIS_LIST%'];
var RA_STARTCOLUMNS = [%STARTCOLUMN_LIST%];
var step = $('#step').val();
$('#stepValue').text(step);
$.each (RA_FILES, function (i, file) {
$('#container').append('<div id="hist'+i+'"></div><hr>');
$('#container').append('<div id="hist'+i+'"></div>');
var options = {
chart: {
chart: {
renderTo: 'hist'+i,
type: 'column',
zoomType: 'xy',
......@@ -30,10 +58,17 @@
text: RA_TITLES[i]
},
subtitle: {
text: '<a href="'+RA_FILES[i]+'">Rawdata file</a>',
text: 'Step : ' + step + '<br><a href="'+RA_FILES[i]+'">Rawdata file</a>',
useHTML: true
},
tooltip: {enabled:false},
tooltip: {
enabled:true,
formatter: function() {
var lowerBound = this.x - step;
var s = this.series.name + ' [ ' + lowerBound + '-' +this.x + '] : ' + this.y;
return s;
}
},
xAxis: {
categories: [],
type: 'category',
......@@ -84,32 +119,28 @@
dataType: 'Text'
}, function(data) {
console.log(data);
var lines = data.split('\n');
var series = {name:"distribution"};
var a_raw_data = [];
$.each(lines, function(lineNo, line) {
var items = line.split('\t');
var itemFactor = items[2];
var value = items[1];
// We rebuild the initial count
for(var i=0;i<itemFactor;i++)
{
a_raw_data.push(parseFloat(value));
}
if (! line.startsWith("#"))
{
var items = line.split('\t');
var value = items[0];
var itemFactor = items[1];
// We rebuild the initial count
for(var i=0;i<itemFactor;i++)
{
a_raw_data.push([parseFloat(value), itemFactor]);
}
}
});
series.data=binData(a_raw_data);
series.data=histogram(a_raw_data, step);
options.series.push(series);
var chart = new Highcharts.Chart(options);
......@@ -117,63 +148,53 @@
});
});
});
function binData(data) {
var hData = new Array(), //the output array
size = data.length, //how many data points
bins = Math.round(Math.sqrt(size)); //determine how many bins we need
bins = bins > 50 ? 50 : bins; //adjust if more than 50 cells
var max = Math.max.apply(null, data), //lowest data value
min = Math.min.apply(null, data), //highest data value
range = max - min, //total range of the data
width = range / bins, //size of the bins
bin_bottom, //place holders for the bounds of each bin
bin_top;
console.log("size", size, "bins", bins);
//loop through the number of cells
for (var i = 0; i < bins; i++) {
}
//set the upper and lower limits of the current cell
bin_bottom = min + (i * width);
bin_top = bin_bottom + width;
function histogram(data, step) {
var histo = {},
x,
i,
arr = [];
//check for and set the x value of the bin
if (!hData[i]) {
hData[i] = new Array();
hData[i][0] = bin_bottom + (width / 2);
}
// Group down
for (i = 0; i < data.length; i++) {
x = Math.floor(data[i][0] / step) * step;
if (!histo[x]) {
histo[x] = 0;
}
histo[x]++;
}
//loop through the data to see if it fits in this bin
for (var j = 0; j < size; j++) {
var x = data[j];
// Make the histo group into an array
for (x in histo) {
if (histo.hasOwnProperty((x))) {
arr.push([parseFloat(x), histo[x]]);
}
}
//adjust if it's the first pass
i == 0 && j == 0 ? bin_bottom -= 1 : bin_bottom = bin_bottom;
// Finally, sort the array
arr.sort(function (a, b) {
return a[0] - b[0];
});
//if it fits in the bin, add it
if (x > bin_bottom && x <= bin_top) {
!hData[i][1] ? hData[i][1] = 1 : hData[i][1]++;
}
}
}
$.each(hData, function(i, point) {
if (typeof point[1] == 'undefined') {
hData[i][1] = 0;
}
});
return hData;
}
return arr;
}
</script>
</head>
<body>
<body onLoad="javascript:BuildHistogram();">
<div>
<label for="step">Step <span id="stepValue"></span></label><br/>
<input type="range" min="1" max="100" id="step" name="step" value="2" onchange="javascript:BuildHistogram();"</input>
</div>
<hr>
<div id="container"></div>
</body>
</html>
</body>
</html>
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