pyhiv package

Subpackages

Submodules

pyhiv.cli module

PyHIV Command Line Interface

pyhiv.cli.count_fasta_files(directory, exclude_dirs=())[source]

Count FASTA files in the input directory and its subdirectories.

pyhiv.cli.update()

Update packaged PyHIV datasets.

pyhiv.cli.validate_n_jobs(ctx, param, value)[source]

Validate that n_jobs is positive if provided.

pyhiv.cli.validate_positive(ctx, param, value)[source]

Validate that an integer option is positive if provided.

pyhiv.cli.validate_reference_groups(ctx, param, value)[source]

Validate comma-separated HIV-1 reference groups.

pyhiv.cli.validate_reference_top_k(ctx, param, value)[source]

Validate candidate reference limit. Zero disables k-mer shortlisting.

pyhiv.cli.validate_splitting(ctx, param, value)[source]

Validate splitting mode while preserving true/false compatibility.

pyhiv.config module

pyhiv.config.get_reference_base_dir()[source]

Return the root directory for reference genomes.

Return type:

Path

pyhiv.config.get_reference_paths(base_dir=None)[source]

Return all key reference paths derived from the base directory.

Parameters:

base_dir (Path | None)

Return type:

dict[str, Path]

pyhiv.config.validate_reference_paths(paths=None)[source]

Ensure all required reference files and directories exist.

Parameters:

paths (dict[str, Path] | None)

Module contents

pyhiv.PyHIV(fastas_dir, subtyping=True, splitting=True, output_dir=None, n_jobs=None, reporting=True, alignment_tool='edlib-HW', kmer_size=15, reference_top_k=30, reference_groups=None, show_progress=False)[source]

Main function to run the PyHIV pipeline. It aligns the user sequences with the reference sequences and saves the best alignment in a fasta file. If subtyping is True, it aligns the user sequences with the reference sequences from the HIV-1 subtyping tool. If splitting is enabled, it splits the user sequences into gene regions and saves them in specific folders. splitting accepts booleans for backwards compatibility, or “subtype”, “hxb2”/”reference”, and “none”. If reporting is True, it generates a PDF report with visualizations. alignment_tool selects the alignment backend. Defaults to edlib-HW. kmer_size and reference_top_k control the k-mer candidate reference prefilter used before alignment. reference_groups controls which HIV-1 reference groups are eligible for subtyping. When splitting is enabled, omitted groups default to group M. When splitting is disabled, omitted groups allow all FASTA references. Use (“M”, “N”, “O”, “P”) to include all known groups. show_progress displays a terminal progress bar for processed input sequences.

Parameters:
  • fastas_dir (str)

  • subtyping (bool)

  • splitting (bool)

  • output_dir (str | None)

  • n_jobs (int | None)

  • reporting (bool)

  • alignment_tool (str)

  • kmer_size (int)

  • reference_top_k (int)

  • show_progress (bool)

pyhiv.build_reference_metadata(reference_sequences)[source]
Parameters:

reference_sequences (pandas.DataFrame)

Return type:

dict[str, dict[str, str]]

pyhiv.final_table_columns_for_splitting(should_split)[source]
Parameters:

should_split (bool)

Return type:

list[str]

pyhiv.has_reference_features(reference_sequences, accession)[source]
Parameters:
  • reference_sequences (pandas.DataFrame)

  • accession (str)

Return type:

bool

pyhiv.normalize_reference_groups(reference_groups)[source]
Return type:

tuple[str, …]

pyhiv.normalize_splitting_mode(splitting, subtyping=True)[source]
Parameters:

subtyping (bool)

Return type:

str

pyhiv.process_fasta_sequence(fasta, rows, paths, subtyping, splitting_mode, should_split, output_dir, n_jobs, alignment_tool, kmer_size, reference_top_k, allowed_reference_accessions, reference_sequences, metadata_by_accession, executor=None)[source]
Parameters:
  • rows (list[list])

  • paths (dict)

  • subtyping (bool)

  • splitting_mode (str)

  • should_split (bool)

  • output_dir (Path)

  • n_jobs (int | None)

  • alignment_tool (str)

  • kmer_size (int)

  • reference_top_k (int)

  • reference_sequences (pandas.DataFrame)

  • metadata_by_accession (dict)

  • executor (Executor | None)

Return type:

None

pyhiv.ranked_closest_subtype_scores(alignment_scores, metadata_by_accession, top_n=3)[source]
Parameters:
  • alignment_scores (list[tuple[int, str]])

  • metadata_by_accession (dict[str, dict[str, str]])

  • top_n (int | None)

Return type:

list[tuple[str, str, int]]

pyhiv.reference_features(reference_sequences, accession)[source]
Parameters:
  • reference_sequences (pandas.DataFrame)

  • accession (str)

Return type:

dict

pyhiv.reference_has_features(features)[source]
Return type:

bool

pyhiv.selected_reference_accessions(reference_sequences, reference_groups, require_features=False)[source]
Parameters:
  • reference_sequences (pandas.DataFrame)

  • reference_groups (tuple[str, ...])

  • require_features (bool)

Return type:

set[str] | None

pyhiv.subtype_score_warning(alignment_scores, metadata_by_accession, threshold=0.01)[source]
Parameters:
  • alignment_scores (list[tuple[int, str]])

  • metadata_by_accession (dict[str, dict[str, str]])

  • threshold (float)

Return type:

str

pyhiv.summarize_closest_subtypes(alignment_scores, metadata_by_accession, top_n=3)[source]
Parameters:
  • alignment_scores (list[tuple[int, str]])

  • metadata_by_accession (dict[str, dict[str, str]])

  • top_n (int)

Return type:

str

pyhiv.write_alignment_file(path, reference_name, ref_aligned, sequence_name, test_aligned)[source]
Parameters:
  • path (Path)

  • reference_name (str)

  • ref_aligned (str)

  • sequence_name (str)

  • test_aligned (str)

Return type:

None