hybkit.util

This module contains helper functions for hybkit's command line scripts.

hybkit.util.get_argparse_doc(docstring: str) str

Get the argparse description from a docstring.

Parameters

docstring (str) -- A docstring.

Returns

A string containing the argparse description.

hybkit.util.dir_exists(dir_name: str) str

Check if a directory exists at the provided path (else raise), and return a normalized path.

Parameters

dir_name (str) -- Name of directory to check for existence.

Returns

A normalized version of the path passed to dir_name.

hybkit.util.file_exists(file_name: str, required_suffixes: Optional[List[str]] = None) str

Check if a file exists at the provided path, and return a normalized path.

Parameters
  • file_name (str) -- Name of file to check for existence.

  • required_suffixes (list, optional) -- List of strings containing file-name suffixes. If provided, a file passed to file-exists must end with one of the strings provided. Otherwise an error will be raised.

Returns

A normalized version of the path passed to file_name.

hybkit.util.hyb_exists(file_name: str) str

Check if a .hyb file exists at the provided path, and return a normalized path.

Wrapper for file_exists() that includes the required suffixes in hybkit.settings.HYB_SUFFIXES.

Parameters

file_name (str) -- Name of file to check for existence.

Returns

A normalized version of the path passed to file_name.

hybkit.util.vienna_exists(file_name: str) str

Check if a .vienna file exists at the provided path, and return a normalized path.

Wrapper for file_exists() that includes the required suffixes in hybkit.settings.VIENNA_SUFFIXES.

Parameters

file_name (str) -- Name of file to check for existence.

Returns

A normalized version of the path passed to file_name.

hybkit.util.ct_exists(file_name: str) str

Check if a .ct file exists at the provided path, and return a normalized path.

Wrapper for file_exists() that includes the required suffixes in hybkit.settings.CT_SUFFIXES.

Parameters

file_name (str) -- Name of file to check for existence.

Returns

A normalized version of the path passed to file_name.

hybkit.util.fold_exists(file_name: str) str

Check if a fold-representing file exists at the provided path, and return a normalized path.

Wrapper for file_exists() that includes the required suffixes in hybkit.settings.FOLD_SUFFIXES.

Parameters

file_name (str) -- Name of file to check for existence.

Returns

A normalized version of the path passed to file_name.

hybkit.util.out_path_exists(file_name: str) str

Check if the directory of the specified output path exists, and return a normalized path.

Parameters

file_name (str) -- Name of path to an output file to check.

Returns

A normalized version of the path passed to file_name.

hybkit.util.make_out_file_name(in_file_name: str, name_suffix: str = 'out', in_suffix: str = '', out_suffix: str = '', out_dir: str = '', seg_sep: str = '_') str

Given an input file name, generate an output file name.

Parameters
  • in_file_name (str) -- Name of input file as template.

  • name_suffix (str) -- Suffix to add to name before file type.

  • in_suffix (str) -- File type suffix on in_file_name (to remove).

  • out_suffix (str) -- File type suffix to add to final output file.

  • out_dir (str) -- Directory path in which to place output file.

  • seg_sep (str) -- Separator string between file name segments.

Returns

An output file path based on the input file template.

hybkit.util.validate_args(args: Namespace, parser: Optional[ArgumentParser] = None) bool

Check supplied arguments to make sure there are no hidden contradictions.

Current checks:
  • If explicit output file names supplied, be sure that they match the number of input files provided.

  • If fold files provided, make sure that they match the number of input hyb files provided.

Parameters
hybkit.util.validate_args_exit(args: Namespace, parser: Optional[ArgumentParser] = None) None

Check supplied arguments using validate_args(), and exit if a conflict exists.

Parameters
hybkit.util.set_setting(setting: str, set_value: Any, verbose: bool = False) str

Take a namespace object as from an argparse parser and update settings.

Each setting in the following settings dictionaries are checked and set where applicable:

Parameters
  • setting (str) -- Name of setting to change

  • set_value (str) -- New value for setting

  • verbose (bool, optional) -- If True, print when changing setting.

hybkit.util.set_settings_from_namespace(nspace: Namespace, verbose: bool = False) None

Take a namespace object as from an argparse parser and update settings.

See set_setting() for details

Parameters
  • nspace (argparse.Namespace) -- Namespace containing settings

  • verbose (bool, optional) -- If True, print when changing setting.