-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,117 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# timaR | ||
|
||
# timaR 2.9.0 | ||
|
||
* Refactored RT matching (#76) | ||
|
||
# timaR 2.8.2 | ||
|
||
* Change from pbmclapply to pblapply | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
utils::globalVariables(c("params")) | ||
|
||
#' @title Filter annotations | ||
#' | ||
#' @description This function filters initial annotations. | ||
#' | ||
#' @param annotations Prepared annotations file | ||
#' @param features Prepared features file | ||
#' @param rts Prepared retention time library | ||
#' @param output Output file | ||
#' @param tolerance_rt Tolerance to filter retention time | ||
#' @param parameters Params | ||
#' | ||
#' @return NULL | ||
#' | ||
#' @export | ||
#' | ||
#' @examples NULL | ||
filter_annotations <- | ||
function(annotations = params$files$annotations$prepared, | ||
features = params$files$features$prepared, | ||
rts = params$files$libraries$temporal$prepared, | ||
output = params$files$annotations$filtered, | ||
tolerance_rt = params$ms$tolerances$rt$minutes, | ||
parameters = params) { | ||
stopifnot( | ||
"Annotations file(s) do(es) not exist" = | ||
rep(TRUE, length(annotations)) == | ||
lapply(X = annotations, file.exists) | ||
) | ||
stopifnot( | ||
"Retention time file(s) do(es) not exist" = | ||
rep(TRUE, length(rts)) == | ||
lapply(X = rts, file.exists) | ||
) | ||
stopifnot("Your features file does not exist." = file.exists(features)) | ||
|
||
paths <<- parse_yaml_paths() | ||
params <<- parameters | ||
|
||
log_debug(x = "... features") | ||
features_table <- tidytable::fread( | ||
file = features, | ||
colClasses = "character", | ||
na.strings = c("", "NA") | ||
) | ||
log_debug(x = "... annotations") | ||
annotation_table <- lapply( | ||
X = annotations, | ||
FUN = tidytable::fread, | ||
colClasses = "character", | ||
na.strings = c("", "NA") | ||
) |> | ||
tidytable::bind_rows() | ||
log_debug(x = "... retention times") | ||
rt_table <- lapply( | ||
X = rts, | ||
FUN = tidytable::fread, | ||
colClasses = "character", | ||
na.strings = c("", "NA") | ||
) |> | ||
tidytable::bind_rows() |> | ||
tidytable::rename(rt_target = rt) | ||
|
||
log_debug( | ||
"Filtering annotations outside of", | ||
tolerance_rt * 3, | ||
"minutes tolerance" | ||
) | ||
features_annotated_table <- features_table |> | ||
tidytable::left_join(annotation_table) |> | ||
tidytable::left_join(rt_table) |> | ||
data.frame() |> | ||
dplyr::mutate(error_rt = as.numeric(rt) - as.numeric(rt_target)) |> | ||
dplyr::arrange(abs(error_rt)) |> | ||
tidytable::tidytable() |> | ||
tidytable::distinct(-error_rt, -rt_target, | ||
.keep_all = TRUE | ||
) |> | ||
data.frame() |> | ||
## TODO adapt for types and improve the * 3 | ||
dplyr::filter(abs(error_rt) <= abs(tolerance_rt * 3) | | ||
is.na(error_rt)) |> | ||
tidytable::tidytable() |> | ||
tidytable::select(-rt_target, -type) | ||
|
||
## in case some features had a single filtered annotation | ||
final_table <- features_table |> | ||
tidytable::left_join(features_annotated_table) | ||
|
||
export_params(step = "filter_annotations") | ||
export_output( | ||
x = final_table, | ||
file = output[[1]] | ||
) | ||
|
||
return(output[[1]]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.