Spaces:
Running

isahn commited on
Commit
4c84426
·
1 Parent(s): d506b96

how-to: add result-files-by-step figure (ko/en/th/id)

Browse files
Files changed (3) hide show
  1. app.py +42 -13
  2. build_usage_files_figs.py +222 -0
  3. howto_figs.py +0 -0
app.py CHANGED
@@ -1857,6 +1857,19 @@ def _method_fig_html(lang: str, alt: str) -> str:
1857
  return ""
1858
 
1859
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1860
  _METHOD_MD = _method_fig_html("ko", "DenAIGeo 분석 방법론 개요") + """
1861
  ## 분석 방법 한눈에 보기
1862
 
@@ -1934,7 +1947,7 @@ ATGAACAACCGGAAAAAGACGGGAAAACCGTCTATC...
1934
  - **예측 요약 차트**: 상위 국가별 확률(유사도)을 막대 그래프로 표시 (Top-3 PNG 포함)
1935
  """
1936
 
1937
- _HOWTO_MD = """
1938
  ## 사용 순서
1939
 
1940
  **🚀 Run Pipeline** 탭에서 아래 순서대로 진행하세요.
@@ -1942,13 +1955,17 @@ _HOWTO_MD = """
1942
  1. **Target Serotype / Target Gene 선택** — 분석하려는 DENV 혈청형(1~4)과 유전자
1943
  영역을 고릅니다. (E 유전자는 혈청형 1, 2에만 존재해서 그때만 선택 가능합니다.)
1944
  2. **⚙️ 설정 적용** 버튼을 눌러 반영합니다.
1945
- 3. **서열 파일 업로드** — FASTA 형식(.seq/.fasta/.fa/.fna/.fas) 파일을 선택합니다.
1946
  4. **① Stage 1 실행** — 서열 정렬과 변이 프로파일 생성을 시작합니다.
1947
  5. **② Stage 2 실행** — Stage 1 결과를 바탕으로 국가/도시 단위 유입원을 예측합니다.
1948
  6. **③ Stage 3 실행** — 지리적 분석 표와 그림을 생성합니다.
1949
- 7. **결과 확인/다운로드** — "🔄 결과 새로고침"으로 최신 표·그림을 불러옵니다.
1950
  8. **📊 2D 시각화 생성** — 모델 프로파일과 사용자 서열을 t-SNE로 투영한 인터랙티브 그래프를 볼 수 있습니다.
1951
- """
 
 
 
 
1952
 
1953
  _ABOUT_MD_EN = """
1954
  ## What does this tool do?
@@ -2053,7 +2070,7 @@ After the analysis is complete, you can check the predicted results in tables, g
2053
  - **Prediction summary chart**: bar chart of probability (similarity) by top country (including the Top-3 PNG)
2054
  """
2055
 
2056
- _HOWTO_MD_EN = """
2057
  ## Usage steps
2058
 
2059
  Follow these steps in order, in the **🚀 Run Pipeline** tab.
@@ -2062,15 +2079,19 @@ Follow these steps in order, in the **🚀 Run Pipeline** tab.
2062
  region you want to analyze. (Gene E only exists for serotypes 1 and 2, so it's only
2063
  selectable then.)
2064
  2. Click **⚙️ Apply Settings** to apply your choice.
2065
- 3. **Upload sequence files** — select FASTA-format files (.seq/.fasta/.fa/.fna/.fas).
2066
  4. **① Run Stage 1** — starts sequence alignment and mutation-profile generation.
2067
  5. **② Run Stage 2** — predicts country/city-level origin based on the Stage 1 results.
2068
  6. **③ Run Stage 3** — generates geographic analysis tables and figures.
2069
- 7. **Check/download results** — click "🔄 Refresh Results" to load the latest tables
2070
- and figures.
2071
  8. **📊 Generate 2D Visualization** — view an interactive graph projecting the model
2072
  profiles and your user sequences together using t-SNE.
2073
- """
 
 
 
 
2074
 
2075
  _ABOUT_MD_TH = """
2076
  ## เครื่องมือนี้ทำอะไรได้บ้าง?
@@ -2172,7 +2193,7 @@ ATGAACAACCGGAAAAAGACGGGAAAACCGTCTATC...
2172
  - **กราฟสรุปผลการทำนาย**: แผนภูมิแท่งแสดงความน่าจะเป็น (ความคล้ายคลึง) ของแต่ละประเทศอันดับสูงสุด (รวมไฟล์ PNG Top-3)
2173
  """
2174
 
2175
- _HOWTO_MD_TH = """
2176
  ## ขั้นตอนการใช้งาน
2177
 
2178
  ทำตามขั้นตอนต่อไปนี้ตามลำดับ ในแท็บ **🚀 Run Pipeline**
@@ -2187,7 +2208,11 @@ _HOWTO_MD_TH = """
2187
  7. **ตรวจสอบ/ดาวน์โหลดผลลัพธ์** — คลิก "🔄 Refresh Results" เพื่อโหลดตารางและกราฟล่าสุด
2188
  8. **📊 Generate 2D Visualization** — ดูกราฟเชิงโต้ตอบที่ฉายโปรไฟล์แบบจำลองและลำดับของผู้ใช้
2189
  ร่วมกันด้วย t-SNE
2190
- """
 
 
 
 
2191
 
