22# '
33# ' An object for holding raw data and associated meta data
44# '
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
88# ' Description, Name and Type with features of SummarizedExperiment such as subsetting.
9- # '
9+ # '
1010# ' There are some important differences between DatasetExperiment and SummarizedExperiment:
1111# ' \itemize{
1212# ' \item In DatasetExperiment data is stored as Samples (rows) x Features (columns)
1313# ' \item DatasetExperiment currently only supports a single assay
1414# ' \item length(DatasetExperiment) returns the number of samples
1515# ' }
16- # '
16+ # '
1717# ' @export
1818# ' @slot name Name of the dataset
1919# ' @slot description Brief description of the dataset
2727# ' @param ... named slot values to pass through to struct_class
2828# ' @import SummarizedExperiment
2929# ' @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
3131# ' @return DatasetExperiment
3232# ' @rdname struct_DatasetExperiment
3333DatasetExperiment = function (
3434 data = data.frame (),
3535 sample_meta = data.frame (),
3636 variable_meta = data.frame (),
3737 ... ){
38-
38+
3939 # convert data set to list
4040 assays = list (data )
41-
41+
4242 # sample_meta
43-
43+
4444 out = .DatasetExperiment(SummarizedExperiment(
4545 assays = assays ,
4646 colData = variable_meta ,
4747 rowData = sample_meta ),
4848 ... )
49-
49+
5050 return (out )
5151}
5252
5353.DatasetExperiment <- setClass(
54- " DatasetExperiment" ,
54+ " DatasetExperiment" ,
5555 contains = c(" struct_class" ," SummarizedExperiment" ),
5656 prototype = list (' libraries' = ' SummarizedExperiment' )
5757)
@@ -61,9 +61,9 @@ DatasetExperiment = function(
6161setMethod (f = "$ ",
6262 signature = c(" DatasetExperiment" ),
6363 definition = function (x ,name ) {
64-
64+
6565 s = c(' data' ,' sample_meta' ,' variable_meta' )
66-
66+
6767 if (name %in% s ) {
6868 if (name == ' data' ) {
6969 if (length(assays(x ))== 0 ) {
@@ -72,23 +72,23 @@ setMethod(f = "$",
7272 value = assay(x ,1 )
7373 }
7474 } else if (name == ' sample_meta' ) {
75- value = S4Vectors :: DataFrame(rowData(x ),check.names = FALSE )
75+ value = S4Vectors :: DataFrame(rowData(x ),check.names = FALSE )
7676 } else if (name == ' variable_meta' ) {
7777 value = S4Vectors :: DataFrame(colData(x ),check.names = FALSE )
78- }
79-
78+ }
79+
8080 if (name %in% s ) {
8181 # convert to data.frame if using the original struct definitions
8282 value = as.data.frame(value )
8383 }
84-
84+
8585 return (value )
86-
86+
8787 } else {
8888 # for name,description etc
8989 return (callNextMethod())
9090 }
91-
91+
9292 }
9393)
9494
@@ -117,10 +117,10 @@ setMethod(f = "$<-",
117117setMethod (f = 'show ',
118118 signature = c(' DatasetExperiment' ),
119119 definition = function (object ) {
120-
120+
121121 # print struct generic info
122122 callNextMethod()
123-
123+
124124 # number of assays
125125 nms <- length(assays(object ))
126126 if (is.null(nms )) {
@@ -135,8 +135,8 @@ setMethod(f = 'show',
135135)
136136
137137# ' 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
140140# ' transposed, and colData and rowData switched to match. struct specific
141141# ' slots such as "name" and "description" are stored in the metaData.
142142# ' @param obj a DatasetExperiment object
@@ -155,16 +155,16 @@ setMethod (f = 'as.SummarizedExperiment',
155155 ' type' = obj $ type ,
156156 ' libraries' = obj $ libraries )
157157 )
158-
158+
159159 return (out )
160160 }
161161)
162162
163163
164164# ' 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
168168# ' metaData if available. NB Any additional metadata will be lost during this conversion.
169169# ' @param obj a SummarizedExperiment object
170170# ' @return a DatasetExperiment object
@@ -177,7 +177,7 @@ setMethod (f = 'as.DatasetExperiment',
177177 B = as.data.frame(t(A ))
178178 colnames(B ) = rownames(A )
179179 rownames(B ) = colnames(A )
180-
180+
181181 out = DatasetExperiment(
182182 data = B ,
183183 variable_meta = as.data.frame(rowData(obj )),
@@ -187,15 +187,15 @@ setMethod (f = 'as.DatasetExperiment',
187187 type = as.character(metadata(obj )$ type ),
188188 libraries = as.character(metadata(obj )$ libraries )
189189 )
190-
190+
191191 return (out )
192192 }
193193)
194194
195195
196196
197197# ' Export a dataset to an excel file
198- # '
198+ # '
199199# ' Exports a dataset object to an excel file with sheets for data, sample_meta and variable_meta
200200# ' @param object a dataset object
201201# ' @param outfile the filename (including path) to write the data to
@@ -211,19 +211,19 @@ setMethod (f = 'as.DatasetExperiment',
211211setMethod (f = "export_xlsx ",
212212 signature = c(" DatasetExperiment" ),
213213 definition = function (object ,outfile ,transpose = TRUE ) {
214-
214+
215215 # check for openxlsx
216216 if (! requireNamespace(' openxlsx' , quietly = TRUE )) {
217217 stop(' package "openxlsx" was not found. Please install it to use "export.xlsx()".' )
218218 }
219-
220-
219+
220+
221221 if (transpose ) {
222222 X = as.data.frame(t(object $ data ))
223223 } else {
224224 X = object $ data
225225 }
226-
226+
227227 OUT = list (
228228 ' data' = X ,
229229 ' sample_meta' = object $ sample_meta ,
@@ -242,7 +242,7 @@ setMethod(f = "export_xlsx",
242242 return (IN )
243243}
244244
245- # ' @export
245+ # ' @export
246246# ' @rdname autocompletion
247247setMethod ('.DollarNames ','DatasetExperiment',.DollarNames.DatasetExperiment)
248248
0 commit comments