Skip to content

Instantly share code, notes, and snippets.

@grybnicky
Last active April 22, 2016 15:02
Show Gist options
  • Save grybnicky/afc1b005be34f64b495b259263733b35 to your computer and use it in GitHub Desktop.
Save grybnicky/afc1b005be34f64b495b259263733b35 to your computer and use it in GitHub Desktop.
Repeat finder circle ruler arc genes line gen keystone numbering Tool tip repeat connect attempt1
[{
"name": 1,
"pham": 7,
"start": 0,
"stop": 2000,
"direction": "forward"
},
{
"name": 2,
"pham": 201,
"start": 1950,
"stop": 3100,
"direction": "forward"
},
{
"name": 3,
"pham": 90,
"start": 3000,
"stop": 4550,
"direction": "forward"
},
{
"name": 4,
"pham": 3752,
"start": 4200,
"stop": 7550,
"direction": "forward"
},
{
"name": 5,
"pham": 7,
"start": 7600,
"stop": 8753,
"direction": "forward"
},
{
"name": 6,
"pham": 201,
"start": 8800,
"stop": 9194,
"direction": "forward"
},
{
"name": 7,
"pham": 90,
"start": 9190,
"stop": 10325,
"direction": "forward"
},
{
"name": 8,
"pham": 3752,
"start": 10000,
"stop": 11256,
"direction": "forward"
},
{
"name": 9,
"pham": 7,
"start": 11532,
"stop": 12111,
"direction": "forward"
},
{
"name": 10,
"pham": 201,
"start": 12200,
"stop": 13326,
"direction": "reverse"
},
{
"name": 11,
"pham": 90,
"start": 13541,
"stop": 13798,
"direction": "reverse"
},
{
"name": 12,
"pham": 3752,
"start": 13856,
"stop": 14962,
"direction": "reverse"
},
{
"name": 13,
"pham": 7,
"start": 14896,
"stop": 15239,
"direction": "reverse"
},
{
"name": 14,
"pham": 201,
"start": 15326,
"stop": 15986,
"direction": "forward"
},
{
"name": 15,
"pham": 90,
"start": 16052,
"stop": 16879,
"direction": "forward"
},
{
"name": 16,
"pham": 3752,
"start": 16921,
"stop": 18003,
"direction": "forward"
}
]
-<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic">
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
/*tool tip*/
.d3-tip {
line-height: 1;
font-weight: bold;
padding: 12px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
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 northward tooltips differently */
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
</style>
</head>
<body>
<script>
var genomelength = 80000
var keystone = d3.svg.arc()
.innerRadius(230)
.outerRadius(250)
.startAngle(-0.0436332)
.endAngle(0.0436332)
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<strong>GP:</strong> <span style='color:red'>" + d.name + "</span>";
})
var chart = d3.select("body").append("svg:svg")
.attr("class", "chart")
.attr("width", 700)
.attr("height", 700).append("svg:g")
.attr("transform", "translate(400,400)")
;
d3.json("genes.json.txt", function(error, json) {
if (error) return console.warn(error);
var arc = d3.svg.arc()
.innerRadius(function(d){if (d.name%2==0)
return 290
else if (d.name%2==1)
return 250;})
.outerRadius(function(d){if (d.name%2==0)
return 330
else if (d.name%2==1)
return 290;})
.startAngle(function(d, i){return ((d.start/genomelength)*6.2)+0.0436332;})
.endAngle(function(d, i){return ((d.stop/genomelength)*6.2)+0.0436332;})
;
chart.call(tip);
chart.selectAll("path")
.data(json)
.enter().append("svg:path")
.style("fill", function(d, i){ if (d.direction=="forward")
return "green"
else if (d.direction=="reverse")
return "red";
})
.style("stroke", "black")
.attr("d", arc)
.on('mouseover', tip.show)
.on('mouseout', tip.hide)
chart.append("circle")
.attr({cx: 0, cy: 0, r: 250})
.style({ fill: "gray", opacity: 0})
.attr({stroke: "black"});
//Keystone
chart.append("path")
.attr("d", keystone)
.attr("fill", "black")
//.attr("stroke", "black")
//Add code for line ticks
var r = d3.scale.linear()
.domain([0, 1])
.range([0, 200]);
//default accessor [[x1,y1]] => radian and angle
var line = d3.svg.line.radial()
.radius(function(d){; return (r(d[1])); }) // will change between -1 and 1
.angle(function(d) { ;return d[0];});
// radius axis
// cheat with CSS
var gr = chart.append("g")
.attr("class", "r axis")
.selectAll("g")
.data(r.ticks(10).slice(0))
.enter().append("g");
var thoutick = chart.append("g")
.attr("stroke", "black")
.selectAll("g")
.data(d3.range(2.5, 357.5, (1000/genomelength)*355))
.enter().append("g")
.attr("transform", function(d) { return "rotate(" + (d-90) + ")"; });
var fhuntick = chart.append("g")
.attr("stroke", "black")
.selectAll("g")
.data(d3.range(2.5, 357.5, (500/genomelength)*355))
.enter().append("g")
.attr("transform", function(d) { return "rotate(" + (d-90) + ")"; });
var fthotick = chart.append("g")
.attr("stroke", "black")
.selectAll("g")
.data(d3.range(2.5, 357.5, (5000/genomelength)*355))
.enter().append("g")
.attr("transform", function(d) { return "rotate(" + (d-90) + ")"; });
fthotick.append("line")
.attr("x2", 250);
fhuntick.append("line")
.attr("x2", 235);
thoutick.append("line")
.attr("x2", 240)
.style("stroke", "black");
chart.append("circle")
.attr({cx: 0, cy: 0, r: 230})
.attr({stroke: "black"})
.style({ fill: "white", opacity: 0});
fthotick.append("text")
.attr("x", 240)
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return Math.ceil(((d-2.5)/355)*genomelength/1000); })
.style("fill", "white")
.attr({stroke: "none"})
.attr({"font-size": "14px", "font-family": "Arial"})
//.attr("transform", "rotate(90)")
;
;})
d3.json("repeats.json.txt", function(error, json) {
if (error) return console.warn(error);
var repeat = chart.selectAll(".rep")
.data(json)
.enter()
.append("g");
var loc = repeat.selectAll(".loc")
.data(function(d){return d.coordinates;})
.enter()
.append("g");
var connectfunc = loc.line()
.x(function(d){return 400+(230*Math.sin(d.start*2*Math.PI/genomelength));})
.y(function(d){return 400+(230*Math.cos(d.start*2*Math.PI/genomelength));})
.interpolate(linear)
;
var connects = loc.append("path")
.attr("d", connectfunc)
.attr("stroke", "red")
.attr("stroke-width", 5)
;})
</script>
</body>
[{
"sequence": "GATACGGTCAAT",
"width":12,
"E-value": 2,
"coordinates":[{
"start": 50,
"stop": 2000}]
},
{
"sequence": "GATACGGTCAAT",
"width":12,
"E-value": 2,
"coordinates":[{
"start": 35000,
"stop": 2000}]
},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment