Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from nguyenbq'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"></script>
<script src="https://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<style>
body {
margin:46;
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
}
.d3-tip {
line-height: 1;
font-weight: bold;
padding: 11px;
background: rgba(0, 0, 0, 0.8);
color: #ff0505;
border-radius: 2px;
}
/* Creates a small triangle extender 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;
}
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see!
var genomelength = 16294;
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);
}
});
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-55, -48])
.html(function(d) {
return "<b>Product:</b> <span style='color:white'>" + d.product + "</span>";
})
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"})
;
svg.call(tip);
d3.json("genes.json.txt", function(error, json) {
if (error) return console.warn(error);
var rects = svg.selectAll(".genes")
.data(json)
.enter()
.append("rect")
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
function fade(opacity) {
return function(g, i) {
svg.selectAll(".genes")
.filter(function(d) { return d.start != i && d.stop != i; })
.transition()
.style("opacity", opacity);
};
}
var rectLabels = svg.selectAll (".name")
.data (json)
.enter()
.append("text");
var rectlabels = rectLabels
.attr("x", function (d) {
return ((d.stop+d.start)/10)/2.04
})
.attr("y", function (d) {
if (d.direction == "forward" && d.name%2==0) {
return 57;
}
else if (d.direction == "forward" && d.name%2!==0) {
return 82;
}
else if (d.direction == "reverse" && d.name%2==0) {
return 160;
}
else if (d.direction == "reverse" && d.name%2!==0) {
return 180;
}
else {
return 82;
}
})
.transition (1000).delay (1000)
.text(function (d) {return d.name})
.style({
"font-family":"verdana",
"font-size":"20px",
"fill":"white"
});
var rectAttributes = rects
.attr("x", function (d) {
return d.start/10;
})
.attr("y", function (d) {
return 100;
})
.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 "green";
}
else if (d.direction === "reverse"){
return "red";
}
else {
return "yellow";
}
})
.style({"stroke":"black", "stroke-width":"2px"})
.transition().delay(2000).duration(1000)
.attr("y", function (d) {
if (d.direction == "forward" && d.name%2==0) {
return 35;
}
else if (d.direction == "forward" && d.name%2!==0) {
return 60;
}
else if (d.direction === "reverse" && d.name%2==0) {
return 140;
}
else if (d.direction == "reverse" && d.name%2!==0) {
return 158;
}
else {
return 60;
}
})
.attr("height", function (d) {return 30;})}
);
var group = svg.selectAll(".a")
.data(tickMarks.thousand)
.enter()
.append("g");
group.append("rect")
.style({"fill": "black"})
.attr({x: 0, y: 100, width: "1px", height: 30})
.transition().duration(3000)
.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
var group2 = svg.selectAll(".b")
.data(tickMarks.fivehundred)
.enter()
.append("g");
group2.append("rect")
.style({"fill": "black"})
.attr({x: 0, y: 100, width: "1px", height: 15})
.transition().duration(2000)
.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
var group3 = svg.selectAll(".c")
.data(tickMarks.onehundred)
.enter()
.append("g");
group3.append("rect")
.style({"fill": "black"})
.attr({x: 0, y: 115, width: "1px", height: 15})
.transition().duration(1000)
.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