-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
160 lines (136 loc) · 5.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<title>ITMI Pre-Term Birth Study</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.min.css"/>
<style type="text/css">
body {
margin: 20px 20px 20px 20px;
position: relative;
}
svg {
font-size: 12px;
}
.foreground path {
fill: none;
stroke-opacity: .5;
stroke-width: 1.5px;
}
.foreground path.fade {
stroke: #000;
stroke-opacity: .05;
}
.axis line, .axis path {
fill: none;
stroke: #000;
}
.axis text {
text-shadow: 0 1px 0 #fff;
cursor: move;
}
</style>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/bootstrap.min.js"></script>
<script type="text/javascript" src="http://raw.github.com/mbostock/d3/master/d3.min.js"></script>
</head>
<body>
<table class="table data-grid table-striped table-condensed table-bordered">
<thead>
<tr class="C_HEADERS">
<th>Gene</th>
<th>MAF(%)</th>
<th>Polyphen2 prediction</th>
<th>Gene Function</th>
<th>Minor Allele Transmitted</th>
<th>Major Allele Transmitted</th>
<th>Admix Ratios</th>
</tr>
</thead>
</table>
<script type="text/javascript">
var RACES = ["AMR", "AFA", "EUR", "ASN"];
var SUB_POPULATION_PERCS = {};
$.ajax({
"method":"GET",
"url":"data/variants.tsv",
success:function (tsv) {
var headers = $(".C_HEADERS").find("th");
var rows = d3.tsv.parse(tsv);
var html = "";
_.each(rows, function (row) {
var GENE = row["Gene"];
html += "<tr>";
html += "<td class='span2'>";
html += "<strong>" + GENE + "</strong>";
html += "<ul class='nav nav-list'>";
html += "<li>" + row["Coordinate"] + "</li>";
html += "</ul>";
html += "</td>";
html += "<td class='span1'>" + row["MAF(%)"] + "</td>";
html += "<td class='span1'>" + row["Polyphen2 prediction"] + "</td>";
html += "<td class='span3'>" + row["Gene Function"] + "</td>";
html += "<td class='span1'>" + row["Minor Allele Transmitted"] + "</td>";
html += "<td class='span1'>" + row["Major Allele Transmitted"] + "</td>";
html += "<td class='span3' id='C_" + GENE + "' class='vis_container'></td>";
html += "</tr>";
SUB_POPULATION_PERCS[GENE] = {};
_.each(RACES, function (race) {
SUB_POPULATION_PERCS[GENE][race] = row[race];
})
});
$(".data-grid").append(html);
LoadNewborns();
}
});
var LoadNewborns = function () {
var line = d3.svg.line();
var m = [20, 40, 0, 40];
var w = 300;
var h = 50;
var x = d3.scale.ordinal().domain(RACES).rangePoints([0, w]);
var y = {};
var strokeFn = d3.scale.category20b();
var axis = d3.svg.axis().ticks(0).orient("left");
d3.tsv("data/samples.tsv", function (tsvdata) {
var dataByRows = _.groupBy(tsvdata, "Gene");
_.each(dataByRows, function (data, GENE) {
var svg = d3.select("#C_" + GENE).append("svg:svg").attr("width", w + m[1] + m[3]).attr("height", h + m[0] + m[2])
.append("svg:g").attr("transform", "translate(" + m[3] + "," + m[0] + ")");
// Create a scale for each trait.
RACES.forEach(function (d) {
y[d] = d3.scale.linear().domain([0,1]).range([h, 0]);
});
// Add foreground lines.
var idx = 0;
svg.append("svg:g").attr("class", "foreground").selectAll("path").data(data)
.enter().append("svg:path").attr("d", path).attr("stroke", function(d) {
return strokeFn(idx++ % 20);
});
// Add a group element for each trait.
var g = svg.selectAll(".trait").data(RACES).enter().append("svg:g").attr("class", "trait")
.attr("transform", function (d) {
return "translate(" + x(d) + ")";
});
// Add an axis and title.
g.append("svg:g").attr("class", "axis")
.each(function (d) {
d3.select(this).call(axis.scale(y[d]));
})
.append("svg:text").attr("text-anchor", "middle").attr("y", -9)
.text(function (d) {
return d + " (" + SUB_POPULATION_PERCS[GENE][d] + "%)";
});
});
});
// Returns the path for a given data point.
function path(d) {
return line(RACES.map(function (p) {
return [x(p), y[p](d[p])];
}));
}
}
</script>
</body>
</html>