Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from smith13mr's block: genome browser 2 with numbers
forked from smith13mr's block: genome browser 4 with numbers
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<body>
<script>
var svg = d3.select("body").append("svg");
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;
})
})
.attr("height", 2000);
var genomes = svg.selectAll(".genomes")
.data(json)
.enter()
.append ("g");
genomes.attr("transform", function(d, i){ return "translate(0," + ( (i*225)) + ")"});
genomes.append("rect") //background for ruler
.attr({x: 0, y: 100, width: function (d) {return d.genomelength/10}, height: 30})
.style({"stroke-width": "2px", "fill": "white", "stroke": "black"});
var genes = genomes.selectAll(".genes")
.data(function(d) { return d.genes; })
.enter()
.append ("g");
genes.append("rect") // gene boxes
.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; })
.attr("style", function (d) { return (d.dirction)})
.style ("fill", function (d) {
if (d.direction === "forward") {
return "turquoise";
}
else if (d.direction === "reverse") {
return "lightpink";
}
else {
return "black";
}
})
.attr("y", function (d) {
if (d.direction === "forward") {
if (d.name%2 === 0)
return 60;
else {
return 40;
}
}
else {
if (d.name%2 === 0)
return 140;
else {
return 170;
}
}
})
.attr("x", function (d) {
if (d.direction === "forward") {
return (0 - ((d.stop-d.start)/10)) - 2;
}
else if (d.direction === "reverse") {
w = d3.select("svg").style("width");
return w;
}
})
.style ("stroke", function (d) {
if (d.direction === "forward") {
return "lightseagreen";
}
else if (d.direction === "reverse") {
return "hotpink";
}
else {
return "black";
}
})
.style ({"stroke-width": "2px"})
.transition().delay(3000).duration(1000)
.attr("height", function (d) {
return 30;
})
.attr("x", function (d) {
return d.start/10;
})
;
genes.append("text") // gene name
.attr("x", function (d) {
return ((d.stop+d.start)/2)/10;
})
.attr("y", function (d) {
if (d.direction === "forward") {
if (d.name%2 === 0)
return 80;
else {
return 60;
}
}
else {
if (d.name%2 === 0)
return 160;
else {
return 190;
}
}
})
.transition().delay(4000).duration(1000)
.text ( function (d) { return d.name; })
.style({"text-anchor": "middle", "font-family": "ariel", "font-weight": "bold"})
.style ("fill", function(d) {
if (d.direction === "forward") {
return "black";
}
else {
return "black";
}
});
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 50;
}
else {
return 30;
}
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) {
return 190;
}
else {
return 220;}
}
})
.style({"text-anchor": "middle", "fill": "black", "font-family": "ariel", "font-weight": "bold"})
.text(function(d) {
return d.pham
})
.attr("fill-opacity", 0)
.transition().delay(3500).duration(1500)
.attr("fill-opacity", 1);
var group = genomes.selectAll(".a") // tickmarks
.data(function (d) {
ticks = [];
genome_position = d3.range(d.genomelength);
genome_position.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})
.transition().duration(3000)
.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
var group2 = genomes.selectAll(".b")
.data(function (d) {
ticks = [];
genome_position = d3.range(d.genomelength);
genome_position.forEach(function (currentValue, index, myArray) {
if(currentValue % 500 === 0) {
ticks.push(currentValue);
}
});
return ticks;
})
.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 = genomes.selectAll(".c")
.data(function (d) {
ticks = [];
genome_position = d3.range(d.genomelength);
genome_position.forEach(function (currentValue, index, myArray) {
if(currentValue % 100 === 0 & currentValue % 1000 !== 0 & currentValue % 500 !== 0) {
ticks.push(currentValue);
}
});
return ticks;
})
.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)"; })
group.append("text")
.text(function (d,i) {
return i;
})
.attr({y: 115, width: "1px", height: 15})
.attr("x", function(d) {return (d/10)+2;})
.attr({"font-size": "10px", "fill":"grey"});
});
</script>
</body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js