Skip to content

Commit

Permalink
Merge pull request #10 from maize-genetics/metric-updates
Browse files Browse the repository at this point in the history
Summary and visualization requests
  • Loading branch information
btmonier authored Aug 8, 2024
2 parents 4e6bca2 + 56d8615 commit 10b1470
Show file tree
Hide file tree
Showing 23 changed files with 789 additions and 71 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rPHG2
Title: R interface to PHGv2
Version: 0.5
Version: 0.6
Authors@R:
person(
given = "Brandon",
Expand All @@ -25,7 +25,7 @@ URL:
https://rphg2.maizegenetics.net/
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Depends:
R (>= 4.1.0)
Imports:
Expand Down
10 changes: 8 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ export(metricsIds)
export(metricsMetaData)
export(metricsTable)
export(numberOfChromosomes)
export(numberOfHaplotypes)
export(numberOfRefRanges)
export(numberOfTaxa)
export(numberOfSamples)
export(phgType)
export(plotDot)
export(plotGvcf)
export(plotHaploCounts)
export(plotHaploDist)
export(port)
export(readHapIdMetaData)
export(readHapIdPosMetaData)
Expand Down Expand Up @@ -59,11 +62,14 @@ exportMethods(metricsIds)
exportMethods(metricsMetaData)
exportMethods(metricsTable)
exportMethods(numberOfChromosomes)
exportMethods(numberOfHaplotypes)
exportMethods(numberOfRefRanges)
exportMethods(numberOfTaxa)
exportMethods(numberOfSamples)
exportMethods(phgType)
exportMethods(plotDot)
exportMethods(plotGvcf)
exportMethods(plotHaploCounts)
exportMethods(plotHaploDist)
exportMethods(port)
exportMethods(readHapIdMetaData)
exportMethods(readHapIdPosMetaData)
Expand Down
22 changes: 21 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
## rPHG 0.5
## rPHG2 0.6
* Added new parameters to `plogtGvcf()`:
+ `mData` and `mVar`
+ allows user to override default sample color option with categorical data
* Added new generic, `numberOfHaplotypes()`:
+ returns the number of unique haplotypes found within each reference range or
the total value found within a `PHGDataSet` object
* Added getters to `PHGDataSet` objects:
+ `numberOfChromosomes()`
+ `numberOfSamples()`
+ `numberOfRefRanges()`
* Changed functions and variables containing `taxa` to `samples`
+ e.g., `numberOfTaxa()` is now `numberOfSamples()`
* Format tweaks to `HaplotypeGraph` objects' `show()` method
* Added new function `plotHaploCount()`:
+ Plots unique haplotype counts for all or given reference ranges
* Added new function `plotHaploDist()`:
+ Plots unique haplotype distribution for entire `PHGDataSet` object


## rPHG2 0.5
* Added new visualization method, `plotGvcf()`:
+ auto plotting various gVCF metrics
+ granular metric support through formula subsetting
Expand Down
55 changes: 50 additions & 5 deletions R/class_all_generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ setGeneric("metricsTable<-", function(object, ..., value) standardGeneric("metri
setGeneric("numberOfChromosomes", function(object, ...) standardGeneric("numberOfChromosomes"))


## ----
#' @title Return number of haplotypes
#'
#' @description
#' Returns the number of haplotypes either for the whole dataset or by each
#' individual reference range.
#'
#' @param object an \code{rPHG2} local or server connection object
#' @param ... Additional arguments, for use in specific methods
#'
#' @rdname numberOfHaplotypes
#' @export
setGeneric("numberOfHaplotypes", function(object, ...) standardGeneric("numberOfHaplotypes"))


## ----
#' @title Return number of reference ranges
#'
Expand All @@ -203,24 +218,25 @@ setGeneric("numberOfRefRanges", function(object, ...) standardGeneric("numberOfR


## ----
#' @title Return number of taxa
#' @title Return number of samples
#'
#' @description
#' Returns the number of taxa for a given object
#' Returns the number of samples for a given object
#'
#' @param object an \code{rPHG2} local or server connection object
#' @param ... Additional arguments, for use in specific methods
#'
#' @rdname numberOfTaxa
#' @rdname numberOfSamples
#' @export
setGeneric("numberOfTaxa", function(object, ...) standardGeneric("numberOfTaxa"))
setGeneric("numberOfSamples", function(object, ...) standardGeneric("numberOfSamples"))


## ----
#' @title Return type of PHG connection
#'
#' @description
#' Returns the PHG type for a given \code{rPHG2} local or server connection object
#' Returns the PHG type for a given \code{rPHG2} local or server connection
#' object
#'
#' @param object an \code{rPHG2} connection object
#' @param ... Additional arguments, for use in specific methods
Expand Down Expand Up @@ -258,6 +274,35 @@ setGeneric("plotDot", function(object, ...) standardGeneric("plotDot"))
setGeneric("plotGvcf", function(object, ...) standardGeneric("plotGvcf"))


## ----
#' @title Plot haplotype counts
#'
#' @description
#' Plots the counts of unique haplotype IDs found in each reference range.
#'
#' @param object a \code{\linkS4class{PHGDataSet}} object
#' @param ... Additional arguments, for use in specific methods
#'
#' @rdname plotHaploCounts
#' @export
setGeneric("plotHaploCounts", function(object, ...) standardGeneric("plotHaploCounts"))


## ----
#' @title Plot haplotype distribution
#'
#' @description
#' Plots a general distribution of the number of unique haplotypes in a
#' \code{\linkS4class{PHGDataSet}} object.
#'
#' @param object a \code{\linkS4class{PHGDataSet}} object
#' @param ... Additional arguments, for use in specific methods
#'
#' @rdname plotHaploDist
#' @export
setGeneric("plotHaploDist", function(object, ...) standardGeneric("plotHaploDist"))


## ----
#' @title Return port value
#'
Expand Down
20 changes: 10 additions & 10 deletions R/class_haplotype_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @slot nChrom Number of chromosomes
#' @slot nRefRanges Number of reference ranges
#' @slot nTaxa Number of taxa
#' @slot nSamples Number of samples
#' @slot jHapGraph An \code{rJava} \code{jobjRef} object representing a
#' \code{HaplotypeGraph} class in the PHG API
#' @slot jMemAddress An identifier string to the JVM memory space
Expand All @@ -20,14 +20,14 @@ setClass(
slots = c(
nChrom = "integer",
nRefRanges = "integer",
nTaxa = "integer",
nSamples = "integer",
jHapGraph = "jobjRef",
jMemAddress = "character"
),
prototype = list(
nChrom = NA_integer_,
nRefRanges = NA_integer_,
nTaxa = NA_integer_,
nSamples = NA_integer_,
jHapGraph = rJava::.jnull(),
jMemAddress = NA_character_
)
Expand Down Expand Up @@ -96,7 +96,7 @@ buildHaplotypeGraph <- function(
Class = "HaplotypeGraph",
nChrom = jvmGraph$getContigs()$size(),
nRefRanges = jvmGraph$numberOfRanges(),
nTaxa = jvmGraph$numberOfSamples(),
nSamples = jvmGraph$numberOfSamples(),
jHapGraph = jvmGraph,
jMemAddress = pointer
)
Expand Down Expand Up @@ -129,9 +129,9 @@ setMethod(
"A ", cli::style_bold("HaplotypeGraph"), " object @ ",
cli::style_bold(cli::col_blue(javaMemoryAddress(object)))
),
paste0(" ", pointerSymbol, " # of ref ranges....: ", numberOfRefRanges(object)),
paste0(" ", pointerSymbol, " # of taxa..........: ", numberOfTaxa(object)),
paste0(" ", pointerSymbol, " # of chromosomes...: ", numberOfChromosomes(object))
paste0(" ", pointerSymbol, " # of ref ranges....: ", cli::style_bold(numberOfRefRanges(object))),
paste0(" ", pointerSymbol, " # of samples.......: ", cli::style_bold(numberOfSamples(object))),
paste0(" ", pointerSymbol, " # of chromosomes...: ", cli::style_bold(numberOfChromosomes(object)))
)

cat(msg, sep = "\n")
Expand Down Expand Up @@ -191,13 +191,13 @@ setMethod(


## ----
#' @rdname numberOfTaxa
#' @rdname numberOfSamples
#' @export
setMethod(
f = "numberOfTaxa",
f = "numberOfSamples",
signature = signature(object = "HaplotypeGraph"),
definition = function(object) {
return(object@nTaxa)
return(object@nSamples)
}
)

Expand Down
Loading

0 comments on commit 10b1470

Please sign in to comment.