Mercurial > repos > iuc > cemitool
comparison CEMiTool.R @ 1:81bffdf16b71 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cemitool commit 90f5b1b6df8661779e097330e1f11346c6f388fc
author | iuc |
---|---|
date | Mon, 19 Aug 2024 10:47:14 +0000 |
parents | 3f9ff31c88bb |
children |
comparison
equal
deleted
inserted
replaced
0:3f9ff31c88bb | 1:81bffdf16b71 |
---|---|
2 library(CEMiTool, quietly = TRUE, warn.conflicts = FALSE) | 2 library(CEMiTool, quietly = TRUE, warn.conflicts = FALSE) |
3 library(ggplot2, quietly = TRUE, warn.conflicts = FALSE) | 3 library(ggplot2, quietly = TRUE, warn.conflicts = FALSE) |
4 library(getopt, quietly = TRUE, warn.conflicts = FALSE) | 4 library(getopt, quietly = TRUE, warn.conflicts = FALSE) |
5 # setup R error handling to go to stderr | 5 # setup R error handling to go to stderr |
6 options( | 6 options( |
7 show.error.messages = FALSE, | 7 show.error.messages = FALSE, |
8 error = function() { | 8 error = function() { |
9 cat(geterrmessage(), file = stderr()) | 9 cat(geterrmessage(), file = stderr()) |
10 q("no", 1, FALSE) | 10 q("no", 1, FALSE) |
11 } | 11 } |
12 ) | 12 ) |
13 | 13 |
14 # we need that to not crash galaxy with an UTF8 error on German LC settings. | 14 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
15 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | 15 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
16 | 16 |
21 # Collect arguments from command line | 21 # Collect arguments from command line |
22 args <- commandArgs(trailingOnly = TRUE) | 22 args <- commandArgs(trailingOnly = TRUE) |
23 | 23 |
24 # Get options, using the spec as defined by the enclosed list. | 24 # Get options, using the spec as defined by the enclosed list. |
25 # Read the options from the default: commandArgs(TRUE). | 25 # Read the options from the default: commandArgs(TRUE). |
26 spec <- matrix(c( | 26 spec <- matrix( |
27 "expressionMatrix", "M", 1, "character", | 27 c( |
28 "sampleAnnotation", "A", 2, "character", | 28 "expressionMatrix", "M", 1, "character", |
29 "pathwayList", "P", 2, "character", | 29 "sampleAnnotation", "A", 2, "character", |
30 "interactions", "I", 2, "character", | 30 "pathwayList", "P", 2, "character", |
31 "filter", "f", 1, "logical", | 31 "interactions", "I", 2, "character", |
32 "filter_pval", "i", 1, "numeric", | 32 "set_beta", "B", 1, "integer", |
33 "apply_vst", "a", 1, "logical", | 33 "filter", "f", 1, "logical", |
34 "n_genes", "n", 1, "integer", | 34 "filter_pval", "i", 1, "numeric", |
35 "eps", "e", 1, "numeric", | 35 "apply_vst", "a", 1, "logical", |
36 "cor_method", "c", 1, "character", | 36 "n_genes", "n", 1, "integer", |
37 "cor_function", "y", 1, "character", | 37 "eps", "e", 1, "numeric", |
38 "network_type", "x", 1, "character", | 38 "cor_method", "c", 1, "character", |
39 "tom_type", "t", 1, "character", | 39 "cor_function", "y", 1, "character", |
40 "merge_similar", "m", 1, "logical", | 40 "network_type", "x", 1, "character", |
41 "rank_method", "r", 1, "character", | 41 "tom_type", "t", 1, "character", |
42 "min_ngen", "g", 1, "integer", | 42 "merge_similar", "m", 1, "logical", |
43 "diss_thresh", "d", 1, "numeric", | 43 "rank_method", "r", 1, "character", |
44 "center_func", "h", 1, "character", | 44 "min_ngen", "g", 1, "integer", |
45 "ora_pval", "o", 1, "numeric", | 45 "diss_thresh", "d", 1, "numeric", |
46 "gsea_scale", "l", 1, "logical", | 46 "center_func", "h", 1, "character", |
47 "gsea_min_size", "w", 1, "integer", | 47 "ora_pval", "o", 1, "numeric", |
48 "gsea_max_size", "z", 1, "integer", | 48 "gsea_scale", "l", 1, "logical", |
49 "sample_column_name", "v", 1, "character"), | 49 "gsea_min_size", "w", 1, "integer", |
50 byrow = TRUE, ncol = 4 | 50 "gsea_max_size", "z", 1, "integer", |
51 "sample_column_name", "v", 1, "character" | |
52 ), | |
53 byrow = TRUE, ncol = 4 | |
51 ) | 54 ) |
52 | 55 |
53 opt <- getopt(spec) | 56 opt <- getopt(spec) |
54 counts <- read.table( | 57 counts <- read.table( |
55 opt$expressionMatrix, | 58 opt$expressionMatrix, |
56 header = TRUE, | 59 header = TRUE, |
57 sep = "\t", | 60 sep = "\t", |
58 strip.white = TRUE, | 61 strip.white = TRUE, |
59 stringsAsFactors = FALSE, | 62 stringsAsFactors = FALSE, |
60 check.names = FALSE | 63 check.names = FALSE |
61 ) | 64 ) |
62 | 65 |
63 | 66 |
64 # Run CEMiTool | 67 # Run CEMiTool |
65 | 68 |
66 if (is.null(opt$sampleAnnotation)) { | 69 if (is.null(opt$sampleAnnotation)) { |
67 cem <- cemitool( | 70 cem <- cemitool( |
68 counts, | 71 counts, |
69 filter = opt$filter, | 72 filter = opt$filter, |
70 filter_pval = opt$filter_pval, | 73 filter_pval = opt$filter_pval, |
71 apply_vst = opt$apply_vst, | 74 apply_vst = opt$apply_vst, |
72 n_genes = opt$n_genes, | 75 n_genes = opt$n_genes, |
73 eps = opt$eps, | 76 eps = opt$eps, |
74 cor_method = opt$cor_method, | 77 cor_method = opt$cor_method, |
75 cor_function = opt$cor_function, | 78 cor_function = opt$cor_function, |
76 network_type = opt$network_type, | 79 network_type = opt$network_type, |
77 tom_type = opt$tom_type, | 80 tom_type = opt$tom_type, |
78 merge_similar = opt$merge_similar, | 81 merge_similar = opt$merge_similar, |
79 min_ngen = opt$min_ngen, | 82 min_ngen = opt$min_ngen, |
80 diss_thresh = opt$diss_thresh, | 83 diss_thresh = opt$diss_thresh, |
81 center_func = opt$center_func, | 84 center_func = opt$center_func, |
82 verbose = TRUE, | 85 verbose = TRUE, |
83 ora_pval = opt$ora_pval | 86 ora_pval = opt$ora_pval, |
84 ) | 87 set_beta = opt$set_beta |
88 ) | |
85 } else { | 89 } else { |
86 annotation <- read.table( | 90 annotation <- read.table( |
87 opt$sampleAnnotation, | 91 opt$sampleAnnotation, |
88 header = TRUE, | 92 header = TRUE, |
89 sep = "\t", | 93 sep = "\t", |
90 strip.white = TRUE, | 94 strip.white = TRUE, |
91 stringsAsFactors = FALSE, | 95 stringsAsFactors = FALSE, |
92 check.names = FALSE | 96 check.names = FALSE |
93 ) | 97 ) |
94 cem <- cemitool( | 98 cem <- cemitool( |
95 counts, | 99 counts, |
96 annotation, | 100 annotation, |
97 filter = opt$filter, | 101 filter = opt$filter, |
98 filter_pval = opt$filter_pval, | 102 filter_pval = opt$filter_pval, |
99 apply_vst = opt$apply_vst, | 103 apply_vst = opt$apply_vst, |
100 n_genes = opt$n_genes, | 104 n_genes = opt$n_genes, |
101 eps = opt$eps, | 105 eps = opt$eps, |
102 cor_method = opt$cor_method, | 106 cor_method = opt$cor_method, |
103 cor_function = opt$cor_function, | 107 cor_function = opt$cor_function, |
104 network_type = opt$network_type, | 108 network_type = opt$network_type, |
105 tom_type = opt$tom_type, | 109 tom_type = opt$tom_type, |
106 merge_similar = opt$merge_similar, | 110 merge_similar = opt$merge_similar, |
107 min_ngen = opt$min_ngen, | 111 min_ngen = opt$min_ngen, |
108 diss_thresh = opt$diss_thresh, | 112 diss_thresh = opt$diss_thresh, |
109 center_func = opt$center_func, | 113 center_func = opt$center_func, |
110 verbose = TRUE, | 114 verbose = TRUE, |
111 ora_pval = opt$ora_pval, | 115 ora_pval = opt$ora_pval, |
112 sample_name_column = opt$sample_column_name, | 116 sample_name_column = opt$sample_column_name, |
113 class_column = "Class", | 117 class_column = "Class", |
114 order_by_class = TRUE | 118 order_by_class = TRUE |
115 ) | 119 ) |
116 cem <- mod_gsea( | 120 cem <- mod_gsea( |
117 cem, | 121 cem, |
118 gsea_scale = opt$gsea_scale, | 122 gsea_scale = opt$gsea_scale, |
119 gsea_min_size = opt$gsea_min_size, | 123 gsea_min_size = opt$gsea_min_size, |
120 gsea_max_size = opt$gsea_max_size, | 124 gsea_max_size = opt$gsea_max_size, |
121 rank_method = opt$rank_method | 125 rank_method = opt$rank_method |
122 ) | 126 ) |
123 cem <- plot_gsea(cem) | 127 cem <- plot_gsea(cem) |
124 } | 128 } |
125 | 129 |
126 if (!is.null(opt$pathwayList)) { | 130 if (!is.null(opt$pathwayList)) { |
127 gmt_in <- read_gmt(opt$pathwayList) | 131 gmt_in <- read_gmt(opt$pathwayList) |
128 cem <- mod_ora(cem, gmt_in) | 132 cem <- mod_ora(cem, gmt_in) |
129 cem <- plot_ora(cem) | 133 cem <- plot_ora(cem) |
130 } | 134 } |
131 | 135 |
132 if (!is.null(opt$interactions)) { | 136 if (!is.null(opt$interactions)) { |
133 interactions <- read.table( | 137 interactions <- read.table( |
134 opt$interactions, | 138 opt$interactions, |
135 header = TRUE, | 139 header = TRUE, |
136 sep = "\t", | 140 sep = "\t", |
137 strip.white = TRUE, | 141 strip.white = TRUE, |
138 stringsAsFactors = FALSE, | 142 stringsAsFactors = FALSE, |
139 check.names = FALSE | 143 check.names = FALSE |
140 ) | 144 ) |
141 interactions_data(cem) <- interactions # add interactions | 145 interactions_data(cem) <- interactions # add interactions |
142 cem <- plot_interactions(cem) | 146 cem <- plot_interactions(cem) |
143 } | 147 } |
144 | 148 |
145 ## Write analysis results into files | 149 ## Write analysis results into files |
146 write_files(cem, | 150 write_files(cem, |
147 directory = "./Tables", | 151 directory = "./Tables", |
148 force = TRUE) | 152 force = TRUE |
153 ) | |
149 | 154 |
150 generate_report(cem) | 155 generate_report(cem) |
151 | 156 |
152 save_plots(cem, | 157 save_plots(cem, |
153 value = "all", | 158 value = "all", |
154 directory = "./Plots", | 159 directory = "./Plots", |
155 force = TRUE) | 160 force = TRUE |
161 ) |