Commit 9eae287a authored by Marc Duez's avatar Marc Duez
Browse files

export.js : acces model using ref instead of global

parent 4fba51e7
function Report() {
function Report(model) {
this.m = model
}
Report.prototype = {
reportHTML : function() {
m.wait("generating report : this operation can take a few seconds")
this.m.wait("generating report : this operation can take a few seconds")
var self = this
this.w = window.open("report.html", "_blank", "selected=0, toolbar=yes, scrollbars=yes, resizable=yes");
this.list = m.getSelected()
this.list = this.m.getSelected()
if (this.list.length==0) this.list = this.defaultList()
var text = ""
date_min = m.dateMin()
date_max = m.dateMax()
date_min = this.m.dateMin()
date_max = this.m.dateMax()
if (typeof m.patient_name != 'undefined')
text += m.patient_name
if (typeof this.m.patient_name != 'undefined')
text += this.m.patient_name
else
text += m.dataFileName
text += this.m.dataFileName
if (date_max != "0" && date_min != "0")
text += "" + date_min + "" + date_max
......@@ -34,27 +35,27 @@ Report.prototype = {
.readsStat()
.cloneList()
m.resize()
m.resume()
self.m.resize()
self.m.resume()
}
},
reportHTMLdiag : function() {
m.wait("generating report : this operation can take a few seconds")
this.m.wait("generating report : this operation can take a few seconds")
var self = this
this.w = window.open("report.html", "_blank", "selected=0, toolbar=yes, scrollbars=yes, resizable=yes");
var text = ""
if (typeof m.patient_name != 'undefined')
text += m.patient_name
if (typeof this.m.patient_name != 'undefined')
text += this.m.patient_name
else
text += m.dataFileName
text += ""+ m.getStrTime(m.t, "name")
if (typeof m.samples.timestamp != 'undefined')
text += ""+m.samples.timestamp[m.t].split(" ")[0]
text += this.m.dataFileName
text += ""+ this.m.getStrTime(this.m.t, "name")
if (typeof this.m.samples.timestamp != 'undefined')
text += ""+this.m.samples.timestamp[this.m.t].split(" ")[0]
this.list = m.getSelected()
this.list = this.m.getSelected()
if (this.list.length==0) this.list = this.defaultList()
this.w.onload = function(){
......@@ -62,15 +63,15 @@ Report.prototype = {
self.w.document.getElementById("header-title").innerHTML = text
self.info()
.sampleInfo(m.t)
.readsStat(m.t)
for (var i=0; i<m.system_selected.length; i++){
var system = m.system_selected[i]
self.addScatterplot(system, m.t)
.sampleInfo(self.m.t)
.readsStat(self.m.t)
for (var i=0; i<self.m.system_selected.length; i++){
var system = self.m.system_selected[i]
self.addScatterplot(system, self.m.t)
}
m.resize()
m.resume()
self.m.resize()
self.m.resume()
}
},
......@@ -80,9 +81,9 @@ Report.prototype = {
//use taged clones
var tag=0
while (tag < 8 && list.length < 5) {
for (var i = 0; i < m.clones.length; i++) {
var clone_tag = m.clone(i).getTag()
if (clone_tag == tag && m.clone(i).isActive) list.push(i)
for (var i = 0; i < this.m.clones.length; i++) {
var clone_tag = this.m.clone(i).getTag()
if (clone_tag == tag && this.m.clone(i).isActive) list.push(i)
}
tag++
}
......@@ -90,13 +91,13 @@ Report.prototype = {
//add best two clones from each system
if (list.length <5){
for (var k=0; k<2; k++){
for (var i=0; i<m.system_available.length; i++){
var system = m.system_available[i]
for (var i=0; i<this.m.system_available.length; i++){
var system = this.m.system_available[i]
var clone = -1
for (var j=0; j<m.clones.length; j++) {
if (list.indexOf(j)==-1 && m.clone(j).germline==system &&
(clone==-1 || m.clone(j).top < m.clone(clone).top ) ) clone=j
for (var j=0; j<this.m.clones.length; j++) {
if (list.indexOf(j)==-1 && this.m.clone(j).germline==system &&
(clone==-1 || this.m.clone(j).top < this.m.clone(clone).top ) ) clone=j
}
if (clone!=-1) list.push(clone)
}
......@@ -126,16 +127,16 @@ Report.prototype = {
var report_timestamp = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate()
var analysis_timestamp = ""
if (typeof m.analysis.timestamp != "undefined")
analysis_timestamp = m.analysis.timestamp.split(" ")[0]
if (m.analysisHasChanged)
if (typeof this.m.analysis.timestamp != "undefined")
analysis_timestamp = this.m.analysis.timestamp.split(" ")[0]
if (this.m.analysisHasChanged)
analysis_timestamp = report_timestamp + " (not saved)"
var content = [
{'label': "Filename:" , 'value' : m.dataFileName },
{'label': "Filename:" , 'value' : this.m.dataFileName },
{'label': "Report date:" , 'value' : report_timestamp},
{'label': "Updated on:" , 'value' : analysis_timestamp},
{'label': "Software used:" , 'value' : m.getSoftVersion()},
{'label': "Software used:" , 'value' : this.m.getSoftVersion()},
{'label': "Analysis date:" , 'value' : "" }
]
......@@ -149,21 +150,21 @@ Report.prototype = {
var note = $('<div/>', {'class': 'float-left'}).appendTo(left);
$('<div/>', {'class': 'case label', 'text' : "User note" }).appendTo(note);
$('<div/>', {'class': 'note', 'text' : m.info }).appendTo(note);
$('<div/>', {'class': 'note', 'text' : this.m.info }).appendTo(note);
return this
},
sampleInfo : function(time) {
var sinfo = this.container("Sample info ("+m.getStrTime(time)+")")
var sinfo = this.container("Sample info ("+this.m.getStrTime(time)+")")
var left = $('<div/>', {'class': 'flex'}).appendTo(sinfo);
var content = [
{'label': "Filename:" , value : m.samples.original_names[time]},
{'label': "Sample date:" , value : m.getSampleTime(time)},
{'label': "Software used:" , value : m.getSoftVersionTime(time)},
{'label': "Parameters:" , value : m.getCommandTime(time)},
{'label': "Analysis date:" , value : m.getTimestampTime(time)}
{'label': "Filename:" , value : this.m.samples.original_names[time]},
{'label': "Sample date:" , value : this.m.getSampleTime(time)},
{'label': "Software used:" , value : this.m.getSoftVersionTime(time)},
{'label': "Parameters:" , value : this.m.getCommandTime(time)},
{'label': "Analysis date:" , value : this.m.getTimestampTime(time)}
]
var table = $('<table/>', {'class': 'info-table float-left'}).appendTo(left);
......@@ -178,7 +179,7 @@ Report.prototype = {
$('<div/>', {'class': 'case label', 'text': "User note" }).appendTo(note);
var info = "..."
if (typeof m.samples.info != "undefined") info = m.samples.info[time]
if (typeof this.m.samples.info != "undefined") info = this.m.samples.info[time]
$('<div/>', {'class': 'note', 'text': info }).appendTo(note);
return this
......@@ -190,10 +191,10 @@ Report.prototype = {
var svg_graph = document.getElementById(graph.id+"_svg").cloneNode(true);
svg_graph.setAttribute("viewBox","0 0 "+svg_graph.getAttribute("width")+" "+svg_graph.getAttribute("height"));
for (var i = 0; i < m.clones.length; i++) {
for (var i = 0; i < this.m.clones.length; i++) {
var polyline = svg_graph.querySelectorAll('[id="polyline'+i+'"]')[0]
var tag = m.clone(i).getTag()
var color = tag[tag].color
var tag = this.m.clone(i).getTag()
var color = this.m.tag[tag].color
if (i == norm) {
polyline.setAttribute("style", "stroke-width:12px");
......@@ -207,7 +208,7 @@ Report.prototype = {
polyline.setAttribute("stroke", color);
//remove "other" and disabled clones
if (i != norm && (m.clone(i).id == "other" || !m.clone(i).isActive())) {
if (i != norm && (this.m.clone(i).id == "other" || !this.m.clone(i).isActive())) {
polyline.parentNode.removeChild(polyline);
}
}
......@@ -233,12 +234,12 @@ Report.prototype = {
},
normalizeInfo: function () {
if (m.norm){
if (this.m.norm){
var container = this.container("Normalization")
var norm_id = m.normalization.id
var norm_value = m.normalization.B
var norm_id = this.m.normalization.id
var norm_value = this.m.normalization.B
m.compute_normalization(-1)
this.m.compute_normalization(-1)
graph.resize(791,300)
graph.draw(0)
var svg_graph = this.svg_graph(norm_id)
......@@ -246,7 +247,7 @@ Report.prototype = {
svg_graph.setAttribute("height", "150px")
container.append(svg_graph)
m.compute_normalization(norm_id, norm_value)
this.m.compute_normalization(norm_id, norm_value)
graph.resize(791,300)
graph.draw(0)
var svg_graph = this.svg_graph(norm_id)
......@@ -261,17 +262,17 @@ Report.prototype = {
},
addScatterplot : function(system, time) {
if (typeof system == "undefined") system = m.germlineV.system
if (typeof time != "undefined") m.changeTime(time)
if (typeof system == "undefined") system = this.m.germlineV.system
if (typeof time != "undefined") this.m.changeTime(time)
m.changeGermline(system, false)
this.m.changeGermline(system, false)
sp.changeSplitMethod('gene_v', 'gene_j', 'plot')
//resize 791px ~> 21cm
sp.resize(791,250)
sp.fastForward()
var w_sp = this.container(m.getStrTime(m.t) + '' + system)
var w_sp = this.container(this.m.getStrTime(this.m.t) + '' + system)
w_sp.addClass("scatterplot");
var svg_sp = document.getElementById(sp.id+"_svg").cloneNode(true);
......@@ -279,13 +280,13 @@ Report.prototype = {
//set viewbox (same as resize)
svg_sp.setAttribute("viewBox","0 0 791 250");
for (var i = 0; i < m.clones.length; i++) {
for (var i = 0; i < this.m.clones.length; i++) {
var circle = svg_sp.querySelectorAll('[id="circle'+i+'"]')[0]
var color = tag[m.clone(i).getTag()].color
var color = this.m.tag[this.m.clone(i).getTag()].color
circle.setAttribute("stroke", color);
//remove "other" and disabled clones
if (m.clone(i).germline != system || m.clone(i).id == "other" || !m.clone(i).isActive()) {
if (this.m.clone(i).germline != system || this.m.clone(i).id == "other" || !this.m.clone(i).isActive()) {
circle.parentNode.removeChild(circle);
}
}
......@@ -298,7 +299,7 @@ Report.prototype = {
for (var i=0; i<this.list.length; i++){
var cloneID = this.list[i]
if (m.clone(cloneID).germline == system) this.clone(cloneID, time).appendTo(this.w.document.body);
if (this.m.clone(cloneID).germline == system) this.clone(cloneID, time).appendTo(this.w.document.body);
}
return this
......@@ -315,21 +316,21 @@ Report.prototype = {
$('<div/>', {'class': 'case', 'text': 'total'}).appendTo(head);
$('<div/>', {'class': 'case', 'text': 'segmented'}).appendTo(head);
if (m.system_selected.length < m.system_available.length) {
if (this.m.system_selected.length < this.m.system_available.length) {
$('<div/>', {'class': 'case', 'text': 'segmented (selected systems)'}).appendTo(head);
}
if (m.system_available.length>1){
for (var i=0; i<m.system_selected.length; i++){
var system = m.system_selected[i]
if (this.m.system_available.length>1){
for (var i=0; i<this.m.system_selected.length; i++){
var system = this.m.system_selected[i]
var system_label = $('<div/>', {'class': 'case', 'text': system}).appendTo(head);
$('<span/>', {'class': 'system_colorbox', style:'background-color:'+m.germlineList.getColor(system)}).appendTo(system_label);
$('<span/>', {'class': 'system_colorbox', style:'background-color:'+this.m.germlineList.getColor(system)}).appendTo(system_label);
}
}
if (time == -1){
for (var i=0; i<m.samples.order.length; i++){
var t = m.samples.order[i]
for (var i=0; i<this.m.samples.order.length; i++){
var t = this.m.samples.order[i]
var box=this.readsStat2(t)
box.appendTo(reads_stats);
}
......@@ -343,29 +344,29 @@ Report.prototype = {
readsStat2: function (time){
var box = $('<div/>', {'class': 'float-left'})
$('<div/>', {'class': 'case centered', 'text': m.getStrTime(time)}).appendTo(box);
$('<div/>', {'class': 'case centered', 'text': m.toStringThousands(m.reads.total[time])}).appendTo(box);
$('<div/>', {'class': 'case centered', 'text': this.m.getStrTime(time)}).appendTo(box);
$('<div/>', {'class': 'case centered', 'text': this.m.toStringThousands(this.m.reads.total[time])}).appendTo(box);
var segmented = ((m.reads.segmented_all[time]/m.reads.total[time])*100).toFixed(0) + "%"
var segmented = ((this.m.reads.segmented_all[time]/this.m.reads.total[time])*100).toFixed(0) + "%"
var seg_box = $('<div/>', {'class': 'case centered', 'text': segmented}).appendTo(box);
$('<div/>', {'class': 'background1'}).appendTo(seg_box);
$('<div/>', {'class': 'background2', style: 'width:'+segmented}).appendTo(seg_box);
if (m.system_selected.length < m.system_available.length) {
if (this.m.system_selected.length < this.m.system_available.length) {
var segmented = ((m.reads.segmented[time]/m.reads.total[time])*100).toFixed(0) + "%"
var segmented = ((this.m.reads.segmented[time]/this.m.reads.total[time])*100).toFixed(0) + "%"
var seg_box = $('<div/>', {'class': 'case centered', 'text': segmented}).appendTo(box);
$('<div/>', {'class': 'background1'}).appendTo(seg_box);
$('<div/>', {'class': 'background2', style: 'width:'+segmented}).appendTo(seg_box);
}
if (m.system_available.length>1){
if (this.m.system_available.length>1){
var pie = $('<div/>').appendTo(box);
var pie_label = $('<div/>', {'class': 'left'}).appendTo(pie);
for (var j=0; j<m.system_selected.length; j++){
var system = m.system_selected[j]
var value = ((m.systemSize(system,time))*100).toFixed(0) + "%"
for (var j=0; j<this.m.system_selected.length; j++){
var system = this.m.system_selected[j]
var value = ((this.m.systemSize(system,time))*100).toFixed(0) + "%"
$('<div/>', {'class': 'case', 'text': value}).appendTo(pie_label);
}
......@@ -379,7 +380,7 @@ Report.prototype = {
},
systemPie: function(time) {
if (typeof time == "undefined") time = m.t
if (typeof time == "undefined") time = this.m.t
var radius = 40
var pie = document.createElementNS("http://www.w3.org/2000/svg", "svg");
pie.setAttribute("viewBox","0 0 100 100");
......@@ -387,9 +388,9 @@ Report.prototype = {
pie.setAttribute("height",(radius*2)+"px");
var start = 0
for (var i=0; i<m.system_selected.length; i++){
var system = m.system_selected[i]
var value = m.systemSize(system,time)
for (var i=0; i<this.m.system_selected.length; i++){
var system = this.m.system_selected[i]
var value = this.m.systemSize(system,time)
var angle = Math.PI*2*(value)
var stop = start+angle
......@@ -408,7 +409,7 @@ Report.prototype = {
" A " + radius + " " + radius + " 0 "+longArc+" 1 " + (radius + x2) + " " + (radius + y2) +
" z ";
slice.setAttribute('d', d);
slice.setAttribute('fill', m.germlineList.getColor(system));
slice.setAttribute('fill', this.m.germlineList.getColor(system));
pie.appendChild(slice)
}else{
var slice = document.createElementNS("http://www.w3.org/2000/svg", "circle");
......@@ -416,7 +417,7 @@ Report.prototype = {
slice.setAttribute('r', radius)
slice.setAttribute('cx', radius)
slice.setAttribute('cy', radius)
slice.setAttribute('fill', m.germlineList.getColor(system));
slice.setAttribute('fill', this.m.germlineList.getColor(system));
pie.appendChild(slice)
}
......@@ -441,8 +442,8 @@ Report.prototype = {
clone : function(cloneID, time) {
if (typeof time == "undefined") time = -1
var color = tag[m.clone(cloneID).getTag()].color
var system = m.clone(cloneID).germline
var color = this.m.tag[this.m.clone(cloneID).getTag()].color
var system = this.m.clone(cloneID).germline
var clone = $('<div/>', {'class': 'clone'})
graph.resize(791,300)
......@@ -464,33 +465,33 @@ Report.prototype = {
}
//clone label
$('<span/>', {'text': ">"+m.clone(cloneID).getCode()+'\u00a0', 'class': 'clone_name', style : 'color:'+color}).appendTo(head);
if (typeof m.clone(cloneID).c_name != "undefined"){
$('<span/>', {'text': m.clone(cloneID).c_name+'\u00a0', 'class': 'clone_name', style : 'color:'+color}).appendTo(head);
$('<span/>', {'text': ">"+this.m.clone(cloneID).getCode()+'\u00a0', 'class': 'clone_name', style : 'color:'+color}).appendTo(head);
if (typeof this.m.clone(cloneID).c_name != "undefined"){
$('<span/>', {'text': this.m.clone(cloneID).c_name+'\u00a0', 'class': 'clone_name', style : 'color:'+color}).appendTo(head);
}
//clone reads stats
if (time == -1){
var reads_stats = $('<span/>', {'class': 'clone_table'}).appendTo(clone);
for (var i=0; i<m.samples.order.length; i++){
var t = m.samples.order[i]
$('<span/>', {'text': m.clone(cloneID).getPrintableSize(t)+'\u00a0', 'class': 'clone_value'}).appendTo(reads_stats);
for (var i=0; i<this.m.samples.order.length; i++){
var t = this.m.samples.order[i]
$('<span/>', {'text': this.m.clone(cloneID).getPrintableSize(t)+'\u00a0', 'class': 'clone_value'}).appendTo(reads_stats);
}
}else{
$('<span/>', {'text': m.clone(cloneID).getPrintableSize(time)+'\u00a0', 'class': 'float-right'}).appendTo(head);
$('<span/>', {'text': this.m.clone(cloneID).getPrintableSize(time)+'\u00a0', 'class': 'float-right'}).appendTo(head);
}
//colorized clone sequence
var sequence = $('<div/>', {'class': 'sequence'}).appendTo(clone);
if (typeof m.clone(cloneID).seg != 'undefined'){
var seg = m.clone(cloneID).seg
var seq = m.clone(cloneID).getSequence()
if (typeof this.m.clone(cloneID).seg != 'undefined'){
var seg = this.m.clone(cloneID).seg
var seq = this.m.clone(cloneID).getSequence()
var seqV = seq.substring(0, seg['5end'] + 1)
var seqN = seq.substring(seg['5end'] + 1, seg['3start'])
var seqJ = seq.substring(seg['3start'])
$('<span/>', {'class': 'v_gene', 'text': seqV}).appendTo(sequence);
if (m.clone(cloneID).getD() != "undefined D"){
if (this.m.clone(cloneID).getD() != "undefined D"){
var seqN1 = seq.substring(seg['5end'] + 1, seg['4start'])
var seqD = seq.substring(seg['4start'] , seg['4end'] + 1)
var seqN2 = seq.substring(seg['4end'] + 1, seg['3start'])
......@@ -502,8 +503,8 @@ Report.prototype = {
}
$('<span/>', {'class': 'j_gene', 'text': seqJ}).appendTo(sequence);
}
else if (m.clone(cloneID).getSequence() != "0") {
$('<span/>', {'class': 'unseg_gene', 'text': m.clone(cloneID).getSequence()}).appendTo(sequence);
else if (this.m.clone(cloneID).getSequence() != "0") {
$('<span/>', {'class': 'unseg_gene', 'text': this.m.clone(cloneID).getSequence()}).appendTo(sequence);
} else {
$('<span/>', {'text': 'segment fail'}).appendTo(sequence);
}
......
Supports Markdown
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