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