-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.Rmd
More file actions
217 lines (161 loc) · 5.71 KB
/
Copy pathreport.Rmd
File metadata and controls
217 lines (161 loc) · 5.71 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
---
title: "Prime Hits Report"
date: "`r Sys.Date()`"
output:
word_document:
reference_docx: report_style.docx
# pdf_document:
# latex_engine: pdflatex # Or lualatex (both have excellent Unicode support)
# keep_tex: TRUE # Useful for debugging if issues arise
# fig_crop: FALSE
#geometry: "margin=0.1in" # Adjust margins if needed
# Other font options: Arial Unicode MS, FreeSerif, etc.
# You might also need to specify sansfont, monofont if used
#classoption: landscape
params:
target: NA
stage: NA
run: NA
Ch1_norm: NA
Ch2_norm: NA
scale_scope: NA
col_to_penalise: NA
equation: NA
zero_limit: NA
channel_flip: NA
hit_threshold: NA
norm_plots: NA
run_summary: NA
d_dens_plot: NA
combined_plot: NA
df_normw_plot: NA
df_export_plot_ratio: NA
df_export_plot_penalised: NA
zoom_Ch1_raw: NA
zoom_Ch2_raw: NA
hit_tbl_tags: NA
hit_tbl: NA
plates_wide: NA
header-includes:
- \usepackage{booktabs}
# - \usepackage{longtable}
# - \usepackage{array}
# - \usepackage{multirow}
# - \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
# - \usepackage{pdflscape}
# - \usepackage{tabu}
# - \usepackage{threeparttable}
# - \usepackage[normalem]{ulem}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(patchwork)
library(tidyverse)
library(kableExtra)
library(knitr)
# Define formatting function
# Custom function to format numbers based on conditions
format_number <- function(x) {
sapply(x, function(val) {
if (abs(val) > 1000 || abs(val) < 0.01) {
return(formatC(val, format = "e", digits = 2)) # Scientific notation
} else {
return(as.character(round(val, 2))) # Round to two decimal places
}
})
}
```
## Parameters used:
* Target: `r params$target`
* Stage: `r params$stage`
* Run: `r params$run`
* Ch1 (X-axis) normalisation: `r params$Ch1_norm`
* Ch2 (Y-axis) normalisation: `r params$Ch2_norm`
* Normalisation scope: `r params$scale_scope`
* Column to penalise: `r params$col_to_penalise`
* Hit threshold: `r params$hit_threshold`
* Equation: `r params$equation`
* Limit penalized number to max of zero: `r params$zero_limit`
* Acceptor First: `r params$channel_flip`
## Run summary
### Normalisation center and scale and Density of d
```{r norm_plots, echo=FALSE, fig.width=12, fig.height=4}
params$norm_plots
```
### Run Summary Table
```{r run_summary,fig.width=12, fig.height=4, echo=FALSE}
formatted_run_summary <- select(params$run_summary,feature,median_Compound:`median_Positive Control`,mad_Compound:`mad_Positive Control`,rCV_Compound:`rCV_Positive Control`) %>%
mutate(across(
where(is.numeric),
~ format_number(.x)
))
# Output kable with scaling
kable(formatted_run_summary, booktabs = TRUE, caption="Run summary")# %>%
#kable_styling(latex_options = c("striped", "scale_down", position = "H"))
# # Create a flextable from your data frame
# ft <- flextable(formatted_run_summary)
#
# # Optional: Configure the theme to be somewhat similar to a stripped effect
# ft <- theme_vanilla(ft)
#
# # Autofit to adjust to the content
# ft <- autofit(ft)
#
# # Optional: You can add features similar to striped rows using color shading
# ft <- bg(ft, i = seq(from = 1, to = nrow(formatted_run_summary), by = 2), bg = "#F0F0F0")
#
# # (Flextable doesn't directly support caption in PDF, adjust document format accordingly)
# ft
```
### Density of d
```{r d_dens_plot, echo=FALSE, fig.width=12, fig.height=4}
params$d_dens_plot
```
\newpage
## Penaltry strength plots
`r params$equation`
```{r combined_plot, echo=FALSE, fig.width=12, fig.height=8.1}
params$combined_plot
```
## Heatplot of penalised values in normalised space
```{r df_normw_plot, echo=FALSE, fig.width=12, fig.height=5}
params$df_normw_plot
```
## Heatplot of penalised and non-penalised values in raw space
```{r plots_both_penalty, echo=FALSE, fig.width=12, fig.height=8}
df_export_plot_ratio_zoom<- params$df_export_plot_ratio+coord_cartesian(xlim=params$zoom_Ch1_raw,ylim=params$zoom_Ch2_raw)
df_export_plot_penalised_zoom <- params$df_export_plot_penalised+coord_cartesian(xlim=params$zoom_Ch1_raw,ylim=params$zoom_Ch2_raw)
df_export_plot_ratio_zoom / df_export_plot_penalised_zoom
```
## Actives by Well Type
```{r Actives by Well Type, echo=FALSE}
# kable(params$hit_tbl, format = "latex", booktabs = TRUE, caption="Actives by Well Type") %>%
# kable_styling(latex_options = c("striped", "scale_down", position = "H"))
kable(params$hit_tbl, caption="Actives by Well Type")
```
## Actives by tag
```{r Actives by Well Tag,echo=FALSE}
# kable(params$hit_tbl_tags, format = "latex", booktabs = TRUE, caption="Actives by Well Tag") %>%
# kable_styling(latex_options = c("striped", "scale_down", position = "H"))
kable(params$hit_tbl_tags, caption="Actives by Well Tag")
```
## Plate Summary Table
```{r all_plates, echo=FALSE}
plates_wide <- select(params$plates_wide,feature,`Plate ID`,median_Compound:`median_Positive Control`,mad_Compound:`mad_Positive Control`,rCV_Compound:`rCV_Positive Control`,rSB,rZf)
# Create a copy of plates_wide with formatted results as character columns
formatted_plates_wide <- plates_wide %>% na.omit %>%
mutate(`Plate ID`=as.character(`Plate ID`)) %>%
mutate(across(
where(is.numeric),
~ format_number(.x)
))
names(formatted_plates_wide) <- str_remove(names(formatted_plates_wide),"Control")
names(formatted_plates_wide) <- str_replace(names(formatted_plates_wide),"Compound","Cpd")
# # Output kable with scaling
# kable(formatted_plates_wide, format = "latex", booktabs = TRUE, caption="Plate Stats") %>%
# kable_styling(latex_options = c("striped", "scale_down", position = "H"))
kable(formatted_plates_wide, caption="Plate Stats")
```