Skip to content
Snippets Groups Projects
Select Git revision
  • 690eaa85e42df38876e21adb642eb56e8bfd100f
  • main default protected
  • cqc
  • revert-8c34924c
4 results

.Rhistory

  • micwij's avatar
    Micha Wijesingha Ahchige authored
    690eaa85
    History
    .Rhistory 8.59 KiB
    rm(list = ls())
    library(openxlsx)
    library(tidyverse)
    library(car)
    library(pheatmap)
    library(broom)
    library(ggpubr)
    library(viridisLite)
    library(modelr)
    #library(dlookr)
    #library(imputeLCMD)
    library(ggrepel)
    here::i_am("workflows/GC_MS_normalization/210927_primary_normalization_with_split.R")
    library(here)
    out <- here("runs/GC-MS normalization")
    if (file.exists(out)) {
    cat("The folder already exists")
    } else {
    dir.create(out)
    }
    setwd(here())# Not recommended but convenient in Rstudio to start from root
    sam_dat1 <- readxl::read_xlsx(here("studies/cmQTL_val1_GH_2020/isa.study.xlsx"))
    View(sam_dat1)
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = str_extract(`Factor [sample fresh weight]`, "^\\d{2},\\d{2}"))
    View(sam_dat1_tidy)
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = str_extract(`Factor [sample fresh weight]`, "\\d{2},\\d{2}"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}")))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(str_remove(Parameter))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(str_remove("Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(str_remove(pattern = "Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(str_remove(string = .x, pattern = "Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), str_remove(string = .x, pattern = "Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = str_remove(string = .x, pattern = "Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter"))
    View(sam_dat1_tidy)
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "\\w"), replacement = "_")
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "\\w", replacement = "_"))
    ?stringr
    View(sam_dat1_tidy)
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "\\s", replacement = "_"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter [")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic [")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    sam_dat1_tidy <- GC_run1 %>%
    left_join(GC_machine_nums) %>%
    select(extraction_num = `Sample name`, everything())%>%
    mutate(class = as_factor(if_else(str_detect(extraction_num, "run_qc"), "run_qc",
    if_else(str_detect(extraction_num, "blank"), "blank", "sample"))),
    extraction_num = as.numeric(if_else(str_detect(extraction_num, "run_qc"), "0",
    if_else(str_detect(extraction_num, "blank"), "-1",extraction_num))),
    exp = as_factor(1)) %>%
    left_join(sam_dat1) %>%
    left_join(genotypes) %>%
    select(treatment = irrigation, everything()) %>%
    select(all_of(sam_vars)) %>%
    arrange(run_num_GC)
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter [")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic [")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Factor \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    sam_dat1_tidy <- sam_dat1 %>%
    mutate(sample_weight = as.double(str_extract(`Factor [sample fresh weight]`, "\\d{2}\\.\\d{2}"))) %>%
    rename(source_name = `Source Name`) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Parameter \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Characteristic \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "Factor \\[")) %>%
    rename_with(.cols = everything(), .fn = ~str_remove(string = .x, pattern = "\\]")) %>%
    rename_with(.cols = everything(), .fn = ~str_replace_all(string = .x, pattern = "[:blank:]", replacement = "_"))
    x <- c(1,2,3,4)
    y <- c("A", "B","C", "D")
    replace(x, c(3,2,1,4), y)
    colnames(sam_dat1_tidy)
    sam_dat1_tidy$`multi-tissue_plant_structure`