comparison pathview.r @ 2:fe154a7af404 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/pathview commit f21f5effc122e992ed977bc42b27f9520f59a33b"
author iuc
date Fri, 08 Apr 2022 15:36:51 +0000
parents bd99e8fbde97
children
comparison
equal deleted inserted replaced
1:03c13085aecc 2:fe154a7af404
1 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) 1 error_foo <- function() {
2 cat(geterrmessage(), file = stderr());
3 q("no", 1, F)
4 }
5 options(show.error.messages = F, error = error_foo)
2 6
3 # 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.
4 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") 8 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
5 9
6 suppressPackageStartupMessages({ 10 suppressPackageStartupMessages({
9 }) 13 })
10 14
11 sessionInfo() 15 sessionInfo()
12 16
13 option_list <- list( 17 option_list <- list(
14 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"),
15 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"),
16 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"),
17 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"),
18 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"),
19 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"),
20 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"),
21 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"),
22 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"),
23 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"),
24 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?"),
25 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?"),
26 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"),
27 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?"),
28 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?"),
29 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?"),
30 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?"),
31 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")
32 ) 36 )
33 37
34 parser <- OptionParser(usage = "%prog [options] file", option_list=option_list) 38 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
35 args = parse_args(parser) 39 args <- parse_args(parser)
36 print(args) 40 print(args)
37 41
38 read_table = function(fp, header, rownames=1, colclasses=NA){ 42 read_table <- function(fp, header, rownames = 1, colclasses = NA) {
39 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)
40 # transform to vector if only one column 44 # transform to vector if only one column
41 if(dim(table)[2] == 1){ 45 if (dim(table)[2] == 1) {
42 names = rownames(table) 46 names <- rownames(table)
43 table = table[,1] 47 table <- table[, 1]
44 names(table) = names 48 names(table) <- names
45 } 49 }
46 return(table) 50 return(table)
47 } 51 }
48 52
49 get_table = function(fp, header){ 53 get_table <- function(fp, header) {
50 table = NULL 54 table <- NULL
51 if(!is.null(fp)){ 55 if (!is.null(fp)) {
52 table = read_table(fp, header, rownames=1) 56 table <- read_table(fp, header, rownames = 1)
53 } 57 }
54 return(table) 58 return(table)
55 } 59 }
56 60
57 # load gene_data file 61 # load gene_data file
58 gene_data = get_table(args$gene_data, args$gd_header) 62 gene_data <- get_table(args$gene_data, args$gd_header)
59 63
60 # load compound data file 64 # load compound data file
61 cpd_data = get_table(args$cpd_data, args$cpd_header) 65 cpd_data <- get_table(args$cpd_data, args$cpd_header)
62 66
63 run_pathview = function(pathway_id){ 67 run_pathview <- function(pathway_id) {
64 pathview( 68 pathview(
65 pathway.id=pathway_id, 69 pathway.id = pathway_id,
66 gene.data=gene_data, 70 gene.data = gene_data,
67 gene.idtype=args$gene_idtype, 71 gene.idtype = args$gene_idtype,
68 cpd.data=cpd_data, 72 cpd.data = cpd_data,
69 cpd.idtype=args$cpd_idtype, 73 cpd.idtype = args$cpd_idtype,
70 species=args$species, 74 species = args$species,
71 multi.state=args$multi_state, 75 multi.state = args$multi_state,
72 match.data=args$match_data, 76 match.data = args$match_data,
73 kegg.native=args$kegg_native, 77 kegg.native = args$kegg_native,
74 same.layer=args$same_layer, 78 same.layer = args$same_layer,
75 split.group=args$split_group, 79 split.group = args$split_group,
76 expand.node=args$expand_node, 80 expand.node = args$expand_node,
77 sign.pos=args$sign_pos, 81 sign.pos = args$sign_pos,
78 map.null=args$map_null) 82 map.null = args$map_null)
79 } 83 }
80 84
81 # get pathway ids 85 # get pathway ids
82 if(!is.null(args$pathway_id)){ 86 if (!is.null(args$pathway_id)) {
83 run_pathview(args$pathway_id) 87 run_pathview(args$pathway_id)
84 } else { 88 } else {
85 pthws = read_table(args$pathway_id_fp, args$pathway_id_header, rownames=NULL, colclasses="character") 89 pthws <- read_table(args$pathway_id_fp, args$pathway_id_header, rownames = NULL, colclasses = "character")
86 for(p in pthws){ 90 for (p in pthws) {
87 run_pathview(p) 91 run_pathview(p)
88 } 92 }
89 } 93 }