File size: 49,196 Bytes
7edc0cc
 
 
 
 
 
0000048
 
7edc0cc
0000048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
 
 
 
0000048
 
 
 
 
 
 
 
 
 
7edc0cc
0000048
7edc0cc
 
0000048
7edc0cc
0000048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
0000048
 
 
 
 
 
 
 
 
 
7edc0cc
0000048
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
 
 
 
 
 
0000048
 
7edc0cc
 
 
0000048
 
 
7edc0cc
 
 
0000048
7edc0cc
 
 
0000048
 
 
7edc0cc
0000048
7edc0cc
0000048
7edc0cc
 
 
0000048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
 
 
 
 
 
0000048
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
 
0000048
 
 
 
 
 
 
 
7edc0cc
0000048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
0000048
7edc0cc
 
 
 
 
 
 
 
0000048
7edc0cc
 
 
0000048
7edc0cc
 
 
0000048
 
 
 
 
 
 
 
7edc0cc
 
 
0000048
 
 
 
 
7edc0cc
 
 
0000048
7edc0cc
0000048
 
 
 
 
7edc0cc
 
0000048
7edc0cc
 
 
0000048
7edc0cc
 
0000048
7edc0cc
 
0000048
7edc0cc
0000048
 
7edc0cc
 
 
0000048
 
 
 
 
 
 
7edc0cc
0000048
 
7edc0cc
 
 
0000048
 
 
 
 
 
 
 
7edc0cc
0000048
7edc0cc
 
0000048
 
 
 
 
 
 
 
 
 
 
 
7edc0cc
 
0000048
7edc0cc
 
 
0000048
 
 
7edc0cc
 
0000048
 
 
 
 
7edc0cc
 
 
 
 
0000048
 
7edc0cc
 
0000048
7edc0cc
 
0000048
7edc0cc
0000048
 
7edc0cc
0000048
7edc0cc
 
0000048
7edc0cc
 
 
 
 
 
 
 
