Mercurial > repos > iuc > goseq
annotate goseq.r @ 11:602de62d995b draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 0829a85b7fd9d09202450e50d30446cf9845791c
author | iuc |
---|---|
date | Wed, 11 Jan 2023 10:13:15 +0000 |
parents | ef2ad746b589 |
children |
rev | line source |
---|---|
11
602de62d995b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 0829a85b7fd9d09202450e50d30446cf9845791c
iuc
parents:
9
diff
changeset
|
1 options(show.error.messages = FALSE, error = function() { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
2 cat(geterrmessage(), file = stderr()) |
11
602de62d995b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 0829a85b7fd9d09202450e50d30446cf9845791c
iuc
parents:
9
diff
changeset
|
3 q("no", 1, FALSE) |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
4 }) |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
5 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
6 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
7 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
8 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
9 suppressPackageStartupMessages({ |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
10 library("goseq") |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
11 library("optparse") |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
12 library("dplyr") |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
13 library("ggplot2") |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
14 }) |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
15 |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
16 sessionInfo() |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
17 |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
18 option_list <- list( |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
19 make_option("--dge_file", type = "character", help = "Path to file with differential gene expression result"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
20 make_option("--length_file", type = "character", default = NULL, help = "Path to tabular file mapping gene id to length"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
21 make_option("--genome", type = "character", default = NULL, help = "Genome [used for looking up correct gene length]"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
22 make_option("--gene_id", type = "character", default = NULL, help = "Gene ID format of genes in DGE file"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
23 make_option("--fetch_cats", type = "character", default = NULL, help = "Categories to get can include one or more of GO:CC, GO:BP, GO:MF, KEGG"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
24 make_option("--category_file", type = "character", default = NULL, help = "Path to tabular file with gene_id <-> category mapping"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
25 make_option("--wallenius_tab", type = "character", default = NULL, help = "Path to output file with P-values estimated using wallenius distribution"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
26 make_option("--nobias_tab", type = "character", default = NULL, help = "Path to output file with P-values estimated using hypergeometric distribution and no correction for gene length bias"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
27 make_option("--repcnt", type = "integer", default = 0, help = "Number of repeats for sampling"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
28 make_option("--sampling_tab", type = "character", default = NULL, help = "Path to output file with P-values estimated using sampling distribution"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
29 make_option("--p_adj_method", type = "character", default = "BH", help = "Multiple hypothesis testing correction method to use"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
30 make_option("--use_genes_without_cat", type = "logical", default = FALSE, help = "A large number of gene may have no GO term annotated. If this option is set to FALSE, genes without category will be ignored in the calculation of p-values(default behaviour). If TRUE these genes will count towards the total number of genes outside the tested category (default behaviour prior to version 1.15.2)."), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
31 make_option("--top_plot", type = "character", default = NULL, help = "Path to output PDF with top10 over-rep GO terms"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
32 make_option("--make_plots", default = FALSE, type = "logical", help = "Produce diagnostic plots?"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
33 make_option("--length_bias_plot", type = "character", default = NULL, help = "Path to length-bias plot"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
34 make_option("--sample_vs_wallenius_plot", type = "character", default = NULL, help = "Path to plot comparing sampling with wallenius p-values"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
35 make_option("--rdata", type = "character", default = NULL, help = "Path to RData output file"), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
36 make_option("--categories_genes_out_fp", type = "character", default = NULL, help = "Path to file with categories (GO/KEGG terms) and associated DE genes") |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
37 ) |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
38 |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
39 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
40 args <- parse_args(parser) |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
41 |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
42 if (!is.null(args$fetch_cats)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
43 fetch_cats <- unlist(strsplit(args$fetch_cats, ",")) |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
44 } else { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
45 fetch_cats <- "Custom" |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
46 } |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
47 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
48 # format DE genes into named vector suitable for goseq |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
49 # check if header is present |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
50 first_line <- read.delim(args$dge_file, header = FALSE, nrow = 1) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
51 second_col <- toupper(first_line[, ncol(first_line)]) |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
52 if (second_col == TRUE || second_col == FALSE) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
53 dge_table <- read.delim(args$dge_file, header = FALSE, sep = "\t") |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
54 } else { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
55 dge_table <- read.delim(args$dge_file, header = TRUE, sep = "\t") |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
56 } |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
57 genes <- as.numeric(as.logical(dge_table[, ncol(dge_table)])) # Last column contains TRUE/FALSE |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
58 names(genes) <- dge_table[, 1] # Assuming first column contains gene names |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
59 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
60 # gene lengths, assuming last column |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
61 first_line <- read.delim(args$length_file, header = FALSE, nrow = 1) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
62 if (is.numeric(first_line[, ncol(first_line)])) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
63 length_table <- read.delim(args$length_file, header = FALSE, sep = "\t", check.names = FALSE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
64 } else { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
65 length_table <- read.delim(args$length_file, header = TRUE, sep = "\t", check.names = FALSE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
66 } |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
67 row.names(length_table) <- length_table[, 1] |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
68 # get vector of gene length in same order as the genes |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
69 gene_lengths <- length_table[names(genes), ][, ncol(length_table)] |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
70 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
71 # Estimate PWF |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
72 if (args$make_plots) { |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
73 pdf(args$length_bias_plot) |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
74 } |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
75 pwf <- nullp(genes, genome = args$genome, id = args$gene_id, bias.data = gene_lengths, plot.fit = args$make_plots) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
76 if (args$make_plots) { |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
77 dev.off() |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
78 } |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
79 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
80 # Fetch GO annotations if category_file hasn't been supplied: |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
81 if (is.null(args$category_file)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
82 go_map <- getgo(genes = names(genes), genome = args$genome, id = args$gene_id, fetch.cats = fetch_cats) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
83 } else { |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
84 # check for header: first entry in first column must be present in genes, else it's a header |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
85 first_line <- read.delim(args$category_file, header = FALSE, nrow = 1) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
86 if (first_line[, 1] %in% names(genes)) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
87 go_map <- read.delim(args$category_file, header = FALSE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
88 } else { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
89 go_map <- read.delim(args$category_file, header = TRUE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
90 } |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
91 } |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
92 |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
93 results <- list() |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
94 |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
95 run_goseq <- function(pwf, genome, gene_id, goseq_method, use_genes_without_cat, repcnt, gene2cat, p_adj_method, out_fp) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
96 out <- goseq(pwf, genome = genome, id = gene_id, method = goseq_method, use_genes_without_cat = use_genes_without_cat, gene2cat = go_map) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
97 out$p_adjust_over_represented <- p.adjust(out$over_represented_pvalue, method = p_adj_method) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
98 out$p_adjust_under_represented <- p.adjust(out$under_represented_pvalue, method = p_adj_method) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
99 write.table(out, out_fp, sep = "\t", row.names = FALSE, quote = FALSE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
100 return(out) |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
101 } |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
102 |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
103 # wallenius approximation of p-values |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
104 if (!is.null(args$wallenius_tab)) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
105 results[["Wallenius"]] <- run_goseq( |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
106 pwf, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
107 genome = args$genome, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
108 gene_id = args$gene_id, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
109 goseq_method = "Wallenius", |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
110 use_genes_without_cat = args$use_genes_without_cat, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
111 repcnt = args$repcnt, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
112 gene2cat = go_map, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
113 p_adj_method = args$p_adj_method, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
114 out_fp = args$wallenius_tab |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
115 ) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
116 } |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
117 |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
118 |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
119 # hypergeometric (no length bias correction) |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
120 if (!is.null(args$nobias_tab)) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
121 results[["Hypergeometric"]] <- run_goseq( |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
122 pwf, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
123 genome = args$genome, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
124 gene_id = args$gene_id, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
125 goseq_method = "Hypergeometric", |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
126 use_genes_without_cat = args$use_genes_without_cat, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
127 repcnt = args$repcnt, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
128 gene2cat = go_map, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
129 p_adj_method = args$p_adj_method, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
130 out_fp = args$nobias_tab |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
131 ) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
132 } |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
133 |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
134 # Sampling distribution |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
135 if (args$repcnt > 0) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
136 results[["Sampling"]] <- run_goseq( |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
137 pwf, |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
138 genome = args$genome, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
139 gene_id = args$gene_id, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
140 goseq_method = "Sampling", |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
141 use_genes_without_cat = args$use_genes_without_cat, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
142 repcnt = args$repcnt, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
143 gene2cat = go_map, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
144 p_adj_method = args$p_adj_method, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
145 out_fp = args$sampling_tab |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
146 ) |
5
bbcf5f7f2af2
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 2dffcdff171ebf695ef0fc7eb8f8264f0d132115
iuc
parents:
4
diff
changeset
|
147 |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
148 # Compare sampling with wallenius |
11
602de62d995b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 0829a85b7fd9d09202450e50d30446cf9845791c
iuc
parents:
9
diff
changeset
|
149 if (args$make_plots && !is.null(args$wallenius_tab)) { |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
150 pdf(args$sample_vs_wallenius_plot) |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
151 plot(log10(results[["Wallenius"]][, 2]), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
152 log10(results[["Sampling"]][match(results[["Sampling"]][, 1], results[["Wallenius"]][, 1]), 2]), |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
153 xlab = "log10(Wallenius p-values)", |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
154 ylab = "log10(Sampling p-values)", |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
155 xlim = c(-3, 0) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
156 ) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
157 abline(0, 1, col = 3, lty = 2) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
158 dev.off() |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
159 } |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
160 } |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
161 |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
162 # Plot the top 10 |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
163 if (!is.null(args$top_plot)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
164 cats_title <- gsub("GO:", "", args$fetch_cats) |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
165 # modified from https://bioinformatics-core-shared-training.github.io/cruk-summer-school-2018/RNASeq2018/html/06_Gene_set_testing.nb.html |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
166 pdf(args$top_plot) |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
167 for (m in names(results)) { |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
168 p <- results[[m]] %>% |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
169 top_n(10, wt = -over_represented_pvalue) %>% |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
170 mutate(hitsPerc = numDEInCat * 100 / numInCat) %>% |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
171 ggplot(aes( |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
172 x = hitsPerc, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
173 y = reorder(substr(term, 1, 40), -over_represented_pvalue), # only use 1st 40 chars of terms otherwise squashes plot |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
174 colour = p_adjust_over_represented, |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
175 size = numDEInCat |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
176 )) + |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
177 geom_point() + |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
178 expand_limits(x = 0) + |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
179 labs(x = "% DE in category", y = "Category", colour = "Adj P value", size = "Count", title = paste("Top over-represented categories in", cats_title), subtitle = paste(m, " method")) + |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
180 theme(plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5)) |
3
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
181 print(p) |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
182 } |
783e8b70b047
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents:
2
diff
changeset
|
183 dev.off() |
0
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
184 } |
ade933eff007
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff
changeset
|
185 |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
186 # Extract the genes to the categories (GO/KEGG terms) |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
187 if (!is.null(args$categories_genes_out_fp)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
188 cat2gene <- split(rep(names(go_map), sapply(go_map, length)), unlist(go_map, use.names = FALSE)) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
189 # extract categories (GO/KEGG terms) for all results |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
190 categories <- c() |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
191 for (m in names(results)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
192 categories <- c(categories, results[[m]]$category) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
193 } |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
194 categories <- unique(categories) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
195 # extract the DE genes for each catge term |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
196 categories_genes <- data.frame(category = categories, de_genes = rep("", length(categories))) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
197 categories_genes$de_genes <- as.character(categories_genes$de_genes) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
198 rownames(categories_genes) <- categories |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
199 for (cat in categories) { |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
200 tmp <- pwf[cat2gene[[cat]], ] |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
201 tmp <- rownames(tmp[tmp$DEgenes > 0, ]) |
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
202 categories_genes[cat, "de_genes"] <- paste(tmp, collapse = ",") |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
203 } |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
204 # output |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
205 write.table(categories_genes, args$categories_genes_out_fp, sep = "\t", row.names = FALSE, quote = FALSE) |
8
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
206 } |
8b3e3657034e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents:
7
diff
changeset
|
207 |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
208 # Output RData file |
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
209 if (!is.null(args$rdata)) { |
9
ef2ad746b589
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit e230a8db9e090c6e0ea9577863ec6153df79e145"
iuc
parents:
8
diff
changeset
|
210 save.image(file = args$rdata) |
2
ab492df30cdf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents:
0
diff
changeset
|
211 } |