2
2
# '
3
3
# ' An object for holding raw data and associated meta data
4
4
# '
5
- # ' The DatasetExperiment object is an extension of the SummarizedExperiment object
6
- # ' from the SummarizedExperiment package (found on Bioconductor).
7
- # ' It incorporates the basic functionality of struct objects, containing fields such as
5
+ # ' The DatasetExperiment object is an extension of the SummarizedExperiment object
6
+ # ' from the SummarizedExperiment package (found on Bioconductor).
7
+ # ' It incorporates the basic functionality of struct objects, containing fields such as
8
8
# ' Description, Name and Type with features of SummarizedExperiment such as subsetting.
9
- # '
9
+ # '
10
10
# ' There are some important differences between DatasetExperiment and SummarizedExperiment:
11
11
# ' \itemize{
12
12
# ' \item In DatasetExperiment data is stored as Samples (rows) x Features (columns)
13
13
# ' \item DatasetExperiment currently only supports a single assay
14
14
# ' \item length(DatasetExperiment) returns the number of samples
15
15
# ' }
16
- # '
16
+ # '
17
17
# ' @export
18
18
# ' @slot name Name of the dataset
19
19
# ' @slot description Brief description of the dataset
27
27
# ' @param ... named slot values to pass through to struct_class
28
28
# ' @import SummarizedExperiment
29
29
# ' @import S4Vectors
30
- # ' @include generics.R struct_class.R stato_class .R chart_class.R
30
+ # ' @include generics.R struct_class.R output_class.R parameter_class .R chart_class.R
31
31
# ' @return DatasetExperiment
32
32
# ' @rdname struct_DatasetExperiment
33
33
DatasetExperiment = function (
34
34
data = data.frame (),
35
35
sample_meta = data.frame (),
36
36
variable_meta = data.frame (),
37
37
... ){
38
-
38
+
39
39
# convert data set to list
40
40
assays = list (data )
41
-
41
+
42
42
# sample_meta
43
-
43
+
44
44
out = .DatasetExperiment(SummarizedExperiment(
45
45
assays = assays ,
46
46
colData = variable_meta ,
47
47
rowData = sample_meta ),
48
48
... )
49
-
49
+
50
50
return (out )
51
51
}
52
52
53
53
.DatasetExperiment <- setClass(
54
- " DatasetExperiment" ,
54
+ " DatasetExperiment" ,
55
55
contains = c(" struct_class" ," SummarizedExperiment" ),
56
56
prototype = list (' libraries' = ' SummarizedExperiment' )
57
57
)
@@ -61,9 +61,9 @@ DatasetExperiment = function(
61
61
setMethod (f = "$ ",
62
62
signature = c(" DatasetExperiment" ),
63
63
definition = function (x ,name ) {
64
-
64
+
65
65
s = c(' data' ,' sample_meta' ,' variable_meta' )
66
-
66
+
67
67
if (name %in% s ) {
68
68
if (name == ' data' ) {
69
69
if (length(assays(x ))== 0 ) {
@@ -72,23 +72,23 @@ setMethod(f = "$",
72
72
value = assay(x ,1 )
73
73
}
74
74
} else if (name == ' sample_meta' ) {
75
- value = S4Vectors :: DataFrame(rowData(x ),check.names = FALSE )
75
+ value = S4Vectors :: DataFrame(rowData(x ),check.names = FALSE )
76
76
} else if (name == ' variable_meta' ) {
77
77
value = S4Vectors :: DataFrame(colData(x ),check.names = FALSE )
78
- }
79
-
78
+ }
79
+
80
80
if (name %in% s ) {
81
81
# convert to data.frame if using the original struct definitions
82
82
value = as.data.frame(value )
83
83
}
84
-
84
+
85
85
return (value )
86
-
86
+
87
87
} else {
88
88
# for name,description etc
89
89
return (callNextMethod())
90
90
}
91
-
91
+
92
92
}
93
93
)
94
94
@@ -117,10 +117,10 @@ setMethod(f = "$<-",
117
117
setMethod (f = 'show ',
118
118
signature = c(' DatasetExperiment' ),
119
119
definition = function (object ) {
120
-
120
+
121
121
# print struct generic info
122
122
callNextMethod()
123
-
123
+
124
124
# number of assays
125
125
nms <- length(assays(object ))
126
126
if (is.null(nms )) {
@@ -135,8 +135,8 @@ setMethod(f = 'show',
135
135
)
136
136
137
137
# ' Convert a DatasetExperiment to SummarizedExperiment
138
- # '
139
- # ' Converts a DatasetExperiment to SummarizedExperiment. The assay data is
138
+ # '
139
+ # ' Converts a DatasetExperiment to SummarizedExperiment. The assay data is
140
140
# ' transposed, and colData and rowData switched to match. struct specific
141
141
# ' slots such as "name" and "description" are stored in the metaData.
142
142
# ' @param obj a DatasetExperiment object
@@ -155,16 +155,16 @@ setMethod (f = 'as.SummarizedExperiment',
155
155
' type' = obj $ type ,
156
156
' libraries' = obj $ libraries )
157
157
)
158
-
158
+
159
159
return (out )
160
160
}
161
161
)
162
162
163
163
164
164
# ' Convert a SummarizedExperiment to DatasetExperiment
165
- # '
166
- # ' The assay data is transposed, and colData and rowData switched to match.
167
- # ' struct specific slots such as "name" and "description" are extracted from the
165
+ # '
166
+ # ' The assay data is transposed, and colData and rowData switched to match.
167
+ # ' struct specific slots such as "name" and "description" are extracted from the
168
168
# ' metaData if available. NB Any additional metadata will be lost during this conversion.
169
169
# ' @param obj a SummarizedExperiment object
170
170
# ' @return a DatasetExperiment object
@@ -177,7 +177,7 @@ setMethod (f = 'as.DatasetExperiment',
177
177
B = as.data.frame(t(A ))
178
178
colnames(B ) = rownames(A )
179
179
rownames(B ) = colnames(A )
180
-
180
+
181
181
out = DatasetExperiment(
182
182
data = B ,
183
183
variable_meta = as.data.frame(rowData(obj )),
@@ -187,15 +187,15 @@ setMethod (f = 'as.DatasetExperiment',
187
187
type = as.character(metadata(obj )$ type ),
188
188
libraries = as.character(metadata(obj )$ libraries )
189
189
)
190
-
190
+
191
191
return (out )
192
192
}
193
193
)
194
194
195
195
196
196
197
197
# ' Export a dataset to an excel file
198
- # '
198
+ # '
199
199
# ' Exports a dataset object to an excel file with sheets for data, sample_meta and variable_meta
200
200
# ' @param object a dataset object
201
201
# ' @param outfile the filename (including path) to write the data to
@@ -211,19 +211,19 @@ setMethod (f = 'as.DatasetExperiment',
211
211
setMethod (f = "export_xlsx ",
212
212
signature = c(" DatasetExperiment" ),
213
213
definition = function (object ,outfile ,transpose = TRUE ) {
214
-
214
+
215
215
# check for openxlsx
216
216
if (! requireNamespace(' openxlsx' , quietly = TRUE )) {
217
217
stop(' package "openxlsx" was not found. Please install it to use "export.xlsx()".' )
218
218
}
219
-
220
-
219
+
220
+
221
221
if (transpose ) {
222
222
X = as.data.frame(t(object $ data ))
223
223
} else {
224
224
X = object $ data
225
225
}
226
-
226
+
227
227
OUT = list (
228
228
' data' = X ,
229
229
' sample_meta' = object $ sample_meta ,
@@ -242,7 +242,7 @@ setMethod(f = "export_xlsx",
242
242
return (IN )
243
243
}
244
244
245
- # ' @export
245
+ # ' @export
246
246
# ' @rdname autocompletion
247
247
setMethod ('.DollarNames ','DatasetExperiment',.DollarNames.DatasetExperiment)
248
248
0 commit comments