codon-yat — A codon-aware amino acid variant typer from SAM alignments of viral NGS data.
Project description
codonyat
codon-yat — A codon-aware amino acid variant typer from SAM alignments of viral NGS data.
A standalone Python package that performs amino acid variant calling, including:
-
SAM parsing that honors amplicon labels and strand orientation.
-
Ratio balancing, entropy tracking, and TSV/XML exporters mirroring the legacy Perl outputs.
-
Configurable CLI flags for strand ratio bounds and entropy sensitivity.
-
Works directly on viral genomic datasets generated by high-throughput NGS pipelines and relies on protein-level annotations so you can derive amino-acid variants without reimplementing parsing logic.
Highlights
- Produces consistent TSV/XML diagnostics while adding Python objects (
SamContainer,FullReference, etc.) that downstream tooling can import. - Validates every input file before parsing to surface malformed SAM/FASTA/amplicon data early.
- Logs per-position entropy and strand balance for easier debugging in CI or local runs.
Installation
pip install .
Or publish the package (e.g., via twine/PyPI) and install it like any other dependency.
CLI usage
Once installed, the codonyat entry point is available:
codonyat /path/to/sample.sam /path/to/reference.fasta /path/to/amplicons.tsv
Supply --ratio-upper, --ratio-lower, and --entropy-threshold to tune the balancing heuristics.
The CLI writes [sam-file].tsv (columns: FILE, REFERENCE, PROTEIN, VARIANT, POSITION, FREQ, FWCOV, RVCOV, TOTALCOV, RATIO) and [sam-file].xml (per-position <Depth>, <FwCover>, <RvCover>, <Variants>).
Package API
Import aa_caller to reuse the core objects:
from aa_caller import SamContainer, FullReference, parse_amplicons
The SamContainer constructor still accepts ratio_upper, ratio_lower, and entropy_threshold so you can reuse the balancing logic in scripts.
Python wrapper
Use call_variants to run the full pipeline from Python without touching the CLI. It validates the inputs, builds the SamContainer, and writes the TSV/XML artifacts while returning a VariantCallResult you can inspect.
from pathlib import Path
from aa_caller import call_variants
result = call_variants(
sam_path=Path("reads.sam"),
reference_path=Path("reference.fasta"),
amplicons_path=Path("amps.tsv"),
ratio_upper=3.2,
)
print(result.csv_path, result.xml_path)
print(result.container.variants.keys())
If you already have an argparse.Namespace or mapping of the CLI arguments, call_variants_from_args adapts them directly.
from argparse import Namespace
args = Namespace(
sam_file="reads.sam",
reference_file="reference.fasta",
amplicons_file="amps.tsv",
ratio_upper=3.2,
)
call_variants_from_args(args)
CLI wrapper
This repository installs a lightweight runner at codonyat-runner that exposes the same entry arguments as call_variants_from_args. Use it when you prefer a small CLI shim over the full codonyat entry point:
codonyat-runner reads.sam reference.fasta amps.tsv --ratio-upper 3.1 --csv-path results.tsv
Development
Install the repository with the optional dev tooling so your local environment matches CI:
pip install --upgrade pip
pip install -e .[dev]
Now you can run the same checks that land in .github/workflows/python-tests.yml:
ruff check .
python -m pytest
The workflow installs pytest and ruff, runs the linter, and then executes the pytest suite on every push/PR against main.
Testing
Run the upstream validation helpers with pytest:
python -m pytest
Keep the code tidy with ruff before committing:
ruff check .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codonyat-0.1.0.tar.gz.
File metadata
- Download URL: codonyat-0.1.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58de2b66899d6276148a084cff8b8350856b9cd32876c9ef04382c364d7a5fb3
|
|
| MD5 |
54c75cded9f526f68d08cb57713be7f2
|
|
| BLAKE2b-256 |
b1aad7d7e140a0d3dd48f1d85decc0b67efca35b39c6364f39150a6269a81048
|
File details
Details for the file codonyat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codonyat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe564d31826d458524577c660e4eebec03c231ea05e4e17558358e90899641c8
|
|
| MD5 |
e1e7dc886ef795e6f12c2d3c769cc039
|
|
| BLAKE2b-256 |
564d2b548ef9310924bd1813df6aa1c6b903e614ab7327623e8808c371ad593b
|