@@ -60,20 +60,27 @@ setMethod('detectMissInjections',signature = 'MetaboProfile',
60
60
mi <- x %> %
61
61
processedData()
62
62
63
- if (str_detect(technique(x ),' GCMS' )) {
64
- mi <- mi %> %
65
- rowSums() %> %
66
- tibble(value = . ) %> %
67
- bind_cols(i )
68
- } else {
69
- mi <- mi %> %
70
- map(rowSums ) %> %
71
- bind_cols() %> %
72
- rowSums() %> %
73
- as_tibble() %> %
74
- bind_cols(i )
63
+ if (! is.list(mi )){
64
+ mi <- list (mi )
65
+ }
66
+
67
+ mi <- mi %> %
68
+ map(rowSums )
69
+
70
+ if (mi %> %
71
+ names() %> %
72
+ is.na() %> %
73
+ any()) {
74
+ names(mi ) <- replace(names(mi ),
75
+ is.na(names(mi )),
76
+ ' NA' )
75
77
}
76
- mi %> %
78
+
79
+ mi %> %
80
+ bind_cols() %> %
81
+ rowSums() %> %
82
+ as_tibble() %> %
83
+ bind_cols(i ) %> %
77
84
missInject(idx = idx )
78
85
})
79
86
@@ -102,7 +109,7 @@ missInject <- function(TICdat,idx){
102
109
# ' @details Analysis of Variance (ANOVA) is used to detect differences in total ion count (TIC) averages between batches/blocks.
103
110
# ' @examples
104
111
# ' ## Retrieve file paths and sample information for example data
105
- # ' files <- metaboData::filePaths('FIE-HRMS','BdistachyonEcotypes')[1:2]
112
+ # ' files <- metaboData::filePaths('FIE-HRMS','BdistachyonEcotypes',ask = FALSE )[1:2]
106
113
# '
107
114
# ' info <- metaboData::runinfo('FIE-HRMS','BdistachyonEcotypes')[1:2,]
108
115
# '
@@ -159,21 +166,30 @@ setMethod('detectBatchDiff',signature = "MetaboProfile",
159
166
TICdat <- x %> %
160
167
processedData()
161
168
162
- if (str_detect(technique(x ),' GCMS' )) {
163
- TICdat <- TICdat %> %
164
- rowSums() %> %
165
- {tibble(Sample = 1 : length(. ),
166
- TIC = . ,
167
- batch = ri [,by ] %> % deframe() %> % factor ())}
168
- } else {
169
- TICdat <- TICdat %> %
170
- map(rowSums ) %> %
171
- bind_cols() %> %
172
- rowid_to_column(var = ' Sample' ) %> %
173
- mutate(batch = ri [,by ] %> % unlist() %> % factor ()) %> %
174
- gather(' Mode' ,' TIC' ,- batch ,- Sample )
169
+ if (! is.list(TICdat )){
170
+ TICdat <- list (TICdat )
175
171
}
176
172
173
+ TICdat <- TICdat %> %
174
+ map(rowSums )
175
+
176
+ if (TICdat %> %
177
+ names() %> %
178
+ is.na() %> %
179
+ any()) {
180
+ names(TICdat ) <- replace(names(TICdat ),
181
+ is.na(names(TICdat )),
182
+ ' NA' )
183
+ }
184
+
185
+ TICdat <- TICdat %> %
186
+ bind_cols() %> %
187
+ rowid_to_column(var = ' Sample' ) %> %
188
+ mutate(batch = ri [,by ] %> %
189
+ unlist() %> %
190
+ factor ()) %> %
191
+ gather(' Mode' ,' TIC' ,- batch ,- Sample )
192
+
177
193
diff <- batchDiff(TICdat ,pthresh )
178
194
return (diff )
179
195
})
@@ -242,6 +258,8 @@ batchDiff <- function(TICdat,pthresh = 0.05){
242
258
# ' @rdname detectPretreatmentParameters
243
259
# ' @description Detect pre-treatment parameters for `Binalysis` or `MetaboProfile` class objects.
244
260
# ' @param x S4 object of class `Binalysis`, `MetaboProfile` or `AnalysisData`
261
+ # ' @param cls the name of the sample information table column containing the sample class information
262
+ # ' @param QCidx QC sample class label
245
263
# ' @return S4 object of class `AnalysisParameters`
246
264
# ' @examples
247
265
# ' ## Retreive example file paths and sample information
@@ -263,22 +281,49 @@ batchDiff <- function(TICdat,pthresh = 0.05){
263
281
# ' pp
264
282
# ' @export
265
283
266
- setGeneric ('detectPretreatmentParameters ',function(x){
284
+ setGeneric ('detectPretreatmentParameters ',function(x,
285
+ cls = ' class' ,
286
+ QCidx = ' QC' ){
267
287
standardGeneric(' detectPretreatmentParameters' )
268
288
})
269
289
270
290
# ' @rdname detectPretreatmentParameters
291
+ # ' @importFrom metabolyseR changeParameter<-
271
292
272
293
setMethod ('detectPretreatmentParameters ',signature = 'Binalysis',
273
- function (x ){
274
- detectPretreatment(x )
294
+ function (x ,cls = ' class' ,QCidx = ' QC' ){
295
+ pp <- detectPretreatment(x )
296
+
297
+ sample_info <- binneR :: sampleInfo(x )
298
+
299
+ if (! detectQC(sample_info ,cls ,QCidx )){
300
+ parameters(pp ,' pre-treatment' )$ QC <- NULL
301
+ } else {
302
+ changeParameter(pp ,' QCidx' ,' pre-treatment' ) <- QCidx
303
+ }
304
+
305
+ changeParameter(pp ,' cls' ,' pre-treatment' ) <- cls
306
+
307
+ return (pp )
275
308
})
276
309
277
310
# ' @rdname detectPretreatmentParameters
278
311
279
312
setMethod ('detectPretreatmentParameters ',signature = 'MetaboProfile',
280
- function (x ){
281
- detectPretreatment(x )
313
+ function (x ,cls = ' class' ,QCidx = ' QC' ){
314
+ pp <- detectPretreatment(x )
315
+
316
+ sample_info <- profilePro :: sampleInfo(x )
317
+
318
+ if (! detectQC(sample_info ,cls ,QCidx )){
319
+ parameters(pp ,' pre-treatment' )$ QC <- NULL
320
+ } else {
321
+ changeParameter(pp ,' QCidx' ,' pre-treatment' ) <- QCidx
322
+ }
323
+
324
+ changeParameter(pp ,' cls' ,' pre-treatment' ) <- cls
325
+
326
+ return (pp )
282
327
})
283
328
284
329
# ' @importFrom metabolyseR parameters<- parameters
@@ -314,6 +359,10 @@ detectPretreatment <- function(x){
314
359
return (pre_treat_params )
315
360
}
316
361
362
+ detectQC <- function (sample_info ,cls ,QCidx ){
363
+ any(str_detect(sample_info [[cls ]],' QC' ))
364
+ }
365
+
317
366
# ' Detect modelling parameters
318
367
# ' @rdname detectModellingParameters
319
368
# ' @description Detect modelling parameters for `Binalysis`, `MetaboProfile` or `Analysis` S4 classes.
@@ -366,17 +415,17 @@ setMethod('detectModellingParameters',signature = 'Binalysis',
366
415
367
416
setMethod ('detectModellingParameters ',signature = 'MetaboProfile',
368
417
function (x ){
369
- idx <- x %> %
370
- processingParameters() %> %
371
- . $ info %> %
372
- . $ cls
373
-
374
- sample_information <- x %> %
375
- profilePro :: sampleInfo() %> %
376
- select(all_of(idx )) %> %
377
- deframe()
378
-
379
- detectModelling(sample_information ,idx )
418
+ idx <- x %> %
419
+ processingParameters() %> %
420
+ . $ info %> %
421
+ . $ cls
422
+
423
+ sample_information <- x %> %
424
+ profilePro :: sampleInfo() %> %
425
+ select(all_of(idx )) %> %
426
+ deframe()
427
+
428
+ detectModelling(sample_information ,idx )
380
429
})
381
430
382
431
# ' @rdname detectModellingParameters
0 commit comments