0000048
7edc0cc
 
 
 
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>SeqTypeAI — NGS Library Classifier</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=DM+Sans:wght@300;400;500&family=DM+Mono&display=swap" rel="stylesheet">
<style>
:root{
  --bg:#ffffff;--bg2:#f6f6f4;--bg3:#efefec;
  --text:#18181a;--text2:#5c5c60;--text3:#9c9ca0;
  --border:rgba(0,0,0,0.10);--border2:rgba(0,0,0,0.18);
  --blue:#2563a8;--bluebg:#EBF3FC;--bluedark:#1a4a82;
  --green:#1a6e42;--greenbg:#e8f5ee;
  --amber:#8a5200;--amberbg:#fef3dc;
  --red:#992020;--redbg:#fceaea;
  --r:6px;--rl:10px;
  --serif:'DM Serif Display',Georgia,serif;
  --sans:'DM Sans',-apple-system,sans-serif;
  --mono:'DM Mono',monospace;
}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:var(--sans);font-size:15px;line-height:1.65;color:var(--text);background:var(--bg);min-height:100vh;display:flex;flex-direction:column}
header{background:var(--bg);border-bottom:1px solid var(--border);padding:0 32px;display:flex;align-items:center;height:56px;position:sticky;top:0;z-index:100}
.header-brand{display:flex;align-items:baseline;gap:0;margin-right:40px;text-decoration:none}
.header-brand .name{font-family:var(--serif);font-size:20px;color:var(--text);letter-spacing:-0.01em}
.header-brand .tag{font-size:11px;color:var(--text3);margin-left:8px;font-weight:300;letter-spacing:0.02em}
nav{display:flex;align-items:center;gap:0;flex:1}
nav a{font-size:13px;font-weight:400;color:var(--text2);text-decoration:none;padding:0 14px;height:56px;display:flex;align-items:center;border-bottom:2px solid transparent;transition:color .15s,border-color .15s;letter-spacing:0.01em;cursor:pointer}
nav a:hover{color:var(--text)}
nav a.active{color:var(--text);border-bottom-color:var(--text);font-weight:500}
.header-logo{height:28px;width:auto;margin-left:auto;opacity:0.9}
.header-ver{font-size:11px;font-family:var(--mono);color:var(--text3);margin-left:16px}
main{flex:1;max-width:1140px;margin:0 auto;padding:32px 24px;width:100%}
.page{display:none}.page.active{display:block}
.hero{padding:40px 0 32px;max-width:680px}
.hero h1{font-family:var(--serif);font-size:38px;line-height:1.15;letter-spacing:-0.02em;margin-bottom:16px}
.hero p{font-size:15px;color:var(--text2);line-height:1.75;margin-bottom:8px}
.hero-badges{display:flex;flex-wrap:wrap;gap:6px;margin-top:18px}
.badge{font-size:11px;padding:3px 9px;border-radius:20px;background:var(--bg2);color:var(--text2);border:1px solid var(--border);font-family:var(--mono)}
.badge.hi{background:var(--bluebg);color:var(--bluedark);border-color:rgba(37,99,168,.2)}
.upload-section{display:grid;grid-template-columns:1fr 320px;gap:24px;align-items:start;margin-top:8px}
.drop-zone{border:1.5px dashed var(--border2);border-radius:var(--rl);padding:40px 28px;text-align:center;cursor:pointer;transition:all .15s;background:var(--bg)}
.drop-zone:hover,.drop-zone.drag{border-color:var(--blue);background:var(--bluebg)}
.drop-zone h2{font-size:15px;font-weight:500;margin-bottom:5px}
.drop-zone p{font-size:12px;color:var(--text2)}
.drop-icon{width:36px;height:36px;margin:0 auto 12px;color:var(--text3)}
.how-card{background:var(--bg2);border-radius:var(--rl);padding:20px;border:1px solid var(--border)}
.how-card h3{font-size:12px;font-weight:500;text-transform:uppercase;letter-spacing:.1em;color:var(--text3);margin-bottom:14px}
.how-step{display:flex;gap:10px;margin-bottom:12px;align-items:flex-start}
.how-num{width:20px;height:20px;border-radius:50%;background:var(--bg);border:1px solid var(--border2);display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:500;color:var(--text2);flex-shrink:0;margin-top:2px}
.how-step p{font-size:13px;color:var(--text2);line-height:1.5}
.how-step strong{color:var(--text);font-weight:500}
.assay-grid{display:flex;flex-wrap:wrap;gap:4px;margin-top:14px;padding-top:14px;border-top:1px solid var(--border)}
.pill{font-size:11px;padding:2px 7px;border-radius:4px;background:var(--bg);color:var(--text2);display:inline-block;margin:2px;font-family:var(--mono);border:1px solid var(--border)}
.card{background:var(--bg);border:1px solid var(--border);border-radius:var(--r);padding:18px}
.card-label{font-size:10px;color:var(--text3);text-transform:uppercase;letter-spacing:.12em;margin-bottom:10px;font-weight:500;display:flex;align-items:center;gap:6px}
.results-grid{display:grid;grid-template-columns:minmax(0,300px) minmax(0,1fr);gap:16px;align-items:start}
.top-label{font-family:var(--serif);font-size:22px;line-height:1.2;margin-bottom:4px}
.conf-big{font-size:34px;font-weight:300;font-family:var(--mono)}
.bar-row{display:flex;align-items:center;gap:8px;padding:3px 0}
.bar-track{flex:1;height:4px;background:var(--bg3);border-radius:2px;overflow:hidden}
.bar-fill{height:100%;border-radius:2px}
.frow{display:flex;justify-content:space-between;align-items:center;padding:4px 0;border-bottom:1px solid var(--border)}
.mono{font-family:var(--mono);font-size:12px}
.tabs{display:flex;border-bottom:1px solid var(--border);margin-bottom:16px}
.tab{padding:8px 16px;font-size:13px;cursor:pointer;border-bottom:2px solid transparent;color:var(--text2);background:none;border-top:none;border-left:none;border-right:none;margin-bottom:-1px;font-family:var(--sans)}
.tab.active{border-bottom-color:var(--text);color:var(--text);font-weight:500}
.tab-panel{display:none}.tab-panel.active{display:block}
.step{display:flex;gap:12px;margin-bottom:6px}
.step-num{width:22px;height:22px;border-radius:50%;background:var(--bg2);border:1px solid var(--border2);display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:500;flex-shrink:0;color:var(--text2)}
.step-name{font-size:13px;font-weight:500;display:flex;align-items:center;gap:6px;margin-bottom:3px}
.step-role{font-size:11px;background:var(--bg2);color:var(--text2);padding:1px 6px;border-radius:4px}
.cmd{font-size:11px;font-family:var(--mono);background:var(--bg2);padding:5px 8px;border-radius:4px;color:var(--text2);word-break:break-all;line-height:1.5}
.qc-row{padding:9px 11px;margin-bottom:6px;border-radius:6px;border:1px solid var(--border)}
.dot{width:8px;height:8px;border-radius:50%;display:inline-block;margin-right:5px;flex-shrink:0}
.badge-good{background:var(--greenbg);color:var(--green)}
.badge-warn{background:var(--amberbg);color:var(--amber)}
.badge-poor{background:var(--redbg);color:var(--red)}
.chat-wrap{display:flex;flex-direction:column;gap:8px;min-height:280px;max-height:380px;overflow-y:auto;margin-bottom:12px}
.chat-bubble{max-width:88%;padding:8px 12px;border-radius:10px;font-size:13px;line-height:1.6;white-space:pre-wrap}
.chat-bubble.user{background:var(--bluebg);border-bottom-right-radius:3px;align-self:flex-end;margin-left:auto}
.chat-bubble.assistant{background:var(--bg2);border-bottom-left-radius:3px}
.chat-input-row{display:flex;gap:8px;border-top:1px solid var(--border);padding-top:10px}
/* docs */
.doc-layout{display:grid;grid-template-columns:200px 1fr;gap:40px;align-items:start}
.doc-nav{position:sticky;top:76px}
.doc-nav a{display:block;font-size:13px;color:var(--text2);text-decoration:none;padding:5px 0 5px 12px;border-left:2px solid transparent;margin-bottom:2px;cursor:pointer}
.doc-nav a:hover,.doc-nav a.dn-active{color:var(--text);border-left-color:var(--text)}
.doc-nav-section{font-size:10px;font-weight:500;text-transform:uppercase;letter-spacing:.1em;color:var(--text3);margin:16px 0 6px 12px}
.doc-content h2{font-family:var(--serif);font-size:26px;letter-spacing:-0.01em;margin-bottom:10px;padding-top:40px;border-top:1px solid var(--border)}
.doc-content h2:first-child{border-top:none;padding-top:0}
.doc-content h3{font-size:15px;font-weight:500;margin:20px 0 8px}
.doc-content p{color:var(--text2);margin-bottom:12px;line-height:1.75}
.doc-content code{font-family:var(--mono);font-size:12px;background:var(--bg2);padding:2px 5px;border-radius:3px;color:var(--text)}
.doc-content pre{font-family:var(--mono);font-size:12px;background:var(--bg2);padding:14px 16px;border-radius:var(--r);overflow-x:auto;margin-bottom:14px;line-height:1.6;border:1px solid var(--border)}
.doc-table{width:100%;border-collapse:collapse;margin-bottom:16px;font-size:13px}
.doc-table th{text-align:left;padding:7px 12px;background:var(--bg2);font-weight:500;font-size:11px;text-transform:uppercase;letter-spacing:.07em;color:var(--text3);border-bottom:1px solid var(--border)}
.doc-table td{padding:8px 12px;border-bottom:1px solid var(--border);color:var(--text2);vertical-align:top;line-height:1.6}
.doc-table td:first-child{font-family:var(--mono);font-size:12px;color:var(--text);white-space:nowrap}
.doc-note{padding:12px 16px;border-radius:var(--r);background:var(--bluebg);border:1px solid rgba(37,99,168,.2);margin-bottom:16px;font-size:13px;color:var(--bluedark);line-height:1.6}
/* about */
.about-grid{display:grid;grid-template-columns:1fr 1fr;gap:24px;margin-top:16px}
.about-card{background:var(--bg2);border-radius:var(--rl);padding:24px;border:1px solid var(--border)}
.about-card h3{font-family:var(--serif);font-size:18px;margin-bottom:10px}
.about-card p{font-size:13px;color:var(--text2);line-height:1.7}
.stat-row{display:flex;gap:40px;margin:28px 0;flex-wrap:wrap}
.stat .num{font-family:var(--serif);font-size:36px;color:var(--text);line-height:1}
.stat .lbl{font-size:12px;color:var(--text3);margin-top:4px}
/* common */
input[type=text]{flex:1;height:36px;border:1px solid var(--border2);border-radius:var(--r);padding:0 12px;font-size:13px;outline:none;font-family:var(--sans)}
input[type=text]:focus{border-color:var(--blue)}
button{height:36px;padding:0 16px;border:1px solid var(--border2);border-radius:var(--r);background:var(--bg);font-size:13px;cursor:pointer;font-family:var(--sans)}
button:hover{background:var(--bg2)}button:disabled{opacity:0.4;cursor:default}
.btn-primary{background:var(--text);color:var(--bg);border-color:var(--text)}
.btn-primary:hover{background:#333}
.err-box{padding:12px 14px;border-radius:var(--r);background:var(--redbg);color:var(--red);font-size:13px;margin-top:12px;display:none;line-height:1.6}
.spinner{width:30px;height:30px;border:2px solid var(--border);border-top-color:var(--text);border-radius:50%;animation:spin .8s linear infinite;margin:0 auto}
@keyframes spin{to{transform:rotate(360deg)}}
@media(max-width:800px){
  .upload-section,.results-grid,.doc-layout,.about-grid{grid-template-columns:1fr}
  .doc-nav{display:none}
  header{padding:0 16px}
  .header-brand .tag,.header-ver{display:none}
  main{padding:20px 16px}
  .hero h1{font-size:28px}
  .hero{padding:24px 0 20px}
}
</style>
</head>
<body>
<header>
  <a class="header-brand" onclick="showPage('classify')">
    <span class="name">SeqTypeAI</span>
    <span class="tag">NGS library classifier</span>
  </a>
  <nav>
    <a class="active" id="nav-classify" onclick="showPage('classify')">Classify</a>
    <a id="nav-docs" onclick="showPage('docs')">Documentation</a>
    <a id="nav-about" onclick="showPage('about')">About</a>
  </nav>
  <span class="header-ver" id="ver"></span>
  <a href="https://cusanovichlab.github.io" target="_blank" rel="noopener">
    <img src="/static/logo.png" alt="Cusanovich Lab" class="header-logo"/>
  </a>
</header>

<main>

<!-- ═══ CLASSIFY ═══ -->
<div class="page active" id="page-classify">
  <div class="hero">
    <h1>Identify any NGS library from a FASTQ file</h1>
    <p>SeqTypeAI classifies sequencing library type using a machine learning model trained on 12,000 curated samples across 12 assay classes. Upload a FASTQ file — we extract sequence-level features and return a ranked prediction with confidence scores, quality assessment, and a recommended processing pipeline.</p>
    <p>No alignment required. Works on raw FASTQ files directly from the sequencer or a public repository. Classification takes a few seconds.</p>
    <div class="hero-badges">
      <span class="badge hi">91% test accuracy</span>
      <span class="badge hi">AUC 0.994</span>
      <span class="badge hi">12 assay classes</span>
      <span class="badge">50k reads analyzed</span>
      <span class="badge">sequence features only</span>
      <span class="badge">no alignment needed</span>
    </div>
  </div>

  <div id="upload-view">
    <div class="upload-section">
      <div>
        <div class="drop-zone" id="drop" onclick="document.getElementById('fi').click()">
          <svg class="drop-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
          <h2>Drop a FASTQ file here</h2>
          <p>.fastq and .fastq.gz &middot; max 50 MB &middot; first 50,000 reads analyzed</p>
          <p style="margin-top:8px;font-size:12px;color:var(--text3)">or click to browse</p>
          <input type="file" id="fi" accept=".fastq,.fq,.fastq.gz,.fq.gz" style="display:none" onchange="handleFile(this.files[0])"/>
        </div>
        <div id="err" class="err-box"></div>
      </div>
      <div>
        <div class="how-card">
          <h3>How it works</h3>
          <div class="how-step"><div class="how-num">1</div><p><strong>Upload</strong> any .fastq or .fastq.gz file — R1 from a paired-end run, single-end, or a subsample.</p></div>
          <div class="how-step"><div class="how-num">2</div><p><strong>Features extracted</strong> from the first 50,000 reads: GC content, read length, Tn5/MNase bias, k-mer composition, bisulfite conversion, barcode structure, and more.</p></div>
          <div class="how-step"><div class="how-num">3</div><p><strong>Classified</strong> by a gradient-boosted model trained on 12,000 curated public samples. Returns ranked predictions with confidence scores.</p></div>
          <div class="how-step"><div class="how-num">4</div><p><strong>Results</strong> include quality metrics, a recommended processing pipeline, and an AI assistant to discuss next steps.</p></div>
          <div class="assay-grid">
            <span class="pill">ATAC-seq</span><span class="pill">scATAC-seq</span><span class="pill">CUT&amp;RUN</span><span class="pill">CUT&amp;Tag</span><span class="pill">ChIP-seq</span><span class="pill">RNA-seq</span><span class="pill">scRNA-seq</span><span class="pill">Spatial</span><span class="pill">Bisulfite</span><span class="pill">WGS</span><span class="pill">WES</span><span class="pill">16S</span>
          </div>
        </div>
        <p style="font-size:11px;color:var(--text3);margin-top:10px;line-height:1.6">Files larger than 50 MB should be subsampled first. See the <a onclick="showPage('docs')" style="color:var(--blue);cursor:pointer">documentation</a> for subsampling commands.</p>
      </div>
    </div>
  </div>

  <div id="loading-view" style="display:none;text-align:center;padding:80px 0">
    <div class="spinner" style="margin-bottom:16px"></div>
    <p id="load-msg" style="font-size:14px;font-weight:500">Uploading file&hellip;</p>
    <p id="load-file" style="font-size:12px;color:var(--text3);font-family:var(--mono);margin-top:4px"></p>
  </div>

  <div id="result-view" style="display:none">
    <div id="warnings-banner" style="display:none;margin-bottom:12px"></div>
    <div class="results-grid">
      <div style="display:flex;flex-direction:column;gap:12px">
        <div class="card" id="top-card"></div>
        <div class="card" id="pred-card"></div>
        <div class="card" id="feat-card"></div>
        <button onclick="reset()" style="font-size:13px">&larr; Classify another file</button>
      </div>
      <div class="card" style="display:flex;flex-direction:column">
        <div class="tabs">
          <button class="tab active" onclick="switchTab('quality',event)">Quality</button>
          <button class="tab" onclick="switchTab('pipeline',event)">Pipeline</button>
          <button class="tab" onclick="switchTab('chat',event)">Ask AI</button>
        </div>
        <div id="tab-quality" class="tab-panel active"></div>
        <div id="tab-pipeline" class="tab-panel"></div>
        <div id="tab-chat" class="tab-panel"></div>
      </div>
    </div>
  </div>
</div>

<!-- ═══ DOCS ═══ -->
<div class="page" id="page-docs">
  <div class="doc-layout">
    <div class="doc-nav">
      <div class="doc-nav-section">Overview</div>
      <a class="dn-active" onclick="scrollTo('doc-intro')">Introduction</a>
      <a onclick="scrollTo('doc-input')">Input requirements</a>
      <a onclick="scrollTo('doc-subsampling')">Subsampling</a>
      <div class="doc-nav-section">Assay classes</div>
      <a onclick="scrollTo('doc-assays')">All 12 classes</a>
      <div class="doc-nav-section">Results</div>
      <a onclick="scrollTo('doc-confidence')">Confidence scores</a>
      <a onclick="scrollTo('doc-qc')">Quality assessment</a>
      <a onclick="scrollTo('doc-pipeline')">Pipeline recommendations</a>
      <div class="doc-nav-section">API</div>
      <a onclick="scrollTo('doc-api')">REST API</a>
      <a onclick="scrollTo('doc-limits')">Limits &amp; performance</a>
    </div>
    <div class="doc-content">

      <h2 id="doc-intro">Introduction</h2>
      <p>SeqTypeAI identifies the assay type of an NGS library from raw FASTQ data. It is designed for situations where metadata is missing, ambiguous, or untrusted — for example when reprocessing archived public data from SRA/ENA, auditing sample submissions from a sequencing core, or verifying that a delivered library matches the requested assay.</p>
      <p>Classification is based entirely on the sequence content of the reads: nucleotide composition, read length distribution, k-mer frequencies, enzymatic bias signals (Tn5 insertion, MNase cleavage), bisulfite conversion signatures, and single-cell barcode structure. No alignment to a reference genome is required.</p>
      <p>The model is a <code>HistGradientBoostingClassifier</code> trained on 12,000 samples (1,000 per class) downloaded from ENA/SRA and quality-filtered. Test accuracy is 91%, with macro AUC of 0.994 across all 12 classes.</p>

      <h2 id="doc-input">Input requirements</h2>
      <h3>File format</h3>
      <p>SeqTypeAI accepts plain FASTQ (<code>.fastq</code>, <code>.fq</code>) or gzip-compressed FASTQ (<code>.fastq.gz</code>, <code>.fq.gz</code>). Only the first 50,000 reads are used.</p>
      <h3>Which read to submit</h3>
      <p>For paired-end libraries, submit <strong>R1 only</strong> whenever possible. R2 is the cDNA insert for 10x Chromium assays and may reduce confidence for single-cell assay classification. For bulk assays (ATAC-seq, ChIP-seq, RNA-seq, WGS, WES) either read will classify correctly.</p>
      <p>Interleaved paired-end files (R1 and R2 merged into a single file) are detected automatically. SeqTypeAI extracts R1 reads only and displays a warning.</p>
      <h3>Read count</h3>
      <p>The model performs best with at least 10,000 reads. Files with fewer reads may still classify correctly but confidence scores will be lower.</p>

      <h2 id="doc-subsampling">Subsampling large files</h2>
      <p>Files larger than 50 MB should be subsampled before uploading. The commands below extract 50,000 reads — all SeqTypeAI uses.</p>
      <h3>seqtk (recommended &mdash; random sampling)</h3>
      <pre>seqtk sample -s42 input.fastq.gz 50000 | gzip > sample_50k.fastq.gz</pre>
      <h3>zcat + head (no extra tools needed)</h3>
      <pre>zcat input.fastq.gz | head -200000 | gzip > sample_50k.fastq.gz</pre>
      <p style="font-size:12px;color:var(--text3);margin-top:-8px">200,000 lines = 50,000 reads (4 lines per FASTQ record).</p>
      <h3>Extract R1 from an interleaved file</h3>
      <pre>seqtk seq -1 interleaved.fastq.gz | gzip > R1.fastq.gz</pre>

      <h2 id="doc-assays">Supported assay classes</h2>
      <div class="doc-note">Assay classes are defined by library preparation chemistry, not biological application. For example, CUT&amp;Tag uses pA-Tn5 and produces reads biochemically similar to ATAC-seq — the classifier distinguishes them by signal strength and fragment length characteristics.</div>
      <table class="doc-table">
        <thead><tr><th>Class key</th><th>Description</th><th>Key discriminating features</th></tr></thead>
        <tbody>
          <tr><td>atac_seq</td><td>Bulk ATAC-seq</td><td>High Tn5 AT-bias at read start, moderate GC, 50&ndash;200 bp</td></tr>
          <tr><td>sc_atac_seq</td><td>Single-cell ATAC-seq</td><td>R1 = 24&ndash;28 bp barcode + UMI; same Tn5 signal as bulk</td></tr>
          <tr><td>cut_and_tag</td><td>CUT&amp;Tag (pA-Tn5)</td><td>Tn5 bias similar to ATAC-seq; antibody-targeted so lower global enrichment</td></tr>
          <tr><td>cut_and_run</td><td>CUT&amp;RUN (pA-MNase)</td><td>MNase AT-bias at read start; variable fragment length</td></tr>
          <tr><td>chip_seq</td><td>ChIP-seq</td><td>Low Tn5/MNase bias; repeat k-mer fraction &lt; 0.04; moderate GC</td></tr>
          <tr><td>rna_seq</td><td>Bulk RNA-seq</td><td>GC 45&ndash;55%, poly-A signal, read length 75&ndash;200 bp</td></tr>
          <tr><td>sc_rna_seq</td><td>Single-cell RNA-seq (10x)</td><td>R1 = 28 bp (v3) or 26 bp (v2); high barcode match fraction</td></tr>
          <tr><td>spatial</td><td>10x Visium spatial</td><td>R1 = 28 bp spatial barcode + UMI; very low poly-A on R1</td></tr>
          <tr><td>bisulfite</td><td>WGBS</td><td>C fraction &lt; 5% (C&rarr;T conversion); GC &lt; 35%</td></tr>
          <tr><td>wgs</td><td>Whole-genome sequencing</td><td>GC ~41%, repeat k-mer 0.005&ndash;0.025, read length &ge; 100 bp</td></tr>
          <tr><td>wes</td><td>Whole-exome sequencing</td><td>GC ~49% (exon-enriched), very low repeat k-mer (&lt; 0.04)</td></tr>
          <tr><td>amplicon_16s</td><td>16S rRNA amplicon</td><td>Fixed read length (V4 ~253 bp, V3&ndash;V4 ~464 bp), high entropy</td></tr>
        </tbody>
      </table>

      <h2 id="doc-confidence">Confidence scores</h2>
      <p>Confidence scores are the model's predicted class probabilities, summing to 1.0 across all 12 classes. They are well-calibrated — a 90% confidence prediction is correct approximately 90% of the time.</p>
      <p>Scores below 50% indicate genuine uncertainty, often because the library sits at the boundary between two classes (e.g. CUT&amp;Tag vs ATAC-seq, or scRNA-seq vs Visium). In these cases, examine the second-ranked prediction and consider the biological context.</p>

      <h2 id="doc-qc">Quality assessment</h2>
      <p>After classification, SeqTypeAI evaluates the library against assay-specific quality thresholds derived from the training data. Each check is rated <strong>Pass</strong>, <strong>Marginal</strong>, or <strong>Fail</strong>. For a comprehensive QC assessment, use FastQC and assay-specific tools (ATACseqQC, RSeQC, Bismark's bismark2summary, etc.).</p>

      <h2 id="doc-pipeline">Pipeline recommendations</h2>
      <p>The Pipeline tab provides a step-by-step processing workflow for the predicted assay type, including adapter trimming, alignment, deduplication, and downstream analysis tools. Commands are provided as starting points — adjust parameters for your organism, sequencing depth, and analysis goals.</p>

      <h2 id="doc-api">REST API</h2>
      <p>SeqTypeAI is accessible via a REST API. Interactive documentation is available at <a href="/docs" style="color:var(--blue)">/docs</a>.</p>
      <h3>POST /classify</h3>
      <pre>curl -X POST https://cusanovichlab-seqtypeai.hf.space/classify \
  -F "file=@sample_R1.fastq.gz" | python -m json.tool</pre>
      <h3>Response fields</h3>
      <table class="doc-table">
        <thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead>
        <tbody>
          <tr><td>top_assay</td><td>string</td><td>Top predicted class key (e.g. <code>atac_seq</code>)</td></tr>
          <tr><td>top_label</td><td>string</td><td>Human-readable label (e.g. <code>Bulk ATAC-seq</code>)</td></tr>
          <tr><td>confidence</td><td>float</td><td>Probability of top prediction (0&ndash;1)</td></tr>
          <tr><td>predictions</td><td>array</td><td>All 12 classes ranked by confidence</td></tr>
          <tr><td>features</td><td>object</td><td>Extracted sequence features used for classification</td></tr>
          <tr><td>qc_checks</td><td>array</td><td>Assay-specific quality checks with pass/warn/poor status</td></tr>
          <tr><td>qc_overall</td><td>string</td><td><code>good</code>, <code>warn</code>, or <code>poor</code></td></tr>
          <tr><td>reasoning</td><td>string</td><td>Brief explanation of classification</td></tr>
          <tr><td>warnings</td><td>array</td><td>File-level warnings (e.g. interleaved detection)</td></tr>
          <tr><td>model_version</td><td>string</td><td>Model version string</td></tr>
        </tbody>
      </table>
      <h3>GET /health</h3>
      <pre>curl https://cusanovichlab-seqtypeai.hf.space/health</pre>

      <h2 id="doc-limits">Limits &amp; performance</h2>
      <table class="doc-table">
        <thead><tr><th>Parameter</th><th>Value</th></tr></thead>
        <tbody>
          <tr><td>Max file size</td><td>50 MB</td></tr>
          <tr><td>Reads analyzed</td><td>First 50,000</td></tr>
          <tr><td>Min reads recommended</td><td>10,000</td></tr>
          <tr><td>Classification time</td><td>~2&ndash;5 seconds</td></tr>
          <tr><td>Supported formats</td><td>.fastq, .fq, .fastq.gz, .fq.gz</td></tr>
          <tr><td>Interleaved files</td><td>Supported (R1 extracted automatically)</td></tr>
          <tr><td>Long-read platforms</td><td>Not supported (Illumina only)</td></tr>
        </tbody>
      </table>

    </div>
  </div>
</div>

<!-- ═══ ABOUT ═══ -->
<div class="page" id="page-about">
  <div style="max-width:760px">
    <div style="padding:40px 0 24px">
      <h1 style="font-family:var(--serif);font-size:34px;letter-spacing:-0.02em;margin-bottom:14px">About SeqTypeAI</h1>
      <p style="color:var(--text2);line-height:1.75">SeqTypeAI was developed in the <a href="https://cusanovichlab.github.io" style="color:var(--blue)">Cusanovich Lab</a> at the University of Arizona, Department of Cellular and Molecular Medicine. The lab specializes in single-cell genomics technology development and the study of gene regulation in complex diseases, with particular expertise in chromatin accessibility profiling.</p>
    </div>
    <div class="stat-row">
      <div class="stat"><div class="num">12</div><div class="lbl">assay classes</div></div>
      <div class="stat"><div class="num">12k</div><div class="lbl">training samples</div></div>
      <div class="stat"><div class="num">377</div><div class="lbl">sequence features</div></div>
      <div class="stat"><div class="num">91%</div><div class="lbl">test accuracy</div></div>
      <div class="stat"><div class="num">0.994</div><div class="lbl">macro AUC</div></div>
    </div>
    <div class="about-grid">
      <div class="about-card">
        <h3>Model</h3>
        <p>A <code>HistGradientBoostingClassifier</code> (scikit-learn) trained on 1,000 samples per class from ENA/SRA. Features are extracted from raw FASTQ reads: nucleotide frequencies, k-mer composition (2&ndash;4-mers), read length statistics, Tn5 and MNase enzymatic bias, bisulfite conversion metrics, GC distribution, poly-A signal, repeat content, and single-cell barcode structure. No reference alignment required.</p>
      </div>
      <div class="about-card">
        <h3>Training data</h3>
        <p>Training samples were downloaded from ENA/SRA across 12 assay classes representing human and mouse genomics data. Each sample was quality-filtered to require at least 10,000 reads and exclude files with non-standard formats, interleaved paired-end reads, platform mismatches, and known contamination. Biological and technical diversity was ensured by shuffling and drawing from diverse studies.</p>
      </div>
      <div class="about-card">
        <h3>Limitations</h3>
        <p>SeqTypeAI is trained on short-read Illumina data. Long-read platforms (PacBio, Oxford Nanopore) are not currently supported. Classification accuracy is lower for assay pairs with shared biochemistry: scATAC-seq vs bulk ATAC-seq, and scRNA-seq vs Visium spatial. These boundaries are improved by submitting R1 reads only for single-cell assays.</p>
      </div>
      <div class="about-card">
        <h3>Source &amp; citation</h3>
        <p>SeqTypeAI is open source. If you use this tool in your research, please cite the Cusanovich Lab. Source code and training pipeline are available on GitHub. Model artifacts are hosted on HuggingFace.</p>
        <p style="margin-top:10px"><a href="https://github.com/cusanovichlab" style="color:var(--blue)">GitHub</a> &nbsp;&middot;&nbsp; <a href="https://cusanovichlab.github.io" style="color:var(--blue)">Lab website</a></p>
      </div>
    </div>
    <div style="margin-top:32px;padding-top:24px;border-top:1px solid var(--border)">
      <h3 style="font-size:14px;font-weight:500;margin-bottom:8px">Contact</h3>
      <p style="font-size:13px;color:var(--text2)">For questions about SeqTypeAI, please open an issue on GitHub or contact the Cusanovich Lab at the University of Arizona.</p>
    </div>
  </div>
</div>

</main>

<script>
const COLORS={amplicon_16s:"#D85A30",atac_seq:"#1D9E75",bisulfite:"#3B6D11",chip_seq:"#534AB7",cut_and_run:"#EF9F27",cut_and_tag:"#378ADD",rna_seq:"#97C459",sc_atac_seq:"#D4537E",sc_rna_seq:"#7F77DD",spatial:"#BA7517",wes:"#185FA5",wgs:"#5F5E5A"};
const LABELS={amplicon_16s:"16S Amplicon",atac_seq:"Bulk ATAC-seq",bisulfite:"Bisulfite-seq (WGBS)",chip_seq:"ChIP-seq",cut_and_run:"CUT&RUN",cut_and_tag:"CUT&Tag",rna_seq:"RNA-seq",sc_atac_seq:"scATAC-seq",sc_rna_seq:"scRNA-seq",spatial:"Spatial transcriptomics",wes:"Whole exome seq",wgs:"Whole genome seq"};
const PIPELINES={
  atac_seq:{summary:"Maps open chromatin using Tn5 transposase. Align paired-end reads, remove duplicates and mitochondrial reads, then call peaks in nucleosome-free regions.",tools:[{n:"FastQC",r:"QC",c:"fastqc *.fastq.gz -o qc/"},{n:"Trimmomatic",r:"Adapter trim",c:"trimmomatic PE R1.fq.gz R2.fq.gz ... ILLUMINACLIP:NexteraPE-PE.fa:2:30:10 MINLEN:38"},{n:"Bowtie2",r:"Align",c:"bowtie2 --very-sensitive -X 2000 -x genome -1 R1 -2 R2 | samtools sort -o aligned.bam"},{n:"Picard + samtools",r:"Dedup & filter",c:"MarkDuplicates REMOVE_DUPLICATES=true && samtools view -F 1804 -f 2 -q 30"},{n:"MACS2",r:"Peak calling",c:"macs2 callpeak -f BAMPE -t dedup.bam --nomodel --shift -100 --extsize 200 -g hs"},{n:"deepTools",r:"QC & tracks",c:"plotFingerprint && bamCoverage --normalizeUsing RPKM"}],notes:"Apply +4/\u22125 bp Tn5 offset. Remove ENCODE blacklist regions."},
  sc_atac_seq:{summary:"Profiles open chromatin in individual cells. R1 carries the cell barcode and UMI. Cell Ranger ATAC handles demultiplexing; ArchR or Signac for downstream analysis.",tools:[{n:"Cell Ranger ATAC",r:"Align + demux",c:"cellranger-atac count --id=sample --reference=refdata --fastqs=fastq_dir"},{n:"ArchR",r:"Arrow files",c:"createArrowFiles(inputFiles, minTSS=4, minFrags=1000)"},{n:"ArchR",r:"Dim reduction",c:"addIterativeLSI() \u2192 addClusters() \u2192 addUMAP()"},{n:"ArchR",r:"Peak calling",c:"addGroupCoverages() \u2192 addReproduciblePeakSet() \u2192 addPeakMatrix()"},{n:"chromVAR",r:"TF activity",c:"addDeviationsMatrix(peakAnnotation='Motif')"}],notes:"TSS enrichment > 4 is a good library benchmark."},
  chip_seq:{summary:"Profiles protein\u2013DNA interactions by immunoprecipitation. Requires matched input or IgG controls.",tools:[{n:"FastQC",r:"QC",c:"fastqc *.fastq.gz"},{n:"BWA-MEM2",r:"Align",c:"bwa-mem2 mem -t 16 genome.fa trimmed.fq.gz | samtools sort -o aligned.bam"},{n:"Picard",r:"Dedup",c:"MarkDuplicates REMOVE_DUPLICATES=true"},{n:"MACS2",r:"Peak calling",c:"macs2 callpeak -t chip.bam -c input.bam -n sample -g hs -q 0.01"},{n:"deepTools",r:"QC & tracks",c:"plotFingerprint -b chip.bam input.bam"}],notes:"Input control is mandatory. Narrow peaks (TFs): --nomodel. Broad marks: --broad."},
  cut_and_run:{summary:"Protein A\u2013MNase cleaves DNA adjacent to antibody-bound targets. Very low background compared with ChIP-seq.",tools:[{n:"Trimmomatic",r:"Adapter trim",c:"trimmomatic PE ... ILLUMINACLIP:adapters.fa:2:30:10 MINLEN:25"},{n:"Bowtie2",r:"Align",c:"bowtie2 --end-to-end --very-sensitive --no-mixed --no-discordant -I 10 -X 700"},{n:"SEACR",r:"Peak calling",c:"SEACR.sh sample.bedgraph IgG.bedgraph non stringent output"},{n:"deepTools",r:"Fragment QC",c:"bamPEFragmentSize"}],notes:"E. coli spike-in calibration recommended. nf-core/cutandrun pipeline available."},
  cut_and_tag:{summary:"Uses pA-Tn5 transposase, enabling single-cell compatibility. Analysis mirrors CUT&RUN.",tools:[{n:"Trimmomatic",r:"Adapter trim",c:"trimmomatic PE ... ILLUMINACLIP:NexteraPE-PE.fa:2:30:10 MINLEN:25"},{n:"Bowtie2",r:"Align",c:"bowtie2 --end-to-end --very-sensitive --no-mixed --no-discordant -I 10 -X 700"},{n:"MACS2 or SEACR",r:"Peak calling",c:"macs2 callpeak -f BAMPE -t cut_tag.bam --nomodel"}],notes:"Apply +4/\u22125 bp Tn5 offset. E. coli spike-in normalization recommended."},
  bisulfite:{summary:"Maps DNA methylation at single-base resolution. Good conversion: < 5% unconverted cytosines.",tools:[{n:"Trim Galore",r:"Trim",c:"trim_galore --paired --cores 4 --clip_r1 10 --clip_r2 10 R1.fq.gz R2.fq.gz"},{n:"Bismark",r:"Align",c:"bismark --genome genome/ -1 R1_trimmed.fq.gz -2 R2_trimmed.fq.gz"},{n:"Bismark",r:"Dedup + extract",c:"deduplicate_bismark aligned.bam && bismark_methylation_extractor --paired-end --CX"},{n:"DSS",r:"Diff. methylation",c:"callDML() \u2192 callDMR()"}],notes:"Verify conversion efficiency via lambda spike-in. Target 10\u201315\u00d7 coverage."},
  rna_seq:{summary:"Quantifies gene expression transcriptome-wide. nf-core/rnaseq provides a standardized workflow.",tools:[{n:"FastQC + MultiQC",r:"QC",c:"fastqc *.fastq.gz && multiqc ."},{n:"STAR",r:"Align",c:"STAR --genomeDir star_index/ --readFilesIn R1.fq.gz R2.fq.gz --readFilesCommand zcat --outSAMtype BAM SortedByCoordinate"},{n:"featureCounts",r:"Count",c:"featureCounts -a annotation.gtf -o counts.txt aligned.bam"},{n:"DESeq2",r:"Diff. expression",c:"DESeqDataSetFromMatrix() \u2192 DESeq() \u2192 results()"}],notes:"Check strandedness with RSeQC infer_experiment.py."},
  sc_rna_seq:{summary:"Profiles gene expression in individual cells. R1 = barcode + UMI, R2 = cDNA insert.",tools:[{n:"Cell Ranger",r:"Align + demux",c:"cellranger count --id=sample --transcriptome=refdata-gex-GRCh38 --fastqs=fastq_dir"},{n:"Seurat / Scanpy",r:"QC filter",c:"subset(nFeature_RNA > 200 & percent.mt < 20)"},{n:"Seurat / Scanpy",r:"Normalize",c:"NormalizeData() \u2192 FindVariableFeatures() \u2192 ScaleData()"},{n:"Seurat / Scanpy",r:"Cluster",c:"RunPCA() \u2192 RunUMAP(dims=1:30) \u2192 FindClusters()"}],notes:"Use SoupX or DecontX for ambient RNA correction."},
  spatial:{summary:"Adds spatial coordinates to gene expression. Space Ranger maps barcodes to tissue spots.",tools:[{n:"Space Ranger",r:"Align + spatial",c:"spaceranger count --id=sample --transcriptome=refdata-gex-GRCh38 --fastqs=fastq_dir --image=tissue.tif"},{n:"Seurat",r:"Normalize",c:"Load10X_Spatial('spaceranger_out/') \u2192 SCTransform()"},{n:"Seurat",r:"Spatial genes",c:"FindSpatiallyVariableFeatures(selection.method='moransi')"},{n:"RCTD",r:"Deconvolution",c:"create.RCTD() \u2192 run.RCTD()"}],notes:"Visium: 6.5 mm\u00b2 area, ~5000 spots at 55 \u00b5m."},
  wgs:{summary:"Uniform coverage across the genome. Follow GATK Best Practices for variant calling.",tools:[{n:"BWA-MEM2",r:"Align",c:"bwa-mem2 mem -t 32 genome.fa R1.fq.gz R2.fq.gz | samtools sort"},{n:"GATK MarkDuplicates",r:"Dedup",c:"gatk MarkDuplicates -I aligned.bam -O dedup.bam"},{n:"GATK BQSR",r:"Recalibrate",c:"gatk BaseRecalibrator && gatk ApplyBQSR"},{n:"GATK HaplotypeCaller",r:"Variant calling",c:"gatk HaplotypeCaller -R genome.fa -I recal.bam -O sample.g.vcf.gz -ERC GVCF"}],notes:"Target 30\u00d7 germline, 60\u2013100\u00d7 somatic. nf-core/sarek recommended."},
  wes:{summary:"Targets protein-coding regions using capture probes. Same GATK pipeline as WGS restricted to capture intervals.",tools:[{n:"Trimmomatic",r:"Trim",c:"trimmomatic PE R1.fq.gz R2.fq.gz ... ILLUMINACLIP:TruSeq3-PE.fa:2:30:10 MINLEN:36"},{n:"BWA-MEM2",r:"Align",c:"bwa-mem2 mem -t 16 genome.fa R1.fq.gz R2.fq.gz | samtools sort"},{n:"GATK HaplotypeCaller",r:"Variant calling",c:"gatk HaplotypeCaller -I recal.bam -O sample.g.vcf.gz -ERC GVCF -L capture_targets.bed"},{n:"GATK VQSR",r:"Filter",c:"VariantRecalibrator \u2192 ApplyVQSR"}],notes:"Use -L target_intervals.bed with +100 bp padding. Target \u2265100\u00d7 mean coverage."},
  amplicon_16s:{summary:"Profiles microbial communities via 16S rRNA amplification. DADA2 is standard for exact ASV calling.",tools:[{n:"Cutadapt",r:"Primer removal",c:"cutadapt -g GTGYCAGCMGCCGCGGTAA -a ATTAGAWACCCBNGTAGTCC --discard-untrimmed"},{n:"DADA2",r:"Filter + denoise",c:"filterAndTrim() \u2192 learnErrors() \u2192 dada() \u2192 mergePairs()"},{n:"DADA2",r:"ASV table",c:"makeSequenceTable() \u2192 removeBimeraDenovo()"},{n:"phyloseq",r:"Diversity",c:"estimate_richness() \u2192 ordinate() \u2192 plot_ordination()"}],notes:"Include positive (mock community) and negative (extraction blank) controls."},
};

function showPage(id){
  document.querySelectorAll('.page').forEach(p=>p.classList.remove('active'));
  document.querySelectorAll('nav a').forEach(a=>a.classList.remove('active'));
  document.getElementById('page-'+id).classList.add('active');
  document.getElementById('nav-'+id).classList.add('active');
  window.scrollTo(0,0);
}
function scrollTo(id){document.getElementById(id)?.scrollIntoView({behavior:'smooth'});}

function showErr(msg,isSizeErr=false){
  const e=document.getElementById('err');
  if(isSizeErr){
    e.innerHTML=`<strong>File too large (50 MB limit)</strong><br><br>SeqTypeAI only needs the first 50,000 reads. Use one of these commands to subsample:<br><br>`+
    `<code style="display:block;background:rgba(153,32,32,0.08);padding:6px 9px;border-radius:4px;margin:5px 0;font-size:11px">seqtk sample -s42 input.fastq.gz 50000 | gzip > sample_50k.fastq.gz</code>`+
    `<code style="display:block;background:rgba(153,32,32,0.08);padding:6px 9px;border-radius:4px;margin:5px 0;font-size:11px">zcat input.fastq.gz | head -200000 | gzip > sample_50k.fastq.gz</code>`+
    `See <a onclick="showPage('docs')" style="color:var(--red);cursor:pointer">documentation</a> for more options.`;
  }else{e.textContent=msg;}
  e.style.display='block';
}
function reset(){
  document.getElementById('upload-view').style.display='';
  document.getElementById('result-view').style.display='none';
  document.getElementById('warnings-banner').style.display='none';
  document.getElementById('err').style.display='none';
  CTX=null;chatHistory=[];
}

let CTX=null,chatHistory=[],chatBusy=false;
const drop=document.getElementById('drop');
drop.addEventListener('dragover',e=>{e.preventDefault();drop.classList.add('drag');});
drop.addEventListener('dragleave',()=>drop.classList.remove('drag'));
drop.addEventListener('drop',e=>{e.preventDefault();drop.classList.remove('drag');if(e.dataTransfer.files[0])handleFile(e.dataTransfer.files[0]);});

async function handleFile(file){
  if(!file)return;
  if(!/\.(fastq|fq)(\.gz)?$/i.test(file.name)){showErr('Please upload a .fastq or .fastq.gz file');return;}
  if(file.size>50*1024*1024){showErr('File too large',true);return;}
  document.getElementById('upload-view').style.display='none';
  document.getElementById('loading-view').style.display='';
  document.getElementById('load-file').textContent=file.name;
  document.getElementById('load-msg').textContent='Uploading and analyzing file\u2026';
  const fd=new FormData();fd.append('file',file);
  try{
    const r=await fetch('/classify',{method:'POST',body:fd});
    if(!r.ok){
      const isSizeErr=r.status===413;
      const e=await r.json().catch(()=>({detail:'Server error'}));
      document.getElementById('loading-view').style.display='none';
      document.getElementById('upload-view').style.display='';
      showErr(e.detail||'Server error',isSizeErr);
      return;
    }
    const data=await r.json();
    document.getElementById('loading-view').style.display='none';
    renderResults(data);
  }catch(e){
    document.getElementById('loading-view').style.display='none';
    document.getElementById('upload-view').style.display='';
    showErr(e.message);
  }
}

function renderResults(data){
  const top=data.predictions[0];CTX=data;
  const col=COLORS[top.assay]||'#888';
  const wb=document.getElementById('warnings-banner');
  if(data.warnings&&data.warnings.length>0){
    wb.innerHTML=data.warnings.map(w=>`<div style="padding:10px 14px;border-radius:8px;background:var(--amberbg);border:1px solid rgba(184,104,0,.25);margin-bottom:8px;display:flex;gap:8px;align-items:flex-start"><span style="flex-shrink:0">&#9888;</span><span style="font-size:12px;color:var(--amber);line-height:1.55">${w}</span></div>`).join('');
    wb.style.display='';
  }else wb.style.display='none';

  document.getElementById('top-card').innerHTML=`
    <div class="card-label"><span class="dot" style="background:${col}"></span>Top prediction</div>
    <div class="top-label">${LABELS[top.assay]||top.assay}</div>
    <div class="conf-big" style="color:${col}">${(top.confidence*100).toFixed(0)}%</div>
    <p style="font-size:12px;color:var(--text2);margin-top:8px;line-height:1.55">${data.reasoning}</p>
    <div style="font-size:10px;font-family:var(--mono);color:var(--text3);margin-top:10px;padding-top:8px;border-top:1px solid var(--border);word-break:break-all">${data.filename}</div>`;

  document.getElementById('pred-card').innerHTML=`
    <div class="card-label">All predictions</div>
    ${data.predictions.map((p,i)=>`
      <div class="bar-row" style="opacity:${p.confidence<0.005?0.35:1}">
        <div style="width:72px;font-size:11px;font-family:var(--mono);color:${i===0?'var(--text)':'var(--text2)'};font-weight:${i===0?500:400};overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex-shrink:0">${(LABELS[p.assay]||p.assay).replace('Whole ','').replace(' seq','').replace('(WGBS)','').replace('transcriptomics','tx.')}</div>
        <div class="bar-track"><div class="bar-fill" style="width:${Math.max(p.confidence*100,.3)}%;background:${COLORS[p.assay]||'#888'}"></div></div>
        <div style="width:32px;text-align:right;font-size:11px;font-family:var(--mono);color:${i===0?'var(--text)':'var(--text2)'};font-weight:${i===0?500:400};flex-shrink:0">${(p.confidence*100).toFixed(0)}%</div>
      </div>`).join('')}`;

  const feats=data.features;
  document.getElementById('feat-card').innerHTML=`
    <div class="card-label">Extracted features</div>
    ${[['Read length (mean)',`${feats.rl_mean.toFixed(1)} bp`],['Read length (std)',`\u00b1${feats.rl_std.toFixed(1)} bp`],['GC content',`${(feats.gc_mean*100).toFixed(1)}%`],['Raw C fraction',`${(feats.c_fraction*100).toFixed(1)}%`],['Shannon entropy',feats.entropy_mean.toFixed(3)],['Tn5/MNase AT bias',`${(feats.tn5_start_approx*100).toFixed(1)}%`],['Poly-A signal',`${(feats.polya_signal*100).toFixed(1)}%`],['Repeat k-mer',`${(feats.repeat_kmer_frac*100).toFixed(1)}%`],['GC < 30% reads',`${(feats.gc_tail_low*100).toFixed(1)}%`],['Reads analyzed',feats.n_reads.toLocaleString()]].map(([l,v])=>`<div class="frow"><span style="font-size:12px;color:var(--text2)">${l}</span><span class="mono" style="font-weight:500">${v}</span></div>`).join('')}`;

  const qcO=data.qc_overall||'good';
  const qcBg={good:'var(--greenbg)',warn:'var(--amberbg)',poor:'var(--redbg)'};
  const qcCl={good:'var(--green)',warn:'var(--amber)',poor:'var(--red)'};
  const qcLb={good:'Good quality',warn:'Acceptable \u2014 review flagged metrics',poor:'Poor quality \u2014 inspect library preparation'};
  document.getElementById('tab-quality').innerHTML=`
    <div style="padding:9px 12px;border-radius:6px;background:${qcBg[qcO]};margin-bottom:14px;display:flex;align-items:center;gap:6px">
      <span class="dot" style="background:${qcCl[qcO]}"></span><span style="font-size:13px;font-weight:500;color:${qcCl[qcO]}">${qcLb[qcO]}</span>
    </div>
    ${(data.qc_checks||[]).map(c=>`
      <div class="qc-row">
        <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:3px">
          <span style="font-size:13px;font-weight:500">${c.label}</span>
          <span class="badge-${c.status}" style="font-size:11px;padding:2px 8px;border-radius:10px;font-weight:500">${c.status==='good'?'Pass':c.status==='warn'?'Marginal':'Fail'}</span>
        </div>
        <div style="display:flex;justify-content:space-between;gap:8px">
          <span style="font-size:12px;color:var(--text2);line-height:1.4">${c.desc}</span>
          <span class="mono" style="color:var(--text3);flex-shrink:0">${c.key==='is_barcode_length'?(c.value===1?'yes':'no'):(c.value*100).toFixed(1)+'%'}</span>
        </div>
      </div>`).join('')}
    <p style="font-size:11px;color:var(--text3);border-top:1px solid var(--border);padding-top:10px;line-height:1.5">QC computed from first 50,000 reads. For comprehensive QC use FastQC and assay-specific tools.</p>`;

  const pipe=PIPELINES[top.assay];
  document.getElementById('tab-pipeline').innerHTML=pipe?`
    <p style="font-size:13px;color:var(--text2);margin-bottom:16px;line-height:1.6">${pipe.summary}</p>
    ${pipe.tools.map((s,i)=>`
      <div class="step">
        <div style="display:flex;flex-direction:column;align-items:center;flex-shrink:0"><div class="step-num">${i+1}</div>${i<pipe.tools.length-1?'<div style="width:1px;flex:1;background:var(--border);min-height:6px;margin:2px 0"></div>':''}</div>
        <div style="flex:1;padding-bottom:6px">
          <div class="step-name">${s.n}<span class="step-role">${s.r}</span></div>
          <div class="cmd">${s.c}</div>
        </div>
      </div>`).join('')}
    ${pipe.notes?`<div style="padding:9px 11px;border-radius:6px;background:var(--bluebg);border:1px solid rgba(37,99,168,.2);margin-top:4px"><p style="font-size:12px;color:var(--bluedark);margin:0;line-height:1.6">${pipe.notes}</p></div>`:''}
  `:'<p style="font-size:13px;color:var(--text2)">Pipeline not available for this assay.</p>';

  chatHistory=[{role:'assistant',content:`I've classified **${data.filename}** as **${LABELS[top.assay]||top.assay}** with ${(top.confidence*100).toFixed(0)}% confidence.\n\n${data.reasoning}\n\nAsk me anything about the result, quality, or how to process this library.`}];
  renderChat();
  document.getElementById('result-view').style.display='';
}

function renderChat(){
  const panel=document.getElementById('tab-chat');
  panel.innerHTML=`
    <div class="chat-wrap" id="chat-messages">${chatHistory.map(m=>`<div class="chat-bubble ${m.role}">${m.content}</div>`).join('')}</div>
    <div class="chat-input-row">
      <input type="text" id="chat-in" placeholder="Ask about the results, quality, or next steps\u2026" onkeydown="if(event.key==='Enter')sendChat()"/>
      <button onclick="sendChat()" id="chat-btn" class="btn-primary">Send</button>
    </div>`;
  const cw=document.getElementById('chat-messages');
  if(cw)cw.scrollTop=cw.scrollHeight;
}

async function sendChat(){
  const inp=document.getElementById('chat-in');
  const text=inp?.value.trim();
  if(!text||!CTX||chatBusy)return;
  inp.value='';chatBusy=true;
  const btn=document.getElementById('chat-btn');if(btn)btn.disabled=true;
  chatHistory.push({role:'user',content:text});
  renderChat();
  try{
    const top=CTX.predictions[0];
    const sys=`You are SeqTypeAI Assistant. Classification context \u2014 File: ${CTX.filename}. Predicted: ${LABELS[top.assay]||top.assay} (${(top.confidence*100).toFixed(0)}% confidence). Quality: ${CTX.qc_overall}. Read length: ${CTX.features.rl_mean.toFixed(1)} bp, GC: ${(CTX.features.gc_mean*100).toFixed(1)}%, entropy: ${CTX.features.entropy_mean.toFixed(3)}. Reasoning: ${CTX.reasoning}. Be concise and practical.`;
    const r=await fetch('https://api.anthropic.com/v1/messages',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({model:'claude-sonnet-4-20250514',max_tokens:800,system:sys,messages:chatHistory.map(m=>({role:m.role,content:m.content}))})});
    const d=await r.json();
    chatHistory.push({role:'assistant',content:d.content[0].text});
  }catch{chatHistory.push({role:'assistant',content:'Sorry, I encountered an error. Please try again.'});}
  chatBusy=false;renderChat();
}

function switchTab(id,event){
  document.querySelectorAll('.tab').forEach(t=>t.classList.remove('active'));
  document.querySelectorAll('.tab-panel').forEach(p=>p.classList.remove('active'));
  event.target.classList.add('active');
  document.getElementById('tab-'+id).classList.add('active');
}

fetch('/health').then(r=>r.json()).then(d=>{
  const v=document.getElementById('ver');
  if(v)v.textContent=`v${d.model_version} \u00b7 ${d.n_classes} classes`;
}).catch(()=>{});
</script>
</body>
</html>