R/change_params_small.R

Defines functions change_params_small

Documented in change_params_small

#' @title Change Params Small
#'
#' @description This function helps changing convenience parameters.
#'
#' @include create_dir.R
#' @include get_default_paths.R
#' @include go_to_cache.R
#' @include load_yaml_files.R
#'
#' @param fil_pat The pattern identifying your whole job. You can put whatever you want. STRING
#' @param fil_fea_raw The path to the file containing your features' intensities. Can be generated by mzmine3 or SLAW. STRING
#' @param fil_met_raw The path to the file containing your metadata. If your experiment contains a single taxon, you can provide it below instead. STRING
#' @param fil_sir_raw The directory containing the sirius annotations. STRING
#' @param fil_spe_raw The path to the file containing your features' spectra. Can contain MS1 and/or MS2 spectra. STRING
#' @param ms_pol The polarity used. Must be either "pos" or "neg". STRING
#' @param org_tax If your experiment contains a single taxon, its scientific name. "Homo sapiens". STRING
#' @param hig_con Filter high confidence candidates only. BOOLEAN
#' @param summarise Summarize all candidates per feature to a single row. BOOLEAN
#'
#' @export
#'
#' @return YAML file with changed parameters.
#'
#' @examples
#' \dontrun{
#' tima:::copy_backbone()
#' tima::change_params_small(
#'   fil_pat = "myExamplePattern",
#'   fil_fea_raw = "myExampleDir/myExampleFeatures.csv",
#'   fil_met_raw = "myExampleDir2SomeWhereElse/myOptionalMetadata.tsv",
#'   fil_sir_raw = "myExampleDir3/myAwesomeSiriusProject.zip",
#'   fil_spe_raw = "myBeautifulSpectra.mgf",
#'   ms_pol = "pos",
#'   org_tax = "Gentiana lutea",
#'   hig_con = TRUE,
#'   summarise = FALSE
#' )
#' }
change_params_small <- function(fil_pat = NULL,
                                fil_fea_raw = NULL,
                                fil_met_raw = NULL,
                                fil_sir_raw = NULL,
                                fil_spe_raw = NULL,
                                ms_pol = NULL,
                                org_tax = NULL,
                                hig_con = NULL,
                                summarise = NULL) {
  tima:::go_to_cache()
  paths_data_source <- tima:::get_default_paths()$data$source$path
  paths_data_interim_annotations <-
    tima:::get_default_paths()$data$interim$annotations$path
  tima:::create_dir(paths_data_source)
  list <- tima:::load_yaml_files()

  yamls_params <- list$yamls_params
  yaml_files <- list$yaml_files
  yaml_names <- list$yaml_names

  yaml_small <- yamls_params[["params/prepare_params"]]
  if (!is.null(fil_pat)) {
    yaml_small$files$pattern <- fil_pat
  }
  if (!is.null(fil_fea_raw)) {
    stopifnot("Your features' file does not exist" = file.exists(fil_fea_raw))
    fil_fea_raw_rdy <- paths_data_source |>
      file.path(basename(fil_fea_raw))
    fs::file_copy(
      path = fil_fea_raw,
      new_path = fil_fea_raw_rdy,
      overwrite = TRUE
    )
    yaml_small$files$features$raw <- fil_fea_raw_rdy
  }
  if (!is.null(fil_met_raw)) {
    stopifnot("Your metadata file does not exist" = file.exists(fil_met_raw))
    fil_met_raw_rdy <- paths_data_source |>
      file.path(basename(fil_met_raw))
    fs::file_copy(
      path = fil_met_raw,
      new_path = fil_met_raw_rdy,
      overwrite = TRUE
    )
    yaml_small$files$metadata$raw <- fil_met_raw_rdy
  }
  if (!is.null(fil_sir_raw)) {
    stopifnot("Your sirius directory does not exist" = file.exists(fil_sir_raw))
    fil_sir_raw_rdy <- paths_data_interim_annotations |>
      file.path(basename(fil_sir_raw))
    fs::file_copy(
      path = fil_sir_raw,
      new_path = fil_sir_raw_rdy,
      overwrite = TRUE
    )
    yaml_small$files$annotations$raw$sirius <- fil_sir_raw_rdy
  }
  if (!is.null(fil_spe_raw)) {
    stopifnot("Your spectra file does not exist" = file.exists(fil_spe_raw))
    fil_spe_raw_rdy <- paths_data_source |>
      file.path(basename(fil_spe_raw))
    fs::file_copy(
      path = fil_spe_raw,
      new_path = fil_spe_raw_rdy,
      overwrite = TRUE
    )
    yaml_small$files$spectral$raw <- fil_spe_raw_rdy
  }
  if (!is.null(ms_pol)) {
    yaml_small$ms$polarity <- ms_pol
  }
  if (!is.null(org_tax)) {
    yaml_small$organisms$taxon <- org_tax
  }
  if (!is.null(hig_con)) {
    yaml_small$options$high_confidence <- hig_con
  }
  if (!is.null(summarise)) {
    yaml_small$options$summarise <- summarise
  }

  yaml::write_yaml(
    x = yaml_small,
    file = tima:::get_default_paths()$params$prepare_params
  )
}
taxonomicallyinformedannotation/tima-r documentation built on Nov. 20, 2024, 4:34 a.m.