Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from cheneymb's block: genome browser blocks
forked from anonymous's block: genome browser named
forked from cheneymb's block: genome browser 3/15
forked from cheneymb's block: genome browser 3/15
forked from cheneymb's block: genome browser 3/15
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>
</head>
<style>
/* Body to hold whole ruler */
body {
margin: ;
position: fixed ;
top: 75;
bottom: 0;
left: 0;
right: 0;
}
/* Hover box style */
.d3-hover {
line-height: 1;
font-weight: bold;
padding: 11px;
background: #DCDCDC;
color: #000000;
border-radius: 2px;
}
/* This is for the little triangle for the hover box */
.d3-hover:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: #000000;
content: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips differently */
.d3-hover.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
/* Click box style */
.d3-click {
line-height: 1;
font-weight: bold;
padding: 11px;
background: #F08080;
color: #000000;
border-radius: 2px;
}
/* This is for the little triangle for the click box */
.d3-click:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: #000000;
content: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips differently */
.d3-click.n:after {
margin: -60px 0 0 0;
top: 100%;
left: 0;
}
</style>
<body>
<script>
var genomelength = 9500;
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 rulerNumber = [];
//setting the ruler and scaling it
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"});
//calling the data to the ruler
d3.json("genes.json.txt", function(error, json) {
if (error) return console.warn(error);
var rects = svg.selectAll(".genes")
.data(json)
.enter()
.append("rect")
;
//Defining hoverboxes when you mouseover genes
var hover = d3.tip()
.attr('class','d3-hover')
.offset(function(d) {
if (d.direction == "forward") {
return [-29, -1];
}
if (d.direction == "reverse") {
return [-40, -1];
}
})
.html(function(d) {
return "<b>Product:</b> <span style='color:white'>"
+ d.product + "</span>";
})
//Defining boxes linked to blast when you click on genes
var click = d3.tip()
.attr('class', 'd3-click')
.offset(function(d){
if (d.direction == "forward") {
return [100, -1];
}
if (d.direction == "reverse") {
return [90, -1];
}
})
.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>";
})
//calling the hover and click boxes
svg.call(hover);
svg.call(click);
//calling labels for genes
var rectLabels = svg.selectAll(".name")
.data(json)
.enter()
.append("text");
//setting the style and position of the gene name
var geneNames = rectLabels
.attr("x", function (d) { return ((d.start+d.stop)/10)/2})
.style("text-anchor","middle")
.style({
"font-family":"Arial",
"font-size":"18px",
"fill":"#f9fffe"
})
//setting the genes position depending on name and direction
.attr("y", function (d) {
if (d.direction === "forward" && d.name%2==0)
{return 58;}
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;
}})
//setting the text to the gene name from the data
.text(function (d) {
return d.name;});
//var c = 0;
//var g = 0;
//for (var i=0; i<=d.sequence.length; i++) {
//if (d.sequence[i] === "C") {c++; }
// else if (d.sequence[i] === "G") {g++;}
// return (((c+g)/d.sequence.length)*100);})
//.attr("fill-opacity",0)
//.transition().duration(3000).delay(2000)
//.attr("fill-opacity",1);
//setting style and position of rectangle depending on direction
var rectAttributes = rects
.on('mouseover', hover.show).on('mouseout', hover.hide)
.on('click', click.show).on('dblclick', click.hide)
.attr("y", function (d) {
if (d.direction == "forward") {return 100; }
else if (d.direction == "reverse") {return 130;}
else {return 200}})
.attr("x", function (d) {
if (d.direction == "forward") {return 0 - ((d.stop-d.start)) - 3;}
else if (d.direction == "reverse") {return (genomelength/10) + 2;}})
.attr("height", function(d) { return 0;})
.attr("width", function(d) { return (d.stop-d.start)/10; })
.transition().duration(2000).delay(1000)
.attr("x", function (d) { return d.start/10; })
.style("fill", function(d) {
if (d.direction === "forward") {return "#659EC7"}
else {return "#837E7C"}})
.style({"stroke":"black", "stroke-width":"2px"})
.attr("y", function (d) {
if (d.direction == "forward" && d.name%2==0) {return 37;}
else if (d.direction == "forward" && d.name%2!==0) {return 70;}
else if (d.direction == "reverse" && d.name%2==0) {return 130;}
else if (d.direction == "reverse" && d.name%2!==0) {return 163;}
else {return 70}
})
.attr("height", function (d) {return 30;})
var famLabels = svg.selectAll(".famname")
.data(json)
.enter()
.append("text");
var famtext = famLabels
.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.famname})
.attr("fill-opacity", 0)
.transition().delay(4500).duration(1000)
.attr("fill-opacity", 1);
});
//setting tick marks and labeling the thousand marks with numbers on ruler
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)"; })
group.append("text")
.style({
"font-family":"Arial",
"font-size":"14px",
"fill":"#C36241"})
.attr({y:112})
.attr("x", function(d) {
return d/10 - 8})
.transition().duration(3000).delay(3000)
.text(function (d) {return d/1000});
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