noisemarseille commited on
Commit
f2bb329
·
1 Parent(s): 1dbe522
Files changed (4) hide show
  1. Dockerfile +7 -1
  2. app.py +22 -1
  3. static/style.css +9 -0
  4. templates/index.html +44 -9
Dockerfile CHANGED
@@ -32,6 +32,12 @@ COPY --chown=user . .
32
 
33
  EXPOSE 7860
34
 
 
 
 
 
 
 
35
  CMD ["gunicorn", "app:app", \
36
  "--workers", "1", "--threads", "4", "--worker-class", "gthread", \
37
- "--timeout", "300", "--bind", "0.0.0.0:7860"]
 
32
 
33
  EXPOSE 7860
34
 
35
+ # --timeout 900: /analyze's synchronous path (ESM/PHLAM load, annotation
36
+ # retriever's first touch of reference_min.* on hfmount) can be slow on a
37
+ # cold start over a network-mounted bucket -- this is gunicorn's worker
38
+ # silence timeout, not a hard request cap; background jobs (neighbor
39
+ # search, synteny) run in threads and never block a worker at all, so they
40
+ # aren't bound by this regardless of how long the FAISS indexes take.
41
  CMD ["gunicorn", "app:app", \
42
  "--workers", "1", "--threads", "4", "--worker-class", "gthread", \
43
+ "--timeout", "900", "--bind", "0.0.0.0:7860"]
app.py CHANGED
@@ -6,7 +6,7 @@ import uuid
6
  import numpy as np
7
  from flask import Flask, jsonify, render_template, request
8
 
9
- from pipeline import run_pipeline
10
  from utils.genome_neighbor_retrieval import GenomeNeighborRetriever
11
  from utils.protein_neighbor_retrieval import ProteinNeighborRetriever
12
  from utils.gene_context_retrieval import GeneContextRetriever
@@ -81,6 +81,27 @@ def _start_job(fn):
81
  return job_id
82
 
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  @app.route("/", methods=["GET"])
85
  def index():
86
  return render_template("index.html")
 
6
  import numpy as np
7
  from flask import Flask, jsonify, render_template, request
8
 
9
+ from pipeline import run_pipeline, _get_esm, _get_phlam, _get_annotation_retriever
10
  from utils.genome_neighbor_retrieval import GenomeNeighborRetriever
11
  from utils.protein_neighbor_retrieval import ProteinNeighborRetriever
12
  from utils.gene_context_retrieval import GeneContextRetriever
 
81
  return job_id
82
 
83
 
84
+ def _warm_up(name, fn):
85
+ """Touches one model/index at process start so the first real request
86
+ isn't the one paying the cold-load cost -- especially the big FAISS
87
+ indexes on a network-mounted bucket. Each runs in its own thread so
88
+ one slow index doesn't delay the others."""
89
+ try:
90
+ t0 = time.time()
91
+ fn()
92
+ print(f"[warmup] {name} ready in {time.time() - t0:.1f}s")
93
+ except Exception as e:
94
+ print(f"[warmup] {name} failed: {e}")
95
+
96
+
97
+ for _name, _fn in (
98
+ ("esm", _get_esm), ("phlam", _get_phlam), ("annotation", _get_annotation_retriever),
99
+ ("genome_retriever", _get_genome_retriever), ("protein_retriever", _get_protein_retriever),
100
+ ("gene_context_retriever", _get_gene_context_retriever),
101
+ ):
102
+ threading.Thread(target=_warm_up, args=(_name, _fn), daemon=True).start()
103
+
104
+
105
  @app.route("/", methods=["GET"])
106
  def index():
107
  return render_template("index.html")
