Skip to content

Commit

Permalink
Merge pull request #10 from umccr/gha-test
Browse files Browse the repository at this point in the history
Dependency update to R v4.3
  • Loading branch information
pdiakumis authored Dec 15, 2024
2 parents 9a5b4dc + 6d39b47 commit 49cb0ca
Show file tree
Hide file tree
Showing 28 changed files with 798 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
^\.bumpversion\.cfg$
^\.bumpversion\.toml$
^data-raw$
^docs$
^LICENSE\.md$
Expand Down
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.1.2.1"
current_version = "0.1.2.5"
search = "{current_version}"
replace = "{new_version}"
message = "Bump version: {current_version} → {new_version}"
Expand Down
48 changes: 19 additions & 29 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
push:
branches:
- main
- gha-test
env:
atoken: ${{ secrets.ANACONDA_UPLOAD_TOKEN }}
recipe_path: conda/recipe
env_yaml_path: conda/env/yaml
env_lock_path: conda/env/lock
VERSION: '0.1.2.1' # versioned by bump2version
VERSION: '0.1.2.5' # versioned by bump2version
GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }}

jobs:
Expand All @@ -25,47 +26,36 @@ jobs:
steps:
- name: Code checkout
uses: actions/checkout@v4
- name: Miniconda setup
uses: conda-incubator/setup-miniconda@v2
- name: MicroMamba setup
uses: mamba-org/setup-micromamba@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"
environment-file: ${{ env.env_yaml_path }}/condabuild.yaml
- name: 🐍 Conda pkg build and upload
run: |
conda activate
mamba create --name cbuildenv conda-build conda-verify anaconda-client boa
conda activate cbuildenv
conda mambabuild --R 4.2 ${recipe_path} --token ${atoken}
conda mambabuild ${recipe_path} -c umccr -c conda-forge -c bioconda --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
# 1. generate a combined lock file
# 2. render platform-specific locks
conda-lock lock --file ${env_yaml_path}/sigrap.yaml -p osx-64 -p linux-64
conda-lock render --kind explicit -p osx-64 -p linux-64 conda-lock.yml --filename-template 'sigrap-{platform}.lock' && rm conda-lock.yml
mv sigrap-*.lock ${env_lock_path}/
- 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 "actions@github.com"
git config --local user.name "GitHub Actions"
MSG="[bot] Updating conda-lock file (v${VERSION})"
MSG="[bot] Updating conda-lock files (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: 🌐 Website publish
# run: |
# micromamba env create -n pkgdownenv -f ${env_yaml_path}/pkgdown.yaml
# micromamba 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
Expand All @@ -75,7 +65,7 @@ jobs:
LATEST_COMMIT_HASH="$(git --no-pager log -1 --format='%H')"
echo "latest_commit_hash=${LATEST_COMMIT_HASH}" >> $GITHUB_OUTPUT
- name: 🔖 Create tag
uses: actions/github-script@v6
uses: actions/github-script@v7
env:
LATEST_COMMIT_HASH: ${{ steps.pull_lock_commit.outputs.latest_commit_hash }}
with:
Expand Down
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sigrap
Title: Wrappers for somatic mutation signature analysis tools
Version: 0.1.2.1
Version: 0.1.2.5
Description: Wraps functionality from somatic signature analysis tools.
Authors@R:
person(given = "Peter",
Expand All @@ -14,7 +14,6 @@ License: MIT + file LICENSE
Depends:
R (>= 4.1)
Remotes:
umccr/gpgr,
umccr/signature.tools.lib,
UMCUGenetics/CHORD
Imports:
Expand All @@ -23,8 +22,9 @@ Imports:
cli,
CHORD,
dplyr,
fs,
ggplot2,
gpgr (>= 1.0.0),
jsonlite,
MutationalPatterns,
readr,
rlang,
Expand Down Expand Up @@ -55,5 +55,4 @@ ByteCompile: true
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
VignetteBuilder: knitr
RoxygenNote: 7.3.1
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(chord_mantavcf2df)
export(chord_run)
export(date_log)
export(get_genome_obj)
export(hrdetect_prep_cnv)
export(hrdetect_prep_snvindel)
Expand All @@ -10,6 +11,7 @@ export(hrdetect_read_purple_cnv)
export(hrdetect_read_snvindel_vcf)
export(hrdetect_read_sv_vcf)
export(hrdetect_run)
export(pkg_exists)
export(sig_contribution)
export(sig_contribution_table)
export(sig_count_dbs)
Expand All @@ -19,5 +21,6 @@ export(sig_plot_dbs)
export(sig_plot_indel)
export(sig_plot_snv)
export(sig_workflow_run)
export(write_jsongz)
importFrom(rlang,":=")
importFrom(rlang,.data)
20 changes: 6 additions & 14 deletions R/chord.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' <https://github.com/UMCUGenetics/CHORD/blob/d7c963/R/extractSigsChord.R>.
#'
#' @examples
#'
#' \dontrun{
#' snv <- system.file("extdata/umccrise/snv/somatic-ensemble-PASS.vcf.gz", package = "gpgr")
#' sv <- system.file("extdata/umccrise/sv/manta.vcf.gz", package = "gpgr")
#' chord_res <- chord_run(
Expand All @@ -25,13 +25,7 @@
#' )
#' # chord_res2 <- chord_run(vcf.snv = snv, vcf.sv = sv, sample.name = "foo",
#' # outpath = "nogit/chord_results.json.gz")
#' @testexamples
#'
#' expect_equal(length(chord_res), 2)
#' expect_equal(names(chord_res), c("contexts", "prediction"))
#' expect_equal(chord_res[["prediction"]][, 1, drop = TRUE], "foo")
#'
#'
#' }
#' @return List with extracted signatures and HRD prediction.
#'
#' @export
Expand Down Expand Up @@ -75,7 +69,7 @@ chord_run <- function(vcf.snv = NULL, vcf.sv = NULL, df.sv = NULL,

# write json.gz to file
if (!is.null(outpath)) {
gpgr::write_jsongz(x = prediction, path = outpath)
write_jsongz(x = prediction, path = outpath)
}

list(
Expand All @@ -93,12 +87,10 @@ chord_run <- function(vcf.snv = NULL, vcf.sv = NULL, df.sv = NULL,
#' @return Tibble with two columns: sv_type and sv_len (INFO/SVTYPE and INFO/SVLEN from VCF).
#'
#' @examples
#' \dontrun{
#' in_vcf <- system.file("extdata/umccrise/sv/manta.vcf.gz", package = "gpgr")
#' d <- chord_mantavcf2df(in_vcf)
#' @testexamples
#' expect_equal(d$sv_len[1], "-108")
#' expect_equal(d$sv_type[1], "DEL")
#'
#' }
#' @export
chord_mantavcf2df <- function(in_vcf) {
assertthat::assert_that(file.exists(in_vcf))
Expand Down Expand Up @@ -140,7 +132,7 @@ get_genome_obj <- function(genome = "hg38") {
"{paste(names(bsgenome), collapse = ', ')}"
)
)
if (!gpgr::pkg_exists(pkg)) {
if (!pkg_exists(pkg)) {
stop(glue::glue(
"{pkg} is not installed on your system.\n",
"Please install with:\n'BiocManager::install(\"{pkg}\")'"
Expand Down
48 changes: 15 additions & 33 deletions R/hrdetect.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
#' for SNVs and INDELs in separate tibbles.
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/umccrise/snv/somatic-ensemble-PASS.vcf.gz", package = "gpgr")
#' (l <- hrdetect_read_snvindel_vcf(x))
#' @testexamples
#' expect_equal(length(l), 2)
#' expect_equal(names(l), c("snv", "indel"))
#' expect_equal(colnames(l$snv), c("chr", "position", "REF", "ALT"))
#' expect_equal(colnames(l$indel), c("chr", "position", "REF", "ALT"))
#'
#' }
#' @export
hrdetect_read_snvindel_vcf <- function(x) {
assertthat::assert_that(file.exists(x))
Expand Down Expand Up @@ -61,13 +57,11 @@ hrdetect_read_snvindel_vcf <- function(x) {
#'
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/umccrise/sv/manta.vcf.gz", package = "gpgr")
#' sv_bedpe <- hrdetect_read_sv_vcf(x, nm = "SAMPLE")
#' head(sv_bedpe)
#' @testexamples
#' expect_equal(nrow(sv_bedpe), 190)
#' expect_equal(colnames(sv_bedpe), c("chrom1", "start1", "end1", "chrom2",
#' "start2", "end2", "sample", "strand1", "strand2"))
#' }
#' @export
hrdetect_read_sv_vcf <- function(x, nm = NULL, genome = "hg38") {
assertthat::assert_that(file.exists(x))
Expand Down Expand Up @@ -103,13 +97,10 @@ hrdetect_read_sv_vcf <- function(x, nm = NULL, genome = "hg38") {
#' - minorAllelePloidy
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/purple/purple.cnv.somatic.tsv", package = "gpgr")
#' (cnv <- hrdetect_read_purple_cnv(x))
#' @testexamples
#' expect_equal(colnames(cnv), c("Chromosome", "chromStart", "chromEnd",
#' "total.copy.number.inTumour",
#' "minor.copy.number.inTumour"))
#'
#' }
#' @export
hrdetect_read_purple_cnv <- function(x) {
assertthat::assert_that(file.exists(x))
Expand Down Expand Up @@ -143,12 +134,10 @@ hrdetect_read_purple_cnv <- function(x) {
#' - indel_results: tibble with a summary of the count of indels and their proportion.
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/umccrise/snv/somatic-ensemble-PASS.vcf.gz", package = "gpgr")
#' (l <- hrdetect_prep_snvindel(x, nm = "sampleA"))
#' @testexamples
#' expect_equal(c("snv_results", "indel_results"), names(l))
#' expect_equal(c("sig", "exposure"), colnames(l[["snv_results"]]))
#' expect_equal(colnames(l[["indel_results"]])[c(1, 7)], c("sample", "del.mh.prop"))
#' }
#'
#' @export
hrdetect_prep_snvindel <- function(x, nm = NULL, genome = "hg38",
Expand Down Expand Up @@ -219,13 +208,11 @@ hrdetect_prep_snvindel <- function(x, nm = NULL, genome = "hg38",
#' @return Single-column data.frame (with rownames) with counts for each SV category.
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/umccrise/sv/manta.vcf.gz", package = "gpgr")
#' nm <- "SampleA"
#' (d <- hrdetect_prep_sv(x, nm))
#' @testexamples
#' expect_equal(colnames(d), nm)
#' expect_true(inherits(d, "data.frame"))
#'
#' }
#' @export
hrdetect_prep_sv <- function(x, nm = NULL, genome = "hg38") {
assertthat::assert_that(file.exists(x))
Expand All @@ -248,12 +235,10 @@ hrdetect_prep_sv <- function(x, nm = NULL, genome = "hg38") {
#' @return Tibble with sample name and HRD-LOH index.
#'
#' @examples
#' \dontrun{
#' x <- system.file("extdata/purple/purple.cnv.somatic.tsv", package = "gpgr")
#' (l <- hrdetect_prep_cnv(x, nm = "SampleA"))
#' @testexamples
#' expect_equal(colnames(l), c("name", "hrdloh_index"))
#' expect_equal(nrow(l), 1)
#'
#' }
#' @export
hrdetect_prep_cnv <- function(x, nm = NULL) {
assertthat::assert_that(file.exists(x))
Expand Down Expand Up @@ -283,6 +268,7 @@ hrdetect_prep_cnv <- function(x, nm = NULL) {
#' @return Tibble with sample name and HRD probability in first two columns.
#'
#' @examples
#' \dontrun{
#' snvindel_vcf <- system.file(
#' "extdata/umccrise/snv/somatic-ensemble-PASS.vcf.gz",
#' package = "gpgr"
Expand All @@ -294,11 +280,7 @@ hrdetect_prep_cnv <- function(x, nm = NULL) {
#' (res <- hrdetect_run(nm, snvindel_vcf, sv_vcf, cnv_tsv, genome))
#' # hrdetect_run(nm, snvindel_vcf, sv_vcf, cnv_tsv, genome,
#' # outpath = "nogit/hrdetect_results.json.gz")
#' @testexamples
#' expect_equal(colnames(res), c("sample", "Probability", "intercept", "del.mh.prop", "SNV3",
#' "SV3", "SV5", "hrdloh_index", "SNV8"))
#' expect_true(inherits(res, "data.frame"))
#'
#' }
#' @export
hrdetect_run <- function(nm, snvindel_vcf, sv_vcf, cnv_tsv, genome = "hg38",
sigsToUse = c(1, 2, 3, 5, 6, 8, 13, 17, 18, 20, 26, 30),
Expand Down Expand Up @@ -358,7 +340,7 @@ hrdetect_run <- function(nm, snvindel_vcf, sv_vcf, cnv_tsv, genome = "hg38",

# write json.gz to file
if (!is.null(outpath)) {
gpgr::write_jsongz(x = res, path = outpath)
write_jsongz(x = res, path = outpath)
}

res
Expand Down
21 changes: 10 additions & 11 deletions R/mutationalpatterns.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sig_contribution_table <- function(contr, type, outdir = NULL) {
# if an outdir is specified, copy out the COSMIC plots to be linked to
if (!is.null(outdir)) {
img_cp_dir <- file.path(outdir, "sig_plots", type)
gpgr::mkdir(img_cp_dir)
fs::dir_create(img_cp_dir)
sig_table <-
readr::read_tsv(file = file.path(sig_dir, "description.tsv"), col_types = "cc") |>
dplyr::mutate(
Expand Down Expand Up @@ -276,14 +276,14 @@ sig_plot_dbs <- function(dbs_counts) {
#'
#' @export
sig_workflow_run <- function(vcf, sample_nm, ref_genome = "hg38", outdir) {
gpgr::mkdir(outdir)
fs::dir_create(outdir)
outdir <- normalizePath(outdir)
ref_genome <- get_genome_obj(ref_genome)

save_plot_list <- function(pl, outdir) {
assertthat::assert_that(is.list(pl), length(pl) > 0)
assertthat::assert_that(all(sapply(pl, inherits, "ggplot")))
gpgr::mkdir(outdir)
fs::dir_create(outdir)
for (i in seq_len(length(pl))) {
nm <- names(pl)[i]
fn <- file.path(outdir, paste0(nm, ".png"))
Expand All @@ -292,7 +292,7 @@ sig_workflow_run <- function(vcf, sample_nm, ref_genome = "hg38", outdir) {
}
}

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

cli::cli_h2(glue::glue("{gpgr::date_log()} Saving MutationalPatterns results to\n'{outdir}'"))
cli::cli_h2(glue::glue("{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"))
gpgr::write_jsongz(x = sigs_snv_2015, path = file.path(outdir, "sigs/snv2015.json.gz"))
gpgr::write_jsongz(x = sigs_snv_2020, path = file.path(outdir, "sigs/snv2020.json.gz"))
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("{gpgr::date_log()} End of MutationalPatterns workflow"))
write_jsongz(x = sigs_snv_2015, path = file.path(outdir, "sigs/snv2015.json.gz"))
write_jsongz(x = sigs_snv_2020, path = file.path(outdir, "sigs/snv2020.json.gz"))
write_jsongz(x = sigs_dbs, path = file.path(outdir, "sigs/dbs.json.gz"))
write_jsongz(x = sigs_indel, path = file.path(outdir, "sigs/indel.json.gz"))
cli::cli_h2(glue::glue("{date_log()} End of MutationalPatterns workflow"))
}
Loading

0 comments on commit 49cb0ca

Please sign in to comment.