-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignMFs.R
59 lines (53 loc) · 1.68 KB
/
assignMFs.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
#' assignMFs
#' @description assign molecular formulas to a set of given m/z.
#' @param dat tibble containing the peak intensities of m/z for which to assign molecular formulas
#' @param parameters an S4 object of class AssignmentParamters containing the parameters for molecular formula assignment
#' @param verbose should output be printed to the console
#' @importFrom tibble tibble
#' @importFrom stringr str_split_fixed
#' @importFrom cli console_width
#' @importFrom lubridate seconds_to_period
#' @importFrom utils capture.output
#' @examples
#' plan(future::sequential)
#' p <- assignmentParameters('FIE')
#'
#' assignment <- assignMFs(peakData,p)
#'
#' @export
assignMFs <- function(dat,parameters,verbose = TRUE) {
options(digits = 10)
if (verbose == TRUE) {
startTime <- proc.time()
message(blue('\nMFassign '),red(str_c('v',packageVersion('MFassign') %>% as.character())),' ',date())
message(rep('_',console_width()))
params <- parameters %>%
{capture.output(print(.))} %>%
{.[-1]} %>%
{
.[1] <- yellow(.[1])
.
} %>%
str_c(collapse = '\n')
message(params)
message(rep('_',console_width()),'\n')
message('No. m/z:\t',ncol(dat),'\n')
}
assignment <- new('Assignment',
data = dat,
parameters = parameters)
assignment@log$verbose <- verbose
assignment <- assignment %>%
doAssignment()
if (verbose == T) {
endTime <- proc.time()
elapsed <- {endTime - startTime} %>%
.[3] %>%
round(1) %>%
seconds_to_period() %>%
str_c('[',.,']')
message(rep('_',console_width()))
message('\n',green('Complete! '),elapsed,'\n')
}
return(assignment)
}