Skip to content

Commit

Permalink
Dockerise and conda-lock (#6)
Browse files Browse the repository at this point in the history
* fix hrdetect pvalue bug

* fix run scripts

* fix cli modules

* fix README cli

* cleanup

* cleanup README

* reorg conda

* rename gha file

* add docker/conda-lock GH Action

* add Dockerfile
  • Loading branch information
pdiakumis authored Jun 10, 2022
1 parent 00ea6ef commit f66d557
Show file tree
Hide file tree
Showing 28 changed files with 485 additions and 262 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
^conda$
^\.github$
^vignettes$
^Dockerfile$
^\.dockerignore$
16 changes: 16 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,19 @@ replace = Version: {new_version}
[bumpversion:file:conda/recipe/meta.yaml]
search = version: {current_version}
replace = version: {new_version}

[bumpversion:file:.github/workflows/deploy.yaml]
search = VERSION: '{current_version}'
replace = VERSION: '{new_version}'

[bumpversion:file:conda/env/yaml/sigrap.yaml]
search = r-sigrap =={current_version}
replace = r-sigrap =={new_version}

[bumpversion:file:README.Rmd]
search = sigrap.R {current_version}
replace = sigrap.R {new_version}

[bumpversion:file:README.md]
search = sigrap.R {current_version}
replace = sigrap.R {new_version}
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!conda
!.dockerignore
120 changes: 120 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: conda-docker-docs

on:
push:
branches:
- main
env:
atoken: ${{ secrets.ANACONDA_UPLOAD_TOKEN }}
recipe_path: conda/recipe
env_yaml_path: conda/env/yaml
env_lock_path: conda/env/lock
VERSION: '0.0.4' # versioned by bump2version
GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }}

jobs:
condarise-dockerise-document:
# When merging to main and the commit message starts with 'Bump version:'
if: "startsWith(github.event.head_commit.message, 'Bump version:')"
name: Conda Docker Docs
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}

