annotate goseq.r @ 8:8b3e3657034e draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
author iuc
date Fri, 06 Sep 2019 07:50:46 -0400
parents 67c29afac85f
children ef2ad746b589
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
1 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
2
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
3 # 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
4 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
5
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
6 suppressPackageStartupMessages({
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
7 library("goseq")
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
8 library("optparse")
3
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
9 library("dplyr")
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
10 library("ggplot2")
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
11 })
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
12
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
13 sessionInfo()
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
14
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
15 option_list <- list(
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
16 make_option(c("-d", "--dge_file"), type="character", help="Path to file with differential gene expression result"),
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
17 make_option(c("-lf", "--length_file"), type="character", default=NULL, help="Path to tabular file mapping gene id to length"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
18 make_option(c("-g", "--genome"), type="character", default=NULL, help="Genome [used for looking up correct gene length]"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
19 make_option(c("-i", "--gene_id"), type="character", default=NULL, help="Gene ID format of genes in DGE file"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
20 make_option(c("-fc", "--fetch_cats"), type="character", default=NULL, help="Categories to get can include one or more of GO:CC, GO:BP, GO:MF, KEGG"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
21 make_option(c("-cat_file", "--category_file"), type="character", default=NULL, help="Path to tabular file with gene_id <-> category mapping"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
22 make_option(c("-w","--wallenius_tab"), type="character", default=NULL, help="Path to output file with P-values estimated using wallenius distribution"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
23 make_option(c("-n","--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"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
24 make_option(c("-r", "--repcnt"), type="integer", default=0, help="Number of repeats for sampling"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
25 make_option(c("-s","--sampling_tab"), type="character", default=NULL, help="Path to output file with P-values estimated using sampling distribution"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
26 make_option(c("-p", "--p_adj_method"), type="character", default="BH", help="Multiple hypothesis testing correction method to use"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
27 make_option(c("-cat", "--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)."),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
28 make_option(c("-tp", "--top_plot"), type="character", default=NULL, help="Path to output PDF with top10 over-rep GO terms"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
29 make_option(c("-plots", "--make_plots"), default=FALSE, type="logical", help="Produce diagnostic plots?"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
30 make_option(c("-l","--length_bias_plot"), type="character", default=NULL, help="Path to length-bias plot"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
31 make_option(c("-sw","--sample_vs_wallenius_plot"), type="character", default=NULL, help="Path to plot comparing sampling with wallenius p-values"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
32 make_option(c("-rd", "--rdata"), type="character", default=NULL, help="Path to RData output file"),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
33 make_option(c("-g2g", "--categories_genes_out_fp"), type="character", default=NULL, help="Path to file with categories (GO/KEGG terms) and associated DE genes")
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
34 )
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
35
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
36 parser <- OptionParser(usage = "%prog [options] file", option_list=option_list)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
37 args = parse_args(parser)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
38
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
39 if (!is.null(args$fetch_cats)) {
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
40 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
41 } else {
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
42 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
43 }
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
44
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
45 # 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
46 # check if header is present
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
47 first_line = read.delim(args$dge_file, header=FALSE, nrow=1)
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
48 second_col = toupper(first_line[, ncol(first_line)])
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
49 if (second_col == TRUE || second_col == FALSE) {
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
50 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
51 } else {
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
52 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
53 }
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
54 genes = as.numeric(as.logical(dge_table[, ncol(dge_table)])) # Last column contains TRUE/FALSE
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
55 names(genes) = dge_table[,1] # Assuming first column contains gene names
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
56
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
57 # gene lengths, assuming last column
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
58 first_line = read.delim(args$length_file, header=FALSE, nrow=1)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
59 if (is.numeric(first_line[, ncol(first_line)])) {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
60 length_table = read.delim(args$length_file, header=FALSE, sep="\t", check.names=FALSE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
61 } else {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
62 length_table = read.delim(args$length_file, header=TRUE, sep="\t", check.names=FALSE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
63 }
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
64 row.names(length_table) = length_table[,1]
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
65 # get vector of gene length in same order as the genes
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
66 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
67
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
68 # 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
69 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
70 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
71 }
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
72 pwf=nullp(genes, genome=args$genome, id=args$gene_id, bias.data=gene_lengths, plot.fit=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 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
74 dev.off()
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
75 }
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
76
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
77 # 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
78 if (is.null(args$category_file)) {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
79 go_map=getgo(genes=names(genes), genome=args$genome, id=args$gene_id, fetch.cats=fetch_cats)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
80 } else {
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
81 # check for header: first entry in first column must be present in genes, else it's a header
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
82 first_line = read.delim(args$category_file, header=FALSE, nrow=1)
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
83 if (first_line[,1] %in% names(genes)) {
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
84 go_map = read.delim(args$category_file, header=FALSE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
85 } else {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
86 go_map = read.delim(args$category_file, header=TRUE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
87 }
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
88 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
89
3
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
90 results <- list()
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
91
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
92 runGoseq <- function(pwf, genome, gene_id, goseq_method, use_genes_without_cat, repcnt, gene2cat, p_adj_method, out_fp){
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
93 out=goseq(pwf, genome=genome, id=gene_id, method=goseq_method, use_genes_without_cat=use_genes_without_cat, gene2cat=go_map)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
94 out$p.adjust.over_represented = p.adjust(out$over_represented_pvalue, method=p_adj_method)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
95 out$p.adjust.under_represented = p.adjust(out$under_represented_pvalue, method=p_adj_method)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
96 write.table(out, out_fp, sep="\t", row.names=FALSE, quote=FALSE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
97 return(out)
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
98 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
99
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
100 # wallenius approximation of p-values
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
101 if (!is.null(args$wallenius_tab)) results[['Wallenius']] <- runGoseq(
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
102 pwf,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
103 genome=args$genome,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
104 gene_id=args$gene_id,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
105 goseq_method="Wallenius",
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
106 use_genes_without_cat=args$use_genes_without_cat,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
107 repcnt=args$repcnt,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
108 gene2cat=go_map,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
109 p_adj_method=args$p_adj_method,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
110 out_fp=args$wallenius_tab)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
111
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
112
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
113 # hypergeometric (no length bias correction)
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
114 if (!is.null(args$nobias_tab)) results[['Hypergeometric']] <- runGoseq(
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
115 pwf,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
116 genome=args$genome,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
117 gene_id=args$gene_id,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
118 goseq_method="Hypergeometric",
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
119 use_genes_without_cat=args$use_genes_without_cat,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
120 repcnt=args$repcnt,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
121 gene2cat=go_map,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
122 p_adj_method=args$p_adj_method,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
123 out_fp=args$nobias_tab)
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
124
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
125 # Sampling distribution
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
126 if (args$repcnt > 0){
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
127 results[['Sampling']] <- runGoseq(
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
128 pwf,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
129 genome=args$genome,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
130 gene_id=args$gene_id,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
131 goseq_method="Sampling",
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
132 use_genes_without_cat=args$use_genes_without_cat,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
133 repcnt=args$repcnt,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
134 gene2cat=go_map,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
135 p_adj_method=args$p_adj_method,
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
136 out_fp=args$sampling_tab)
5
bbcf5f7f2af2 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 2dffcdff171ebf695ef0fc7eb8f8264f0d132115
iuc
parents: 4
diff changeset
137
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
138 # Compare sampling with wallenius
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
139 if (args$make_plots & !is.null(args$wallenius_tab)) {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
140 pdf(args$sample_vs_wallenius_plot)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
141 plot(log10(results[['Wallenius']][,2]),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
142 log10(results[['Sampling']][match(results[['Sampling']][,1], results[['Wallenius']][,1]), 2]),
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
143 xlab="log10(Wallenius p-values)",
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
144 ylab="log10(Sampling p-values)",
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
145 xlim=c(-3,0))
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
146 abline(0,1,col=3,lty=2)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
147 dev.off()
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
148 }
3
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
149 }
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
150
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
151 # 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
152 if (!is.null(args$top_plot)) {
4
ae39895af5fe planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 0798278a90c08228a386516881680b328fc33f0c
iuc
parents: 3
diff changeset
153 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
154 # 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
155 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
156 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
157 p <- results[[m]] %>%
5
bbcf5f7f2af2 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 2dffcdff171ebf695ef0fc7eb8f8264f0d132115
iuc
parents: 4
diff changeset
158 top_n(10, wt=-over_represented_pvalue) %>%
3
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
159 mutate(hitsPerc=numDEInCat*100/numInCat) %>%
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
160 ggplot(aes(x=hitsPerc,
7
67c29afac85f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e60c1cecc4561d61624799b0999e89687677ab1
iuc
parents: 5
diff changeset
161 y=reorder(substr(term, 1, 40), -over_represented_pvalue), # only use 1st 40 chars of terms otherwise squashes plot
67c29afac85f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e60c1cecc4561d61624799b0999e89687677ab1
iuc
parents: 5
diff changeset
162 colour=p.adjust.over_represented,
3
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
163 size=numDEInCat)) +
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
164 geom_point() +
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
165 expand_limits(x=0) +
7
67c29afac85f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e60c1cecc4561d61624799b0999e89687677ab1
iuc
parents: 5
diff changeset
166 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")) +
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
167 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
168 print(p)
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
169 }
783e8b70b047 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 46c4278d292ab4d76dc5f3f74c3109c3179be7ef
iuc
parents: 2
diff changeset
170 dev.off()
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
171 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
172
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
173 # 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
174 if (!is.null(args$categories_genes_out_fp)) {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
175 cat2gene = split(rep(names(go_map), sapply(go_map, length)), unlist(go_map, use.names = FALSE))
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
176 # extract categories (GO/KEGG terms) for all results
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
177 categories = c()
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
178 for (m in names(results)) {
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
179 categories = c(categories, results[[m]]$category)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
180 }
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
181 categories = unique(categories)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
182 # extract the DE genes for each catge term
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
183 categories_genes = data.frame(Categories=categories, DEgenes=rep('', length(categories)))
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
184 categories_genes$DEgenes = as.character(categories_genes$DEgenes)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
185 rownames(categories_genes) = categories
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
186 for (cat in categories){
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
187 tmp = pwf[cat2gene[[cat]],]
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
188 tmp = rownames(tmp[tmp$DEgenes > 0, ])
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
189 categories_genes[cat, 'DEgenes'] = paste(tmp, collapse=',')
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
190 }
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
191 # output
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
192 write.table(categories_genes, args$categories_genes_out_fp, sep = "\t", row.names=FALSE, quote=FALSE)
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
193 }
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
194
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
195 # 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
196 if (!is.null(args$rdata)) {
8
8b3e3657034e "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 8e19f8bcaea6f607a1eaa14bb88f2d625ed63df0"
iuc
parents: 7
diff changeset
197 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
198 }