Commit 2f117f42 authored by Mikaël Salson's avatar Mikaël Salson

clone.js: hasSeg now checks for properties inside seg

This follows a suggestion by @magiraud in #2085 about
the usefulness of hasSeg.
Now hasSeg is used to reduce the code written, enhance the
readability and minimize my cognitive dissonance (see c97705f9).

Closes #2085.
parent 90fdcfb2
......@@ -99,8 +99,7 @@ Axis.prototype = {
//clone position
this.pos = function(cloneID) {
var clone = self.m.clone(cloneID)
if (clone.hasSeg()
&& typeof clone.seg[type2] != "undefined"
if (clone.hasSeg('type2')
&& typeof clone.seg[type2]["name"] != 'undefined'
&& typeof gene_list[clone.seg[type2]["name"].split("*")[0]] != "undefined")
{
......
......@@ -142,8 +142,7 @@ Clone.prototype = {
* Get the amino-acid sequence of the provided field (in the seg part)
*/
getSegAASequence: function(field_name) {
if (this.hasSeg()
&& typeof this.seg[field_name] != 'undefined'
if (this.hasSeg(field_name)
&& typeof this.seg[field_name].aa != 'undefined') {
return this.seg[field_name].aa;
}
......@@ -180,8 +179,7 @@ Clone.prototype = {
* If it does not exist return null
*/
getSegStartStop: function(field_name) {
if (this.hasSeg()
&& typeof this.seg[field_name] != 'undefined'
if (this.hasSeg(field_name)
&& typeof this.seg[field_name].start != 'undefined'
&& typeof this.seg[field_name].stop != 'undefined') {
return {'start': this.seg[field_name].start,
......@@ -501,8 +499,15 @@ Clone.prototype = {
}, //end getSize
hasSeg: function() {
return typeof(this.seg) != 'undefined' && ! $.isEmptyObject(this.seg)
/**
* @param: A variable number of arguments which consists of property names that should be found in seg.
* @return true iff all of the property are found in seg.
*/
hasSeg: function(/* some arguments */) {
for (i = 0; i < arguments.length; i++)
if (typeof(this.seg[arguments[i]]) == 'undefined')
return false
return true
},
computeEValue: function () {
......@@ -515,7 +520,7 @@ Clone.prototype = {
getGene: function (type, withAllele) {
withAllele = typeof withAllele !== 'undefined' ? withAllele : true;
if (this.hasSeg() && typeof (this.seg[type]) != 'undefined' && typeof this.seg[type]["name"] != 'undefined') {
if (this.hasSeg(type) && typeof this.seg[type]["name"] != 'undefined') {
if (withAllele) {
return this.seg[type]["name"];
}else{
......@@ -534,7 +539,7 @@ Clone.prototype = {
},
getNlength: function () {
if (this.hasSeg() && typeof this.seg['3'] != 'undefined' && typeof this.seg['5'] != 'undefined'){
if (this.hasSeg('3', '5')){
return this.seg['3']['start']-this.seg['5']['stop']-1
}else{
return 'undefined'
......@@ -570,7 +575,7 @@ Clone.prototype = {
},
getPrintableSegSequence: function () {
if (! this.hasSeg() || typeof this.seg['5'] == 'undefined' || typeof this.seg['3'] == 'undefined') {
if (! this.hasSeg('3', '5')) {
return this.getSequence()
}
......@@ -706,8 +711,7 @@ Clone.prototype = {
}else if (this.m.colorMethod == "system") {
this.color = this.m.germlineList.getColor(this.germline)
} else if (this.m.colorMethod == 'productive') {
if (this.hasSeg()
&& typeof this.seg.junction != 'undefined'
if (this.hasSeg('junction')
&& typeof this.seg.junction.productive != 'undefined') {
this.color = colorProductivity(this.seg.junction.productive)
}
......
......@@ -710,7 +710,7 @@ Report.prototype = {
//colorized clone sequence
var sequence = $('<div/>', {'class': 'sequence'}).appendTo(clone);
if (typeof this.m.clone(cloneID).hasSeg()){
if (typeof this.m.clone(cloneID).hasSeg('5', '3')){
var seg = this.m.clone(cloneID).seg
var seq = this.m.clone(cloneID).getSequence()
var seqV = seq.substring(0, seg['5']['stop'] + 1)
......
......@@ -178,8 +178,7 @@ Germline.prototype = {
//and add undetected genes (missing from germline)
var g = {}
for (var i=0; i<this.m.clones.length; i++){
if (typeof this.m.clone(i).hasSeg() != "undefined" &&
typeof this.m.clone(i).seg[type2] != "undefined" &&
if (this.m.clone(i).hasSeg(type2) &&
typeof this.m.clone(i).seg[type2]["name"] != "undefined"
){
var gene=this.m.clone(i).seg[type2]["name"];
......
......@@ -716,7 +716,7 @@ Model_loader.prototype = {
var count = 0;
for (var i in this.clones){
if (typeof this.clones[i].hasSeg() && typeof this.clones[i].seg.quality != "undefined"){
if (this.clones[i].hasSeg('quality')){
var s = this.clones[i].seg.quality.seq;
for (var j in s){
if (s[j] != "!"){
......
......@@ -875,13 +875,11 @@ Segment.prototype = {
}
// In the .seg element, What looks like DNA sequence or what is a Pos field
if (clone.hasSeg()){
for (var i in clone.seg) {
if (forbidden_fields.indexOf(i) == -1 &&(this.isDNA(clone.seg[i]) || this.isPos(clone.seg[i])) ){
if (result.indexOf(i) == -1) result.push(i);
}
}
}
}
//Add external infos like IMGT's ... to selectbox values in a static way
......@@ -1046,7 +1044,7 @@ Sequence.prototype = {
var stop = -1;
var clone = this.m.clone(this.id);
if (clone.hasSeg() && typeof clone.seg["cdr3"] != "undefined"){
if (clone.hasSeg('cdr3')){
if (typeof clone.seg["cdr3"].start != "undefined") {
start = this.pos[clone.seg["cdr3"].start];
stop = this.pos[clone.seg["cdr3"].stop];
......@@ -1114,7 +1112,7 @@ Sequence.prototype = {
if (typeof clone.sequence != 'undefined' && clone.sequence != 0) {
//find V, D, J position
if (clone.hasSeg()){
if (clone.hasSeg('5', '3')){
var vdjArray = this.getVdjStartEnd(clone);
var vdjArrayRev = {};
......@@ -1141,8 +1139,8 @@ Sequence.prototype = {
}
var window_start = this.pos[clone.sequence.indexOf(clone.id)];
if (clone.hasSeg() && typeof clone.seg["cdr3"] != "undefined"){
if (clone.seg["cdr3"].start != "undefined"){
if (clone.hasSeg('cdr3')){
if (typeof clone.seg["cdr3"].start != "undefined"){
window_start = this.pos[clone.seg["cdr3"].start];
}else if (clone.seg["cdr3"].constructor === String){
window_start = this.pos[clone.sequence.indexOf(clone.seg["cdr3"])];
......@@ -1269,7 +1267,7 @@ Sequence.prototype = {
// Find the good object p
if (typeof clone[field] != 'undefined'){
p = clone[field]; //check clone meta-data
}else if (clone.hasSeg() && typeof clone.seg[field] != 'undefined'){
}else if (clone.hasSeg(field)){
p = clone.seg[field]; //check clone seg data
}else if (typeof this.m[field] != 'undefined'){
p = this.m[field]; //check model
......
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