R/TargetRelations-class.R

#' TargetRelations
#'
#' Class used to represent siRNA-to-gene on- and off-target relations
#' for a knockdown library and a set of genes.
#' 
#' @author Fabian Schmich
#' @name TargetRelations-class
#' @rdname TargetRelations-class
#' @aliases TargetRelations
#' @exportClass TargetRelations
#' 
#' @slot siRNAs The siRNA identifiers
#' @slot genes The gene identifiers (Entrez)
#' @slot path The path to and \code{.rds} \code{\linkS4class{TargetRelations}} file
#' @slot is.loaded An indicator if target relations values are loaded
#' @slot values The quantitative target relation values between siRNAs and genes
#' 
#' @seealso \code{\link{join}}
#' @seealso \code{\link{loadValues}}
#' @seealso \code{\link{unloadValues}}
#' @seealso \code{\link{writeValues}}
#' @seealso \code{\link{values}}
#' @seealso \code{\link{path<-}}
#' 
#' @examples
#' trels <- TargetRelations(readRDS(system.file("extdata", "TR_screen_A.rds", package = "gespeR")))
setClass(Class = "TargetRelations",
         representation = representation(
           siRNAs = "character",
           genes = "character",
           path = "character",
           is.loaded = "logical",
           values = "Matrix"
         ),
         validity=function(object) {
           if (object@is.loaded) {
             if (!all(dim(object@values) == c(length(object@siRNAs), length(object@genes)))) {
               stop("Incorrect target matrix dimensions.")
             }             
             if(!all(object@genes == colnames(object@values))) {
               stop("Gene IDs do not match with targets matrix.")
             } 
             if(!all(object@siRNAs == rownames(object@values))) {
               stop("siRNA IDs do not match with targets matrix.")
             }
           }
           return(TRUE)
         }
)

#' @rdname TargetRelations-class
#' @export 
#' 
#' @param targets Path to a .rds target relations matrix file or \code{\link{Matrix}} object
#' @return A \code{\linkS4class{TargetRelations}} object 
setGeneric(name = "TargetRelations", 
           def = function(targets) { 
             standardGeneric("TargetRelations")
           })

#' @rdname TargetRelations-class
setMethod(f = "TargetRelations",
          signature = signature(targets = "character"),
          function(targets) {
            mat <- readRDS(targets)
            new("TargetRelations",
                path = targets,
                siRNAs = rownames(mat),
                values = mat,
                genes = colnames(mat),
                is.loaded = TRUE
            )  
          }
)

#' @rdname TargetRelations-class
setMethod(f = "TargetRelations",
          signature = signature(targets="Matrix"),
          function(targets) {
            new("TargetRelations",
                path = "",
                siRNAs = rownames(targets),
                values = targets,
                genes = colnames(targets),
                is.loaded = TRUE
            )  
          }
)

#' path
#' 
#' Set the path of a a \code{\linkS4class{TargetRelations}} object object
#' 
#' @author Fabian Schmich
#' @export 
#' @rdname path-methods
#' 
#' @param object A \code{\linkS4class{TargetRelations}} object
#' @param value A string defining the path
#' @return A \code{\linkS4class{TargetRelations}} object with set path
#' @examples
#' trels <- TargetRelations(readRDS(system.file("extdata", "TR_screen_A.rds", package = "gespeR")))
#' path(trels) <- "/dev/null"
setGeneric(name = "path<-", 
           def = function(object, value) {
             standardGeneric("path<-")
           })

#' @rdname path-methods
setMethod(f="path<-",
          signature = signature(object="TargetRelations", value="character"),
          function(object, value) {
            object@path <- value
            return(object)
          }
)

Try the gespeR package in your browser

Any scripts or data that you put into this service are public.

gespeR documentation built on Nov. 8, 2020, 5:35 p.m.