Commit 850c746b authored by Alexia Omietanski's avatar Alexia Omietanski Committed by Mikaël Salson

browser,tools: Add percentages in CloneDB results

Fixes #2929
parent 5a3a67b0
......@@ -740,7 +740,20 @@ Report.prototype = {
} else {
$('<span/>', {'text': 'segment fail'}).appendTo(sequence);
}
//CloneDB results
if (typeof this.m.clones[cloneID].seg.clonedb != 'undefined'){
var clonedbContent = $('<div/>', {'class': 'cloneDB'}).appendTo(clone);
var table = $('<table/>', {'class': 'info-table'}).appendTo(clonedbContent);
var result = this.m.clones[cloneID].seg.clonedb.clones_names;
var j = 0;
for (var c in result){
var row = $('<tr/>').appendTo(table);
$('<td/>', {'class': 'label', 'text': result[j]}).appendTo(row);
$('<td/>', {'text': result[c][0] +' clone'+((result[c][0] === 1) ? '' : 's') + ' (' + this.m.formatSize(result[c][1],true,this.m.getSizeThresholdQ(this.m.t)) + ')'}).appendTo(row);
j++;
}
}
return clone
},
......
......@@ -130,9 +130,10 @@ function prepend_path_if_not_web(file, path) {
* An additional key (termed 'original') corresponds to the original
* results as returned by CloneDB.
*/
function processCloneDBContents(results) {
function processCloneDBContents(results,model) {
var existing_urls = {};
var final_results = {};
var clones_results = {};
var count_non_viewable = 0;
for (var clone in results) {
if (typeof results[clone].tags != 'undefined' &&
......@@ -150,13 +151,17 @@ function processCloneDBContents(results) {
config_name = config_name[0];
else
config_name = 'unknown';
url = '?sample_set_id='+results[clone].tags.sample_set[i]+'&config='+results[clone].tags.config_id[0];
var url = '?sample_set_id='+results[clone].tags.sample_set[i]+'&config='+results[clone].tags.config_id[0];
var msg = '<a href="'+url+'">'+name+'</a> ('+config_name+')';
if (! (url in existing_urls)) {
clones_results[name] = [results[clone].occ,parseFloat(results[clone].tags.percentage[0])];
existing_urls[url] = true;
final_results[msg] = results[clone].occ;
final_results[msg] = [results[clone].occ,parseFloat(results[clone].tags.percentage[0])];
} else{
final_results[msg] += results[clone].occ;
final_results[msg][0] += results[clone].occ;
clones_results[name][0] += results[clone].occ;
final_results[msg][1] += parseFloat(results[clone].tags.percentage[0]);
clones_results[name][1] += parseFloat(results[clone].tags.percentage[0]);
}
} else {
......@@ -168,7 +173,7 @@ function processCloneDBContents(results) {
}
}
for (var fr in final_results) {
final_results[fr] = final_results[fr]+' clone'+((final_results[fr] === 1) ? '' : 's');
final_results[fr] = final_results[fr][0]+' clone'+((final_results[fr][0] === 1) ? '' : 's') + ' (' + model.formatSize(final_results[fr][1],true,model.getSizeThresholdQ(model.t)) + ')';
}
if (count_non_viewable > 0)
final_results['Non viewable samples'] = count_non_viewable;
......@@ -177,6 +182,7 @@ function processCloneDBContents(results) {
final_results[''] = "No occurrence of this clone in CloneDB"
final_results.original = results;
final_results.clones_names = clones_results;
return final_results;
}
......
......@@ -62,7 +62,11 @@ QUnit.test("prepend_path_if_not_web", function(assert) {
QUnit.test("processCloneDBContents", function(assert) {
var emptyResult = [];
assert.deepEqual(processCloneDBContents(emptyResult), {'original': [],
var m = new Model();
m.parseJsonData(json_data, 100);
assert.deepEqual(processCloneDBContents(emptyResult, m), {'original': [],
'clones_names': {},
'': 'No occurrence of this clone in CloneDB'},
"processing empty result");
......@@ -71,13 +75,19 @@ QUnit.test("processCloneDBContents", function(assert) {
'sample_set': ["15", "152"],
'config_id': ['1024'],
'config_name': ['config'],
'sample_name': ['toto']},
'sample_name': ['toto'],
'percentage' : [.1242]
},
'occ': 3,
'V' : 'IGHV1*02',
'J' : 'IGHJ3*01'}];
assert.deepEqual(processCloneDBContents(singleResult),
{'<a href="?sample_set_id=15&config=1024">patient</a> (config)': "3 clones",
'<a href="?sample_set_id=152&config=1024">152</a> (config)': "3 clones",
assert.deepEqual(processCloneDBContents(singleResult, m),
{'<a href="?sample_set_id=15&config=1024">patient</a> (config)': "3 clones (12.42%)",
'<a href="?sample_set_id=152&config=1024">152</a> (config)': "3 clones (12.42%)",
'clones_names': {
'152' : [3, .1242],
'patient' : [3, .1242]
},
'original': singleResult}, "processing one result");
var multipleResults = [{'tags': {'sample_set_viewable': [true, true],
......@@ -85,6 +95,7 @@ QUnit.test("processCloneDBContents", function(assert) {
'sample_set': ["15", "152"],
'config_id': ['1024'],
'config_name': ['config'],
'percentage': [.15],
'sample_name': ['toto']},
'occ': 3,
'V' : 'IGHV1*02',
......@@ -95,6 +106,7 @@ QUnit.test("processCloneDBContents", function(assert) {
'sample_set': ["152"],
'config_id': ['1024'],
'config_name': ['config'],
'percentage': [.1],
'sample_name': ['toto']},
'occ': 2,
'V' : 'IGHV1*01',
......@@ -105,19 +117,20 @@ QUnit.test("processCloneDBContents", function(assert) {
'sample_set': ["666"],
'config_id': ['10'],
'config_name': ['[old] config'],
'percentage': [.05],
'sample_name': ['toto']},
'occ': 100,
'V' : 'IGHV1*02',
'J' : 'IGHJ3*01'}];
var results = processCloneDBContents(multipleResults);
assert.equal(results['<a href="?sample_set_id=152&config=1024">152</a> (config)'], '5 clones', "multiple results");
assert.equal(results['<a href="?sample_set_id=15&config=1024">patient</a> (config)'], '3 clones', "multiple results, one entry");
var results = processCloneDBContents(multipleResults, m);
assert.equal(results['<a href="?sample_set_id=152&config=1024">152</a> (config)'], '5 clones (25.00%)', "multiple results");
assert.equal(results['<a href="?sample_set_id=15&config=1024">patient</a> (config)'], '3 clones (15.00%)', "multiple results, one entry");
assert.equal(results['Non viewable samples'], 1, "One non viewable sample");
var count = 0;
for (var item in results) {
count += 1;
}
assert.equal(count, 4, "Two results plus one non-viewable plus original entry");
assert.equal(count, 5, "Two results plus one non-viewable plus original entry plus clone names");
// Test missing viewable property
var missingViewable = [{'tags': {'sample_set_name': ['patient', null],
......@@ -128,7 +141,11 @@ QUnit.test("processCloneDBContents", function(assert) {
'occ': 3,
'V' : 'IGHV1*02',
'J' : 'IGHJ3*01'}];
assert.deepEqual(processCloneDBContents(missingViewable), {'Non viewable samples': 1, 'original': missingViewable},
assert.deepEqual(processCloneDBContents(missingViewable, m),
{'Non viewable samples': 1,
'original': missingViewable,
'clones_names' : {} // Empty as the sample can't be viewed
},
"processing missingViewable");
});
......
......@@ -6,3 +6,5 @@ $ 19 sequences with a seg field should be found
$ Affectation for sequence YYGGGYYACGYAYAGCGGYGYTTYYCCTYTYTGYTYTGCYAAAYAACYYYYTGTGYCTYTGTGCYGYGTTYCCCGGYYYAAACYCYCYYCCTYGGCYAGGYCYGGCTTTTGGYAYYGYYTYYAATGTYCYYCCC
1:VDJ 1 95 100 105 107 134
$ Percentage for sequence GGAGTCGGGGGAGGCTTGGTACAGCCTGGCAGGTCCCTGAGACTCTCCTGTGCAGCCTCTGGATTCACCTTTGATGATTATGCCATGCACTGGGTCCGGCAAGCTCCAGGGAAGGGCCTGGAGTGGGTCTCAGGTATTAGTTGGAATAGTGGTAGCATAGGCTATGCGGACTCTGTGAAGGGCCGATTCACCATCTCCAGAGACAACGCCAAGAACTCCCTGTATCTGCAAATGAACAGTCTGAGAGCTGAGGACACGGCCTTGTATTACTGTGCACCCGGAGGTATGGACGTCTGGGGCCAAGGGACCCTGGTCACC
1:IGHV3-9.01 7/CCCGGA/17 IGHJ6.02 .* percentage=0.304534313725
......@@ -184,6 +184,7 @@ def write_fuse_to_fasta(data, outfile, used_names, current_filename, options, me
used so far as well as their number of occurrences (prevents
having sequences with the same name)
'''
clones_percentage = {}
if options.top < MAX_TOP:
data.filter(data.getTop(options.top))
......@@ -207,6 +208,17 @@ def write_fuse_to_fasta(data, outfile, used_names, current_filename, options, me
else:
name += clone.d['name'].replace(' ', spacer)
additional_header_info = []
#Percentage
#take the max reads number of the samples (in case of multiple
#samples)
max_sample = max(clone.d['reads'])
#take the index corresponding to the max_sample
index_max_sample = clone.d['reads'].index(max_sample)
germline = clone.d['germline']
reads_total_nb = data.d['reads'].d['germline'][germline][index_max_sample]
percentage = float(max_sample)/reads_total_nb
if name in used_names:
used_names[name] += 1
additional_header_info.append(str(used_names[name]))
......@@ -221,6 +233,8 @@ def write_fuse_to_fasta(data, outfile, used_names, current_filename, options, me
sample_name = current_filename
additional_header_info.append('sample_name=%s' % sample_name)
additional_header_info.append('percentage=%s'%percentage)
if len(metadata) > 0:
additional_header_info.append(metadata.replace(' ', spacer))
......
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