2192
 
2193
  _ID_UI = {
@@ -2506,7 +2531,7 @@ Program ini dilindungi hak cipta oleh **KISTI (Korea Institute of Science and Te
2506
  Information)**. Penggunaan atau redistribusi tanpa izin dilarang.
2507
  """
2508
 
2509
- _HOWTO_MD_ID = """
2510
  ## Langkah penggunaan
2511
 
2512
  Ikuti langkah-langkah berikut secara berurutan di tab **🚀 Jalankan Pipeline**.
@@ -2522,7 +2547,11 @@ Ikuti langkah-langkah berikut secara berurutan di tab **🚀 Jalankan Pipeline**
2522
  7. **Periksa/unduh hasil** — klik "🔄 Segarkan Hasil" untuk memuat tabel dan gambar terbaru.
2523
  8. **📊 Buat Visualisasi 2D** — lihat grafik interaktif yang memproyeksikan profil model
2524
  dan sekuens pengguna Anda bersama-sama menggunakan t-SNE.
2525
- """
 
 
 
 
2526
 
2527
  _METHOD_MD_ID = _method_fig_html("id", "Gambaran umum metode DenAIGeo") + """
2528
  ## Metode sekilas
 
1857
  return ""
1858
 
1859
 
1860
+ def _howto_fig_html(lang: str, alt: str) -> str:
1861
+ """howto_figs.py 에 base64 로 저장된 '사용 순서' 그림을 인라인합니다 (없으면 빈 문자열)."""
1862
+ try:
1863
+ from howto_figs import HOWTO_FIGS
1864
+ b64 = HOWTO_FIGS.get(lang, "")
1865
+ if not b64:
1866
+ return ""
1867
+ return (f'<img src="data:image/jpeg;base64,{b64}" alt="{alt}" '
1868
+ 'style="width:100%; height:auto; border-radius:12px; border:1px solid #dbe4ef; margin-bottom:1.2rem;"/>\n\n')
1869
+ except Exception:
1870
+ return ""
1871
+
1872
+
1873
  _METHOD_MD = _method_fig_html("ko", "DenAIGeo 분석 방법론 개요") + """
1874
  ## 분석 방법 한눈에 보기
1875
 
 
1947
  - **예측 요약 차트**: 상위 국가별 확률(유사도)을 막대 그래프로 표시 (Top-3 PNG 포함)
1948
  """
1949
 
1950
+ _HOWTO_MD = _howto_fig_html("ko", "DenAIGeo 사용 순서") + """
1951
  ## 사용 순서
1952
 
1953
  **🚀 Run Pipeline** 탭에서 아래 순서대로 진행하세요.
 
1955
  1. **Target Serotype / Target Gene 선택** — 분석하려는 DENV 혈청형(1~4)과 유전자
1956
  영역을 고릅니다. (E 유전자는 혈청형 1, 2에만 존재해서 그때만 선택 가능합니다.)
1957
  2. **⚙️ 설정 적용** 버튼을 눌러 반영합니다.
1958
+ 3. **서열 파일 업로드** — FASTA 형식(.seq/.fasta/.fa/.fna/.fas) 파일을 선택한 뒤 **업로드한 서열 저장**을 누릅니다.
1959
  4. **① Stage 1 실행** — 서열 정렬과 변이 프로파일 생성을 시작합니다.
1960
  5. **② Stage 2 실행** — Stage 1 결과를 바탕으로 국가/도시 단위 유입원을 예측합니다.
1961
  6. **③ Stage 3 실행** — 지리적 분석 표와 그림을 생성합니다.
1962
+ 7. **결과 확인/다운로드** — 먼저 "🔄 결과 새로고침"으로 최신 표·그림을 불러온 뒤, "전체 ZIP으로 다운로드" 또는 개별 파일을 내려받습니다.
1963
  8. **📊 2D 시각화 생성** — 모델 프로파일과 사용자 서열을 t-SNE로 투영한 인터랙티브 그래프를 볼 수 있습니다.
1964
+
1965
+ ## 단계별 결과 파일
1966
+
1967
+ 각 단계에서 **어떤 파일이 만들어지는지**, 그리고 **어디에서 확인·다운로드하는지**를 보여줍니다. 다운로드 가능한 파일은 **🔄 결과 새로고침** 후 목록과 ZIP에 나타납니다.
1968
+ """ + _howto_fig_html("files_ko", "DenAIGeo 단계별 결과 파일")
1969
 
1970
  _ABOUT_MD_EN = """
1971
  ## What does this tool do?
 
2070
  - **Prediction summary chart**: bar chart of probability (similarity) by top country (including the Top-3 PNG)
2071
  """
2072
 
2073
+ _HOWTO_MD_EN = _howto_fig_html("en", "DenAIGeo usage steps") + """
2074
  ## Usage steps
2075
 
2076
  Follow these steps in order, in the **🚀 Run Pipeline** tab.
 
2079
  region you want to analyze. (Gene E only exists for serotypes 1 and 2, so it's only
2080
  selectable then.)
2081
  2. Click **⚙️ Apply Settings** to apply your choice.
2082
+ 3. **Upload sequence files** — select FASTA-format files (.seq/.fasta/.fa/.fna/.fas), then click **Save Uploaded Sequences**.
2083
  4. **① Run Stage 1** — starts sequence alignment and mutation-profile generation.
2084
  5. **② Run Stage 2** — predicts country/city-level origin based on the Stage 1 results.
2085
  6. **③ Run Stage 3** — generates geographic analysis tables and figures.
2086
+ 7. **Check/download results** — click "🔄 Refresh Results" first to load the latest tables
2087
+ and figures, then download the ZIP or individual files.
2088
  8. **📊 Generate 2D Visualization** — view an interactive graph projecting the model
2089
  profiles and your user sequences together using t-SNE.
2090
+
2091
+ ## Result files by step
2092
+
2093
+ This shows **which files are created at each step** and **where to check and download them**. Downloadable files appear in the list and in the ZIP after you click **🔄 Refresh Results**.
2094
+ """ + _howto_fig_html("files_en", "DenAIGeo result files by step")
2095
 
2096
  _ABOUT_MD_TH = """
2097
  ## เครื่องมือนี้ทำอะไรได้บ้าง?
 
2193
  - **กราฟสรุปผลการทำนาย**: แผนภูมิแท่งแสดงความน่าจะเป็น (ความคล้ายคลึง) ของแต่ละประเทศอันดับสูงสุด (รวมไฟล์ PNG Top-3)
2194
  """
2195
 
2196
+ _HOWTO_MD_TH = _howto_fig_html("th", "ขั้นตอนการใช้งาน DenAIGeo") + """
2197
  ## ขั้นตอนการใช้งาน
2198
 
2199
  ทำตามขั้นตอนต่อไปนี้ตามลำดับ ในแท็บ **🚀 Run Pipeline**
 
2208
  7. **ตรวจสอบ/ดาวน์โหลดผลลัพธ์** — คลิก "🔄 Refresh Results" เพื่อโหลดตารางและกราฟล่าสุด
2209
  8. **📊 Generate 2D Visualization** — ดูกราฟเชิงโต้ตอบที่ฉายโปรไฟล์แบบจำลองและลำดับของผู้ใช้
2210
  ร่วมกันด้วย t-SNE
2211
+
2212
+ ## ไฟล์ผลลัพธ์ของแต่ละขั้นตอน
2213
+
2214
+ แสดง **ไฟล์ที่ถูกสร้างขึ้นในแต่ละขั้นตอน** และ **ตำแหน่งที่ตรวจสอบและดาวน์โหลดได้** ไฟล์ที่ดาวน์โหลดได้จะปรากฏในรายการและไฟล์ ZIP หลังจากคลิก **🔄 รีเฟรชผลลัพธ์**
2215
+ """ + _howto_fig_html("files_th", "ไฟล์ผลลัพธ์ของ DenAIGeo ในแต่ละขั้นตอน")
2216
 
2217
 
2218
  _ID_UI = {
 
2531
  Information)**. Penggunaan atau redistribusi tanpa izin dilarang.
2532
  """
2533
 
2534
+ _HOWTO_MD_ID = _howto_fig_html("id", "Langkah penggunaan DenAIGeo") + """
2535
  ## Langkah penggunaan
2536
 
2537
  Ikuti langkah-langkah berikut secara berurutan di tab **🚀 Jalankan Pipeline**.
 
2547
  7. **Periksa/unduh hasil** — klik "🔄 Segarkan Hasil" untuk memuat tabel dan gambar terbaru.
2548
  8. **📊 Buat Visualisasi 2D** — lihat grafik interaktif yang memproyeksikan profil model
2549
  dan sekuens pengguna Anda bersama-sama menggunakan t-SNE.
2550
+
2551
+ ## File hasil per tahap
2552
+
2553
+ Bagian ini menunjukkan **file apa yang dibuat pada setiap tahap** dan **di mana memeriksa serta mengunduhnya**. File yang dapat diunduh muncul di daftar dan di ZIP setelah Anda mengklik **🔄 Segarkan Hasil**.
2554
+ """ + _howto_fig_html("files_id", "File hasil DenAIGeo per tahap")
2555
 
2556
  _METHOD_MD_ID = _method_fig_html("id", "Gambaran umum metode DenAIGeo") + """
2557
  ## Metode sekilas
build_usage_files_figs.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """'사용법' 탭의 '단계별 결과 파일' 그림을 4개 언어로 그려서 howto_figs.py 의 HOWTO_FIGS 에
3
+ "files_ko" / "files_en" / "files_th" / "files_id" 키로 추가(갱신)합니다.
4
+ 사용법: python build_usage_files_figs.py (playwright + chromium + pillow 필요. 한글/태국어 글꼴 필요)
5
+ 문구를 바꾸려면 아래 TEXT 사전을 수정하고 다시 실행하세요."""
6
+ import base64, io, os, re, tempfile
7
+ from PIL import Image
8
+ from playwright.sync_api import sync_playwright
9
+
10
+ HERE = os.path.dirname(os.path.abspath(__file__))
11
+ TEMPLATE = r"""<!doctype html><html lang="ko"><head><meta charset="utf-8"><style>
12
+ *{box-sizing:border-box;margin:0;padding:0}
13
+ body{width:1536px;background:#fff;font-family:'Noto Sans CJK KR','Noto Sans CJK JP',sans-serif;color:#14213d;padding:10px}
14
+ .banner{background:linear-gradient(90deg,#0f4c9a,#1565c0);color:#fff;border-radius:12px 12px 0 0;padding:16px 26px;display:flex;align-items:center;gap:16px}
15
+ .banner .n{width:46px;height:46px;border-radius:50%;background:#fff;color:#0f4c9a;font-weight:800;font-size:28px;display:flex;align-items:center;justify-content:center}
16
+ .banner h1{font-size:30px;font-weight:800;letter-spacing:-.5px}
17
+ .banner p{font-size:17px;opacity:.95;margin-top:2px}
18
+ .panel{border:1px solid #cfdcf0;border-top:none;border-radius:0 0 12px 12px;background:#f4f8ff;padding:20px 18px 16px}
19
+ .flow{display:flex;align-items:stretch;gap:0}
20
+ .col{flex:1;background:#fff;border:2px solid var(--c);border-radius:12px;overflow:hidden;display:flex;flex-direction:column}
21
+ .col .hd{background:var(--bg);padding:10px 12px;text-align:center;border-bottom:2px solid var(--c)}
22
+ .col .hd .s{font-size:14px;font-weight:800;color:var(--c);letter-spacing:.5px}
23
+ .col .hd .t{font-size:19px;font-weight:800;color:#14213d;margin-top:2px}
24
+ .col .bd{padding:10px 10px;font-size:14px;line-height:1.5;color:#334155;flex:0 0 auto;min-height:82px}
25
+ .col .out{margin:0 10px 10px;background:#f1f5f9;border-radius:8px;padding:8px 10px;flex:1}
26
+ .col .out .lab{font-size:13.5px;font-weight:800;color:#14213d;margin-bottom:5px;display:flex;justify-content:space-between;align-items:center}
27
+ .tag{font-size:11.5px;font-weight:800;border-radius:10px;padding:2px 8px;color:#fff}
28
+ .tag.dl{background:#15803d}.tag.in{background:#64748b}
29
+ .f{font-family:'DejaVu Sans Mono',monospace;font-size:11.6px;background:#fff;border:1px solid #d5dfee;border-radius:5px;padding:3px 6px;margin:3px 0;color:#14213d;word-break:break-all}
30
+ .f b{color:var(--c)}
31
+ .f.png{border-left:4px solid #c2410c}.f.csv{border-left:4px solid #2563eb}
32
+ .arrow{width:24px;display:flex;align-items:center;justify-content:center;font-size:26px;color:#2563eb;font-weight:800}
33
+ .fasta{width:54px;height:66px;border:3px solid #2563eb;border-radius:6px;position:relative;margin:2px auto 6px;background:#eaf2ff}
34
+ .fasta span{position:absolute;bottom:-1px;left:-3px;right:-3px;background:#2563eb;color:#fff;font-size:12px;font-weight:800;text-align:center;border-radius:0 0 4px 4px;padding:2px 0}
35
+ .note{font-size:12.5px;color:#64748b;margin-top:4px}
36
+ .sub{margin-top:16px;display:grid;grid-template-columns:1fr 1fr 1.25fr;gap:16px}
37
+ .card{background:#fff;border:2px solid var(--c);border-radius:12px;overflow:hidden}
38
+ .card .hd{background:var(--bg);padding:9px 14px;border-bottom:2px solid var(--c);display:flex;align-items:center;gap:10px}
39
+ .card .hd .s{font-size:13.5px;font-weight:800;color:#fff;background:var(--c);border-radius:10px;padding:2px 9px}
40
+ .card .hd .t{font-size:18px;font-weight:800}
41
+ .card .bd{padding:10px 14px 12px;font-size:14.5px;line-height:1.55;color:#334155}
42
+ .card .bd .out{margin-top:8px;background:#f1f5f9;border-radius:8px;padding:8px 10px}
43
+ .where{display:flex;gap:10px;margin-top:2px}
44
+ .where .step{flex:1;background:#fff;border:1px solid #cfdcf0;border-radius:10px;padding:8px 10px;font-size:14px;line-height:1.5}
45
+ .where .step b{color:#0f4c9a}
46
+ .zip{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
47
+ .btn{font-size:13px;font-weight:800;color:#fff;border-radius:7px;padding:5px 10px}
48
+ .legend{margin-top:12px;display:flex;gap:18px;align-items:center;font-size:13.5px;color:#475569;justify-content:flex-end}
49
+ .sw{display:inline-block;width:14px;height:14px;border-radius:3px;vertical-align:-2px;margin-right:5px}
50
+ </style></head><body>
51
+ <div class="banner"><div class="n">★</div><div><h1>{title}</h1><p>{sub}</p></div></div>
52
+ <div class="panel">
53
+ <div class="flow">
54
+ <div class="col" style="--c:#475569;--bg:#eef2f7">
55
+ <div class="hd"><div class="s">STEP 1</div><div class="t">{s1t}</div></div>
56
+ <div class="bd">{s1d}</div>
57
+ <div class="out"><div class="lab">{res} <span class="tag in">{t_screen}</span></div>
58
+ <div class="f">{s1o}<br><span style="font-family:inherit">(Serotype · Gene)</span></div></div>
59
+ </div>
60
+ <div class="arrow">➜</div>
61
+ <div class="col" style="--c:#2563eb;--bg:#e8f0ff">
62
+ <div class="hd"><div class="s">STEP 2</div><div class="t">{s2t}</div></div>
63
+ <div class="bd"><div class="fasta"><span>FASTA</span></div>{s2d}</div>
64
+ <div class="out"><div class="lab">{res} <span class="tag in">{t_in}</span></div>
65
+ <div class="f">{s2o}</div></div>
66
+ </div>
67
+ <div class="arrow">➜</div>
68
+ <div class="col" style="--c:#1d4ed8;--bg:#e5ecff">
69
+ <div class="hd"><div class="s">STEP 3-①</div><div class="t">Stage 1</div></div>
70
+ <div class="bd">{p1d}</div>
71
+ <div class="out"><div class="lab">{res} <span class="tag in">{t_in}</span></div>
72
+ <div class="f csv"><b>{p1o}</b><br>{p1o2}</div>
73
+ <div class="note">{p1n}</div></div>
74
+ </div>
75
+ <div class="arrow">➜</div>
76
+ <div class="col" style="--c:#15803d;--bg:#e6f6ec">
77
+ <div class="hd"><div class="s">STEP 3-②</div><div class="t">Stage 2</div></div>
78
+ <div class="bd">{p2d}</div>
79
+ <div class="out"><div class="lab">{res_csv} <span class="tag dl">{t_dl}</span></div>
80
+ <div class="f csv"><b>[r0]</b>newseq_byCountry_similarity…</div>
81
+ <div class="f csv"><b>[r1]</b>unknown_top5_similarity…</div>
82
+ <div class="f csv"><b>[r2]</b>unknown_best_region_similarity…</div>
83
+ <div class="f csv"><b>[r1-1]</b>city_within_topCountry…</div>
84
+ <div class="f csv"><b>[r2-1]</b>best_city_within_bestCountry…</div></div>
85
+ </div>
86
+ <div class="arrow">➜</div>
87
+ <div class="col" style="--c:#c2410c;--bg:#fff0e6">
88
+ <div class="hd"><div class="s">STEP 3-③</div><div class="t">Stage 3</div></div>
89
+ <div class="bd">{p3d}</div>
90
+ <div class="out"><div class="lab">{tab_fig} <span class="tag dl">{t_dl}</span></div>
91
+ <div class="f png"><b>PNG</b> 01_overall_source_region</div>
92
+ <div class="f png"><b>PNG</b> 02_overall_source_country</div>
93
+ <div class="f png"><b>PNG</b> 03_endemic_vs_imported</div>
94
+ <div class="f png"><b>PNG</b> 04_region_flow_heatmap</div>
95
+ <div class="f png"><b>PNG</b> {p3png}</div>
96
+ <div class="f csv"><b>CSV</b> {p3csv}</div>
97
+ <div class="note">{p3n}</div></div>
98
+ </div>
99
+ </div>
100
+
101
+ <div class="sub">
102
+ <div class="card" style="--c:#6d28d9;--bg:#f1eaff"><div class="hd"><span class="s">STEP 4</span><span class="t">{s4t}</span></div>
103
+ <div class="bd"><div class="where"><div class="step">① <b>{refresh}</b><br>{s4a}</div><div class="step">② <b>{zip}</b><br>{s4b}</div></div>
104
+ <div class="out"><div class="f">{s4l1}</div><div class="f">{s4l2}</div></div></div></div>
105
+ <div class="card" style="--c:#0f766e;--bg:#e4f6f3"><div class="hd"><span class="s">STEP 5-a</span><span class="t">{s5at}</span></div>
106
+ <div class="bd">{s5ad}
107
+ <div class="out"><div class="lab">{res} <span class="tag dl">{t_dl}</span></div><div class="f png"><b>PNG</b> {s5ap}</div><div class="note">{s5an}</div></div></div></div>
108
+ <div class="card" style="--c:#0891b2;--bg:#e3f4fa"><div class="hd"><span class="s">STEP 5-b</span><span class="t">{s5bt}</span></div>
109
+ <div class="bd">{s5bd}
110
+ <div class="out"><div class="lab">{res} <span class="tag dl">{t_dl}</span></div><div class="f png"><b>PNG</b> top3_countries_{s5bp}.png</div></div></div></div>
111
+ </div>
112
+ <div class="legend"><span><i class="sw" style="background:#2563eb"></i>{l_csv}</span><span><i class="sw" style="background:#c2410c"></i>{l_png}</span><span><i class="sw" style="background:#15803d"></i>{l_dl}</span><span><i class="sw" style="background:#64748b"></i>{l_in}</span><span>{l_note}</span></div>
113
+ </div></body></html>
114
+ """
115
+
116
+ TEXT = {
117
+ "ko": dict(
118
+ title="파이프라인 실행 — 단계별 결과 파일",
119
+ sub="사용 순서대로 <b>어떤 파일이 만들어지고</b>, <b>어디에서 확인·다운로드하는지</b> 보여줍니다.",
120
+ res="결과", res_csv="결과 CSV", tab_fig="표 + 그림", t_dl="다운로드", t_in="내부 저장", t_screen="화면 표시",
121
+ s1t="분석 설정", s1d="혈청형(1~4)과 유전자 영역을 고르고 <b>설정 적용</b>을 클릭합니다.", s1o="적용된 설정",
122
+ s2t="서열 업로드", s2d="FASTA 파일을 선택하고 <b>업로드한 서열 저장</b>을 클릭합니다.",
123
+ s2o="저장된 서열 목록<br><span style=\"font-family:inherit\">→ <b>현재 저장된 서열 확인</b>으로 점검</span>",
124
+ p1d="<b>변이 프로파일 계산</b><br>Reference와 MAFFT 정렬 → 위치별 변이율 계산", p1o="변이 분석 CSV", p1o2="(서열별 변이 프로파일)", p1n="다운로드 목록에는 나타나지 않습니다.",
125
+ p2d="<b>국가별 유사도 계산</b><br>국가별 모델 프로파일과 비교 → 국가·도시 순위",
126
+ p3d="<b>지역별 집계 및 분석</b><br>[r1-1] 결과를 지역 단위로 집계", p3png="05·06 국가별/도시별 그림", p3csv="overall_source_country 등 표", p3n="데이터에 따라 일부 그림은 생략됩니다.",
127
+ s4t="결과 확인 및 다운로드", refresh="결과 새로고침 클릭", s4a="→ 최신 표·그림 불러오기", zip="전체 ZIP으로 다운로드", s4b="또는 개별 파일 다운로드",
128
+ s4l1="다운로드 가능한 결과 파일(CSV, PNG) 목록", s4l2="그림 보기 갤러리 (클릭하면 확대)",
129
+ s5at="(선택) 2D 시각화", s5ad="모델 프로파일(국가별)과 내 서열을 한 평면에 투영합니다.", s5ap="2D 임베딩 산점도", s5an="화면에서는 인터랙티브 플롯으로 확인",
130
+ s5bt="(선택) 예측 요약 차트", s5bd="[r1-1] 결과의 서열별 Top-3 국가와 유사도(%)를 막대그래프로 표시합니다.", s5bp="&lt;혈청형&gt;_&lt;유전자&gt;_&lt;시각&gt;",
131
+ l_csv="CSV 표", l_png="PNG 그림", l_dl="다운로드 가능", l_in="내부 저장(다운로드 대상 아님)", l_note="※ 각 단계는 앞 단계 결과를 사용하므로 반드시 순서대로 실행"),
132
+ "en": dict(
133
+ title="Run Pipeline — Result Files by Step",
134
+ sub="In the order of use: <b>which files are created</b> and <b>where to check and download them</b>.",
135
+ res="Output", res_csv="Output CSV", tab_fig="Tables + Figures", t_dl="Download", t_in="Internal", t_screen="On screen",
136
+ s1t="Settings", s1d="Choose the serotype (1–4) and gene region, then click <b>Apply Settings</b>.", s1o="Applied settings",
137
+ s2t="Upload", s2d="Select FASTA file(s) and click <b>Save Uploaded Sequences</b>.",
138
+ s2o="Saved sequence list<br><span style=\"font-family:inherit\">→ check with <b>Check Saved Sequences</b></span>",
139
+ p1d="<b>Mutation profile calculation</b><br>MAFFT alignment with reference → site-wise mutation rates", p1o="Mutation analysis CSV", p1o2="(profile per sequence)", p1n="Not shown in the download list.",
140
+ p2d="<b>Country similarity calculation</b><br>Compare with country model profiles → country/city ranking",
141
+ p3d="<b>Regional aggregation and analysis</b><br>Aggregate [r1-1] results by region", p3png="05·06 per-country / city figures", p3csv="tables, e.g. overall_source_country", p3n="Some figures are omitted depending on the data.",
142
+ s4t="Check results and download", refresh="Click Refresh Results", s4a="→ load the latest tables and figures", zip="Download All as ZIP", s4b="or download individual files",
143
+ s4l1="Downloadable result files (CSV, PNG) list", s4l2="Figure gallery (click to enlarge)",
144
+ s5at="(Optional) 2D Visualization", s5ad="Projects the country model profiles and your sequences onto one plane.", s5ap="2D embedding scatter plot", s5an="Shown as an interactive plot on screen",
145
+ s5bt="(Optional) Prediction Summary Chart", s5bd="Bar chart of the Top-3 countries and similarity (%) per sequence from [r1-1].", s5bp="&lt;serotype&gt;_&lt;gene&gt;_&lt;time&gt;",
146
+ l_csv="CSV table", l_png="PNG figure", l_dl="Downloadable", l_in="Stored internally (not for download)", l_note="※ Each step uses the previous step's results, so run them in order"),
147
+ "th": dict(
148
+ title="เรียกใช้ไปป์ไลน์ — ไฟล์ผลลัพธ์ของแต่ละขั้นตอน",
149
+ sub="ตามลำดับการใช้งาน: <b>ไฟล์ใดถูกสร้างขึ้น</b> และ <b>ตรวจสอบ/ดาวน์โหลดได้ที่ไหน</b>",
150
+ res="ผลลัพธ์", res_csv="ผลลัพธ์ CSV", tab_fig="ตาราง + รูปภาพ", t_dl="ดาวน์โหลด", t_in="เก็บภายใน", t_screen="แสดงบนหน้าจอ",
151
+ s1t="ตั้งค่า", s1d="เลือกสายพันธุ์ (1–4) และส่วนยีน แล้วคลิก <b>ใช้การตั้งค่า</b>", s1o="การตั้งค่าที่ใช้",
152
+ s2t="อัปโหลด", s2d="เลือกไฟล์ FASTA แล้วคลิก <b>บันทึกลำดับที่อัปโหลด</b>",
153
+ s2o="รายการลำดับที่บันทึก<br><span style=\"font-family:inherit\">→ ตรวจสอบด้วย <b>ตรวจสอบลำดับที่บันทึกไว้</b></span>",
154
+ p1d="<b>คำนวณอัตราการกลายพันธุ์</b><br>จัดเรียงด้วย MAFFT กับสายอ้างอิง → อัตราการกลายพันธุ์รายตำแหน่ง", p1o="ไฟล์ CSV การวิเคราะห์การกลายพันธุ์", p1o2="(โปรไฟล์ของแต่ละลำดับ)", p1n="ไม่แสดงในรายการดาวน์โหลด",
155
+ p2d="<b>คำนวณความคล้ายคลึงระดับประเทศ</b><br>เปรียบเทียบกับโปรไฟล์แบบจำลองของประเทศ → จัดอันดับประเทศ/เมือง",
156
+ p3d="<b>สรุประดับภูมิภาคและวิเคราะห์</b><br>รวมผล [r1-1] ตามภูมิภาค", p3png="05·06 รูปรายประเทศ/เมือง", p3csv="ตาราง เช่น overall_source_country", p3n="บางรูปอาจไม่ถูกสร้างขึ้นขึ้นกับข้อมูล",
157
+ s4t="ตรวจสอบผลลัพธ์และดาวน์โหลด", refresh="คลิก รีเฟรชผลลัพธ์", s4a="→ โหลดตารางและรูปล่าสุด", zip="ดาวน์���หลดทั้งหมด (ZIP)", s4b="หรือดาวน์โหลดทีละไฟล์",
158
+ s4l1="รายการไฟล์ผลลัพธ์ที่ดาวน์โหลดได้ (CSV, PNG)", s4l2="แกลเลอรีรูปภาพ (คลิกเพื่อขยาย)",
159
+ s5at="(ตัวเลือก) การแสดงผล 2D", s5ad="ฉายโปรไฟล์แบบจำลองของประเทศและลำดับของคุณลงบนระนาบเดียวกัน", s5ap="แผนภาพกระจาย 2 มิติ", s5an="แสดงเป็นกราฟโต้ตอบบนหน้าจอ",
160
+ s5bt="(ตัวเลือก) กราฟสรุปผลการทำนาย", s5bd="แผนภูมิแท่ง 3 ประเทศอันดับสูงสุดและความคล้ายคลึง (%) ของแต่ละลำดับจาก [r1-1]", s5bp="&lt;สายพันธุ์&gt;_&lt;ยีน&gt;_&lt;เวลา&gt;",
161
+ l_csv="ตาราง CSV", l_png="รูป PNG", l_dl="ดาวน์โหลดได้", l_in="เก็บภายใน (ไม่ให้ดาวน์โหลด)", l_note="※ แต่ละขั้นตอนใช้ผลจากขั้นตอนก่อนหน้า จึงต้องรันตามลำดับ"),
162
+ "id": dict(
163
+ title="Jalankan Pipeline — File Hasil per Tahap",
164
+ sub="Sesuai urutan penggunaan: <b>file apa yang dibuat</b> dan <b>di mana memeriksa serta mengunduhnya</b>.",
165
+ res="Hasil", res_csv="CSV hasil", tab_fig="Tabel + Gambar", t_dl="Unduh", t_in="Internal", t_screen="Di layar",
166
+ s1t="Pengaturan", s1d="Pilih serotipe (1–4) dan wilayah gen, lalu klik <b>Terapkan Pengaturan</b>.", s1o="Pengaturan diterapkan",
167
+ s2t="Unggah", s2d="Pilih file FASTA lalu klik <b>Simpan Sekuens yang Diunggah</b>.",
168
+ s2o="Daftar sekuens tersimpan<br><span style=\"font-family:inherit\">→ periksa dengan <b>Lihat Sekuens Tersimpan</b></span>",
169
+ p1d="<b>Perhitungan profil mutasi</b><br>Penyelarasan MAFFT dengan referensi → tingkat mutasi per posisi", p1o="CSV analisis mutasi", p1o2="(profil tiap sekuens)", p1n="Tidak muncul di daftar unduhan.",
170
+ p2d="<b>Perhitungan similaritas antar negara</b><br>Bandingkan dengan profil model negara → peringkat negara/kota",
171
+ p3d="<b>Agregasi wilayah dan analisis</b><br>Agregasi hasil [r1-1] per wilayah", p3png="05·06 gambar per negara / kota", p3csv="tabel, mis. overall_source_country", p3n="Sebagian gambar dilewati tergantung data.",
172
+ s4t="Periksa hasil dan unduh", refresh="Klik Segarkan Hasil", s4a="→ muat tabel dan gambar terbaru", zip="Unduh Semua sebagai ZIP", s4b="atau unduh file satu per satu",
173
+ s4l1="Daftar file hasil yang dapat diunduh (CSV, PNG)", s4l2="Galeri gambar (klik untuk memperbesar)",
174
+ s5at="(Opsi) Visualisasi 2D", s5ad="Memproyeksikan profil model negara dan sekuens Anda ke satu bidang.", s5ap="Plot sebar embedding 2D", s5an="Tampil sebagai plot interaktif di layar",
175
+ s5bt="(Opsi) Grafik Ringkasan Prediksi", s5bd="Diagram batang 3 negara teratas dan similaritas (%) tiap sekuens dari [r1-1].", s5bp="&lt;serotipe&gt;_&lt;gen&gt;_&lt;waktu&gt;",
176
+ l_csv="Tabel CSV", l_png="Gambar PNG", l_dl="Dapat diunduh", l_in="Disimpan internal (tidak untuk diunduh)", l_note="※ Tiap tahap memakai hasil tahap sebelumnya, jalankan secara berurutan"),
177
+ }
178
+
179
+
180
+ def render(lang, browser):
181
+ d = TEXT[lang]
182
+ html = TEMPLATE
183
+ for k, v in d.items():
184
+ html = html.replace("{" + k + "}", v)
185
+ assert not re.search(r"\{[a-z0-9_]+\}", re.sub(r"<style>.*?</style>", "", html, flags=re.S)), "치환되지 않은 항목이 있습니다"
186
+ html = html.replace("lang=\"ko\"", f"lang=\"{lang}\"")
187
+ with tempfile.TemporaryDirectory() as td:
188
+ hp = os.path.join(td, "u.html")
189
+ open(hp, "w", encoding="utf-8").write(html)
190
+ pg = browser.new_page(viewport={"width": 1556, "height": 900}, device_scale_factor=1)
191
+ pg.goto("file://" + hp)
192
+ pg.wait_for_timeout(400)
193
+ h = pg.evaluate("document.querySelector('.panel').getBoundingClientRect().bottom+10")
194
+ png = pg.screenshot(clip={"x": 0, "y": 0, "width": 1556, "height": h})
195
+ pg.close()
196
+ buf = io.BytesIO()
197
+ Image.open(io.BytesIO(png)).convert("RGB").save(buf, "JPEG", quality=90, optimize=True)
198
+ return base64.b64encode(buf.getvalue()).decode("ascii")
199
+
200
+
201
+ def main():
202
+ import importlib.util
203
+ path = os.path.join(HERE, "howto_figs.py")
204
+ spec = importlib.util.spec_from_file_location("howto_figs", path)
205
+ mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod)
206
+ figs = dict(mod.HOWTO_FIGS)
207
+ with sync_playwright() as p:
208
+ browser = p.chromium.launch(executable_path=os.environ.get("CHROMIUM_PATH") or None)
209
+ for lang in TEXT:
210
+ figs["files_" + lang] = render(lang, browser)
211
+ print(lang, "ok")
212
+ browser.close()
213
+ with open(path, "w", encoding="utf-8") as f:
214
+ f.write("# -*- coding: utf-8 -*-\n# build_howto_figs.py / build_usage_files_figs.py 가 생성한 파일입니다 (사용법 탭 그림을 base64 텍스트로 보관).\nHOWTO_FIGS = {\n")
215
+ for k, v in figs.items():
216
+ f.write(f' "{k}": "{v}",\n')
217
+ f.write("}\n")
218
+ print("saved howto_figs.py:", sorted(figs))
219
+
220
+
221
+ if __name__ == "__main__":
222
+ main()
howto_figs.py ADDED
The diff for this file is too large to render. See raw diff