Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0b13496
fix: leave features combat cannot estimate uncorrected
eneskemalergin Nov 21, 2026
faf27b2
fix: read data matrices exactly as written
eneskemalergin Nov 21, 2026
37b4581
fix: cli run outputs match the given options
eneskemalergin Nov 21, 2026
0174968
fix: reject or set aside engine inputs that break the fit
eneskemalergin Nov 21, 2026
9463582
fix: make the dry run and the reader match the run
eneskemalergin Nov 21, 2026
8602859
refactor: share duplicated code across the package
eneskemalergin Nov 21, 2026
d127d0c
docs: standardise the core module docstrings
eneskemalergin Nov 21, 2026
b579f0e
perf: solve combat batches together and trim per-group work
eneskemalergin Nov 21, 2026
e1cdea1
perf: compute the non-parametric prior in smaller blocks
eneskemalergin Nov 21, 2026
60c0ff8
perf: read delimited files on the calling thread
eneskemalergin Nov 21, 2026
9d23850
fix: keep precision in the non-parametric combat prior
eneskemalergin Nov 21, 2026
f3d7e02
fix: fit engine features on their measured batches
eneskemalergin Nov 21, 2026
bfbf715
feat: warn when input values look untransformed
eneskemalergin Nov 21, 2026
7f486cf
docs: make documentation match the code
eneskemalergin Nov 21, 2026
78414d8
test: run docstring examples with the suite
eneskemalergin Nov 21, 2026
96bfd0d
feat: report what happened to each feature
eneskemalergin Nov 21, 2026
ec9c713
fix: keep zero-variance rows raw in non-parametric modes
eneskemalergin Nov 22, 2026
d460399
perf: cut per-group overhead of the combat checks
eneskemalergin Nov 22, 2026
a730cda
docs: bring the docs up to date for 0.4.0
eneskemalergin Nov 22, 2026
7bdd5ec
docs: regroup the changelog with a summary per version
eneskemalergin Nov 22, 2026
2141009
ci: add a release workflow for tagged versions
eneskemalergin Nov 22, 2026
937c475
docs: overhaul the wiki
eneskemalergin Nov 22, 2026
59dbdab
fix: break unique-removal ties independently of row order
eneskemalergin Nov 22, 2026
c9cc65b
fix: never crop a feature into a one-batch affiliation
eneskemalergin Nov 22, 2026
6623201
fix: require a whole number for needed_values
eneskemalergin Nov 22, 2026
d8a74da
fix: refuse cli outputs that overwrite inputs
eneskemalergin Nov 22, 2026
03ccf38
fix: count features correctly in the log
eneskemalergin Nov 22, 2026
01b221b
fix: reject values too large for combat's variance sums
eneskemalergin Nov 22, 2026
ea75fdb
docs: correct cli help, readme guidance, and parity list
eneskemalergin Nov 22, 2026
c6fc6c5
fix: record cpu, blas threads and version in reports
eneskemalergin Nov 22, 2026
96eff75
test: check rows and missing cells against R both ways
eneskemalergin Nov 22, 2026
01086a1
fix: let unique removal target any other feature's pattern
eneskemalergin Nov 22, 2026
67831a8
build: sync renv.lock to the installed R library
eneskemalergin Nov 22, 2026
304d0d8
fix: leave limma features without a residual raw
eneskemalergin Nov 22, 2026
bff0ff0
docs: describe the current rules in the wiki
eneskemalergin Nov 22, 2026
dedaf62
fix: make seriation order independent of row order
eneskemalergin Nov 22, 2026
4b6e405
fix: read feature names and sample ids as written
eneskemalergin Nov 22, 2026
04ff5cf
fix: write output files atomically
eneskemalergin Nov 22, 2026
d7032eb
test: check per-cell missing values against r
eneskemalergin Nov 22, 2026
1f4c15c
fix: keep one-sided feature counts in report json
eneskemalergin Nov 22, 2026
59e3dd9
docs: align docstrings, help and wiki with the code
eneskemalergin Nov 22, 2026
27f6a7c
bench: draw benchmark figures from new sweeps
eneskemalergin Nov 22, 2026
4abee43
docs: report the 0.4.0 benchmarks with figures
eneskemalergin Nov 22, 2026
48b25d6
chore: release 0.4.0
eneskemalergin Nov 22, 2026
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
108 changes: 108 additions & 0 deletions .github/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
# Release checks and packages for HarmonizePy.
#
# release.sh version print the version, after checking pyproject.toml, __init__.py, and CITATION.cff agree
# release.sh notes [TAG] print the CHANGELOG.md section of the version (TAG must be vVERSION)
# release.sh package OUTPUT_DIR build the wheel and sdist, check them, smoke-test the wheel, copy both to OUTPUT_DIR
#
# The sdist must hold only files git tracks, and the wheel is installed into a fresh environment outside the
# checkout and run there. Work directories are made under RUNNER_TEMP (or /var/tmp) and left in place.

