annotate batch-consistency-plot.r @ 11:5cc393c09610 draft

Uploaded
author modencode-dcc
date Thu, 17 Jan 2013 15:59:22 -0500
parents bdd073e7ad8b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
1 # 1-20-10 Qunhua Li
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
2 #
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
3 # This program first plots correspondence curve and IDR threshold plot
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
4 # (i.e. number of selected peaks vs IDR) for each pair of sample
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
5 #
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
6 # usage:
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
7 # Rscript batch-consistency-plot-merged.r [npairs] [output.dir] [input.file.prefix 1, 2, 3 ...]
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
8 # [npairs]: integer, number of consistency analyses
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
9 # (e.g. if 2 replicates, npairs=1, if 3 replicates, npairs=3
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
10 # [output.prefix]: output directory and file name prefix for plot eg. /plots/idrPlot
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
11 # [input.file.prefix 1, 2, 3]: prefix for the output from batch-consistency-analysis2. They are the input files for merged analysis see below for examples (i.e. saved.file.prefix). It can be multiple files
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
12 #
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
13
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
14 args <- commandArgs(trailingOnly=T)
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
15 npair <- args[1] # number of curves to plot on the same figure
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
16 output.file.prefix <- args[2] # file name for plot, generated from script at the outer level
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
17 df.txt <- 10
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
18 ntemp <- as.numeric(npair)
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
19 saved.file.prefix <- list() # identifier of filenames that contain the em and URI results
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
20 source("/mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/idr/functions-all-clayton-12-13.r")
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
21
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
22 uri.list <- list()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
23 uri.list.match <- list()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
24 ez.list <- list()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
25 legend.txt <- c()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
26 em.output.list <- list()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
27 uri.output.list <- list()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
28
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
29 for(i in 1:npair){
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
30 saved.file.prefix[i] <- args[2+i]
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
31
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
32 load(paste(saved.file.prefix[i], "-uri.sav", sep=""))
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
33 load(paste(saved.file.prefix[i], "-em.sav", sep=""))
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
34
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
35 uri.output.list[[i]] <- uri.output
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
36 em.output.list[[i]] <- em.output
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
37
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
38 ez.list[[i]] <- get.ez.tt.all(em.output, uri.output.list[[i]]$data12.enrich$merge1,
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
39 uri.output.list[[i]]$data12.enrich$merge2) # reverse =T for error rate
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
40
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
41 # URI for all peaks
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
42 uri.list[[i]] <- uri.output$uri.n
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
43 # URI for matched peaks
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
44 uri.match <- get.uri.matched(em.output$data.pruned, df=df.txt)
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
45 uri.list.match[[i]] <- uri.match$uri.n
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
46
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
47 file.name <- unlist(strsplit(as.character(saved.file.prefix[i]), "/"))
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
48
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
49 legend.txt[i] <- paste(i, "=", file.name[length(file.name)])
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
50
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
51 }
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
52
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
53 plot.uri.file <- paste(output.file.prefix, "-plot.ps", sep="")
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
54
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
55 ############# plot and report output
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
56 # plot correspondence curve for each pair,
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
57 # plot number of selected peaks vs IDR
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
58 # plot all into 1 file
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
59 postscript(paste(output.file.prefix, "-plot.ps", sep=""))
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
60 par(mfcol=c(2,3), mar=c(5,6,4,2)+0.1)
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
61 plot.uri.group(uri.list, NULL, file.name=NULL, c(1:npair), title.txt="all peaks")
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
62 plot.uri.group(uri.list.match, NULL, file.name=NULL, c(1:npair), title.txt="matched peaks")
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
63 plot.ez.group(ez.list, plot.dir=NULL, file.name=NULL, legend.txt=c(1:npair), y.lim=c(0, 0.6))
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
64 plot(0, 1, type="n", xlim=c(0,1), ylim=c(0,1), xlab="", ylab="", xaxt="n", yaxt="n") # legends
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
65 legend(0, 1, legend.txt, cex=0.6)
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
66
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
67 dev.off()
bdd073e7ad8b Uploaded
modencode-dcc
parents:
diff changeset
68