diff --git a/.Rbuildignore b/.Rbuildignore index ada87cc..8642063 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -7,3 +7,4 @@ LICENSE README.rst .travis.yml ^appveyor\.yml$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/ISSUE_TEMPLATE/issue_template.md b/.github/ISSUE_TEMPLATE/issue_template.md new file mode 100644 index 0000000..6e857c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue_template.md @@ -0,0 +1,56 @@ +--- +name: Bug report or feature request +about: Describe a bug you've seen or make a case for a new feature +title: "[BUG] Your bug or feature request" +labels: '' +assignees: '' +--- + +Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on using the appropriate tag(s) including one for this package. + +## Context + +Provide some context for your bug report or feature request. This could be the: + +* link to raw code, example: https://github.com/lcolladotor/osca_LIIGH_UNAM_2020/blob/master/00-template.Rmd#L24-L28 +* link to a commit, example: https://github.com/lcolladotor/osca_LIIGH_UNAM_2020/commit/6aa30b22eda614d932c12997ba611ba582c435d7 +* link to a line of code inside a commit, example: https://github.com/lcolladotor/osca_LIIGH_UNAM_2020/commit/6aa30b22eda614d932c12997ba611ba582c435d7#diff-e265269fe4f17929940e81341b92b116R17 +* link to code from an R package, example: https://github.com/LieberInstitute/spatialLIBD/blob/master/R/run_app.R#L51-L55 + +## Code + +Include the code you ran and comments + +```R +## prompt an error +stop('hola') + +## check the error trace +traceback() +``` + +## Small reproducible example + +If you copy the lines of code that lead to your error, you can then run [`reprex::reprex()`](https://reprex.tidyverse.org/reference/reprex.html) which will create a small website with code you can then easily copy-paste here in a way that will be easy to work with later on. + +```R +## prompt an error +stop('hola') +#> Error in eval(expr, envir, enclos): hola + +## check the error trace +traceback() +#> No traceback available +``` + + +## R session information + +Remember to include your full R session information. + +```R +options(width = 120) +sessioninfo::session_info() +``` + +The output of `sessioninfo::session_info()` includes relevant GitHub installation information and other details that are missed by `sessionInfo()`. diff --git a/.github/workflows/check-bioc.yml b/.github/workflows/check-bioc.yml new file mode 100644 index 0000000..ca4dadf --- /dev/null +++ b/.github/workflows/check-bioc.yml @@ -0,0 +1,271 @@ +## Read more about GitHub actions the features of this GitHub Actions workflow +## at https://lcolladotor.github.io/biocthis/articles/biocthis.html#use_bioc_github_action +## +## For more details, check the biocthis developer notes vignette at +## https://lcolladotor.github.io/biocthis/articles/biocthis_dev_notes.html +## +## You can add this workflow to other packages using: +## > biocthis::use_bioc_github_action() +## +## Using GitHub Actions exposes you to many details about how R packages are +## compiled and installed in several operating system.s +### If you need help, please follow the steps listed at +## https://github.com/r-lib/actions#where-to-find-help +## +## If you found an issue specific to biocthis's GHA workflow, please report it +## with the information that will make it easier for others to help you. +## Thank you! + +## Acronyms: +## * GHA: GitHub Action +## * OS: operating system + +on: + push: + pull_request: + +name: R-CMD-check-bioc + +## These environment variables control whether to run GHA code later on that is +## specific to testthat, covr, and pkgdown. +## +## If you need to clear the cache of packages, update the number inside +## cache-version as discussed at https://github.com/r-lib/actions/issues/86. +## Note that you can always run a GHA test without the cache by using the word +## "/nocache" in the commit message. +env: + has_testthat: 'true' + run_covr: 'true' + run_pkgdown: 'false' + has_RUnit: 'false' + cache-version: 'cache-v1' + +jobs: + build-check: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + container: ${{ matrix.config.cont }} + ## Environment variables unique to this job. + + strategy: + fail-fast: false + matrix: + config: + - { os: ubuntu-latest, r: 'devel', bioc: '3.13', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + - { os: macOS-latest, r: 'devel', bioc: '3.13'} + - { os: windows-latest, r: 'devel', bioc: '3.13'} + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + NOT_CRAN: true + TZ: UTC + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + + ## Set the R library to the directory matching the + ## R packages cache step further below when running on Docker (Linux). + - name: Set R Library home on Linux + if: runner.os == 'Linux' + run: | + mkdir /__w/_temp/Library + echo ".libPaths('/__w/_temp/Library')" > ~/.Rprofile + + ## Most of these steps are the same as the ones in + ## https://github.com/r-lib/actions/blob/master/examples/check-standard.yaml + ## If they update their steps, we will also need to update ours. + - name: Checkout Repository + uses: actions/checkout@v2 + + ## R is already included in the Bioconductor docker images + - name: Setup R from r-lib + if: runner.os != 'Linux' + uses: r-lib/actions/setup-r@master + with: + r-version: ${{ matrix.config.r }} + + ## pandoc is already included in the Bioconductor docker images + - name: Setup pandoc from r-lib + if: runner.os != 'Linux' + uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + shell: Rscript {0} + + - name: Cache R packages + if: "!contains(github.event.head_commit.message, '/nocache') && runner.os != 'Linux'" + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-devel-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-devel- + + - name: Cache R packages on Linux + if: "!contains(github.event.head_commit.message, '/nocache') && runner.os == 'Linux' " + uses: actions/cache@v2 + with: + path: /home/runner/work/_temp/Library + key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-devel-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-devel-r-devel- + + - name: Install Linux system dependencies + if: runner.os == 'Linux' + run: | + sysreqs=$(Rscript -e 'cat("apt-get update -y && apt-get install -y", paste(gsub("apt-get install -y ", "", remotes::system_requirements("ubuntu", "20.04")), collapse = " "))') + echo $sysreqs + sudo -s eval "$sysreqs" + + - name: Install macOS system dependencies + if: matrix.config.os == 'macOS-latest' + run: | + ## Enable installing XML from source if needed + brew install libxml2 + echo "XML_CONFIG=/usr/local/opt/libxml2/bin/xml2-config" >> $GITHUB_ENV + + ## Required to install magick as noted at + ## https://github.com/r-lib/usethis/commit/f1f1e0d10c1ebc75fd4c18fa7e2de4551fd9978f#diff-9bfee71065492f63457918efcd912cf2 + brew install imagemagick@6 + + ## For textshaping, required by ragg, and required by pkgdown + brew install harfbuzz fribidi + + ## For installing usethis's dependency gert + brew install libgit2 + + - name: Install Windows system dependencies + if: runner.os == 'Windows' + run: | + ## Edit below if you have any Windows system dependencies + shell: Rscript {0} + + - name: Install BiocManager + run: | + message(paste('****', Sys.time(), 'installing BiocManager ****')) + remotes::install_cran("BiocManager") + shell: Rscript {0} + + - name: Set BiocVersion + run: | + BiocManager::install(version = "${{ matrix.config.bioc }}", ask = FALSE) + shell: Rscript {0} + + - name: Install dependencies pass 1 + run: | + ## Try installing the package dependencies in steps. First the local + ## dependencies, then any remaining dependencies to avoid the + ## issues described at + ## https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016675.html + ## https://github.com/r-lib/remotes/issues/296 + ## Ideally, all dependencies should get installed in the first pass. + + ## Pass #1 at installing dependencies + message(paste('****', Sys.time(), 'pass number 1 at installing dependencies: local dependencies ****')) + remotes::install_local(dependencies = TRUE, repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE) + continue-on-error: true + shell: Rscript {0} + + - name: Install dependencies pass 2 + run: | + ## Pass #2 at installing dependencies + message(paste('****', Sys.time(), 'pass number 2 at installing dependencies: any remaining dependencies ****')) + remotes::install_local(dependencies = TRUE, repos = BiocManager::repositories(), build_vignettes = TRUE, upgrade = TRUE) + + ## For running the checks + message(paste('****', Sys.time(), 'installing rcmdcheck and BiocCheck ****')) + remotes::install_cran("rcmdcheck") + BiocManager::install("BiocCheck") + shell: Rscript {0} + + - name: Install BiocGenerics + if: env.has_RUnit == 'true' + run: | + ## Install BiocGenerics + BiocManager::install("BiocGenerics") + shell: Rscript {0} + + - name: Install covr + if: github.ref == 'refs/heads/master' && env.run_covr == 'true' && runner.os == 'Linux' + run: | + remotes::install_cran("covr") + shell: Rscript {0} + + - name: Install pkgdown + if: github.ref == 'refs/heads/master' && env.run_pkgdown == 'true' && runner.os == 'Linux' + run: | + remotes::install_github("r-lib/pkgdown") + shell: Rscript {0} + + - name: Session info + run: | + options(width = 100) + pkgs <- installed.packages()[, "Package"] + sessioninfo::session_info(pkgs, include_base = TRUE) + shell: Rscript {0} + + - name: Run CMD check + env: + _R_CHECK_CRAN_INCOMING_: false + run: | + rcmdcheck::rcmdcheck( + args = c("--no-build-vignettes", "--no-manual", "--timings"), + build_args = c("--no-manual", "--no-resave-data"), + error_on = "warning", + check_dir = "check" + ) + shell: Rscript {0} + + ## Might need an to add this to the if: && runner.os == 'Linux' + - name: Reveal testthat details + if: env.has_testthat == 'true' + run: find . -name testthat.Rout -exec cat '{}' ';' + + - name: Run RUnit tests + if: env.has_RUnit == 'true' + run: | + BiocGenerics:::testPackage() + shell: Rscript {0} + + - name: Run BiocCheck + run: | + BiocCheck::BiocCheck( + dir('check', 'tar.gz$', full.names = TRUE), + `quit-with-status` = TRUE, + `no-check-R-ver` = TRUE, + `no-check-bioc-help` = TRUE, + `no-check-pkg-size` = TRUE, + `no-check-file-size` = TRUE + ) + shell: Rscript {0} + + - name: Test coverage + if: github.ref == 'refs/heads/master' && env.run_covr == 'true' && runner.os == 'Linux' + run: | + covr::codecov() + shell: Rscript {0} + + - name: Install package + if: github.ref == 'refs/heads/master' && env.run_pkgdown == 'true' && runner.os == 'Linux' + run: R CMD INSTALL . + + - name: Deploy package + if: github.ref == 'refs/heads/master' && env.run_pkgdown == 'true' && runner.os == 'Linux' + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e "pkgdown::deploy_to_branch(new_process = FALSE)" + shell: bash {0} + ## Note that you need to run pkgdown::deploy_to_branch(new_process = FALSE) + ## at least one locally before this will work. This creates the gh-pages + ## branch (erasing anything you haven't version controlled!) and + ## makes the git history recognizable by pkgdown. + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@master + with: + name: ${{ runner.os }}-biocversion-devel-r-devel-results + path: check diff --git a/.gitignore b/.gitignore index 666300d..f2547ca 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ pmp/.Rhistory pmp/pmp.Rproj .Rproj.user inst/doc +*.Rproj +.Rhistory diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f62b0b5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: r -r: bioc-devel -cache: - packages: true -sudo: required -warnings_are_errors: false -dist: xenial - -addons: - apt: - update: true - sources: - - sourceline: 'ppa:cran/imagemagick' - packages: - - libmagick++-dev - -after_success: - - Rscript -e 'covr::codecov()' diff --git a/R/glog_transformation.R b/R/glog_transformation.R index 4269d8b..b83bacc 100644 --- a/R/glog_transformation.R +++ b/R/glog_transformation.R @@ -112,8 +112,13 @@ glog_omptimise_lambda <- function(upper_lim, df_qc){ glog_plot_optimised_lambda <- function(df, optimised_lambda, classes, qc_label, plot_grid=100){ + df <- check_input_data(df, classes=classes) df_qc <- df[, classes == qc_label] + + offset <- min(assay(df_qc), na.rm=TRUE)#set offset to the minimum QC samples + assay(df_qc) <- assay(df_qc) - offset # set minimum of qc data to 0 + lambda_lim <- c(optimised_lambda, optimised_lambda) + c(-optimised_lambda*0.8, optimised_lambda*0.8) sse_df <- data.frame(lambda=seq(lambda_lim[1], lambda_lim[2], @@ -123,8 +128,8 @@ glog_plot_optimised_lambda <- function(df, optimised_lambda, classes, qc_label, g <- ggplot(data=sse_df, aes_string(x='lambda',y='SSE')) + geom_vline(xintercept=optimised_lambda, color="red") + geom_line(size=1.1) + theme_bw() + - labs (title="Optimisation outup of glog lambda parameter", - caption=paste("lambda=",optimised_lambda, sep="")) + labs (title="glog parameter optimisation", + caption=paste("optimum = ",round(optimised_lambda,2), sep="")) return (g) } @@ -173,8 +178,13 @@ glog_transformation <- function(df, classes, qc_label, lambda=NULL) { } df <- check_input_data(df=df, classes=classes) df_qc <- df[, classes == qc_label] + + # offset for QC samples offset <- min(assay(df_qc), na.rm=TRUE)#set offset to the minimum QC samples + assay(df_qc) <- assay(df_qc) - offset # set minimum of qc data to 0 + assay(df) <- assay(df) - offset # apply qc offset to samples + VF <- rowVars(assay(df_qc), na.rm=TRUE) # variance of all features # Upper limit max var or largest ratio max(var)/min(var) upper_lim <- max(pmax(VF, max(VF) / sort(VF)[sort(VF) > 0][1])) @@ -195,7 +205,7 @@ glog_transformation <- function(df, classes, qc_label, lambda=NULL) { lambda <- 5.0278 * 10^(-9) assay(df) <- glog_rescale_data(assay(df)) } - assay(df) <- assay(df) - min(assay(df), na.rm=TRUE) + # set minimum over all values to 0 assay(df) <- glog(assay(df), 0, lambda) # apply glog meta_data <- metadata(df) diff --git a/R/normalisation.R b/R/normalisation.R index 667ec4c..a82f4c4 100644 --- a/R/normalisation.R +++ b/R/normalisation.R @@ -46,8 +46,18 @@ normalise_to_sum <- function(df, check_df=TRUE) { #' #' @return vector of reference mean values #' @noRd -calculate_ref_mean <- function(df_qc){ - ref_mean <- rowMeans(df_qc, na.rm=TRUE) +calculate_ref_mean <- function(df_qc,ref_method='mean'){ + + if (ref_method=='mean') { + ref_mean <- rowMeans(df_qc, na.rm=TRUE) + } else if (ref_method=='median') { + ref_mean <- rowMedians(df_qc,na.rm=TRUE) + } else { + stop(paste0('Unknown ref_method for calculate_ref_mean: "',ref_method, + '". Valid options are ', + '"mean" or "median".')) + } + names(ref_mean)=rownames(df_qc) return(ref_mean) } @@ -69,9 +79,19 @@ calculate_ref_mean <- function(df_qc){ #' @param ref_mean \code{numeric()} or \code{NULL}, Vector of reference mean #' values to use instead of calculating from QC sample group. If set to #' \code{NULL}, QC sample data will be used. -#' @return Object of class \code{SummarizedExperiment}. If input data are a -#' matrix-like (e.g. an ordinary matrix, a data frame) object, function returns -#' the same R data structure as input with all value of data type +#' @param qc_frac \code{numeric()} A value between 0 and 1 to indicate the +#' minimum proportion of QC samples a feature must be present in for it to be included +#' when computing the reference. Default \code{qc_frac = 0}. +#' @param sample_frac \code{numeric()} A value between 0 and 1 to indicate the +#' minimum proportion of samples a feature must be present in for it to be considered +#' when computing the normalisation coefficients. Default \code{sample_frac = 0}. +#' @param ref_method \code{character()} Method used to compute the reference from +#' the QC samples. Default \code{ref_method = 'mean'}. Allowed +#' values are "mean" or "median". +#' @return Object of class \code{SummarizedExperiment}. If input data are +#' matrix-like (e.g. an ordinary matrix, a data frame) object, the same R data +#' structure as the input will be returned with all values of the data type. +#' #' \code{numeric()}. #' #' @examples @@ -81,34 +101,139 @@ calculate_ref_mean <- function(df_qc){ #' #' @export -pqn_normalisation <- function(df, classes, qc_label, ref_mean=NULL) { +pqn_normalisation <- function(df, classes, qc_label, ref_mean=NULL, qc_frac=0, + sample_frac=0,ref_method='mean') { + + # check df for issues df <- check_input_data(df=df, classes=classes) + + # add some rownames if not present + rm_rownames=FALSE + if (is.null(rownames(assay(df)))) { + rownames(df)=as.character(1:nrow(df)) + rm_rownames=TRUE + } + + # if no reference then create one if (is.null(ref_mean)){ if (qc_label == "all") { + # use all samples ref <- df + ref_class = classes } else { + # use only samples with the provided QC label ref <- df[, classes == qc_label] + ref_class = classes[classes == qc_label] + } + ## apply missing value filter to reference + # only keep features present in qc_frac*100% samples + ref = filter_peaks_by_fraction( + df=ref, + min_frac = qc_frac, + classes = ref_class, + method='across', + qc_label=qc_label, + remove_peaks = TRUE + ) + # check we have some features left + if (nrow(assay(ref))<1) { + stop(paste0('QC filtering was too strict and none of the selected ', + 'reference features survived the filtering. Try reducing the value', + ' of qc_frac.') + ) } - ref_mean <- calculate_ref_mean(df_qc=assay(ref)) + # record the number of reference samples used + n_ref = nrow(assay(ref)) + + # average the reference samples + ref_mean <- calculate_ref_mean(df_qc=assay(ref),ref_method) + } + + # filter the samples before calculating coefficient + df_filt = filter_peaks_by_fraction( + df=df, + min_frac = sample_frac, + classes = classes, + method='across', + qc_label=qc_label, + remove_peaks = TRUE + ) + + # check we have some features left + if (nrow(assay(df_filt))<1) { + stop(paste0('Sample filtering was too strict and none of the', + ' features survived the filtering. Try reducing the ', + 'value of sample_frac.') + ) } - coef <- vector() - for (i in seq_len(dim(df)[2])) { - tempMat <- cbind(ref_mean, assay(df)[, i]) - vecelim <- which(rowAnyMissings(tempMat)) - if (length(vecelim) != 0) { - tempMat <- tempMat[-c(vecelim), , drop=FALSE] + + ## only keep features that survive both filters + U=intersect(rownames(assay(df_filt)),rownames(assay(ref))) + ref_mean=ref_mean[U] + df_filt=df_filt[U,] + + # check we have some features left + if (nrow(assay(df_filt))<1) { + stop(paste0('No features remain after filtering that are common to ', + 'both the reference and the sample matrix. Try again with lower ', + 'values for QC_frac and/or sample_frac.') + ) + } + # record number of features + n_samp=nrow(df_filt) + + ## calculate coefficients + # divide each sample by reference + coef = apply(assay(df_filt),2,function(x) { + return(x / ref_mean) } - coef[i] <- median(as.numeric(tempMat[, 2]/tempMat[, 1]), na.rm=TRUE) + ) + # count number of coefficients per sample + coef_count = apply(coef,2,function(x){ + return(sum(!is.na(x))) + }) + # median coefficient for each sample + coef_med = matrixStats::colMedians(coef,na.rm=TRUE) + # index of coefficient used for normalisation + # (lowest index of, in event of ties) + coef_idx = apply(coef,2,function(x) { + return(which.min(abs(x - median(x,na.rm=TRUE)))[1]) + }) + # name of featured used for scaling + coef_idx_name=rownames(df_filt)[coef_idx] + # convert to matrix + coef_med=matrix(coef_med,nrow=nrow(df),ncol=length(coef_med),byrow = TRUE) + + if (any(is.na(coef_med))) { + warning(paste0('A normlisation coefficient could not be computed for ', + 'one or more samples.')) } - assay(df) <- assay(df)/coef[col(assay(df))] - col_data <- DataFrame(pqn_coef=coef) + + # apply normalisation + assay(df) <- assay(df) / coef_med + col_data <- DataFrame(pqn_coef=coef_med[1,]) colData(df) <- cbind(colData(df), col_data) meta_data <- metadata(df) - meta_data$processing_history$pqn_normalisation <- return_function_args() + meta_data$processing_history$pqn_normalisation <- c( + return_function_args(), + list('reference_feature_count'=n_ref, + 'sample_feature_count'=n_samp, + 'coef_feature_count'=coef_count, + 'coef_idx'=coef_idx, + 'coef_idx_name'=coef_idx_name, + 'computed_ref'=ref_mean + ) + ) metadata(df) <- meta_data df <- return_original_data_structure(df) if (!is(df, "SummarizedExperiment")){ attributes(df)$flags <- as.matrix(col_data) } + + # remove the temporary rownames if we added them earlier + if (rm_rownames) { + rownames(df)=NULL + } + return(df) } diff --git a/README.rst b/README.rst index 2f69bb2..ecda661 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ PMP: Peak Matrix Processing ============================================== -|Git| |Bioconda| |Build Status (Travis)| |Build Status (AppVeyor)| |License| |Coverage| +|Git| |Bioconda| |Build Status| |License| |Coverage| ------------ @@ -35,14 +35,8 @@ References ------------ -.. |Build Status (Travis)| image:: https://img.shields.io/travis/computational-metabolomics/pmp/master.svg?label=Travis - :target: https://travis-ci.com/computational-metabolomics/pmp - -.. |Build Status (AppVeyor)| image:: https://ci.appveyor.com/api/projects/status/github/computational-metabolomics/pmp?branch=master&svg=true - :target: https://ci.appveyor.com/project/computational-metabolomics/pmp - -.. |Build Status (AppVeyor)| image:: https://ci.appveyor.com/api/projects/status/github/computational-metabolomics/pmp?branch=master&svg=true - :target: https://ci.appveyor.com/project/computational-metabolomcis/pmp +.. |Build Status| image:: https://github.com/computational-metabolomics/pmp/workflows/pmp/badge.svg + :target: https://github.com/computational-metabolomics/pmp/actions .. |Git| image:: https://img.shields.io/badge/repository-GitHub-blue.svg?style=flat&maxAge=3600 :target: https://github.com/computational-metabolomics/pmp diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 688ab5c..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,56 +0,0 @@ -# DO NOT CHANGE the "init" and "install" sections below - -# Download script file from GitHub -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' - -install: - ps: Bootstrap - -cache: - #- C:\RLibrary - -environment: - NOT_CRAN: true - # env vars that may need to be set, at least temporarily, from time to time - # see https://github.com/krlmlr/r-appveyor#readme for details - # USE_RTOOLS: true - # R_REMOTES_STANDALONE: true - R_VERSION: release - BIOC_USE_DEVEL: false - USE_RTOOLS: true - PKGTYPE: both - -# Adapt as necessary starting from here - -build_script: - - travis-tool.sh install_deps - -test_script: - - travis-tool.sh run_tests - -on_failure: - - 7z a failure.zip *.Rcheck\* - - appveyor PushArtifact failure.zip - -artifacts: - - path: '*.Rcheck\**\*.log' - name: Logs - - - path: '*.Rcheck\**\*.out' - name: Logs - - - path: '*.Rcheck\**\*.fail' - name: Logs - - - path: '*.Rcheck\**\*.Rout' - name: Logs - - - path: '\*_*.tar.gz' - name: Bits - - - path: '\*_*.zip' - name: Bits diff --git a/man/MTBLS79.Rd b/man/MTBLS79.Rd index 548320e..039affa 100644 --- a/man/MTBLS79.Rd +++ b/man/MTBLS79.Rd @@ -4,7 +4,8 @@ \name{MTBLS79} \alias{MTBLS79} \title{Direct-infusion mass spectrometry (DIMS) data set} -\format{A \link[SummarizedExperiment]{RangedSummarizedExperiment-class} +\format{ +A \link[SummarizedExperiment]{RangedSummarizedExperiment-class} object. \cr \code{assay(MTBLS79)} Peak intensities of the DIMS data set. Contains 172 samples and 2488 features. \cr @@ -13,7 +14,8 @@ Contains 172 samples and 2488 features. \cr \code{Sample_Rep} - \code{character()}, sample replicate code. \cr \code{Class} - \code{character()}, sample class labels. \cr \code{Class2} - \code{character()}, alternative sample class labels - grouping together replicate samples. \cr} + grouping together replicate samples. \cr +} \source{ https://www.ebi.ac.uk/metabolights/MTBLS79 } diff --git a/man/pqn_normalisation.Rd b/man/pqn_normalisation.Rd index 11c0316..9879be5 100644 --- a/man/pqn_normalisation.Rd +++ b/man/pqn_normalisation.Rd @@ -4,7 +4,15 @@ \alias{pqn_normalisation} \title{Probabilistic quotient normalisation (PQN)} \usage{ -pqn_normalisation(df, classes, qc_label, ref_mean = NULL) +pqn_normalisation( + df, + classes, + qc_label, + ref_mean = NULL, + qc_frac = 0, + sample_frac = 0, + ref_method = "mean" +) } \arguments{ \item{df}{A matrix-like (e.g. an ordinary matrix, a data frame) or @@ -23,11 +31,24 @@ identify QC samples.} \item{ref_mean}{\code{numeric()} or \code{NULL}, Vector of reference mean values to use instead of calculating from QC sample group. If set to \code{NULL}, QC sample data will be used.} + +\item{qc_frac}{\code{numeric()} A value between 0 and 1 to indicate the +minimum proportion of QC samples a feature must be present in for it to be included +when computing the reference. Default \code{qc_frac = 0}.} + +\item{sample_frac}{\code{numeric()} A value between 0 and 1 to indicate the +minimum proportion of samples a feature must be present in for it to be considered +when computing the normalisation coefficients. Default \code{sample_frac = 0}.} + +\item{ref_method}{\code{character()} Method used to compute the reference from +the QC samples. Default \code{ref_method = 'mean'}. Allowed +values are "mean" or "median".} } \value{ -Object of class \code{SummarizedExperiment}. If input data are a -matrix-like (e.g. an ordinary matrix, a data frame) object, function returns -the same R data structure as input with all value of data type +Object of class \code{SummarizedExperiment}. If input data are +matrix-like (e.g. an ordinary matrix, a data frame) object, the same R data +structure as the input will be returned with all values of the data type. + \code{numeric()}. } \description{ diff --git a/tests/testthat/test-glog_transformation.R b/tests/testthat/test-glog_transformation.R index fcda385..def809a 100644 --- a/tests/testthat/test-glog_transformation.R +++ b/tests/testthat/test-glog_transformation.R @@ -13,8 +13,12 @@ test_that("Glog function returns expected output", { optimised_lambda <- optimised_lambda$processing_history$glog_transformation$lambda_opt - graph <- glog_plot_optimised_lambda(df=data, optimised_lambda=optimised_lambda, - classes=testData$class, qc_label="QC",) + graph <- glog_plot_optimised_lambda( + df=data, + optimised_lambda=optimised_lambda, + classes=testData$class, + qc_label="QC") + expect_equal(graph[[9]]$x, "lambda") expect_equal(graph[[9]]$y, "SSE") diff --git a/tests/testthat/test-normalisation.R b/tests/testthat/test-normalisation.R index 8babac1..d0586ba 100644 --- a/tests/testthat/test-normalisation.R +++ b/tests/testthat/test-normalisation.R @@ -52,6 +52,32 @@ test_that("PQN normalisation returns correct output when matrix needs to be tran test_that("PQN normalisation doesn't crash if only one feature is selected for normalisation", { out <- matrix(nrow=3, ncol=9) out <- rbind(out, testData$data[1, ]) - out <- pqn_normalisation(df=out, classes=testData$class, qc_label="QC") + expect_warning(out <- pqn_normalisation(df=out, classes=testData$class, qc_label="QC")) expect_true(nrow(out) == 4) }) + + +test_that("PQN computation of reference works as expected for mean and median",{ + out <- pqn_normalisation(df=testData$data, classes=testData$class, + qc_label="QC",ref_method = 'mean') + mean_ref=attributes(out)$processing_history$pqn_normalisation$computed_ref + expect_equal(mean_ref[[1]],106308.238,tolerance = 0.0005) + + out <- pqn_normalisation(df=testData$data, classes=testData$class, + qc_label="QC",ref_method = 'median') + median_ref=attributes(out)$processing_history$pqn_normalisation$computed_ref + expect_equal(median_ref[[1]],88597.333,tolerance = 0.0005) +}) + + +test_that("PQN check reference when appling additional filtering",{ + out <- pqn_normalisation(df=testData$data, classes=testData$class, + qc_label="QC",qc_frac = 1,sample_frac=1,ref_method = 'mean') + mean_ref=attributes(out)$processing_history$pqn_normalisation$computed_ref + expect_equal(mean_ref[[1]],19855.36,tolerance = 0.0005) + + out <- pqn_normalisation(df=testData$data, classes=testData$class, + qc_label="QC",qc_frac = 1,sample_frac=1,ref_method = 'median') + median_ref=attributes(out)$processing_history$pqn_normalisation$computed_ref + expect_equal(median_ref[[1]],10773.31,tolerance = 0.0005) +}) \ No newline at end of file