Genome browser for phamerator.org
forked from scresawn's block: genome browser
forked from smith13mr's block: genome browser for final group project
forked from scresawn's block: genome browser for final group project
forked from smith13mr's block: Two tooltips and fade out
forked from scresawn's block: Two tooltips and fade out
xxxxxxxxxx
<head>
<meta charset="utf-8">
<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">
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
</head>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
</script>
<style>
/* set the CSS */
div.tooltip {
position: absolute;
text-align: center;
//width: 60px;
height: 20px;
padding: 2px;
font: 14px Raleway;
background: violet;
border: 0px;
border-radius: 4px;
pointer-events: none;
}
</style>
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-content">
<h4 id="domain_header">Domain Header</h4>
<p id="domain_body">Stuff about this domain</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Close</a>
</div>
</div>
<script>
$(document).ready(function(){
console.log("modal ready!");
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal();
});
var svg = d3.select("body").append("svg").attr("height", 1000);
d3.json("test.json", function(error, json) {
var data = function(hsps) {
var paths = Array();
hsps.forEach(function(value, index, myArray) {
var dataset = Array();
dataset.push({x: value.query_from/10, y: 130, evalue: value.evalue});
dataset.push({x: value.query_to/10, y: 130});
dataset.push({x: value.hit_to/10, y: 325});
dataset.push({x: value.hit_from/10, y: 325});
paths.push(dataset);
});
return paths;
}
var hsps = json.BlastOutput2[0].report.results.bl2seq[0].hits[0].hsps;
pathset = data(hsps);
var hsps = svg.selectAll(".hsps")
.data(pathset);
var d3line2 = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("linear-closed");
hsps.enter()
.append("svg:path")
.on("mouseover", function(d){
console.log(d);
tooltip.html("e-value: " + d[0].evalue) ;
d3.select(this).style("fill", "purple");
return tooltip.style("visibility", "visible");
})
.style("fill-opacity", 0)
.style("stroke-width", 0)
.attr("d", function(d) { //console.log(d);
return d3line2(d);})
.transition()
.duration(3000)
.delay(4000)
.style("stroke-width", 1)
.style("stroke", "black")
.style("fill", "violet")
.style("fill-opacity", 0.5)
hsps
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");})
.on("mouseout", function(){
d3.select(this).style("fill-opacity", 0.5);
d3.select(this).style("fill", "violet");
return tooltip.style("visibility", "hidden");
})
var tooltip = d3.select("body")
.append("div")
.style("z-index", "10")
.style("visibility", "hidden")
.style("background","lightcyan")
//.style("width","150px")
.style("height", "30px")
.style("text-align", "center")
.style("position", "absolute")
.style("padding", "2px")
.style("font-family", "Raleway")
.style("border-radius","8px");
});
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;
})
});
// Define the div for the tooltip
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var phage = svg.selectAll(".genomes")
.data(json)
.enter()
.append("g");
phage.attr("transform", function(d, i) { return "translate(0," + (100 + (i*225)) + ")"; });
phage.append("rect") // background for ruler
.attr({x: 0, y: 0, width: function(d) { return d.genomelength/10; }, height: 30})
.style({"stroke-width": "2px", "fill": "white", "stroke": "black"})
.attr("stroke-opacity", 0)
.transition().duration(1000)
.attr("stroke-opacity", 1);
var group = phage.selectAll(".thousandticks")
.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: function (d) { return d/10; }, y: 0, width: "1px", height: 30})
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
group.append("text") // kbp label
.attr("x", function(d) {return (d/10) + 3;})
.attr("y", 12)
.attr("font-family", "Roboto")
.attr("font-size", "14px")
.attr("fill", "black")
.style("text-anchor", "start")
.text(function(d) { return d/1000; })
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
var group2 = phage.selectAll(".fivehundredticks")
.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: function(d) {return d/10;}, y: 0, width: "1px", height: 15})
.attr({"fill-opacity": 0})
.transition().duration(1500)
.attr({"fill-opacity": 1});
var group3 = phage.selectAll(".onehundredticks")
.data(function (d) {
ticks = [];
genome_positions = d3.range(d.genomelength);
genome_positions.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: function (d) { return d/10; }, y: 15, width: "1px", height: 15})
.attr("fill-opacity", 0)
.transition().duration(1500)
.attr("fill-opacity", 1);
gene = phage.selectAll(".genes")
.data(function(d, i) { return d.genes;})
.enter()
.append("g").on("mouseover", function(d) {
nodedata = this.parentNode.__data__;
div.transition()
.duration(500)
.style("opacity", .9);
div .html(nodedata.phagename + " gp" + d.name)
// the text of the tooltip ...
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
gene_group_x = function(d) {
return (d.start)/10;
};
gene_group_y = function(d) {
console.log(d);
if (d.direction == "forward") {
if (d.name % 2 === 0) {
return -70;
}
else { return -30;}
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) {
return 30;
}
else { return 60;}
}
};
gene
.attr("transform", function (d) { return "translate(" + gene_group_x(d) + "," + gene_group_y(d) + ")"});
gene.append("rect")
.attr("height", function (d) {return 30;})
.style({"stroke":"black", "stroke-width": "2px"})
.attr("fill", function (d) {
if (d.direction == "forward") {
return "aquamarine";
}
else if (d.direction == "reverse") {
return "lightskyblue";
}
else {
return "black";
}
})
.attr("width", 0)
.transition()
.duration(1600)
.attr("width", function (d) { return (d.stop-d.start)/10; });
domain = gene.selectAll(".domains")
.data(function(d, i) { return d.domains;})
.enter()
.append("g")
.on('click', function(d,i){
d3.select('#domain_header').text(d.description)
d3.select('#domain_body').text(d.description + " description could go here")
$('#modal1').openModal();
})
;
domain.append("rect")
.attr("fill-opacity", 0)
.attr("height", function (d) {return 28;})
.attr("width", function (d) { return ((d.stop*3)-(d.start*3))/10; })
.attr("x", function(d) {return (d.start*3)/10; })
.attr("y", function (d) {
g = this.parentNode.parentNode.__data__;
if (g.direction == "forward") {
if (g.name % 2 === 0) {
return -78;
}
else { return -38;}
}
else if (g.direction == "reverse") {
if (g.name % 2 === 0) {
return 1;
}
else { return 1;}
}
})
.attr("fill", "orange")
.transition()
.duration(750)
.delay(3000)
.attr("fill-opacity", 0.9);
gene.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) { // forward and even
return 20;
}
else { return 20;} // forward and odd
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) { // reverse and even
return 20;
}
else { return 20;} //reverse and odd
}
})
.style({"text-anchor": "middle", "fill": "black"})
.attr("font-family", "ariel")
.text(function(d) {return d.name})
.attr("fill-opacity", 0)
.transition().delay(2000).duration(1500)
.attr("fill-opacity", 1)
;
gene.append("text") // pham 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) { // forward and even
return -10;
}
else { return -10;} // forward and odd
}
else if (d.direction == "reverse") {
if (d.name % 2 === 0) { // reverse and even
return 50;
}
else { return 50;} //reverse and odd
}
})
.style({"text-anchor": "middle", "fill": "black"})
.attr("font-family", "ariel")
.text(function(d) {return d.pham})
.attr("fill-opacity", 0)
.transition().delay(3500).duration(1500)
.attr("fill-opacity", 1);
});
</script>
<!-- Modal Structure -->
</body>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js
https://code.jquery.com/jquery-2.2.3.min.js
https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js