-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_export_recipes.Rmd
131 lines (102 loc) · 4.35 KB
/
import_export_recipes.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
title: "Reproducibility in Microbiome Data Analysis"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Reproducibility in Microbiome Data Analysis}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
message = FALSE,
digits = 3,
collapse = TRUE,
comment = "#>"
)
options(digits = 3)
```
<style>
body {
text-align: justify}
</style>
Reproducibility is a crucial aspect of data analysis, particularly in the
context of microbiome data. The ability to consistently replicate an analysis
and obtain the same results is essential for ensuring the reliability of
findings and facilitating scientific collaboration.
The `dar` package includes two key functions, `export_steps` and
`import_steps`, which promote reproducibility in microbiome data analysis.
These functions allow you to export the steps of a recipe to a JSON file and
then import those steps to reproduce the analysis in a different environment.
## Exporting Steps of a Recipe
The `export_steps` function facilitates the export of a recipe's steps to a
JSON file. This is useful for documenting and sharing the parameters used in
the analysis.
Here's an example of how to use the `export_steps` function:
```{r}
library(dar)
data(metaHIV_phy)
# Create a recipe with steps
rec <-
recipe(metaHIV_phy, "RiskGroup2", "Species") |>
step_subset_taxa(tax_level = "Kingdom", taxa = c("Bacteria", "Archaea")) |>
step_filter_taxa(.f = "function(x) sum(x > 0) >= (0.3 * length(x))") |>
step_maaslin()
# Export the steps to a JSON file
out_file <- tempfile(fileext = ".json")
export_steps(rec, out_file)
```
In this example, a recipe with multiple steps is created, and then the steps
are exported to a JSON file using the `export_steps` function.
## Importing Steps from a JSON File
The `import_steps` function allows you to import steps from a JSON file and
add them to an existing recipe. This is useful when you want to reuse a
previously saved set of steps or incorporate steps from another recipe into
your current analysis.
Here's an example of how to use the `import_steps` function:
```{r}
# Initialize a recipe with a phyloseq object
rec <- recipe(metaHIV_phy, "RiskGroup2", "Species")
# Import the steps from a JSON file
json_file <- out_file
rec <- import_steps(rec, json_file)
rec
```
In this example, an empty recipe is initialized, and then the steps are
imported from a JSON file using the `import_steps` function. The imported steps
are added to the existing recipe.
Once the recipe is imported, we can choose to add more steps or execute the
code using the `prep` function. In this case, we choose to execute `prep`
directly.
```{r}
## Execute
da_results <- prep(rec, parallel = FALSE) |> bake()
da_results
```
## Limitations and Considerations
It's important to note some limitations and considerations when using the
`export_steps` and `import_steps` functions:
- The JSON files generated by `export_steps` only contain the parameters of the
recipe steps and bakes, not the original data used in the analysis. Therefore,
when importing the steps from a JSON file, ensure that you have access to the
same data that was originally used.
- The `export_steps` and `import_steps` functions are specific to the `dar`
package and are designed for use in microbiome data analysis. They are not
applicable to other types of analyses or packages.
- When importing steps from a JSON file, it's important to check if the file
contains "bake" steps. If so, the recipe will be automatically prepared after
importing the steps. This may have implications for runtime and resource
requirements of the analysis.
- Make sure you have the correct versions of the dependencies of the `dar`
package when exporting and importing recipe steps. Updates in dependencies can
affect the compatibility and reproducibility of the analyses.
## Conclusion
Reproducibility is essential in microbiome data analysis, and the `dar` package
facilitates this aspect by providing the `export_steps` and `import_steps`
functions. These functions allow you to export the steps of a recipe to a JSON
file and then import them to reproduce the analysis in a different environment.
With these tools, you can effectively document and share your analyses,
increasing transparency and the reliability of your results.
## Session info
```{r}
devtools::session_info()
```