static/style.css CHANGED
@@ -36,6 +36,15 @@ body { margin: 0; background: var(--bg); font-family: var(--sans); color: var(--
36
  .section { padding: 22px 28px; border-bottom: 1px solid var(--line); }
37
  .h2 { font: 600 16px var(--sans); margin: 0 0 14px; }
38
 
 
 
 
 
 
 
 
 
 
39
  .tabs { display: flex; align-items: center; gap: 26px; padding: 0 28px; border-bottom: 1px solid var(--line); }
40
  .tab { font: 400 15px var(--sans); color: var(--ink2); padding: 16px 0; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-left: 0; border-right: 0; border-top: 0; }
41
  .tab.on { font-weight: 600; color: var(--ink); border-bottom-color: var(--ink); }
 
36
  .section { padding: 22px 28px; border-bottom: 1px solid var(--line); }
37
  .h2 { font: 600 16px var(--sans); margin: 0 0 14px; }
38
 
39
+ .genome { display: flex; align-items: flex-end; gap: 36px; padding: 22px 28px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
40
+ .genome .id { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
41
+ .genome .acc { font: 500 19px var(--mono); word-break: break-all; }
42
+ .genome .name { font-size: 15px; color: var(--ink2); }
43
+ .facts { margin-left: auto; display: flex; gap: 32px; flex-wrap: wrap; }
44
+ .fact { display: flex; flex-direction: column; gap: 4px; }
45
+ .fact span { font-size: 11.5px; color: var(--ink3); text-transform: uppercase; letter-spacing: .05em; }
46
+ .fact b { font: 400 16px var(--mono); }
47
+
48
  .tabs { display: flex; align-items: center; gap: 26px; padding: 0 28px; border-bottom: 1px solid var(--line); }
49
  .tab { font: 400 15px var(--sans); color: var(--ink2); padding: 16px 0; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-left: 0; border-right: 0; border-top: 0; }
50
  .tab.on { font-weight: 600; color: var(--ink); border-bottom-color: var(--ink); }
templates/index.html CHANGED
@@ -29,6 +29,17 @@
29
  </div>
30
  </section>
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  <div class="tabs" id="view-tabs" hidden>
33
  <button class="tab on" data-tab="circular">Circular</button>
34
  <button class="tab" data-tab="genes">Genes</button>
@@ -36,7 +47,7 @@
36
  <div class="legend" id="legend" hidden></div>
37
 
38
  <section class="section" id="circular-section" hidden>
39
- <div id="circular-plot" class="scroll-pane"></div>
40
  </section>
41
 
42
  <section class="section" id="genes-section" hidden>
@@ -54,9 +65,11 @@
54
  <h2 class="h2">Nearest genomes</h2>
55
  <div class="tabs" id="neighbor-tabs">
56
  <button class="tab on" data-src="all">All</button>
57
- <button class="tab" data-src="imgvr_inphared">IMG/VR + INPHARED</button>
 
58
  </div>
59
  <p id="neighbors-status" class="status"></p>
 
60
  <div class="scroll-pane">
61
  <table id="neighbors-table" class="grid" hidden>
62
  <thead><tr><th>#</th><th>genome</th><th>genes</th><th>length (bp)</th><th>cosine</th></tr></thead>
@@ -166,17 +179,29 @@
166
  document.getElementById("genes-section").hidden = tab !== "genes";
167
  }));
168
 
169
- // "All" and "imgvr_inphared" render the same list today -- there's only
170
- // one genome corpus behind this bucket. Kept as separate tabs so a
171
- // second corpus later is just another entry here, not a UI rework.
 
172
  let neighborList = [];
173
  function renderNeighbors() {
 
 
174
  const tbody = document.querySelector("#neighbors-table tbody");
175
- tbody.innerHTML = neighborList.map((h, i) => `<tr>
 
 
 
 
 
 
 
 
 
176
  <td class="ink">${i + 1}</td><td class="ink">genome_${h.genome_id}</td>
177
  <td>${h.n_genes}</td><td>${h.length_bp ?? "-"}</td><td>${h.score.toFixed(4)}</td>
178
  </tr>`).join("");
179
- document.getElementById("neighbors-table").hidden = false;
180
  }
181
  document.querySelectorAll("#neighbor-tabs .tab").forEach(btn => btn.addEventListener("click", () => {
182
  document.querySelectorAll("#neighbor-tabs .tab").forEach(b => b.classList.remove("on"));
@@ -192,15 +217,20 @@
192
  }
193
 
194
  // Polls /job/<id> until done/error; resolves with the final {status, result, error}.
 
 
 
 
195
  async function pollJob(jobId, { onDone } = {}) {
196
- for (let i = 0; i < 150; i++) {
 
197
  const res = await fetch(`/job/${jobId}`);
198
  const data = await res.json();
199
  if (data.status !== "pending") {
200
  if (onDone) onDone(data);
201
  return data;
202
  }
203
- await new Promise(r => setTimeout(r, 2000));
204
  }
205
  return { status: "timeout" };
206
  }
@@ -281,6 +311,11 @@
281
  return;
282
  }
283
  statusEl.textContent = `Done: ${data.num_genes} genes predicted in ${data.display_name}.`;
 
 
 
 
 
284
  renderGenes(data.genes);
285
  renderLegend(data.genes);
286
  renderCircular(data);
 
29
  </div>
30
  </section>
31
 
32
+ <section class="genome" id="genome-card" hidden>
33
+ <div class="id">
34
+ <span class="acc" id="genome-acc"></span>
35
+ <span class="name" id="genome-name"></span>
36
+ </div>
37
+ <div class="facts">
38
+ <div class="fact"><span>length</span><b id="fact-length"></b></div>
39
+ <div class="fact"><span>genes</span><b id="fact-genes"></b></div>
40
+ </div>
41
+ </section>
42
+
43
  <div class="tabs" id="view-tabs" hidden>
44
  <button class="tab on" data-tab="circular">Circular</button>
45
  <button class="tab" data-tab="genes">Genes</button>
 
47
  <div class="legend" id="legend" hidden></div>
48
 
49
  <section class="section" id="circular-section" hidden>
50
+ <div id="circular-plot"></div>
51
  </section>
52
 
53
  <section class="section" id="genes-section" hidden>
 
65
  <h2 class="h2">Nearest genomes</h2>
66
  <div class="tabs" id="neighbor-tabs">
67
  <button class="tab on" data-src="all">All</button>
68
+ <button class="tab" data-src="IMGVR">IMG/VR</button>
69
+ <button class="tab" data-src="INPHARED">INPHARED</button>
70
  </div>
71
  <p id="neighbors-status" class="status"></p>
72
+ <p id="neighbors-note" class="status" hidden></p>
73
  <div class="scroll-pane">
74
  <table id="neighbors-table" class="grid" hidden>
75
  <thead><tr><th>#</th><th>genome</th><th>genes</th><th>length (bp)</th><th>cosine</th></tr></thead>
 
179
  document.getElementById("genes-section").hidden = tab !== "genes";
180
  }));
