-
Notifications
You must be signed in to change notification settings - Fork 2
/
blast-item.html
219 lines (216 loc) · 10.5 KB
/
blast-item.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<link rel="import" href="blast-styles.html">
<link rel="import" href="external-scripts.html">
<!--
`blast-item`
Blast item demo
@demo demo/blast-item-demo.html
-->
<dom-module id="blast-item">
<template>
<style include="blast-styles">
:host {
background:#ECF0F1;
}
.collapse-content {
background-color: #F3F5FC;
}
.item-line {
margin-top: 10px;
border-bottom: #ebeffa 1px solid;
}
.hsp-container {
border-bottom: solid lightgray 1px;
margin-bottom: 10px;
}
.details-line {
margin: 5px 5px 5px 7px;
}
.hsp-segment {
margin: 5px 0;
}
font-large-x {
font-size: 120%;
}
svg {
margin-top: 5px;
}
</style>
<div class="item-line">
<div class="row" on-tap="_toggleAlignment">
<div class="col-lg-6">
<a href="https://www.nextprot.org/entry/[[data.description.0.entry_accession]]" target="_parent" class="font-large-x">
[[data.description.0.title]]
</a><br/>
<div id="querySvgContainer"></div>
</div>
<div class="col-lg-2 nomargin hright">
<div id="targetSvgContainer"></div>
<!--<svg height="22" width="95%"><rect y="12" height="6" width="100%" fill$="[[data.hsps.0.color]]" on-mouseover="_pointIdentity"></rect></svg>-->
</div>
<div class="col-lg-1 nomargin hright">[[data.len]]aa</div>
<div class="col-lg-1 nomargin hright">[[identity_percent]]%</div>
<div class="col-lg-1 nomargin hright">[[data.global.total_score]]</div>
<div class="col-lg-1 hright">[[_toExponential(data.global.min_evalue)]]</div>
</div>
<iron-collapse id="alignmentContainer" opened="[[showAlignment]]">
<div class="collapse-content">
<template is="dom-repeat" items="[[data.hsps]]" as="hsp">
<div class="hsp-container">
<div class="details-line">
<span class="quiet">score </span>
<span class="bold">[[hsp.bit_score]] bits ([[hsp.score]])</span><span class="quiet">, identities </span>
<span class="bold">[[hsp.identity]]/[[hsp.align_len]]</span><span class="quiet">, positives </span>
<span class="bold">[[hsp.positive]]/[[hsp.align_len]]</span><span class="quiet">, gaps </span>
<span class="bold">[[hsp.gaps]]/[[hsp.align_len]]</span>
</div>
<div>
<template is="dom-repeat" items="[[_formatAlignment(hsp)]]" as="segment">
<div class="hsp-segment">
<span class="pre small"> [[segment.0]]</span><br/>
<span class="pre small"> [[segment.1]]</span><br/>
<span class="pre small"> [[segment.2]]</span><br/>
</div>
</template>
</div>
</div>
</template>
</div>
</iron-collapse>
</div>
</template>
<script>
Polymer({
is: 'blast-item',
properties: {
data: {
type: Object,
observer: "_initialize"
},
showAlignment: {
type: Boolean,
value: true
},
seqCharPerLine: {
type: Number,
value: 80
}
},
_initialize: function(){
this.identity_percent=(Math.round(this.data.global.identity_percent*10)/10).toFixed(1);
this._querySvgGraph();
this._targetSvgGraph();
},
_querySvgGraph: function(){
var svg = d3.select(this).select("#querySvgContainer")
.append("svg")
.style("border", "1px solid black")
.attr("width", "95%")
.attr("height", "12")
.style("margin-top", "4px");;
this.data.hsps.sort(this._sortQuery);
var lastPosition = "0%";
for (var i in this.data.hsps) {
var queryFrom = Math.round((((this.data.hsps[i].query_from-1)/this.data.queryLength)*100)).toString()+"%";
var queryTo = Math.round((((this.data.hsps[i].query_to - this.data.hsps[i].query_from)/this.data.queryLength)*100)).toString()+"%";
if (queryFrom>=lastPosition) {
var rect = svg.append("rect")
.attr("x", lastPosition)
.attr("y", "0")
.attr("width", (queryFrom.replace("%",'')-lastPosition.replace("%",'')).toString()+"%")
.attr("height", "12")
.attr('fill', "#f0f0f0");
}
var self=this;
var rect = svg.append("rect")
.attr("index", i)
.attr("x", queryFrom)
.attr("y", "0")
.attr("width", queryTo)
.attr("height", "12")
.attr('fill', this.data.hsps[i].color)
.on("mouseover", function(e) {
self.domHost.domHost.pointIdentity(e["data.hsps"][this.attributes[0].value].identity_percent);
});
lastPosition = (new Number(queryFrom.replace("%",''))+new Number(queryTo.replace("%",''))).toString()+"%";
}
var rect = svg.append("rect")
.attr("x", lastPosition)
.attr("y", "0")
.attr("width", (100-lastPosition.replace("%",'')).toString()+"%")
.attr("height", "12")
.attr('fill', "#f0f0f0");
},
_targetSvgGraph: function(){
var svg = d3.select(this).select("#targetSvgContainer")
.append("svg")
.style("border", "1px solid black")
.attr("width", "95%")
.attr("height", "6")
.style("margin-top", "20px");
this.data.hsps.sort(this._sortHit);
var lastPosition = "0%";
for (var i in this.data.hsps) {
var hitFrom = Math.round(((this.data.hsps[i].hit_from/this.data.len)*100)).toString()+"%";
var hitTo = Math.round((((this.data.hsps[i].hit_to - this.data.hsps[i].hit_from)/this.data.len)*100)).toString()+"%";
if (hitFrom>=lastPosition) {
var rect = svg.append("rect")
.attr("x", lastPosition)
.attr("y", "0")
.attr("width", (hitFrom.replace("%",'')-lastPosition.replace("%",'')).toString()+"%")
.attr("height", "12")
.attr('fill', "#f0f0f0");
}
var self=this;
var rect = svg.append("rect")
.attr("index", i)
.attr("x", hitFrom)
.attr("y", "0")
.attr("width", hitTo)
.attr("height", "6")
.attr('fill', this.data.hsps[i].color)
.on("mouseover", function(e) {
self.domHost.domHost.pointIdentity(e["data.hsps"][this.attributes[0].value].identity_percent);
});
lastPosition = (new Number(hitFrom.replace("%",''))+new Number(hitTo.replace("%",''))).toString()+"%";
}
var rect = svg.append("rect")
.attr("x", lastPosition)
.attr("y", "0")
.attr("width", (100-lastPosition.replace("%",'')).toString()+"%")
.attr("height", "12")
.attr('fill', "#f0f0f0");
},
_sortQuery: function(a,b){
return a.query_from> b.query_from? 1:-1;
},
_sortHit: function(a,b){
return a.hit_from> b.hit_from? 1:-1;
},
_formatAlignment: function(hit){
var index=0;
var formatedSeq = [];
var max_label_len = hit.query_to >= hit.hit_to ? hit.query_to.toString().length : hit.hit_to.toString().length;
while (index<hit.qseq.length) {
var query_start = hit.query_from+index;
var query_max = new Number(query_start+this.seqCharPerLine);
var query_end = hit.query_to<=query_max ? hit.query_to : query_max-1;
var hit_start = hit.hit_from+index;
var hit_max = new Number(hit_start+this.seqCharPerLine);
var hit_end = hit.hit_to<=hit_max ? hit.hit_to : hit_max-1;
formatedSeq.push([
"query "+" ".repeat(max_label_len-query_start.toString().length)+query_start+" "+hit.qseq.slice(index,index+this.seqCharPerLine)+" "+query_end,
" "+" ".repeat(max_label_len+1)+(hit.midline.slice(index,index+this.seqCharPerLine)),
"subject "+" ".repeat(max_label_len-hit_start.toString().length)+hit_start+" "+hit.hseq.slice(index,index+this.seqCharPerLine)+" "+hit_end]);
index+=this.seqCharPerLine;
}
return formatedSeq;
},
_toggleAlignment: function(){
this.$.alignmentContainer.toggle();
},
_toExponential: function(num){
return new Number(num).toExponential(1);
}
});
</script>
</dom-module>