Mercurial > repos > mvdbeek > r_goseq_1_22_0
comparison goseq.r @ 0:a6427f7893b0 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/goseq_1_22_0 commit fdd0811efc61c31f88ff17096fbe8ee8cfacd766-dirty
author | mvdbeek |
---|---|
date | Fri, 26 Feb 2016 06:57:47 -0500 |
parents | |
children | 81283f3d65c7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a6427f7893b0 |
---|---|
1 sink(stdout(), type = "message") | |
2 library(goseq) | |
3 library(optparse) | |
4 | |
5 option_list <- list( | |
6 make_option(c("-d", "--dge_file"), type="character", help="Path to file with differential gene expression result"), | |
7 make_option(c("-w","--wallenius_tab"), type="character", help="Path to output file with P-values estimated using wallenius distribution."), | |
8 make_option(c("-s","--sampling_tab"), type="character", default=FALSE, help="Path to output file with P-values estimated using wallenius distribution."), | |
9 make_option(c("-n","--nobias_tab"), type="character", default=FALSE, help="Path to output file with P-values estimated using wallenius distribution and no correction for gene length bias."), | |
10 make_option(c("-l","--length_bias_plot"), type="character", default=FALSE, help="Path to length-bias plot."), | |
11 make_option(c("-sw","--sample_vs_wallenius_plot"), type="character", default=FALSE, help="Path to plot comparing sampling with wallenius p-values."), | |
12 make_option(c("-padj", "--p_adj_column"), type="integer",help="Column that contains p. adjust values"), | |
13 make_option(c("-c", "--cutoff"), type="double",dest="p_adj_cutoff", | |
14 help="Genes with p.adjust below cutoff are considered not differentially expressed and serve as control genes"), | |
15 make_option(c("-r", "--repcnt"), type="integer", default=100, help="Number of repeats for sampling"), | |
16 make_option(c("-lf", "--length_file"), default=FALSE, help = "Path to "), | |
17 make_option(c("-g", "--genome"), type="character", help = "Genome [used for looking up correct gene length]"), | |
18 make_option(c("-i", "--gene_id"), type="character", help="Gene ID of gene column in DGE file") | |
19 ) | |
20 parser <- OptionParser(usage = "%prog [options] file", option_list=option_list) | |
21 args = parse_args(parser) | |
22 | |
23 # Vars: | |
24 dge_file = args$dge_file | |
25 p_adj_column = args$p_adj_colum | |
26 p_adj_cutoff = args$p_adj_cutoff | |
27 length_file = args$length_file | |
28 genome = args$genome | |
29 gene_id = args$gene_id | |
30 wallenius_tab = args$wallenius_tab | |
31 sampling_tab = args$sampling_tab | |
32 nobias_tab = args$nobias_tab | |
33 length_bias_plot = args$length_bias_plot | |
34 sample_vs_wallenius_plot = args$sample_vs_wallenius_plot | |
35 repcnt = args$repcnt | |
36 | |
37 | |
38 # format DE genes into vector suitable for use with goseq | |
39 dge_table = read.delim(dge_file, header = TRUE, sep="\t", check.names = FALSE) | |
40 genes = as.integer(dge_table[,p_adj_column]<p_adj_cutoff) | |
41 names(genes) = dge_table[,1] # Assuming first row contains gene names | |
42 | |
43 # Get gene lengths | |
44 | |
45 if (length_file) { | |
46 length_table = read.delim(length_file, header=TRUE, sep="\t", check.names=FALSE, row.names=TRUE) | |
47 gene_lengths = length_table[names(genes),]$length | |
48 } else { | |
49 gene_lengths = getlength(names(genes), genome, gene_id) | |
50 } | |
51 | |
52 # Estimate PWF | |
53 | |
54 pdf(length_bias_plot) | |
55 pwf=nullp(genes, genome, gene_id, gene_lengths) | |
56 dev.off() | |
57 # wallenius approximation of p-values | |
58 GO.wall=goseq(pwf, genome, gene_id) | |
59 | |
60 GO.nobias=goseq(pwf, genome, gene_id, method="Hypergeometric") | |
61 | |
62 # Sampling distribution | |
63 if (repcnt > 0) { | |
64 GO.samp=goseq(pwf,genome, gene_id, method="Sampling", repcnt=repcnt) | |
65 # Compare sampling with wallenius | |
66 pdf(sample_vs_wallenius_plot) | |
67 plot(log10(GO.wall[,2]), log10(GO.samp[match(GO.samp[,1],GO.wall[,1]),2]), | |
68 xlab="log10(Wallenius p-values)",ylab="log10(Sampling p-values)", | |
69 xlim=c(-3,0)) | |
70 abline(0,1,col=3,lty=2) | |
71 dev.off() | |
72 write.table(GO.samp, sampling_tab, sep="\t", row.names = FALSE, quote = FALSE) | |
73 } | |
74 | |
75 | |
76 write.table(GO.wall, wallenius_tab, sep="\t", row.names = FALSE, quote = FALSE) | |
77 write.table(GO.nobias, nobias_tab, sep="\t", row.names = FALSE, quote = FALSE) | |
78 | |
79 sessionInfo() | |
80 | |
81 # Use the following to get a list of supported genomes / gene ids | |
82 | |
83 # write.table(supportedGenomes(), "available_genomes.tab", row.names = FALSE, quote=FALSE) | |
84 # write.table(supportedGeneIDs(), "supported_gene_ids.tab", row.name = FALSE, quote = FALSE) | |
85 # write.table(table.summary, "input_gene_count_matrix.tab", row.names = FALSE, quote = FALSE) |