diurnal.utils package

Submodules

diurnal.utils.file_io module

File manipulation module.

diurnal.utils.file_io.clean_dir_path(directory: str) str[source]

Return the correct filepath to directory.

Parameters

directory (str) – Directory name to validate.

Raises

RuntimeError – If the directory does not exist.

Returns (str): Cleaned directory path.

diurnal.utils.file_io.decompress(filename: str, mode: str, dst: str, verbosity: int, name: str = '') None[source]

Decompress a TAR file.

Parameters
  • filename (str) – Name of the file to decompress.

  • mode (str) – Decompression mode (e.g. r:gz).

  • dst (str) – Output directory.

  • verbosity (int) – Verbosity level. 0 silences the function.

  • name (str) – Decompressed file name - used for logging.

diurnal.utils.file_io.download(url: str, dst: str, verbosity: int, name: str = '') None[source]

Download a file through HTTPS.

Parameters
  • url (str) – Location of the file to download.

  • dst (str) – File path of the downloaded content.

  • verbosity (int) – Verbosity level of the function. 0 silences the function. 1 prints a loading bar.

  • name (str) – Name of the downloaded file - used for logging.

diurnal.utils.file_io.is_downloaded(dst: str, n: int) bool[source]

Check if a dataset has been downloaded and is available on the filesystem.

Parameters
  • dst (str) – Expected directory in which the dataset should be.

  • n (int) – Expected number of RNA structure files.

Returns (bool): True if the dataset is downloaded, False otherwise.

diurnal.utils.log module

Message logging module.

diurnal.utils.log.error(message: str) None[source]

Print an error message.

Parameters

message (str) – Message to display.

diurnal.utils.log.info(message: str) None[source]

Print information about the execution of the program.

Parameters

message (str) – Message to display.

diurnal.utils.log.progress_bar(N: int, n: int, suffix: str = '') None[source]

Print a progress bar in the standard output.

Parameters
  • N (int) – Total number of elements to process.

  • n (int) – Number of elements that have been processed.

  • suffix (str) – A text to display after the progress bar.

diurnal.utils.log.title(message: str) None[source]

Print a highlighted message. Used at the beginning of scripts.

Parameters

message (str) – Message to display.

diurnal.utils.log.trace(message: str) None[source]

Print a trace (i.e. pedantic) message.

Parameters

message (str) – Message to display.

diurnal.utils.log.warning(message: str) None[source]

Print a warning message that may cause a failure.

Parameters

message (str) – Message to display.

diurnal.utils.rna_data module

Handle RNA structure data files.

diurnal.utils.rna_data.read_ct_file(path: str) tuple[source]

Read a CT (Connect table) file and return its information.

Parameters

path (str) – File path of the CT file.

Returns (tuple):

The returned tuple contains the following data: - RNA molecule title. - Primary structure (i.e. a list of ‘A’, ‘C’, ‘G’, and ‘U’). - Pairings (i.e. a list of integers indicating the index of the

paired based, with -1 indicating unpaired bases).

diurnal.utils.rna_data.read_ct_file_length(path: str) int[source]

Get the size of the sequence written in a CT file.

Parameters

path (str) – File path of the CT file.

Returns (int): Number of bases in the sequence.

Module contents