comparison sleuth.R @ 3:172091d47f5a draft default tip

planemo upload for repository https://github.com/youyuh48/galaxy-sleuth/tree/master/ commit 8d9ff6181e933951e015e67f1719588bab2b3ab5-dirty
author youyuh48
date Tue, 12 Jun 2018 17:58:47 -0400
parents
children
comparison
equal deleted inserted replaced
2:a049d0d5a05e 3:172091d47f5a
1 #!/usr/bin/env Rscript
2
3 # A command-line interface to sleuth for use with Galaxy This script modified
4 # from https://github.com/pachterlab/bears_analyses/blob/master/sleuth.R
5 # https://github.com/nturaga/bioc-galaxy-integration/blob/master/README.md
6
7 ## Command to run tool:
8 ## Rscript sleuth.R --indir test-rscript --metadata test-rscript/metadata.txt
9 ## --full_model '~condition' --reduced_model '~1'
10 ## --gene_anno_name 'hsapiens_gene_ensembl'
11
12 # setup R error handling to go to stderr
13 options(show.error.messages = F, error = function() {
14 cat(geterrmessage(), file = stderr())
15 q("no", 1, F)
16 })
17
18 # we need that to not crash galaxy with an UTF8 error on German LC settings.
19 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
20
21 library("getopt")
22 library("tools")
23 options(stringAsFactors = FALSE, useFancyQuotes = FALSE)
24 args <- commandArgs(trailingOnly = TRUE)
25
26 # get options, using the spec as defined by the enclosed list.
27 spec <- matrix(c(
28 "quiet", "q", 0, "logical",
29 "help", "h", 0, "logical",
30 "indir", "i", 1, "character",
31 "metadata", "m", 1, "character",
32 "full_model", "f", 1, "character",
33 "reduced_model", "r", 1, "character",
34 "gene_anno_name", "a", 2, "character"),
35 byrow = TRUE, ncol = 4)
36 opt <- getopt(spec)
37
38 # if help was asked for print a friendly message and exit with a non-zero error
39 # code
40 if (!is.null(opt$help)) {
41 cat(getopt(spec, usage = TRUE))
42 q(status = 1)
43 }
44
45 # enforce the following required arguments
46 if (is.null(opt$indir)) {
47 cat("'indir' is required\n")
48 q(status = 1)
49 }
50 if (is.null(opt$metadata)) {
51 cat("'metadata' is required\n")
52 q(status = 1)
53 }
54 if (is.null(opt$full_model)) {
55 cat("'full_model' is required\n")
56 q(status = 1)
57 }
58 if (is.null(opt$reduced_model)) {
59 cat("'reduced_model' is required\n")
60 q(status = 1)
61 }
62
63 verbose <- if (is.null(opt$quiet)) {
64 TRUE
65 } else {
66 FALSE
67 }
68
69 suppressPackageStartupMessages({
70 library("sleuth")
71 library("biomaRt")
72 })
73
74 s2c <- read.table(file.path(opt$metadata), header = TRUE, stringsAsFactors = FALSE)
75 run_dirs <- s2c$sample
76 kal_dirs <- c()
77
78 for (dir in run_dirs) {
79 kal_dirs <- c(kal_dirs, file.path(opt$indir, dir, "kallisto"))
80 }
81
82 s2c <- dplyr::mutate(s2c, path = kal_dirs)
83
84 if (!is.null(opt$gene_anno_name)) {
85 mart <- biomaRt::useMart(biomart = "ensembl", dataset = opt$gene_anno_name)
86 t2g <- biomaRt::getBM(attributes = c("ensembl_transcript_id", "ensembl_gene_id",
87 "external_gene_name"), mart = mart)
88 t2g <- dplyr::rename(t2g, target_id = ensembl_transcript_id, ens_gene = ensembl_gene_id,
89 ext_gene = external_gene_name)
90 so <- sleuth_prep(s2c, as.formula(opt$full_model), target_mapping = t2g, read_bootstrap_tpm = TRUE,
91 extra_bootstrap_summary = TRUE)
92 } else {
93 so <- sleuth_prep(s2c, as.formula(opt$full_model), read_bootstrap_tpm = TRUE,
94 extra_bootstrap_summary = TRUE)
95 }
96 so <- sleuth_fit(so, as.formula(opt$full_model), "full")
97 so <- sleuth_fit(so, as.formula(opt$reduced_model), "reduced")
98 so <- sleuth_lrt(so, "reduced", "full")
99 sleuth_deploy(so, opt$indir)
100
101 cat("Successfully finished script.\n")