Last updated: 2022-08-03

Checks: 7 0

Knit directory: cassavabaseembrapa/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20220609) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 8c657ff. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  definição plot name.txt
    Untracked:  dúvidas_cassavabase.txt

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/index.Rmd) and HTML (docs/index.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 8c657ff WevertonGomesCosta 2022-08-03 workflowr::wflow_publish(files = "*")
html 8c657ff WevertonGomesCosta 2022-08-03 workflowr::wflow_publish(files = "*")
html 2c708e7 WevertonGomesCosta 2022-06-09 Build site.
Rmd 95893ae WevertonGomesCosta 2022-06-09 Start workflowr project.

Automation process to insertion betwen trials on cassavabase

Loading data

library(tidyverse)
-- Attaching packages --------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.6     v purrr   0.3.4
v tibble  3.1.7     v dplyr   1.0.9
v tidyr   1.2.0     v stringr 1.4.0
v readr   2.1.2     v forcats 0.5.1
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
library(readxl)

trials_in_cassava_base <-
  read_excel("data/Trials-in-cassava-base.xlsx") ## Trials already in cassavabase

acessions_in_cassava_base <- read_excel("data/sinonimous.xlsx") ## accesses and synonyms already in cassavabase

abreviation_trials <-
  read_excel("data/locais e siglas dos experimentos 2021.xlsx") ## trial abbreviations

my_col_types = c(
  "numeric",
  rep("text", 7),
  rep("numeric", 69),
  rep("text", 4),
  rep("numeric", 8),
  "text"
)  ## Classes of the columns of the complete dataset

trial_to_insert <-
  read_excel("data/plot_name.xlsx", na = "NA", col_types = my_col_types)  ## Complete dataset

Converting columns to factors and excluding columns with no information

trials_in_cassava_base <- trials_in_cassava_base %>%
  mutate_if(is.character, as.factor) %>%
  mutate_if(is.numeric, as.factor) %>%
  select(where( ~ n_distinct(.) > 1))

trial_to_insert <- trial_to_insert %>%
  mutate_if(is.character, as.factor) %>%
  mutate_if(is.numeric, as.factor) %>%
  select(where( ~ n_distinct(.) > 1))

abreviation_trials <- abreviation_trials %>%
  mutate(Local = toupper(Local)) %>%
  mutate_if(is.character, as.factor) %>%
  mutate_if(is.numeric, as.factor) %>%
  select(where( ~ n_distinct(.) > 1))

Summary of the data to be inserted in cassabase to MUNICÍPIO, LOCAL, CAMPO and BREEDING STAGE

resumo_mun <- trial_to_insert %>%
  group_by(Município, Local, Campo, `Breeding stage`) %>%
  tally()

writexl::write_xlsx(resumo_mun, "data/resumo_mun.xlsx")

Joining trial_to_insert and abreviation_trials datasets according to LOCAL.

trial_to_insert2 <- trial_to_insert %>%
  left_join(abreviation_trials, by = "Local")

Creating datasets with private information from waxy, 16cm and 8MP experiments. This to create the trial_name and trial_name_suggest, with this information. Then we put together in the dataset trial_names_differ these experiments.

trial1 <- trial_to_insert2 %>%
  group_by(Ano, `Breeding stage`, Abbreviation, Campo, Waxy) %>%
  tally() %>%
  filter(Waxy == "SIM") %>%
  mutate(
    trial_name = paste(
      "BR",
      `Breeding stage`,
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    ),
    trial_name_suggest = paste(
      "BR",
      paste(`Breeding stage`, "Wx", sep = ""),
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    )
  ) %>%
  ungroup()

trial2 <- trial_to_insert2 %>%
  group_by(Ano, `Breeding stage`, Abbreviation, Campo) %>%
  tally() %>%
  filter(str_detect(as.character(Campo), "16CM")) %>%
  mutate(
    trial_name = paste(
      "BR",
      `Breeding stage`,
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    ),
    trial_name_suggest = paste(
      "BR",
      paste(`Breeding stage`, "16CM", sep = ""),
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    )
  ) %>%
  ungroup()

trial3 <- trial_to_insert2 %>%
  group_by(Ano, `Breeding stage`, Abbreviation, Campo) %>%
  tally() %>%
  filter(str_detect(as.character(Campo), "8MP")) %>%
  mutate(
    trial_name = paste(
      "BR",
      `Breeding stage`,
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    ),
    trial_name_suggest = paste(
      "BR",
      paste(`Breeding stage`, "8MP", sep = ""),
      as.numeric(as.character(Ano)) - 2001,
      Abbreviation,
      sep = "."
    )
  ) %>%
  ungroup()

trial_names_differ <- trial1 %>%
  full_join(trial2) %>%
  full_join(trial3)
Joining, by = c("Ano", "Breeding stage", "Abbreviation", "Campo", "n",
"trial_name", "trial_name_suggest")
Joining, by = c("Ano", "Breeding stage", "Abbreviation", "Campo", "n",
"trial_name", "trial_name_suggest")

Now join the trial_to_insert2 dataset with the trial_names_differ. Then we corrected the names of the genotypes by adding BR, we created the other trial_name and the trial_name_suggest. We check which trials and accesses are already in cassavabase, creating the trial_inserted_in_cassava and acces_in_cassava columns and also check that the trial names are as we suggest. Finally we create the plot_name_suggest column.

trial_to_insert3 <- trial_to_insert2 %>%
  full_join(trial_names_differ[-6]) %>%
  mutate(
    Genotipo = str_replace_all(Genotipo, c("2011" = "BR-11", "2012" = "BR-12")),
    trial_name = if_else(
      is.na(trial_name),
      paste(
        "BR",
        `Breeding stage`,
        as.numeric(as.character(Ano)) - 2001,
        Abbreviation,
        sep = "."
      ),
      trial_name
    ),
    trial_name_suggest = if_else(is.na(trial_name_suggest), trial_name, trial_name_suggest),
    trial_inserted_in_cassava = if_else(
      trial_name %in% levels(trials_in_cassava_base$`Trial name`) |
        Campo %in% levels(trials_in_cassava_base$`Trial name`) |
        trial_name_suggest %in% levels(trials_in_cassava_base$`Trial name`),
      "yes",
      "no"
    ) ,
    correct_trial_inserted_in_cassava = if_else(
      trial_name_suggest %in% levels(trials_in_cassava_base$`Trial name`),
      "yes",
      "no"
    ),
    acces_in_cassava = if_else(
      Genotipo %in% acessions_in_cassava_base$`germplasmName (Stock_Name)`,
      "yes",
      "no"
    ),
    plot_name_suggest =
      paste(trial_name_suggest, Genotipo, Plot, sep = "-")
  )
Joining, by = c("Ano", "Breeding stage", "Campo", "Waxy", "Abbreviation")

Summary of trials to conference

trials <- trial_to_insert3 %>%
  group_by(
    Ano,
    `Breeding stage`,
    Abbreviation,
    Campo,
    trial_name,
    trial_name_suggest,
    trial_inserted_in_cassava,
    correct_trial_inserted_in_cassava
  ) %>%
  tally()

writexl::write_xlsx(trials, "data/resumo_trials4.xlsx")

Summary of acess to conference

acess <- trial_to_insert3 %>%
  group_by(Genotipo, acces_in_cassava) %>%
  tally()

writexl::write_xlsx(acess, "data/resumo_acess3.xlsx")

Indicating which cultivars are used to create the is_control column in the final dataset of the trials.

cultivars<-c("Aipim Abacate",
"Baianinha-MS",
"BRS Caipira",
"BRS CS01",
"BRS Dourada",
"BRS Formosa",
"BRS Gema de Ovo",
"BRS Jari",
"BRS Kiriris",
"BRS Mulatinha",
"BRS Novo Horizonte",
"BRS Poti Branca",
"BRS Tapioqueira",
"BRS Verdinha",
"Cacau",
"Cascuda",
"Cigana Preta",
"Correntao",
"Corrente",
"Eucalipto",
"Fecula Branca",
"IAC-12",
"IAC-14",
"IAC-576",
"IAC-90",
"Mani Branca",
"Nega Maluca",
"Olho Junto",
"Pioneira",
"Salangor",
"Tailandia",
"Valencia",
"Vassoura Preta"
)

Loop to create trial files separately

for(i in levels(factor(trial_to_insert3$trial_name_suggest))) {
  creating_trials <- trial_to_insert3 %>%
    group_by(plot_name_suggest,
             Genotipo,
             Plot,
             Bloco,
             row_number,
             col_number) %>%
    filter(trial_inserted_in_cassava == "no" &
             trial_name_suggest == i) %>%
    mutate(
      is_a_control = if_else(Genotipo %in% cultivars, 1, 0))%>%
    select(plot_name_suggest,
           Genotipo,
           Plot,
           Bloco,
           is_a_control,
           row_number,
           col_number)
  
      creating_trials["is_a_control"][creating_trials["is_a_control"] == 0] <- NA
      
      colnames(creating_trials) <-
        c(
          "plot_name",
          "accession_name",
          "plot_number",
          "block_number",
          "is_a_control",
          "row_number",
          "col_number"
        )
      
      writexl::write_xlsx(creating_trials, paste("output/", i, ".xlsx", sep =""))
}

Creating the access phenotypic data file

creating_acess <- trial_to_insert3 %>%
  filter(trial_inserted_in_cassava == "no") %>%
  select(plot_name_suggest, 13:72) %>% 
  rename(observationunit_name = plot_name_suggest)

writexl::write_xlsx(creating_acess, "output/acess_pheno.xlsx")

sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] readxl_1.4.0    forcats_0.5.1   stringr_1.4.0   dplyr_1.0.9    
 [5] purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.7   
 [9] ggplot2_3.3.6   tidyverse_1.3.1 workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3     lubridate_1.8.0  getPass_0.2-2    ps_1.6.0        
 [5] assertthat_0.2.1 rprojroot_2.0.3  digest_0.6.29    utf8_1.2.2      
 [9] R6_2.5.1         cellranger_1.1.0 backports_1.4.1  reprex_2.0.1    
