@lipme/vue-blast-viewer 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.vscode/extensions.json +3 -0
  2. package/index.html +13 -0
  3. package/lipme-vue-blast-viewer-1.0.0.tgz +0 -0
  4. package/lipme-vue-blast-viewer-1.0.1.tgz +0 -0
  5. package/lipme-vue-blast-viewer-1.0.2.tgz +0 -0
  6. package/lipme-vue-blast-viewer-1.0.3.tgz +0 -0
  7. package/package.json +7 -7
  8. package/src/App.vue +548 -0
  9. package/src/assets/hero.png +0 -0
  10. package/src/assets/vite.svg +1 -0
  11. package/src/assets/vue.svg +1 -0
  12. package/src/components/BlastAlignmentDetails.vue +581 -0
  13. package/src/components/BlastGraphicViewer.vue +477 -0
  14. package/src/components/BlastHeader.vue +259 -0
  15. package/src/components/BlastHitTable.vue +669 -0
  16. package/src/components/BlastViewer.vue +232 -0
  17. package/src/main.ts +5 -0
  18. package/src/mockData.ts +457 -0
  19. package/src/style.css +258 -0
  20. package/src/types.ts +59 -0
  21. package/tsconfig.app.json +14 -0
  22. package/tsconfig.json +28 -0
  23. package/vite.config.ts +24 -0
  24. package/vue-blast-viewer-1.0.0.tgz +0 -0
  25. package/dist/src/App.vue.d.ts +0 -3
  26. package/dist/src/components/BlastAlignmentDetails.vue.d.ts +0 -10
  27. package/dist/src/components/BlastGraphicViewer.vue.d.ts +0 -12
  28. package/dist/src/components/BlastHeader.vue.d.ts +0 -11
  29. package/dist/src/components/BlastHitTable.vue.d.ts +0 -13
  30. package/dist/src/components/BlastViewer.vue.d.ts +0 -10
  31. package/dist/src/main.d.ts +0 -0
  32. package/dist/src/mockData.d.ts +0 -3
  33. package/dist/src/types.d.ts +0 -53
  34. package/dist/vue-blast-viewer.css +0 -2
  35. package/dist/vue-blast-viewer.js +0 -670
  36. package/dist/vue-blast-viewer.umd.cjs +0 -2
  37. /package/{dist → public}/favicon.svg +0 -0
  38. /package/{dist → public}/icons.svg +0 -0
  39. /package/{dist/src/index.d.ts → src/index.ts} +0 -0
