Commit 6cdc15a2 authored by flothoni's avatar flothoni Committed by Mathieu Giraud

clone.js and test; remove function computeSegFeatureFromSeq

This function is now include inside another function: addSegFeatureFromSeq
Update tests
parent 17d444a3
......@@ -252,6 +252,7 @@ Clone.prototype = {
*/
addSegFeatureFromSeq: function(field_name, sequence, extend)
{
// Does feature and position exist in clone ?
positions = this.getSegStartStop(field_name)
if (positions !== null){
......@@ -259,41 +260,46 @@ Clone.prototype = {
return ;
}
var pos = this.sequence.indexOf(sequence)
if (pos != -1) { // perfect match exist
this.seg[field_name] = {};
this.seg[field_name].seq = sequence;
this.seg[field_name].start = pos
this.seg[field_name].stop = pos + sequence.length -1
} else if (extend == true || extend == undefined) {
// No perfect match; try extension with germline sequence
var genes = [5, 3]
for (var g = 0; g < genes.length; g++) {
var gene_way = genes[g]
if (field_name.indexOf(gene_way.toString()) != -1){ // Warning; need to clarify rule for feature naming
germseq = this.getExtendedSequence(gene_way)
if (germseq != undefined){
var rst = bsa_align(true, germseq, sequence, [1, -2], [-2, -1]) // return [score, start pos, ~cigar]
var germpos = rst[1]
if (rst[0] > (sequence.length/2) ){
if (gene_way == 5){
computed_pos = this.seg["5"].stop + germpos - germseq.length - this.seg["5"].delRight //-sequence.length // start n'existe pas si extention; (this.seg["5"].start != undefined ? this.seg["5"].start : 0)
console.log( "(5) computed_pos = germpos; germseq.length; sequence.length; this.seg['5'].delRight; this.seg['5'].stop; (this.seg['5'].start != undefined ? this.seg['5'].start : 0)")
console.log( computed_pos+" = "+germpos+"; "+germseq.length+"; "+sequence.length+"; "+this.seg["5"].delRight+"; "+this.seg["5"].stop+"; "+(this.seg["5"].start != undefined ? this.seg["5"].start : 0))
} else if (gene_way == 3){
computed_pos = germpos + this.seg["3"].start - this.seg["3"].delLeft
console.log( "(3) computed_pos = germpos + this.seg['3'].start - this.seg['3'].delLeft")
console.log( computed_pos+" = "+germpos+" + "+this.seg["3"].start+" - "+this.seg["3"].delLeft)
if (sequence == undefined && this.seg[field_name] != undefined && this.seg[field_name].seq != undefined){
// try to get sequence from existing feature in the clone
sequence = this.seg[field_name].seq
}
if (sequence != undefined){
// Insert sequence and positions if possible
var pos = this.sequence.indexOf(sequence)
if (pos != -1) {
// perfect match exist
this.seg[field_name] = {};
this.seg[field_name].seq = sequence;
this.seg[field_name].start = pos
this.seg[field_name].stop = pos + sequence.length -1
} else if (extend == true || extend == undefined) {
// No perfect match; try extension with germline sequence
// Warning; predictive approach can't be perfect
var genes = [5, 3]
for (var g = 0; g < genes.length; g++) {
var gene_way = genes[g]
if (field_name.indexOf(gene_way.toString()) != -1){ // Warning; need to clarify rule for feature naming
germseq = this.getExtendedSequence(gene_way)
if (germseq != undefined){
var rst = bsa_align(true, germseq, sequence, [1, -2], [-2, -1]) // return [score, start pos, ~cigar]
var germpos = rst[1]
if (rst[0] > (sequence.length/2) ){
if (gene_way == 5){
computed_pos = this.seg["5"].stop + germpos - germseq.length - this.seg["5"].delRight //-sequence.length // start n'existe pas si extention; (this.seg["5"].start != undefined ? this.seg["5"].start : 0)
} else if (gene_way == 3){
computed_pos = germpos + this.seg["3"].start - this.seg["3"].delLeft
}
this.seg[field_name] = {};
this.seg[field_name].seq = sequence;
this.seg[field_name].start = computed_pos
this.seg[field_name].stop = computed_pos + sequence.length -1
break
}
this.seg[field_name] = {};
this.seg[field_name].seq = sequence;
this.seg[field_name].start = computed_pos
this.seg[field_name].stop = computed_pos + sequence.length -1
break
}
}
}
}
}
}
......@@ -320,32 +326,6 @@ Clone.prototype = {
},
/**
* Compute feature positions (start/stop) from its sequence, unless they are already present
* Computed positions are converted to start from 0 and can be used without manipualtions
*/
computeSegFeatureFromSeq: function(field_name)
{
positions = this.getSegStartStop(field_name)
if (positions !== null)
// Start/stop do already exist
return ;
seq = this.seg[field_name].seq
var pos = this.sequence.indexOf(seq)
if (pos < 0)
// No feature here
return;
this.seg[field_name].start = pos
this.seg[field_name].stop = pos + seq.length -1
},
/**
* Return the best matching sequence from a list of sequence
* Can be used to find the best matching primer from a list of primers
......
......@@ -412,19 +412,6 @@ QUnit.test('clone: get info from seg', function(assert) {
assert.equal(c2.getDeletion('5', 'delRight'), 18, 'return length of the deletion for c2')
});
QUnit.test("clone : feature defined by a nucleotide sequence", function(assert) {
var m = new Model()
m.parseJsonData(json_data)
var c1 = new Clone(json_clone1, m, 0, c_attributes)
var c2 = new Clone(json_clone2, m, 1, c_attributes)
var c3 = new Clone(json_clone3, m, 2, c_attributes)
m.initClones()
assert.deepEqual(c3.getSegStartStop('somefeature'), null, "start/stop positions are not present")
c3.computeSegFeatureFromSeq('somefeature')
assert.deepEqual(c3.getSegStartStop('somefeature'), {"start": 6, "stop": 12}, "start/stop positions, computed from sequence")
assert.equal(c3.getSegLength('somefeature'), 7, "length of the feature");
});
QUnit.test("getSequence/RevComp", function(assert) {
var m = new Model();
......@@ -737,8 +724,22 @@ QUnit.test("clonedb", function(assert) {
});
QUnit.test("primer detection align", function(assert) {
QUnit.test("clone : feature defined by a nucleotide sequence", function(assert) {
// Test with sequence already in a feature inside clone
var m = new Model()
m.parseJsonData(json_data)
var c1 = new Clone(json_clone1, m, 0, c_attributes)
var c2 = new Clone(json_clone2, m, 1, c_attributes)
var c3 = new Clone(json_clone3, m, 2, c_attributes)
m.initClones()
assert.deepEqual(c3.getSegStartStop('somefeature'), null, "start/stop positions are not present")
c3.addSegFeatureFromSeq('somefeature')
assert.deepEqual(c3.getSegStartStop('somefeature'), {"start": 6, "stop": 12}, "start/stop positions, computed from sequence")
assert.equal(c3.getSegLength('somefeature'), 7, "length of the feature");
// Test with given sequence for new feature
var m = new Model();
m.parseJsonData(json_data, 100);
m.populatePrimerSet()
......
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