fasta_lake.benchmark#
fasta_lake.benchmark
#
Benchmark FastaLake results against a baseline search.
For proteomics: compare against canonical SwissProt search. For metaproteomics: compare against matched metagenome or iterative search.
Computes 6 metrics: 1. Identification gain (peptides, proteins, genes) 2. FDR control (entrapment hits) 3. Canonical coverage (overlap with baseline) 4. Biological plausibility (species distribution, variant frequencies) 5. Reproducibility (cross-sample CV) 6. Quantitative agreement (intensity correlation)
SearchResult
dataclass
#
Parsed search engine result (DIA-NN or SAGE report.tsv).
Gene counts use ONLY real gene symbols (HGNC/MGI), not UniProt accession fallbacks. This prevents inflated counts when the FASTA contains many TrEMBL entries without proper gene names.
The genes_all field contains everything (including accession fallbacks)
for debugging. The genes field is filtered to real symbols only.
Source code in fasta_lake/benchmark.py
BenchmarkResult
dataclass
#
Complete benchmark comparison between FastaLake and baseline.
Source code in fasta_lake/benchmark.py
is_real_gene_symbol
#
Check if a gene name is a real HGNC/MGI symbol, not an accession fallback.
When FASTA headers lack a proper gene name (GN= tag), the heal function falls back to using the UniProt accession (e.g., A0A024CIM4) or entry name as the gene. These look like gene names but aren't — they inflate gene counts if not filtered.
Real gene symbols: ALB, APOA1, HP, TP53, BRCA1, MGYG000000001_00001 Accession fallbacks: A0A024CIM4, B2R6Q2, Q8IZF2, F6KPG5
The UniProt accession pattern is [A-Z][0-9][A-Z0-9]{3,} (e.g., P02768,
A0A024CIM4, Q6UXV3). This regex catches accessions but not gene symbols
like ALB, TP53, or C3 (which are short and don't match the pattern).
Source code in fasta_lake/benchmark.py
load_diann_report
#
load_diann_report(report_path: str | Path, qvalue: float = 0.01) -> SearchResult
Load a DIA-NN report.tsv and extract peptides, genes, protein groups.
Gene names are filtered to real HGNC/MGI symbols only. Accession fallbacks (A0A024CIM4, B2R6Q2, etc.) are excluded from gene counts but kept in genes_all for debugging.
Source code in fasta_lake/benchmark.py
build_gene_map
#
Build accession → gene name map from a FASTA file.
Extracts gene names from GN= tags in FASTA headers. Only returns real gene symbols (filtered by is_real_gene_symbol), not accession fallbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_path
|
path
|
FASTA file (healed or canonical). |
required |
Returns:
| Type | Description |
|---|---|
dict mapping protein accession → gene symbol
|
|
Source code in fasta_lake/benchmark.py
load_sage_report
#
load_sage_report(report_path: str | Path, fasta_path: str | Path | None = None, qvalue: float = 0.01) -> SearchResult
Load a SAGE results.sage.tsv and extract peptides, genes, protein groups.
SAGE doesn't report gene names directly — it reports protein accessions. To get gene-level counts, provide the FASTA that was searched so we can map accession → gene using the GN= tag.
Without a FASTA, only peptide and protein counts are available (no genes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report_path
|
path
|
SAGE results.sage.tsv file. |
required |
fasta_path
|
path
|
The FASTA file that was searched. Used to map proteins → genes. |
None
|
qvalue
|
float
|
FDR threshold (default 0.01). |
0.01
|
Source code in fasta_lake/benchmark.py
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 | |
compare
#
compare(fastalake_result: SearchResult, baseline_result: SearchResult, label: str = 'FastaLake vs Baseline') -> BenchmarkResult
Compare FastaLake search results against a baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fastalake_result
|
SearchResult
|
Results from searching the FastaLake-built FASTA. |
required |
baseline_result
|
SearchResult
|
Results from searching the baseline FASTA (canonical or matched metagenome). |
required |
label
|
str
|
Description for logging. |
'FastaLake vs Baseline'
|
Returns:
| Type | Description |
|---|---|
BenchmarkResult
|
Complete comparison metrics. |
Source code in fasta_lake/benchmark.py
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 392 393 394 395 396 397 | |
print_benchmark
#
print_benchmark(bench: BenchmarkResult, label: str = '') -> None
Pretty-print benchmark results.