Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: R CI
on:
push:
branches: [main, master, develop, test, fix/45-fix_ci_yaml]
pull_request:
branches: [main, master, develop, test, 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 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 }}
34 changes: 31 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
language: r
sudo: false
cache: packages

r_github_packages:
- r-lib/covr
branches:
only:
- main
- master
- develop
- test

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
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 <xiaoli@broadinstitute.org>
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
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ S3method(flagSamples,sampleDataset)
S3method(getAttr,sampleDataset)
S3method(inferAncestry,default)
S3method(inferAncestry,sampleDataset)
S3method(outlierPlots,default)
S3method(outlierPlots,sampleDataset)
S3method(print,sampleDataset)
S3method(sampleQcPlot,default)
S3method(sampleQcPlot,sampleDataset)
S3method(save,sampleDataset)
S3method(setAttr,sampleDataset)
S3method(sort,sampleDataset)
export(GeomSplitViolin)
export(PCplots)
export(calZscore)
export(flagSamples)
export(geom_split_violin)
export(getAttr)
export(hasAttr)
export(inferAncestry)
export(multiplot)
export(multiplotWithSharedLegend)
export(outlierPlots)
export(runQcExplorer)
export(sampleDataset)
export(sampleQcPlot)
export(save)
export(scatter)
export(setAttr)
importFrom(ggplot2,Geom)
18 changes: 13 additions & 5 deletions R/S3Method.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#' Save an sds to a specific format
#'
#' Save an sds to tsv, RDS or excel format
#' @description Save an sds to tsv, RDS or excel format
#'
#' @param sds
#' @param sds sample dataset
#' @param ... Additional arguments to be passed.
#'
#' @export
#' @seealso{\link{sort.sampleDataset}}
#' @seealso{\link{save.sampleDataset}}
#' @seealso{\link{dim.sampleDataset}}
#' @seealso{\link{print.sampleDataset}}

save <-function(sds, ...) UseMethod('save')

