Commit 167f0a25 authored by flothoni's avatar flothoni Committed by Mathieu Giraud

clone.js and test; fix '+1' error in primers search

Also update tests on it
parent f5f8f3bc
......@@ -255,16 +255,17 @@ Clone.prototype = {
// Does feature and position exist in clone ?
positions = this.getSegStartStop(field_name)
// Start/stop do already exist
if (positions !== null){
// Start/stop do already exist
return ;
}
// try to get sequence from existing feature in the clone if not given
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)
......@@ -274,6 +275,7 @@ Clone.prototype = {
this.seg[field_name].seq = sequence;
this.seg[field_name].start = pos +1 // seq is 1-based
this.seg[field_name].stop = pos + sequence.length
return
} else if (extend == true || extend == undefined) {
// No perfect match; try extension with germline sequence
// Warning; predictive approach can't be perfect
......@@ -285,20 +287,17 @@ Clone.prototype = {
if (germseq != undefined){
var rst = bsa_align(true, germseq, sequence, [1, -2], [-2, -1]) // return [score, start pos, ~cigar]
var germpos = rst[1] // -1 to be 0-based
if (rst[0] > (sequence.length/2) ){
var nb_match = bsa_cigar2match(rst[2]) // Get number of match
if (nb_match > (sequence.length/2) ){
if (gene_way == 5){
computed_pos = this.seg["5"].stop + germpos - germseq.length //-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))
computed_pos = this.seg["5"].stop + germpos - germseq.length + this.seg["5"].delRight
} else if (gene_way == 3){
computed_pos = this.seg["3"].start + (germpos - this.seg["3"].delLeft)
console.log( "computed_pos = this.seg[3].start; germpos; this.seg[3].delLeft; sequence.length")
console.log( computed_pos+" = "+this.seg["3"].start+"; "+germpos+"; "+this.seg["3"].delLeft+"; "+sequence.length)
computed_pos = this.seg["3"].start - this.seg["3"].delLeft + germpos -1
}
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
this.seg[field_name].start = computed_pos + 1
this.seg[field_name].stop = computed_pos + sequence.length// + end_adding
break
}
}
......@@ -366,8 +365,9 @@ Clone.prototype = {
if (germseq != undefined){
for (seq_pos = 0; seq_pos < sequences.length; seq_pos++) {
sequence = sequences[seq_pos]
var rst = bsa_align(true, germseq, sequence, [1, -2], [-2, -1])
if (rst[0] > best_score){
rst = bsa_align(true, germseq, sequence, [1, -2], [-2, -1])
var nb_match = bsa_cigar2match(rst[2])
if (rst[0] > best_score && nb_match > (sequence.length/2) ){
best_seq = [sequence]
best_rst = [rst]
best_score = rst[0]
......@@ -404,7 +404,7 @@ Clone.prototype = {
positions = this.getSegStartStop(field_name)
if (positions !== null) {
// return this.sequence.substr(positions.start-1, (positions.stop+1) - positions.start)
return this.sequence.substr(positions.start-1, (positions.stop - positions.start-1))
return this.sequence.substr(positions.start-1, this.getSegLength(field_name))
}
return '';
},
......@@ -434,7 +434,7 @@ Clone.prototype = {
var positions2 = this.getSegStartStop(field_name2)
if (positions1 !== null && positions2 !== null) {
return positions2.stop - (positions1.start - 1)
return positions2.stop - positions1.start + 1
} else {
return 'undefined';
}
......
......@@ -738,12 +738,17 @@ QUnit.test("clone : feature defined by a nucleotide sequence", function(assert)
assert.equal(c3.getSegLength('somefeature'), 7, "length of the feature");
assert.equal(c3.getSegNtSequence('somefeature'), "aaaattt" , "Seq of the feature");
// Test with given sequence for new feature
var m = new Model();
m.parseJsonData(json_data, 100);
m.populatePrimerSet()
m.germline.IGH = {
"IGH5seg":"ACTGAAGTCATTGGAAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAATTTTTAAAAA",
"IGH4seg":"gtgtgtgtgtgtgtgtgtgt",
"IGH3seg":"GGGGGCCCCCGGGGGCCCCCGGGGGCTATCATATGCATACGGGGGCCCCC"
}
// Clone with seg start and stop position
var clone8 = {
"germline": "IGH",
......@@ -753,88 +758,85 @@ QUnit.test("clone : feature defined by a nucleotide sequence", function(assert)
"seg": {
"3": {
"delLeft": 0,
"name": "IGHJ1*01",
"start": 297
"name": "IGH3seg",
"start": -1
},
"5": {
"delRight": 0,
"name": "IGHV1-2*01",
"stop": 296,
"name": "IGH5seg",
"stop": -1,
"start": 0
}
},
"sequence": "init",
}
var clone = new Clone(clone8, m, 0, c_attributes);
m.initClones();
primer5_ecngs_igh = m.primersSetData.ecngs.IGH.primer5
primer3_ecngs_igh = m.primersSetData.ecngs.IGH.primer3
primer3_biomed_igh = m.primersSetData.biomed2.IGH.primer5
primer3_biomed_igh = m.primersSetData.biomed2.IGH.primer3
primer5_ecngs_trd = m.primersSetData.ecngs.TRD.primer5
primer3_ecngs_trd = m.primersSetData.ecngs.TRD.primer3
primer5_fictif = ["ACTGAAGTCATTGGA", "ttggttggtgttggttggtgttggttggtgttggttggtg","aaccaaccaaaaccaaccaaaaccaaccaaaaccaaccaa","atgcggatgcatgcggatgcatgcggatgcatgcggatgc"]
primer3_fictif = ["CTATCATATGCATAT", "ttaattaatattaattaatattaattaatattaattaata","aaccaaccaaaaccaaccaaaaccaaccaaaaccaaccaa"]
//"IGHV1-2*01 // IGHJ1*01",
// var igh_V1_2_J1_full
clone.sequence = "CAGGTGCAGCTGGTGCAGTCTGGGGCTGAGGTGAAGAAGCCTGGGGCCTCAGTGAAGGTCTCCTGCAAGGCTTCTGGATACACCTTCACCGGCTACTATATGCACTGGGTGCGACAGGCCCCTGGACAAGGGCTTGAGTGGATGGGACGGATCAACCCTAACAGTGGTGGCACAAACTATGCACAGAAGTTTCAGGGCAGGGTCACCAGTACCAGGGACACGTCCATCAGCACAGCCTACATGGAGCTGAGCAGGCTGAGATCTGACGACACGGTCGTGTATTACTGTGCGAGAGAGCTGAATACTTCCAGCACTGGGGCCAGGGCACCCTGGTCACCGTCTCCTCAG"
assert.deepEqual( clone.getBestMatchingSequence(primer5_ecngs_igh, false), ["CTGGGTGCGACAGGCCCCT", false], "seq full; primer5, no extend" )
assert.deepEqual( clone.getBestMatchingSequence(primer5_ecngs_igh, [5]), ["CTGGGTGCGACAGGCCCCT", false], "seq full; primer5, extend 5" )
clone.sequence = m.germline.IGH.IGH5seg + m.germline.IGH.IGH3seg
clone.seg[5].stop = 100
clone.seg[3].start = 101
assert.deepEqual( clone.getBestMatchingSequence(primer5_fictif, false), [primer5_fictif[0], false], "seq full; BestMatching; primer5, no extend" )
assert.deepEqual( clone.getBestMatchingSequence(primer5_fictif, [5]), [primer5_fictif[0], false], "seq full; BestMatching; primer5, extend 5" )
// not full match, but if extend, have bas_align call
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, []), [undefined, false],"seq full; primer3, no extend")
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, [5]), ["GGTCACCGTCTCCTCAGGTAAG", true],"seq full; primer3, extend 5" )
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, [3]), ["GGTCACCGTCTCCTCAGGTAAG", true],"seq full; primer3, extend 3" )
clone.addSegFeatureFromSeq("primer5", "CTGGGTGCGACAGGCCCCT", true)
clone.addSegFeatureFromSeq("primer3", "GGTCACCGTCTCCTCAGGTAAG", true)
assert.deepEqual( clone.seg["primer5"], {"seq":"CTGGGTGCGACAGGCCCCT", "start":105, "stop":123}, "Primer5 value")
assert.deepEqual( clone.seg["primer3"], {"seq":"GGTCACCGTCTCCTCAGGTAAG", "start":331, "stop":353}, "Primer3 value")
console.log( clone.seg )
assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 249, "Correct length for genescan ecngs" ) // ~245
delete clone.seg["primer5"]
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, []), [undefined, false],"seq full; BestMatching; primer3, no extend")
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, [5]), [undefined, false],"seq full; BestMatching; primer3, extend 5" )
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, [3]), [primer3_fictif[0], true],"seq full; BestMatching; primer3, extend 3" )
clone.addSegFeatureFromSeq("primer5", primer5_fictif[0], true)
clone.addSegFeatureFromSeq("primer3", primer3_fictif[0], true)
assert.deepEqual( clone.seg["primer5"], {"seq":primer5_fictif[0], "start":1, "stop":15}, "addSegFeatureFromSeq; Primer5 value")
assert.deepEqual( clone.seg["primer3"], {"seq":primer3_fictif[0], "start":126, "stop":140}, "addSegFeatureFromSeq; Primer3 value")
assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 140, "Correct length for genescan ecngs" ) // ~245
delete clone.seg["primer5"] // delete for next addSegFeatureFromSeq call
delete clone.seg["primer3"]
// Sequence with 5' and 3' deletion
clone.seg[5].stop = 176
clone.seg[3].start = 177
clone.sequence = "CCTGGACAAGGGCTTGAGTGGATGGGACGGATCAACCCTAACAGTGGTGGCACAAACTATGCACAGAAGTTTCAGGGCAGGGTCACCAGTACCAGGGACACGTCCATCAGCACAGCCTACATGGAGCTGAGCAGGCTGAGATCTGACGACACGGTCGTGTATTACTGTGCGAGAGAGCTGAATACTTCCAGCACTGGGGC"
assert.deepEqual( clone.getBestMatchingSequence(primer5_ecngs_igh, false), [undefined, false], "seq short; primer5, no extend" )
assert.deepEqual( clone.getBestMatchingSequence(primer5_ecngs_igh, [5]), ["CTGGGTGCGACAGGCCCCT", true], "seq short; primer5, extend 5" )
clone.sequence = m.germline.IGH.IGH5seg.substr(20, 80) + m.germline.IGH.IGH3seg.substr(0, 25)
clone.seg[5].stop = 80
clone.seg[3].start = 81
assert.deepEqual( clone.getBestMatchingSequence(primer5_fictif, false), [undefined, false], "seq short; primer5, no extend" )
assert.deepEqual( clone.getBestMatchingSequence(primer5_fictif, [5]), [primer5_fictif[0], true], "seq short; primer5, extend 5" )
// not full match, but if extend, have bas_align call
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, []), [undefined, false], "seq short; primer3, no extend")
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, [5]), ["GGTCACCGTCTCCTCAGGTAAG", true], "seq short; primer3, extend 5" )
assert.deepEqual( clone.getBestMatchingSequence(primer3_ecngs_igh, [3]), ["GGTCACCGTCTCCTCAGGTAAG", true], "seq short; primer3, extend 3" )
clone.addSegFeatureFromSeq("primer5", "CTGGGTGCGACAGGCCCCT", true)
clone.addSegFeatureFromSeq("primer3", "GGTCACCGTCTCCTCAGGTAAG", true)
assert.deepEqual( clone.seg["primer5"], {"seq":"CTGGGTGCGACAGGCCCCT", "start":-16, "stop":3}, "seq short; Primer5 value")
assert.deepEqual( clone.seg["primer3"], {"seq":"GGTCACCGTCTCCTCAGGTAAG", "start":212, "stop":234}, "seq short; Primer3 value")
console.log( clone.seg )
assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 249, "seq short; Correct length for genescan ecngs" ) // ~245
// delete clone.seg["primer5"]
// delete clone.seg["primer3"]
// // Sequence with 5'(-10) and 3'(-5) deletion, and D insertion (20nt)
// clone.seg[5].stop = 166
// clone.seg[3].start = 187
// clone.seg[3].delRight = 10
// clone.seg[3].delLeft = 5
// clone.seg[4] = {"delLeft": 2, "delRight": 0, "name": "IGHD1-26*01", "start": 169, "stop": 186 }
// clone.sequence = "CCTGGACAAGGGCTTGAGTGGATGGGACGGATCAACCCTAACAGTGGTGGCACAAACTATGCACAGAAGTTTCAGGGCAGGGTCACCAGTACCAGGGACACGTCCATCAGCACAGCCTACATGGAGCTGAGCAGGCTGAGATCTGACGACACGGTCGTGTATTACTggtatagtgggagctactacGCTGAATACTTCCAGCACTGGGGC"
// clone.addSegFeatureFromSeq("primer5", "CTGGGTGCGACAGGCCCCT", true)
// clone.addSegFeatureFromSeq("primer3", "GGTCACCGTCTCCTCAGGTAAG", true)
// assert.deepEqual( clone.seg["primer5"], {"seq":"CTGGGTGCGACAGGCCCCT", "start":-16, "stop":2}, "Seq with D; Primer5 value")
// assert.deepEqual( clone.seg["primer3"], {"seq":"GGTCACCGTCTCCTCAGGTAAG", "start":221, "stop":243}, "Seq with D; Primer3 value")
// console.log( clone.seg )
// assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 258, "Seq with D; Correct length for genescan ecngs" ) // ~245
// // delete clone.seg["primer5"]
// // delete clone.seg["primer3"]
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, []), [undefined, false], "seq short; primer3, no extend")
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, [5]), [undefined, false], "seq short; primer3, extend 5" )
assert.deepEqual( clone.getBestMatchingSequence(primer3_fictif, [3]), [primer3_fictif[0], true], "seq short; primer3, extend 3" )
clone.addSegFeatureFromSeq("primer5", primer5_fictif[0], true)
clone.addSegFeatureFromSeq("primer3", primer3_fictif[0], true)
assert.deepEqual( clone.seg["primer5"], {"seq":primer5_fictif[0], "start":-19, "stop":-5}, "addSegFeatureFromSeq; Primer5 value")
assert.deepEqual( clone.seg["primer3"], {"seq":primer3_fictif[0], "start":106, "stop":120}, "addSegFeatureFromSeq; Primer3 value")
assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 140, "Correct length for genescan ecngs" )
delete clone.seg["primer5"]
delete clone.seg["primer3"]
// Sequence with 5'(-10) and 3'(-5) deletion, and D insertion (20nt)
clone.sequence = m.germline.IGH.IGH5seg.substr(20, 70) + m.germline.IGH.IGH4seg + m.germline.IGH.IGH3seg.substr(5, 25)
clone.seg[5].stop = 70
clone.seg[3].start = 91
clone.seg[5].delRight = 10
clone.seg[3].delLeft = 5
clone.seg[4] = {"delLeft": 0, "delRight": 0, "name": "IGH4seg", "start": 71, "stop": 90 }
clone.addSegFeatureFromSeq("primer5", primer5_fictif[0], true)
clone.addSegFeatureFromSeq("primer3", primer3_fictif[0], true)
assert.deepEqual( clone.seg["primer5"], {"seq":primer5_fictif[0], "start":-19, "stop":-5}, "Seq with D; Primer5 value")
assert.deepEqual( clone.seg["primer3"], {"seq":primer3_fictif[0], "start":111, "stop":125}, "Seq with D; Primer3 value")
assert.equal( clone.getSegLengthDoubleFeature('primer5', 'primer3'), 145, "Seq with D; Correct length for genescan ecngs (-10+20-5)" ) // ~245
delete clone.seg["primer5"]
delete clone.seg["primer3"]
});
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