comparison pathview.r @ 4:dbac244d2214 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/pathview commit 4abfa1933dc0631419b5a277045fbaf2b2a562b8
author iuc
date Mon, 23 Mar 2026 13:46:44 +0000
parents fe154a7af404
children
comparison
equal deleted inserted replaced
3:f1691de443a7 4:dbac244d2214
1 error_foo <- function() { 1 error_foo <- function() {
2 cat(geterrmessage(), file = stderr()); 2 cat(geterrmessage(), file = stderr())
3 q("no", 1, F) 3 q("no", 1, F)
4 } 4 }
5 options(show.error.messages = F, error = error_foo) 5 options(show.error.messages = F, error = error_foo)
6 6
7 # we need that to not crash galaxy with an UTF8 error on German LC settings. 7 # we need that to not crash galaxy with an UTF8 error on German LC settings.
8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") 8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
13 }) 13 })
14 14
15 sessionInfo() 15 sessionInfo()
16 16
17 option_list <- list( 17 option_list <- list(
18 make_option(c("--pathway_id"), type = "character", default = NULL, help = "Path to tabular file with gene data"), 18 make_option(c("--pathway_id"), type = "character", default = NULL, help = "Path to tabular file with gene data"),
19 make_option(c("--pathway_id_fp"), type = "character", default = NULL, help = "Path to tabular file with pathway ids"), 19 make_option(c("--pathway_id_fp"), type = "character", default = NULL, help = "Path to tabular file with pathway ids"),
20 make_option(c("--pathway_id_header"), type = "logical", default = FALSE, help = "Header for tabular file with pathway ids"), 20 make_option(c("--pathway_id_header"), type = "logical", default = FALSE, help = "Header for tabular file with pathway ids"),
21 make_option(c("--species"), type = "character", default = "hsa", help = "KEGG code, scientific name or the common name of the species"), 21 make_option(c("--species"), type = "character", default = "hsa", help = "KEGG code, scientific name or the common name of the species"),
22 make_option(c("--gene_data"), type = "character", default = NULL, help = "Path to tabular file with gene data"), 22 make_option(c("--gene_data"), type = "character", default = NULL, help = "Path to tabular file with gene data"),
23 make_option(c("--gd_header"), type = "logical", default = FALSE, help = "Header for the gene data file"), 23 make_option(c("--gd_header"), type = "logical", default = FALSE, help = "Header for the gene data file"),
24 make_option(c("--gene_idtype"), type = "character", default = "entrez", help = "ID type used for the gene data"), 24 make_option(c("--gene_idtype"), type = "character", default = "entrez", help = "ID type used for the gene data"),
25 make_option(c("--cpd_data"), type = "character", default = NULL, help = "Path to tabular file with compound data"), 25 make_option(c("--cpd_data"), type = "character", default = NULL, help = "Path to tabular file with compound data"),
26 make_option(c("--cpd_header"), type = "logical", default = FALSE, help = "Header for the compound data file"), 26 make_option(c("--cpd_header"), type = "logical", default = FALSE, help = "Header for the compound data file"),
27 make_option(c("--cpd_idtype"), type = "character", default = "kegg", help = "ID type used for the compound data"), 27 make_option(c("--cpd_idtype"), type = "character", default = "kegg", help = "ID type used for the compound data"),
28 make_option(c("--multi_state"), type = "logical", default = TRUE, help = "Are the gene and compound data paired?"), 28 make_option(c("--multi_state"), type = "logical", default = TRUE, help = "Are the gene and compound data paired?"),
29 make_option(c("--match_data"), type = "logical", default = TRUE, help = "Are the gene and compound data paired?"), 29 make_option(c("--match_data"), type = "logical", default = TRUE, help = "Are the gene and compound data paired?"),
30 make_option(c("--kegg_native"), type = "logical", default = TRUE, help = "Render pathway graph as native KEGG grap? Alternative is the Graphviz layout"), 30 make_option(c("--kegg_native"), type = "logical", default = TRUE, help = "Render pathway graph as native KEGG grap? Alternative is the Graphviz layout"),
31 make_option(c("--same_layer"), type = "logical", default = TRUE, help = "Plot on same layer?"), 31 make_option(c("--same_layer"), type = "logical", default = TRUE, help = "Plot on same layer?"),
32 make_option(c("--map_null"), type = "logical", default = TRUE, help = "Map the NULL gene or compound data to pathway?"), 32 make_option(c("--map_null"), type = "logical", default = TRUE, help = "Map the NULL gene or compound data to pathway?"),
33 make_option(c("--split_group"), type = "logical", default = FALSE, help = "Split node groups into individual nodes?"), 33 make_option(c("--split_group"), type = "logical", default = FALSE, help = "Split node groups into individual nodes?"),
34 make_option(c("--expand_node"), type = "logical", default = FALSE, help = "Expand multiple-gene nodes into single-gene nodes?"), 34 make_option(c("--expand_node"), type = "logical", default = FALSE, help = "Expand multiple-gene nodes into single-gene nodes?"),
35 make_option(c("--sign_pos"), type = "character", default = "bottomright", help = "Position of pathview signature") 35 make_option(c("--sign_pos"), type = "character", default = "bottomright", help = "Position of pathview signature")
36 ) 36 )
37 37
38 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) 38 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
39 args <- parse_args(parser) 39 args <- parse_args(parser)
40 print(args) 40 print(args)
41 41
42 read_table <- function(fp, header, rownames = 1, colclasses = NA) { 42 read_table <- function(fp, header, rownames = 1, colclasses = NA) {
43 table <- read.table(fp, header = header, sep = "\t", row.names = rownames, colClasses = colclasses) 43 table <- read.table(fp, header = header, sep = "\t", row.names = rownames, colClasses = colclasses)
44 # transform to vector if only one column 44 # transform to vector if only one column
45 if (dim(table)[2] == 1) { 45 if (dim(table)[2] == 1) {
46 names <- rownames(table) 46 names <- rownames(table)
47 table <- table[, 1] 47 table <- table[, 1]
48 names(table) <- names 48 names(table) <- names
49 } 49 }
50 return(table) 50 return(table)
51 } 51 }
52 52
53 get_table <- function(fp, header) { 53 get_table <- function(fp, header) {
54 table <- NULL 54 table <- NULL
55 if (!is.null(fp)) { 55 if (!is.null(fp)) {
56 table <- read_table(fp, header, rownames = 1) 56 table <- read_table(fp, header, rownames = 1)
57 } 57 }
58 return(table) 58 return(table)
59 } 59 }
60 60
61 # load gene_data file 61 # load gene_data file
62 gene_data <- get_table(args$gene_data, args$gd_header) 62 gene_data <- get_table(args$gene_data, args$gd_header)
63 63
64 # load compound data file 64 # load compound data file
65 cpd_data <- get_table(args$cpd_data, args$cpd_header) 65 cpd_data <- get_table(args$cpd_data, args$cpd_header)
66 66
67 run_pathview <- function(pathway_id) { 67 run_pathview <- function(pathway_id) {
68 pathview( 68 pathview(
69 pathway.id = pathway_id, 69 pathway.id = pathway_id,
70 gene.data = gene_data, 70 gene.data = gene_data,
71 gene.idtype = args$gene_idtype, 71 gene.idtype = args$gene_idtype,
72 cpd.data = cpd_data, 72 cpd.data = cpd_data,
73 cpd.idtype = args$cpd_idtype, 73 cpd.idtype = args$cpd_idtype,
74 species = args$species, 74 species = args$species,
75 multi.state = args$multi_state, 75 multi.state = args$multi_state,
76 match.data = args$match_data, 76 match.data = args$match_data,
77 kegg.native = args$kegg_native, 77 kegg.native = args$kegg_native,
78 same.layer = args$same_layer, 78 same.layer = args$same_layer,
79 split.group = args$split_group, 79 split.group = args$split_group,
80 expand.node = args$expand_node, 80 expand.node = args$expand_node,
81 sign.pos = args$sign_pos, 81 sign.pos = args$sign_pos,
82 map.null = args$map_null) 82 map.null = args$map_null
83 )
83 } 84 }
84 85
85 # get pathway ids 86 # get pathway ids
86 if (!is.null(args$pathway_id)) { 87 if (!is.null(args$pathway_id)) {
87 run_pathview(args$pathway_id) 88 run_pathview(args$pathway_id)
88 } else { 89 } else {
89 pthws <- read_table(args$pathway_id_fp, args$pathway_id_header, rownames = NULL, colclasses = "character") 90 pthws <- read_table(args$pathway_id_fp, args$pathway_id_header, rownames = NULL, colclasses = "character")
90 for (p in pthws) { 91 for (p in pthws) {
91 run_pathview(p) 92 run_pathview(p)
92 } 93 }
93 } 94 }