Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from lambrex's block: genome browser
forked from lambrex's block: genome browser
forked from anonymous's block: genome browser
forked from lambrex's block: genome browser
xxxxxxxxxx
<head>
<meta charset="utf-8">
<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="https://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic">
</head>
<style>
body {
margin:45;
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
}
/* 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;
}
/* Style northward tooltips differently */
.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: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips differently */
.d3-hidden.n:after {
margin: -60px 0 0 0;
top: 100%;
left: 0;
}
</style>
<body>
<script>
// Feel free to change or delete any of the code you see!
var genomelength = 7800;
var tickMarks = {thousand: [], fivehundred: [], onehundred: []};
var genome_positions = [];
for (var i = 1; i <= genomelength; i++) {
genome_positions.push(i);
}
genome_positions.forEach(function(currentValue, index, myArray){
if (currentValue % 1000 === 0) {
tickMarks.thousand.push(currentValue);
}
else if (currentValue % 500 === 0) {
tickMarks.fivehundred.push(currentValue);
}
else if (currentValue % 100 === 0) {
tickMarks.onehundred.push(currentValue);
}
});
d3.json("genes.json.txt", function(error, json) {
if (error) return console.warn(error);
var genomes = svg.selectAll(".genomes")
.data(json)
.enter()
.append("g");
var genes =genomes.selectAll(".genes")
.data(function(d) { return d.genes})
.enter()
.append("g");
//Hover box when you mouseover genes
var svg = d3.select("body").append("svg").attr({height: 500,width: genomelength/10});
svg.append("rect")
.attr({x: 0, y: 100, width: genomelength/10, height: 30})
.style({"stroke-width": "2px", "fill": "white", "stroke": "black"})
.attr("stroke-opacity", 0)
.transition().duration(1000)
.attr("stroke-opacity", 1);
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset(function (d) {
if (d.direction == "forward") {
return [-55, -48];
}
else if (d.direction == "reverse") {
return [-55, -48];
}
})
.html(function(d) {
return "<b>Product:</b> <span style='color:white'>"
+ d.product + "</span>";
})
//Clickable tip box attr
var hidden = d3.tip()
.attr('class', 'd3-hidden')
.offset(function (d) {
if (d.direction == "forward") {
return [70, -48];
}
else if (d.direction == "reverse") {
return [70, -48];
}
})
.html(function(d) {
return "<a style=color:white target=_blank href=https://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);
genes.append("rect")
.on('mouseover', tip.show).on('mouseout', tip.hide)
.on('click', hidden.show).on('dblclick', hidden.hide)
.attr("y", function (d) {
if (d.direction == "forward") {
if (d.name % 2 === 0) {
return 70;
}
else { return 40;}
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) {
return 160;
}
else { return 130; }
}
})
.attr("x", function (d) {
if (d.direction === "forward") {
return (0 - ((d.stop-d.start)/10)) - 2;
}
else if (d.direction === "reverse") {
return (genomelength/10) + 2;
}
})
.attr("height", function (d) {return 30;})
.attr("width", function (d) { return (d.stop-d.start)/10; })
.style({"stroke":"black", "stroke-width": "2px"})
.attr("fill", function (d) {
if (d.direction == "forward") {
return "green";
}
else if (d.direction == "reverse") {
return "red";
}
else {
return "black";
}
})
.transition().delay(1000).duration(1500).attr("x", function (d) { return d.start/10; });
genes.append("text") // gene name
.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 90;
}
else { return 60;}
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) {
return 180;
}
else { return 150;}
}
})
.style({"text-anchor": "middle", "fill": "black"})
.attr("font-family", "sans-serif")
//.text(function(d) {return d.name})
//.text(function(d) {return (d.sequence.split(("C" -1) + ("G" -1) ).length)/(d.sequence.length) * 100})
.text(function(d) {
return ((d.sequence.match(/G/gi).length
+
d.sequence.match(/C/gi).length)/
d.sequence.length
* 100).toPrecision(2) +"%"})
.attr("fill-opacity", 0)
.transition().delay(2000).duration(1500)
.attr("fill-opacity", 1);
genes.append("text") // pham name
.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 60;
}
else { return 30;}
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) {
return 210;
}
else { return 180;}
}
})
.style({"text-anchor": "middle", "fill": "black"})
.attr("font-family", "sans-serif")
.text(function(d) {
return d.pham
})
.attr("fill-opacity", 0)
.transition().delay(3500).duration(1500)
.attr("fill-opacity", 1);
});
var group = svg.selectAll(".thousandticks")
.data(tickMarks.thousand)
.enter()
.append("g");
group.append("rect")
.style({"fill": "black"})
//.attr({x: 0, y: 100, width: "1px", height: 30})
.attr({x: function (d) { return d/10; }, y: 100, width: "1px", height: 30})
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
group.append("text")
.attr("x", function(d) {return (d/10) + 3;})
.attr("y", (90) + 22)
.attr("font-family", "sans-serif")
.attr("font-size", "14px")
.attr("fill", "green")
.style("text-anchor", "start")
.text(function(d) { return d/1000; })
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
var group2 = svg.selectAll(".fivehundredticks")
.data(tickMarks.fivehundred)
.enter()
.append("g");
group2.append("rect")
.style({"fill": "black"})
.attr({x: function(d) {return d/10;}, y: 100, width: "1px", height: 15})
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
var group3 = svg.selectAll(".onehundredticks")
.data(tickMarks.onehundred)
.enter()
.append("g");
group3.append("rect")
.style({"fill": "black"})
.attr({x: function (d) { return d/10; }, y: 115, width: "1px", height: 15})
.attr("fill-opacity", 0)
.transition().duration(1500)
.attr("fill-opacity", 1);
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
</script>
</body>
Modified http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js to a secure url
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js
https://d3js.org/d3.v3.min.js
https://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js