/
allClasses.R
99 lines (87 loc) · 3.01 KB
/
allClasses.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
#' Profile processing parameters class
#' @description An S4 class to store profile processing parameters.
#' @slot technique the profiling technique to use. Defaults to the result of \code{availableTechniques()[1]}
#' @slot processing_parameters a list containing the parameters to use for processing
#' @export
setClass('ProfileParameters',
slots = list(
technique = 'character',
processing_parameters = 'list'
),
prototype = list(
technique = availableTechniques()[1]
)
)
setValidity('ProfileParameters',function(object){
if (!(object@technique %in% availableTechniques())) {
str_c('Technique should be one of ',
str_c(availableTechniques(),collapse = ', '),
'.')
} else {
return(TRUE)
}
})
#' Profiling processing results class
#' @description An S4 class to store the profile processing results
#' @slot version package version
#' @slot creation_date date and time of the initiation of processing
#' @slot file_paths list of file paths to used for processing. Vectors of files form different aquisition modes should be labelled accordingly.
#' @slot processing_parameters object of class ProfileParameters containing the parameters for processing
#' @slot sample_info tibble containing runinfo data
#' @slot data list containing tibbles of processed data
#' @slot processing_results list containing processing results
#' @importFrom utils packageVersion
#' @export
setClass('MetaboProfile',
slots = list(
version = 'character',
creation_date = 'character',
file_paths = 'character',
sample_info = 'tbl_df',
data = 'list',
processing_results = 'list'
),
contains = 'ProfileParameters',
prototype = list(
version = packageVersion('profilePro') %>%
as.character(),
creation_date = date(),
sample_info = tibble(
fileOrder = character(),
injOrder = numeric(),
fileName = character(),
batch = numeric(),
block = numeric(),
name = character(),
class = character()
)
)
)
setValidity('MetaboProfile',function(object){
necessary_names <- c('fileOrder','injOrder','fileName','batch','block','name','class')
info_names <- object %>%
sampleInfo() %>%
colnames()
presence <- necessary_names %in% info_names
if (FALSE %in% presence) {
str_c('Sample information should contain the following column names: ',
str_c(necessary_names,collapse = ', '),
'.')
} else {
TRUE
}
})
setValidity('MetaboProfile',function(object){
file_path_names <- object %>%
filePaths() %>%
basename()
info_file_names <- object %>%
sampleInfo() %>%
.$fileName
matching <- file_path_names == info_file_names
if (length(matching) == 0 | FALSE %in% matching) {
'File names in paths do not match file names in the sample information.'
} else {
TRUE
}
})