Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed May 18, 2022
1 parent 20a0d40 commit 4a19984
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
65 changes: 65 additions & 0 deletions R/make_other.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require(dplyr)

#' Title
#'
#' @param dataframe
#' @param value
#'
#' @return
#' @export
#'
#' @examples
make_other <- function(dataframe, value = "peak_area") {
top_4 <- dataframe |>
dplyr::group_by(best_candidate_1, best_candidate_2) |>
dplyr::mutate(new = sum(!!as.name(value))) |>
dplyr::distinct(new, .keep_all = TRUE) |>
dplyr::group_by(best_candidate_1) |>
dplyr::slice_max(new, n = 4, with_ties = FALSE) |>
dplyr::ungroup() |>
dplyr::select(
smiles_2D,
inchikey_2D,
best_candidate_1,
best_candidate_2,
best_candidate_3
) |>
dplyr::distinct()

last <- dataframe |>
dplyr::ungroup() |>
dplyr::anti_join(
top_4,
by = c(
"best_candidate_1" = "best_candidate_1",
"best_candidate_2" = "best_candidate_2"
)
) |>
dplyr::mutate(best_candidate_2 = "Other") |>
dplyr::select(
smiles_2D,
inchikey_2D,
best_candidate_1,
best_candidate_2,
best_candidate_3
) |>
dplyr::distinct()

new <- dplyr::bind_rows(
top_4,
last
) |>
dplyr::select(
-smiles_2D,
-inchikey_2D
)

df_new <- dataframe |>
dplyr::select(
-best_candidate_1,
-best_candidate_2
) |>
dplyr::left_join(new)

return(df_new)
}
20 changes: 20 additions & 0 deletions R/no_other.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require(dplyr)

#' Title
#'
#' @param dataframe
#'
#' @return
#' @export
#'
#' @examples
no_other <- function(dataframe) {
dataframe_no_other <- dataframe |>
dplyr::filter(!grepl(
pattern = "not",
x = best_candidate_1
) &
!is.na(best_candidate_1))

return(dataframe_no_other)
}
11 changes: 6 additions & 5 deletions inst/scripts/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ source(file = "R/get_gnps.R")
source(file = "R/get_params.R")
source(file = "R/log_debug.R")
source(file = "R/make_confident.R")
source(file = "R/make_other.R")
source(file = "R/no_other.R")
source(file = "R/parse_cli_params.R")
source(file = "R/parse_yaml_params.R")
Expand Down Expand Up @@ -213,17 +214,21 @@ log_debug(x = "keeping peaks similarities with score above", PEAK_SIMILARITY)
df_new_with_cor <- df_new_with_cor_pre_taxo |>
dplyr::filter(comparison_score >= PEAK_SIMILARITY)

#' TODO limit to 5 as for hierarchy
log_debug(x = "plotting histograms")
#' TODO harmonize 'others' among minor and major
df_histogram_ready <- df_new_with_cor_pre_taxo |>
make_other() |>
prepare_plot_2()
df_histogram_outside_ready <- df_peaks_samples_min |>
make_other() |>
prepare_plot_2()

df_histogram_ready_conf <- df_new_with_cor_pre_taxo |>
make_other() |>
no_other() |>
prepare_plot_2()
df_histogram_outside_ready_conf <- df_peaks_samples_min |>
make_other() |>
no_other() |>
prepare_plot_2()

Expand Down Expand Up @@ -292,10 +297,6 @@ plotly::plot_ly(
plotly::layout(colorway = sunburst_colors)


#' TODO minor peaks
#' TODO change MS for counts


#' Work in progress
#' Add some metadata per peak
df_meta <- df_new_with_cor_pre_taxo |>
Expand Down

0 comments on commit 4a19984

Please sign in to comment.