-
Notifications
You must be signed in to change notification settings - Fork 24
/
jackstraw.R
174 lines (160 loc) · 4.7 KB
/
jackstraw.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#' @include zzz.R
#' @include generics.R
#' @importFrom methods slot slot<- slotNames
#'
NULL
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Class definitions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#' The JackStrawData Class
#'
#' The JackStrawData is used to store the results of a JackStraw computation.
#'
#' @slot empirical.p.values Empirical p-values
#' @slot fake.reduction.scores Fake reduction scores
#' @slot empirical.p.values.full Empirical p-values on full
#' @slot overall.p.values Overall p-values from ScoreJackStraw
#'
#' @name JackStrawData-class
#' @rdname JackStrawData-class
#' @exportClass JackStrawData
#'
JackStrawData <- setClass(
Class = "JackStrawData",
slots = list(
empirical.p.values = "matrix",
fake.reduction.scores = "matrix",
empirical.p.values.full = "matrix",
overall.p.values = "matrix"
)
)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Methods for Seurat-defined generics
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#' @rdname JS
#' @export
#' @method JS JackStrawData
#'
JS.JackStrawData <- function(object, slot, ...) {
CheckDots(...)
slot <- switch(
EXPR = slot,
'empirical' = 'empirical.p.values',
'fake' = 'fake.reduction.scores',
'full' = 'empirical.p.values.full',
'overall' = 'overall.p.values',
slot
)
return(slot(object = object, name = slot))
}
#' @rdname JS
#' @export
#' @method JS<- JackStrawData
#'
"JS<-.JackStrawData" <- function(object, slot, ..., value) {
CheckDots(...)
slot <- switch(
EXPR = slot,
'empirical' = 'empirical.p.values',
'fake' = 'fake.reduction.scores',
'full' = 'empirical.p.values.full',
'overall' = 'overall.p.values',
slot
)
slot(object = object, name = slot) <- value
return(object)
}
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Methods for R-defined generics
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#' \code{JackStrawData} Methods
#'
#' Methods for \code{\link{JackStrawData}} objects for generics defined in
#' other packages
#'
#' @param x,object A \code{\link{JackStrawData}} object
#' @param ... Ignored
#'
#' @name JackStrawData-methods
#' @rdname JackStrawData-methods
#'
#' @concept jackstraw
#'
NULL
#' @describeIn JackStrawData-methods Autocompletion for \code{$} access on a
#' \code{JackStrawData} object
#'
#' @inheritParams utils::.DollarNames
#'
#' @importFrom utils .DollarNames
#' @export
#' @method .DollarNames JackStrawData
#'
".DollarNames.JackStrawData" <- function(x, pattern = '') {
slotnames <- as.list(x = slotNames(x = x))
names(x = slotnames) <- unlist(x = slotnames)
return(.DollarNames(x = slotnames, pattern = pattern))
}
#' @describeIn JackStrawData-methods Access data from a \code{JackStrawData}
#' object
#'
#' @param i A \code{JackStrawData} slot name
#'
#' @return \code{$}: Slot \code{i} from \code{x}
#' @export
#'
"$.JackStrawData" <- function(x, i, ...) {
return(slot(object = x, name = i))
}
#' @describeIn JackStrawData-methods Have empirical p-values for a
#' \code{JackStrawData} object been calculated
#'
#' @return \code{as.logical}: \code{TRUE} if empirical p-values have been
#' calculated otherwise \code{FALSE}
#'
#' @export
#' @method as.logical JackStrawData
#'
as.logical.JackStrawData <- function(x, ...) {
CheckDots(...)
empP <- JS(object = x, slot = 'empirical')
return(!(all(dim(x = empP) == 0) || all(is.na(x = empP))))
}
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# S4 methods
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#' @describeIn JackStrawData-methods Overview of a \code{JackStrawData} object
#'
#' @return \code{show}: Prints summary to \code{\link[base]{stdout}} and
#' invisibly returns \code{NULL}
#'
#' @importFrom utils head
#' @importFrom methods show
#'
#' @export
#'
setMethod(
f = 'show',
signature = 'JackStrawData',
definition = function(object) {
empp <- object$empirical.p.values
scored <- object$overall.p.values
cat(
"A JackStrawData object simulated on",
nrow(x = empp),
"features for",
ncol(x = empp),
"dimensions.\n",
"Scored for:",
nrow(x = scored),
"dimensions.\n"
)
return(invisible(x = NULL))
}
)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Internal
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%