-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblast-view.html
350 lines (338 loc) · 15.5 KB
/
blast-view.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<link rel="import" href="paginator-element.html">
<link rel="import" href="blast-item.html">
<link rel="import" href="blast-styles.html">
<link rel="import" href="d3-styles.html">
<link rel="import" href="external-scripts.html">
<script src="colorbar/index.js"></script>
<!--
`blast-view`
View presenting blast search results annotations.
#### Example
<blast-view nx-config='{"entry": "P52701"}'></blast-view>
@demo demo/blast-view-demo.html
-->
<dom-module id="blast-view">
<template>
<style include="blast-styles">
:host {
display: block;
overflow-y: auto;
background: #ffffff;
padding: 10px;
--paper-toggle-button-checked-button-color: #428bca;
--paper-toggle-button-checked-bar-color: #428bca;
}
p {
margin: 0 0 5px;
}
.btn-sm {
padding: 1px 3px 0 0;
margin: 0 5px 3px 5px;
background: #337ab7;
color: white;
}
iron-icon {
padding-bottom: 2px;
color: #337ab7;
}
#reloadButton {
color: white;
}
button > iron-icon {
color: white;
zoom: 75%;
}
.number-input {
width: 40px;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
#evalue-input {
width: 50px;
}
.mode-toggle {
display: inline-flex;
margin-top: -3px;
}
.toggle-label {
padding: 5px 10px 5px 3px;
}
.control-header {
margin: 10px 0 50px;
}
#acceptButton {
zoom: 125%;
}
#resubmitSpinner {
width: 24px;
height: 24px;
vertical-align: top;
}
#blastParametersContainer {
background-color: white;
border-bottom: solid grey 1px;
padding-left: 15px;
}
.matrixDropdown{
margin-left: 5px;
color: #337ab7;
border-bottom: 1px solid #337ab7;
}
/*#shortenedSequence {
color: #337ab7;
}*/
paper-toggle-button > div#toggleBar {
height: 104%;
width: 74%;
}
paper-toggle-button > div#toggleButton {
width: 70%;
margin-top: 3px;
}
</style>
<div id="blastParametersContainer">
<paper-spinner-lite id="spinner" active></paper-spinner-lite>
<template is="dom-if" if="[[params]]">
<p><span class="quiet bold">
<template is="dom-if" if="[[entry]]">Protein [[entry]]</template>
<template is="dom-if" if="[[isoform]]">, isoform [[isoform]]</template>
</span></p>
<p>
<span class="quiet bold">Sequence</span>
<span id="sequenceContainer">
<!--commented code produces an input field with sequence, it should be uncommented when api accepts post query for blast by sequence-->
<span id="shortenedSequence" class="pre"><!-- on-tap="_editSequence">-->[[_shortenedSequence()]]</span>
<!--<iron-icon id="editButton" icon="image:edit" on-tap="_editSequence"></iron-icon>
<iron-autogrow-textarea id="sequenceEditor" value="[[sequence]]" hidden></iron-autogrow-textarea>
<iron-icon id="acceptButton" icon="done" on-tap="_updateSequence" hidden></iron-icon>-->
</span>
<span class="quiet bold">([[sequence.length]] AA)</span>
</p>
<div class="quiet">
<p>Query in all human sequences in neXtProt ([[params.db_num]] sequences, [[params.db_len]] amino acids)</p>
Similarity matrix:
<select class="matrixDropdown" on-change="_setMatrix">
<template is="dom-repeat" items="[[matrices]]" >
<option value="[[item]]" selected="[[_selectedMatrix(item)]]">[[item]]</option>
</template>
</select>
<p class="blast-params">
Expect: <input is="iron-input" id="evalue-input" class="number-input" bind-value="{{evalue}}"> ; filter: [[_getFilterState()]]; gap-open: <input is="iron-input" class="number-input" bind-value="{{gapopen}}"> ; gap-extend: <input is="iron-input" class="number-input" bind-value="{{gapextend}}">
<button id="reloadButton" class="btn btn-sm" on-tap="getByIsoform"><iron-icon icon="icons:autorenew"></iron-icon> Reload</button>
<paper-spinner-lite id="resubmitSpinner"></paper-spinner-lite>
</p>
<p>Program version: [[params.version]]</p>
</div>
</template>
<div id="scale"></div>
<span class="bold" style="color: red;">[[error]]</span>
</div>
<template is="dom-if" if="[[results.length]]">
<div class="column control-header">
<div class="col-lg-6">Sequences [[from]] to [[to]] of [[results.length]]</div>
<div class="col-lg-1">
show
<select on-change="_changePageSize">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<div class="col-lg-2">
<div class="mode-toggle"><span class="toggle-label">summary</span><paper-toggle-button checked="{{showAlignment}}"></paper-toggle-button><span class="toggle-label">alignments</span></div>
</div>
</div>
<div class="beanlist-beans-header column span-24">
<div class="column nomargin">
<div class="col-lg-6 bold">Query hit (click to show/hide alignment)</div>
<div class="col-lg-2 bold">Target hit</div>
<div class="col-lg-1 nomargin hright bold">Target len</div>
<div class="col-lg-1 nomargin hright bold">Identity</div>
<div class="col-lg-1 nomargin hright bold">Tot. score</div>
<div class="col-lg-1 hright bold">E-value</div>
</div>
</div>
</template>
<div class="col-lg-12">
<paginator-element entries="{{results}}" onDemand="{{false}}" page="{{page}}" layout="blast-item" bind-attribute="showAlignment" bind-value="[[showAlignment]]" page-size="[[pageSize]]" from="{{from}}" to="{{to}}" related-entry-count="[[results.length]]"></paginator-element>
</div>
</template>
<script>
Polymer({
is: 'blast-view',
properties: {
nxConfig: {
type: Object,
value: {}
},
sequence: {
type: String
},
title: {
type: String,
value: "blast"
},
isoform: {
type: String
},
begin: {
type: Number
},
end: {
type: Number
},
matrix: {
type: String,
value: "BLOSUM62",
observer: "_checkMatrix"
},
evalue: {
type: Number,
value: 10
},
gapopen: {
type: Number,
value: 11
},
gapextend: {
type: Number,
value: 1
},
showAlignment: {
type: Boolean,
value: false
},
page: {
type: Number,
notify: true
},
pageSize: {
type: Number,
value: 10
},
results: {
type: Array,
notify: true
},
matrices: {
type: Array,
value: ["BLOSUM45", "BLOSUM50", "BLOSUM62", "BLOSUM80", "BLOSUM90", "PAM250", "PAM30", "PAM70"]
}
},
attached: function(){
this.nx = new Nextprot.Client("neXtProt blast view", "Calipho Group");
if (this.nxConfig.env) this.nx.updateEnvironment(this.nxConfig.env);
if (this.nxConfig.isoform) this.isoform = this.nxConfig.isoform;
if (this.nxConfig.sequence) this.sequence = this.nxConfig.sequence;
if (this.nxConfig.begin) this.begin = this.nxConfig.begin;
if (this.nxConfig.end) this.end = this.nxConfig.end;
if (this.isoform) this.getByIsoform();
else if(this.sequence) this.getBySequence();
},
getByIsoform: function(){
var self = this;
if (this.$$("#resubmitSpinner")) this.$$("#resubmitSpinner").active = true;
this.nx.getBlastByIsoform(this.isoform, this.matrix, this.evalue, this.gapopen, this.gapextend, this.begin, this.end)
.then(function(response){
Polymer.RenderStatus.afterNextRender(self, function() {self._processResponse(response)});
});
this.entry = this.isoform.split("-")[0];
},
getBySequence: function(){
var self=this;
this.$$("#resubmitSpinner").active = true;
this.nx.getBlastBySequence(this.sequence, this.title, this.matrix, this.evalue, this.gapopen, this.gapextend)
.then(function(response){
Polymer.RenderStatus.afterNextRender(self, function() {self._processResponse(response)});
});
this.entry = this.nxConfig.entry;
this.isoform = undefined;
},
_processResponse: function(response){
this.results = [];
this.$.spinner.active = false;
this.$.spinner.hidden = true;
if (this.$$("#resubmitSpinner")) this.$$("#resubmitSpinner").active = false;
if (response.error) {
this.error = Object.values(response.error.causes);
return false;
} else this.error = "";
if(!this.$$("#scale").children.length) this._colorScale();
for (var i in response.data.results.search.hits) {
response.data.results.search.hits[i].queryLength = response.data.params.sequence.length;
for (var j in response.data.results.search.hits[i].hsps){
response.data.results.search.hits[i].hsps[j].color = this.scale(response.data.results.search.hits[i].hsps[j].identity_percent);
}
}
response.data.params.version = response.data.version;
response.data.params.db_num = response.data.results.search.stat.db_num;
response.data.params.db_len = response.data.results.search.stat.db_len;
response.data.params.message = response.data.results.search.message;
this.params=response.data.params;
this.evalue=this.params.expect;
this.gapopen=this.params.gap_open;
this.gapextend=this.params.gap_extend;
this.sequence = this.params.sequence;
Polymer.RenderStatus.afterNextRender(this, function() {
this.results = response.data.results.search.hits;
});
},
_setMatrix: function(event){
this.matrix = event.srcElement.value;
},
_checkMatrix: function(newValue, oldValue){
this.async(function(){
if (this.matrices.indexOf(newValue) === -1) {
console.warn(this.matrix+" is not recognized as a valid BLAST substitution matrix. "+oldValue+" matrix will be used instead.");
this.matrix = oldValue;
}
});
},
_selectedMatrix: function(matrix) {
return matrix === "BLOSUM62";
},
_colorScale: function(){
var svg = d3.select(this).select("#scale").append("svg")
.attr("width",600).attr("height",50)
.append("text").text("Color code for identity (%)").attr("x", 0).attr("y", 20);
this.scale = d3.scale.linear().range(["red","tomato","yellow","green"]).domain([0,35,70,100]);
colorbar = Colorbar()
.origin([190,5])
.scale(this.scale).barlength(400).thickness(10)
.orient("horizontal");
bar = d3.select(this).select("#scale").select("svg").append("g").attr("id", "colorbar");
this.colorbarObject = d3.select(this).select("#colorbar").call(colorbar);
},
_shortenedSequence: function(){
var sequenceLength = this.sequence.length;
if (sequenceLength>55) return this.sequence.substring(0,27)+"..."+this.sequence.substring(sequenceLength-27, sequenceLength)
return this.sequence;
},
_editSequence: function(){
this.$$("#sequenceEditor").hidden = false;
this.$$("#acceptButton").hidden = false;
this.$$("#shortenedSequence").hidden = true;
this.$$("#editButton").hidden = true;
},
_updateSequence: function(event){
this.sequence = this.$$("#sequenceEditor").value;
this.$$("#shortenedSequence").innerHTML = this._shortenedSequence();
this.$$("#sequenceEditor").hidden = true;
this.$$("#acceptButton").hidden = true;
this.$$("#shortenedSequence").hidden = false;
this.$$("#editButton").hidden = false;
},
_getFilterState: function(){
return this.params.filter === "F" ? "false" : "true";
},
_changePageSize: function(evt){
this.pageSize = new Number(evt.target[evt.target.selectedIndex].value);
},
pointIdentity: function(identity){
this.colorbarObject.pointTo(identity)
}
});
</script>
</dom-module>