annotate chipseeker.R @ 8:8bd92f2404dd draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
author rnateam
date Fri, 27 Aug 2021 10:49:39 +0000
parents 1b9a9409831d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
1 options(
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
2 show.error.messages = F,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
3 error = function() {
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
4 cat(geterrmessage(), file = stderr())
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
5 q("no", 1, F)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
6 }
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
7 )
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
8
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
9 # we need that to not crash galaxy with an UTF8 error on German LC settings.
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
10 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
11
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
12 suppressPackageStartupMessages({
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
13 library(ChIPseeker)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
14 library(GenomicFeatures)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
15 library(rtracklayer)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
16 library(optparse)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
17 library(ggupset)
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
18 })
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
19
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
20 option_list <- list(
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
21 make_option(c("-i", "--infile"), type = "character", help = "Peaks file to be annotated"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
22 make_option(c("-H", "--header"), type = "logical", help = "Peaks file contains header row"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
23 make_option(c("-G", "--gtf"), type = "character", help = "GTF to create TxDb."),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
24 make_option(c("-u", "--upstream"), type = "integer", help = "TSS upstream region"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
25 make_option(c("-d", "--downstream"), type = "integer", help = "TSS downstream region"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
26 make_option(c("-F", "--flankgeneinfo"), type = "logical", help = "Add flanking gene info"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
27 make_option(c("-D", "--flankgenedist"), type = "integer", help = "Flanking gene distance"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
28 make_option(c("-j", "--ignore_upstream"), type = "logical", help = "Ignore upstream"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
29 make_option(
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
30 c("-k", "--ignore_downstream"),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
31 type = "logical",
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
32 help = "Ignore downstream"
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
33 ),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
34 make_option(c("-f", "--format"), type = "character", help = "Output format (interval or tabular)."),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
35 make_option(c("-p", "--plots"), type = "logical", help = "PDF of plots."),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
36 make_option(c("-r", "--rdata"), type = "logical", help = "Output RData file.")
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
37 )
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
38
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
39 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
40 args <- parse_args(parser)
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
41
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
42 peaks <- args$infile
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
43 gtf <- args$gtf
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
44 up <- args$upstream
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
45 down <- args$downstream
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
46 format <- args$format
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
47
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
48 if (!is.null(args$flankgeneinfo)) {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
49 flankgeneinfo <- TRUE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
50 } else {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
51 flankgeneinfo <- FALSE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
52 }
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
53
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
54 if (!is.null(args$ignore_upstream)) {
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
55 ignore_upstream <- TRUE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
56 } else {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
57 ignore_upstream <- FALSE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
58 }
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
59
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
60 if (!is.null(args$ignore_downstream)) {
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
61 ignore_downstream <- TRUE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
62 } else {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
63 ignore_downstream <- FALSE
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
64 }
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
65
7
1b9a9409831d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit e07ee851144e07fde91877727d6a39a1906f7639
rnateam
parents: 6
diff changeset
66 if (!is.null(args$header)) {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
67 header <- TRUE
7
1b9a9409831d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit e07ee851144e07fde91877727d6a39a1906f7639
rnateam
parents: 6
diff changeset
68 } else {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
69 header <- FALSE
7
1b9a9409831d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit e07ee851144e07fde91877727d6a39a1906f7639
rnateam
parents: 6
diff changeset
70 }
1b9a9409831d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit e07ee851144e07fde91877727d6a39a1906f7639
rnateam
parents: 6
diff changeset
71
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
72 peaks <- readPeakFile(peaks, header = header)
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
73
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
74 # Make TxDb from GTF
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
75 txdb <- makeTxDbFromGFF(gtf, format = "gtf")
6
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
76
b418a1d3585d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit d83142dbe2432fcb0f56dcd6311a05c061628ecc
rnateam
parents: 4
diff changeset
77 # Annotate peaks
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
78 peak_anno <- annotatePeak(
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
79 peaks,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
80 TxDb = txdb,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
81 tssRegion = c(-up, down),
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
82 addFlankGeneInfo = flankgeneinfo,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
83 flankDistance = args$flankgenedist,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
84 ignoreUpstream = ignore_upstream,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
85 ignoreDownstream = ignore_downstream
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
86 )
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
87
3
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
88 # Add gene name
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
89 features <- import(gtf, format = "gtf")
3
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
90 ann <- unique(mcols(features)[, c("gene_id", "gene_name")])
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
91 res <- as.data.frame(peak_anno)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
92 res <- merge(res, ann, by.x = "geneId", by.y = "gene_id")
3
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
93 names(res)[names(res) == "gene_name"] <- "geneName"
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
94
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
95 #Extract metadata cols, 1st is geneId, rest should be from col 7 to end
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
96 metacols <- res[, c(7:ncol(res), 1)]
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
97 # Convert from 1-based to 0-based format
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
98 if (format == "interval") {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
99 metacols <-
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
100 apply(as.data.frame(metacols), 1, function(col)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
101 paste(col, collapse = "|"))
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
102 resout <- data.frame(res$seqnames,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
103 res$start - 1,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
104 res$end,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
105 metacols)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
106 colnames(resout)[1:4] <- c("Chrom", "Start", "End", "Comment")
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
107 } else {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
108 resout <- data.frame(res$seqnames,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
109 res$start - 1,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
110 res$end,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
111 metacols)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
112 colnames(resout)[1:3] <- c("Chrom", "Start", "End")
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
113 }
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
114 write.table(
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
115 resout,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
116 file = "out.tab",
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
117 sep = "\t",
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
118 row.names = FALSE,
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
119 quote = FALSE
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
120 )
1
95f779f4adb7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 3419a5a5e19a93369c8c20a39babe5636a309292
rnateam
parents:
diff changeset
121
3
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
122 if (!is.null(args$plots)) {
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
123 pdf("out.pdf", width = 14)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
124 plotAnnoPie(peak_anno)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
125 p1 <- plotAnnoBar(peak_anno)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
126 print(p1)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
127 vennpie(peak_anno)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
128 upsetplot(peak_anno)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
129 p2 <-
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
130 plotDistToTSS(peak_anno, title = "Distribution of transcription factor-binding loci\nrelative to TSS")
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
131 print(p2)
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
132 dev.off()
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
133 rm(p1, p2)
3
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
134 }
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
135
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
136 ## Output RData file
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
137
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
138 if (!is.null(args$rdata)) {
535321abf9a4 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/chipseeker commit 861db0d1f76bb320f49c2501f4e656cf88d389ce
rnateam
parents: 1
diff changeset
139 save.image(file = "ChIPseeker_analysis.RData")
8
8bd92f2404dd "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/chipseeker commit d30c91c3b4f71ec45b72976f7c2f08ea7df1e376-dirty"
rnateam
parents: 7
diff changeset
140 }