𧬠PyHIV: A Python Package for Local HIVβ1 Sequence Alignment, Subtyping and Gene Splittingο
π Overviewο
PyHIV is a Python tool that aligns HIV nucleotide sequences against reference genomes to determine the most similar subtype and optionally split the aligned sequences into gene regions.
It produces:
Best reference alignment per sequence
Subtype and reference metadata
Ranked top 3 closest HIV-1 subtypes
Gene-regionβspecific FASTA files (optional)
A final summary table (
final_table.tsv)
βοΈ How It Worksο
βββββββββββββββββββββββββββββββββββββββββββββββ
β User FASTA sequences β
βββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Read and preprocess input
β
βΌ
Align sequences against reference genomes
β
βΌ
Identify best matching reference
β
βΌ
(Optional) Split by gene region
β
βΌ
Save results and summary table (.tsv)
π¦ Installationο
You can install PyHIV using pip:
pip install pyhiv-tools
Alternatively, you can clone the repository and install it manually:
git clone https://github.com/anaapspereira/PyHIV.git
cd PyHIV
pip install -e .
π Getting Startedο
Basic usage:
from pyhiv import PyHIV
PyHIV(
fastas_dir="path/to/fasta/files",
subtyping=True,
splitting=True, # True/"subtype", "hxb2"/"reference", or False/"none"
output_dir="results_folder",
n_jobs=4,
reporting=True,
alignment_tool="edlib-HW",
kmer_size=15,
reference_top_k=30,
reference_groups="M",
show_progress=False,
)
Parameters:ο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
Required |
Directory containing user FASTA files. |
|
|
|
Aligns against subtype reference genomes. If |
|
|
|
Splits aligned sequences into gene regions. Use |
|
|
|
Output directory for results. |
|
|
|
Number of parallel worker processes, created once per run and reused for every sequence. |
|
|
|
Generates a PDF report ( |
|
|
|
Alignment backend: |
|
|
|
K-mer size used to prefilter candidate references. |
|
|
|
Number of top k-mer ranked references to align. Use |
|
|
|
HIV-1 reference groups used for subtyping. Use |
|
|
|
Displays a terminal progress bar for processed input sequences. |
edlib-HW is the default and projects alignments onto full-reference genome coordinates. parasail-NW/parasail, PyFamsa, and MAFFT remain available as alternatives. Before final alignment, PyHIV ranks references using query/reference k-mer containment and aligns only the top candidates by default. Use reference_top_k=0 to keep the original all-reference strategy. By default, subtyping uses group M references from reference_fastas, selected through the group column in sequences_with_locations.tsv; set reference_groups="M,N,O,P" (or "all") to include groups N, O, and P. This M-only default only applies when splitting is enabled or reference_groups is set explicitly; if splitting is disabled and reference_groups is omitted, all reference groups are eligible. edlib is installed with PyHIV. parasail and PyFamsa are optional extras: parasail β install with pip install pyhiv-tools[parasail] β since it has no prebuilt wheel on some platforms (e.g. macOS on Apple Silicon); PyFamsa β install with pip install pyhiv-tools[famsa] β since pyfamsa is GPL-3.0 licensed and is kept out of the default (MIT) install. MAFFT requires an external mafft executable. PyHIV resolves MAFFT from PYHIV_MAFFT_BIN, then mafft on PATH. PyHIV validates that the selected alignment_tool is actually available before processing starts and raises immediately with an install hint if it isnβt, instead of failing per-reference partway through a run.
When subtyping=False, any active splitting mode is treated as HXB2-based splitting, even if splitting="subtype" is provided.
When subtyping=True and splitting=True, PyHIV keeps the selected subtype reference in the Reference column. If that reference has no annotated features in sequences_with_locations.tsv, PyHIV splits against HXB2 instead and records K03455 in Splitting Reference; the PDF report also shows the splitting reference.
Input sequences longer than 12000 nucleotides are skipped with this warning: The submitted sequence is longer than the HIV-1 genome.
fastas_dir is searched recursively, but output_dir is always excluded from that search β so setting output_dir to a subfolder of fastas_dir is safe and wonβt cause a rerun to re-ingest files from a previous run.
The reference dataset root (reference_fastas/, HXB2_fasta/, sequences_with_locations.tsv) is resolved from the REFERENCE_GENOMES_DIR environment variable, falling back to the packaged reference_genomes directory. Set it to point PyHIV at a custom or offline reference dataset, e.g. one prepared with pyhiv update reference-dataset --reference-dir <path>.
π Output Structureο
After running PyHIV, your output directory (default: PyHIV_results/) will contain:
PyHIV_results/
β
βββ best_alignment_<file_stem>_<sequence>.fasta # Alignment to best reference
βββ splitting_alignment_<file_stem>_<sequence>.fasta # HXB2 alignment when splitting uses HXB2 with subtyping
βββ final_table.tsv # Summary of results
βββ PyHIV_report_all_sequences.pdf # Per-sequence PDF report (when reporting=True)
β
βββ gag/
β βββ <file_stem>_<sequence>_gag.fasta
β βββ ...
βββ pol/
β βββ <sequence>_pol.fasta
β βββ ...
βββ env/
βββ <sequence>_env.fasta
βββ ...
Final Table Columns:ο
Column |
Description |
|---|---|
File Name |
Source FASTA file name |
Sequence |
Input sequence name |
Reference |
Best matching reference accession |
Group |
Predicted HIV-1 reference group |
Subtype |
Predicted HIV-1 subtype |
Closest Subtypes |
Top 3 closest group/subtype calls by alignment score |
Subtype Score Warning |
|
Splitting Reference |
Reference accession used for gene splitting |
Most Matching Gene Region |
Region with highest similarity |
Present Gene Regions |
All detected gene regions with valid alignments |
π Command Line Interfaceο
PyHIV provides a user-friendly CLI for HIV-1 sequence analysis.
π Getting Startedο
# Basic usage
pyhiv run sequences/
# With custom options
pyhiv run sequences/ -o results/ -j 4 -v
# Validate inputs first
pyhiv validate sequences/
# Refresh the packaged reference dataset
pyhiv update reference-dataset --yes
βοΈ Main Optionsο
Option |
Description |
|---|---|
|
Enable/disable HIV-1 subtyping (default: |
|
Splitting mode: |
|
Output directory (default: |
|
Number of parallel jobs (default: all CPUs) |
|
Show a terminal progress bar (default: |
|
Generate a PDF report (default: |
|
Detailed output |
|
Suppress non-error output |
See CLI.md for the full option list, including --alignment-tool, --kmer-size, --reference-top-k, --reference-groups, and the pyhiv update reference-dataset command.
πΌ Common Use Casesο
Full analysis with subtyping and splitting:
pyhiv run data/sequences/
Alignment only:
pyhiv run data/sequences/ --subtyping false --splitting false
Subtyping without gene splitting:
pyhiv run data/sequences/ --splitting false
Subtyping with HXB2-based splitting:
pyhiv run data/sequences/ --splitting hxb2
Parallel processing:
pyhiv run data/sequences/ -j 8 -o results/batch1/
Validation:
pyhiv validate data/sequences/
π€ Outputο
PyHIV generates:
final_table.tsv- Summary with sequence IDs, references, group/subtype calls, closest subtypes, and gene regionsbest_alignment_*.fasta- Best alignment for each sequenceGene-specific folders (when
--splittingis enabled) with extracted regionsPyHIV_report_all_sequences.pdf- Per-sequence PDF report (when--reportingis enabled, the default)
π Getting Helpο
pyhiv --help # Show all commands
pyhiv run --help # Show options for run command
pyhiv update reference-dataset --help # Show options for the reference dataset updater
pyhiv --version # Show version
For comprehensive documentation, see CLI.md.
ποΈ Citationο
Manuscript in preparation. Please cite this repository if you use PyHIV in your research.
π§Ύ Licenseο
This project is licensed under the MIT License β see the LICENSE file for details.