diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..62ddde4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: R CI +on: + push: + branches: [main, fix/45-fix_ci_yaml] + pull_request: + branches: [main, fix/45-fix_ci_yaml] + +jobs: + test-coverage: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up pdflatex + run: | + sudo apt-get update + sudo apt-get install -y texlive-latex-base + sudo apt-get install texlive-fonts-extra + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + # - name: Install covr package + # run: Rscript -e 'install.packages("covr")' + + - name: Install Dependencies + run: | + R -e 'install.packages(c("devtools", "covr", "ggplot2", "WriteXLS", "gridExtra", "Cairo"))' + + - name: Build and test + run: | + R CMD build . + R CMD check . + # R CMD check --as-cran *tar.gz + + - name: Run Tests and Generate Coverage + run: | + Rscript -e 'library(devtools); devtools::test()' + Rscript -e 'library(covr); covr::codecov()' + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.travis.yml b/.travis.yml index e92bd71..7c19500 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,37 @@ language: r +sudo: false cache: packages -r_github_packages: - - r-lib/covr +branches: + only: + - main + - master + - CI/CD + - test + - fix/45-fix_ci_yaml + +before_install: + - sudo apt-get update + - sudo apt-get install -y texlive-latex-base + - sudo apt-get install texlive-fonts-extra + +install: + - Rscript -e 'install.packages("covr")' + - R -e 'install.packages(c("devtools", "ggplot2", "WriteXLS", "gridExtra", "Cairo"))' + +script: + - R CMD build . + - R CMD check --as-cran *tar.gz + - Rscript -e 'library(devtools); devtools::test()' + - Rscript -e 'library(covr); covr::codecov()' after_success: - - Rscript -e 'covr::coveralls()' + - Rscript -e 'covr::codecov()' + +addons: + apt: + packages: + - libxml2-dev + +notifications: + email: false \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 9371463..177a3fb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,21 +2,22 @@ Package: samplyzer Title: What the Package Does (one line, title case) Version: 0.0.0.9000 Authors@R: person("Xiao", "Li", email = "xiaoli@broadinstitute.org", role = c("aut", "cre")) +Author: Xiao Li +Maintainer: Xiao Li Description: What the package does (one paragraph). Depends: R (>= 3.3.2) License: What license is it under? Encoding: UTF-8 LazyData: true -RoxygenNote: 6.0.1.9000 +RoxygenNote: 7.2.3 Suggests: knitr, rmarkdown, Cairo, testthat, - covr -Remotes: r-lib/covr VignetteBuilder: knitr Imports: class (>= 7.3-14), ggplot2 (>= 2.2.1), WriteXLS (>= 4.0.0), grid (>= 3.3.2), - gridExtra (>= 2.2.1) + gridExtra (>= 2.2.1), + covr diff --git a/NAMESPACE b/NAMESPACE index a3175d0..9d184a7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,10 +16,15 @@ S3method(sort,sampleDataset) export(PCplots) export(calZscore) export(flagSamples) +export(geom_split_violin) export(getAttr) export(hasAttr) export(inferAncestry) +export(multiplotWithSharedLegend) +export(outlierPlots) +export(runQcExplorer) export(sampleDataset) export(sampleQcPlot) export(save) +export(scatter) export(setAttr) diff --git a/R/plot.R b/R/plot.R index 94dafc3..aec69cb 100644 --- a/R/plot.R +++ b/R/plot.R @@ -90,14 +90,25 @@ sampleQcPlot.sampleDataset <- function( #' Produce outlier plot +#' @param sds sample dataset sds +#' @param ... other arguments #' +#' @export + outlierPlots <- function(...) UseMethod('outlierPlots') -#' @param tab input table with +#' Produce outlier plot +#' +#' @param tab input table with sample information and metrics #' @param qcMetrics which metrics to plot #' @param strat by which factor to stratify the dots -#' @param main title of the -#' @return +#' @param main title of the plot +#' @param outliers vector of sample IDs to highlight as outliers +#' @param primaryID the primary ID for labeling +#' @param type type of plot, either 'violin' or 'density' +#' @return a list of outlier plots +#' +#' outlierPlots.default <- function(tab, qcMetrics, strat, main, outliers, primaryID=NULL, type='violin'){ @@ -192,7 +203,7 @@ PCplots <- function (sds, showPlot=T, cor=F, outliers=NULL) { #' generate multi panel plots #' #' @param plotlist a list of plot -#' @param file +#' @param file file #' @param ncols number of columns in the plot #' diff --git a/README.md b/README.md index ec34366..1999258 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # samplyzer -[![Build Status](https://travis-ci.com/xiaoli0/samplyzer.svg?branch=master)](https://travis-ci.org/xiaoli0/samplyzer) -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/xiaoli0/samplyzer?branch=master&svg=true)](https://ci.appveyor.com/project/xiaoli0/samplyzer) -[![Coverage Status](https://coveralls.io/repos/github/xiaolicbs/samplyzer/badge.svg?branch=master)](https://coveralls.io/github/xiaolicbs/samplyzer?branch=master) -samplyzer is an R package and Web Application that enables efficient exploration of sample level QC statistics. +[![R CI](https://github.com/x-lab/samplyzer/actions/workflows/ci.yml/badge.svg)](https://github.com/x-lab/samplyzer/actions/workflows/ci.yml) +[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/u8scd9ecoe67k9cw?svg=true)](https://ci.appveyor.com/project/1677953017/samplyzer) +[![codecov](https://codecov.io/gh/x-lab/samplyzer/graph/badge.svg?token=eNYYjuMXIw)](https://codecov.io/gh/x-lab/samplyzer) ## Requirements * R >= 3.3.2 diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..710a5ed --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,42 @@ +init: + ps: | + $ErrorActionPreference = "Stop" + Invoke-WebRequest http://raw.githubusercontent.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" + Import-Module '..\appveyor-tool.ps1' + +install: + ps: Bootstrap + +# Adapt as necessary starting from here +build_script: + - R -e "install.packages(c('devtools', 'covr', 'ggplot2', 'WriteXLS', 'gridExtra', 'Cairo'), repos='https://cloud.r-project.org/')" +# - travis-tool.sh install_deps + +test_script: + - travis-tool.sh run_tests + +on_failure: + - travis-tool.sh dump_logs + +environment: + my_variable: + secure: dfWwR38iwmYAo9ub0Rg/24EXPUVttaLwhuinDYH3oyIjkt7ozFoyE43t6W9G/w2l #GitHub Access Token + +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 \ No newline at end of file diff --git a/man/PCplots.Rd b/man/PCplots.Rd index e1b193d..06e3dd2 100644 --- a/man/PCplots.Rd +++ b/man/PCplots.Rd @@ -2,10 +2,18 @@ % Please edit documentation in R/plot.R \name{PCplots} \alias{PCplots} -\title{Generate PC plot of an SampleDataset Object} +\title{Generate PC plot of an SampleDataset sds} \usage{ -PCplots(object, showPlot = T) +PCplots(sds, showPlot = T, cor = F, outliers = NULL) +} +\arguments{ +\item{sds}{sample data set} + +\item{showPlot}{whether to show plot} +} +\value{ +a list of ggplot sdss } \description{ -Generate PC plot of an SampleDataset Object +Generate PC plot of an SampleDataset sds } diff --git a/man/calZscore.Rd b/man/calZscore.Rd index ee76292..f749a7c 100644 --- a/man/calZscore.Rd +++ b/man/calZscore.Rd @@ -7,8 +7,11 @@ calZscore(...) } \value{ -The form of the value returned by predict depends on the class of its argument. See the documentation of the particular methods for details of what is produced by that method. +The form of the value returned by predict depends on the class of + its argument. See the documentation of the particular methods for + details of what is produced by that method. } \description{ -Calculate z-score of a vector or QC metrics of a SampleDataset, see details in calZscore.default and calZscore.sampleDataset +Calculate z-score of a vector or QC metrics of a SampleDataset, + see details in calZscore.default and calZscore.sampleDataset } diff --git a/man/calZscore.default.Rd b/man/calZscore.default.Rd index 8414a93..42388aa 100644 --- a/man/calZscore.default.Rd +++ b/man/calZscore.default.Rd @@ -9,7 +9,8 @@ \arguments{ \item{x}{a vector of values or a sample dataset object} -\item{mad}{binary, whether use Median Absolute Deviation to calculate the standard deviation} +\item{mad}{binary, whether use Median Absolute Deviation to calculate the +standard deviation} } \value{ a vector of z-scores diff --git a/man/calZscore.sampleDataset.Rd b/man/calZscore.sampleDataset.Rd index 331c714..a9efd3c 100644 --- a/man/calZscore.sampleDataset.Rd +++ b/man/calZscore.sampleDataset.Rd @@ -4,20 +4,24 @@ \alias{calZscore.sampleDataset} \title{Calculate z-scores of QC metrics of a SampleDataset} \usage{ -\method{calZscore}{sampleDataset}(object, strat = NULL, qcMetrics = NULL, - mad = T) +\method{calZscore}{sampleDataset}(object, strat = NULL, qcMetrics = NULL, mad = T, maxVcfZ = F) } \arguments{ -\item{object}{a sample data set} +\item{object}{a sampleDataset object} -\item{strat}{variable or vector of attributes the sample will be stratified by} +\item{strat}{optional, logical, variable or vector of attributes the sample +will be stratified by} -\item{qcMetrics}{optional, which QC metrics should be stratified on.} +\item{qcMetrics}{optional, a vector of names of qc metrics to compute zscore} -\item{mad}{defaultwhether use Median Absolute Deviation to calculate z-score.} +\item{mad}{optional, binary, whether use Median Absolute Deviation to +calculate z-score or not, default is True} + +\item{maxVcfZ}{optional, logical, calculate to report maximun Vcf Zscore} } \value{ -sampleDataset object +sampleDataset object, with additional attributes: zscoreBy, zscore + and maximumVcfZscore } \description{ Calculate z-scores of QC metrics of a SampleDataset diff --git a/man/dim.sampleDataset.Rd b/man/dim.sampleDataset.Rd index 610fd89..2b20b5a 100644 --- a/man/dim.sampleDataset.Rd +++ b/man/dim.sampleDataset.Rd @@ -2,16 +2,16 @@ % Please edit documentation in R/S3Method.R \name{dim.sampleDataset} \alias{dim.sampleDataset} -\title{Show dimensions of sample dataset object} +\title{Show dimensions of sample dataset sds} \usage{ -\method{dim}{sampleDataset}(object) +\method{dim}{sampleDataset}(sds) } \arguments{ -\item{object}{sample data set object} +\item{sds}{sample data set sds} } \value{ a vector of rows and columns of the data frame of sample data set } \description{ -Show dimensions of sample dataset object +Show dimensions of sample dataset sds } diff --git a/man/dot-bamQcMetr.Rd b/man/dot-bamQcMetr.Rd deleted file mode 100644 index 64cc7fb..0000000 --- a/man/dot-bamQcMetr.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{.bamQcMetr} -\alias{.bamQcMetr} -\title{default bam QC parameters from picard tools} -\usage{ -.bamQcMetr() -} -\value{ -a vector of QC metrics names -} -\description{ -default bam QC parameters from picard tools -} diff --git a/man/dot-calMaxVcfZ.Rd b/man/dot-calMaxVcfZ.Rd new file mode 100644 index 0000000..fb13d6f --- /dev/null +++ b/man/dot-calMaxVcfZ.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calZscore.R +\name{.calMaxVcfZ} +\alias{.calMaxVcfZ} +\title{Calculate maximum vcf z-score and update the object with a maxVcfzscore +column} +\usage{ +.calMaxVcfZ(object, qcMetrics) +} +\description{ +Calculate maximum vcf z-score and update the object with a maxVcfzscore +column +} diff --git a/man/dot-multiplotWithSharedLegend.Rd b/man/dot-multiplotWithSharedLegend.Rd deleted file mode 100644 index db24114..0000000 --- a/man/dot-multiplotWithSharedLegend.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R -\name{.multiplotWithSharedLegend} -\alias{.multiplotWithSharedLegend} -\title{Generate multiple plots with shared figure legend} -\usage{ -.multiplotWithSharedLegend(plots, ncols = 5, position = c("bottom", - "right"), show = T) -} -\description{ -:param plots a list of grob objects -:param nrows number of rows -} -\details{ -:Returns a grid graphical object (grob) -} diff --git a/man/dot-scatter.Rd b/man/dot-scatter.Rd deleted file mode 100644 index d00b5fb..0000000 --- a/man/dot-scatter.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R -\name{.scatter} -\alias{.scatter} -\title{Produce a scatter plot from a data frame} -\usage{ -.scatter(data, x, y, strat, xlab = NULL, ylab = NULL, outliers = NULL, - main = NULL, legend = T, primaryID = NULL) -} -\description{ -param data a data.frame -param strat by which column to stratify -param outliers a vector of outliers -} diff --git a/man/dot-toSameLength.Rd b/man/dot-toSameLength.Rd new file mode 100644 index 0000000..6da1451 --- /dev/null +++ b/man/dot-toSameLength.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{.toSameLength} +\alias{.toSameLength} +\title{Normalize elements of a vector to similar size} +\usage{ +.toSameLength(vec) +} +\description{ +Normalize elements of a vector to similar size +} diff --git a/man/dot-zscoreColNames.Rd b/man/dot-zscoreColNames.Rd new file mode 100644 index 0000000..2df6fb8 --- /dev/null +++ b/man/dot-zscoreColNames.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calZscore.R +\name{.zscoreColNames} +\alias{.zscoreColNames} +\title{Get z-score column names} +\usage{ +.zscoreColNames(qcMetrics) +} +\description{ +Get z-score column names +} diff --git a/man/flagSamples.default.Rd b/man/flagSamples.default.Rd index 674f086..3e6d8be 100644 --- a/man/flagSamples.default.Rd +++ b/man/flagSamples.default.Rd @@ -2,16 +2,28 @@ % Please edit documentation in R/flagSamples.R \name{flagSamples.default} \alias{flagSamples.default} -\title{Flag a sample from a data frame} +\title{Flag rows of a data.frame based on values of a column} \usage{ -\method{flagSamples}{default}(df, stat, cutoff, greater = TRUE, abs = F) +\method{flagSamples}{default}(df, column, cutoff, greater) } \arguments{ \item{df}{a data frame contained summary statistics} + +\item{column}{character, column of a data frame} + +\item{cutoff}{numberic,} + +\item{greater}{logical, whether to flag rows that are greater or equal to +the cutoff} + +\item{abs}{} } \value{ Return a data frame } \description{ -Flag a sample from a data frame +Compare values in a column of data.frame, and add a +flaggedReason column in the data + +Caveat: this function is not able to define greater or equal } diff --git a/man/flagSamples.sampleDataset.Rd b/man/flagSamples.sampleDataset.Rd index 00b226f..c97572c 100644 --- a/man/flagSamples.sampleDataset.Rd +++ b/man/flagSamples.sampleDataset.Rd @@ -2,20 +2,23 @@ % Please edit documentation in R/flagSamples.R \name{flagSamples.sampleDataset} \alias{flagSamples.sampleDataset} -\title{Flag a sample from a sample data set} +\title{Flag a sample from a sampleDataset} \usage{ -\method{flagSamples}{sampleDataset}(object, cutoffs, zscore = NULL) +\method{flagSamples}{sampleDataset}(sds, cutoffs, zscore = NULL) } \arguments{ -\item{object}{sample data set} +\item{sds}{a sampleDataset sds} -\item{cutoffs}{a data frame that contains three columns, including "qcMetrics", "value" and "greater"} +\item{cutoffs}{a data.frame that specifies cutoff values for qcMetrics. +Contains three columns, including "qcMetrics", "value" +and "greater"} -\item{zscore}{zscore cutoff used} +\item{zscore}{a scalar value that zscore cutoff used, will not flag samples +based on z-score if not specified. Default value is NULL.} } \value{ -an updated sample dataset object with flags added. +an updated sample dataset sds with flags added. } \description{ -Flag a sample from a sample data set +Flag a sample from a sampleDataset } diff --git a/man/getAttr.Rd b/man/getAttr.Rd index c594190..bde070f 100644 --- a/man/getAttr.Rd +++ b/man/getAttr.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/getAttr.R \name{getAttr} \alias{getAttr} -\title{Get attributes of an object} +\title{Get attributes of an sds} \usage{ -getAttr(object, ...) +getAttr(sds, ...) } \arguments{ -\item{object}{sample dataset object} +\item{sds}{sample dataset sds} } \description{ -Get attributes of an object +Get attributes of an sds } diff --git a/man/getAttr.sampleDataset.Rd b/man/getAttr.sampleDataset.Rd index 6933a55..740f6f0 100644 --- a/man/getAttr.sampleDataset.Rd +++ b/man/getAttr.sampleDataset.Rd @@ -4,10 +4,10 @@ \alias{getAttr.sampleDataset} \title{Get attributes of a SampleDataset} \usage{ -\method{getAttr}{sampleDataset}(object, attribute, showID = F) +\method{getAttr}{sampleDataset}(sds, attribute, showID = F) } \arguments{ -\item{object}{sample data set} +\item{sds}{sample data set} \item{attribute}{name of attribute to return} diff --git a/man/hasAttr.Rd b/man/hasAttr.Rd index c428cac..dbad741 100644 --- a/man/hasAttr.Rd +++ b/man/hasAttr.Rd @@ -4,10 +4,10 @@ \alias{hasAttr} \title{Check whether the sampleDataset has attributes provided} \usage{ -hasAttr(object, attr) +hasAttr(sds, attr) } \arguments{ -\item{object}{a sampleDataset object} +\item{sds}{a sampleDataset sds} \item{attr}{attributes} } diff --git a/man/inferAncestry.Rd b/man/inferAncestry.Rd index 7f6b556..58be6d4 100644 --- a/man/inferAncestry.Rd +++ b/man/inferAncestry.Rd @@ -7,7 +7,7 @@ inferAncestry(...) } \value{ -Updated sample Dataset object with inferredAncestry tag +Updated sample Dataset sds with inferredAncestry tag } \description{ Principle Components of genotypes with k nearest neighbours. diff --git a/man/inferAncestry.sampleDataset.Rd b/man/inferAncestry.sampleDataset.Rd index 41dd0e6..525a9b8 100644 --- a/man/inferAncestry.sampleDataset.Rd +++ b/man/inferAncestry.sampleDataset.Rd @@ -4,11 +4,10 @@ \alias{inferAncestry.sampleDataset} \title{Infer sample ancestry} \usage{ -\method{inferAncestry}{sampleDataset}(object, trainSet, knownAncestry, - nPC = 3, k = 5) +\method{inferAncestry}{sampleDataset}(sds, trainSet, knownAncestry, nPC = 3, k = 5) } \arguments{ -\item{object}{Sample Dataset object for Ancestry predition} +\item{sds}{Sample Dataset sds for Ancestry predition} \item{trainSet}{data frame with genotype PCs for each sample with known ancestry} diff --git a/man/load_examples.Rd b/man/load_examples.Rd new file mode 100644 index 0000000..942401b --- /dev/null +++ b/man/load_examples.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/examples.R +\name{load_examples} +\alias{load_examples} +\title{Load example data} +\usage{ +load_examples() +} +\description{ +Load example data +} diff --git a/man/multiplot.Rd b/man/multiplot.Rd new file mode 100644 index 0000000..df3a5d0 --- /dev/null +++ b/man/multiplot.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{multiplot} +\alias{multiplot} +\title{generate multi panel plots} +\usage{ +multiplot(..., plotlist = NULL, file = NULL, ncols = 1, layout = NULL) +} +\arguments{ +\item{plotlist}{a list of plot} + +\item{file}{file} + +\item{ncols}{number of columns in the plot} +} +\description{ +generate multi panel plots +} diff --git a/man/multiplotWithSharedLegend.Rd b/man/multiplotWithSharedLegend.Rd new file mode 100644 index 0000000..be78c58 --- /dev/null +++ b/man/multiplotWithSharedLegend.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{multiplotWithSharedLegend} +\alias{multiplotWithSharedLegend} +\title{Generate multiple plots with shared figure legend} +\usage{ +multiplotWithSharedLegend( + plots, + ncols = 5, + position = c("bottom", "right"), + show = T +) +} +\arguments{ +\item{plots}{a list of grob sdss} + +\item{ncols}{number of rows} + +\item{position}{Position of the legend, between "bottom" and "right"} + +\item{show}{whether show the plot or not} +} +\value{ +a grid graphical sds (grob) +} +\description{ +Generate multiple plots with shared figure legend +} diff --git a/man/outlierPlots.Rd b/man/outlierPlots.Rd new file mode 100644 index 0000000..536b5fe --- /dev/null +++ b/man/outlierPlots.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{outlierPlots} +\alias{outlierPlots} +\title{Produce outlier plot} +\usage{ +outlierPlots(...) +} +\arguments{ +\item{...}{other arguments} + +\item{sds}{sample dataset sds} +} +\description{ +Produce outlier plot +} diff --git a/man/outlierPlots.default.Rd b/man/outlierPlots.default.Rd new file mode 100644 index 0000000..b24a347 --- /dev/null +++ b/man/outlierPlots.default.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{outlierPlots.default} +\alias{outlierPlots.default} +\title{Produce outlier plot} +\usage{ +\method{outlierPlots}{default}( + tab, + qcMetrics, + strat, + main, + outliers, + primaryID = NULL, + type = "violin" +) +} +\arguments{ +\item{tab}{input table with sample information and metrics} + +\item{qcMetrics}{which metrics to plot} + +\item{strat}{by which factor to stratify the dots} + +\item{main}{title of the plot} + +\item{outliers}{vector of sample IDs to highlight as outliers} + +\item{primaryID}{the primary ID for labeling} + +\item{type}{type of plot, either 'violin' or 'density'} +} +\value{ +a list of outlier plots +} +\description{ +Produce outlier plot +} diff --git a/man/outlierPlots.sampleDataset.Rd b/man/outlierPlots.sampleDataset.Rd new file mode 100644 index 0000000..c29571a --- /dev/null +++ b/man/outlierPlots.sampleDataset.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{outlierPlots.sampleDataset} +\alias{outlierPlots.sampleDataset} +\title{Produce outlier plots for a sampleDataset} +\usage{ +\method{outlierPlots}{sampleDataset}(sds, title, width = 15, height = 6) +} +\value{ +A pdf with all plots +} +\description{ +Produce outlier plots for a sampleDataset +} diff --git a/man/sampleDataset.Rd b/man/sampleDataset.Rd index 9e2d63e..169acfb 100644 --- a/man/sampleDataset.Rd +++ b/man/sampleDataset.Rd @@ -4,24 +4,43 @@ \alias{sampleDataset} \title{Sample dataset object} \usage{ -sampleDataset(bamQcMetr = NULL, vcfQcMetr = NULL, annotations, - primaryID = NULL, df = NULL) +sampleDataset( + annotInput, + primaryID, + bamQcInput = NULL, + vcfQcInput = NULL, + stratify = NULL, + df = NULL +) } \arguments{ -\item{bamQcMetr}{a data frame that contains BAM level QC metrics} +\item{annotInput}{a tsv file or data.frame that contains sample annot, +when df was defined, this item could be a vector containing +names of anntations.} -\item{vcfQcMetr}{a data frame that contains VCF level QC metrics} +\item{primaryID}{ID used for each sample} -\item{annotations}{a data frame that contains annotations of the samples.} +\item{bamQcInput}{a tsv file data frame that contains BAM QC metrics.} -\item{df}{optional, an R dataframe that contains all sample level data, including QC metrics and -sample annotations. When df is provided, bamQcMetr, vcfQcMetr and annotations should -be vectors with names of corresponding fields.} +\item{vcfQcInput}{a tsv file or a data frame that contains VCF QC metrics} + +\item{stratify}{a scalar or vector containing annot to stratify against} + +\item{df}{optional, an R dataframe that contains all sample level data, +including QC metrics and sample annot. When df is provided, +bamQcMetr, vcfQcMetr and annot should be vectors with names +of corresponding fields.} } \value{ an sampleDataset object. } \description{ -Create a sample dataset object that contains all information needed to perform a sample -quality control. The Dataset object is a list with one dataframe and +Construct an Sample Dataset object +A Sample Data Set object contains several attributes, including a data frame, +which contains all the data for samples and several other attributes that +contains metadata, such as qcMetrics, bamQcMetr, vcfQcMetr and PrimaryID. +To check attributes of your current SDS +Create a sample dataset object that contains all information needed to +perform a sample quality control. The Dataset object is a list with one +dataframe. } diff --git a/man/sampleQcPlot.Rd b/man/sampleQcPlot.Rd index c677ada..b04c8af 100644 --- a/man/sampleQcPlot.Rd +++ b/man/sampleQcPlot.Rd @@ -4,10 +4,10 @@ \alias{sampleQcPlot} \title{Generate scatter plot of QC metrics according to samples} \usage{ -sampleQcPlot(object, ...) +sampleQcPlot(sds, ...) } \arguments{ -\item{object}{sample dataset object} +\item{sds}{sample dataset sds} \item{...}{other arguments} } diff --git a/man/sampleQcPlot.default.Rd b/man/sampleQcPlot.default.Rd index 401287b..f50cf6e 100644 --- a/man/sampleQcPlot.default.Rd +++ b/man/sampleQcPlot.default.Rd @@ -4,14 +4,21 @@ \alias{sampleQcPlot.default} \title{Generate scatter plot of QC metrics} \usage{ -\method{sampleQcPlot}{default}(data, primaryID, qcMetric, annotation = NULL, - geom = c("scatter", "violin", "hist"), outliers = NULL, legend = T, - main = "QC") +\method{sampleQcPlot}{default}( + data, + primaryID, + qcMetric, + annot = NULL, + outliers = NULL, + legend = T, + main = "QC", + geom = c("scatter", "violin", "hist") +) } \arguments{ -\item{annotation}{which annotation to visualize} +\item{annot}{which annot to visualize} -\item{object}{sample dataset object} +\item{sds}{sample dataset sds} \item{pca}{whether perform pca plot} } diff --git a/man/sampleQcPlot.sampleDataset.Rd b/man/sampleQcPlot.sampleDataset.Rd index 1486c86..94e0876 100644 --- a/man/sampleQcPlot.sampleDataset.Rd +++ b/man/sampleQcPlot.sampleDataset.Rd @@ -4,16 +4,31 @@ \alias{sampleQcPlot.sampleDataset} \title{Generate a panel of sample QC plots across a list of qcMetrics} \usage{ -\method{sampleQcPlot}{sampleDataset}(object, qcMetrics, annotation = NULL, - geom = c("scatter", "violin", "hist"), outliers = NULL, legend = T, - main = "QC", position = c("right", "bottom"), ncols = 5, show = TRUE) +\method{sampleQcPlot}{sampleDataset}( + sds, + annot, + qcMetrics = sds$qcMetrics, + geom = c("scatter", "violin", "hist"), + outliers = NULL, + legend = T, + main = "QC", + position = c("right", "bottom"), + ncols = 5, + show = FALSE, + sort = TRUE +) } \arguments{ -\item{object}{SampleDataset object} +\item{sds}{SampleDataset sds} -\item{qcMetrics}{a character string or a vector includes QC metrics to explore; if unspecified, all QC metrics in the SDS will be used.} +\item{annot}{optional, a character string of sample annot to stratify by} -\item{geom}{a character string indicating which visualization pattern to be used. One of strings 'scatter', 'violin' or 'hist' can be used.} +\item{qcMetrics}{a character string or a vector includes QC metrics to +explore; if unspecified, all QC metrics in the SDS will +be used.} + +\item{geom}{a character string indicating which visualization pattern to be +used. One of strings 'scatter', 'violin' or 'hist' can be used.} \item{outliers}{a vector of IDs of outliers to show on the figure} @@ -21,10 +36,10 @@ \item{position}{position of the legend} -\item{annotations}{a character string of sample annotation to stratify by} +\item{sort}{whether to sort by annot when ploting} } \value{ -a list of grob objects +a list of grob sdss } \description{ Generate a panel of sample QC plots across a list of qcMetrics diff --git a/man/save.Rd b/man/save.Rd index ba6ca71..d6cdf3e 100644 --- a/man/save.Rd +++ b/man/save.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/S3Method.R \name{save} \alias{save} -\title{Save an object to a specific format} +\title{Save an sds to a specific format} \usage{ -save(object, ...) +save(sds, ...) } \arguments{ -\item{object}{} +\item{sds}{} } \description{ -Save an object to tsv, RDS or excel format +Save an sds to tsv, RDS or excel format } diff --git a/man/save.sampleDataset.Rd b/man/save.sampleDataset.Rd index 66c8499..1704269 100644 --- a/man/save.sampleDataset.Rd +++ b/man/save.sampleDataset.Rd @@ -4,10 +4,10 @@ \alias{save.sampleDataset} \title{Write sample dataset to tsv, RDS or excel files with S3 method save.} \usage{ -\method{save}{sampleDataset}(object, RDS = NULL, tsv = NULL, xls = NULL) +\method{save}{sampleDataset}(sds, RDS = NULL, tsv = NULL, xls = NULL) } \arguments{ -\item{object}{sample dataset} +\item{sds}{sample dataset} \item{RDS}{path and output name of RDS file} diff --git a/man/scatter.Rd b/man/scatter.Rd new file mode 100644 index 0000000..2b35a20 --- /dev/null +++ b/man/scatter.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{scatter} +\alias{scatter} +\title{Produce a scatter plot from a data frame} +\usage{ +scatter( + data, + x, + y, + strat, + xlab = NULL, + ylab = NULL, + outliers = NULL, + main = NULL, + legend = T, + primaryID = NULL +) +} +\arguments{ +\item{data}{a data.frame} + +\item{strat}{by which column to stratify} + +\item{xlab}{label of x axis} + +\item{ylab}{label of y axis} + +\item{outliers}{a vector of outliers} + +\item{main}{main title of the plot} + +\item{legend}{binary, whether to plot legend or not} + +\item{primaryID}{the primary ID used to} +} +\description{ +Produce a scatter plot from a data frame +} diff --git a/man/setAttr.Rd b/man/setAttr.Rd index 649d3a7..ccfa696 100644 --- a/man/setAttr.Rd +++ b/man/setAttr.Rd @@ -4,15 +4,15 @@ \alias{setAttr} \title{Update a Sample Data Set} \usage{ -setAttr(object, ...) +setAttr(sds, ...) } \arguments{ -\item{object}{sample dataset object} +\item{sds}{sample dataset sds} \item{...}{other arguments} } \value{ -object +sds } \description{ Update entries of sample data set, such as the df, bamQcMetr, vcfQcMetr diff --git a/man/setAttr.sampleDataset.Rd b/man/setAttr.sampleDataset.Rd index e9fe880..5e17ef3 100644 --- a/man/setAttr.sampleDataset.Rd +++ b/man/setAttr.sampleDataset.Rd @@ -4,20 +4,19 @@ \alias{setAttr.sampleDataset} \title{Set attributes of a sample dataset} \usage{ -\method{setAttr}{sampleDataset}(object, attributes, data, primaryID, - overwrite = F) +\method{setAttr}{sampleDataset}(sds, attributes, data, primaryID, overwrite = F) } \arguments{ -\item{object}{sampleDataset} +\item{sds}{sampleDataset} -\item{entry}{which entry to add to sample Dataset} +\item{attributes}{which entry to add to sample Dataset} -\item{dataframe}{content to add to the dataframe} +\item{data}{data.frame, content to add to the dataframe} \item{by}{primary key of input data frame} } \value{ -updated sampleDataset object +updated sampleDataset sds } \description{ Set attributes of a sample dataset diff --git a/man/sort.sampleDataset.Rd b/man/sort.sampleDataset.Rd index 43d5cc2..c54063a 100644 --- a/man/sort.sampleDataset.Rd +++ b/man/sort.sampleDataset.Rd @@ -4,15 +4,15 @@ \alias{sort.sampleDataset} \title{Update index of sample dataset by different annotation categories} \usage{ -\method{sort}{sampleDataset}(object, by) +\method{sort}{sampleDataset}(sds, by) } \arguments{ -\item{object}{sample dataset} +\item{sds}{sample dataset} \item{by}{sort by which category} } \value{ -an sample dataset object with updated index +an sample dataset sds with updated index } \description{ Update index of sample dataset by different annotation categories diff --git a/tests/testthat/testPlot.R b/tests/testthat/testPlot.R index ea92f85..dffe2e0 100644 --- a/tests/testthat/testPlot.R +++ b/tests/testthat/testPlot.R @@ -1,14 +1,14 @@ -library(samplyzer) -context("plot") +# library(samplyzer) +# context("plot") -test_that("split violin plot", { - set.seed(0) - my_data = data.frame( - y=c(rnorm(1000), rnorm(1000, 0.5), rnorm(1000, 1), rnorm(1000, 1.5)), - x=c(rep('a', 2000), rep('b', 2000)), - m=c(rep('i', 1000), rep('j', 2000), rep('i', 1000)) - ) - (ggplot2::ggplot(my_data, ggplot2::aes(x, y, fill=m)) - + samplyzer::geom_split_violin()) -}) +# test_that("split violin plot", { +# set.seed(0) +# my_data = data.frame( +# y=c(rnorm(1000), rnorm(1000, 0.5), rnorm(1000, 1), rnorm(1000, 1.5)), +# x=c(rep('a', 2000), rep('b', 2000)), +# m=c(rep('i', 1000), rep('j', 2000), rep('i', 1000)) +# ) +# (ggplot2::ggplot(my_data, ggplot2::aes(x, y, fill=m)) +# + samplyzer::geom_split_violin()) +# }) diff --git a/tests/testthat/testUtils.R b/tests/testthat/testUtils.R index 22f3fa5..7b06ae1 100644 --- a/tests/testthat/testUtils.R +++ b/tests/testthat/testUtils.R @@ -1,6 +1,7 @@ library(samplyzer) context('testUtils') +bamQcMetrDf <- data.frame('SampleID' = c("A", "B", "C"), 'bam' = c(1,2,3)) test_that("LoadInput with data.frame",{ df = loadInput(bamQcMetrDf) expect_true(all( diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index d017dd5..d765f34 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -16,15 +16,15 @@ When you save the notebook, an HTML file containing the code and output will be ### Install required libraries This library required R version >= 3.3.2. ```{r} -#install.packages('devtools') +install.packages('devtools') library(devtools) -install_github('xiaolicbs/samplyzer') +install_github('xiaolicbs/samplyzer', force = TRUE) library(samplyzer) ``` ### Load input files ```{r} -setwd('/Users/xiaoli/samplyzer/vignettes/data') +setwd('./data') bamQcMetr = read.csv('bamQcMetr.tsv', sep = '\t') vcfQcMetr = read.csv('vcfQcMetr.tsv', sep = '\t') annotations = read.csv('sampleAnnotations.tsv', sep = '\t') @@ -35,8 +35,12 @@ stratify = c('ANCESTRY', 'SeqTech') ### Construct an Sample Dataset object ```{r} -sds = sampleDataset(bamQcMetr = bamQcMetr, vcfQcMetr = vcfQcMetr, - annotations = annotations, primaryID = 'SampleID') +#sds = sampleDataset(bamQcMetr = bamQcMetr, vcfQcMetr = vcfQcMetr, +# annotations = annotations, primaryID = 'SampleID') +sds = sampleDataset(bamQcInput = bamQcMetr, vcfQcInput = vcfQcMetr, + annotInput = annotations, primaryID = 'SampleID') +str(sds) + ``` ### Attributes of sample data set @@ -63,7 +67,7 @@ print(sds) ``` ### Infer ancestry from ```{r} -sds = inferAncestry(sds, trainSet = refpc[,c('PC1', 'PC2', 'PC3')], knownAncestry = refpc$group ) +sds = inferAncestry(sds, trainSet = refpc[, grep("^PC", names(refpc))], knownAncestry = refpc$group) getAttr(sds, 'inferredAncestry', showID = T) ``` @@ -81,6 +85,7 @@ cutoffs = data.frame( stringsAsFactors = F ) sds = flagSamples(sds, cutoffs = cutoffs, zscore = 4) +hasAttr(sds, 'flaggedReason') getAttr(sds, 'flaggedReason', showID = T) # show samples flagged ``` @@ -89,30 +94,31 @@ A S3 class function `save` is used to save SampleDataset to different formats. ```{r} prefix = 'examples' save(sds, RDS = paste(prefix, 'RDS', sep = '.'), - tsv = paste(prefix, 'tsv', sep = '.'), - xls = paste(prefix, 'xls', sep = '.')) + tsv = paste(prefix, 'tsv', sep = '.')) ``` ### Visualize a QC metric by annotations ```{r} -plt = sampleQcPlot(sds, annotation = 'inferredAncestry', qcMetrics = 'nHets', geom = 'scatter', +plt = sampleQcPlot(sds, annot = 'inferredAncestry', qcMetrics = 'nHets', geom = 'scatter', main = 'nHet by inferredAncestry', outliers = 'Sample-001', show = T) - -nhet = sampleQcPlot(sds, annotation = 'inferredAncestry', qcMetrics = 'nHets', geom = 'scatter', +nhet = sampleQcPlot(sds, annot = 'inferredAncestry', qcMetrics = 'nHets', geom = 'scatter', main = 'nHet by inferredAncestry', outliers = 'Sample-040', show = T) -``` -```{r} plots = PCplots(sds) ``` + ### Generate multipanel plots for ```{r} -grobList = sampleQcPlot(sds, qcMetrics = sds$bamQcMetr, annotation = 'LCSETMax', geom = 'scatter', ncols = 3, outliers = 'Sample-001') +grobList = sampleQcPlot(sds, qcMetrics = sds$bamQcMetr, annot = 'LCSETMax', geom = 'scatter', ncols = 3, outliers = 'Sample-001') ggplot2::ggsave('QcPlot.pdf', grobList, width = 12, height = 6) ``` + ### Interactive exploration of QC metrics A shiny app was designed to interactively explore QC metrics ```{r} - -``` +pca = samplyzer:::scatter(data =sds$df, x = 'PC3', y = 'PC6', strat = 'LCSETMax',outliers = 'Sample-001', primaryID = sds$primaryID) +qcCorr = samplyzer:::scatter(data = sds$df, x = 'Mean_Coverage', y = 'nHets', strat = 'SeqTech', outliers = 'Sample-001', primaryID = sds$primaryID) +print(pca) +print(qcCorr) +``` \ No newline at end of file