Skip to content

Commit

Permalink
Merge pull request #78 from DEploid-dev/use_deploid_utils
Browse files Browse the repository at this point in the history
Use deploid utils
  • Loading branch information
shajoezhu authored Dec 20, 2024
2 parents 7cd7a76 + af0427f commit 71873bc
Show file tree
Hide file tree
Showing 30 changed files with 1,084 additions and 1,216 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ src/DEploid/lasso/version
^tests/testthat/Rplots.pdf$
^tests/testthat/.*\.png$
^tests/testthat/.*\.html$
codecov.yml

# vignettes/
^vignettes/commbine.sh
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ jobs:
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.REPO_CODECOV_TOKEN }}

- name: Show testthat output
if: always()
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DEploid
Type: Package
Title: Deconvolute Mixed Genomes with Unknown Proportions
Version: 0.5.4
Version: 0.5.5
Authors@R: c(
person("Joe", "Zhu", role=c("aut", "cre", "cph"), email="[email protected]"),
person('Jacob', 'Almagro-Garcia', role=c('aut')),
Expand All @@ -26,7 +26,8 @@ URL: https://github.com/DEploid-dev/DEploid-r
BugReports: https://github.com/DEploid-dev/DEploid-r/issues
License: GPL (>= 3)
Depends:
R (>= 3.1.0)
R (>= 3.1.0),
DEploid.utils (>= 0.0.1)
Imports:
Rcpp (>= 0.11.2),
scales (>= 0.4.0),
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export(plotObsExpWSAFPlotly)
export(plotProportions)
export(plotWSAFVsPLAFPlotly)
export(plotWSAFvsPLAF)
importFrom(DEploid.utils,computeObsWSAF)
importFrom(DEploid.utils,extractCoverageFromTxt)
importFrom(DEploid.utils,extractCoverageFromVcf)
importFrom(DEploid.utils,extractPLAF)
importFrom(DEploid.utils,haplotypePainter)
importFrom(DEploid.utils,histWSAF)
importFrom(DEploid.utils,plotAltVsRef)
importFrom(DEploid.utils,plotObsExpWSAF)
importFrom(DEploid.utils,plotProportions)
importFrom(DEploid.utils,plotWSAFvsPLAF)
importFrom(Rcpp,evalCpp)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,rainbow)
Expand Down
315 changes: 315 additions & 0 deletions R/DEploid.utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
#' @importFrom DEploid.utils extractCoverageFromTxt
#' @title Extract read counts from plain text file
#'
#' @note The allele count files must be tab-delimited. The allele count files
#' contain three columns: chromosomes, positions and allele count.
#'
#' @param refFileName Path of the reference allele count file.
#'
#' @param altFileName Path of the alternative allele count file.
#'
#' @return A data.frame contains four columns: chromosomes, positions, reference
#' allele count, alternative allele count.
#'
#' @export
#'
#' @examples
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390 <- extractCoverageFromTxt(refFile, altFile)
#'
DEploid.utils::extractCoverageFromTxt


#' @importFrom DEploid.utils extractCoverageFromVcf
#' @title Extract read counts from VCF
#'
#' @note The VCF file should only contain one sample. If more samples present in
#' the VCF, it only returns coverage for of the first sample.
#'
#' @param vcfFileName Path of the VCF file.
#'
#' @param ADFieldIndex Index of the AD field of the sample field. For example,
#' if the format is "GT:AD:DP:GQ:PL", the AD index is 2 (by default).
#'
#' @return A data.frame contains four columns: chromosomes, positions, reference
#' allele count, alternative allele count.
#'
#' @export
#'
#' @examples
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390 <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#'
DEploid.utils::extractCoverageFromVcf


#' @importFrom DEploid.utils extractPLAF
#'
#' @title Extract PLAF
#'
#' @note The text file must have header, and population level allele frequency
#' recorded in the "PLAF" field.
#'
#' @param plafFileName Path of the PLAF text file.
#'
#' @return A numeric array of PLAF
#'
#' @export
#'
#' @examples
#' plafFile <- system.file("extdata", "labStrains.test.PLAF.txt",
#' package = "DEploid"
#' )
#' plaf <- extractPLAF(plafFile)
DEploid.utils::extractPLAF


