annotate plot_rna.R @ 24:431aebd93843 draft default tip

Fixed a bug in k2n.R where the function k2n_calc() would result in an error for single-end read files.
author nikos
date Wed, 05 Aug 2015 09:21:02 -0400
parents 33e625bef2b9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
1 #Setup R error handling to go to stderr
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
2 options( show.error.messages = FALSE, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
3
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
4 # we need that to not crash galaxy with an UTF8 error on German LC settings.
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
5 Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
6
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
7 suppressMessages(library('getopt'))
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
8
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
9 #get options, using the spec as defined by the enclosed list.
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
10 #we read the options from the default: commandArgs(TRUE).
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
11 spec = matrix(c(
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
12 'help' , 'h', 0, "logical",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
13 'input', 'i', 1, "character",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
14 'transcript', 't', 1, "character",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
15 'method', 'm', 2, "character",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
16 'cutoff', 'c', 2, "double",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
17 'type', 'p', 2, "character",
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
18 'output', 'o', 1, "character"
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
19 ), byrow=TRUE, ncol=4);
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
20
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
21 opt = getopt(spec);
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
22
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
23 suppressMessages(require(RNAprobR))
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
24
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
25 #Read and convert input to GRanges object
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
26 data <- read.table(opt$input, header = TRUE)
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
27 dataGR <- norm_df2GR(data)
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
28
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
29 #Check if given transcript exists in input file
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
30 if ( ! opt$transcript %in% data$RNAid ) { stop("Transript not found. Check input file.") }
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
31
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
32 pdf(opt$output)
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
33 for (method in strsplit(opt$method, ",")[[1]] ) {
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
34
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
35 #Check if columns exists in data file
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
36 if (! method %in% colnames(data)) { next }
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
37
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
38 plotRNA(dataGR, opt$transcript, method, stat_cutoff = opt$cutoff, type = opt$type,
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
39 main=paste(opt$transcript,": ", method, sep=""))
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
40 }
33e625bef2b9 Uploaded
nikos
parents:
diff changeset
41 dev.off()