-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (118 loc) · 5.59 KB
/
Copy pathMakefile
File metadata and controls
152 lines (118 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# This Makefile provides shortcut commands to facilitate local development.
# Common variables
PACKAGE_NAME = winnow
# LAST_COMMIT returns the current HEAD commit
LAST_COMMIT = $(shell git rev-parse --short HEAD)
# VERSION represents a clear statement of which tag based version of the repository you're actually running.
# If you run a tag based version, it returns the according HEAD tag, otherwise it returns:
# * `LAST_COMMIT-staging` if no tags exist
# * `BASED_TAG-SHORT_SHA_COMMIT-staging` if a previous tag exist
VERSION := $(shell git describe --always --exact-match --abbrev=0 --tags $(LAST_COMMIT) 2> /dev/null)
ifndef VERSION
BASED_VERSION := $(shell git describe --always --abbrev=3 --tags $(git rev-list --tags --max-count=1))
ifndef BASED_VERSION
VERSION = $(LAST_COMMIT)-staging
else
VERSION = $(BASED_VERSION)-staging
endif
endif
# Docker variables
DOCKER_HOME_DIRECTORY = "/app"
DOCKER_RUNS_DIRECTORY = "/runs"
DOCKERFILE := Dockerfile
DOCKER_IMAGE_NAME = winnow
DOCKER_IMAGE_TAG = $(VERSION)
DOCKER_IMAGE = $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
DOCKER_RUN_FLAGS = --rm --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --shm-size='1gb'
DOCKER_RUN_FLAGS_VOLUME_MOUNT_HOME = $(DOCKER_RUN_FLAGS) --volume $(PWD):$(DOCKER_HOME_DIRECTORY)
DOCKER_RUN_FLAGS_VOLUME_MOUNT_RUNS = $(DOCKER_RUN_FLAGS) --volume $(PWD)/runs:$(DOCKER_RUNS_DIRECTORY)
DOCKER_RUN = docker run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE_NAME)
PYTEST = uv run pytest tests --verbose --cov=winnow --cov-report xml:coverage.xml --cov-report term-missing --junitxml=pytest.xml --cov-fail-under=0
#################################################################################
## Docker build commands #
#################################################################################
.PHONY: build build-arm
define docker_buildx_template
docker buildx build --platform=$(1) --progress=plain . \
-f $(DOCKERFILE) -t $(2) --build-arg GID=$(shell id -g) \
--build-arg UID=$(shell id -u) --build-arg LAST_COMMIT=$(LAST_COMMIT) \
--build-arg VERSION=$(VERSION) --build-arg HOME_DIRECTORY=$(DOCKER_HOME_DIRECTORY) \
--build-arg RUNS_DIRECTORY=$(DOCKER_RUNS_DIRECTORY)
endef
## Build Docker image for winnow on AMD64
build:
$(call docker_buildx_template,linux/amd64,$(DOCKER_IMAGE))
## Build Docker image for winnow on ARM64
build-arm:
$(call docker_buildx_template,linux/arm64,$(DOCKER_IMAGE))
#################################################################################
## Install packages commands #
#################################################################################
.PHONY: install install-frozen install-dev
## Install project dependencies (may resolve and update lockfile if needed)
# Note that uv includes the `dev` group by default, so we need to exclude it with `--no-dev`
install:
uv sync --no-dev
## Install development tools (testing, linting, etc.)
install-dev:
uv sync
## Install project dependencies exactly as specified in lockfile (fast, no resolution)
install-frozen:
uv sync --frozen
## Install all dependencies
install-all:
uv sync --all-extras
#################################################################################
## Development commands #
#################################################################################
.PHONY: tests clean-coverage test-docker bash build-package clean-build clean-workspace test-build clean-all-build test-cli-isolated test-cli-config set-gcp-credentials
## Run all tests
tests:
$(PYTEST)
## Clean coverage reports
clean-coverage:
rm -rf htmlcov/ .coverage coverage.xml pytest.xml
## Run all tests in the Docker Image
test-docker:
docker run $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE) $(PYTEST)
## Open a bash shell in the Docker image
bash:
docker run -it $(DOCKER_RUN_FLAGS) $(DOCKER_IMAGE) /bin/bash
## Build the winnow-fdr package (creates wheel and sdist in dist/)
build-package:
uv build
## Clean all build artifacts (dist/, build/, *.egg-info/)
clean-build:
rm -rf dist/ build/ *.egg-info/ winnow_fdr.egg-info/
## Build the package and then clean up (safe test build)
test-build: build-package clean-build
## Set the GCP credentials
set-gcp-credentials:
uv run python scripts/set_gcp_credentials.py
gcloud auth activate-service-account dtu-denovo-sa@ext-dtu-denovo-sequencing-gcp.iam.gserviceaccount.com --key-file=ext-dtu-denovo-sequencing-gcp.json --project=ext-dtu-denovo-sequencing-gcp
#################################################################################
## Sample data and CLI commands #
#################################################################################
.PHONY: train-sample predict-sample clean clean-all
## Run winnow train with sample data
train-sample:
uv run winnow train \
dataset.spectrum_path_or_directory=examples/example_data/spectra.mgf \
dataset.predictions_path=examples/example_data/predictions.csv \
model_output_dir=models/new_model \
dataset_output_path=results/calibrated_dataset.csv \
calibrator.features.retention_time_feature.train_fraction=0.3 \
calibrator.features.retention_time_feature.min_train_points=2 \
calibrator.hidden_layer_sizes="[32, 16]" \
calibrator.early_stopping=false \
calibrator.max_iter=100
## Run winnow predict with sample data (uses locally trained model from models/new_model)
predict-sample:
uv run winnow predict \
calibrator.pretrained_model_name_or_path=models/new_model \
fdr_control.fdr_threshold=1.0 \
dataset.spectrum_path_or_directory=examples/example_data/spectra.mgf \
dataset.predictions_path=examples/example_data/predictions.csv
## Clean output directories (does not delete sample data)
clean:
rm -rf models/ results/