Expand Down Expand Up @@ -36,7 +41,7 @@ save.sampleDataset <- function(sds, RDS = NULL, tsv = NULL, xls = NULL) {
#'
#' @param sds sample dataset
#' @param by sort by which category
#' @return an sample dataset sds with updated index
#' @return A sample dataset `sds` with updated index.
#'
#' @export

Expand All @@ -49,15 +54,18 @@ sort.sampleDataset <- function(sds, by) {

#' Show dimensions of sample dataset sds
#'
#' @param sds sample data set sds
#' @param sds Sample dataset `sds`.
#' @return a vector of rows and columns of the data frame of sample data set
#'
#' @export

dim.sampleDataset <- function(sds){
dim(sds$df)
}

#' Print information about the sample dataset `sds`.
#'
#' @param sds Sample dataset `sds`.
#'
#' @export
print.sampleDataset <- function(sds) {
cat("\nClass: SampleDataset\n",
Expand Down
35 changes: 20 additions & 15 deletions R/calZscore.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#' Calculate z-score of a vector or QC metrics of a SampleDataset
#'
#' @description Calculate z-score of a vector or QC metrics of a SampleDataset,
#' see details in calZscore.default and calZscore.sampleDataset
#' @return 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.
#'
#' @param ... Additional arguments to be passed.
#'
#' @return
#' 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.
#'
#' @export
#' @seealso{\link{calZscore.default}}
#' @seealso{\link{calZscore.sampleDataset}}

calZscore <- function(...) UseMethod("calZscore")

Expand All @@ -14,7 +21,7 @@ calZscore <- function(...) UseMethod("calZscore")
#' @description Calculate z-scores of a vector
#' @param x a vector of values or a sample dataset object
#' @param mad binary, whether use Median Absolute Deviation to calculate the
#' standard deviation
#' standard deviation.Default is TRUE.
#' @return a vector of z-scores
#' @export

Expand All @@ -30,15 +37,13 @@ calZscore.default <- function(x, mad = T) {

#' Calculate z-scores of QC metrics of a SampleDataset
#'
#' @param object a sampleDataset object
#' @param strat optional, logical, variable or vector of attributes the sample
#' will be stratified by
#' @param mad optional, binary, whether use Median Absolute Deviation to
#' calculate z-score or not, default is True
#' @param qcMetrics optional, a vector of names of qc metrics to compute zscore
#' @param maxVcfZ optional, logical, calculate to report maximun Vcf Zscore
#' @return sampleDataset object, with additional attributes: zscoreBy, zscore
#' and maximumVcfZscore
#' @param object a sampleDataset object.
#' @param strat optional, logical, variable, or vector of attributes the sample
#' will be stratified by.
#' @param qcMetrics optional, a vector of names of QC metrics to compute z-score.
#' @param mad optional, binary, whether to use Median Absolute Deviation to
#' calculate z-score or not, default is TRUE.
#' @param maxVcfZ optional, logical, calculate to report maximum Vcf Z-score.
#' @export

calZscore.sampleDataset <- function (
Expand Down
6 changes: 6 additions & 0 deletions R/flagSamples.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#'
#' Flag a sample from a data frame or a sampleDataset
#' @export
#' @seealso{\link{flagSamples.default}}
#' @seealso{\link{flagSamples.sampleDataset}}

flagSamples <- function(...) UseMethod('flagSamples')

Expand All @@ -21,6 +23,8 @@ flagSamples <- function(...) UseMethod('flagSamples')
#'
#' @return Return a data frame
#' @export
#' @seealso{\link{flagSamples}}
#' @seealso{\link{flagSamples.sampleDataset}}

flagSamples.default <- function (df, column, cutoff, greater) {
column = as.character(column)
Expand Down Expand Up @@ -55,6 +59,8 @@ flagSamples.default <- function (df, column, cutoff, greater) {
#' based on z-score if not specified. Default value is NULL.
#' @return an updated sample dataset sds with flags added.
#' @export
#' @seealso{\link{flagSamples.default}}
#' @seealso{\link{flagSamples}}

flagSamples.sampleDataset <- function(sds, cutoffs, zscore = NULL){
# conditions
Expand Down
13 changes: 9 additions & 4 deletions R/getAttr.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#' Get attributes of an sds
#'
#' @param sds sample dataset sds
#' @param sds sample dataset
#' @param attribute name of attribute to return
#' @param showID whether to display sample IDs or not in the output data frame
#'
#' @return a data frame that contains values of specific attribute
#' @export
#'
#' @seealso{\link{getAttr.sampleDataset}}

getAttr <- function (sds, ...) UseMethod('getAttr', sds)

#' Get attributes of a SampleDataset
#'
#' @param sds sample data set
#' @param attribute name of attribute to return
#' @param showID whether to display sample IDs or not in the output data fram
#' @param return a data frame that contains values of specific attribute
#' @param showID whether to display sample IDs or not in the output data frame
#'
#' @return data frame
#' @return a data frame that contains values of specific attribute
#' @export

getAttr.sampleDataset <- function(sds, attribute, showID = F) {
Expand Down
34 changes: 24 additions & 10 deletions R/inferAncestry.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#' Predict sample ancestry from genotype Principle Components
#'
#' Principle Components of genotypes with k nearest neighbours.
#' @return Updated sample Dataset sds with inferredAncestry tag
#'
#' @param ... Additional parameters for future expansion.
#' @return Updated sample Dataset sds with inferredAncestry tag.
#' @export
#'
#' @seealso{\link{inferAncestry.sampleDataset}}
#' @seealso{\link{inferAncestry.default}}

inferAncestry <- function(...) UseMethod('inferAncestry')

#' Infer anestry with KNN
#' Infer ancestry with KNN
#'
#' @param testSet Matrix used for test.
#' @param trainSet Matrix for training PCs.
#' @param ancestry Ancestries corresponding to the training PCs.
#' @param k Number of nearest neighbors to use in this classification.
#'
#' @param testSet matrix used for test
#' @param trainSet matrix for training PCs
#' @param ancestry ancestries correspond to the training PCs
#' @param k Number of nearest neighbour to use in this classfication
#' @return A vector of inferred ancestries.
#' @export
#'
#' @seealso{\link{inferAncestry.sampleDataset}}
#' @seealso{\link{inferAncestry}}

inferAncestry.default <- function(testSet, trainSet, ancestry, k = 5) {
inferredAncestry = class::knn(train = trainSet, test = testSet, cl = ancestry, k = k)
Expand All @@ -21,12 +31,16 @@ inferAncestry.default <- function(testSet, trainSet, ancestry, k = 5) {

#' Infer sample ancestry
#'
#' @param sds Sample Dataset sds for Ancestry predition
#' @param trainSet data frame with genotype PCs for each sample with known ancestry
#' @param knownAncestry a vector with known ancestry for each sample in same order of trainSet
#' @param nPC Use first n PCs to predict ancestry
#' @param sds Sample Dataset sds for ancestry prediction.
#' @param trainSet Data frame with genotype PCs for each sample with known ancestry.
#' @param knownAncestry A vector with known ancestry for each sample in the same order as trainSet.
#' @param nPC Use the first n PCs to predict ancestry.
#'
#' @return Updated sample Dataset sds with inferredAncestry tag.
#' @export
#'
#' @seealso{\link{inferAncestry}}
#' @seealso{\link{inferAncestry.default}}

inferAncestry.sampleDataset <- function(
sds, trainSet, knownAncestry, nPC = 3, k = 5
Expand Down
Loading