diff --git a/NAMESPACE b/NAMESPACE index d45300f..d4383eb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(fit_3_exp) export(fix_class_result) export(get_example_control) export(get_example_fit_k_params) +export(get_example_fit_k_params_2) export(get_fit_results) export(get_fit_values_info) export(get_params_summary_image) diff --git a/R/calculate_hires.R b/R/calculate_hires.R index a130aaf..21692d0 100644 --- a/R/calculate_hires.R +++ b/R/calculate_hires.R @@ -40,6 +40,7 @@ calculate_hires <- function(fit_values, } tmp_params <- tmp_params %>% + filter(!class_name %in% c("invalid", "invalid_uc")) %>% arrange(nchar(sequence), class_name) %>% .[1, ] @@ -119,13 +120,13 @@ calculate_hires <- function(fit_values, res <- data.frame(Protein = Protein, State = State, position = pos, - n_1 = NA, - k_1 = NA, - n_2 = NA, - k_2 = NA, - n_3 = NA, - k_3 = NA, - k_est = NA, + n_1 = class_example[["n_1"]], + k_1 = class_example[["k_1"]], + n_2 = class_example[["n_2"]], + k_2 = class_example[["k_3"]], + n_3 = class_example[["n_3"]], + k_3 = class_example[["k_3"]], + k_est = class_example[["k_est"]], class_name = class_example[["class_name"]], color = class_example[["color"]]) diff --git a/R/create_fit_dataset.R b/R/create_fit_dataset.R index 4c47140..4839413 100644 --- a/R/create_fit_dataset.R +++ b/R/create_fit_dataset.R @@ -28,6 +28,7 @@ create_fit_dataset <- function(kin_dat, control = list(maxiter = 1000, scale = "levenberg"), trace = FALSE, fractional = FALSE, + omit_t_100 = FALSE, workflow = 321){ peptide_list <- kin_dat %>% @@ -47,6 +48,7 @@ create_fit_dataset <- function(kin_dat, trace = trace, workflow = workflow, fractional = fractional, + omit_t_100 = omit_t_100, edge_times = edge_times) }) %>% bind_rows() %>% mutate(id = 1:nrow(.)) %>% remove_rownames(.) %>% select(id, everything()) diff --git a/R/get_fit_results.R b/R/get_fit_results.R index 83ed060..5e71672 100644 --- a/R/get_fit_results.R +++ b/R/get_fit_results.R @@ -5,6 +5,7 @@ get_fit_results <- function(fit_dat, trace = FALSE, workflow = 31, fractional = TRUE, + omit_t_100 = FALSE, edge_times = c(min(fit_dat[["Exposure"]]), max(fit_dat[["Exposure"]]))){ workflow <- match.arg(as.character(workflow), choices = c(31, 21, 321)) @@ -27,6 +28,11 @@ get_fit_results <- function(fit_dat, fit_k_params)) } + if(omit_t_100){ + time_100 <- attr(fit_dat, "time_100") + fit_dat <- filter(fit_dat, Exposure < time_100) + } + if(workflow == 31){ fit_3 <- fit_3_exp(fit_dat, @@ -145,7 +151,7 @@ fix_class_result <- function(fit_dat, color = "#000000" } - if(class_name == "invalid"){ + if(class_name %in% c("invalid", "invalid_uc")){ k_1 = n_1 = k_2 = n_2 = k_3 = n_3 = NA color = "#808080" } @@ -200,6 +206,9 @@ detect_class <- function(fit_dat, edge_times = NULL){ if(du_100/ max_uptake < threshold & du_100 < 1) return("none") # if((du_100 - du_1)/max_uptake < threshold & du_1 / du_100 > 1 - threshold) return("immediate") + accepted_fluctuation = 0.5 ## 0.5 Da doesnt significate exchange + if(du_100 < du_1 & !all(fit_dat[["deut_uptake"]] - du_100 < 0.5)) return("invalid_uc") + class_name } diff --git a/R/getters.R b/R/getters.R index d22ae4a..8510a88 100644 --- a/R/getters.R +++ b/R/getters.R @@ -11,6 +11,19 @@ get_example_fit_k_params <- function(){ } +#' Example k parameters +#' +#' @export + +get_example_fit_k_params_2 <- function(){ + + return(data.frame( + start = c(k_1 = 2, k_2 = 0.2, k_3 = 0.02), + lower = c(k_1 = 1, k_2 = 0.1, k_3 = 0.0001), + upper = c(k_1 = 30, k_2 = 1, k_3 = 0.1))) + +} + #' Example control #' #' @export @@ -88,7 +101,7 @@ get_3_n_params <- function(fractional = TRUE, data.frame( start = c(n_1 = MaxUptake/3, n_2 = MaxUptake/3, n_3 = MaxUptake/3), - lower = c(n_1 = 0, n_2 = 0, n_3 = 0), + lower = c(n_1 = 1, n_2 = 1, n_3 = 1), upper = c(n_1 = MaxUptake, n_2 = MaxUptake, n_3 = MaxUptake) ) @@ -122,7 +135,7 @@ get_2_n_params <- function(fractional = TRUE, data.frame( start = c(n_1 = MaxUptake/2, n_2 = MaxUptake/2), - lower = c(n_1 = 0, n_2 = 0), + lower = c(n_1 = 1, n_2 = 1), upper = c(n_1 = MaxUptake, n_2 = MaxUptake) ) } @@ -155,7 +168,7 @@ get_1_n_params <- function(fractional = TRUE, data.frame( start = c(n_1 = MaxUptake*0.7), - lower = c(n_1 = 0), + lower = c(n_1 = 1), upper = c(n_1 = MaxUptake) ) diff --git a/R/recreate_uc.R b/R/recreate_uc.R index 781e6b8..fc0c378 100644 --- a/R/recreate_uc.R +++ b/R/recreate_uc.R @@ -8,6 +8,16 @@ #' @description This function recovers fractional deuterium uptake from high-resolution level #' back to the peptide level. First, the values are aggregated into high-resolution #' level using selected aggregation method. +#' If there are no calculated recovered values, probably the peptide was calssified as +#' invalid - check that in fit_values_all param to be sure. +#' +#' @examples +#' kin_dat <- prepare_kin_dat(alpha_dat) +#' fit_values_all <- create_fit_dataset(kin_dat, control = get_example_control(), +#' fit_k_params = get_example_fit_k_params_2(), +#' fractional = TRUE) +#' fit_dat <- kin_dat[kin_dat[["ID"]] == 54, ] +#' calculate_uc_from_hires_peptide(fit_dat, fit_values_all, hires_method = "weighted") #' #' @seealso #' \code{\link{create_uc_from_hires_dataset}} @@ -59,7 +69,6 @@ calculate_uc_from_hires_peptide <- function(fit_dat, ## uc filtered dat hr_diff = deut_uptake - hr_deut_uptake) } - return(res) } diff --git a/man/calculate_uc_from_hires_peptide.Rd b/man/calculate_uc_from_hires_peptide.Rd index 591f125..f1d69bd 100644 --- a/man/calculate_uc_from_hires_peptide.Rd +++ b/man/calculate_uc_from_hires_peptide.Rd @@ -25,6 +25,17 @@ calculate_uc_from_hires_peptide( This function recovers fractional deuterium uptake from high-resolution level back to the peptide level. First, the values are aggregated into high-resolution level using selected aggregation method. +If there are no calculated recovered values, probably the peptide was calssified as +invalid - check that in fit_values_all param to be sure. +} +\examples{ +kin_dat <- prepare_kin_dat(alpha_dat) +fit_values_all <- create_fit_dataset(kin_dat, control = get_example_control(), + fit_k_params = get_example_fit_k_params_2(), + fractional = TRUE) +fit_dat <- kin_dat[kin_dat[["ID"]] == 54, ] +calculate_uc_from_hires_peptide(fit_dat, fit_values_all, hires_method = "weighted") + } \seealso{ \code{\link{create_uc_from_hires_dataset}} diff --git a/man/create_fit_dataset.Rd b/man/create_fit_dataset.Rd index ba0003d..935e225 100644 --- a/man/create_fit_dataset.Rd +++ b/man/create_fit_dataset.Rd @@ -10,6 +10,7 @@ create_fit_dataset( control = list(maxiter = 1000, scale = "levenberg"), trace = FALSE, fractional = FALSE, + omit_t_100 = FALSE, workflow = 321 ) } diff --git a/man/get_example_fit_k_params_2.Rd b/man/get_example_fit_k_params_2.Rd new file mode 100644 index 0000000..09f2d80 --- /dev/null +++ b/man/get_example_fit_k_params_2.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getters.R +\name{get_example_fit_k_params_2} +\alias{get_example_fit_k_params_2} +\title{Example k parameters} +\usage{ +get_example_fit_k_params_2() +} +\description{ +Example k parameters +}