File size: 8,492 Bytes
de4a4d8 20cfc05 de4a4d8 20cfc05 de4a4d8 20cfc05 de4a4d8 20cfc05 de4a4d8 02d42d8 de4a4d8 0280f4f de4a4d8 | 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 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<title>Gene mapping tutorial</title>
<style>
:root {
color-scheme: light dark;
--background: #f6f8fb;
--surface: #ffffff;
--text: #172033;
--muted: #566176;
--border: #dce2eb;
--accent: #2563eb;
--code: #eef2f7;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #111827;
--surface: #1f2937;
--text: #f3f4f6;
--muted: #c2c9d4;
--border: #374151;
--accent: #93b4ff;
--code: #111827;
}
}
* {
box-sizing: border-box;
}
body {
margin: 0;
background: var(--background);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
line-height: 1.65;
}
main {
width: min(960px, calc(100% - 32px));
margin: 0 auto;
padding: 40px 0 72px;
}
h1, h2, h3 {
line-height: 1.25;
}
h1 {
margin-bottom: 8px;
}
h2 {
margin-top: 42px;
}
a {
color: var(--accent);
}
.intro,
.card,
.warning {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 20px;
margin: 18px 0;
}
.warning {
border-left: 5px solid var(--accent);
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin: 22px 0;
}
.button {
display: inline-block;
border: 1px solid var(--accent);
border-radius: 10px;
padding: 10px 15px;
text-decoration: none;
font-weight: 650;
}
code {
background: var(--code);
border-radius: 5px;
padding: 2px 5px;
}
pre {
overflow-x: auto;
background: var(--code);
border: 1px solid var(--border);
border-radius: 12px;
padding: 16px;
}
pre code {
padding: 0;
}
table {
width: 100%;
border-collapse: collapse;
display: block;
overflow-x: auto;
}
th, td {
border: 1px solid var(--border);
padding: 9px 12px;
text-align: left;
vertical-align: top;
}
.flow {
text-align: center;
font-weight: 650;
line-height: 2;
}
.muted {
color: var(--muted);
}
</style>
</head>
<body>
<main>
<p>
<a href="index.html">← Back to the embedding catalog</a>
</p>
<h1>Gene identifier mapping tutorial</h1>
<p class="muted">
Convert the identifiers used by your source embedding into the
unversioned Ensembl gene IDs required by
<code>genes.tsv</code>.
</p>
<div class="button-row">
<a
class="button"
href="https://huggingface.co/datasets/embeddingsSSRF/gene_embeddings/resolve/main/data/master_gene_table.csv?download=true"
>
Download master table CSV
</a>
</div>
<h2>Overview</h2>
<div class="card flow">
Source identifiers + source matrix<br />
↓<br />
Map identifiers to the master table<br />
↓<br />
Classify as unique, unmapped, or ambiguous<br />
↓<br />
Exclude unmapped and ambiguous rows<br />
↓<br />
Average rows mapping to the same final gene<br />
↓<br />
Row-aligned <code>embeddings.npz</code> +
<code>genes.tsv</code>
</div>
<div class="intro">
<strong>Important:</strong> the final
<code>genes.tsv</code> row order must exactly match the row
order of the matrix in <code>embeddings.npz</code>.
</div>
<h2>1. Identify the source identifier type</h2>
<table>
<thead>
<tr>
<th>Source identifier</th>
<th>Master-table column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ensembl gene ID</td>
<td><code>map_ensembl_gene_ids_all</code></td>
</tr>
<tr>
<td>Entrez Gene ID</td>
<td><code>map_entrez_ids_all</code></td>
</tr>
<tr>
<td>UniProt accession</td>
<td><code>map_uniprot_ids_all</code></td>
</tr>
<tr>
<td>RefSeq accession</td>
<td><code>map_refseq_ids_all</code></td>
</tr>
<tr>
<td>CCDS ID</td>
<td><code>map_ccds_ids_all</code></td>
</tr>
<tr>
<td>Ensembl transcript ID</td>
<td><code>map_ensembl_transcript_ids_all</code></td>
</tr>
<tr>
<td>Ensembl protein ID</td>
<td><code>map_ensembl_protein_ids_all</code></td>
</tr>
<tr>
<td>STRING protein ID</td>
<td><code>map_string_protein_ids_all</code></td>
</tr>
</tbody>
</table>
<p>
Multiple identifiers in one master-table cell are separated by
<code>|</code>.
</p>
<h2>2. Gene-symbol mapping requires priority</h2>
<div class="warning">
Do not blindly use <code>map_symbols_all</code>. It combines
current symbols, previous symbols, aliases, and names.
</div>
<ol>
<li>
Try <code>gene_symbol</code> and
<code>hgnc_approved_symbol</code>.
</li>
<li>
Then try <code>hgnc_previous_symbols</code>.
</li>
<li>
Finally try <code>hgnc_alias_symbols</code>.
</li>
</ol>
<p>
Move to a lower-priority source only when the identifier was not
matched at a higher-priority level.
</p>
<h2>3. Accept only unique mappings</h2>
<div class="card">
<p>
<strong>Unique:</strong> exactly one Ensembl gene candidate.
Retain the row.
</p>
<p>
<strong>Unmapped:</strong> no candidate. Exclude.
</p>
<p>
<strong>Ambiguous:</strong> more than one candidate. Exclude.
</p>
</div>
<h2>4. Basic lookup example</h2>
<p>
This example builds an Entrez-to-Ensembl lookup. Replace
<code>map_entrez_ids_all</code> with the appropriate mapping
column for your source.
</p>
<pre><code>from collections import defaultdict
import pandas as pd
master = pd.read_csv(
"master_gene_table.csv",
dtype=str,
)
lookup = defaultdict(set)
for row in master[
["ensembl_gene_id", "map_entrez_ids_all"]
].dropna().itertuples(index=False):
for identifier in row.map_entrez_ids_all.split("|"):
identifier = identifier.strip()
if identifier:
lookup[identifier].add(
row.ensembl_gene_id
)
candidates = lookup.get(source_identifier, set())
if len(candidates) == 1:
status = "unique"
ensembl_gene_id = next(iter(candidates))
elif len(candidates) == 0:
status = "unmapped"
ensembl_gene_id = None
else:
status = "ambiguous"
ensembl_gene_id = None</code></pre>
<h2>5. Collapse duplicate final mappings</h2>
<p>
Different source identifiers may map uniquely to the same final
Ensembl gene. Average those source vectors after mapping so that
the final package contains one row per gene.
</p>
<pre><code>final_vector = source_matrix[source_indices].mean(
axis=0,
)</code></pre>
<h2>6. Preserve row alignment</h2>
<p>
Apply every mapping, filtering, and duplicate-collapsing decision
to the source identifiers and matrix together. Never sort or
filter <code>genes.tsv</code> independently.
</p>
<pre><code>assert final_matrix.shape[0] == len(final_gene_ids)
assert len(final_gene_ids) == len(set(final_gene_ids))
np.savez_compressed(
"embeddings.npz",
embeddings=final_matrix.astype("float32"),
)
pd.DataFrame(
{"ensembl_gene_id": final_gene_ids}
).to_csv(
"genes.tsv",
sep="\t",
index=False,
)</code></pre>
<h2>7. Document the procedure in submission.yaml</h2>
<pre><code>provenance:
species: Homo sapiens
identifier_before_mapping: Entrez Gene ID
mapping_method: Source Entrez IDs were mapped through map_entrez_ids_all in the project master gene table. Only unique mappings were retained, unmapped and ambiguous identifiers were excluded, and duplicate source rows mapping to the same final Ensembl gene were averaged.</code></pre>
</main>
</body>
</html>
|