R/AllClasses.R

Defines functions PGx

#' PGx class object
#'
#' The PGx class inherits from \code{\link[VariantAnnotation]{VCF}}. Like the
#' \code{CollapsedVCF} class it is expected that users will not create instances
#' of the PGx class but instead the PGx class will be created by one of the
#' constructor functions, i.e. \code{readPGx}.
#'
#' @slot gene The PGx gene used to construct the PGx object. See \code{pgxGenes()} for available genes.
#' @slot referencePositions GRanges object containing all unique allele positions for the reference gene.
#' @slot missingPositions GRanges object containing all positions in the reference that are missing from the input VCF.
#' @slot matchingPositions GRanges object containing all positions in the reference that have matches in the input VCF.
#' @slot referenceHaplotyes GRanges object containing all positions for all alleles ans suballeles for the reference gene.
#' @export
#' @import methods
#' @importClassesFrom VariantAnnotation CollapsedVCF
.PGx <- setClass(
  "PGx",
  slots = representation(
    gene = "character",
    missingPositions = "GRanges",
    matchingPositions = "GRanges",
    referencePositions = "GRanges",
    referenceHaplotypes = "GRanges"
    ),
  contains = "CollapsedVCF"
)

#' @export
#' @importFrom GenomicRanges GRanges
#' @importClassesFrom VariantAnnotation VCF
PGx <- function(vcf = VCF(), gene = "", referencePositions = GRanges(),
                missingPositions = GRanges(), matchingPositions = GRanges(),
                referenceHaplotypes = GRanges()) {
  .PGx(
    vcf,
    gene = gene,
    referencePositions = referencePositions,
    missingPositions = missingPositions,
    matchingPositions = matchingPositions,
    referenceHaplotypes = referenceHaplotypes
  )
}

setValidity("PGx", function(object) {
  if (!is(object@referencePositions)[[1]] == "GRanges") {
    return("referencePositions must be a GRanges object.")
  }
  if (!is(object@missingPositions)[[1]] == "GRanges") {
    return("missingPositions must be a GRanges object.")
  }
  if (!is(object@matchingPositions)[[1]] == "GRanges") {
    return("matchingPositions must ba a GRanges object.")
  }
  if (!is(object@referenceHaplotypes)[[1]] == "GRanges") {
    return("referenceHaplotypes must be a GRanges object.")
  }
  TRUE
})
coriell-research/pgx documentation built on June 4, 2022, 11:08 a.m.