set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/../.."

die() {
printf 'error: %s\n' "$*" >&2
exit 1
}

version=$(sed -n 's/^version = "\([^"]*\)"$/\1/p' pyproject.toml)
[[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] ||
die "pyproject.toml must declare one major.minor.patch version"
init_version=$(sed -n 's/^__version__ = "\([^"]*\)"$/\1/p' src/harmonizepy/__init__.py)
[[ "$init_version" == "$version" ]] || die "__init__.py has version '$init_version', pyproject.toml '$version'"
cff_version=$(sed -n 's/^version: \(.*\)$/\1/p' CITATION.cff)
[[ "$cff_version" == "$version" ]] || die "CITATION.cff has version '$cff_version', pyproject.toml '$version'"

notes() {
awk -v version="$version" '
/^## / {
if (found) exit
found = ($2 == "[" version "]")
next
}
found {
if ($0 ~ /[^[:space:]]/) nonempty = 1
if (nonempty) print
}
END { if (!found || !nonempty) exit 1 }
' CHANGELOG.md || die "CHANGELOG.md needs a nonempty [$version] section"
}

package() {
local output="$1" work dist wheel sdist untracked name="harmonizepy-$version"
work=$(mktemp -d "${RUNNER_TEMP:-/var/tmp}/harmonizepy-release.XXXXXX")
dist="$work/dist"
uv build --out-dir "$dist" > "$work/build.log" 2>&1 || { cat "$work/build.log" >&2; die "uv build failed"; }
wheel="$dist/$name-py3-none-any.whl"
sdist="$dist/$name.tar.gz"
[[ -s "$wheel" && -s "$sdist" ]] || die "expected $name-py3-none-any.whl and $name.tar.gz, found: $(ls "$dist")"
[[ "$(find "$dist" -maxdepth 1 -type f \( -name '*.whl' -o -name '*.tar.gz' \) | wc -l)" -eq 2 ]] ||
die "expected one wheel and one sdist in the build output: $(ls "$dist")"

tar -tzf "$sdist" | sed -n "s,^$name/,,p" | grep -v -e '/$' -e '^PKG-INFO$' | LC_ALL=C sort > "$work/sdist-files"
git ls-files | LC_ALL=C sort > "$work/tracked-files"
untracked=$(LC_ALL=C comm -23 "$work/sdist-files" "$work/tracked-files")
[[ -z "$untracked" ]] || die "the sdist holds files git does not track: $untracked"

uv venv --quiet --python 3.12 "$work/venv"
uv pip install --quiet --python "$work/venv/bin/python" "$wheel"
(
cd "$work"
export PATH="$work/venv/bin:/usr/bin:/bin"
[[ "$(harmonizepy --version)" == "harmonizepy $version" ]] || die "--version is not 'harmonizepy $version'"
python - <<'PY'
import numpy as np
import pandas as pd

import harmonizepy

rng = np.random.default_rng(0)
batch = np.repeat([1, 2, 3], 4)
values = rng.normal(20, 1, (30, 1)) + rng.normal(0, 0.3, (30, 12)) + np.array([0.0, 1.0, -1.0])[batch - 1]
values[:2, batch == 3] = np.nan
samples = [f"s{i}" for i in range(12)]
data = pd.DataFrame(values, index=[f"f{i}" for i in range(30)], columns=samples)
data.to_csv("data.tsv", sep="\t")
pd.DataFrame({"ID": samples, "sample": range(1, 13), "batch": batch}).to_csv("batch.csv", index=False)
for algorithm, mode in (("ComBat", 1), ("ComBat", 3), ("limma", 1)):
out, report = harmonizepy.harmonize(data, "batch.csv", algorithm=algorithm, combat_mode=mode, return_report=True)
assert out.shape == data.shape and report["status"].eq("corrected").all(), (algorithm, mode)
assert out.iloc[:2, 8:].isna().all().all() and np.isfinite(out.iloc[2:]).all().all()
PY
harmonizepy data.tsv batch.csv -o corrected.tsv --report report.tsv --no-log -q
[[ "$(wc -l < corrected.tsv)" -eq 31 && "$(wc -l < report.tsv)" -eq 31 ]] || die "the CLI run wrote the wrong number of rows"
)
mkdir -p "$output"
cp "$wheel" "$sdist" "$output/"
printf 'tested %s\n' "$output/$(basename "$wheel")" "$output/$(basename "$sdist")"
}

