fasta_lake.helpers#
fasta_lake.helpers
#
Shared helper functions for FASTA Lake.
These helpers originated in the tested standalone inference scripts and now include explicit input checks. They form the foundation for all inference strategies.
Notes
The Aho-Corasick automaton performs multi-pattern peptide matching. This experimental Python interface has different parsing and inference rules from the supported Rust workflow; sharing the matching algorithm does not establish end-to-end equivalence. See docs/concepts/algorithms.md, section 4.4.
normalize_il
#
Normalize isoleucine (I) to leucine (L) for mass spec equivalence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
str
|
Protein or peptide sequence. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Sequence with all I replaced by L. |
Source code in fasta_lake/helpers.py
clean_sequence
#
Clean a protein sequence by uppercasing and removing stop codons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq
|
str
|
Raw protein sequence. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Cleaned sequence (uppercase, no |
Source code in fasta_lake/helpers.py
get_db_type
#
Classify a protein by its database source based on ID prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protein_id
|
str
|
Protein identifier (first token of FASTA header). |
required |
Returns:
| Type | Description |
|---|---|
str
|
One of |
Source code in fasta_lake/helpers.py
get_species_id
#
Extract a species/genome identifier from a protein ID, or None.
Only identifiers that carry a species are resolved. Everything else is
None so that callers can see, count and refuse unresolved proteins
instead of pooling them into one pseudo-species (which turned
species_budget into razor on every content-hash lake).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protein_id
|
str
|
Protein identifier, either a raw catalogue accession or a FastaLake
lake header |
required |
Returns:
| Type | Description |
|---|---|
str or None
|
|
Source code in fasta_lake/helpers.py
count_fasta_headers
#
Number of '>' records in a FASTA file, read with the file closed afterwards.
load_fasta_proteins
#
Load proteins from a FASTA file into a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_file
|
str or Path
|
Path to FASTA file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of protein ID (first header token) → sequence. |
Source code in fasta_lake/helpers.py
require_columns
#
require_columns(fieldnames, required: tuple[str, ...] | list[str], path, *, any_of: tuple[str, ...] | list[str] = ()) -> None
Raise ValueError when a table lacks the columns a reader depends on.
Readers used to fill a missing column with a default (1 for a q value,
0 for an intensity, "" for a sequence), so a renamed column produced
an empty result and exit 0. Naming the missing and the present columns is
the only honest answer.
Source code in fasta_lake/helpers.py
collect_peptides_with_scores
#
collect_peptides_with_scores(alphanovo_csv: str | Path, min_length: int = 9, max_length: int = 50) -> dict[str, float]
Collect peptides with their best AlphaNovo scores from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alphanovo_csv
|
str or Path
|
Path to a predictions CSV: AlphaNovo columns
|
required |
min_length
|
int
|
Minimum peptide length (inclusive). |
9
|
max_length
|
int
|
Maximum peptide length (inclusive). |
50
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping of I/L-normalized peptide sequence → best score. |
Source code in fasta_lake/helpers.py
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 | |
map_peptides_to_proteins
#
map_peptides_to_proteins(proteins: dict[str, str], peptides: set[str] | dict[str, float]) -> tuple[dict[str, set[str]], dict[str, set[str]]]
Map peptides to proteins using Aho-Corasick multi-pattern matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proteins
|
dict[str, str]
|
Mapping of protein ID → sequence. |
required |
peptides
|
set[str] or dict[str, float]
|
Peptide sequences to search for (I/L-normalized). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
pep2prot |
dict[str, set[str]]
|
Mapping of peptide → set of protein IDs containing it. |
prot2pep |
dict[str, set[str]]
|
Mapping of protein ID → set of peptides found in it. |