diff --git a/tcga_downloader/download.py b/tcga_downloader/download.py new file mode 100644 index 0000000..473ef95 --- /dev/null +++ b/tcga_downloader/download.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +import shutil +import subprocess +from pathlib import Path + + +def build_gdc_command(manifest_path: Path, out_dir: Path, processes: int, retries: int) -> list[str]: + return [ + "gdc-client", + "download", + "-m", + str(manifest_path), + "-d", + str(out_dir), + "--n-processes", + str(processes), + "--retry-count", + str(retries), + "--checksum", + ] + + +def run_gdc_download(manifest_path: Path, out_dir: Path, processes: int = 4, retries: int = 3) -> None: + if not shutil.which("gdc-client"): + raise RuntimeError("gdc-client not found in PATH") + cmd = build_gdc_command(manifest_path, out_dir, processes, retries) + subprocess.run(cmd, check=True) diff --git a/tests/test_download.py b/tests/test_download.py new file mode 100644 index 0000000..2d72dd7 --- /dev/null +++ b/tests/test_download.py @@ -0,0 +1,9 @@ +from pathlib import Path + +from tcga_downloader.download import build_gdc_command + + +def test_build_gdc_command(): + cmd = build_gdc_command(Path("/tmp/m.tsv"), Path("/data"), processes=4, retries=3) + assert "gdc-client" in cmd[0] + assert "-m" in cmd