case "${1:-}" in
version)
printf '%s\n' "$version"
;;
notes)
tag="${2:-v$version}"
[[ "$tag" == "v$version" ]] || die "tag $tag does not match version v$version"
notes
;;
package)
[[ $# -eq 2 ]] || die "usage: release.sh package OUTPUT_DIR"
package "$2"
;;
*)
printf 'usage: release.sh version | notes [TAG] | package OUTPUT_DIR\n' >&2
exit 2
;;
esac
40 changes: 39 additions & 1 deletion .github/scripts/wiki_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
_LINK_TITLE = re.compile(r"""\s+(?:"[^"]*"|'[^']*'|\([^)]*\))\s*$""")
_INLINE_CODE = re.compile(r"`+[^`\n]*`+")
_FENCE = re.compile(r"^( {0,3})(`{3,}|~{3,})")
_ASSET_DIR = "assets"
_ASSET_SUFFIXES = (".png",)
_ASSET_REFERENCE = re.compile(r"""(?:src|srcset)\s*=\s*["']([^"']+)["']|!\[[^]\n]*\]\(([^)\s]+)""")


def _blank(text: str) -> str:
Expand Down Expand Up @@ -87,6 +90,26 @@ def _is_external(target: str) -> bool:
) or target.startswith("#")


def _validate_assets(asset_dir: Path, assets: set[str]) -> list[str]:
"""Check the image folder and record its files as ``assets/NAME`` references."""

errors: list[str] = []
for entry in sorted(asset_dir.iterdir(), key=lambda path: path.name.casefold()):
relative = f"{asset_dir}/{entry.name}"
if entry.is_symlink() or not entry.is_file():
errors.append(f"{_ASSET_DIR}/ entries must be regular files: {relative}")
continue
if not entry.name.casefold().endswith(_ASSET_SUFFIXES):
errors.append(f"{_ASSET_DIR}/ permits PNG images only: {relative}")
continue
if _PORTABLE_FILENAME_CHARS.search(entry.name):
errors.append(f"image filename contains a non-portable character: {relative}")
if entry.stat().st_size == 0:
errors.append(f"image is empty: {relative}")
assets.add(f"{_ASSET_DIR}/{entry.name}")
return errors


def validate(wiki_dir: Path) -> list[str]:
"""Return validation errors for ``wiki_dir``; an empty list means valid."""

