Skip to content

Commit

Permalink
Merge pull request #30 from gymrek-lab/citrus-package-setup
Browse files Browse the repository at this point in the history
Initial package setup with poetry and tests
  • Loading branch information
RossDeVito authored Sep 20, 2024
2 parents 0df9ec0 + 67969bd commit 8ad779f
Show file tree
Hide file tree
Showing 20 changed files with 3,604 additions and 2,536 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests

on: [pull_request, workflow_call]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
tests:
name: ${{ matrix.session }} / ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { python: "3.11", os: "ubuntu-latest", session: "tests" }
- { python: "3.12", os: "ubuntu-latest", session: "tests" }

env:
NOXSESSION: ${{ matrix.session }}
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: citrus
miniforge-variant: Mambaforge
auto-activate-base: false
miniforge-version: latest
use-mamba: true

- name: Get Date
id: get-date
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Conda env
uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/envs
key:
conda-${{ runner.os }}--${{ runner.arch }}--${{ steps.get-date.outputs.today }}-${{ hashFiles('dev-env.yml') }}-${{ env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if dev-env.yml has not changed
CACHE_NUMBER: 0
id: cache

- name: Install dev environment
run:
mamba env update -n citrus -f dev-env.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Try to build citrus
shell: bash -el {0}
run: |
poetry build --no-ansi
- name: Check distribution size
if: matrix.session == 'size'
run: |
du -csh dist/*
tar -ztvf dist/*.tar.gz
# check that the generated dist/ directory does not exceed 0.3 MB
# if this check fails, it's because you forgot to list large files in the "exclude" section of our pyproject.toml
# https://python-poetry.org/docs/pyproject/#include-and-exclude
[ $(du -b dist | cut -f1) -lt 300000 ]
- name: Check code coverage
if: matrix.session == 'coverage'
shell: bash -el {0}
run: |
export NOXSESSION=tests
# check that code coverage is not lower than specific percent
nox --verbose --python=${{ matrix.python }} -- --cov=. --cov-report=term-missing --cov-fail-under=0 # TODO update!!
- name: Run tests with nox
if: matrix.session == 'tests'
shell: bash -el {0}
run: |
nox --verbose --python=${{ matrix.python }}
large-files:
name: File sizes
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Check for large files
uses: actionsdesk/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }} # Optional
filesizelimit: 500000b
labelName: large-files
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ CITRUS, the CIs and Trans inteRaction nUmerical Simulator, is a tool for simulat

[Command Line Interface](doc/cli.md)


## Installation

For plotting models, you will need to have [graphviz](https://graphviz.org/) installed.

### With conda

**TODO - conda install instructions**

### With pip

**TODO - pip install instructions**

### From source

To install from source (only recommended for development), clone the CITRUS repository and checkout the branch you're interested in:

```bash
git clone https://github.com/gymrek-lab/CITRUS.git
cd CITRUS
pip install .
```

Now, create 1) a conda environment with our development tools and 2) a virtual environment with our dependencies and an editable install of CITRUS:

```
conda env create -n citrus -f dev-env.yml
conda run -n citrus poetry install
conda activate citrus
```
6 changes: 6 additions & 0 deletions citrus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
except PackageNotFoundError:
__version__ = "unknown"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions citrus/tests/test_citrus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest

# To check pytest framework is working
def test_dummy():
assert True
2,505 changes: 0 additions & 2,505 deletions cl_tool/sim_results/output.csv

This file was deleted.

14 changes: 14 additions & 0 deletions dev-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- conda-forge::python=3.11 # the lowest version of python that we formally support
- conda-forge::pip==24.0
- conda-forge::poetry==1.8.3 # keep in sync with release.yml
- conda-forge::nox==2024.4.15
- conda-forge::poetry-plugin-export==1.8.0
- anaconda::graphviz==2.50.0
- pip:
- nox-poetry==1.0.3
- poetry-conda==0.1.1
Binary file added example-files/example_gts_chr19.vcf.gz
Binary file not shown.
Binary file added example-files/example_gts_chr19.vcf.gz.tbi
Binary file not shown.
70 changes: 70 additions & 0 deletions example-files/linear_additive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"input": [
{
"file": "example-files/example_gts_chr19.vcf.gz",
"file_format": "vcf",
"reference_genome": "GRCh37",
"force_bgz": true,
"input_nodes": [
{
"alias": "chr19_280540_G_A",
"type": "SNP",
"chr": "19",
"pos": 280540
},
{
"alias": "chr19_523746_C_T",
"type": "SNP",
"chr": "19",
"pos": [523746]
}
]
}
],
"simulation_steps": [
{
"type": "Constant",
"alias": "chr19_280540_G_A_beta",
"input_match_size": "chr19_280540_G_A",
"constant": 0.1
},
{
"type": "Constant",
"alias": "chr19_523746_C_T_beta",
"input_match_size": "chr19_523746_C_T",
"constant": 0.3
},
{
"type": "Product",
"alias": "chr19_280540_G_A_effect",
"input_aliases": [
"chr19_280540_G_A_beta", "chr19_280540_G_A"
]
},
{
"type": "Product",
"alias": "chr19_523746_C_T_effect",
"input_aliases": [
"chr19_523746_C_T_beta", "chr19_523746_C_T"
]
},
{
"type": "Concatenate",
"alias": "effects_by_haplotype",
"input_aliases": [
"chr19_280540_G_A_effect",
"chr19_523746_C_T_effect"
]
},
{
"type": "AdditiveCombine",
"alias": "effects",
"input_alias": "effects_by_haplotype"
},
{
"type": "SumReduce",
"alias": "phenotype",
"input_alias": "effects"
}
]
}
69 changes: 69 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Nox sessions."""
import os
from pathlib import Path

import nox
from nox_poetry import Session
from nox_poetry import session


package = "citrus"
python_versions = ["3.11", "3.12"]
nox.needs_version = ">= 2022.11.21"
nox.options.sessions = (
"tests",
)


cov_cli_args = [
"--cov=.",
"--cov-report=term-missing",
]


def install_handle_python(session):
"""
handle incompatibilities between python and other packages
see https://github.com/cjolowicz/nox-poetry/issues/1116
"""
# install the latest versions of all dependencies for py3.9+
# but install the locked versions for < py3.9 to ensure some stability in the CI and
# help us understand when we need to bump our version constraints
if session._session.python in ("3.9", "3.10", "3.11", "3.12"):
session._session.install(".")
else:
session.install(".")


# detect whether conda/mamba is installed
if os.getenv("CONDA_EXE"):
conda_cmd = "conda"
if (Path(os.getenv("CONDA_EXE")).parent / "mamba").exists():
conda_cmd = "mamba"
conda_args = ["-c", "conda-forge"]

@session(venv_backend=conda_cmd, venv_params=conda_args, python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.conda_install(
"numpy",
"pytest",
"pytest-cov",
channel="conda-forge",
)
install_handle_python(session)
session.run(
"python", "-m", "pytest", *cov_cli_args, *session.posargs
)
session.run("./test/cmdline_tests.sh", external=True)
else:

@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.install("pytest", "pytest-cov")
install_handle_python_numpy(session)
session.run(
"python", "-m", "pytest", *cov_cli_args, *session.posargs
)
session.run("./test/cmdline_tests.sh", external=True)
Loading

0 comments on commit 8ad779f

Please sign in to comment.