Skip to content

Commit 062f590

Browse files
Add human readable log to DESeq2 pipelines
1 parent fa080df commit 062f590

File tree

8 files changed

+117
-55
lines changed

8 files changed

+117
-55
lines changed

tools/deseq-lrt-step-1.cwl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ outputs:
169169
outputBinding:
170170
glob: "*_all_contrasts.tsv"
171171

172+
human_log:
173+
type: File?
174+
outputBinding:
175+
glob: "error_report.txt"
176+
172177
stdout_log:
173178
type: stdout
174179

@@ -177,4 +182,4 @@ outputs:
177182

178183
baseCommand: [run_deseq_lrt_step_1.sh]
179184
stdout: error_msg.txt
180-
stderr: error_report.txt
185+
stderr: deseq_lrt_step_1_stderr.log

tools/deseq-lrt-step-2.cwl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ outputs:
125125
outputBinding:
126126
glob: "*_diff_expr.tsv"
127127

128+
human_log:
129+
type: File?
130+
outputBinding:
131+
glob: "error_report.txt"
132+
128133
stdout_log:
129134
type: stdout
130135

@@ -133,4 +138,4 @@ outputs:
133138

134139
baseCommand: [run_deseq_lrt_step_2.sh]
135140
stdout: error_msg.txt
136-
stderr: error_report.txt
141+
stderr: deseq_lrt_step_2_stderr.log

tools/dockerfiles/scripts/diff_tools/modules/io.R

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -215,51 +215,17 @@ export_morpheus_html_heatmap <- function(gct_location, rootname, color_scheme=NU
215215
)
216216
}
217217

218-
load_metadata <- function(location, aliases, batch=NULL){
218+
load_metadata <- function(location){
219219
metadata <- utils::read.table(
220220
location,
221221
sep=get_file_type(location),
222222
header=TRUE,
223223
stringsAsFactors=FALSE,
224224
row.names=1,
225225
quote="",
226-
colClasses="character" # to prevent loading numbers as numerical types
227-
) %>% dplyr::mutate_at(base::colnames(.), forcats::fct_inorder) # assigns levels bases on the first appearance in the metadata
228-
base::rownames(metadata) <- adjust_names(base::rownames(metadata)) # to make it correspond to the aliases
229-
230-
if (base::anyDuplicated(base::rownames(metadata)) > 0) {
231-
base::print(
232-
base::paste(
233-
"Exiting: the first columns in",
234-
"the metadata shouldn't include",
235-
"any duplicates."
236-
)
237-
)
238-
base::quit(save="no", status=1, runLast=FALSE)
239-
}
240-
241-
if (!generics::setequal(base::rownames(metadata), aliases)){ # we already cheched that neither metadata nor aliases have duplicates
242-
base::print(
243-
base::paste(
244-
"Exiting: the sample names in the",
245-
"metadata should correposnd to the",
246-
"sample names provided in the aliases",
247-
"parameter."
248-
)
249-
)
250-
base::quit(save="no", status=1, runLast=FALSE)
251-
}
252-
253-
if (!is.null(batch) && !(batch %in% base::colnames(metadata))){
254-
base::print(
255-
base::paste(
256-
"Exiting: the batch parameter",
257-
"should be used as one of the",
258-
"samples metadata column."
259-
)
260-
)
261-
base::quit(save="no", status=1, runLast=FALSE)
262-
}
226+
colClasses="character" # to prevent loading numbers as numerical types
227+
) %>% dplyr::mutate_at(base::colnames(.), forcats::fct_inorder) # assigns levels bases on the first appearance in the metadata
228+
base::rownames(metadata) <- adjust_names(base::rownames(metadata)) # to make it correspond to the aliases
263229

264230
for (i in 1:length(base::colnames(metadata))){
265231
base::print(
@@ -269,7 +235,6 @@ load_metadata <- function(location, aliases, batch=NULL){
269235
)
270236
)
271237
}
272-
273238
return (metadata)
274239
}
275240

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import("futile.logger", attach=FALSE)
2+
3+
export(
4+
"setup",
5+
"info"
6+
)
7+
8+
9+
setup <- function(location, name="hlog", header=NULL, level=futile.logger::INFO, format="~m"){
10+
futile.logger::flog.logger(
11+
name,
12+
level,
13+
appender=futile.logger::appender.file(location),
14+
layout=futile.logger::layout.format(format)
15+
)
16+
if (!is.null(header)){
17+
futile.logger:::.log_level(
18+
header, level=level, name=name,
19+
capture=FALSE, logger=NULL
20+
)
21+
}
22+
}
23+
24+
info <- function(message, name="hlog", skip_stdout=FALSE){
25+
futile.logger::flog.info(message, name=name)
26+
if (!skip_stdout) {print(message)}
27+
}

