Mercurial > repos > ieguinoa > tximport
annotate tximport.R @ 0:2f5e9c0fe367 draft default tip
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
author | ieguinoa |
---|---|
date | Wed, 09 Oct 2019 15:38:21 -0400 |
parents | |
children |
rev | line source |
---|---|
0
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
1 # setup R error handling to go to stderr |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
2 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
3 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
4 # we need that to not crash galaxy with an UTF8 error on German LC settings. |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
5 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
6 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
7 library("getopt") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
8 #library("tools") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
9 options(stringAsFactors = FALSE, useFancyQuotes = FALSE) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
10 args <- commandArgs(trailingOnly = TRUE) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
11 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
12 # get options, using the spec as defined by the enclosed list. |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
13 # we read the options from the default: commandArgs(TRUE). |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
14 spec <- matrix(c( |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
15 "help", "h", 0, "logical", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
16 "base_dir", "w", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
17 "out_file", "o", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
18 "countsFiles", "n", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
19 "countsFromAbundance", "r", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
20 "format", "v", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
21 "gff_file", "H", 0, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
22 "tx2gene", "f", 0, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
23 "geneIdCol", "l", 0, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
24 "txIdCol" , "p", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
25 "abundanceCol", "i", 0, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
26 "countsCol", "y", 1, "character", |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
27 "lengthCol", "x", 1, "character"), |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
28 byrow=TRUE, ncol=4) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
29 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
30 opt <- getopt(spec) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
31 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
32 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
33 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
34 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
35 # if help was asked for print a friendly message |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
36 # and exit with a non-zero error code |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
37 if (!is.null(opt$help)) { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
38 cat(getopt(spec, usage=TRUE)) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
39 q(status=1) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
40 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
41 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
42 if (is.null(opt$gff_file) & is.null(opt$tx2gene)) { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
43 cat("A GFF/GTF file or a tx2gene table is required\n") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
44 q(status=1) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
45 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
46 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
47 if (opt$format == 'none'){ #custom format |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
48 if (is.null(opt$txIdCol) | is.null(opt$abundanceCol) | is.null(opt$countsCol) | is.null(opt$lengthCol)) { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
49 cat("If you select a custom format for the input files you need to specify the column names\n") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
50 q(status=1) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
51 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
52 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
53 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
54 if (is.null(opt$countsFiles)) { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
55 cat("'countsFiles' is required\n") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
56 q(status=1) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
57 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
58 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
59 ## parse counts files |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
60 library(rjson) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
61 dat <- fromJSON(opt$countsFiles) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
62 samples_df <- lapply(dat, function(samples) # Loop through each "sample" |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
63 { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
64 # Convert each group to a data frame. |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
65 # This assumes you have 6 elements each time |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
66 data.frame(matrix(unlist(samples), ncol=2, byrow=T)) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
67 }) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
68 samples_df <- do.call(rbind, samples_df) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
69 colnames(samples_df) <- c("path","id") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
70 rownames(samples_df) <- NULL |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
71 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
72 # Prepare char vector with files and sample names |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
73 files <- file.path(samples_df[,"path"]) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
74 names(files) <- samples_df[,"id"] |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
75 #files |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
76 #all(file.exists(files)) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
77 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
78 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
79 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
80 library(tximport) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
81 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
82 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
83 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
84 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
85 ### if the input is a gff/gtf file first need to create the tx2gene table |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
86 if (!is.null(opt$gff_file)) { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
87 suppressPackageStartupMessages({ |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
88 library("GenomicFeatures") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
89 }) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
90 txdb <- makeTxDbFromGFF(opt$gff_file) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
91 k <- keys(txdb, keytype = "TXNAME") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
92 tx2gene <- select(txdb, keys=k, columns="GENEID", keytype="TXNAME") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
93 # Remove 'transcript:' from transcript IDs (when gffFile is a GFF3 from Ensembl and the transcript does not have a Name) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
94 tx2gene$TXNAME <- sub('^transcript:', '', tx2gene$TXNAME) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
95 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
96 } else { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
97 tx2gene <- read.table(opt$tx2gene,header=FALSE) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
98 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
99 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
100 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
101 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
102 ## |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
103 if (is.null(opt$geneIdCol)) { ## there is a tx2gene table |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
104 if (opt$format == 'none'){ #predefined format |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
105 cat("here i am too\n") |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
106 txi_out <- tximport(files, type="none",txIdCol=opt$txIdCol,abundanceCol=opt$abundanceCol,countsCol=opt$countsCol,lengthCol=opt$lengthCol,tx2gene=tx2gene,countsFromAbundance=opt$countsFromAbundance) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
107 } else { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
108 txi_out <- tximport(files, type=opt$format, tx2gene=tx2gene,countsFromAbundance=opt$countsFromAbundance) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
109 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
110 } else { # the gene_ID is a column in the counts table |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
111 if (opt$format == 'none'){ #predefined format |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
112 txi_out <- tximport(files, type="none",geneIdCol=opt$geneIdCol,txIdCol=opt$txIdCol,abundanceCol=opt$abundanceCol,countsCol=opt$countsCol,lengthCol=opt$lengthCol,tx2gene=tx2gene,countsFromAbundance=opt$countsFromAbundance) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
113 } else { |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
114 txi_out <- tximport(files, type=opt$format, geneIdCol=opt$geneIdCol,countsFromAbundance=opt$countsFromAbundance) |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
115 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
116 |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
117 } |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
118 # write count as table |
2f5e9c0fe367
"planemo upload for repository https://github.com/ieguinoa/tximport-galaxy-wrapper commit 2bb25471c1320fb1206afa2c4daf536b6d6e275f-dirty"
ieguinoa
parents:
diff
changeset
|
119 write.table(txi_out$counts, file=opt$out_file, row.names = TRUE, col.names = TRUE, quote = FALSE, sep = "\t") |