Built with blockbuilder.org
forked from nguyenbq's block: Genome Viewer using GBK
forked from nguyenbq's block: Genome Viewer using GBK
xxxxxxxxxx
<!-- Check Out BioJS -->
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/d3@2.10.3/d3.v2.js"></script>
<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>
<style>
body {
margin: ;
position:fixed;
top:0;
right:0;
bottom:0;
left:2;
background-image: linear-gradient(to bottom, #EFEFBB, #D4D3DD 100%);
}
</style>
</head>
<body>
<script>
var svg = d3.select("body")
.append("svg")
.attr("height", 1000);
d3.json("GBKtoJSONtest.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;
})
});
var sequences = svg.selectAll(".genomes")
.data(json)
.enter()
.append("g");
sequences.attr("transform", function(d, i) {
return "translate(0," + (10 + (i*225)) + ")";
});
//Names of the Sequences
sequences.append("text")
.attr({x:-500})
.style({"font-family":"verdana","font-size":"18px","fill":"green"})
.transition(1000).delay(3000).duration(1000).ease("bounce")
.attr({x:10, y:20})
.text(function(d) {
return d.genomename;
});
//starting the ruler
sequences.append("rect")
.attr({x: -500, y: 100, width: function(d) {
return d.genomelength/10; }, height: 30
})
.style({"stroke-width": "2px", "fill": "white", "stroke": "#9932CC",})
.attr("stroke-opacity", 0)
.transition(1000).duration(3000)
.attr({x: 0})
.attr("stroke-opacity", 1);
//grouping the 3 tick groups and displaying them
var group = sequences.selectAll(".a")
.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: 0, y: 100, width: "1px", height: 30})
.attr({x: -100})
.transition().duration(3000)
.attr({x: function (d) { return d/10; }, y: 100, width: "1px", height: 30})
.attr({"fill-opacity": 1});
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
//numbers @1000 ticks
group.append("text")
.attr("y", 112)
.attr("x", function(d) { return (d/10) + 1 })
.style({"font-size":"20px","fill":"red"})
.transition().duration(2000).delay(2000)
.style({"font-family":"verdana","font-size":"10px","fill":"green"})
.text(function(d,i) { return i; })
var group2 = sequences.selectAll(".b")
.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: 0, y: 100, width: "1px", height: 15})
.attr({x:-100})
.transition().duration(3000)
.attr({x: function(d) {return d/10;}, y: 100, width: "1px", height: 15})
//.attr("transform", function (d) {return "translate(" + d/10 + ",0)";});
var group3 = sequences.selectAll(".onehundredticks")
.data(function(d) {
ticks = [];
genome_positions = d3.range(d.genomelength);
genome_positions.forEach(function (currentValue, index, myArray) {
if (currentValue % 100 === 0 & currentValue % 500 !== 0
& currentValue % 1000 !== 0) {
ticks.push(currentValue);
}
});
return ticks;
})
.enter()
.append("g");
group3.append("rect")
.style({"fill": "black"})
//.attr({x: 0, y: 115, width: "1px", height: 15})
.attr({x: -100})
.transition().duration(3000)
.attr({x: function (d) { return d/10; }, y: 115, width: "1px", height: 15})
//.attr("transform", function (d) { return "translate(" + d/10 + ",0)"; });
//Attaching the coming gene boxes to the graph w/the data
var genes = sequences.selectAll(".genes")
.data(function(d) { return d.genes;})
.enter()
.append("g");
var position = genes.selectAll(".location")
.data(function (d) {return d.location;})
.enter()
.append("g");
//The gene boxes attributes
position.append("rect")
.attr("x", function (d) {
return (0 - ((d.end-d.start)/10)) - 2
})
.attr("y", function (d) {
if (((d.end-d.start)/10)%2==0) {
return 100;
} else {
return 160;
}
})
.attr("height", function(d) { return 0; })
.attr("width", function (d) { return (d.end-d.start)/10; })
.style("fill", function(d) {
if (d.start%3==0) {
return "009900";
} else {
return "009900";
}
})
.style("stroke","black")
.style({"stroke-width":"2px"})
.transition().delay(2000).duration(2000)
.attr("x", function (d) {
return d.start/10;
})
.attr("y", function (d) {
if (d.start%3==0) {
return 140;
} else {
return 60;
}
})
.attr("height", function (d) {return 30;})
group.on("click", function() {
console.log("rect");
})
//text in gene boxes
genes.append("text")
.attr("x", function (d) { console.log(d);return ((d.location[0].start+d.location[0].end)/10)/2})
.style("text-anchor","middle")
.style({"font-family":"verdana","font-size":"18px","fill":"black"})
.attr("y", 80)
.text(function (d) {
return d.gene;})
//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);
// text above or below boxes
position.append("text")
.attr("x", function(d) { return ((d.end - d.start)/2)/10;})
.attr("y", 50)
.style({"text-anchor":"middle","fill":"black","font-weight":"bold"})
.attr("font-family","sans-serif")
.text(function(d) {return d.start;})
.attr("fill-opacity", 0)
.transition().delay(4500).duration(1000)
.attr("fill-opacity", 1);
});
</script>
<button onclick="SNPs()" class="button">Show SNPs</button>
</body>
Modified http://mbostock.github.com/d3/d3.js to a secure url
Modified http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js to a secure url
https://mbostock.github.com/d3/d3.js
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