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