[13] evaluate_0.15    httr_1.4.3       pillar_1.7.0     rlang_1.0.4     
[17] rstudioapi_0.13  whisker_0.4      callr_3.7.0      jquerylib_0.1.4 
[21] rmarkdown_2.14   munsell_0.5.0    broom_1.0.0      compiler_4.1.3  
[25] httpuv_1.6.5     modelr_0.1.8     xfun_0.30        pkgconfig_2.0.3 
[29] htmltools_0.5.2  tidyselect_1.1.2 fansi_1.0.3      withr_2.5.0     
[33] crayon_1.5.1     tzdb_0.3.0       dbplyr_2.2.1     later_1.3.0     
[37] grid_4.1.3       jsonlite_1.8.0   gtable_0.3.0     lifecycle_1.0.1 
[41] DBI_1.1.3        git2r_0.30.1     magrittr_2.0.3   scales_1.2.0    
[45] writexl_1.4.0    cli_3.3.0        stringi_1.7.6    fs_1.5.2        
[49] promises_1.2.0.1 xml2_1.3.3       bslib_0.3.1      ellipsis_0.3.2  
[53] generics_0.1.3   vctrs_0.4.1      tools_4.1.3      glue_1.6.2      
[57] hms_1.1.1        processx_3.5.3   fastmap_1.1.0    yaml_2.3.5      
[61] colorspace_2.0-3 rvest_1.0.2      knitr_1.39       haven_2.5.0     
[65] sass_0.4.1