GenomeUtils.Downloaders

Class Descriptions

Downloader

Abstract base for downloaders with caching, logging, and cleanup helpers for fetched files.

EnsemblGenomeDownloader

Ensembl-specific implementation that locates genome resources with gget and downloads DNA, cDNA, and GTF assets.

Classes

class GenomeUtils.Downloaders.Downloader(download_dir=None)[source]

Bases: ABC

Abstract base class for all downloaders.

Parameters:

download_dir (Path | None)

cleanup()[source]

Clean up created files.

download_file(url, filename=None, force=False)[source]

Download a single file from a URL and saves it in the cache directory.

Parameters:
  • url (str) – The URL of the file to download.

  • filename (str) – The name of the file to be saved in the cache directory.

  • force (bool) – If True, redownload the file even if it exists. Defaults to False.

Returns:

The path to the downloaded file.

Return type:

Path

class GenomeUtils.Downloaders.EnsemblGenomeDownloader(assembly_id, ensembl_release, species, genomes_root_dir=PosixPath('data/genomes'))[source]

Bases: Downloader

Downloads genome data from Ensembl FTP.

This downloader constructs URLs directly from the Ensembl FTP layout and downloads the files, storing them in genomes_root_dir/ensembl/{assembly_id}/{ensembl_release}.

Parameters:
  • assembly_id (str)

  • ensembl_release (int)

  • species (str)

  • genomes_root_dir (Path | str)

FTP_BASE = 'https://ftp.ensembl.org/pub'
download(force=False, output_db=False)[source]

Download DNA, cDNA, and Annotation files from Ensembl FTP.

Returns:

A dictionary mapping a file type to the local Path. Keys are dna, cdna, and annotation. When output_db is true, the returned mapping also contains the annotation database path under the db key.

Parameters:
  • force (bool) – If True, redownload the files even if they already exist. Defaults to False.

  • output_db (bool) – If True, create a reusable gffutils annotation database and include its path in the returned mapping.

Return type:

dict[str, Path]

get_urls()[source]

Build the Ensembl FTP URLs for DNA, cDNA, and Annotation files.

Returns:

A dictionary with keys ‘dna’, ‘cdna’, ‘annotation’ mapping to URLs.

Return type:

dict[str, str]