Mercurial > repos > iuc > sleuth
comparison sleuth.R @ 0:5f1cb4c28d73 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/sleuth commit 6b943159b4d68812dc6911309f23d54ec659282f
author | iuc |
---|---|
date | Thu, 01 Jun 2023 07:56:00 +0000 |
parents | |
children | d3e447dd52c8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5f1cb4c28d73 |
---|---|
1 library(sleuth, | |
2 quietly = TRUE, | |
3 warn.conflicts = FALSE) | |
4 library(annotables, quietly = TRUE, warn.conflicts = FALSE) | |
5 library(argparse, quietly = TRUE, warn.conflicts = FALSE) | |
6 library(tidyverse) | |
7 | |
8 | |
9 # setup R error handling to go to stderr | |
10 options( | |
11 show.error.messages = FALSE, | |
12 error = function() { | |
13 cat(geterrmessage(), file = stderr()) | |
14 q("no", 1, FALSE) | |
15 } | |
16 ) | |
17 | |
18 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
19 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
20 | |
21 ################################################################################ | |
22 ### Input Processing | |
23 ################################################################################ | |
24 | |
25 | |
26 # Collect arguments from command line | |
27 parser <- ArgumentParser(description = "Sleuth R script") | |
28 | |
29 parser$add_argument("--factorLevel", action = "append", required = TRUE) | |
30 parser$add_argument("--factorLevel_counts", | |
31 action = "append", | |
32 required = TRUE) | |
33 parser$add_argument("--factorLevel_n", action = "append", required = TRUE) | |
34 parser$add_argument("--cores", type = "integer", required = TRUE) | |
35 parser$add_argument("--normalize", action = "store_true", required = FALSE) | |
36 parser$add_argument("--nbins", type = "integer", required = TRUE) | |
37 parser$add_argument("--lwr", type = "numeric", required = TRUE) | |
38 parser$add_argument("--upr", type = "numeric", required = TRUE) | |
39 | |
40 args <- parser$parse_args() | |
41 | |
42 all_files <- args$factorLevel_counts | |
43 | |
44 conditions <- c() | |
45 for (x in seq_along(args$factorLevel)) { | |
46 temp <- append(conditions, rep(args$factorLevel[[x]])) | |
47 conditions <- temp | |
48 } | |
49 | |
50 sample_names <- all_files %>% | |
51 str_replace(pattern = "\\.tab", "") | |
52 | |
53 design <- | |
54 data.frame(list( | |
55 sample = sample_names, | |
56 condition = conditions, | |
57 path = all_files | |
58 )) | |
59 so <- sleuth_prep(design, | |
60 cores = args$cores, | |
61 normalize = args$normalize) | |
62 | |
63 so <- sleuth_fit( | |
64 so, | |
65 ~ condition, | |
66 "full", | |
67 n_bins = args$nbins, | |
68 lwr = args$lwr, | |
69 upr = args$upr | |
70 ) | |
71 | |
72 so <- sleuth_fit( | |
73 so, | |
74 ~ 1, | |
75 "reduced", | |
76 n_bins = args$nbins, | |
77 lwr = args$lwr, | |
78 upr = args$upr | |
79 ) | |
80 | |
81 so <- sleuth_lrt(so, "reduced", "full") | |
82 | |
83 sleuth_table <- | |
84 sleuth_results(so, "reduced:full", "lrt", show_all = FALSE) | |
85 | |
86 write.table( | |
87 sleuth_table, | |
88 file = "sleuth_table.tab", | |
89 quote = FALSE, | |
90 sep = "\t", | |
91 col.names = TRUE, | |
92 row.names = FALSE | |
93 ) | |
94 | |
95 | |
96 outputFile <- file.path(getwd(), "pca_plot.pdf") | |
97 pdf(file = outputFile, | |
98 height = 6, | |
99 width = 9) | |
100 plot_pca(so, color_by = "condition") | |
101 dev.off() | |
102 | |
103 outputFile <- file.path(getwd(), "group_density.pdf") | |
104 pdf(file = outputFile, | |
105 height = 6, | |
106 width = 9) | |
107 plot_group_density( | |
108 so, | |
109 use_filtered = TRUE, | |
110 units = "est_counts", | |
111 trans = "log", | |
112 grouping = setdiff(colnames(so$sample_to_covariates), | |
113 "sample"), | |
114 offset = 1 | |
115 ) | |
116 dev.off() |