comparison gss.R @ 0:d0cbe6cc1f04 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/genomic_super_signature commit 1aadd5dce3b254e7714c2fdd39413029fd4b9b7a"
author iuc
date Wed, 12 Jan 2022 19:07:45 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d0cbe6cc1f04
1 suppressPackageStartupMessages(library(optparse))
2
3 ### Parsing command line -------------------------------------------------------
4 option_list <- list(
5 make_option(c("--input"), type = "character",
6 default = NULL, help = "Count matrix in tsv format"),
7 make_option(c("--model"), type = "character",
8 default = NULL, help = "RAVmodel to apply.
9 Currently 'C2' and 'PLIERpriors' are available"),
10 make_option(c("--method"), type = "character",
11 default = formals(GenomicSuperSignature::validate)$method),
12 make_option(c("--maxFrom"), type = "character",
13 default = formals(GenomicSuperSignature::validate)$maxFrom),
14 make_option(c("--level"), type = "character",
15 default = formals(GenomicSuperSignature::validate)$level),
16 make_option(c("--scale"), type = "character",
17 default = formals(GenomicSuperSignature::validate)$scale),
18 make_option(c("--outDir"), type = "character",
19 default = NULL, help = "Output file name"),
20 make_option(c("--validate"), type = "character",
21 default = NULL, help = "Path to save validate.csv"),
22 make_option(c("--html"), type = "character",
23 default = NULL, help = "Path to save HTML report"),
24 make_option(c("--numOut"), type = "integer",
25 default = 3, help = "The number of top validated RAVs to check"),
26 make_option(c("--toolDir"), type = "character",
27 default = ".", help = "Directory containing the tool scripts (e.g. gss.Rmd")
28 )
29
30 opt <- parse_args(OptionParser(option_list = option_list),
31 args = commandArgs(trailingOnly = TRUE))
32 input <- opt$input
33 model <- opt$model
34 out_dir <- opt$outDir
35 num_out <- opt$numOut
36
37 if (is.null(input)) stop("Need --input.")
38 if (is.null(model)) stop("Need --model.")
39 if (is.null(out_dir)) stop("Need --outDir.")
40
41 input_name <- basename(tools::file_path_sans_ext(input))
42 out_dir <- normalizePath(out_dir)
43
44 suppressPackageStartupMessages(library(GenomicSuperSignature))
45 dat <- as.matrix(read.table(file = input, header = TRUE, sep = "\t",
46 row.names = 1))
47 if (model %in% c("C2", "PLIERpriors")) {
48 rav_model <- getModel(model)
49 } else {
50 rav_model <- readRDS(model)
51 }
52
53
54
55 ### validate -------------------------------------------------------------------
56 val_all <- validate(dat, rav_model)
57 validated_ind <- validatedSignatures(val_all, num.out = num_out,
58 swCutoff = 0, indexOnly = TRUE)
59 n <- min(num_out, length(validated_ind), na.rm = TRUE)
60
61 ### Save tables in csv ---------------------------------------------------------
62 # Validation
63 if (is.null(opt$validate)) {
64 output_fname <- file.path(out_dir, paste0(input_name, "_validate.csv"))
65 } else {
66 output_fname <- opt$validate
67 }
68 write.csv(val_all,
69 file = output_fname,
70 row.names = TRUE)
71
72 # GSEA
73 for (i in seq_len(n)) {
74 rav_num <- validated_ind[i]
75 rav_name <- paste0("RAV", rav_num)
76 res <- gsea(rav_model)[[rav_name]]
77
78 output_fname <- paste0(input_name, "_genesets_RAV", rav_num, ".csv")
79 write.csv(res,
80 file = file.path(out_dir, output_fname),
81 row.names = TRUE)
82 }
83
84 # Related prior studies
85 for (i in seq_len(n)) {
86 rav_num <- validated_ind[i]
87 res <- findStudiesInCluster(rav_model, rav_num)
88
89 output_fname <- paste0(input_name, "_literatures_RAV", rav_num, ".csv")
90 write.csv(res,
91 file = file.path(out_dir, output_fname),
92 row.names = TRUE)
93 }
94
95 ### Create a report ------------------------------------------------------------
96 if (is.null(opt$html)) {
97 output_fname <- file.path(out_dir, paste0("GSS-", input_name, "-",
98 format(Sys.Date(), format = "%Y%m%d"), ".html"))
99 } else {
100 output_fname <- opt$html
101
102 }
103 rmarkdown::render(
104 file.path(opt$toolDir, "gss.Rmd"), params = list(
105 val_all = val_all,
106 dat = dat,
107 RAVmodel = rav_model,
108 inputName = input_name,
109 numOut = num_out
110 ),
111 output_file = output_fname,
112 intermediates_dir = ".",
113 knit_root_dir = "."
114 )