fasta_lake.tune#
fasta_lake.tune
#
FastaLake tune — parameter tuning from existing SAGE results.
Takes a directory of SAGE entrapment searches, applies a grid of filters post-hoc, and recommends parameters that achieve a user-specified target FDP.
No re-search required — operates on existing results.sage.tsv files.
CLI: fasta-lake tune --results-dir PATH --target-fdp 0.02
Output: tuning_report.csv — per-filter FDP, target count, pareto verdict recommended.json — the winning filter as a SAGE config diff
FilterSpec
dataclass
#
default_filter_grid
#
default_filter_grid() -> list[FilterSpec]
Standard grid. len × q × score cartesian product.
Source code in fasta_lake/tune.py
apply_filter
#
apply_filter(rows: list[dict], spec: FilterSpec, entrap_prefix: str) -> dict
Count target / decoy / entrapment PSMs under a filter.
Source code in fasta_lake/tune.py
parse_tsv
#
Parse required Sage fields for the historical spectrum-q tuning diagnostic.
Return q, length, discriminant score, protein text and the legacy decoy flag for each row. Missing columns and invalid numeric fields raise errors.
Source code in fasta_lake/tune.py
compute_fdp_combined
#
Noble 2025 combined-method FDP as percentage; None when undefined.
A sample with no accepted PSMs has no FDP, not an FDP of zero; returning 0.0 pulled the median that picks the winning filter towards zero.
Source code in fasta_lake/tune.py
find_sample_results
#
Yield (sample_id, entrap_type, results.sage.tsv path) for each sample.
Source code in fasta_lake/tune.py
tune
#
tune(results_dir: Path, target_fdp_pct: float = 2.0, entrap_db_sizes: dict[str, int] | None = None, target_db_size_fn=None, grid: list[FilterSpec] | None = None) -> dict
Tune parameters by post-hoc filter sweep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results_dir
|
Path
|
Directory with per-sample subdirs (each containing entrapment/, entrapment_plant/, entrapment_archaea/ with results.sage.tsv). |
required |
target_fdp_pct
|
float
|
Maximum acceptable median shuffled FDP (percent). Winner is the filter with highest target PSM count that satisfies this threshold. |
2.0
|
entrap_db_sizes
|
dict[str, int] | None
|
Map entrap_type -> protein count. Defaults to FastaLake standard sizes. |
None
|
target_db_size_fn
|
Callable (sample_id) -> int returning the target FASTA protein count. If None, assumes 75000 (typical MP metaproteomics). |
None
|
|
grid
|
list[FilterSpec] | None
|
List of FilterSpec to evaluate. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
dict with keys: all_results (per-filter per-entrap summary), winner (best filter).
|
|
Source code in fasta_lake/tune.py
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 | |
write_reports
#
Write tuning CSV, recommended settings and supporting reports.
Create the directory as needed and overwrite report files. An empty result list produces no new tuning_report.csv.