Mercurial > repos > rnateam > chipseeker
annotate chipseeker.R @ 1:2019b4dd86a8 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
author | rnateam |
---|---|
date | Tue, 29 May 2018 15:07:04 -0400 |
parents | |
children | 195cba35110e |
rev | line source |
---|---|
1
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
1 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
2 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
3 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
4 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
5 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
6 suppressPackageStartupMessages({ |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
7 library(ChIPseeker) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
8 library(GenomicFeatures) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
9 library(optparse) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
10 }) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
11 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
12 option_list <- list( |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
13 make_option(c("-i","--infile"), type="character", help="Peaks file to be annotated"), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
14 make_option(c("-G","--gtf"), type="character", help="GTF to create TxDb."), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
15 make_option(c("-u","--upstream"), type="integer", help="TSS upstream region"), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
16 make_option(c("-d","--downstream"), type="integer", help="TSS downstream region"), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
17 make_option(c("-F","--flankgeneinfo"), type="logical", help="Add flanking gene info"), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
18 make_option(c("-D","--flankgenedist"), type="integer", help="Flanking gene distance"), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
19 make_option(c("-f","--format"), type="character", help="Output format (interval or tabular)."), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
20 make_option(c("-p","--plots"), type="character", help="PDF of plots.") |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
21 ) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
22 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
23 parser <- OptionParser(usage = "%prog [options] file", option_list=option_list) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
24 args = parse_args(parser) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
25 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
26 peaks = args$infile |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
27 gtf = args$gtf |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
28 up = args$upstream |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
29 down = args$downstream |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
30 format = args$format |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
31 plots = args$plots |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
32 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
33 peaks <- readPeakFile(peaks) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
34 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
35 # Make TxDb from GTF |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
36 txdb <- makeTxDbFromGFF(gtf, format="gtf") |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
37 if (!is.null(args$flankgeneinfo)) { |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
38 peakAnno <- annotatePeak(peaks, TxDb=txdb, tssRegion=c(-up, down), addFlankGeneInfo=args$flankgeneinfo, flankDistance=args$flankgenedist) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
39 } else { |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
40 peakAnno <- annotatePeak(peaks, TxDb=txdb, tssRegion=c(-up, down)) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
41 } |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
42 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
43 # Convert from 1-based to 0-based format |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
44 res <- as.GRanges(peakAnno) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
45 metacols <- mcols(res) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
46 if (format == "interval") { |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
47 metacols <- apply(as.data.frame(metacols), 1, function(col) paste(col, collapse="|")) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
48 resout <- data.frame(Chrom=seqnames(res), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
49 Start=start(res) - 1, |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
50 End=end(res), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
51 Comment=metacols) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
52 } else { |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
53 resout <- data.frame(Chrom=seqnames(res), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
54 Start=start(res) - 1, |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
55 End=end(res), |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
56 metacols) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
57 } |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
58 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
59 write.table(resout, file="out.tab", sep="\t", row.names=FALSE, quote=FALSE) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
60 |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
61 if (!is.null(plots)) { |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
62 pdf("out.pdf", width=14) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
63 plotAnnoPie(peakAnno) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
64 plotAnnoBar(peakAnno) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
65 vennpie(peakAnno) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
66 upsetplot(peakAnno) |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
67 plotDistToTSS(peakAnno, title="Distribution of transcription factor-binding loci\nrelative to TSS") |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
68 dev.off() |
2019b4dd86a8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff
changeset
|
69 } |