Commit 89f8b580 authored by Mikaël Salson's avatar Mikaël Salson
Browse files

tools.js: correct positions coming from IMGT/V-QUEST

When having insertions, positions correspond to the *corrected* sequence
rather than the original one.
parent 87425100
......@@ -214,6 +214,7 @@ function imgtPostForSegmenter(data, system, override_imgt_options) {
m.clones[cloneIdx].seg.imgt = {}
m.clones[cloneIdx].seg.imgt2display = {}
}
correctIMGTPositionsForInsertions(imgtArray[i]);
append_to_object(imgtArray[i], m.clones[cloneIdx].seg.imgt);
append_to_object(computeStartStop(imgtArray[i],m.clones[cloneIdx].getSequence()),
m.clones[cloneIdx].seg.imgt2display);
......
......@@ -43,6 +43,48 @@ function tsvToArray(allText) {
return lines;
}
/**
* With insertions, IMGT positions must be understood with the insertions
* removed. As we display the original sequence and not the corrected one, we
* have to correct the positions so that they reflect the displayed sequence
* rather than the corrected one.
*/
function correctIMGTPositionsForInsertions(data) {
if (typeof data['V-REGION identity % (with ins/del events)'] != 'undefined'
&& data['V-REGION identity % (with ins/del events)'].length > 0
&& typeof data['V-REGION end'] != 'undefined') {
// Ok we may have insertions and we have positions.
// 1. Find position of insertions
var positions_of_insertion = []
// Insertions are capital letters in the sequence
var ins_regexp = /[A-Z]/g;
while ((match = ins_regexp.exec(data['Sequence'])) != null) {
positions_of_insertion.push(match.index + 1) // +1 to take into
// account positions
// starting at 1 for
// IMGT
}
if (positions_of_insertion.length == 0)
return;
// Shift all positions that are after insertions
for (var item in data) {
if (item.endsWith(' end') || item.endsWith(' start')) {
var seq_position = parseInt(data[item])
var after_insertions = 0;
var i = 0
while (after_insertions < positions_of_insertion.length
&& positions_of_insertion[after_insertions] <= seq_position + after_insertions)
after_insertions += 1
data[item] = (seq_position + after_insertions).toString()
}
}
}
}
/**
* extract information from htlm page
*
......
......@@ -58,6 +58,25 @@ asyncTest("processImgtContents", function () {
}
);
test("correctIMGTPositionsForInsertions", function() {
data = {
'V-REGION identity % (with ins/del events)': "98.2%",
"Sequence": "taggctagctagctaAgcgctaTcgcaTcagcagAagcagcat",
// "taggctagctagctagcgctacgcacagcagagcagcat",
"V-REGION end": "13",
"CDR1-IMGT start": "16", // 17 when accounting for insertion
"CDR1-IMGT end": "22", // 24 when accounting for insertion
"CDR2-IMGT start": "25", // 27 when accounting for insertion
"CDR2-IMGT end": "26" // 29 when accounting for insertion
}
correctIMGTPositionsForInsertions(data)
equal(data["V-REGION end"], "13", "V-REGION end should not change")
equal(data["CDR1-IMGT start"], "17", "CDR1-IMGT should be 17 ("+data["CDR1-IMGT start"]+")")
equal(data["CDR1-IMGT end"], "24", "CDR1-IMGT should be 24 ("+data["CDR1-IMGT end"]+")")
equal(data["CDR2-IMGT start"], "27", "CDR2-IMGT should be 27 ("+data["CDR2-IMGT start"]+")")
equal(data["CDR2-IMGT end"], "29", "CDR2-IMGT should be 29 ("+data["CDR2-IMGT end"]+")")
});
test("computeStartStop(arrayToProcess,sequence)", function () {
var imgt2displayCheck = {
......
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