annotate goseq.r @ 2:ab492df30cdf draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
author iuc
date Mon, 23 Oct 2017 11:19:12 -0400
parents ade933eff007
children 783e8b70b047
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")
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
9 })
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
10
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
11 option_list <- list(
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
12 make_option(c("-d", "--dge_file"), type="character", help="Path to file with differential gene expression result"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
13 make_option(c("-w","--wallenius_tab"), type="character", help="Path to output file with P-values estimated using wallenius distribution."),
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
14 make_option(c("-s","--sampling_tab"), type="character", default=FALSE, help="Path to output file with P-values estimated using sampling distribution."),
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
15 make_option(c("-n","--nobias_tab"), type="character", default=FALSE, help="Path to output file with P-values estimated using hypergeometric distribution and no correction for gene length bias."),
0
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("-l","--length_bias_plot"), type="character", default=FALSE, help="Path to length-bias plot."),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
17 make_option(c("-sw","--sample_vs_wallenius_plot"), type="character", default=FALSE, help="Path to plot comparing sampling with wallenius p-values."),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
18 make_option(c("-r", "--repcnt"), type="integer", default=100, help="Number of repeats for sampling"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
19 make_option(c("-lf", "--length_file"), type="character", default="FALSE", help = "Path to tabular file mapping gene id to length"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
20 make_option(c("-cat_file", "--category_file"), default="FALSE", type="character", help = "Path to tabular file with gene_id <-> category mapping."),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
21 make_option(c("-g", "--genome"), default=NULL, type="character", help = "Genome [used for looking up correct gene length]"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
22 make_option(c("-i", "--gene_id"), default=NULL, type="character", help = "Gene ID format of genes in DGE file"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
23 make_option(c("-p", "--p_adj_method"), default="BH", type="character", help="Multiple hypothesis testing correction method to use"),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
24 make_option(c("-cat", "--use_genes_without_cat"), default=FALSE, type="logical",
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
25 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)."),
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
26 make_option(c("-plots", "--make_plots"), default=FALSE, type="logical", help="produce diagnostic plots?"),
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
27 make_option(c("-fc", "--fetch_cats"), default=NULL, type="character", help="Categories to get can include one or more of GO:CC, GO:BP, GO:MF, KEGG"),
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
28 make_option(c("-rd", "--rdata"), default=NULL, type="character", help="Path to RData output file.")
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
29 )
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
30
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
31 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
32 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
33
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
34 # Vars:
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
35 dge_file = args$dge_file
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
36 category_file = args$category_file
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
37 length_file = args$length_file
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
38 genome = args$genome
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
39 gene_id = args$gene_id
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
40 wallenius_tab = args$wallenius_tab
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
41 sampling_tab = args$sampling_tab
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
42 nobias_tab = args$nobias_tab
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
43 length_bias_plot = args$length_bias_plot
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
44 sample_vs_wallenius_plot = args$sample_vs_wallenius_plot
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
45 repcnt = args$repcnt
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
46 p_adj_method = args$p_adj_method
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
47 use_genes_without_cat = args$use_genes_without_cat
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
48 make_plots = args$make_plots
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
49 rdata = args$rdata
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
50
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
51 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
52 fetch_cats = unlist(strsplit(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
53 }
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
54
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
55 # 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
56 # check if header is present
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
57 first_line = read.delim(dge_file, header = FALSE, nrow=1)
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
58 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
59 if (second_col == TRUE || second_col == FALSE) {
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
60 dge_table = read.delim(dge_file, header = FALSE, sep="\t")
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
61 } else {
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
62 dge_table = read.delim(dge_file, header = TRUE, sep="\t")
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
63 }
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
64 genes = as.numeric(as.logical(dge_table[,ncol(dge_table)])) # Last column contains TRUE/FALSE
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
65 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
66
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
67 # gene lengths, assuming last column
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
68 if (length_file != "FALSE" ) {
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
69 first_line = read.delim(length_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
70 if (is.numeric(first_line[, ncol(first_line)])) {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
71 length_table = read.delim(length_file, header=FALSE, sep="\t", check.names=FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
72 } else {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
73 length_table = read.delim(length_file, header=TRUE, sep="\t", check.names=FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
74 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
75 row.names(length_table) = length_table[,1]
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
76 gene_lengths = length_table[names(genes),][,ncol(length_table)]
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
77 } else {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
78 gene_lengths = getlength(names(genes), genome, gene_id)
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
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
81 # Estimate PWF
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
82
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
83 if (make_plots != 'false') {
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
84 pdf(length_bias_plot)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
85 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
86 pwf=nullp(genes, genome = genome, id = gene_id, bias.data = gene_lengths, plot.fit=make_plots)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
87 graphics.off()
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 # Fetch GO annotations if category_file hasn't been supplied:
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
90 if (category_file == "FALSE") {
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
91 go_map=getgo(genes = names(genes), genome=genome, id=gene_id, fetch.cats=fetch_cats)
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
92 } else {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
93 # check for header: first entry in first column must be present in genes, else it's a header
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
94 first_line = read.delim(category_file, header = FALSE, nrow=1)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
95 if (first_line[,1] %in% names(genes)) {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
96 go_map = read.delim(category_file, header = FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
97 } else {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
98 go_map = read.delim(category_file, header= TRUE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
99 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
100 }
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 # wallenius approximation of p-values
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
103 if (wallenius_tab != "" && wallenius_tab!="None") {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
104 GO.wall=goseq(pwf, genome = genome, id = gene_id, use_genes_without_cat = use_genes_without_cat, gene2cat=go_map)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
105 GO.wall$p.adjust.over_represented = p.adjust(GO.wall$over_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
106 GO.wall$p.adjust.under_represented = p.adjust(GO.wall$under_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
107 write.table(GO.wall, wallenius_tab, sep="\t", row.names = FALSE, quote = FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
108 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
109
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
110 # hypergeometric (no length bias correction)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
111 if (nobias_tab != "" && nobias_tab != "None") {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
112 GO.nobias=goseq(pwf, genome = genome, id = gene_id, method="Hypergeometric", use_genes_without_cat = use_genes_without_cat, gene2cat=go_map)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
113 GO.nobias$p.adjust.over_represented = p.adjust(GO.nobias$over_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
114 GO.nobias$p.adjust.under_represented = p.adjust(GO.nobias$under_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
115 write.table(GO.nobias, nobias_tab, sep="\t", row.names = FALSE, quote = FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
116 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
117
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
118 # Sampling distribution
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
119 if (repcnt > 0) {
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
120
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
121 # capture the sampling progress so it doesn't fill stdout
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
122 zz <- file("/dev/null", open = "wt")
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
123 sink(zz)
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
124 GO.samp=goseq(pwf, genome = genome, id = gene_id, method="Sampling", repcnt=repcnt, use_genes_without_cat = use_genes_without_cat, gene2cat=go_map)
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
125 sink()
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
126
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
127 GO.samp$p.adjust.over_represented = p.adjust(GO.samp$over_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
128 GO.samp$p.adjust.under_represented = p.adjust(GO.samp$under_represented_pvalue, method=p_adj_method)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
129 write.table(GO.samp, sampling_tab, sep="\t", row.names = FALSE, quote = FALSE)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
130 # Compare sampling with wallenius
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
131 if (make_plots == TRUE) {
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
132 pdf(sample_vs_wallenius_plot)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
133 plot(log10(GO.wall[,2]), log10(GO.samp[match(GO.samp[,1],GO.wall[,1]),2]),
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
134 xlab="log10(Wallenius p-values)",ylab="log10(Sampling p-values)",
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
135 xlim=c(-3,0))
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
136 abline(0,1,col=3,lty=2)
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
137 graphics.off()
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
138 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
139 }
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
140
2
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
141 # 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
142 if (!is.null(args$rdata)) {
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
143 save.image(file = "goseq_analysis.RData")
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
144 }
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
145
ab492df30cdf planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit 4a3c9f195ba5d899b1a1ce5e80281cdf230f456a
iuc
parents: 0
diff changeset
146
0
ade933eff007 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/goseq commit b7dcd020c6a15fa55f392cc09cbc37580d6e75c4
iuc
parents:
diff changeset
147 sessionInfo()