tools/dockerfiles/scripts/diff_tools/run_deseq_lrt_step_1.R

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ options(error=function(){traceback(3); quit(save="no", status=1, runLast=FALSE)}
1515
HERE <- (function() {return (dirname(sub("--file=", "", commandArgs(trailingOnly=FALSE)[grep("--file=", commandArgs(trailingOnly=FALSE))])))})()
1616
suppressMessages(io <- modules::use(file.path(HERE, "modules/io.R")))
1717
suppressMessages(analyses <- modules::use(file.path(HERE, "modules/analyses.R")))
18+
suppressMessages(logger <- modules::use(file.path(HERE, "modules/logger.R")))
1819

1920

2021
assert_args <- function(args){
2122

2223
if (length(args$expression) != length(args$aliases)) {
23-
print(
24+
logger$info(
2425
paste(
2526
"Exiting: the --expression and --aliases",
2627
"parameters should have the same length."
@@ -30,7 +31,7 @@ assert_args <- function(args){
3031
}
3132

3233
if (is.null(args$batch) != is.null(args$correction)){
33-
print(
34+
logger$info(
3435
paste(
3536
"Exiting: for batch correction both",
3637
"--batch and --correction parameters",
@@ -44,7 +45,7 @@ assert_args <- function(args){
4445
grepl("\\*", args$design) ||
4546
grepl("\\*", args$reduced)
4647
){
47-
print(
48+
logger$info(
4849
paste(
4950
"Exiting: both of the --design and",
5051
"--reduced formulas should be povided",
@@ -60,7 +61,7 @@ assert_args <- function(args){
6061
!is.null(args$batch) &&
6162
!(args$batch %in% unique(all.vars(args$design)))
6263
){
63-
print(
64+
logger$info(
6465
paste(
6566
"Exiting: the --batch parameter should",
6667
"also be used in the --design formula."
@@ -71,7 +72,7 @@ assert_args <- function(args){
7172

7273
args$aliases <- io$adjust_names(args$aliases)
7374
if (anyDuplicated(args$aliases) > 0) {
74-
print(
75+
logger$info(
7576
paste(
7677
"Exiting: the sample names provided",
7778
"in the --aliases parameter shouldn't",
@@ -276,7 +277,12 @@ get_args <- function() {
276277
type="integer",
277278
default=1
278279
)
279-
args <- assert_args(parser$parse_args(commandArgs(trailingOnly=TRUE)))
280+
args <- parser$parse_args(commandArgs(trailingOnly=TRUE))
281+
logger$setup(
282+
file.path(dirname(ifelse(args$output == "", "./", args$output)), "error_report.txt"),
283+
header="DESeq2 LRT Step 1 (run_deseq_lrt_step_1.R)"
284+
)
285+
args <- assert_args(args)
280286
return(args)
281287
}
282288

@@ -289,13 +295,43 @@ print(paste("Setting parallelizations to", args$cpus, "cores."))
289295
register(MulticoreParam(args$cpus))
290296

291297
print("Loading metadata.")
292-
metadata <- io$load_metadata(
293-
location=args$metadata,
294-
aliases=args$aliases,
295-
batch=args$batch
296-
)
298+
metadata <- io$load_metadata(args$metadata)
297299
print(metadata)
298300

301+
if (anyDuplicated(rownames(metadata)) > 0) {
302+
logger$info(
303+
paste(
304+
"Exiting: the first columns in",
305+
"the metadata shouldn't include",
306+
"any duplicates."
307+
)
308+
)
309+
quit(save="no", status=1, runLast=FALSE)
310+
}
311+
312+
if (!setequal(rownames(metadata), args$aliases)){ # we already cheched that neither metadata nor aliases have duplicates
313+
logger$info(
314+
paste(
315+
"Exiting: the sample names in the",
316+
"metadata should correspond to the",
317+
"sample names provided in the aliases",
318+
"parameter."
319+
)
320+
)
321+
quit(save="no", status=1, runLast=FALSE)
322+
}
323+
324+
if (!is.null(args$batch) && !(args$batch %in% colnames(metadata))){
325+
logger$info(
326+
paste(
327+
"Exiting: the batch parameter",
328+
"should be used as one of the",
329+
"samples metadata column."
330+
)
331+
)
332+
quit(save="no", status=1, runLast=FALSE)
333+
}
334+
299335
print("Loading gene expression.")
300336
expression_data <- io$load_expression_data(
301337
locations=args$expression,

tools/dockerfiles/scripts/diff_tools/run_deseq_lrt_step_2.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ HERE <- (function() {return (dirname(sub("--file=", "", commandArgs(trailingOnly
1313
suppressMessages(io <- modules::use(file.path(HERE, "modules/io.R")))
1414
suppressMessages(analyses <- modules::use(file.path(HERE, "modules/analyses.R")))
1515
suppressMessages(graphics <- modules::use(file.path(HERE, "modules/graphics.R")))
16+
suppressMessages(logger <- modules::use(file.path(HERE, "modules/logger.R")))
1617

1718

1819
assert_args <- function(args){
@@ -138,7 +139,12 @@ get_args <- function() {
138139
type="integer",
139140
default=1
140141
)
141-
args <- assert_args(parser$parse_args(commandArgs(trailingOnly=TRUE)))
142+
args <- parser$parse_args(commandArgs(trailingOnly=TRUE))
143+
logger$setup(
144+
file.path(dirname(ifelse(args$output == "", "./", args$output)), "error_report.txt"),
145+
header="DESeq2 LRT Step 2 (run_deseq_lrt_step_2.R)"
146+
)
147+
args <- assert_args(args)
142148
return(args)
143149
}
144150

@@ -184,7 +190,7 @@ selected_contrasts <- all_contrasts[intersect(args$target, names(all_contrasts))
184190
print(selected_contrasts)
185191

186192
if (length(selected_contrasts) == 0) {
187-
print(
193+
logger$info(
188194
paste(
189195
"Exiting: no target contrasts found."
190196
)
@@ -259,7 +265,7 @@ collected_deseq_results <- collected_deseq_results %>%
259265
rownames_to_column(var="Feature") # we need to to join with cluster information
260266
print(head(collected_deseq_results))
261267
if(!any(grepl("_padj$", colnames(collected_deseq_results)))){ # to check that we have at least one contrast successfully calculated
262-
print(
268+
logger$info(
263269
paste(
264270
"Exiting: neither of the selected",
265271
"contrasts were successfully calculated."

workflows/deseq-lrt-step-1.cwl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ outputs:
321321
All contrasts produced by DESeq2 Wald tests.
322322
RDS format.
323323

324+
human_log:
325+
type: File?
326+
outputSource: deseq_lrt_step_1/human_log
327+
label: "Human readable error log"
328+
doc: |
329+
Human readable error log
330+
from the deseq_lrt_step_1 step.
331+
324332
stdout_log:
325333
type: File
326334
outputSource: deseq_lrt_step_1/stdout_log
@@ -371,5 +379,6 @@ steps:
371379
- diff_expr_tsv
372380
- all_contrasts_rds
373381
- all_contrasts_tsv
382+
- human_log
374383
- stdout_log
375384
- stderr_log

workflows/deseq-lrt-step-2.cwl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ outputs:
231231
Morpheus compatible heatmap of normalized read counts.
232232
GCT format.
233233

234+
human_log:
235+
type: File?
236+
outputSource: deseq_lrt_step_2/human_log
237+
label: "Human readable error log"
238+
doc: |
239+
Human readable error log
240+
from the deseq_lrt_step_2 step.
241+
234242
stdout_log:
235243
type: File
236244
outputSource: deseq_lrt_step_2/stdout_log
@@ -268,5 +276,6 @@ steps:
268276
- read_counts_gct
269277
- read_counts_html
270278
- diff_expr_tsv
279+
- human_log
271280
- stdout_log
272281
- stderr_log

0 commit comments

Comments
 (0)