-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release 1.0.0 See merge request casm/team78/hairpin-core!11
- Loading branch information
Showing
21 changed files
with
1,968 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
data* | ||
.env/ | ||
venv/ | ||
.venv/ | ||
dist/ | ||
*.egg-info/ | ||
__pycache__/ | ||
.helix/ | ||
build/ | ||
test_data_creation/ | ||
*.txt | ||
*.sif | ||
*.json | ||
poetry.lock | ||
.coverage | ||
test/sim-data/ | ||
test/old_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
stages: | ||
- build | ||
- test | ||
- publish | ||
|
||
include: | ||
# DOCS: https://gitlab.internal.sanger.ac.uk/team113sanger/common/cicd-template/-/blob/develop/README.md | ||
- project: 'team113sanger/common/cicd-template' | ||
ref: 0.3.1 | ||
file: '.gitlab-ci-components.yml' | ||
|
||
############# | ||
# TEMPLATES # | ||
############# | ||
|
||
.generic-wo-script-or-rules: | ||
extends: | ||
- .component-variables | ||
- .component-before_script | ||
- .component-tags-shared-large-runner | ||
|
||
.specific-variables: | ||
variables: | ||
UNIT_TEST_MOUNT_POINT: /opt/tests | ||
RUN_SCRIPT_MOUNT_POINT: /tmp/run.sh | ||
# We need to set this to 1 to enable BuildKit as the Dockerfile uses BuildKit features to speed up the build | ||
DOCKER_BUILDKIT: 1 | ||
PRE_FETCH_BASE_IMAGE: python:3.12-slim | ||
# Incase 'docker compose' build is ever used we want to ensure the image | ||
# does not have sudo. By default CICD jobs do not build with 'docker | ||
# compose' but use 'docker' - so this is just a safety measure. | ||
HAS_SUDO: 0 | ||
|
||
############ | ||
# JOBS # | ||
############ | ||
|
||
build: | ||
stage: build | ||
extends: | ||
- .generic-wo-script-or-rules | ||
- .specific-variables | ||
- .component-script_docker-build | ||
- .component-rules-except-release | ||
|
||
unit-test: | ||
stage: test | ||
extends: | ||
- .generic-wo-script-or-rules | ||
- .specific-variables | ||
- .component-rules-except-release | ||
script: | ||
- echo "*** [SCRIPT] START ***" | ||
- echo "I am a script - I run the Python unit tests in a docker container" | ||
- echo "Unit test against CANDIDATE_IMAGE='${CANDIDATE_IMAGE:?not-set-in-before_script}'" | ||
- docker pull "${CANDIDATE_IMAGE}" | ||
# Test image against unit tests - it requires env vars | ||
- docker run --entrypoint "bash" -e TEST_DIR="${UNIT_TEST_MOUNT_POINT}" -v "${PWD}/test:${UNIT_TEST_MOUNT_POINT}:ro" -v "${PWD}/docker-run-unit-tests.sh:${RUN_SCRIPT_MOUNT_POINT}:ro" --rm "${CANDIDATE_IMAGE}" ${RUN_SCRIPT_MOUNT_POINT} | ||
- echo "*** [SCRIPT] END ***" | ||
|
||
publish-develop: | ||
stage: publish | ||
extends: | ||
- .generic-wo-script-or-rules | ||
- .specific-variables | ||
- .component-script-publish-develop-docker-image | ||
- .component-rules-develop-only | ||
|
||
publish-tagged_and_latest_docker_images: | ||
stage: publish | ||
extends: | ||
- .generic-wo-script-or-rules | ||
- .specific-variables | ||
- .component-script-publish-tagged+latest-docker-image | ||
- .component-rules-tag-only | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM python:3.12-slim | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /hairpin2 | ||
|
||
# Copy the current working directory contents into the container | ||
COPY . /hairpin2 | ||
|
||
RUN adduser --disabled-password --gecos '' ubuntu && chsh -s /bin/bash && mkdir -p /home/ubuntu | ||
|
||
USER ubuntu | ||
WORKDIR /home/ubuntu | ||
|
||
# Install the hairpin package | ||
RUN pip install --no-warn-script-location /hairpin2 | ||
|
||
ENV PATH=$PATH:/home/ubuntu/.local/bin | ||
|
||
# Define a test script to check the installation of hairpin | ||
RUN LOC=$(which hairpin2) \ | ||
&& if [ -z "$LOC" ]; then \ | ||
echo "hairpin install failed" && exit 1; \ | ||
else echo "hairpin install successful"; fi | ||
|
||
# Set up the default command for the container | ||
ENTRYPOINT ["hairpin2"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
MIT License | ||
|
||
Copyright (C) 2024 Genome Research Ltd. | ||
|
||
Author: Alex Byrne <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Bootstrap: docker | ||
From: python:3.12-slim | ||
|
||
%files | ||
. hairpin2/ | ||
|
||
%post | ||
pip install --root-user-action ignore hairpin2/ | ||
|
||
%test | ||
LOC=$(which hairpin2) | ||
if [ -z "$LOC"]; then | ||
echo "hairpin install failed" | ||
else | ||
echo "hairpin install successful" | ||
fi | ||
|
||
%runscript | ||
exec hairpin2 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
if [ -z ${TEST_DIR} ]; then | ||
echo "TEST_DIR not set!" | ||
exit 1 | ||
fi | ||
PKG_DIR=$(python -c "import os;import hairpin2;import inspect;print(os.path.dirname(inspect.getfile(hairpin2)))") | ||
|
||
echo "$(python --version)" | ||
echo "Package source directory: ${PKG_DIR}" | ||
|
||
pip install \ | ||
pytest==8.2.2 \ | ||
pytest-cov==5.0.0 \ | ||
pysam==0.22 && \ | ||
pytest -m "validate" --cov="${PKG_DIR}" "${TEST_DIR}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
def _set_version() -> str: # noqa: C901 | ||
"""Set the package version from the project metadata in pyproject.toml.""" | ||
from warnings import warn | ||
|
||
fallback_version = "0.0.0" | ||
try: | ||
# importlib.metadata is present in Python 3.8 and later | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
# use the shim package importlib-metadata pre-3.8 | ||
import importlib_metadata as importlib_metadata | ||
|
||
try: | ||
# __package__ allows for the case where __name__ is "__main__" | ||
version = importlib_metadata.version(__package__ or __name__) | ||
except importlib_metadata.PackageNotFoundError: | ||
version = fallback_version | ||
|
||
if version == fallback_version: | ||
msg = ( | ||
f"Package version will be {fallback_version} because Python could not find " | ||
f"package {__package__ or __name__} in project metadata. Either the " | ||
"version was not set in pyproject.toml or the package was not installed. " | ||
"If developing code, please install the package in editable " | ||
"mode with `poetry install` or `pip install -e .`" | ||
) | ||
warn(msg) | ||
return version | ||
|
||
|
||
__version__ = _set_version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# hairpin2 | ||
# | ||
# Copyright (C) 2024 Genome Research Ltd. | ||
# | ||
# Author: Alex Byrne <[email protected]> | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
from enum import IntEnum, Flag | ||
from typing import Callable | ||
import dataclasses as d | ||
|
||
EXIT_SUCCESS = 0 | ||
EXIT_FAILURE = 1 | ||
|
||
DEFAULTS: dict[str, int | float] = dict((('al_filter_threshold', 0.93), | ||
('min_clip_quality', 35), | ||
('min_mapping_quality', 11), | ||
('min_base_quality', 25), | ||
('max_read_span', 6), | ||
('edge_definition', 0.15), | ||
('edge_fraction', 0.9), | ||
('min_MAD_one_strand', 0), | ||
('min_sd_one_strand', 4), | ||
('min_MAD_both_strand_weak', 2), | ||
('min_sd_both_strand_weak', 2), | ||
('min_MAD_both_strand_strong', 1), | ||
('min_sd_both_strand_strong', 10), | ||
('min_reads', 1))) | ||
|
||
FiltCodes = IntEnum('FiltCodes', | ||
['SIXTYAI', | ||
'SIXTYBI', | ||
'ON_THRESHOLD', | ||
'INSUFFICIENT_READS', | ||
'NO_MUTANTS'], | ||
start=0) | ||
Ops = IntEnum('Ops', | ||
['MATCH', | ||
'INS', | ||
'DEL', | ||
'SKIP', | ||
'SOFT', | ||
'HARD', | ||
'PAD', | ||
'EQUAL', | ||
'DIFF', | ||
'BACK'], | ||
start=0) | ||
ValidatorFlags = Flag('ValidatorFlags', | ||
['CLEAR', | ||
'FLAG', | ||
'MAPQUAL', | ||
'READ_FIELDS_MISSING', | ||
'NOT_ALIGNED', | ||
'BAD_OP', | ||
'NOT_ALT', | ||
'BASEQUAL', | ||
'SHORT', | ||
'CLIPQUAL', | ||
'OVERLAP'], | ||
start=0) | ||
|
||
|
||
class NoAlts(ValueError): | ||
pass | ||
|
||
|
||
class NoMutants(ValueError): | ||
pass | ||
|
||
|
||
@d.dataclass | ||
class FilterData: | ||
name: str | ||
flag: bool = False | ||
code: int | None = None | ||
|
||
def set(self): | ||
self.flag = True | ||
|
||
def __iter__(self): | ||
return (getattr(self, field.name) for field in d.fields(self)) | ||
|
||
|
||
@d.dataclass | ||
class ADFilter(FilterData): | ||
name: str = d.field(default='ADF') | ||
|
||
|
||
@d.dataclass | ||
class ALFilter(FilterData): | ||
name: str = d.field(default='ALF') | ||
avg_as: float | None = None | ||
|
||
|
||
@d.dataclass | ||
class Filters: | ||
AL: ALFilter | ||
HP: ADFilter | ||
|
||
def __iter__(self): | ||
return (getattr(self, field.name) for field in d.fields(self)) | ||
|
||
def fill_field(self, field_name, value): | ||
if hasattr(self, field_name): | ||
setattr(self, field_name, value) | ||
else: | ||
raise AttributeError | ||
|
||
def get_field(self, field_name): | ||
if hasattr(self, field_name): | ||
return getattr(self, field_name) | ||
else: | ||
raise AttributeError | ||
|
||
|
||
FiltReturn = Callable[..., Filters] | ||
FlagReturn = Callable[..., int] |
Oops, something went wrong.