Utilities & Helper Functions

This section documents utility functions and helper code used across the GRiD pipeline. These include functions for data manipulation, file handling, and other common tasks that support the core pipeline steps.

grid.utils.utils.check_index(config, console=None)

Check that all samples have BAM/CRAM files and corresponding indexes.

grid.utils.utils.create_index(config, console=None)

Create index for BAM/CRAM files if not already present.

grid.utils.utils.create_index_for_file(file_path, file_type, reference_genome)
grid.utils.utils.create_region_string(chrom, start, end, console=None)

Create a genomic region string in ‘chr:start-end’ format.

Parameters:
  • chrom (str) – Chromosome name (e.g., ‘chr6’)

  • start (int) – Start position (e.g., 160000000)

  • end (int) – End position (e.g., 160100000)

Returns:

Genomic region string.

Return type:

str

grid.utils.utils.find_file(directory_loc, sample, expected_type=None)

Return file_path or None.

grid.utils.utils.get_flags(config, parameter)
grid.utils.utils.get_samples(samples_file)
grid.utils.utils.has_index(file_path, file_type)

Check if appropriate index exists.

grid.utils.utils.log(console, msg, style=None)
grid.utils.utils.open_maybe_gz(path, mode='rt')
grid.utils.utils.progress_bar(console=None, total=1, description='Working')

Reusable progress bar context manager.

Usage:
with progress_bar(console, total=len(samples), description=”Processing samples”) as (progress, task):
for sample in samples:

progress.update(task, description=f”Processing {sample}”) # do work progress.advance(task)

grid.utils.utils.setup_output_file(output_file, chrom, start, end)

Create output file with header.

Parameters:
  • output_file (str) – Path to output TSV file

  • chrom (str) – Chromosome name

  • start (int) – Start position

  • end (int) – End position

Returns:

Path object for the output file

Return type:

Path