just_dna_enricher.frequencies¶
just_dna_enricher.frequencies ¶
enrich-frequencies — the second pass: coordinates in, frequencies.csv out.
Structured like enrich(), and deliberately a separate pass rather than more work inside it. The
resolution pass answers "where is this variant"; this one answers "how common is it" — different
question, different output file, different failure mode, and a module may want one without the other.
It consumes resolution.csv rather than variants.csv, because a frequency is per allele at a
coordinate: the resolution table is where an rsID has already become chrom-pos-ref-alt, which is
exactly the key gnomAD wants. That also sidesteps the multi-allelic-rsID problem entirely — a problem
the resolver link has to solve, and this pass never meets.
This is the first online-only link in the whole chain. There is no offline snapshot to fall back
on and there will not be one: the v4.1 sites VCFs are 58 GB (exomes) and 742 GB (genomes), so a
frequency slice is not a thing that ships. --offline therefore makes this pass a no-op with a
warning rather than a failure. That is not a hole in reproducibility: once frequencies.csv is
written it is the pin, and every later compile reads it offline and deterministically.
FrequencyEnrichmentError ¶
Bases: RuntimeError
Raised in strict mode when a resolved variant gets no frequency.
FrequencyUnavailable ¶
Bases: FrequencyEnrichmentError
gnomAD could not be reached, so no frequency question was put at all (RM101).
A subclass rather than a second exception, so every existing except FrequencyEnrichmentError still
catches it (P3 — additive within a major). It exists because this pass could fail two ways that
want different responses and had one type for both: gnomAD was asked and never answered, and a resolved variant genuinely has no frequency under strict.
Only this one means the source was asked and never answered.
Before RM101 this case did not reach FrequencyEnrichmentError at all — a GnomadError travelled straight
out through a try/finally with no except, so a caller's handler, written against the type
this module documents, was silent for exactly the failure it was written for.
format_faf95 ¶
Render faf95 to a canonical cell — the one stored float in the table.
Every other number here is an integer count precisely so CSV round-trips are exact; faf95 has no
integer form. str() is the right tool and a fixed %.12g would be a mistake: since Python 3.1,
str(float) produces the shortest string that reloads to the identical double, which is both
exactly lossless and deterministic across platforms for IEEE-754. A fixed-precision format would
be deterministic but would silently truncate, and it would disagree with the compiler's reverse
writer (_scalar_cell), leaving the same number spelled two ways depending on who last wrote the
file.
Source code in enricher/src/just_dna_enricher/frequencies.py
enrich_frequencies ¶
enrich_frequencies(
spec_dir: Path,
*,
mode: str = "best_effort",
offline: bool = False,
populations: list[str] | None = None,
dataset: str = FREQUENCY_DATASET_LABEL,
write: bool = True,
client: GnomadClient | None = None,
) -> FrequencyResult
Fill frequencies.csv from the coordinates already in resolution.csv.
populations restricts the emitted ancestry groups (e.g. ["global"] keeps the table to one row
per allele — the human-legibility escape hatch for a module that wants the number, not the
breakdown). None keeps every group the source reports.
Existing rows are authoritative and are merged, never clobbered — the same rule enrich() applies
to resolution.csv, and it is what makes a hand-corrected number survive a re-run. Note the same
consequence, too: to regenerate after a machinery change you must delete the file first.
Source code in enricher/src/just_dna_enricher/frequencies.py
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 | |