Commit f96e4396 authored by Tatiana Rocher's avatar Tatiana Rocher
Browse files
parents 0f455c24 afd70bc6
......@@ -7,7 +7,7 @@ requirejs.config({
});
require(['../conf'], function () {}, function(err) {});
require(["../view"], function () {}, function(err) {});
require(["jquery",
"d3.v3",
"jquery.form",
......@@ -20,7 +20,6 @@ require(["jquery",
"underscore",
"rgbcolor",
"file",
"../view",
"../compare",
"../menu",
"../dbscan",
......
......@@ -143,65 +143,99 @@ Axis.prototype = {
* @param {boolean} percent - display label as percent ( value 1 => 100%)
* @param {boolean} use_log - use a logarithmic scale instead of a linear
* */
custom: function(fct, default_min, default_max, percent, use_log){
percent = typeof percent !== 'undefined' ? percent : false;
use_log= typeof percent !== 'undefined' ? use_log : false;
custom: function(fct, default_min, default_max, output, use_log){
output = typeof output !== 'undefined' ? output : 'float';
use_log = typeof use_log !== 'undefined' ? use_log : false;
var self = this;
this.fct = fct;
var min = default_min;
var max = default_max;
if (typeof min === 'function') min = min();
if (typeof min === 'function') max = max();
for (var i in this.m.clones){
var tmp;
try{
tmp = fct(i);
}catch(e){}
if ( typeof tmp != "undefined"){
if ( tmp > max || typeof max == "undefined") max = tmp;
if ( tmp < min || typeof min == "undefined") min = tmp;
this.fct = fct;
if (typeof fct == "string"){
this.fct = function(id){
return self.m.clone(id).get(fct)
}
}
if (typeof min == "undefined"){
min = 0;
max = 1;
}
if ( output != "string" ){
var min = default_min;
var max = default_max;
if (typeof min === 'function') min = min();
if (typeof min === 'function') max = max();
var range = [0,1]
if (self.reverse) range = [1,0]
if (use_log){
this.sizeScale = d3.scale.log()
.domain([min, max])
.range(range);
}else{
this.sizeScale = d3.scale.linear()
for (var i in this.m.clones){
var tmp;
try{
tmp = this.fct(i);
}catch(e){}
if ( typeof tmp != "undefined"){
if ( tmp > max || typeof max == "undefined") max = tmp;
if ( tmp < min || typeof min == "undefined") min = tmp;
}
}
if (typeof min == "undefined"){
min = 0;
max = 1;
}
var range = [0,1]
if (self.reverse) range = [1,0]
if (use_log){
this.sizeScale = d3.scale.log()
.domain([min, max])
.range(range);
}
}else{
this.sizeScale = d3.scale.linear()
.domain([min, max])
.range(range);
}
this.min = min;
this.max = max;
this.min = min;
this.max = max;
this.pos = function(cloneID) {
var value, pos;
try{
value = self.fct(cloneID);
}catch(e){}
this.pos = function(cloneID) {
var value, pos;
try{
value = self.fct(cloneID);
}catch(e){}
if (typeof value != "undefined"){
pos = self.sizeScale(value);
}else{
pos = self.sizeScale(self.min);
}
return pos;
}
}else{
this.values = {};
for (var i in this.m.clones){
try{
var tmp = this.fct(i);
console.log(tmp)
if (typeof tmp != 'undefined') this.values[tmp] = 0;
}catch(e){}
}
if (typeof value != "undefined"){
pos = self.sizeScale(value);
}else{
pos = self.sizeScale(self.min);
var key = Object.keys(this.values)
var step = 1/(key.length+1);
pos = step/2;
for (var i in key){
this.values[key[i]] = pos;
pos += step;
}
return pos;
this.values["?"] = pos;
this.pos = function(cloneID) {
result = this.values[this.fct(cloneID)]
if (typeof result == 'undefined') return "?"
return result
}
}
this.computeCustomLabels(min, max, percent, use_log)
this.computeCustomLabels(min, max, output, use_log)
},
/**
......@@ -212,32 +246,39 @@ Axis.prototype = {
* @param {boolean} percent - display label as percent ( value 1 => 100%)
* @param {boolean} use_log - use a logarithmic scale instead of a linear
* */
computeCustomLabels: function(min, max, percent, use_log){
computeCustomLabels: function(min, max, output, use_log){
this.labels = [];
if (use_log){
var h=1
for (var i = 0; i < 10; i++) {
var pos = this.sizeScale(h); // pos is possibly already reversed
var text = this.m.formatSize(h, false)
if (pos >= 0 && pos <= 1)
this.labels.push(this.label("line", pos, text));
h = h / 10;
if (output == "string"){
var key = Object.keys(this.values)
for (var i in key){
this.labels.push(this.label("line", this.values[key[i]], key[i]));
}
}else{
var h = (max-min)/5
var delta = (max-min)
for (var i = 0; i <= 5; i++) {
pos = (h*i)*(1/delta);
var text = Math.round(min+(h*i))
if (percent){
text = ((min+(h*i))*100).toFixed(1) + "%"
if (use_log){
var h=1
for (var i = 0; i < 10; i++) {
var pos = this.sizeScale(h); // pos is possibly already reversed
var text = this.m.formatSize(h, false)
if (pos >= 0 && pos <= 1)
this.labels.push(this.label("line", pos, text));
h = h / 10;
}
}else{
var h = (max-min)/5
var delta = (max-min)
for (var i = 0; i <= 5; i++) {
pos = (h*i)*(1/delta);
var text = Math.round(min+(h*i))
if (output=="percent"){
text = ((min+(h*i))*100).toFixed(1) + "%"
}
if (this.reverse) pos = 1 - pos;
this.labels.push(this.label("line", pos, text));
}
if (this.reverse) pos = 1 - pos;
this.labels.push(this.label("line", pos, text));
}
}
},
......
......@@ -363,15 +363,7 @@ Clone.prototype = {
if ("GgCc".indexOf(this.sequence[i]) > -1)
gc++ }
this.GCContent = 100 * gc / this.sequence.length
},
getGCContent : function () {
if (typeof (this.GCContent) != 'undefined'){
return this.GCContent
}else{
return 0;
}
this.GCContent = gc / this.sequence.length
},
getSequenceLength : function () {
......
......@@ -119,6 +119,8 @@ Database.prototype = {
} else {
self.check_cert()
}
self.warn("callUrl: " + status + " - " + url.replace(self.db_address, '') + "?" + this.argsToStr(args))
}
});
......@@ -355,12 +357,14 @@ Database.prototype = {
request: function (controller_name, args, quiet) {
var self = this;
var url = controller_name + "?" + this.argsToStr(args);
//envoye de la requete ajax
$.ajax({
type: "POST",
timeout: DB_TIMEOUT_CALL,
crossDomain: true,
url: self.db_address + controller_name + "?" + this.argsToStr(args),
url: self.db_address + url,
xhrFields: {withCredentials: true},
success: function (result) {
if (typeof quiet == 'undefined')
......@@ -373,6 +377,11 @@ Database.prototype = {
} else {
self.call("patient/index")
}
if (typeof quiet == 'undefined') {
// This triggers another request() call, but this time with quiet=true
self.warn("request: " + status + " - " + url)
}
}
});
},
......@@ -676,6 +685,8 @@ Database.prototype = {
},
// Log functions, to server
// 'quiet' is set to true to avoid infinite loops with timeouts
log : function (lvl, msg) { this.request('default/logger', {'lvl': lvl, 'msg': msg}, true) },
debug: function(msg) { this.log(10, msg) },
info: function(msg) { this.log(20, msg) },
......
......@@ -55,7 +55,6 @@ function Model() {
window.onresize = function () { self.resize(); };
this.start()
}
......
......@@ -127,15 +127,15 @@ function ScatterPlot(id, model) {
// Plot axis
this.available_axis = {
"sequenceLength" : { "fct" : function(cloneID) {return self.m.clone(cloneID).getSequenceLength()} },
"GCContent" : { "fct" : function(cloneID) {return self.m.clone(cloneID).getGCContent()} },
"GCContent" : { "fct" : "GCContent", "output" : "percent" },
"n" : { "fct" : function(cloneID) {return self.m.clone(cloneID).getNlength()} },
"lengthCDR3" : { "fct" : function(cloneID) {return self.m.clone(cloneID).seg["cdr3"].length} },
"Size" : { "fct" : function(cloneID){return self.m.clone(cloneID).getSizeZero()},
"min" : function(){return self.m.min_size},
"max" : 1, "percent" : true, "log" :true },
"max" : 1, "output" : "percent", "log" :true },
"otherSize" : { "fct" : function(cloneID){return self.m.clone(cloneID).getSizeZero(m.tOther)},
"min" : function(){return self.m.min_size},
"max" : 1, "percent" : true, "log" :true }
"max" : 1, "output" : "percent", "log" :true }
}
// Plot Presets
......@@ -303,7 +303,7 @@ ScatterPlot.prototype = {
this.initMotor();
this.force
.nodes(this.nodes) //Nodes array initialisation
.on("tick", this.tick.bind(this)); // on -> Listen updates compared to modified positions
.on("tick", function(){self.tick()}); // on -> Listen updates compared to modified positions
//Création d'un element SVG pour chaque nodes (this.node.[...])
this.node = this.plot_container.selectAll("circle")
......@@ -585,7 +585,7 @@ ScatterPlot.prototype = {
}
//sort each bar (axisY)
this.sortBarTab(function(a){return self.m.clone(a).getGene("3")});
switch (this.splitY) {
case "allele_v" :
this.sortBarTab(function(cloneID){return self.m.clone(cloneID).getGene("5")});
......@@ -600,13 +600,17 @@ ScatterPlot.prototype = {
this.sortBarTab(function(cloneID){return self.m.clone(cloneID).getGene("3",false)});
break;
default :
if (typeof this.available_axis[this.splitY])
if (typeof this.available_axis[this.splitY]){
this.sortBarTab(this.available_axis[this.splitY].fct);
}else{
this.sortBarTab(function(a){return self.m.clone(a).getGene("3")});
}
break;
}
//compute position for each clones
this.computeBarTab();
},
/**
......@@ -618,7 +622,14 @@ ScatterPlot.prototype = {
* */
makeBarTab: function (fct, values) {
var min, max;
this.barTab = [];
this.barTab = {};
if (typeof fct == "string"){
var tmp = fct
fct = function(id){
return self.m.clone(id).get(tmp)
}
}
if (typeof values == "undefined"){
for (var i in this.m.clones) {
......@@ -657,7 +668,6 @@ ScatterPlot.prototype = {
}
}
}
return this;
},
......@@ -666,16 +676,25 @@ ScatterPlot.prototype = {
* param {function} fct - distribution function
* */
sortBarTab: function (fct) {
console.log('sort')
console.log(fct)
if (typeof fct == "string"){
var tmp = fct
fct = function(id){
return self.m.clone(id).get(tmp)
}
}
for (var i in this.barTab) {
this.barTab[i].sort(function (a,b) {
var va;
try{
var v = fct(a);
}catch(e){}
var va = fct(a);
}catch(e){
}
var vb;
try{
var v = fct(b);
var vb = fct(b);
}catch(e){}
if (typeof va == "undefined") return (typeof vb == "undefined") ? 0 : -1;
......@@ -730,6 +749,7 @@ ScatterPlot.prototype = {
k=1 ;
for (var i in this.barTab) {
var y_pos = 0
var x_pos = this.axisX.posBarLabel(k, tab_length)
......@@ -1628,8 +1648,8 @@ ScatterPlot.prototype = {
this.update();
}
if (typeof m.graph != "undefined") {
m.graph.setOtherVisibility(this.splitX == "otherSize" || this.splitY == "otherSize")
if (typeof this.m.graph != "undefined") {
this.m.graph.setOtherVisibility(this.splitX == "otherSize" || this.splitY == "otherSize")
}
},
......@@ -1656,7 +1676,7 @@ ScatterPlot.prototype = {
default :
if (typeof this.available_axis[splitMethod]){
var a = this.available_axis[splitMethod];
axis.custom(a.fct, a.min, a.max, a.percent, a.log)
axis.custom(a.fct, a.min, a.max, a.output, a.log)
}
break;
}
......
......@@ -74,10 +74,27 @@ test("Axis : ", function() {
//Nlength
axis.custom(function(cloneID) {
var value = m.clone(cloneID)
.getNlength()
if (typeof value != "undefined" && value != 0) return value;
return undefined;
})
m.clone(cloneID).getNlength()
return m.clone(cloneID).getNlength();
},
0,25)
equal(axis.pos(0).toPrecision(3), 0.00, "custom : clone 0 (nlength = 0) position -> 0.00")
equal(axis.pos(1).toPrecision(3), 0.360, "custom : clone 1 (nlength = 9) position -> 0.360")
//gc
axis.custom('GCContent', 0, 1, 'percent')
equal(axis.pos(0).toPrecision(3), 0.0476, "custom (percent) : clone 0 (gc = 1/21) position -> 0.0476")
equal(axis.pos(1).toPrecision(3), 0.944, "custom (percent) : clone 1 (gc = 17/18) position -> 0.944")
deepEqual(axis.labels[0].text, "0.0%", "custom (percent) : check label 0.0%")
//gc + log
axis.custom('GCContent', 0.001, 1, 'percent', true)
equal(axis.pos(0).toPrecision(3), 0.559, "custom (percent+log) : clone 0 (gc = 1/21) position -> 0.559")
equal(axis.pos(1).toPrecision(3), 0.992, "custom (percent+log) : clone 1 (gc = 17/18) position -> 0.992")
deepEqual(axis.labels[0].text, "100%", "custom (percent+log) : check label 100%")
deepEqual(axis.labels[1].text, "10%", "custom (percent+log) : check label 10%")
});
......@@ -36,7 +36,7 @@ json_data = {
},
"clones": [
{
"sequence" : "aaaaaaaaaaaaaaaaaaaaa",
"sequence" : "aaaaaaaaaaaaaaaaaaaag",
"name" : "test1",
"id" : "id1",
"reads" : [10,10,15,15] ,
......@@ -50,7 +50,7 @@ json_data = {
}
},
{
"sequence" : "bbbbbbbbbbbbbbb",
"sequence" : "ccccccccccccccccca",
"name" : "test2",
"id" : "id2",
"reads" : [20,20,10,10] ,
......
test("scatterplot : grid", function() {
var m = new Model(m);
m.parseJsonData(json_data,100)
......@@ -6,7 +7,8 @@ test("scatterplot : grid", function() {
m.initClones()
var sp = new ScatterPlot("visu",m);
sp.init();
equal(sp.returnActiveclones(), 3, "returnActiveClones -> 3");
sp.buildSystemGrid()
......@@ -17,6 +19,21 @@ test("scatterplot : grid", function() {
{"enabled": true,"text": "IGH","x": 0.80,"y": 0.75}]},
"buildSystemGrid()");
//deepEqual(sp.nodes[0], "","")
equal(sp.nodes.length, 4 , "check nodes");
sp.changeSplitMethod("gene_v", "gene_v", "plot");
sp.update()
equal(sp.axisX.pos(1), sp.axisY.pos(1), "check splitMethod V/V /plot : xpos = ypos");
equal(sp.axisX.pos(1), sp.axisY.pos(1), "check splitMethod V/V /plot : xpos = ypos");
equal(document.getElementById("circle1").className.baseVal, "circle", "check splitMethod V/V /plot : check if plot are displayed")
sp.changeSplitMethod("gene_v", "gene_v", "bar");
sp.update()
equal(document.getElementById("bar1").className.baseVal, "", "check splitMethod V/V /plot : check if bar are displayed")
$(document.getElementsByClassName("sp_legend")[0]).d3Click() //click label ighv4
deepEqual(m.getSelected(), [2], "check click label");
});
\ No newline at end of file
......@@ -55,12 +55,23 @@
<script src="../../js/lib/qunit-1.14.0.js"></script>
<script type="text/javascript" src="../../js/lib/qunit-tap.js"></script>
<script>
var tap_output;
qunitTap(QUnit, function() {
if (typeof arguments != "undefined"){
tap_output+=arguments[0]+"\n"
}
});
jQuery.fn.d3Click = function () {
this.each(function (i, e) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
e.dispatchEvent(evt);
});
};
</script>
<script src="./testFiles/dbscan_test.js"></script>
<script src="./testFiles/model_test.js"></script>
......
......@@ -43,7 +43,7 @@ def logger():
log.log(lvl, res)
def init_db(force=False):
if (db(db.auth_user.id > 0).count() == 0) or (force) :
if (force) or (db(db.auth_user.id > 0).count() == 0) :
for table in db :
table.truncate()
......
......@@ -36,11 +36,11 @@ def add_form():
import shutil, os.path, datetime
error = ""
if request.vars['sampling_date'] != None :
if request.vars['sampling_date'] != '' :
try:
datetime.datetime.strptime(""+request.vars['sampling_date'], '%Y-%m-%d')
except ValueError:
error += "date missing or wrong format, "
error += "date (wrong format), "
if request.vars['filename'] == None :
error += " missing filename"
......@@ -98,6 +98,11 @@ def edit_form():
error += "missing id"
if request.vars['filename'] == None :
error += " missing filename"
if request.vars['sampling_date'] != '' :
try:
datetime.datetime.strptime(""+request.vars['sampling_date'], '%Y-%m-%d')
except ValueError:
error += "date (wrong format), "
if error=="" :
mes = "file " + str(request.vars['id']) + " : "
......
# coding: utf8
import gluon.contrib.simplejson, datetime
import vidjil_utils
import time