Expand All @@ -98,10 +121,17 @@ def validate(wiki_dir: Path) -> list[str]:
pages: list[Path] = []
aliases: dict[str, Path] = {}

assets: set[str] = set()

for entry in entries:
relative = f"{wiki_dir}/{entry.name}"
if entry.name == _ASSET_DIR and entry.is_dir() and not entry.is_symlink():
errors.extend(_validate_assets(entry, assets))
continue
if entry.is_symlink() or not entry.is_file():
errors.append(f"wiki entries must be regular top-level files: {relative}")
errors.append(
f"wiki entries must be regular top-level files or the {_ASSET_DIR}/ folder: {relative}"
)
continue
if not entry.name.endswith(".md"):
errors.append(f"wiki source currently permits Markdown pages only: {relative}")
Expand Down Expand Up @@ -134,6 +164,14 @@ def validate(wiki_dir: Path) -> list[str]:
continue

visible_text = _without_code(text)
for match in _ASSET_REFERENCE.finditer(visible_text):
reference = (match.group(1) or match.group(2)).strip()
if _is_external(reference) or not reference.startswith(f"{_ASSET_DIR}/"):
continue
if reference not in assets:
line = _line_number(text, match.start())
errors.append(f"{page}:{line} references a missing image: {reference}")

for match in _WIKI_LINK.finditer(visible_text):
specification = match.group(1).strip()
page_target = specification.split("|", 1)[0].strip()
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@ jobs:
- name: Mypy
run: uv run mypy src/

package:
name: Package
runs-on: ubuntu-24.04
timeout-minutes: 15

steps:
- name: Check out repository
uses: actions/checkout@v7.0.1

- name: Install uv
uses: astral-sh/setup-uv@v10.3.0
with:
enable-cache: true
cache-suffix: package

- name: Build, check, and smoke-test the wheel and sdist
run: bash .github/scripts/release.sh package "$RUNNER_TEMP/dist"

