fasta_lake.refine#
fasta_lake.refine
#
ICS-guided variant proposal for FastaLake. Research module, proposal-only.
STATUS: this module proposes sequence variants; it does not validate them.
It is not part of the published FastaLake method, is not reachable from the
fasta-lake command line, and its output must not be used as a per-sample
search database. A proposed variant is a hypothesis about where a database
sequence may be wrong; confirming it requires a re-search and an ICS
comparison that this module does not perform.
What it does: after a SAGE search, identify_refinement_candidates selects
FDR-passing PSMs with low ion coverage (ICS), and generate_variant_fasta
writes, for each candidate protein, the single amino-acid substitution with
the best BLOSUM95 (or de novo confusion) score at the peptide position. The
original sequence is replaced in the output and the accession is suffixed
__VAR so the file cannot be mistaken for the input.
What it does not do: compute ICS for the variant, compare it with the
original, or accept only improving variants. run_refinement therefore
raises NotImplementedError until that validation exists.
Reference: Miura et al. (2025) for the ICS definition.
identify_refinement_candidates
#
identify_refinement_candidates(sage_results_path: str | Path, ics_threshold: float = 0.4, fdr_threshold: float = 0.01, max_candidates: int = 500) -> list[dict]
Find low-ICS PSMs that are candidates for variant refinement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sage_results_path
|
path
|
SAGE results.sage.tsv |
required |
ics_threshold
|
float
|
PSMs below this ICS are candidates. Default 0.4. |
0.4
|
fdr_threshold
|
float
|
Only consider PSMs passing FDR. Default 0.01. |
0.01
|
max_candidates
|
int
|
Limit candidates to avoid combinatorial explosion. Default 500. |
500
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Each with: peptide, protein_id, position, ics, hyperscore |
Source code in fasta_lake/refine.py
generate_variant_fasta
#
generate_variant_fasta(fasta_path: str | Path, candidates: list[dict], matrix: str = 'blosum95', min_score: int = -1, max_variants_per_position: int = 3, output_path: str | Path | None = None) -> dict[str, str]
Write a proposal FASTA: one best-scoring substitution per candidate protein.
For each candidate peptide: 1. Locate it in the parent protein sequence (exact, then I/L-folded) 2. Generate BLOSUM/denovo-guided single-AA variants at each peptide position 3. Keep the single variant with the highest substitution score
Every candidate protein that maps is modified, unconditionally. No ICS
or spectral evidence is consulted for the variant; the substitution score
is the only criterion. The output has the same number of records as the
input, modified records carry the accession suffix __VAR, and it is
a proposal for a validating re-search, not a search database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_path
|
path
|
Per-sample FASTA to refine. |
required |
candidates
|
list of dict
|
From |
required |
matrix
|
str
|
|
'blosum95'
|
output_path
|
path
|
Write variant FASTA. If None, returns dict only. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Statistics: n_variants, n_proteins_modified, etc. |
Source code in fasta_lake/refine.py
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 | |
run_refinement
#
run_refinement(sage_results: str | Path, sample_fasta: str | Path, output_fasta: str | Path, ics_threshold: float = 0.4, fdr_threshold: float = 0.01, matrix: str = 'blosum95', max_candidates: int = 500) -> dict
Not implemented: a validated refinement pass does not exist yet.
The validated pass would (1) propose variants with
generate_variant_fasta, (2) re-search the proposal FASTA, (3) compute
ICS per variant PSM, and (4) accept only variants whose ICS improves on the
original. Steps 2 to 4 are not implemented. Calling this function raises
NotImplementedError so that an unvalidated proposal FASTA is never
produced under the name "refinement". Use
identify_refinement_candidates and generate_variant_fasta directly
to obtain proposals.