#' @importFrom DEploid.utils plotProportions
#'
#' @title Plot proportions
#'
#' @param proportions Matrix of the MCMC proportion samples. The matrix size is
#' number of the MCMC samples by the number of strains.
#'
#' @param title Figure title.
#'
#' @param cex.lab Label size.
#'
#' @param cex.main Title size.
#'
#' @param cex.axis Axis text size.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' plafFile <- system.file("extdata", "labStrains.test.PLAF.txt",
#' package = "DEploid"
#' )
#' panelFile <- system.file("extdata", "labStrains.test.panel.txt",
#' package = "DEploid"
#' )
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390CoverageT <- extractCoverageFromTxt(refFile, altFile)
#' PG0390Coverage.deconv <- dEploid(paste(
#' "-ref", refFile, "-alt", altFile,
#' "-plaf", plafFile, "-noPanel"
#' ))
#' plotProportions(PG0390Coverage.deconv$Proportions, "PG0390-C proportions")
#' }
#'
DEploid.utils::plotProportions


#' @importFrom DEploid.utils plotAltVsRef
#'
#' @title Plot coverage
#'
#' @param ref Numeric array of reference allele count.
#'
#' @param alt Numeric array of alternative allele count.
#'
#' @param title Figure title, "Alt vs Ref" by default
#'
#' @param exclude.ref Numeric array of reference allele count at sites that are
#' not deconvoluted.
#'
#' @param exclude.alt Numeric array of alternative allele count at sites that
#' are not deconvoluted
#'
#' @param potentialOutliers Index of potential outliers.
#'
#' @param cex.lab Label size.
#'
#' @param cex.main Title size.
#'
#' @param cex.axis Axis text size.
#'
#' @export
#'
#' @examples
#' # Example 1
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390CoverageT <- extractCoverageFromTxt(refFile, altFile)
#' plotAltVsRef(PG0390CoverageT$refCount, PG0390CoverageT$altCount)
#'
#' # Example 2
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390CoverageV <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#' plotAltVsRef(PG0390CoverageV$refCount, PG0390CoverageV$altCount)
#'
DEploid.utils::plotAltVsRef


#' @importFrom DEploid.utils histWSAF
#'
#' @title WSAF histogram
#'
#' @param obsWSAF Observed allele frequency within sample
#'
#' @param exclusive When TRUE 0 < WSAF < 1; otherwise 0 <= WSAF <= 1.
#'
#' @param title Histogram title
#'
#' @param cex.lab Label size.
#'
#' @param cex.main Title size.
#'
#' @param cex.axis Axis text size.
#'
#' @return histogram
#'
#' @export
#'
#' @examples
#' # Example 1
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390Coverage <- extractCoverageFromTxt(refFile, altFile)
#' obsWSAF <- computeObsWSAF(PG0390Coverage$altCount, PG0390Coverage$refCount)
#' histWSAF(obsWSAF)
#' myhist <- histWSAF(obsWSAF, FALSE)
#'
#' # Example 2
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390CoverageV <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#' obsWSAF <- computeObsWSAF(PG0390CoverageV$altCount, PG0390CoverageV$refCount)
#' histWSAF(obsWSAF)
#' myhist <- histWSAF(obsWSAF, FALSE)
#'
DEploid.utils::histWSAF