@@ -0,0 +1,477 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed } from 'vue';
3
+ import type { BlastSearch, BlastHit, BlastHsp } from '../types';
4
+
5
+ const props = defineProps<{
6
+ searchData: BlastSearch;
7
+ isProtein: boolean;
8
+ }>();
9
+
10
+ const emit = defineEmits<{
11
+ (e: 'select-hit', hitNum: number): void;
12
+ }>();
13
+
14
+ // SVG Layout Constants
15
+ const svgWidth = 1000;
16
+ const margin = { top: 50, right: 40, bottom: 25, left: 40 };
17
+ const chartWidth = svgWidth - margin.left - margin.right;
18
+ const hitHeight = 10;
19
+ const hitSpacing = 12;
20
+
21
+ // Tooltip State
22
+ const tooltipActive = ref(false);
23
+ const tooltipX = ref(0);
24
+ const tooltipY = ref(0);
25
+ const tooltipData = ref<{
26
+ title: string;
27
+ accession: string;
28
+ bitScore: number;
29
+ evalue: number;
30
+ identity: number;
31
+ coverage: number;
32
+ qFrom: number;
33
+ qTo: number;
34
+ hFrom: number;
35
+ hTo: number;
36
+ } | null>(null);
37
+
38
+ // Active hovered hit index to highlight
39
+ const hoveredHitIndex = ref<number | null>(null);
40
+
41
+ // Compute height based on number of hits
42
+ const svgHeight = computed(() => {
43
+ const numHits = props.searchData.hits.length;
44
+ // If no hits, just height for query
45
+ if (numHits === 0) return margin.top + margin.bottom + 40;
46
+ return margin.top + 30 + numHits * (hitHeight + hitSpacing) + margin.bottom;
47
+ });
48
+
49
+ // Color coding based on Bit Score (standard BLAST ranges)
50
+ const getScoreColor = (score: number) => {
51
+ if (score < 40) return 'var(--blast-score-low)';
52
+ if (score >= 40 && score < 50) return 'var(--blast-score-mid-low)';
53
+ if (score >= 50 && score < 80) return 'var(--blast-score-mid)';
54
+ if (score >= 80 && score < 200) return 'var(--blast-score-mid-high)';
55
+ return 'var(--blast-score-high)'; // >= 200
56
+ };
57
+
58
+ // Calculate Query Coordinate Ticks (5-10 ticks depending on length)
59
+ const ticks = computed(() => {
60
+ const len = props.searchData.query_len;
61
+ let interval = 50;
62
+ if (len > 100 && len <= 500) interval = 100;
63
+ else if (len > 500 && len <= 2000) interval = 200;
64
+ else if (len > 2000 && len <= 10000) interval = 1000;
65
+ else if (len > 10000) interval = 5000;
66
+
67
+ const result = [];
68
+ for (let val = 0; val <= len; val += interval) {
69
+ result.push(val);
70
+ }
71
+ // Make sure the end coordinate is represented if not already
72
+ if (result[result.length - 1] !== len) {
73
+ // If the last tick is too close, replace it or append it
74
+ if (len - result[result.length - 1] < interval / 3) {
75
+ result[result.length - 1] = len;
76
+ } else {
77
+ result.push(len);
78
+ }
79
+ }
80
+ return result.map(val => ({
81
+ value: val,
82
+ x: margin.left + (val / len) * chartWidth
83
+ }));
84
+ });
85
+
86
+ // Coordinate converter helper
87
+ const getX = (coord: number) => {
88
+ return margin.left + ((coord - 1) / props.searchData.query_len) * chartWidth;
89
+ };
90
+
91
+ // Tooltip Handlers
92
+ const showTooltip = (event: MouseEvent, hit: BlastHit, hsp: BlastHsp) => {
93
+ tooltipActive.value = true;
94
+ updateTooltipPosition(event);
95
+
96
+ const mainDesc = hit.description[0];
97
+ const queryLen = props.searchData.query_len;
98
+
99
+ // Calculate coverage for this HSP
100
+ const coveragePercent = Math.round((hsp.align_len / queryLen) * 100);
101
+ // Calculate identity percent
102
+ const identityPercent = Math.round((hsp.identity / hsp.align_len) * 100);
103
+
104
+ tooltipData.value = {
105
+ title: mainDesc.title,
106
+ accession: mainDesc.accession,
107
+ bitScore: hsp.bit_score,
108
+ evalue: hsp.evalue,
109
+ identity: identityPercent,
110
+ coverage: coveragePercent,
111
+ qFrom: hsp.query_from,
112
+ qTo: hsp.query_to,
113
+ hFrom: hsp.hit_from,
114
+ hTo: hsp.hit_to
115
+ };
116
+ };
117
+
118
+ const updateTooltipPosition = (event: MouseEvent) => {
119
+ // Center tooltip slightly above cursor
120
+ const offsetTarget = event.currentTarget as SVGGraphicsElement;
121
+ const svgEl = offsetTarget.ownerSVGElement;
122
+ if (!svgEl) return;
123
+
124
+ const rect = svgEl.getBoundingClientRect();
125
+ tooltipX.value = event.clientX - rect.left + 15;
126
+ tooltipY.value = event.clientY - rect.top + 15;
127
+ };
128
+
129
+ const hideTooltip = () => {
130
+ tooltipActive.value = false;
131
+ tooltipData.value = null;
132
+ hoveredHitIndex.value = null;
133
+ };
134
+
135
+ const selectHit = (hitNum: number) => {
136
+ emit('select-hit', hitNum);
137
+ };
138
+ </script>
139
+
140
+ <template>
141
+ <div class="blast-graphics glass-panel fade-in">
142
+ <div class="graphics-header">
143
+ <h2>Graphical Alignment Overview</h2>
144
+ <p>Hover over alignment bars for details. Click to view full text alignments.</p>
145
+ </div>
146
+
147
+ <!-- Color Code Legend -->
148
+ <div class="color-legend">
149
+ <div class="legend-title">Color Key for Alignment Scores:</div>
150
+ <div class="legend-items">
151
+ <div class="legend-item">
152
+ <span class="legend-color" style="background-color: var(--blast-score-low)"></span>
153
+ <span class="legend-label">&lt; 40</span>
154
+ </div>
155
+ <div class="legend-item">
156
+ <span class="legend-color" style="background-color: var(--blast-score-mid-low)"></span>
157
+ <span class="legend-label">40-50</span>
158
+ </div>
159
+ <div class="legend-item">
160
+ <span class="legend-color" style="background-color: var(--blast-score-mid)"></span>
161
+ <span class="legend-label">50-80</span>
162
+ </div>
163
+ <div class="legend-item">
164
+ <span class="legend-color" style="background-color: var(--blast-score-mid-high)"></span>
165
+ <span class="legend-label">80-200</span>
166
+ </div>
167
+ <div class="legend-item">
168
+ <span class="legend-color" style="background-color: var(--blast-score-high)"></span>
169
+ <span class="legend-label">&ge; 200</span>
170
+ </div>
171
+ </div>
172
+ </div>
173
+
174
+ <!-- Alignment Map container -->
175
+ <div class="svg-container">
176
+ <svg :viewBox="`0 0 ${svgWidth} ${svgHeight}`" width="100%" class="alignment-svg">
177
+ <!-- Grid lines behind coordinates -->
178
+ <g class="grid-lines">
179
+ <line
180
+ v-for="tick in ticks"
181
+ :key="'grid-' + tick.value"
182
+ :x1="tick.x"
183
+ :y1="margin.top - 10"
184
+ :x2="tick.x"
185
+ :y2="svgHeight - margin.bottom"
186
+ stroke="var(--bg-overlay-hover)"
187
+ stroke-dasharray="4,4"
188
+ />
189
+ </g>
190
+
191
+ <!-- Coordinate Ruler / Query Bar -->
192
+ <g class="query-ruler">
193
+ <!-- Query Bar -->
194
+ <rect
195
+ :x="margin.left"
196
+ :y="margin.top - 20"
197
+ :width="chartWidth"
198
+ height="10"
199
+ rx="5"
200
+ fill="var(--color-primary-glow)"
201
+ stroke="var(--color-primary)"
202
+ stroke-width="1.5"
203
+ />
204
+ <text
205
+ :x="margin.left"
206
+ :y="margin.top - 28"
207
+ fill="var(--color-primary)"
208
+ font-size="11"
209
+ font-weight="600"
210
+ >
211
+ QUERY ({{ searchData.query_len }} {{ isProtein ? 'aa' : 'bp' }})
212
+ </text>
213
+
214
+ <!-- Ticks -->
215
+ <g v-for="tick in ticks" :key="'tick-' + tick.value">
216
+ <line
217
+ :x1="tick.x"
218
+ :y1="margin.top - 10"
219
+ :x2="tick.x"
220
+ :y2="margin.top - 4"
221
+ stroke="var(--text-secondary)"
222
+ stroke-width="1.5"
223
+ />
224
+ <text
225
+ :x="tick.x"
226
+ :y="margin.top + 8"
227
+ text-anchor="middle"
228
+ fill="var(--text-secondary)"
229
+ font-family="var(--font-mono)"
230
+ font-size="10"
231
+ >
232
+ {{ tick.value }}
233
+ </text>
234
+ </g>
235
+ </g>
236
+
237
+ <!-- Alignment Matches Stack -->
238
+ <g class="hits-group" transform="translate(0, 30)">
239
+ <g
240
+ v-for="(hit, index) in searchData.hits"
241
+ :key="hit.num"
242
+ class="hit-row"
243
+ :class="{ 'is-hovered': hoveredHitIndex === index }"
244
+ @click="selectHit(hit.num)"
245
+ >
246
+ <!-- Background highlight bar on hover -->
247
+ <rect
248
+ :x="margin.left - 5"
249
+ :y="margin.top + index * (hitHeight + hitSpacing) - 4"
250
+ :width="chartWidth + 10"
251
+ :height="hitHeight + 8"
252
+ fill="var(--bg-overlay-hover)"
253
+ class="row-hover-bg"
254
+ rx="4"
255
+ />
256
+
257
+ <!-- Connection line for multiple HSPs -->
258
+ <line
259
+ v-if="hit.hsps.length > 1"
260
+ :x1="getX(Math.min(...hit.hsps.map((h: any) => h.query_from)))"
261
+ :y1="margin.top + index * (hitHeight + hitSpacing) + hitHeight/2"
262
+ :x2="getX(Math.max(...hit.hsps.map((h: any) => h.query_to)))"
263
+ :y2="margin.top + index * (hitHeight + hitSpacing) + hitHeight/2"
264
+ stroke="var(--text-muted)"
265
+ stroke-width="1"
266
+ stroke-dasharray="3,3"
267
+ />
268
+
269
+ <!-- Hits/HSPs Alignments -->
270
+ <rect
271
+ v-for="hsp in hit.hsps"
272
+ :key="hsp.num"
273
+ :x="getX(hsp.query_from)"
274
+ :y="margin.top + index * (hitHeight + hitSpacing)"
275
+ :width="Math.max(2, getX(hsp.query_to) - getX(hsp.query_from))"
276
+ :height="hitHeight"
277
+ :fill="getScoreColor(hsp.bit_score)"
278
+ class="hsp-bar"
279
+ rx="2"
280
+ @mouseenter="hoveredHitIndex = index; showTooltip($event, hit, hsp)"
281
+ @mousemove="updateTooltipPosition"
282
+ @mouseleave="hideTooltip"
283
+ />
284
+
285
+ <!-- Hit Label on left (Optional indicator) -->
286
+ <text
287
+ :x="margin.left - 8"
288
+ :y="margin.top + index * (hitHeight + hitSpacing) + 8"
289
+ text-anchor="end"
290
+ fill="var(--text-muted)"
291
+ font-family="var(--font-mono)"
292
+ font-size="9"
293
+ class="hit-index-label"
294
+ >
295
+ {{ index + 1 }}
296
+ </text>
297
+ </g>
298
+ </g>
299
+ </svg>
300
+
301
+ <!-- SVG Tooltip -->
302
+ <div
303
+ v-if="tooltipActive && tooltipData"
304
+ class="blast-tooltip"
305
+ :style="{ left: tooltipX + 'px', top: tooltipY + 'px' }"
306
+ >
307
+ <div class="tooltip-title">{{ tooltipData.title }}</div>
308
+ <div class="tooltip-acc">Accession: {{ tooltipData.accession }}</div>
309
+ <hr class="tooltip-divider" />
310
+ <table>
311
+ <tr>
312
+ <td class="label">Bit Score:</td>
313
+ <td class="val">{{ tooltipData.bitScore.toFixed(1) }}</td>
314
+ </tr>
315
+ <tr>
316
+ <td class="label">E-value:</td>
317
+ <td class="val">{{ tooltipData.evalue === 0 ? '0.0' : tooltipData.evalue }}</td>
318
+ </tr>
319
+ <tr>
320
+ <td class="label">Identities:</td>
321
+ <td class="val">{{ tooltipData.identity }}%</td>
322
+ </tr>
323
+ <tr>
324
+ <td class="label">Query Cover:</td>
325
+ <td class="val">{{ tooltipData.coverage }}%</td>
326
+ </tr>
327
+ <tr>
328
+ <td class="label">Query:</td>
329
+ <td class="val">{{ tooltipData.qFrom }} .. {{ tooltipData.qTo }}</td>
330
+ </tr>
331
+ <tr>
332
+ <td class="label">Subject:</td>
333
+ <td class="val">{{ tooltipData.hFrom }} .. {{ tooltipData.hTo }}</td>
334
+ </tr>
335
+ </table>
336
+ </div>
337
+ </div>
338
+ </div>
339
+ </template>
340
+
341
+ <style scoped>
342
+ .blast-graphics {
343
+ padding: 1.5rem;
344
+ margin-bottom: 2rem;
345
+ }
346
+
347
+ .graphics-header {
348
+ margin-bottom: 1.25rem;
349
+ }
350
+
351
+ .graphics-header h2 {
352
+ font-size: 1.15rem;
353
+ font-weight: 600;
354
+ margin-bottom: 0.25rem;
355
+ }
356
+
357
+ .graphics-header p {
358
+ font-size: 0.85rem;
359
+ color: var(--text-secondary);
360
+ }
361
+
362
+ .color-legend {
363
+ display: flex;
364
+ flex-wrap: wrap;
365
+ align-items: center;
366
+ gap: 0.75rem;
367
+ padding: 0.75rem 1rem;
368
+ background: var(--bg-depth-light);
369
+ border-radius: var(--radius-sm);
370
+ margin-bottom: 1.5rem;
371
+ border: 1px solid var(--border-color);
372
+ }
373
+
374
+ .legend-title {
375
+ font-size: 0.8rem;
376
+ font-weight: 600;
377
+ color: var(--text-secondary);
378
+ }
379
+
380
+ .legend-items {
381
+ display: flex;
382
+ flex-wrap: wrap;
383
+ gap: 1rem;
384
+ }
385
+
386
+ .legend-item {
387
+ display: flex;
388
+ align-items: center;
389
+ gap: 0.35rem;
390
+ }
391
+
392
+ .legend-color {
393
+ width: 14px;
394
+ height: 14px;
395
+ border-radius: 3px;
396
+ display: inline-block;
397
+ border: 1px solid var(--bg-overlay-2);
398
+ }
399
+
400
+ .legend-label {
401
+ font-family: var(--font-mono);
402
+ font-size: 0.75rem;
403
+ color: var(--text-primary);
404
+ font-weight: 500;
405
+ }
406
+
407
+ .svg-container {
408
+ position: relative;
409
+ width: 100%;
410
+ overflow-x: auto;
411
+ background: var(--bg-depth-light);
412
+ border-radius: var(--radius-sm);
413
+ border: 1px solid var(--bg-overlay-hover);
414
+ }
415
+
416
+ .alignment-svg {
417
+ display: block;
418
+ min-width: 700px;
419
+ }
420
+
421
+ .hit-row {
422
+ cursor: pointer;
423
+ }
424
+
425
+ .row-hover-bg {
426
+ opacity: 0;
427
+ transition: opacity var(--transition-fast);
428
+ }
429
+
430
+ .hit-row:hover .row-hover-bg,
431
+ .hit-row.is-hovered .row-hover-bg {
432
+ opacity: 1;
433
+ }
434
+
435
+ .hsp-bar {
436
+ transition: transform var(--transition-fast), filter var(--transition-fast);
437
+ }
438
+
439
+ .hit-row:hover .hsp-bar {
440
+ filter: brightness(1.2);
441
+ /* transform: scaleY(1.1); */
442
+ }
443
+
444
+ .hit-index-label {
445
+ transition: fill var(--transition-fast);
446
+ }
447
+
448
+ .hit-row:hover .hit-index-label {
449
+ fill: var(--text-primary);
450
+ }
451
+
452
+ /* Tooltip Custom Styles override */
453
+ .tooltip-title {
454
+ font-weight: 600;
455
+ color: var(--text-primary);
456
+ margin-bottom: 0.25rem;
457
+ font-size: 0.85rem;
458
+ overflow: hidden;
459
+ text-overflow: ellipsis;
460
+ display: -webkit-box;
461
+ -webkit-line-clamp: 2;
462
+ -webkit-box-orient: vertical;
463
+ }
464
+
465
+ .tooltip-acc {
466
+ font-family: var(--font-mono);
467
+ font-size: 0.75rem;
468
+ color: var(--color-primary);
469
+ margin-bottom: 0.5rem;
470
+ }
471
+
472
+ .tooltip-divider {
473
+ border: none;
474
+ border-top: 1px solid var(--bg-overlay-2);
475
+ margin: 0.5rem 0;
476
+ }
477
+ </style>