181
 
182
+ // IMGVR/INPHARED are filtered by hit.source, which the bucket doesn't
183
+ // carry yet (phlam_genomes.parquet has no source column) -- those two
184
+ // tabs show an honest "not available yet" state until it's exported;
185
+ // "All" always works since it needs no source field.
186
  let neighborList = [];
187
  function renderNeighbors() {
188
+ const src = document.querySelector("#neighbor-tabs .tab.on").dataset.src;
189
+ const rows = src === "all" ? neighborList : neighborList.filter(h => h.source === src);
190
  const tbody = document.querySelector("#neighbors-table tbody");
191
+ const table = document.getElementById("neighbors-table");
192
+ const note = document.getElementById("neighbors-note");
193
+ if (src !== "all" && !neighborList.some(h => "source" in h)) {
194
+ table.hidden = true;
195
+ note.hidden = false;
196
+ note.textContent = "Per-source genome metadata isn't available yet -- use \"All\" for now.";
197
+ return;
198
+ }
199
+ note.hidden = true;
200
+ tbody.innerHTML = rows.map((h, i) => `<tr>
201
  <td class="ink">${i + 1}</td><td class="ink">genome_${h.genome_id}</td>
202
  <td>${h.n_genes}</td><td>${h.length_bp ?? "-"}</td><td>${h.score.toFixed(4)}</td>
203
  </tr>`).join("");
204
+ table.hidden = false;
205
  }
206
  document.querySelectorAll("#neighbor-tabs .tab").forEach(btn => btn.addEventListener("click", () => {
207
  document.querySelectorAll("#neighbor-tabs .tab").forEach(b => b.classList.remove("on"));
 
217
  }
218
 
219
  // Polls /job/<id> until done/error; resolves with the final {status, result, error}.
220
+ // Large budget: the big FAISS indexes live on a network-mounted bucket
221
+ // (hfmount), so a cold first touch can take several minutes -- the
222
+ // background job itself has no timeout, only this poll loop does.
223
+ const POLL_BUDGET_MS = 45 * 60 * 1000;
224
  async function pollJob(jobId, { onDone } = {}) {
225
+ const deadline = Date.now() + POLL_BUDGET_MS;
226
+ while (Date.now() < deadline) {
227
  const res = await fetch(`/job/${jobId}`);
228
  const data = await res.json();
229
  if (data.status !== "pending") {
230
  if (onDone) onDone(data);
231
  return data;
232
  }
233
+ await new Promise(r => setTimeout(r, 3000));
234
  }
235
  return { status: "timeout" };
236
  }
 
311
  return;
312
  }
313
  statusEl.textContent = `Done: ${data.num_genes} genes predicted in ${data.display_name}.`;
314
+ document.getElementById("genome-acc").textContent = data.genome_name;
315
+ document.getElementById("genome-name").textContent = data.display_name;
316
+ document.getElementById("fact-length").textContent = `${data.genome_length.toLocaleString()} bp`;
317
+ document.getElementById("fact-genes").textContent = data.num_genes;
318
+ document.getElementById("genome-card").hidden = false;
319
  renderGenes(data.genes);
320
  renderLegend(data.genes);
321
  renderCircular(data);