#' @importFrom DEploid.utils plotWSAFvsPLAF
#'
#' @title Plot WSAF vs PLAF
#'
#' @param plaf Numeric array of population level allele frequency.
#'
#' @param obsWSAF Numeric array of observed altenative allele frequencies within
#' sample.
#'
#' @param expWSAF Numeric array of expected WSAF from model.
#'
#' @param title Figure title, "WSAF vs PLAF" by default
#'
#' @param potentialOutliers Index of potential outliers.
#'
#' @param cex.lab Label size.
#'
#' @param cex.main Title size.
#'
#' @param cex.axis Axis text size.
#'
#' @export
#'
#' @examples
#' # Example 1
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390CoverageT <- extractCoverageFromTxt(refFile, altFile)
#' obsWSAF <- computeObsWSAF(PG0390CoverageT$altCount, PG0390CoverageT$refCount)
#' plafFile <- system.file("extdata", "labStrains.test.PLAF.txt",
#' package = "DEploid"
#' )
#' plaf <- extractPLAF(plafFile)
#' plotWSAFvsPLAF(plaf, obsWSAF)
#'
#' # Example 2
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390CoverageV <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#' obsWSAF <- computeObsWSAF(PG0390CoverageV$altCount, PG0390CoverageV$refCount)
#' plafFile <- system.file("extdata", "labStrains.test.PLAF.txt",
#' package = "DEploid"
#' )
#' plaf <- extractPLAF(plafFile)
#' plotWSAFvsPLAF(plaf, obsWSAF)
#'
DEploid.utils::plotWSAFvsPLAF


#' @importFrom DEploid.utils plotObsExpWSAF
#'
#' @title Plot WSAF
#'
#' @param obsWSAF Numeric array of observed WSAF.
#'
#' @param expWSAF Numeric array of expected WSAF.
#'
#' @param title Figure title.
#'
#' @param cex.lab Label size.
#'
#' @param cex.main Title size.
#'
#' @param cex.axis Axis text size.
#'
#' @export
#'
#' @examples
#'
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390CoverageV <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#' obsWSAF <- computeObsWSAF(PG0390CoverageV$altCount, PG0390CoverageV$refCount)
#' plafFile <- system.file("extdata", "labStrains.test.PLAF.txt",
#' package = "DEploid"
#' )
#' PG0390.deconv <- dEploid(paste(
#' "-vcf", vcfFile,
#' "-plaf", plafFile, "-noPanel"
#' ))
#' prop <- PG0390.deconv$Proportions[dim(PG0390.deconv$Proportions)[1], ]
#' expWSAF <- t(PG0390.deconv$Haps) %*% prop
#' plotObsExpWSAF(obsWSAF, expWSAF)
#'
DEploid.utils::plotObsExpWSAF


#' @importFrom DEploid.utils computeObsWSAF
#'
#' @title Compute observed WSAF
#'
#' @param ref Numeric array of reference allele count.
#'
#' @param alt Numeric array of alternative allele count.
#'
#' @return Numeric array of observed allele frequency within sample.
#'
#' @seealso \code{\link{histWSAF}} for histogram.
#'
#' @export
#'
#' @examples
#' # Example 1
#' refFile <- system.file("extdata", "PG0390-C.test.ref", package = "DEploid")
#' altFile <- system.file("extdata", "PG0390-C.test.alt", package = "DEploid")
#' PG0390CoverageT <- extractCoverageFromTxt(refFile, altFile)
#' obsWSAF <- computeObsWSAF(PG0390CoverageT$altCount, PG0390CoverageT$refCount)
#'
#' # Example 2
#' vcfFile <- system.file("extdata", "PG0390-C.test.vcf.gz", package = "DEploid")
#' PG0390CoverageV <- extractCoverageFromVcf(vcfFile, "PG0390-C")
#' obsWSAF <- computeObsWSAF(PG0390CoverageV$altCount, PG0390CoverageV$refCount)
#'
DEploid.utils::computeObsWSAF


#' @importFrom DEploid.utils haplotypePainter
#'
#' @title Painting haplotype according the reference panel
#'
#' @param posteriorProbabilities Posterior probabilities matrix with the size of
#' number of loci by the number of reference strain.
#'
#' @param title Figure title.
#'
#' @param labelScaling Scaling parameter for plotting.
#'
#' @param numberOfInbreeding Number of inbreeding strains copying from.
#'
#' @export
#'
DEploid.utils::haplotypePainter
Loading

0 comments on commit 71873bc

Please sign in to comment.