Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from nguyenbq's block: Genome Viewer Final
forked from devssunil's block: Genome viewer Final
Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from nguyenbq's block: Genome Viewer Final
forked from devssunil's block: Genome viewer Final
[{ | |
"genomename": "Bp190", | |
"genomelength": 9000, | |
"genes": [{ | |
"name": 1, | |
"start": 124, | |
"stop": 1410, | |
"direction": "forward", | |
"product": "dnaA", | |
"subnum": "13", | |
"snp": "1004", | |
"sequence": "ATAGTCGATGCTAGTATGCGCATCCGGCGCGATCGTGCGTGCTAGC", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 2, | |
"start": 1413, | |
"stop": 2522, | |
"direction": "forward", | |
"product": "DNA Polymerase III", | |
"sequence": "ATAGTCGATGCTAGTATGCGCGTGCGTGCTAGC", | |
"subnum": "123", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 3, | |
"start": 2617, | |
"stop": 5070, | |
"direction": "forward", | |
"product": "DNA gyrase", | |
"sequence": "ATAGTCGATGCGTGCTAGC", | |
"subnum": "76", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 4, | |
"start": 5189, | |
"stop": 5917, | |
"direction": "reverse", | |
"product": "Transcriptional regulator", | |
"sequence": "ATAGTCGATCGCGGCGGCATGCATGCATGCGCGTGCTAGC", | |
"subnum": "654", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 5, | |
"start": 6100, | |
"stop": 7527, | |
"direction": "reverse", | |
"product": "probable amidase", | |
"sequence": "ATAGTCGATGCTAGTATGCATCGTACGATCCGAGCGCGCGATCGTGCGTGCTAGC", | |
"subnum": "82", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 6, | |
"start": 7566, | |
"stop": 8537, | |
"direction": "forward", | |
"product": "Tricarboxylate transport protein TctC", | |
"sequence": "ATAGTCGATGCTAGTATGCGCGCGCTATCGCGGCGCGCGCGCGCGGATCGTGCGTGCTAGC", | |
"subnum": "41", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 7, | |
"start": 8956, | |
"stop": 10119, | |
"direction": "forward", | |
"product": "L-lactate dehydrogenase", | |
"sequence": "ATAGTCGATGCTAGTATGCGCGCGCCGCGGCGCGGGGCGCGCGATCGTGCGTGCTAGC", | |
"subnum": "38", | |
"translation": "amino acids" | |
}] | |
}, | |
{ | |
"genomename": "Bp1865", | |
"genomelength": 7528, | |
"genes": [{ | |
"name": 1, | |
"start": 124, | |
"stop": 1000, | |
"direction": "forward", | |
"product": "dnaA", | |
"subnum": "323", | |
"sequence": "ATAGTCGATGCTAGTATGCGCATCCGGCGCGATCGTGCGTGCTAGC", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 2, | |
"start": 1200, | |
"stop": 2100, | |
"direction": "reverse", | |
"product": "DNA Polymerase III", | |
"sequence": "ATAGTCGATGCTAGTATGCGCGTGCGTGCTAGC", | |
"subnum": "3456", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 3, | |
"start": 2000, | |
"stop": 4032, | |
"direction": "forward", | |
"product": "DNA gyrase", | |
"sequence": "ATAGTCGATGCGTGCTAGC", | |
"subnum": "966", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 4, | |
"start": 4300, | |
"stop": 5502, | |
"direction": "reverse", | |
"product": "Transcriptional regulator", | |
"sequence": "ATAGTCGATCGCGGCGGCATGCATGCATGCGCGTGCTAGC", | |
"subnum": "211", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 5, | |
"start": 5402, | |
"stop": 7500, | |
"direction": "reverse", | |
"product": "probable amidase", | |
"sequence": "ATAGTCGATGCTAGTATGCATCGTACGATCCGAGCGCGCGATCGTGCGTGCTAGC", | |
"subnum": "1082", | |
"translation": "amino acids" | |
}] | |
}, | |
{ | |
"genomename": "Bp194", | |
"genomelength": 8000, | |
"genes": [{ | |
"name": 1, | |
"start": 100, | |
"stop": 1200, | |
"direction": "reverse", | |
"product": "dnaA", | |
"subnum": "3", | |
"sequence": "ATAGTCGATGCTAGTATGCGCATCCGGCGCGATCGTGCGTGCTAGC", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 2, | |
"start": 1213, | |
"stop": 2000, | |
"direction": "reverse", | |
"product": "DNA Polymerase III", | |
"sequence": "ATAGTCGATGCTAGTATGCGCGTGCGTGCTAGC", | |
"subnum": "3539", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 3, | |
"start": 3000, | |
"stop": 4800, | |
"direction": "forward", | |
"product": "DNA gyrase", | |
"sequence": "ATAGTCGATGCGTGCTAGC", | |
"subnum": "849", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 4, | |
"start": 5000, | |
"stop": 5417, | |
"direction": "reverse", | |
"product": "Transcriptional regulator", | |
"sequence": "ATAGTCGATCGCGGCGGCATGCATGCATGCGCGTGCTAGC", | |
"subnum": "2031", | |
"translation": "amino acids" | |
}, | |
{ | |
"name": 5, | |
"start": 5700, | |
"stop": 7600, | |
"direction": "forward", | |
"product": "probable amidase", | |
"sequence": "ATAGTCGATGCTAGTATGCATCGTACGATCCGAGCGCGCGATCGTGCGTGCTAGC", | |
"subnum": "12", | |
"translation": "amino acids" | |
}] | |
}] |
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script src="//d3js.org/d3.v3.min.js" language="JavaScript"></script> | |
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script> | |
<style> | |
body { | |
margin: ; | |
position:fixed; | |
top:0; | |
right:0; | |
bottom:0; | |
left:2; | |
} | |
/* Tip box */ | |
.d3-tip { | |
line-height: 1; | |
font-weight: bold; | |
padding: 11px; | |
background: rgba(0, 0, 0, 0.8); | |
color: #ff0505; | |
border-radius: 2px; | |
} | |
/* This is for the little triangle for the tooltip */ | |
.d3-tip:after { | |
box-sizing: border-box; | |
display: inline; | |
font-size: 10px; | |
width: 100%; | |
line-height: 1; | |
color: rgba(0, 0, 0, 0.8); | |
content: "\25BC"; | |
position: absolute; | |
text-align: center; | |
} | |
/* Margins for the little triangle */ | |
.d3-tip.n:after { | |
margin: -1px 0 0 0; | |
top: 100%; | |
left: 0; | |
} | |
/* Lower tip box */ | |
.d3-hidden { | |
line-height: 1; | |
font-weight: bold; | |
padding: 11px; | |
background: rgba(1, 34, 34, 0.8); | |
color: #1fe429; | |
border-radius: 2px; | |
} | |
/* This is for the little triangle for the tooltip */ | |
.d3-hidden:after { | |
box-sizing: border-box; | |
display: inline; | |
font-size: 20px; | |
width: 100%; | |
line-height: 1; | |
color: rgba(1, 0, 0, 0.8); | |
content: "\25B2"; | |
position: absolute; | |
text-align: center; | |
} | |
/* Margins for the little triangle */ | |
.d3-hidden.n:after { | |
margin: -55px 0 0 0; | |
top: 100%; | |
left: 0; | |
} | |
/* For download Link */ | |
#download { | |
cursor: pointer; | |
text-decoration: none; | |
color: green; | |
} | |
.dot { | |
stroke: #000; | |
} | |
.button { | |
background-color: #4CAF50; | |
border: none; | |
color: white; | |
padding: 10px 32px; | |
text-align: center; | |
text-decoration: none; | |
display: inline-block; | |
font-size: 16px; | |
margin: 4px 2px; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("height", 1000) | |
; | |
d3.json("genes.json.txt", function(error, json) { | |
if (error) return console.warn(error); | |
svg.attr("width", function(d) { | |
return d3.max(json, function(d) { | |
return d.genomelength/10; | |
}) | |
}); | |
var sequences = svg.selectAll(".genomes") | |
.data(json) | |
.enter() | |
.append("g"); | |
sequences.attr("transform", function(d, i) { | |
return "translate(0," + (0 + (i*153)) + ")"; | |
}); | |
//starting the ruler | |
sequences.append("rect") | |
.attr({x: -500, y: 100, width: function(d) { | |
return d.genomelength/10; }, height: 30 | |
}) | |
.style({"stroke-width": "2px", "fill": "white", "stroke": "#000000",}) | |
.attr("stroke-opacity", 0) | |
.transition(1000).duration(3000) | |
.attr({x: 0}) | |
.attr("stroke-opacity", 1); | |
//grouping the 3 tick groups and displaying them | |
var group = sequences.selectAll(".a") | |
.data(function (d) { | |
ticks = []; | |
genome_positions = d3.range(d.genomelength); | |
genome_positions.forEach(function (currentValue, index, myArray) { | |
if (currentValue % 1000 === 0) { | |
ticks.push(currentValue); | |
} | |
}); | |
return ticks; | |
}) | |
.enter() | |
.append("g"); | |
group.append("rect") | |
.style({"fill":"black"}) | |
//.attr({x: 0, y: 100, width: "1px", height: 30}) | |
.attr({x: -100}) | |
.transition().duration(3000) | |
.attr({x: function (d) { return d/10; }, y: 100, width: "1px", height: 30}) | |
.attr({"fill-opacity": 1}) | |
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; }); | |
//numbers @1000 ticks | |
group.append("text") | |
.attr("y", 112) | |
.attr("x", function(d) { return (d/10) + 1 }) | |
.style({"font-size":"30px","fill":"red"}) | |
.transition().duration(1000).delay(2000) | |
.style({"font-family":"verdana","font-size":"10px","fill":"red"}) | |
.text(function(d,i) { return i; }) | |
var group2 = sequences.selectAll(".b") | |
.data(function(d) { | |
ticks = []; | |
genome_positions = d3.range(d.genomelength); | |
genome_positions.forEach(function (currentValue, index, myArray) { | |
if (currentValue % 500 === 0 & currentValue % 1000 !== 0) { | |
ticks.push(currentValue); | |
} | |
}) | |
return ticks; | |
}) | |
.enter() | |
.append("g"); | |
group2.append("rect") | |
.style({"fill": "black"}) | |
//.attr({x: 0, y: 100, width: "1px", height: 15}) | |
.attr({x:-100}) | |
.transition().duration(3000) | |
.attr({x: function(d) {return d/10;}, y: 100, width: "1px", height: 15}) | |
//.attr("transform", function (d) {return "translate(" + d/10 + ",0)";}); | |
var group3 = sequences.selectAll(".onehundredticks") | |
.data(function(d) { | |
ticks = []; | |
genome_positions = d3.range(d.genomelength); | |
genome_positions.forEach(function (currentValue, index, myArray) { | |
if (currentValue % 100 === 0 & currentValue % 500 !== 0 | |
& currentValue % 1000 !== 0) { | |
ticks.push(currentValue); | |
} | |
}); | |
return ticks; | |
}) | |
.enter() | |
.append("g"); | |
group3.append("rect") | |
.style({"fill": "black"}) | |
//.attr({x: 0, y: 115, width: "1px", height: 15}) | |
.attr({x: -100}) | |
.transition().duration(3000) | |
.attr({x: function (d) { return d/10; }, y: 115, width: "1px", height: 15}) | |
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; }); | |
//Attaching the coming gene boxes to the graph w/the data | |
var genes = sequences.selectAll(".genes") | |
.data(function(d) { return d.genes;}) | |
.enter() | |
.append("g"); | |
//Hover box when you mouseover genes | |
var tip = d3.tip() | |
.attr('class', 'd3-tip') | |
.offset(function (d) { | |
if (d.direction == "forward") { | |
return [-33, -8]; | |
} | |
else if (d.direction == "reverse") { | |
return [-20, -8]; | |
} | |
}) | |
.html(function(d) { | |
return "<b>Product:</b> <span style='color:white'>" + d.product + "</span>";}) | |
//Clickable tip box | |
var hidden = d3.tip() | |
.attr('class', 'd3-hidden') | |
.offset(function (d) { | |
if (d.direction == "forward") { | |
return [80, -8]; | |
} | |
else if (d.direction == "reverse") { | |
return [95, -8]; | |
} | |
}) | |
// .html(function(d) { | |
// return "<a style=color:white target=_blank //href=http://blast.ncbi.nlm.nih.gov/Blast.cgi>BLAST:</a><span style='color:white'>" | |
// + " " + d.translation + "</span>"; | |
// }) | |
//call the "tool-tips" | |
svg.call(tip); | |
svg.call(hidden); | |
//The gene boxes attributes | |
genes.append("rect") | |
.on('mouseover', tip.show).on('mouseout', tip.hide) | |
.on('click', hidden.show).on('dblclick', hidden.hide) | |
.attr("x", function (d) { | |
if (d.direction === "forward") { | |
return (0 - ((d.stop-d.start)/10)) - 2; | |
} | |
else if (d.direction === "reverse") { | |
return (d.genomelength/10) + 2; | |
} | |
}) | |
.attr("y", function (d) { return 100; }) | |
//.attr("rx", "10") | |
//.attr("ry", "10") | |
.attr("height", function(d) { return 0; }) | |
.attr("width", function (d) { return (d.stop-d.start)/10; }) | |
.style("fill", function(d) { | |
if (d.direction === "forward") { return "009900"; | |
} else if (d.direction === "reverse"){ | |
return "red"; | |
} else { | |
return "yellow"; | |
} | |
}) | |
.style("stroke", function(d) { | |
if (d.direction === "forward") { | |
return "#000000"; | |
} else if (d.direction === "reverse") { | |
return "#000000"; | |
} else { | |
return "yellow"; | |
} | |
}) | |
.style({"stroke-width":"3px"}) | |
.transition().delay(2000).duration(2000) | |
.attr("x", function (d) { | |
return d.start/10; | |
}) | |
.attr("y", function (d) { | |
if (d.direction == "forward") { | |
if (d.name % 2 ==0) { | |
return 34; | |
} else { | |
return 67; | |
} | |
} else if (d.direction == "reverse") { | |
if (d.name %2 == 0) { | |
return 133; | |
} else { | |
return 165; | |
} | |
} else { | |
return 60; | |
} | |
}) | |
.attr("height", function (d) {return 30;}) | |
group.on("click", function() { | |
console.log("rect"); | |
}) | |
//text in gene boxes | |
genes.append("text") | |
.attr("x", function (d) { return ((d.start+d.stop)/10)/2}) | |
.style("text-anchor","middle") | |
.style({"font-family":"verdana","font-size":"18px","fill":"white"}) | |
.attr("y", function (d) { | |
if (d.direction === "forward" && d.name%2==0) { | |
return 58; | |
} | |
else if (d.direction === "forward" && d.name%2!==0) { | |
return 91; | |
} | |
else if (d.direction === "reverse" && d.name%2==0) { | |
return 151; | |
} | |
else if (d.direction === "reverse" && d.name%2!==0) { | |
return 185; | |
} | |
else { | |
return 80; | |
} | |
}) | |
.text(function (d) { | |
return d.name;}) | |
genes.append("text") | |
.attr("x", function(d) { return ((d.start + d.stop)/2)/10;}) | |
.attr("y", function (d) { | |
if (d.direction == "forward") { | |
if (d.name % 2 === 0) { | |
return 28; | |
} | |
else { return 59;} | |
} | |
else if (d.direction == "reverse") { | |
if (d.name % 2 === 0) { | |
return 181; | |
} | |
else { return 213;} | |
} | |
}) | |
.style({"text-anchor":"middle","fill":"black","font-weight":"bold"}) | |
.attr("font-family","sans-serif") | |
.text(function(d) {return d.subnum}) | |
.attr("fill-opacity", 0) | |
.transition().delay(4500).duration(1000) | |
.attr("fill-opacity", 1); | |
function writeDownloadLink(){ | |
var html = d3.select("svg") | |
.attr("title", "svg_title") | |
.attr("version", 1.1) | |
.attr("xmlns", "http://www.w3.org/2000/svg") | |
.node().parentNode.innerHTML; | |
d3.select(this) | |
.attr("href-lang", "image/svg+xml") | |
.attr("href", "data:image/svg+xml;base64,\n" + btoa(html)) | |
.on("mousedown", function(){ | |
if(event.button != 2){ | |
d3.select(this) | |
.attr("href", null) | |
.html("Use right click"); | |
} | |
}) | |
.on("mouseout", function(){ | |
d3.select(this) | |
.html("Download SVG"); | |
}); | |
}; | |
}); | |
</script> | |
<button onclick="SNPs()" class="button">Show SNPs</button> | |
</body> |