vignettes/DrS4.Rmd
DrS4.Rmd
methods
may report more than we needWe are interested in the SingleCellExperiment class.
It is defined in a package.
suppressPackageStartupMessages({
library(SingleCellExperiment)
library(DrS4)
library(dplyr)
})
methods(class="SingleCellExperiment")
## [1] != [ [[
## [4] [[<- [<- %in%
## [7] < <= ==
## [10] > >= $
## [13] $<- aggregate altExp
## [16] altExp<- altExpNames altExpNames<-
## [19] altExps altExps<- anyDuplicated
## [22] anyNA append as.character
## [25] as.complex as.data.frame as.env
## [28] as.integer as.list as.logical
## [31] as.matrix as.numeric as.raw
## [34] assay assay<- assayNames
## [37] assayNames<- assays assays<-
## [40] bindROWS by c
## [43] cbind coerce coerce<-
## [46] colData colData<- colLabels
## [49] colLabels<- colPair colPair<-
## [52] colPairNames colPairNames<- colPairs
## [55] colPairs<- combineCols combineRows
## [58] Compare countOverlaps counts
## [61] counts<- coverage cpm
## [64] cpm<- dim dimnames
## [67] dimnames<- disjointBins distance
## [70] distanceToNearest duplicated elementMetadata
## [73] elementMetadata<- end end<-
## [76] eval expand expand.grid
## [79] extractROWS FactorToClass findOverlaps
## [82] flank follow granges
## [85] head horizontal_slot_names int_colData
## [88] int_colData<- int_elementMetadata int_elementMetadata<-
## [91] int_metadata int_metadata<- intersect
## [94] is.na is.unsorted isDisjoint
## [97] length lengths logcounts
## [100] logcounts<- mainExpName mainExpName<-
## [103] match mcols mcols<-
## [106] merge mergeROWS metadata
## [109] metadata<- mstack names
## [112] names<- narrow nearest
## [115] normcounts normcounts<- objectVersion
## [118] order overlapsAny parallel_slot_names
## [121] pcompare precede promoters
## [124] ranges ranges<- rank
## [127] rbind realize reducedDim
## [130] reducedDim<- reducedDimNames reducedDimNames<-
## [133] reducedDims reducedDims<- relist
## [136] rename rep rep.int
## [139] replaceROWS resize restrict
## [142] rev rowData rowData<-
## [145] ROWNAMES ROWNAMES<- rowPair
## [148] rowPair<- rowPairNames rowPairNames<-
## [151] rowPairs rowPairs<- rowRanges
## [154] rowRanges<- rowSubset rowSubset<-
## [157] selfmatch seqinfo seqinfo<-
## [160] seqlevelsInUse seqnames setdiff
## [163] setequal shift shiftApply
## [166] show sizeFactors sizeFactors<-
## [169] sort split split<-
## [172] start start<- strand
## [175] strand<- subset subsetByOverlaps
## [178] summary table tail
## [181] tapply tpm tpm<-
## [184] transform trim union
## [187] unique updateObject values
## [190] values<- vertical_slot_names weights
## [193] weights<- width width<-
## [196] window window<- with
## [199] xtabs xtfrm
## see '?methods' for accessing help and source code
There are many methods listed, including ‘==’.
try(getMethod("==", "SingleCellExperiment"))
## Error in getMethod("==", "SingleCellExperiment") :
## no method found for function '==' and signature SingleCellExperiment
We can find the signatures for which ‘==’ is defined:
showMethods("==")
## Function: == (package base)
## e1="ANY", e2="Vector"
## e1="DataFrame", e2="DataFrame"
## e1="integer", e2="XIntegerViews"
## e1="list", e2="List"
## e1="List", e2="list"
## e1="List", e2="List"
## e1="numeric", e2="XDoubleViews"
## e1="SharedVector", e2="SharedVector"
## e1="Vector", e2="ANY"
## e1="Vector", e2="Vector"
## e1="XDouble", e2="XDoubleViews"
## e1="XDoubleViews", e2="numeric"
## e1="XDoubleViews", e2="XDouble"
## e1="XDoubleViews", e2="XDoubleViews"
## e1="XInteger", e2="XIntegerViews"
## e1="XIntegerViews", e2="integer"
## e1="XIntegerViews", e2="XInteger"
## e1="XIntegerViews", e2="XIntegerViews"
## e1="XRawList", e2="XRawList"
## e1="XVector", e2="XVector"
DrS4 aims to provide clearer access to the methods actually defined for a class. This requires specifying a package where we look for the class and its methods. More work needs to be done in this domain. Specifically, the function ‘defdMethods’ currently only retrieves one method/signature for each generic method defined for the class.
library(DrS4)
require("SingleCellExperiment")
scem = defdMethods(cl="SingleCellExperiment",
pkg="SingleCellExperiment")
## superclasses RangedSummarizedExperiment, SummarizedExperiment, RectangularData, Vector, Annotated, vector_OR_Vector may provide additional relevant methods/signatures
head(scem)
## method cl pkg nmeth4cl
## 1 [ SingleCellExperiment package:SingleCellExperiment 1
## 2 [<- SingleCellExperiment package:SingleCellExperiment 1
## 3 altExp SingleCellExperiment package:SingleCellExperiment 3
## 4 altExp<- SingleCellExperiment package:SingleCellExperiment 3
## 5 altExpNames SingleCellExperiment package:SingleCellExperiment 1
## 6 altExpNames<- SingleCellExperiment package:SingleCellExperiment 1
## sigs
## 1 x="SingleCellExperiment", i="ANY", j="ANY", drop="ANY"
## 2 x="SingleCellExperiment", i="ANY", j="ANY", value="SingleCellExperiment"
## 3 x="SingleCellExperiment", e="character", x="SingleCellExperiment", e="missing", x="SingleCellExperiment", e="numeric"
## 4 x="SingleCellExperiment", e="character", x="SingleCellExperiment", e="missing", x="SingleCellExperiment", e="numeric"
## 5 x="SingleCellExperiment"
## 6 x="SingleCellExperiment", value="character"
Here we’ll list methods of coercing between classes involving SummarizedExperiment, RangedSummarizedExperiment, and SingleCellExperiment.
require("SummarizedExperiment")
se = defdMethods("SummarizedExperiment") # pkg has simple default
## superclasses RectangularData, Vector, Annotated, vector_OR_Vector may provide additional relevant methods/signatures
rse = defdMethods("RangedSummarizedExperiment", pkg="SummarizedExperiment")
## superclasses SummarizedExperiment, RectangularData, Vector, Annotated, vector_OR_Vector may provide additional relevant methods/signatures
cmb = try(rbind(scem,se,rse))
tmp = (cmb |> filter(method=="coerce"))
sl = (tmp |> select(sigs))[[1]]
names(sl) = tmp$cl
sl
## $SingleCellExperiment
## [1] "from=\"RangedSummarizedExperiment\", to=\"SingleCellExperiment\""
## [2] "from=\"SummarizedExperiment\", to=\"SingleCellExperiment\""
##
## $SummarizedExperiment
## [1] "from=\"ExpressionSet\", to=\"SummarizedExperiment\""
## [2] "from=\"RangedSummarizedExperiment\", to=\"SummarizedExperiment\""
## [3] "from=\"SummarizedExperiment\", to=\"ExpressionSet\""
## [4] "from=\"SummarizedExperiment\", to=\"RangedSummarizedExperiment\""
## [5] "from=\"SummarizedExperiment\", to=\"SingleCellExperiment\""
##
## $RangedSummarizedExperiment
## [1] "from=\"ExpressionSet\", to=\"RangedSummarizedExperiment\""
## [2] "from=\"RangedSummarizedExperiment\", to=\"ExpressionSet\""
## [3] "from=\"RangedSummarizedExperiment\", to=\"SingleCellExperiment\""
## [4] "from=\"RangedSummarizedExperiment\", to=\"SummarizedExperiment\""
## [5] "from=\"SummarizedExperiment\", to=\"RangedSummarizedExperiment\""