panorama.utility package#

Subpackages#

Submodules#

panorama.utility.genInput module#

panorama.utility.genInput.create_hmm_list_file(hmm_path, output, metadata_df=None, hmm_coverage=None, target_coverage=None, binary_hmm=False, recursive=False, force=False, disable_bar=False)#

Creates a TSV file containing information about the given HMM files.

Parameters:
  • hmm_path (List[Path]) – The paths to the HMM files.

  • output (Path) – The path to the output directory.

  • metadata_df (DataFrame) – The metadata dataframe. Defaults to None.

  • hmm_coverage (float) – Set a global value of HMM coverage threshold for all HMM. Defaults to None

  • target_coverage (float) – Set a global value of the target coverage threshold for all targets. Defaults to None

  • binary_hmm (bool) – Rewrite the HMM in binary mode. Defaults False

  • recursive (bool) – Whether to search for HMM files recursively in the given directory. Defaults to False.

  • force (bool) – Flag to erase and overwrite files in the output directory

  • disable_bar (bool) – Whether to disable the progress bar. Defaults to False.

Raises:
  • FileNotFoundError – If any of the given paths are not found.

  • Exception – If an unexpected error occurs.

Returns:

None

Return type:

None

panorama.utility.genInput.generate_unique_accession(existing_accessions)#

Generate a unique PANORAMA accession ID.

Parameters:

existing_accessions (Set[str]) – Set of existing accession IDs to avoid duplicates

Returns:

str – Unique accession ID

Return type:

str

panorama.utility.genInput.parse_hmm_info(hmm, panorama_acc, metadata=None)#

Parse the hmm information and set the new value if needed

Parameters:
  • hmm (HMM) – hmm filled with information

  • panorama_acc (Set[str]) – Set of new accession number already given to not have duplicate

  • metadata (DataFrame) – metadata dataframe to fill information

Returns:

Dictionary with the parsed information

Return type:

Dict[str, Union[str, int]]

panorama.utility.genInput.process_hmm_accession(hmm, panorama_acc, hmm_dict)#

Process or generate HMM accession ID.

Parameters:
  • hmm (HMM) – HMM object

  • panorama_acc (Set[str]) – Set of existing accession IDs

  • hmm_dict (Dict[str, Union[str, int, float]]) – HMM dictionary to update

Returns:

Dict – Updated HMM dictionary

Return type:

Dict[str, Union[str, int, float]]

panorama.utility.genInput.process_hmm_name(hmm, hmm_file, hmm_dict)#

Process HMM name from the HMM object and file path.

Parameters:
  • hmm (HMM) – HMM object

  • hmm_file (Path) – Path to HMM file

  • hmm_dict (Dict[str, Union[str, int, float]]) – HMM dictionary to update

Returns:

Dict – Updated HMM dictionary

Raises:

IOError – If HMM name cannot be determined

Return type:

Dict[str, Union[str, int, float]]

panorama.utility.genInput.read_hmm(hmm_path)#

Read a HMM file to get a HMM object from pyHMMer.

Parameters:

hmm_path (Path) – Path to the HMM file.

Returns:

HMM object

Raises:
  • Exception – if opening the HMM file failed

  • IOError – if there is a problem in HMM reading

Return type:

List[HMM]

panorama.utility.genInput.read_metadata(metadata)#

Read metadata associate with HMM

Parameters:

metadata (Path) – path to the metadata file

Raises:
  • FileNotFoundError – If the metadata path is not found.

  • IOError – If the metadata path is not a file

  • ValueError – If the number of fields is unexpected

  • NameError – If the column names used in metadata are not allowed

Returns:

str – metadata dataframe with hmm information

Return type:

DataFrame

panorama.utility.genInput.write_hmm(hmm, output, binary=False, name=False)#

Write a HMM in text or binary

Parameters:
  • hmm (HMM) – hmm to write

  • output (Path) – Path to the output directory

  • binary (bool) – Flag to write the HMM in binary mode

  • name (bool) – Flag to une the name of the HMM as file name rather than the accession number

Returns:

Path of the HMM file

Return type:

Path

panorama.utility.utility module#

This module provides some utilities function

panorama.utility.utility.check_models(models_list, disable_bar=False)#

Checks all JSON files listed in models_list to ensure that they are valid models.

Parameters:
  • models_list (Path) – paths to the models_list.tsv.

  • disable_bar (bool) – Whether to disable the progress bar. Defaults to False.

Return type:

Models

Returns

Models: A Models object to get all models

Raises:

Exception – If a model is not readable.

panorama.utility.utility.check_parameters(args)#

Checks the provided arguments to ensure that they are valid.

Parameters:

args (Namespace) – The parsed arguments.

Raises:

argparse.ArgumentError – If any required arguments are missing or invalid.

Return type:

None

panorama.utility.utility.create_models_list(models_path, output, recursive=False, disable_bar=False)#

Create a file that listing models and path to them. Also, models are checked

Parameters:
  • models_path (List[Path]) – List of paths to models

  • output (Path) – Directory to write models’ list file

  • recursive (bool) – Flag to read models directory recursively (default: False)

  • disable_bar (bool) – Flag to disable progress bar (default: False)

Return type:

None

panorama.utility.utility.launch(args)#

Launches the utilities function for pangenomes.

Parameters:

args (Namespace) – The parsed arguments.

Returns:

None

panorama.utility.utility.parser_utils(parser)#

Parser for the specific arguments of the utils command.

Parameters:

parser (ArgumentParser) – The parser for the utils command.

Returns:

None

panorama.utility.utility.subparser(sub_parser)#

Subparser to launch PANORAMA in the command line.

Parameters:

sub_parser (_SubParsersAction) – The subparser for the utils command.

Returns:

argparse.ArgumentParser – The parser for the utils command.

Return type:

ArgumentParser