# ReUseData: Reusable and Reproducible Data Management - quick start

Qian Liu, Qiang Hu, Song Liu, Alan Hutson, Martin Morgan1

1Roswell Park Comprehensive Cancer Center

#### 2023-07-31

# 1 Introduction

ReUseData is an R/Bioconductor software tool to provide a systematic and versatile approach for standardized and reproducible data management. ReUseData facilitates transformation of shell or other ad hoc scripts for data preprocessing into workflow-based data recipes. Evaluation of data recipes generate curated data files in their generic formats (e.g., VCF, bed). Both recipes and data are cached using database infrastructure for easy data management and reuse. Prebuilt data recipes are available through ReUseData portal (“https://rcwl.org/dataRecipes/”) with full annotation and user instructions. Pregenerated data are available through ReUseData cloud bucket that is directly downloadable through “getCloudData()”.

This quick start shows the basic use of package functions in 2 major categories for managing:

- Data recipes
- Reusable data

Details for each section can be found in the companion vignettes for data recipes and reusable data.

# 2 Package installation and loading

    BiocManager::install(c("ReUseData", "Rcwl"))

    library(ReUseData)

# 3 Data recipes

All pre-built data recipes are included in the package and can be easily updated (`recipeUpdate`), searched (`recipeSearch`) and loaded (`recipeLoad`). Details about data recipes can be found in the vignette `ReUseData_recipe.html`.

## 3.1 Search and load a data recipe

    recipeUpdate(cachePath = "ReUseDataRecipe", force = TRUE)
    #> NOTE: existing caches will be removed and regenerated!
    #> Updating recipes...
    #> STAR_index.R added
    #> bowtie2_index.R added
    #> echo_out.R added
    #> ensembl_liftover.R added
    #> gcp_broad_gatk_hg19.R added
    #> gcp_broad_gatk_hg38.R added
    #> gcp_gatk_mutect2_b37.R added
    #> gcp_gatk_mutect2_hg38.R added
    #> gencode_annotation.R added
    #> gencode_genome_grch38.R added
    #> gencode_transcripts.R added
    #> hisat2_index.R added
    #> reference_genome.R added
    #> salmon_index.R added
    #> ucsc_database.R added
    #>
    #> recipeHub with 15 records
    #> cache path:  /Users/biocbuild/Library/Caches/org.R-project.R/R/ReUseDataRecipe
    #> # recipeSearch() to query specific recipes using multipe keywords
    #> # recipeUpdate() to update the local recipe cache
    #>
    #>            name
    #>   BFC931 | STAR_index
    #>   BFC932 | bowtie2_index
    #>   BFC933 | echo_out
    #>   BFC934 | ensembl_liftover
    #>   BFC935 | gcp_broad_gatk_hg19
    #>   ...      ...
    #>   BFC941 | gencode_transcripts
    #>   BFC942 | hisat2_index
    #>   BFC943 | reference_genome
    #>   BFC944 | salmon_index
    #>   BFC945 | ucsc_database
    recipeSearch("echo")
    #> recipeHub with 1 records
    #> cache path:  /Users/biocbuild/Library/Caches/org.R-project.R/R/ReUseDataRecipe
    #> # recipeSearch() to query specific recipes using multipe keywords
    #> # recipeUpdate() to update the local recipe cache
    #>
    #>            name
    #>   BFC933 | echo_out
    echo_out <- recipeLoad("echo_out")
    #> Note: you need to assign a name for the recipe: rcpName <- recipeLoad('xx')
    #> Data recipe loaded!
    #> Use inputs() to check required input parameters before evaluation.
    #> Check here: https://rcwl.org/dataRecipes/echo_out.html
    #> for user instructions (e.g., eligible input values, data source, etc.)

## 3.2 Evaluate a data recipe

A data recipe can be evaluated by assigning values to the recipe parameters. `getData` runs the recipe as a CWL scripts internally, and generates the data of interest with annotation files for future reuse.

    Rcwl::inputs(echo_out)
    #> inputs:
    #>   input (input)  (string):
    #>   outfile (outfile)  (string):
    echo_out$input <- "Hello World!"
    echo_out$outfile <- "outfile"
    outdir <- file.path(tempdir(), "SharedData")
    res <- getData(echo_out,
                   outdir = outdir,
                   notes = c("echo", "hello", "world", "txt"))
    #> }[1;30mINFO[0m Final process status is success
    res$out
    #> [1] "/tmp/RtmpDamyzk/SharedData/outfile.txt"
    readLines(res$out)
    #> [1] "Print the input: Hello World!"

## 3.3 Create your own data recipes

One can create a data recipe from scratch or by converting an existing shell script for data processing, by specifying input parameters, output globbing patterns using `recipeMake` function.

    script <- system.file("extdata", "echo_out.sh", package = "ReUseData")
    rcp <- recipeMake(shscript = script,
                      paramID = c("input", "outfile"),
                      paramType = c("string", "string"),
                      outputID = "echoout",
                      outputGlob = "*.txt")
    Rcwl::inputs(rcp)
    #> inputs:
    #>   input (string):
    #>   outfile (string):
    Rcwl::outputs(rcp)
    #> outputs:
    #> echoout:
    #>   type: File[]
    #>   outputBinding:
    #>     glob: '*.txt'

# 4 Reusable data

The data that are generated from evaluating data recipes are automatically annotated and tracked with user-specified keywords and time/date tags. It uses a similar cache system as for recipes for users to easily update (`dataUpdate`), search (`dataSearch`) and use (`toList`).

Pre-generated data files from existing data recipes are saved in Google Cloud Bucket, that are ready to be queried (`dataSearch(cloud=TRUE)`) and downloaded (`getCloudData`) to local cache system with annotations.

## 4.1 Update data files that are generated using `ReUseData`

    dh <- dataUpdate(dir = outdir)
    dataSearch(c("echo", "hello"))
    dataNames(dh)
    dataParams(dh)
    dataNotes(dh)

## 4.2 Export data into workflow-ready files

    toList(dh, format="json", file = file.path(outdir, "data.json"))

## 4.3 Download pregenerated data from Google Cloud

    dh <- dataUpdate(dir = outdir, cloud = TRUE)
    getCloudData(dh[2], outdir = outdir)

# 5 SessionInfo

    sessionInfo()
    #> R version 4.3.1 (2023-06-16)
    #> Platform: aarch64-apple-darwin20 (64-bit)
    #> Running under: macOS Monterey 12.6.7
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> time zone: America/New_York
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats4    stats     graphics  grDevices utils     datasets  methods
    #> [8] base
    #>
    #> other attached packages:
    #> [1] ReUseData_1.0.1     Rcwl_1.16.0         S4Vectors_0.38.1
    #> [4] BiocGenerics_0.46.0 yaml_2.3.7          BiocStyle_2.28.0
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] tidyselect_1.2.0      dplyr_1.1.2           blob_1.2.4
    #>  [4] filelock_1.0.2        R.utils_2.12.2        fastmap_1.1.1
    #>  [7] BiocFileCache_2.8.0   promises_1.2.0.1      digest_0.6.31
    #> [10] base64url_1.4         mime_0.12             lifecycle_1.0.3
    #> [13] ellipsis_0.3.2        RSQLite_2.3.1         magrittr_2.0.3
    #> [16] compiler_4.3.1        rlang_1.1.1           sass_0.4.6
    #> [19] progress_1.2.2        tools_4.3.1           utf8_1.2.3
    #> [22] data.table_1.14.8     knitr_1.43            prettyunits_1.1.1
    #> [25] brew_1.0-8            htmlwidgets_1.6.2     bit_4.0.5
    #> [28] curl_5.0.1            here_1.0.1            reticulate_1.30
    #> [31] RColorBrewer_1.1-3    batchtools_0.9.17     BiocParallel_1.34.2
    #> [34] purrr_1.0.1           withr_2.5.0           R.oo_1.25.0
    #> [37] grid_4.3.1            fansi_1.0.4           git2r_0.32.0
    #> [40] xtable_1.8-4          debugme_1.1.0         cli_3.6.1
    #> [43] rmarkdown_2.22        DiagrammeR_1.0.10     crayon_1.5.2
    #> [46] generics_0.1.3        httr_1.4.6            visNetwork_2.1.2
    #> [49] DBI_1.1.3             cachem_1.0.8          parallel_4.3.1
    #> [52] BiocManager_1.30.21   basilisk_1.12.1       vctrs_0.6.3
    #> [55] Matrix_1.5-4.1        jsonlite_1.8.5        dir.expiry_1.8.0
    #> [58] bookdown_0.34         hms_1.1.3             bit64_4.0.5
    #> [61] jquerylib_0.1.4       RcwlPipelines_1.16.0  glue_1.6.2
    #> [64] codetools_0.2-19      stringi_1.7.12        later_1.3.1
    #> [67] tibble_3.2.1          pillar_1.9.0          basilisk.utils_1.12.1
    #> [70] rappdirs_0.3.3        htmltools_0.5.5       R6_2.5.1
    #> [73] dbplyr_2.3.2          rprojroot_2.0.3       evaluate_0.21
    #> [76] shiny_1.7.4           lattice_0.21-8        R.methodsS3_1.8.2
    #> [79] png_0.1-8             backports_1.4.1       memoise_2.0.1
    #> [82] httpuv_1.6.11         bslib_0.5.0           Rcpp_1.0.10
    #> [85] checkmate_2.2.0       xfun_0.39             pkgconfig_2.0.3