gtdblib.util.shell package

Submodules

gtdblib.util.shell.color module

Utility functions for modifying color formats.

gtdblib.util.shell.color.hex_to_rgb(hex: str) tuple

Convert hex to RGB color format.

Parameters:

hex – Hex color format.

Returns:

RGB color format.

gtdblib.util.shell.color.rgb_to_hex(r: int, g: int, b: int) str

Convert RGB to hex color format.

Parameters:
  • r – Red value.

  • g – Green value.

  • b – Blue value.

Returns:

Hex color format.

gtdblib.util.shell.execute module

gtdblib.util.shell.execute.check_dependencies(programs: List[str], exit_on_fail: bool = True)

Check if programs are on the system path.

Parameters:
  • programs – Names of executable programs.

  • exit_on_fail – Exit program with error code -1 if any program in not on path.

Returns:

True if all programs are on path, else False.

gtdblib.util.shell.execute.check_on_path(program: str, exit_on_fail: bool = True)

Check if program is on the system path.

Parameters:
  • programs – Names of executable programs.

  • exit_on_fail – Exit program with error code -1 if any program in not on path.

Returns:

True if all program is on path, else False.

gtdblib.util.shell.execute.is_executable(fpath: str)

Check if file is executable.

Parameters:

fpath – Path to file.

Returns:

True if executable, else False.

gtdblib.util.shell.execute.run(cmd: List[str]) str

Execute external program.

Params cmd:

Command to execute.

Returns:

Output from stdout.

gtdblib.util.shell.execute.run_bash(command: str)

Execute command via bash.

gtdblib.util.shell.execute.which(program: str)

Return path to program.

This is a Python implementation of the linux command ‘which’.

http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python

Parameters:

programs – Names of executable programs.

Returns:

Path to executable, or None if it isn’t on the path.

gtdblib.util.shell.filemgmt module

gtdblib.util.shell.filemgmt.matching_brackets(line)

Split a string to a list with matching brackets. a string a split into substrings based on matching brackets. so we can return nested brackets.

Parameters:

line – str, line to be processed.

Returns:

list, list of strings.

gtdblib.util.shell.filemgmt.select_delimiter(input_file)

Select delimiter for a specific file (.csv,.tsv,…).

Parameters:

input_file – str, Name of file.

Returns:

str, Delimiter.

gtdblib.util.shell.filemgmt.sha256(input_file)

Calculate the SHA256 hash for a specific file.

Parameters:

input_file – str, Name of file.

Returns:

str, SHA256 hash.

gtdblib.util.shell.filemgmt.sha256_rb(input_file)

Calculate SHA256 hash for a specific file with a binary format.

Parameters:

input_file – str, Name of file.

Returns:

str, SHA256 hash.

gtdblib.util.shell.gtdbshutil module

Utility functions for copying and archiving files and directory trees.

gtdblib.util.shell.gtdbshutil.check_dir_exists(input_dir)

Check if directory exists.This function is copied from biolib on the 09/10/2020.

Parameters:

input_dir – path to directory

Returns:

True if path exists

gtdblib.util.shell.gtdbshutil.check_file_exists(input_file)

Check if file exists.This function is copied from biolib on the 09/10/2020.

Parameters:

input_file – path to file

Returns:

True if path exists

gtdblib.util.shell.gtdbshutil.get_num_lines(file_path)

Calculate the number of lines in a file.

Parameters:

file_path – path to file

Returns:

number of lines in file

gtdblib.util.shell.gtdbshutil.make_sure_path_exists(path)

Create directory if it does not exist. This function is copied from biolib on the 09/10/2020.

Parameters:

path – path to directory

Returns:

True if directory exists or was created

Create a symbolic link named link_name pointing to target.

If link_name exists then FileExistsError is raised, unless overwrite=True. When trying to overwrite a directory, IsADirectoryError is raised.

Parameters:
  • target – The target of the link.

  • link_name – The name of the link.

  • overwrite – If True, overwrite existing files and directories.

Raises:

FileExistsError – If link_name exists and overwrite=False.

Returns:

True

Module contents