Commit abbd7983 authored by Marc Duez's avatar Marc Duez

browser.js : use segmentation info

parent f4043b6d
......@@ -62,15 +62,20 @@ Axis.prototype = {
var allele_list = self.germline.allele
var total_gene = Object.keys(gene_list).length
var type2
if (geneType=="V") type2="5"
if (geneType=="D") type2="4"
if (geneType=="J") type2="3"
//clone position
this.pos = function(cloneID) {
var clone = self.m.clone(cloneID)
if (typeof clone[geneType] != "undefined"
&& typeof clone[geneType][0] != "undefined"
&& typeof gene_list[clone[geneType][0].split("*")[0]] != "undefined")
if (typeof clone.seg != "undefined"
&& typeof clone.seg[type2] != "undefined"
&& typeof gene_list[clone.seg[type2][0].split("*")[0]] != "undefined")
{
var allele = clone[geneType][0]
var gene = clone[geneType][0].split("*")[0]
var allele = clone.seg[type2][0]
var gene = clone.seg[type2][0].split("*")[0]
var pos = ((gene_list[gene].rank+0.5)/(total_gene+1))
if (displayAllele){
......@@ -140,7 +145,8 @@ Axis.prototype = {
var n_min = 0;
var n_max = 1;
for (var i=0; i<this.m.n_clones; i++){
if (this.m.clone(i).Nlength > n_max) n_max = this.m.clone(i).Nlength;
var n = this.m.clone(i).getNlength();
if (n > n_max) n_max = n;
}
this.sizeScale = d3.scale.linear()
......@@ -149,13 +155,13 @@ Axis.prototype = {
//clone position
this.pos = function(cloneID) {
return self.sizeScale(self.m.clone(cloneID).Nlength)
return 1 - self.sizeScale(self.m.clone(cloneID).getNlength())
}
//labels
var h = Math.ceil(n_max/5)
for (var i = 0; i < 5; i++) {
var pos = this.sizeScale(h*i);
var pos = 1-this.sizeScale(h*i);
var text = h*i
this.labels.push(this.label("line", pos, text));
}
......
......@@ -114,8 +114,9 @@ Clone.prototype = {
time = typeof time !== 'undefined' ? time : this.m.t;
var result = 0;
for (var j = 0; j < this.m.clusters[this.hash].length; j++) {
result += this.m.clone(this.m.clusters[this.hash][j]).size[time];
var cluster = this.m.clusters[this.hash]
for (var j = 0; j < cluster.length; j++) {
result += this.m.clone(cluster[j]).reads[time];
}
return result
......@@ -127,24 +128,66 @@ Clone.prototype = {
* */
getSequenceReads: function (time) {
time = typeof time !== 'undefined' ? time : this.m.t;
return this.size[time];;
return this.reads[time];;
}, //end getSequenceSize
getV: function () {
if (typeof (this.sequence) != 'undefined' && typeof (this.V) != 'undefined') {
return this.V[0].split('*')[0];
getV: function (withAllele) {
withAllele = typeof withAllele !== 'undefined' ? withAllele : true;
if (typeof (this.seg) != 'undefined' && typeof (this.seg["5"]) != 'undefined') {
if (withAllele) {
return this.seg["5"][0]
}else{
return this.seg["5"][0].split('*')[0];
}
}
return "undefined V";
},
getD: function (withAllele) {
withAllele = typeof withAllele !== 'undefined' ? withAllele : true;
if (typeof (this.seg) != 'undefined' && typeof (this.seg["4"]) != 'undefined') {
if (withAllele) {
return this.seg["4"][0]
}else{
return this.seg["4"][0].split('*')[0];
}
}
return "undefined D";
},
getJ: function () {
if (typeof (this.sequence) != 'undefined' && typeof (this.J) != 'undefined') {
return this.J[0].split('*')[0];;
getJ: function (withAllele) {
withAllele = typeof withAllele !== 'undefined' ? withAllele : true;
if (typeof (this.seg) != 'undefined' && typeof (this.seg["3"]) != 'undefined') {
if (withAllele) {
return this.seg["3"][0]
}else{
return this.seg["3"][0].split('*')[0];
}
}
return "undefined J";
},
getGene: function (type, withAllele) {
withAllele = typeof withAllele !== 'undefined' ? withAllele : true;
if (typeof (this.seg) != 'undefined' && typeof (this.seg[type]) != 'undefined') {
if (withAllele) {
return this.seg[type][0];
}else{
return this.seg[type][0].split('*')[0];
}
}
return "undefined";
},
getNlength: function () {
if (typeof this.seg != 'undefined'){
return this.seg['3start']-this.seg['5end']-1
}else{
return 0
}
},
getSequence : function () {
if (typeof (this.sequence) != 'undefined' && this.sequence != 0){
return this.sequence
......@@ -221,11 +264,11 @@ Clone.prototype = {
this.color = tagColor[this.tag];
}else if (this.m.colorMethod == "dbscan"){
this.color = this.colorDBSCAN;
}else if (this.m.colorMethod == "V" && typeof (this.V) != 'undefined'){
}else if (this.m.colorMethod == "V" && this.seg["5"] !== undefined){
this.color = this.colorV;
}else if (this.m.colorMethod == "D" && typeof (this.D) != 'undefined'){
}else if (this.m.colorMethod == "D" && this.seg["4"] !== undefined){
this.color = this.colorD;
}else if (this.m.colorMethod == "J" && typeof (this.J) != 'undefined'){
}else if (this.m.colorMethod == "J" && this.seg["3"] !== undefined){
this.color = this.colorJ;
}else if (this.m.colorMethod == "N" && typeof (this.N) != 'undefined'){
this.color = this.colorN;
......@@ -314,9 +357,9 @@ Clone.prototype = {
html += "<tr><td> sequence </td><td colspan='" + time_length + "'>" + this.sequence + "</td></tr>"
html += "<tr><td> window </td><td colspan='" + time_length + "'>" + this.window + "</td></tr>"
html += "<tr><td> V </td><td colspan='" + time_length + "'>" + this.V + "</td></tr>"
html += "<tr><td> D </td><td colspan='" + time_length + "'>" + this.D + "</td></tr>"
html += "<tr><td> J </td><td colspan='" + time_length + "'>" + this.J + "</td></tr>"
html += "<tr><td> 5 </td><td colspan='" + time_length + "'>" + this.seg["5"] + "</td></tr>"
html += "<tr><td> 4 </td><td colspan='" + time_length + "'>" + this.seg["4"] + "</td></tr>"
html += "<tr><td> 3 </td><td colspan='" + time_length + "'>" + this.seg["3"] + "</td></tr>"
//other info (clntab)
......
......@@ -46,14 +46,20 @@ Germline.prototype = {
return callback
}
this.gene = {}
var type2
if (type=="V") type2="5"
if (type=="D") type2="4"
if (type=="J") type2="3"
//reduce germline size (keep only detected genes)
//and add undetected genes
var g = {}
for (var i=0; i<this.m.n_clones; i++){
if (typeof this.m.clone(i)[type] != "undefined"
&& typeof this.m.clone(i)[type][0] != "undefined"){
var gene=this.m.clone(i)[type][0];
if (typeof this.m.clone(i).seg != "undefined" &&
typeof this.m.clone(i).seg[type2] != "undefined"
){
var gene=this.m.clone(i).seg[type2][0];
if (this.m.system != "multi" || this.m.clone(i).getSystem() == system){
if ( typeof this.allele[gene] != "undefined"){
g[gene] = this.allele[gene]
......
......@@ -531,21 +531,10 @@ List.prototype = {
var oA = 2147483647
var oB = 2147483647
var cA = self.m.clone(idA)
if (typeof (cA.V) != 'undefined' &&
typeof (cA.V[0]) != 'undefined' &&
typeof (self.m.germlineV.allele[cA.V[0]]) != 'undefined') {
var vA = cA.V[0];
oA = this.m.germlineV.allele[vA].gene * 1000 + this.m.germlineV.allele[vA].rank
}
var cB = self.m.clone(idB)
if (typeof (cB.V) != 'undefined' &&
typeof (cB.V[0]) != 'undefined' &&
typeof (self.m.germlineV.allele[cB.V[0]]) != 'undefined') {
var vB = cB.V[0];
oB = this.m.germlineV.allele[vB].gene * 1000 + this.m.germlineV.allele[vB].rank
}
var vA = self.m.clone(idA).getV(true)
if (vA != "undefined V") oA = this.m.germlineV.allele[vA].gene * 1000 + this.m.germlineV.allele[vA].rank
var vB = self.m.clone(idB).getV(true)
if (vB != "undefined V") oB = this.m.germlineV.allele[vB].gene * 1000 + this.m.germlineV.allele[vB].rank
return oA > oB ? 1 : -1;
})
......@@ -565,21 +554,10 @@ List.prototype = {
var oA = 2147483647
var oB = 2147483647
var cA = self.m.clone(idA)
if (typeof (cA.J) != 'undefined' &&
typeof (cA.J[0]) != 'undefined' &&
typeof (self.m.germlineJ.allele[cA.J[0]]) != 'undefined') {
var jA = cA.J[0];
oA = this.m.germlineJ.allele[jA].gene * 1000 + this.m.germlineJ.allele[jA].rank
}
var cB = self.m.clone(idB)
if (typeof (cB.J) != 'undefined' &&
typeof (cB.J[0]) != 'undefined' &&
typeof (self.m.germlineJ.allele[cB.J[0]]) != 'undefined') {
var jB = cB.J[0];
oB = this.m.germlineJ.allele[jB].gene * 1000 + this.m.germlineJ.allele[jB].rank
}
var jA = self.m.clone(idA).getJ(true)
if (vA != "undefined V") oA = this.m.germlineJ.allele[jA].gene * 1000 + this.m.germlineJ.allele[jA].rank
var jB = self.m.clone(idB).getJ(true)
if (vB != "undefined V") oB = this.m.germlineJ.allele[jB].gene * 1000 + this.m.germlineJ.allele[jB].rank
return oA > oB ? 1 : -1;
})
......
......@@ -235,7 +235,24 @@ Model.prototype = {
var min_sizes = [];
var n_max = 0;
for (var k = 0; k < data.clones[0].size.length; k++) {
self.samples = data.samples
self.reads = data.reads
self.links = data.links;
// default samples
if (typeof self.samples.number == 'string'){
self.samples.number = parseInt(self.samples.number)
}
if (typeof self.samples.order == 'undefined'){
self.samples.order = []
for (var i = 0; i < self.samples.number; i++) self.samples.order.push(i);
}
if (typeof self.samples.names =='undefined'){
self.samples.names = []
for (var i = 0; i < self.samples.number; i++) self.samples.names.push("");
}
for (var k = 0; k < self.samples.number; k++) {
min_sizes[k] = 0.01;
}
......@@ -243,25 +260,11 @@ Model.prototype = {
//keep best top value
for (var i = 0; i < data.clones.length; i++) {
if (data.clones[i].top <= limit) {
//search for min_size
for (var k = 0; k < data.clones[i].size.length; k++) {
var size = (data.clones[i].size[k] / data.reads.segmented[k])
if (min_sizes[k] > size && data.clones[i].size[k] != 0)
min_sizes[k] = size;
}
data.clones[i].Nlength = 0;
if ((typeof (data.clones[i].Jstart) != 'undefined') &&
(typeof (data.clones[i].Vend) != 'undefined') ) {
data.clones[i].Nlength = data.clones[i].Jstart - data.clones[i].Vend
}
//search for n_max
if ((typeof (data.clones[i].sequence) != 'undefined') &&
(typeof (data.clones[i].Nlength) != 'undefined') &&
(data.clones[i].Nlength > n_max)) {
n_max = data.clones[i].Nlength;
//search for min_size
for (var k = 0; k < self.samples.number; k++) {
var size = (data.clones[i].reads[k] / data.reads.segmented[k])
if (min_sizes[k] > size && data.clones[i].reads[k] != 0)min_sizes[k] = size;
}
var clone = new Clone(data.clones[i], self, hash)
......@@ -270,33 +273,16 @@ Model.prototype = {
}
}
self.samples = data.samples
self.reads = data.reads
self.links = data.links;
// synthetic window
var other = {
"sequence": 0,
"window": "other",
"top": 0,
"size": []
"reads": []
}
var clone = new Clone(other, self, hash)
self.clones.push(clone);
// default samples
if (typeof self.samples.number == 'string'){
self.samples.number = parseInt(self.samples.number)
}
if (typeof self.samples.order == 'undefined'){
self.samples.order = []
for (var i = 0; i < self.samples.number; i++) self.samples.order.push(i);
}
if (typeof self.samples.names =='undefined'){
self.samples.names = []
for (var i = 0; i < self.samples.number; i++) self.samples.names.push("");
}
self.n_clones = self.clones.length;
self.min_sizes = min_sizes;
self.n_max = n_max;
......@@ -494,33 +480,26 @@ Model.prototype = {
* */
initClones: function () {
myConsole.log("initClones()");
var maxNlength = 0;
var nsize;
self.mapID = [];
this.clusters = [];
// NSIZE
var n_max = 0;
for (var i = 0; i < this.n_clones; i++) {
var clone = this.clone(i)
var n = clone.getNlength();
if (typeof (clone.getSequence()) != 'undefined') {
nsize = clone.Nlength;
if (nsize > maxNlength) {
maxNlength = nsize;
}
} else {
nsize = -1;
}
if (n > n_max) {n_max = n; }
self.mapID[clone.window] = i;
this.clusters[i] = [i]
clone.Nlength = nsize;
clone.tag = default_tag;
}
// COLOR_N
for (var i = 0; i < this.n_clones; i++) {
var clone = this.clone(i)
clone.colorN = colorGenerator((((clone.Nlength / maxNlength) - 1) * (-250)), color_s, color_v);
clone.colorN = colorGenerator((((clone.getNlength() / n_max) - 1) * (-250)), color_s, color_v);
}
this.computeColor()
......@@ -546,26 +525,20 @@ Model.prototype = {
for (var i = 0; i < this.n_clones; i++) {
var clone = this.clone(i)
if (typeof (clone.V) != 'undefined' && this.germlineV.allele[clone.V[0]]) {
var vGene = clone.V[0];
var vGene = clone.getV();
if (typeof this.germlineV.allele[vGene] != 'undefined' ) {
clone.colorV = this.germlineV.allele[vGene].color;
} else {
clone.colorV = "";
}
}
// COLOR_J
for (var i = 0; i < this.n_clones; i++) {
var clone = this.clone(i)
if (typeof (clone.J) != 'undefined' && this.germlineJ.allele[clone.J[0]]) {
var jGene = clone.J[0];
var jGene = clone.getJ();
if (typeof this.germlineJ.allele[jGene] != 'undefined' ) {
clone.colorJ = this.germlineJ.allele[jGene].color;
} else {
clone.colorJ = "";
}
}
return this
},
......@@ -1325,22 +1298,22 @@ Model.prototype = {
computeOtherSize: function () {
var other = [];
for (var j = 0; j < this.reads.segmented.length; j++) {
for (var j = 0; j < this.samples.number; j++) {
other[j] = this.reads.segmented[j]
}
for (var i = 0; i < this.n_clones - 1; i++) {
for (var j = 0; j < this.reads.segmented.length; j++) {
for (var j = 0; j < this.samples.number; j++) {
if (this.clone(i).isActive()) {
for (var k = 0; k < this.clusters[i].length; k++) {
if (this.clusters[i][k] != this.n_clones - 1)
other[j] -= this.clone(this.clusters[i][k]).size[j];
other[j] -= this.clone(this.clusters[i][k]).getSequenceReads(j);
}
}
}
}
this.clone(this.n_clones - 1).size = other;
this.clone(this.n_clones - 1).reads = other;
},
......
......@@ -684,7 +684,7 @@ ScatterPlot.prototype = {
//classement des clones suivant V
for (var i = 0; i < this.m.n_clones; i++) {
if (this.m.clone(i).isActive()) {
var geneV = this.m.clone(i).getV();
var geneV = this.m.clone(i).getV(false);
var clone = {
id: i
}
......
......@@ -499,33 +499,33 @@ Sequence.prototype = {
//return sequence completed with html tag
toString: function () {
var seg = this.m.clone(this.id)
var clone = this.m.clone(this.id)
var result = ""
if (typeof seg.sequence != 'undefined' && seg.sequence != 0) {
if (typeof clone.sequence != 'undefined' && clone.sequence != 0) {
//find V, D, J position
var endV = this.pos[seg.Vend]
var startJ = this.pos[seg.Jstart]
if (typeof seg.Dstart != 'undefined' && typeof seg.Dend != 'undefined') {
var startD = this.pos[seg.Dstart]
var endD = this.pos[seg.Dend]
var endV = this.pos[clone.seg["5end"]]
var startJ = this.pos[clone.seg["3start"]]
if (typeof clone.seg["4start"] != 'undefined' && typeof clone.seg["4end"] != 'undefined') {
var startD = this.pos[clone.seg["4start"]]
var endD = this.pos[clone.seg["4end"]]
}
//V color
var vColor = "";
if (this.m.colorMethod == "V") vColor = "style='color : " + seg.colorV + "'";
if (this.m.colorMethod == "V") vColor = "style='color : " + clone.colorV + "'";
//J color
var jColor = "";
if (this.m.colorMethod == "J") jColor = "style='color : " + seg.colorJ + "'";
if (this.m.colorMethod == "J") jColor = "style='color : " + clone.colorJ + "'";
//window
var window_start = this.pos[seg.sequence.indexOf(seg.window)]
var window_end = this.pos[seg.sequence.indexOf(seg.window)+seg.window.length]
var window_start = this.pos[clone.sequence.indexOf(clone.window)]
var window_end = this.pos[clone.sequence.indexOf(clone.window)+clone.window.length]
//add span VDJ
if (typeof seg.Vend != 'undefined') result += "<span class='V' " + vColor + " >"
if (typeof clone.seg["5end"] != 'undefined') result += "<span class='V' " + vColor + " >"
else result += "<span>"
for (var i = 0; i < this.seq.length; i++) {
result += this.seq[i]
......@@ -545,7 +545,7 @@ Sequence.prototype = {
result += "</span>"
}else{
var window_start = 0
result += seg.window
result += clone.window
}
//marge
......
......@@ -206,7 +206,7 @@ class ListWindows:
self.d["windows"] = []
self.d["clones"] = []
self.d["reads_segmented"] = [[0]]
self.d["germline"] = [""]
self.d["germline"] = ""
self.d["samples"] = [Samples()]
def __str__(self):
......@@ -378,8 +378,8 @@ class ListWindows:
def add_system_info(self):
w = self.d["windows"]
germline = self.d["germline"][0]
system = germline[-4:].replace('/','')
germline = self.d["germline"]
system = germline.split('/')[-1]
for i in range(len(w)):
......@@ -445,7 +445,6 @@ class ListWindows:
#others += win
self.d["windows"] = w #+ list(others)
self.d["germline"]=self.d["germline"][0]
print "### Cut merged file, keeping window in the top %d for at least one point" % limit
return self
......@@ -810,7 +809,7 @@ def main():
jlist_fused = jlist_fused * jlist
print '\t==> merge to', jlist_fused
jlist_fused.d['germline'][0] = "multi"
jlist_fused.d['germline'] = "multi"
jlist_fused.d["system_segmented"] = ordered(jlist_fused.d["system_segmented"], key=lambda sys: ((GERMLINES_ORDER + [sys]).index(sys), sys))
else:
......@@ -833,7 +832,7 @@ def main():
jlist_fused = jlist_fused + jlist
print '\t==> merge to', jlist_fused
jlist_fused.d['germline'][0] = args.germline
jlist_fused.d['germline'] = args.germline
print
print "### Select point names"
......
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