File size: 6,447 Bytes
58fcc33
 
1b2151b
 
 
1e9de42
58fcc33
 
 
 
 
 
1b2151b
58fcc33
 
1b2151b
fc9c792
1b2151b
 
 
 
58fcc33
 
 
1b2151b
 
 
 
 
 
 
 
58fcc33
 
 
c9daa18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b2151b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f7fb26
 
 
 
 
 
 
 
 
 
 
58fcc33
 
 
1b2151b
58fcc33
1b2151b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58fcc33
 
1b2151b
 
 
 
58fcc33
1b2151b
58fcc33
 
1b2151b
0f7fb26
1b2151b
58fcc33
1b2151b
 
 
 
 
 
 
58fcc33
1b2151b
 
 
 
 
 
 
58fcc33
1b2151b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58fcc33
1b2151b
 
 
 
 
 
58fcc33
 
 
 
 
1b2151b
 
 
 
11e0ddf
1b2151b
 
58fcc33
1b2151b
 
 
 
 
 
 
58fcc33
1b2151b
58fcc33
1b2151b
58fcc33
1b2151b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58fcc33
98616a2
1b2151b
 
 
 
 
 
 
 
 
 
58fcc33
 
 
 
1b2151b
 
 
 
 
 
 
 
 
 
 
58fcc33
1b2151b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58fcc33
 
 
 
 
1b2151b
58fcc33
1b2151b
 
 
 
 
58fcc33
 
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
(() => {
  "use strict";

  const DATASET_BASE =
    "https://huggingface.co/datasets/" +
    "BoevaLab/Gene-Embedding-Hub-dataset/tree/main/";

  const grid = document.getElementById("grid");
  const search = document.getElementById("search");
  const category = document.getElementById("category");
  const dialog = document.getElementById("detail-dialog");
  const detail = document.getElementById("detail-content");

  let catalog = [];




  document
    .getElementById("close-detail")
    .addEventListener("click", () => dialog.close());

  const escapeHtml = (value) => {
    const div = document.createElement("div");

    const safeValue =
      value === null || value === undefined
        ? ""
        : String(value);

    div.textContent = safeValue;

    return div.innerHTML;
  };


  const externalValue = (label, url) => {
    const safeLabel = escapeHtml(label || "—");
    const rawUrl = String(url || "").trim();

    if (!/^https?:\/\//i.test(rawUrl)) {
      return safeLabel;
    }

    return `
      <a
        href="${escapeHtml(rawUrl)}"
        target="_blank"
        rel="noopener noreferrer"
      >${safeLabel}</a>`;
  };

  const communityBadge = (item) => {
    if (item.community_contribution !== true) {
      return "";
    }

    return `
      <span class="badge community-badge">
        Community contribution
      </span>`;
  };

  const contributorDetail = (item) => {
    if (item.community_contribution !== true) {
      return "";
    }

    const name = String(
      item.contributor_name || "Not recorded"
    ).trim();

    const affiliation = String(
      item.contributor_affiliation || ""
    ).trim();

    const affiliationText = affiliation
      ? ` — ${escapeHtml(affiliation)}`
      : "";

    return `
      <p>
        <b>Contributor:</b>
        ${escapeHtml(name)}${affiliationText}
      </p>`;
  };


  const categoryClass = (value) => {
    const slug = String(value || "Other")
      .trim()
      .toLowerCase()
      .replace(/[^a-z0-9]+/g, "-")
      .replace(/^-+|-+$/g, "");

    return `category-${slug || "other"}`;
  };

  function render() {
    const term = search.value.trim().toLowerCase();
    const selected = category.value;

    const items = catalog.filter((item) => {
      if (
        selected !== "All" &&
        item.category !== selected
      ) {
        return false;
      }

      const haystack = [
        item.name,
        item.category,
        item.modality,
        item.algorithm,
        item.description,
        item.contributor_name,
        item.contributor_affiliation,
      ]
        .map((value) => String(value || ""))
        .join(" ")
        .toLowerCase();

      return !term || haystack.includes(term);
    });

    document.getElementById("result-count").textContent =
      `${items.length} of ${catalog.length} embedding sets`;

    grid.innerHTML = "";

    items.forEach((item) => {
      const card = document.createElement("button");

      card.className = `card ${categoryClass(item.category)}`;

      card.innerHTML = `
        <div class="badge-row">
          <span class="badge">
            ${escapeHtml(item.category || "Uncategorized")}
          </span>
          ${communityBadge(item)}
        </div>

        <h3>${escapeHtml(item.name)}</h3>

        <p>
          ${escapeHtml(
            item.description || "No description provided."
          )}
        </p>

        <div class="metrics">
          <span>
            <strong>
              ${Number(item.n_genes).toLocaleString()}
            </strong>
            genes
          </span>

          <span>
            <strong>
              ${Number(item.n_dims).toLocaleString()}
            </strong>
            dims
          </span>

          <span>
            <strong>${item.coverage_pct}%</strong>
            coverage
          </span>
        </div>`;

      card.addEventListener(
        "click",
        () => openDetail(item)
      );

      grid.appendChild(card);
    });
  }

  function openDetail(item) {
    const path =
      item.dataset_path ||
      `data/embeddings/${item.id}`;

    const packageUrl =
      `${DATASET_BASE}${encodeURI(path)}`;

    detail.innerHTML = `
      <div class="badge-row">
        <span class="badge">
          ${escapeHtml(item.category || "Uncategorized")}
        </span>
        ${communityBadge(item)}
      </div>

      <h2>${escapeHtml(item.name)}</h2>

      <p>${escapeHtml(item.description || "")}</p>

      <div class="detail-grid">
        <div>
          <strong>
            ${Number(item.n_genes).toLocaleString()}
          </strong>
          genes
        </div>

        <div>
          <strong>
            ${Number(item.n_dims).toLocaleString()}
          </strong>
          dimensions
        </div>

        <div>
          <strong>${item.coverage_pct}%</strong>
          coverage
        </div>
      </div>
${contributorDetail(item)}

      <a
        class="button primary"
        href="${escapeHtml(packageUrl)}"
        target="_blank"
        rel="noopener noreferrer"
      >
        Open package files
      </a>`;

    dialog.showModal();
  }

  async function init() {
    const response = await fetch(
      "catalog.json",
      { cache: "no-store" }
    );

    if (!response.ok) {
      throw new Error(
        `Could not load catalog.json (${response.status})`
      );
    }

    catalog = await response.json();

    const categories = [
      ...new Set(
        catalog.map((item) =>
          String(item.category || "Uncategorized")
        )
      ),
    ].sort();

    categories.forEach((value) => {
      category.add(new Option(value, value));
    });

    document.getElementById("stat-count").textContent =
      catalog.length.toLocaleString();

    document.getElementById("stat-genes").textContent =
      Math.max(
        ...catalog.map(
          (item) => Number(item.n_genes) || 0
        )
      ).toLocaleString();

    const dims = catalog.map(
      (item) => Number(item.n_dims) || 0
    );

    document.getElementById("stat-dims").textContent =
      `${Math.min(...dims).toLocaleString()}–` +
      `${Math.max(...dims).toLocaleString()}`;

    render();
  }

  search.addEventListener("input", render);
  category.addEventListener("change", render);

  init().catch((error) => {
    grid.innerHTML = `
      <p>
        Catalog failed to load:
        ${escapeHtml(error.message)}
      </p>`;
  });
})();