Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .dockerignore

This file was deleted.

70 changes: 0 additions & 70 deletions .github/workflows/publish.yml

This file was deleted.

29 changes: 0 additions & 29 deletions Dockerfile

This file was deleted.

109 changes: 23 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,46 @@
# prs_utils
# python_template

![test](https://github.com/UMCUGenetics/prs_utils/actions/workflows/test.yml/badge.svg)
![lint](https://github.com/UMCUGenetics/prs_utils/actions/workflows/lint.yml/badge.svg)
![test](https://github.com/UMCUGenetics/python_template/actions/workflows/test.yml/badge.svg)
![lint](https://github.com/UMCUGenetics/python_template/actions/workflows/lint.yml/badge.svg)

Utility commands for the PRS pipeline, bundled as a single installable package.
Python template project - This repository can be used as a starting point / guide on how to setup a python repository, including automated tests and code formatting.

These utilities previously lived as standalone [PEP 723](https://peps.python.org/pep-0723/)
scripts inside the `prsutils` Nextflow modules
(`NF-Modules/modules/UMCUGenetics/prsutils/*/resources/usr/bin/`), each with its own
`uv run --script` header and lock file. They are now one package with shared dependency
resolution, linting and tests. The behaviour of every command is unchanged.
## GitHub repository creation

## Commands
- Repository name: `Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.`
- Add README
- Add .gitignore: `python`
- Add License: `MIT`

Everything is reachable through the `prs-utils` entry point:
Make sure to perform the following actions, after creating a new github repo:

| Subcommand | Original script | NF module |
| --- | --- | --- |
| `prs-utils pgs-to-vcf` | `pgs_to_vcf.py` | `prsutils/getvcf` |
| `prs-utils merge-prs-mqc` | `merge_prs_mqc.py` | `prsutils/mergeprsmqc` |
| `prs-utils normalise-counts` | `normalise_counts.py` | `prsutils/norm` |
| `prs-utils sample-qc` | `sample_qc.py` | `prsutils/sampleqc` |
| `prs-utils get-snp-list` | `get_snp_list.py` | `prsutils/snplist` |
- Create a develop branch.
- Configure branch protection rules.

Each subcommand keeps the argument parser it was written with, so the flags are identical to
the standalone scripts. Use `prs-utils <subcommand> --help` for the per-command options.
## UV

```sh
uv run prs-utils --help
uv run prs-utils normalise-counts --PRS scores.tsv --mu 0.5 --SD 0.1 -o normalised.tsv
uv run prs-utils get-snp-list --scoring_file PGS000004.txt --prefix PGS000004 --flank 100
```

Note that `merge-prs-mqc` takes its inputs as bare positional paths and always writes
`prs_scores_mqc.tsv` in the working directory.
UV supports packaged and unpackaged applications, this repository show cases a packaged application initiated with the command: `uv init --package .`. To create a simpler unpackaged application use: `uv init .`. Unpackaged applications can be used for single file scripts/tools, while packaged applications are used for (larger) tools requiring multiple files, distribution (pip) and tests separation.

## Container image

Each release publishes a multi-arch image to
`ghcr.io/umcugenetics/prs-utils:<version>`, built from `uv.lock` so the dependency set is exactly
the one the tests ran against. This is what the `prsutils` Nextflow modules pin their `container`
directive to.
Setup uv package and development dependencies:

```sh
docker run --rm -v "$PWD:/data" -w /data ghcr.io/umcugenetics/prs-utils:1.0.0 \
prs-utils normalise-counts --PRS scores.tsv --mu 0.5 --SD 0.1 -o normalised.tsv
uv init --package .
uv add --dev ruff
uv add --dev pytest
```

Singularity pulls the same image directly:
Run pytest and the python-template tool:

```sh
singularity exec docker://ghcr.io/umcugenetics/prs-utils:1.0.0 prs-utils --version
```

Build it locally without publishing:

```sh
docker build -t prs-utils:dev .
```

## Releasing

`prs-utils --version` prints the bare version from `pyproject.toml`, and the Nextflow modules
capture that output into their `versions` topic and snapshot it. Keep the two repositories in step:

1. Bump `version` in `pyproject.toml`.
2. Run `uv lock` and commit the updated `uv.lock`.
3. Tag and publish a GitHub release. The `publish.yml` workflow builds and pushes the image, then
fails the release if the image does not report the tagged version.
4. Confirm the new tag appears under the repository's Packages.
5. Bump the `container` tag in the five `prsutils` modules in
[UMCUGenetics/NF-Modules](https://github.com/UMCUGenetics/NF-Modules) and re-run their nf-tests.

The first published version needs one manual step: set the GHCR package visibility to **public**
(Package settings → Change visibility). Otherwise every `singularity pull` in CI and on the HPC
needs registry credentials.

## Development

Setup and run the test suite:

```sh
uv sync
uv run pytest tests
```

Linting and formatting use [Ruff](https://docs.astral.sh/ruff/):

```sh
uv run ruff check src tests
uv run ruff format src tests
uv run python-template World
uv run python-template --help
```

## GitHub Actions

This repository contains two GitHub actions workflows (`.github/workflows/`): `lint.yml` and
`test.yml`. The lint workflow uses the [ruff-action](https://github.com/astral-sh/ruff-action)
action to run ruff. The test workflow uses the
[setup-uv action](https://github.com/astral-sh/setup-uv) to setup uv, install dependencies and
run tests. Both actions are configured to run on each pull request and push to main and develop.
This template project contains two GitHub actions workflows (`.github/workflos/`): `lint.yml` and `test.yml`. The lint workflow uses the [ruff-action](https://github.com/astral-sh/ruff-action) action to run ruff. The test workflow uses the [setup-uv action](https://github.com/astral-sh/setup-uv) to setup uv, install dependencies and run tests. Both actions are configured to run on each pull request and push to main and develop.

## pre-commit

Git pre-commit hooks enable you to run certain commands before each commit and can be used to
check code style before committing. The file `.pre-commit-config.yaml` contains the
[Ruff](https://docs.astral.sh/ruff/) [pre-commit](https://pre-commit.com) hook, which will
automatically run Ruff before each commit. Run the following command to install the git commit
hook: `uvx pre-commit install`.
Git pre-commit hooks enable you to run certain commands before each commit and can be used to check code style before committing. The file `.pre-commit-config.yaml` contains the [Ruff](https://docs.astral.sh/ruff/) [pre-commit](https://pre-commit.com) hook, which will automatically run Ruff before each commit. Run the following command to install the git commit hook: `uvx pre-commit install`.
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[project]
name = "prs-utils"
version = "1.0.0"
description = "Utility commands used by the UMCUGenetics prsutils Nextflow modules."
name = "python-template"
version = "0.1.0"
description = "Python template project."
readme = "README.md"
authors = [
{ name = "Bioinformatica Genetica", email = "bioinformatica-genetica@umcutrecht.nl" }
]
requires-python = ">=3.12"
requires-python = "~=3.14.0"
dependencies = [
"pandas>=2.2",
"typer>=0.26.8",
]

Expand All @@ -20,7 +19,7 @@ dev = [
]

[project.scripts]
prs-utils = "prs_utils.cli:cli"
python-template = "python_template.cli:cli"

[build-system]
requires = ["uv_build>=0.11.27,<0.12"]
Expand Down
88 changes: 0 additions & 88 deletions src/prs_utils/cli.py

This file was deleted.

Loading