steps:
- name: Code checkout
uses: actions/checkout@v3
- name: Miniconda setup
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
add-pip-as-python-dependency: false # conda-lock goes crazy if pip pre-installed
activate-environment: env1
mamba-version: "*"
channels: "umccr,conda-forge,bioconda"
- name: 🐍 Conda pkg build and upload
run: |
conda activate
mamba create --name cbuildenv conda-build conda-verify anaconda-client boa dvc dvc-gdrive
conda activate cbuildenv
dvc pull
ls -l inst/extdata/*
conda mambabuild --R 4.1 ${recipe_path} --token ${atoken}
- name: 🔒 Conda lock
run: |
conda activate
mamba create --name lockenv conda-lock pip
conda activate lockenv
conda-lock --file ${env_yaml_path}/sigrap.yaml --platform linux-64
mv conda-lock.yml ${env_lock_path}/conda-lock.yml
- name: 💾 Commit lockfile
run: |
# TODO: the version bumping guarantees there will be changes,
# but during testing this can be problematic - need to
# commit only if changes exist.
git status
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
MSG="[bot] Updating conda-lock file (v${VERSION})"
git add .
git commit -m "${MSG}"
git push
- name: 🌐 Website publish
run: |
conda activate
mamba env create -n pkgdownenv -f ${env_yaml_path}/pkgdown.yaml
conda activate pkgdownenv
sigrap.R --version
Rscript -e "pkgdown::deploy_to_branch(pkg = '.', commit_message = paste(pkgdown:::construct_commit_message('.'), '- see https://umccr.github.io/sigrap/'), branch = 'gh-pages', new_process = FALSE)"
- name: 📥 Pull lock commit
id: pull_lock_commit
run: |
git pull --no-rebase
git --no-pager log --decorate=short --pretty=oneline -n3
LATEST_COMMIT_HASH="$(git --no-pager log -1 --format='%H')"
echo "::set-output name=latest_commit_hash::${LATEST_COMMIT_HASH}"
- name: 🔖 Create tag
uses: actions/github-script@v5
env:
LATEST_COMMIT_HASH: ${{ steps.pull_lock_commit.outputs.latest_commit_hash }}
with:
script: |
const the_tag_name = 'refs/tags/v' + process.env.VERSION
const the_sha = process.env.LATEST_COMMIT_HASH
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: the_tag_name,
sha: the_sha
})
# work with tag from above
- name: Code checkout
uses: actions/checkout@v3
with:
ref: v${{ env.VERSION }}
- name: 🏰 QEMU setup
uses: docker/setup-qemu-action@v2
- name: 🏯 Buildx setup
uses: docker/setup-buildx-action@v2
with:
install: true
config-inline: |
[worker.oci]
max-parallelism = 2
- name: 🐙 GitHub CR login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🐳 Docker img build and push
uses: docker/build-push-action@v2
with:
tags: ghcr.io/${{ github.repository }}:${{ env.VERSION }}
context: . # yes, dot
push: true
platforms: linux/amd64
48 changes: 0 additions & 48 deletions .github/workflows/pkgdown.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
/docs
/nogit
README.html
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:20.04
LABEL maintainer="https://github.com/pdiakumis"

ARG MINI_VERSION=4.12.0-0
ARG MINI_URL=https://github.com/conda-forge/miniforge/releases/download/${MINI_VERSION}/Mambaforge-${MINI_VERSION}-Linux-x86_64.sh
ARG MAMBA_PREFIX="/opt/mambaforge"

# install core pkgs, mambaforge
RUN apt-get update -qq && \
apt-get install --yes --no-install-recommends -qq \
git bash bzip2 curl ca-certificates && \
apt-get clean && \
rm -r /var/lib/apt/lists/* && \
rm -r /var/cache/apt/* && \
curl --silent -L "${MINI_URL}" -o "mambaforge.sh" && \
/bin/bash mambaforge.sh -b -p "${MAMBA_PREFIX}" && \
rm mambaforge.sh

# create conda env
ENV PATH="${MAMBA_PREFIX}/bin:$PATH"
ARG ENV_DIR=/home/sigrap_conda_env
ARG ENV_NAME="sigrap_env"
COPY ./conda/env/lock ${ENV_DIR}
RUN conda config --set always_yes yes && \
mamba install -c conda-forge conda-lock==1.0.5
RUN conda-lock install --name ${ENV_NAME} ${ENV_DIR}/conda-lock.yml && \
mamba clean --all --force-pkgs-dirs

ENV PATH="${MAMBA_PREFIX}/envs/${ENV_NAME}/bin:${PATH}"
ENV CONDA_PREFIX="${MAMBA_PREFIX}/envs/${ENV_NAME}"

CMD [ "sigrap.R" ]
21 changes: 13 additions & 8 deletions R/hrdetect.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ hrdetect_read_purple_cnv <- function(x) {
#' (l <- hrdetect_prep_snvindel(x, nm = "sampleA"))
#' @testexamples
#' expect_equal(c("snv_results", "indel_results"), names(l))
#' expect_equal(c("sig", "exposure", "pvalue"), colnames(l[["snv_results"]]))
#' expect_equal(c("sig", "exposure"), colnames(l[["snv_results"]]))
#' expect_equal(colnames(l[["indel_results"]])[c(1, 7)], c("sample", "del.mh.prop"))
#'
#' @export
Expand All @@ -169,10 +169,12 @@ hrdetect_prep_snvindel <- function(x, nm = NULL, genome = "hg38",
subs = snvindel_tabs[["snv"]],
genome.v = genome
)[["catalogue"]]
assertthat::assert_that(inherits(snv_catalogue, "data.frame"),
ncol(snv_catalogue) == 1,
colnames(snv_catalogue) == "catalogue",
nrow(snv_catalogue) == 96)
assertthat::assert_that(
inherits(snv_catalogue, "data.frame"),
ncol(snv_catalogue) == 1,
colnames(snv_catalogue) == "catalogue",
nrow(snv_catalogue) == 96
)

subs_fit_res <- signature.tools.lib::Fit(
catalogues = snv_catalogue,
Expand All @@ -184,7 +186,8 @@ hrdetect_prep_snvindel <- function(x, nm = NULL, genome = "hg38",

assertthat::assert_that(
length(subs_fit_res) == 16,
"exposures" %in% names(subs_fit_res))
"exposures" %in% names(subs_fit_res)
)

snv_exp <- subs_fit_res[["exposures"]] |>
t() |>
Expand Down Expand Up @@ -305,8 +308,10 @@ hrdetect_run <- function(nm, snvindel_vcf, sv_vcf, cnv_tsv, genome = "hg38",
genome <- "hg19"
}

snvindel <- hrdetect_prep_snvindel(x = snvindel_vcf, nm = nm,
genome = genome, sigsToUse = sigsToUse)
snvindel <- hrdetect_prep_snvindel(
x = snvindel_vcf, nm = nm,
genome = genome, sigsToUse = sigsToUse
)
snv <- snvindel[["snv_results"]] |>
dplyr::filter(.data$sig %in% c("Signature3", "Signature8")) |>
tidyr::pivot_wider(
Expand Down
6 changes: 3 additions & 3 deletions R/mutationalpatterns.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ sig_workflow_run <- function(vcf, sample_nm, ref_genome = "hg38", outdir) {
}
}

cli::cli_h2(glue::glue("{date_log()} Start of MutationalPatterns workflow"))
cli::cli_h2(glue::glue("{gpgr::date_log()} Start of MutationalPatterns workflow"))
# import VCF
gr <- MutationalPatterns::read_vcfs_as_granges(
vcf_files = vcf,
Expand Down Expand Up @@ -355,7 +355,7 @@ sig_workflow_run <- function(vcf, sample_nm, ref_genome = "hg38", outdir) {
}() |>
sigrap::sig_contribution_table(type = "ID")

cli::cli_h2(glue::glue("{date_log()} Saving MutationalPatterns results to\n'{outdir}'"))
cli::cli_h2(glue::glue("{gpgr::date_log()} Saving MutationalPatterns results to\n'{outdir}'"))
save_plot_list(p_snv, file.path(outdir, "plot/snv"))
save_plot_list(p_dbs, file.path(outdir, "plot/dbs"))
save_plot_list(p_indel, file.path(outdir, "plot/indel"))
Expand All @@ -364,5 +364,5 @@ sig_workflow_run <- function(vcf, sample_nm, ref_genome = "hg38", outdir) {
gpgr::write_jsongz(x = sigs_dbs, path = file.path(outdir, "sigs/dbs.json.gz"))
gpgr::write_jsongz(x = sigs_indel, path = file.path(outdir, "sigs/indel.json.gz"))

cli::cli_h2(glue::glue("{date_log()} End of MutationalPatterns workflow"))
cli::cli_h2(glue::glue("{gpgr::date_log()} End of MutationalPatterns workflow"))
}
Loading

0 comments on commit f66d557

Please sign in to comment.