Skip to content

Commit

Permalink
Merge pull request #33 from cmbi/local_variables_as_var_in_the_js_code
Browse files Browse the repository at this point in the history
Local variables as var in the js code.

Closes #30.
  • Loading branch information
cbaakman authored Sep 10, 2018
2 parents a011b2b + 77f6a70 commit b5397e8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
36 changes: 18 additions & 18 deletions metadome/presentation/web/static/js/dashboard/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Global variables for landscape
******************************************************************************/
var selected_positions = 0;
var meta_domain_ids = new Set();

var main_outerWidth = 1300;
var main_outerHeight = 500;
Expand Down Expand Up @@ -156,14 +157,14 @@ var positionTip = d3.tip()
.attr('class', 'd3-tip')
.offset([ -10, 0 ])
.html(function(d, i) {
positionTip_str = "<span>";
var positionTip_str = "<span>";
positionTip_str += "Position: p." + d.values[0].protein_pos + " " + d.values[0].cdna_pos + "</br>";
positionTip_str += "Codon: " + d.values[0].ref_codon + "</br>";
positionTip_str += "Residue: " + d.values[0].ref_aa_triplet;
if (d.values[0].domains.length > 0){
positionTip_str += "</br> In domain(s): ";
var n_domains_at_position = d.values[0].domains.length;
for (i = 0; i < n_domains_at_position; i++){
for (var i = 0; i < n_domains_at_position; i++){
if (i+1 == n_domains_at_position){
positionTip_str+= d.values[0].domains[i].ID;
}else{
Expand All @@ -183,13 +184,13 @@ var positionTip = d3.tip()
function resetGraph(){
// reset the variables
selected_positions = 0;
meta_domain_ids = new Set();

$("#selected_positions_information").addClass('is-hidden');
document.getElementById("selected_positions_explanation").innerHTML = 'Click on one of positions in the schematic protein to obtain more information';
$("#position_information_table").addClass('is-hidden');
d3.selectAll('.tr').remove();

selected_positions = 0;

// reset the svg
main_svg.selectAll("*").remove();
main_svg = d3.select("#landscape_svg");
Expand Down Expand Up @@ -248,7 +249,7 @@ function createGraph(obj) {

// create an overview of coverage per domain ID
var domain_metadomain_coverage = {}
for (i = 0; i < domain_data.length; i++) {
for (var i = 0; i < domain_data.length; i++) {
domain_metadomain_coverage[domain_data[i].ID] = domain_data[i].meta_domain_alignment_depth;
}

Expand All @@ -270,8 +271,7 @@ function createGraph(obj) {

function drawMetaDomainLandscape(domain_data, data){
// get all possible domain ids
meta_domain_ids = new Set();
for (i = 0; i < domain_data.length; i++){
for (var i = 0; i < domain_data.length; i++){
if (domain_data[i].metadomain){
meta_domain_ids.add(domain_data[i].ID);
}
Expand All @@ -281,7 +281,7 @@ function drawMetaDomainLandscape(domain_data, data){
var global_max_normal = 0;
var global_max_pathogenic = 0;
var global_max_value = 0;
for (i = 0; i < data.length; i++){
for (var i = 0; i < data.length; i++){
meta_domain_ids.forEach(domain_id => {
if (data[i].values[0].hasOwnProperty('domains') && data[i].values[0].domains[domain_id] != null){
global_max_normal = Math.max(data[i].values[0].domains[domain_id].normal_missense_variant_count, global_max_normal);
Expand Down Expand Up @@ -316,7 +316,7 @@ function drawMetaDomainLandscape(domain_data, data){
.attr("class", "normal_missense_variant_count")
.attr("x", function(d) { return main_x(d.values[0].protein_pos - 0.5); })
.attr("y", function(d) {
normal_missense_variant_count = 0;
var normal_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand All @@ -335,7 +335,7 @@ function drawMetaDomainLandscape(domain_data, data){
}
})
.attr("height", function(d) {
normal_missense_variant_count = 0;
var normal_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand All @@ -350,7 +350,7 @@ function drawMetaDomainLandscape(domain_data, data){
.style("fill", "green")
.on("mouseover", function(d) {
if (metadomain_graph_visible){
normal_missense_variant_count = 0;
var normal_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand Down Expand Up @@ -383,7 +383,7 @@ function drawMetaDomainLandscape(domain_data, data){
.attr("class", "pathogenic_missense_variant_count")
.attr("x", function(d) { return main_x(d.values[0].protein_pos); })
.attr("y", function(d) {
pathogenic_missense_variant_count = 0;
var pathogenic_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand All @@ -402,7 +402,7 @@ function drawMetaDomainLandscape(domain_data, data){
}
})
.attr("height", function(d) {
pathogenic_missense_variant_count = 0;
var pathogenic_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand All @@ -417,7 +417,7 @@ function drawMetaDomainLandscape(domain_data, data){
.style("fill", "red")
.on("mouseover", function(d) {
if (metadomain_graph_visible){
pathogenic_missense_variant_count = 0;
var pathogenic_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand Down Expand Up @@ -451,9 +451,9 @@ function drawMetaDomainLandscape(domain_data, data){
.attr("x", function(d) { return main_x(d.values[0].protein_pos); })
.attr("y", function(d) {
if (d.values[0].domains != null){
not_aligned_poition = 0;
var not_aligned_poition = 0;

for (i = 0; i < domain_data.length; i++){
for (var i = 0; i < domain_data.length; i++){
if (domain_data[i].start <= d.values[0].protein_pos && d.values[0].protein_pos < domain_data[i].stop && d.values[0].domains[domain_data[i].ID] == null){
not_aligned_poition = 1;
}
Expand All @@ -479,7 +479,7 @@ function drawMetaDomainLandscape(domain_data, data){
.style("fill", "black")
.on("mouseover", function(d) {
if (metadomain_graph_visible){
pathogenic_missense_variant_count = 0;
var pathogenic_missense_variant_count = 0;
if (d.values[0].domains != null){
meta_domain_ids.forEach(domain_id => {
if (d.values[0].hasOwnProperty('domains') && d.values[0].domains[domain_id] != null){
Expand Down Expand Up @@ -957,7 +957,7 @@ function toggleToleranceLandscapeOrMetadomainLandscape(){
}

function draw_position_schematic_protein(d, element){
pathogenic_missense_variant_count = 0;
var pathogenic_missense_variant_count = 0;
if (clinvar_variants_visible){
// count any pathogenic variants at this position
if (d.values[0].ClinVar != null) {
Expand Down
80 changes: 40 additions & 40 deletions metadome/presentation/web/templates/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function getTranscript() {
transcript_id_results.trancript_ids.sort(function(a,b){return (a.aa_length<b.aa_length) ? 1 : ((b.aa_length<a.aa_length) ? -1: 0);});

// Add the transcripts as options
for (i = 0; i < transcript_id_results.trancript_ids.length; i++) {
for (var i = 0; i < transcript_id_results.trancript_ids.length; i++) {
var opt = new Option();
opt.value = i;
opt.text = transcript_id_results.trancript_ids[i].gencode_id + " ("+ transcript_id_results.trancript_ids[i].aa_length +"aa)" ;
Expand Down Expand Up @@ -554,20 +554,20 @@ function loadDoc() {
// annotates meta domain information for a position
function createPositionalInformation(domain_metadomain_coverage, transcript_id, position_json) {
// Retrieve the needed information for the GET request
protein_position = position_json.values[0].protein_pos;
var protein_position = position_json.values[0].protein_pos;

// Construct the request for this domain and the aligned positions
var requested_domains = {};
domain_ids = Object.keys(position_json.values[0].domains);
for (i = 0; i < domain_ids.length; i++){
domain_id = domain_ids[i];
var domain_ids = Object.keys(position_json.values[0].domains);
for (var i = 0; i < domain_ids.length; i++){
var domain_id = domain_ids[i];

// Check if this position is meta domain suitable
if (!(position_json.values[0].domains[domain_id] == null)){
requested_domains[domain_id] = [];

// append the consensus positions
for (j = 0; j < position_json.values[0].domains[domain_id].consensus_pos.length; j ++) {
for (var j = 0; j < position_json.values[0].domains[domain_id].consensus_pos.length; j ++) {
requested_domains[domain_id].push(position_json.values[0].domains[domain_id].consensus_pos[j])
}
}
Expand All @@ -581,7 +581,7 @@ function createPositionalInformation(domain_metadomain_coverage, transcript_id,
"transcript_id": transcript_id,
"protein_position": protein_position};

// Execute the GET request
// Execute the POST request
$.ajax(
{
type: 'POST',
Expand Down Expand Up @@ -626,7 +626,7 @@ function FillPositionalInformation(domain_metadomain_coverage, position_data, da
var domain_id_list = Object.keys(position_data.values[0].domains);
var n_domains_at_position = Object.keys(position_data.values[0].domains).length;

for (i = 0; i < n_domains_at_position; i++){
for (var i = 0; i < n_domains_at_position; i++){
if (i+1 == n_domains_at_position){
domain_ids += '<a href="http://pfam.xfam.org/family/' + domain_id_list[i] + '" target="_blank">'+domain_id_list[i]+"</a>";
}
Expand All @@ -637,10 +637,10 @@ function FillPositionalInformation(domain_metadomain_coverage, position_data, da
// add meta domain information
if (!(position_data.values[0].domains[domain_id_list[i]] == null)){
// retrieve the domain_information from the data object
meta_domain = data[domain_id_list[i]];
var meta_domain = data[domain_id_list[i]];

// compute coverage
position_coverage = Math.round(((meta_domain.alignment_depth/domain_metadomain_coverage[domain_id_list[i]])*100)*10)/10;
var position_coverage = Math.round(((meta_domain.alignment_depth/domain_metadomain_coverage[domain_id_list[i]])*100)*10)/10;

// Add information to the report
meta_domain_information += '<hr><label class="label">Meta-domain information for domain '+domain_id_list[i]+':</label>';
Expand Down Expand Up @@ -690,10 +690,10 @@ function FillPositionalInformation(domain_metadomain_coverage, position_data, da
document.getElementById("positional_information_overlay_body").innerHTML += '<label class="label">Known pathogenic ClinVar SNVs at position</label>';
if ("ClinVar" in position_data.values[0]){
// Add ClinVar variant table
clinvar_variants = position_data.values[0].ClinVar;
var clinvar_variants = position_data.values[0].ClinVar;

// Add the positional information
for (index = 0; index < clinvar_variants.length; index++){
for (var index = 0; index < clinvar_variants.length; index++){
clinvar_variants[index].chr = position_data.values[0].chr;
clinvar_variants[index].chr_positions = position_data.values[0].chr_positions;
clinvar_variants[index].ref_codon = position_data.values[0].ref_codon;
Expand Down Expand Up @@ -738,22 +738,22 @@ function addRowToPositionalInformationTable(domain_metadomain_coverage, d, trans
domain_ids = "";
related_gnomad = 0;
related_clinvar = 0;
for (i = 0; i < n_domains_at_position; i++){
if (i+1 == n_domains_at_position){
domain_ids += domain_id_list[i];
}
else{
domain_ids += domain_id_list[i]+", ";
}
// append normal and pathogenic variant count
if (!(d.values[0].domains[domain_id_list[i]] == null)){
related_gnomad += d.values[0].domains[domain_id_list[i]].normal_variant_count;
related_clinvar += d.values[0].domains[domain_id_list[i]].pathogenic_variant_count;
}
else{
related_gnomad = "-";
related_clinvar = "-";
}
for (var i = 0; i < n_domains_at_position; i++){
if (i+1 == n_domains_at_position){
domain_ids += domain_id_list[i];
}
else{
domain_ids += domain_id_list[i]+", ";
}
// append normal and pathogenic variant count
if (!(d.values[0].domains[domain_id_list[i]] == null)){
related_gnomad += d.values[0].domains[domain_id_list[i]].normal_variant_count;
related_clinvar += d.values[0].domains[domain_id_list[i]].pathogenic_variant_count;
}
else{
related_gnomad = "-";
related_clinvar = "-";
}
}
}
new_row.append('td').text(domain_ids);
Expand Down Expand Up @@ -794,8 +794,8 @@ function createClinVarTableHeader(){
function createClinVarTableBody(ClinvarVariants){
var html_table= '';
// here comes the data
for (index = 0; index < ClinvarVariants.length; index++){
variant = ClinvarVariants[index];
for (var index = 0; index < ClinvarVariants.length; index++){
var variant = ClinvarVariants[index];
html_table += '<tr>';
html_table += '<td>'+variant.chr+'</td>';
html_table += '<td>'+variant.chr_positions+'</td>';
Expand Down Expand Up @@ -827,16 +827,16 @@ function createGnomADTableHeader(){
function createGnomADTableBody(gnomADVariants){
var html_table= '';
// here comes the data
for (index = 0; index < gnomADVariants.length; index++){
variant = gnomADVariants[index];
html_table += '<tr>';
html_table += '<td>'+variant.chr+'</td>';
html_table += '<td>'+variant.chr_positions+'</td>';
html_table += '<td>'+variant.ref_codon+'>'+variant.alt_codon+'</td>';
html_table += '<td>'+variant.ref_aa_triplet+'>'+variant.alt_aa_triplet+'</td>';
html_table += '<td>'+variant.type+'</td>';
html_table += '<td>' + parseFloat(variant.allele_count/variant.allele_number).toFixed(6) + '</td>';
html_table += '</tr>';
for (var index = 0; index < gnomADVariants.length; index++){
var variant = gnomADVariants[index];
html_table += '<tr>';
html_table += '<td>'+variant.chr+'</td>';
html_table += '<td>'+variant.chr_positions+'</td>';
html_table += '<td>'+variant.ref_codon+'>'+variant.alt_codon+'</td>';
html_table += '<td>'+variant.ref_aa_triplet+'>'+variant.alt_aa_triplet+'</td>';
html_table += '<td>'+variant.type+'</td>';
html_table += '<td>' + parseFloat(variant.allele_count/variant.allele_number).toFixed(6) + '</td>';
html_table += '</tr>';
}

return html_table;
Expand Down

0 comments on commit b5397e8

Please sign in to comment.