Mercurial > repos > iuc > brew3r_r
annotate brew3r.r_script.R @ 2:448beaf9deb8 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
| author | iuc |
|---|---|
| date | Thu, 03 Oct 2024 22:35:41 +0000 |
| parents | 9083012a0abf |
| children |
| rev | line source |
|---|---|
|
0
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
1 library("getopt") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
2 suppressPackageStartupMessages(library("rtracklayer")) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
3 library(GenomicRanges) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
4 library("BREW3R.r") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
5 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
6 options(stringAsFactors = FALSE, useFancyQuotes = FALSE) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
7 args <- commandArgs(trailingOnly = TRUE) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
8 # - Column 1: the long flag name. A multi-character string. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
9 # - Column 2: short flag alias of Column 1. A single-character string. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
10 # - Column 3: Argument mask of the flag. An integer. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
11 # Possible values: 0=no argument, 1=required argument, 2=optional argument. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
12 # - Column 4: Data type to which the flag's argument shall be cast using |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
13 # storage.mode(). A multi-character string. This only considered for same-row |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
14 # Column 3 values of 1,2. Possible values: logical, integer, double, complex, |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
15 # character. If numeric is encountered then it will be converted to double. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
16 # - Column 5 (optional): A brief description of the purpose of the option. |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
17 spec <- matrix(c( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
18 "help", "h", 0, "logical", "display help", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
19 "gtf_to_extend", "i", 1, "character", "input gtf file to be extended on 3'", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
20 "gtf_to_overlap", "g", 1, "character", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
21 "input gtf file that will be used to extend", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
22 "output", "o", 1, "character", "output extended gtf", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
23 "sup_output", "s", 1, "character", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
24 "supplementary output file with resolution of overlaps", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
25 "no_add", "n", 0, "logical", "do not add new exons", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
26 "exclude_pattern", "e", 1, "character", "do not extend genes with names matching this pattern", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
27 "filter_unstranded", "f", 0, "logical", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
28 "remove unstranded intervals from gtf_to_overlap which overlap intervals from gtf_to_extend of both strands", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
29 "quiet", "q", 0, "logical", "decrease verbosity", |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
30 "verbose", "v", 0, "logical", "increase verbosity" |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
31 ), byrow = TRUE, ncol = 5) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
32 opt <- getopt(spec) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
33 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
34 # if help was asked for print a friendly message |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
35 # and exit with a non-zero error code |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
36 if (!is.null(opt$help)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
37 cat(getopt(spec, usage = TRUE)) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
38 q(status = 1) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
39 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
40 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
41 # Check all required arguments |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
42 if (is.null(opt$gtf_to_extend)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
43 stop("--gtf_to_extend is required") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
44 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
45 if (is.null(opt$gtf_to_overlap)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
46 stop("--gtf_to_overlap is required") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
47 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
48 if (is.null(opt$output)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
49 stop("--output is required") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
50 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
51 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
52 # Check incompatible arguments |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
53 if (!is.null(opt$quiet) && !is.null(opt$verbose)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
54 stop("quiet and verbose are mutually exclusive options") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
55 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
56 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
57 # Adjust verbosity |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
58 if (!is.null(opt$quiet)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
59 options(rlib_message_verbosity = "quiet") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
60 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
61 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
62 if (!is.null(opt$verbose)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
63 options(BREW3R.r.verbose = "progression") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
64 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
65 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
66 # Load gtfs as GenomicRanges |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
67 input_gr_to_extend <- rtracklayer::import(opt$gtf_to_extend, format = "gtf") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
68 input_gr_template <- rtracklayer::import(opt$gtf_to_overlap, format = "gtf") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
69 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
70 # Save CDS info |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
71 input_gr_CDS <- subset(input_gr_to_extend, type == "CDS") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
72 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
73 # Filter the template if needed |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
74 if (!is.null(opt$filter_unstranded)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
75 # Find intervals without strand information in template |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
76 unstranded.intervals <- which(strand(input_gr_template) == "*") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
77 if (length(unstranded.intervals) > 0) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
78 # Check if they overlap genes from input with different strands |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
79 # First compute the overlap |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
80 ov <- suppressWarnings( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
81 as.data.frame(findOverlaps( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
82 input_gr_template[unstranded.intervals], |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
83 input_gr_to_extend |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
84 )) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
85 ) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
86 # Add the strand information |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
87 ov$strand <- as.factor(strand(input_gr_to_extend))[ov$subjectHits] |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
88 # Simplify the dataframe to get only the strand info |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
89 ov.simple <- unique(ov[, c("queryHits", "strand")]) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
90 # If the queryHits is duplicated it means there are different strands |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
91 multi.strand.query <- ov.simple$queryHits[duplicated(ov.simple$queryHits)] |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
92 to.remove <- unstranded.intervals[multi.strand.query] |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
93 # Remove these potentially error-prone intervals from the template |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
94 if (length(to.remove) > 0) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
95 input_gr_template <- input_gr_template[-to.remove] |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
96 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
97 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
98 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
99 |
|
2
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
100 if (is.null(input_gr_to_extend$exon_id)) { |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
101 is.exon <- which(input_gr_to_extend$type == "exon") |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
102 input_gr_to_extend$exon_id <- NA |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
103 input_gr_to_extend$exon_id[is.exon] <- paste0( |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
104 "EXON", |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
105 sprintf( |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
106 "%010d", |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
107 1:length(is.exon) |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
108 ) |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
109 ) |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
110 } |
|
448beaf9deb8
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit d287d5688e57f4154d5875789e0cd4d5c87f11ce
iuc
parents:
0
diff
changeset
|
111 |
|
0
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
112 # Run BREW3R.r main function |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
113 if (length(input_gr_template) > 0) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
114 new_gr_exons <- extend_granges( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
115 input_gr_to_extend = input_gr_to_extend, |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
116 input_gr_to_overlap = input_gr_template, |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
117 add_new_exons = is.null(opt$no_add), |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
118 overlap_resolution_fn = opt$sup_output |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
119 ) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
120 } else { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
121 new_gr_exons <- subset(input_gr_to_extend, type == "exon") |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
122 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
123 # Prevent extension using pattern |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
124 if (!is.null(opt$exclude_pattern)) { |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
125 input_gr_pattern <- subset( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
126 input_gr_to_extend, |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
127 type == "exon" & grepl(opt$exclude_pattern, gene_name) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
128 ) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
129 new_gr_no_pattern <- subset( |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
130 new_gr_exons, |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
131 !grepl(opt$exclude_pattern, gene_name) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
132 ) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
133 new_gr_exons <- c(new_gr_no_pattern, input_gr_pattern) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
134 } |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
135 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
136 # Recompose with CDS |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
137 new_gr <- c(new_gr_exons, input_gr_CDS) |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
138 |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
139 # Export |
|
9083012a0abf
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/brew3r_r commit fa525468780f3dea175da15852b1b8c17e1a80d3
iuc
parents:
diff
changeset
|
140 rtracklayer::export.gff(sort(new_gr, ignore.strand = TRUE), opt$output) |