# The release workflow publishes these files from main's CI run on the tagged commit.
- name: Keep the tested packages
uses: actions/upload-artifact@v7.0.2
with:
name: release-dist
path: ${{ runner.temp }}/dist/*
if-no-files-found: error
retention-days: 90

test:
name: Test ${{ matrix.name }}
runs-on: ${{ matrix.os }}
Expand Down
161 changes: 161 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Publishes a GitHub release for a vX.Y.Z tag, in two steps; the first failure stops it.
#
# - gate: the tag names the version in pyproject.toml, __init__.py, and CITATION.cff, CHANGELOG.md has its section,
# the tagged commit is main's head, and main's CI on that commit has passed. Nothing is rebuilt: a tag pushed
# before that CI run finishes fails, and the release is re-run once it has passed. CI keeps the packages for
# 90 days; after that, the release needs a new CI run on main.
# - publish: the wheel and sdist that CI built and smoke-tested, with checksums and the changelog section as notes,
# as a draft release first, so a failed upload or attestation can be re-run without a half-published release;
# attestations; and only then the public release.
#
# Started by hand on main, it rehearses the gate for main's version and publishes nothing.
# It does not upload to a package index.
name: release

on:
push:
tags: ['v*']
workflow_dispatch:

permissions: {}

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

jobs:
gate:
name: Release gate
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
actions: read
outputs:
tag: ${{ steps.tag.outputs.tag }}
version: ${{ steps.tag.outputs.version }}
run: ${{ steps.ci.outputs.run }}
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
steps:
- name: Check out the tagged source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Check the tag, version, and notes
id: tag
run: |
set -euo pipefail
version=$(bash .github/scripts/release.sh version)
if [[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]; then
test "$GITHUB_REF" = refs/heads/main || { echo "a rehearsal runs on main, not $GITHUB_REF" >&2; exit 1; }
tag="v$version"
else
tag="$GITHUB_REF_NAME"
[[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "tag must be vX.Y.Z: $tag" >&2; exit 1; }
test "$tag" = "v$version" || { echo "tag $tag does not match version $version" >&2; exit 1; }
fi
bash .github/scripts/release.sh notes "$tag" > /dev/null
printf 'tag=%s\nversion=%s\n' "$tag" "$version" >> "$GITHUB_OUTPUT"

- name: Check the commit is main's head
env:
TAG: ${{ steps.tag.outputs.tag }}
run: |
set -euo pipefail
main=$(gh api "repos/$GH_REPO/commits/main" --jq .sha)
test "$GITHUB_SHA" = "$main" || { echo "$TAG at $GITHUB_SHA is not main's head ($main)" >&2; exit 1; }

- name: Find main's passed CI run on the commit
id: ci
run: |
set -euo pipefail
run=$(gh run list --workflow ci.yml --branch main --commit "$GITHUB_SHA" --limit 20 \
--json databaseId,event,status,conclusion \
--jq '[.[] | select(.event == "push")][0] // empty | [.databaseId, .status, .conclusion] | @tsv')
[[ -n "$run" ]] || { echo "no CI run on main for $GITHUB_SHA" >&2; exit 1; }
IFS=$'\t' read -r id status conclusion <<< "$run"
[[ "$status" == completed ]] || { echo "CI run $id on main has not finished; re-run the release after it passes" >&2; exit 1; }
[[ "$conclusion" == success ]] || { echo "CI run $id on main concluded $conclusion" >&2; exit 1; }
printf 'run=%s\n' "$id" >> "$GITHUB_OUTPUT"

publish:
name: Publish release
needs: gate
if: github.event_name == 'push'
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
actions: read
id-token: write
attestations: write
artifact-metadata: write
env:
TAG: ${{ needs.gate.outputs.tag }}
VERSION: ${{ needs.gate.outputs.version }}
steps:
- name: Check out the tagged source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Check the tag still names the verified commit
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
tagged=$(gh api "repos/$GH_REPO/commits/$TAG" --jq .sha)
test "$tagged" = "$GITHUB_SHA" || { echo "tag $TAG moved to $tagged during the release" >&2; exit 1; }

- name: Download the tested packages
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
run-id: ${{ needs.gate.outputs.run }}
github-token: ${{ github.token }}
name: release-dist
path: ${{ runner.temp }}/assets

- name: Prepare notes and checksums
run: |
set -euo pipefail
cd "$RUNNER_TEMP/assets"
for name in "harmonizepy-$VERSION-py3-none-any.whl" "harmonizepy-$VERSION.tar.gz"; do
test -s "$name" || { echo "missing tested package: $name" >&2; exit 1; }
done
count=$(find . -maxdepth 1 -type f | wc -l)
test "$count" -eq 2 || { echo "expected the 2 tested packages, found $count files: $(ls)" >&2; exit 1; }
sha256sum ./*.whl ./*.tar.gz > SHA256SUMS
sha256sum --check SHA256SUMS
cd "$GITHUB_WORKSPACE"
bash .github/scripts/release.sh notes "$TAG" > "$RUNNER_TEMP/notes.md"

- name: Create or resume the draft release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
if draft=$(gh release view "$TAG" --json isDraft --jq .isDraft 2> "$RUNNER_TEMP/view.err"); then
test "$draft" = true || { echo "release $TAG is already published" >&2; exit 1; }
elif grep -q "release not found" "$RUNNER_TEMP/view.err"; then
gh release create "$TAG" --draft --verify-tag --title "HarmonizePy $VERSION" --notes-file "$RUNNER_TEMP/notes.md"
else
cat "$RUNNER_TEMP/view.err" >&2
exit 1
fi
gh release upload "$TAG" "$RUNNER_TEMP/assets"/* --clobber

- name: Attest the release packages
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-checksums: ${{ runner.temp }}/assets/SHA256SUMS

- name: Publish the release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: gh release edit "$TAG" --draft=false --latest --verify-tag
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ renv/sandbox/
*.swo
*~
.DS_Store

*.svg
Loading
Loading