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