annotate KDEanalysis.r @ 0:1535ffddeff4 draft

planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
author cristian
date Thu, 07 Sep 2017 08:51:57 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
1 # Carry out analysis of CpGo/E data for Galaxy module
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
2 # Ingo Bulla
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
3 # 27 Jan 16
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
4
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
5 # load packages
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
6 pckg <- c("methods", "optparse")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
7 for (p in pckg) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
8 if (!(p %in% rownames(installed.packages()))) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
9 stop( paste("R package", p , "is not installed"), call. = FALSE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
10 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
11 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
12 require(methods, quietly = TRUE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
13 require(optparse, quietly = TRUE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
14
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
15 # determine directory where functions are located
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
16 cmdArgs <- commandArgs(trailingOnly = FALSE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
17 str <- "--file="
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
18 match <- grep(str, cmdArgs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
19 if (length(match) == 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
20 stop("notos.r not set up to be called from R console")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
21 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
22 path <- normalizePath( sub(str, "", cmdArgs[match]) )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
23 FCTN.DIR <- file.path(dirname(path), "Functions")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
24
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
25 source( file.path( FCTN.DIR, "Kernel_function_form.R") )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
26
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
27
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
28 MAX.CPGOE <- 10 # maximum value for CpGo/e ratios
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
29
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
30
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
31 # process outliers and return quantities characterizing the distribution
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
32 # obs: CpGo/e ratios
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
33 proc.outliers <- function(obs, frac.outl) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
34 ret <- list()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
35
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
36 # remove all zeros from sample
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
37 no.obs.raw <- length(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
38 ret[["prop.zero"]] <- sum(obs == 0) / no.obs.raw
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
39 obs <- obs[obs != 0]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
40 if (length(obs) < 3) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
41 ret[["valid"]] <- FALSE
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
42 return(ret)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
43 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
44 ret[["obs.nz"]] <- obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
45
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
46 # replace very large values by a maximum value
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
47 obs <- sapply(obs, function(x) min(x, MAX.CPGOE))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
48
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
49 # defining variables
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
50 # ... mean, median and standard deviation
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
51 ret[["mu.obs"]] <- mu.obs <- mean(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
52 ret[["me.obs"]] <- me.obs <- median(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
53 sd.obs <- sd(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
54 iqr.obs <- IQR(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
55
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
56 # ... uppper and lower limits, based on mean +- k * sd, med. +- k * iqr, k = 2, ..., 4
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
57 ul.mu <- mu.obs + (2 : 5) * sd.obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
58 ll.mu <- mu.obs - (2 : 5) * sd.obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
59 ul.me <- quantile(obs, 0.75) + (2 : 5) * iqr.obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
60 ll.me <- quantile(obs, 0.25) - (2 : 5) * iqr.obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
61 names(ul.mu) <- names(ll.mu) <- 2 : 5
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
62 names(ul.me) <- names(ll.me) <- 2 : 5
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
63 ret[["ul.mu"]] <- ul.mu
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
64 ret[["ll.mu"]] <- ll.mu
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
65 ret[["ul.me"]] <- ul.me
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
66 ret[["ll.me"]] <- ll.me
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
67
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
68 # summary statistics and data output
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
69 # ... calculate proportion of data excluded when using different ranges
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
70 ret[["prop2"]] <- prop2 <- length(obs[obs < ll.me["2"] | ul.me["2"] < obs]) / no.obs.raw
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
71 ret[["prop3"]] <- prop3 <- length(obs[obs < ll.me["3"] | ul.me["3"] < obs]) / no.obs.raw
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
72 ret[["prop4"]] <- prop4 <- length(obs[obs < ll.me["4"] | ul.me["4"] < obs]) / no.obs.raw
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
73 ret[["prop5"]] <- prop5 <- length(obs[obs < ll.me["5"] | ul.me["5"] < obs]) / no.obs.raw
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
74 # ... choose k in Q1 / Q3 +- k * IQR such that no more than 1% of the data are excluded
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
75 v <- c(prop2, prop3, prop4, prop5) < frac.outl
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
76
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
77 if (any(v)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
78 excl.crit <- min(which(v))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
79 ret[["obs.cl"]] <- obs[!(obs < ll.me[excl.crit] | ul.me[excl.crit] < obs)]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
80 ret[["used"]] <- paste(2 : 5, "iqr", sep = "")[excl.crit]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
81 } else {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
82 ret[["obs.cl"]] <- obs[!(obs < ll.me[4] | ul.me[4] < obs)]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
83 ret[["used"]] <- "limited to 5 * iqr"
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
84 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
85 ret[["valid"]] <- TRUE
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
86 return(ret)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
87 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
88
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
89
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
90 # Read CpGo/e ratios from file
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
91 # warn: issue warning if necessary
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
92 read.CpGoe <- function(fname, warn) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
93 # read input file line by line, split by whitespaces, assign last substring to CpGo/e ratios
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
94 # ... remove comments and trailing whitespaces
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
95 print(fname)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
96 v <- read.table(fname, fill = TRUE, col.names = c("seq", "val"))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
97 obs <- v$val
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
98
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
99 obs <- obs[!is.na(obs)]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
100 return(obs)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
101 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
102
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
103
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
104 # process command line arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
105 # expected arguments:
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
106 # - names of the species (each as a separate argument)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
107 # - names of CpGo/e files of the species (each as a separate argument)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
108 # ... parse arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
109 option_list <- list(make_option(c("-o", "--frac-outl"), type = "double", default = 0.01,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
110 help = "maximum fraction of CpGo/e ratios excluded as outliers [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
111 make_option(c("-d", "--min-dist"), type = "double", default = 0.2,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
112 help = "minimum distance between modes, modes that are closer are joined [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
113 make_option(c("-c", "--conf-level"), type = "double", default = 0.95,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
114 help = "level of the confidence intervals of the mode positions [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
115 make_option(c("-m", "--mode-mass"), type = "double", default = 0.05,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
116 help = "minimum probability mass of a mode [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
117 make_option(c("-b", "--band-width"), type = "double", default = 1.06,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
118 help = "bandwidth constant for kernels [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
119 make_option(c("-B", "--bootstrap"), action="store_true", default = FALSE,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
120 help = "calculate confidence intervals of mode positions using bootstrap [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
121 make_option(c("-r", "--bootstrap-reps"), type = "integer", default = 1500,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
122 help = "number of bootstrap repetitions [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
123 make_option(c("-H", "--outlier-hist-file"), type = "character", default = "outliers_hist.pdf",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
124 help = "name of the output file for the outlier histograms [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
125 make_option(c("-C", "--cutoff-file"), type = "character", default = "outliers_cutoff.csv",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
126 help = "name of the output file for the outlier cutoff [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
127 make_option(c("-k", "--kde-file"), type = "character", default = "KDE.pdf",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
128 help = "name of the output file for the KDE [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
129 make_option(c("-v", "--valley-file"), type = "character", default = "valleys.csv",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
130 help = "name of the output file with the values for valleys of the KDE [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
131 make_option(c("-p", "--peak-file"), type = "character", default = "modes_basic_stats.csv",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
132 help = "name of the output file describing the peaks of the KDE [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
133 make_option(c("-s", "--bootstrap-file"), type = "character", default = "modes_bootstrap.csv",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
134 help = "name of the output file for the bootstrap results [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
135 make_option(c("-u", "--summary-file"), type = "character", default = "summary.csv",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
136 help = "name of the summary file for the KDE results [default %default]"),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
137 make_option(c("-f", "--no-warning-few-seqs"), action = "store_true", default = FALSE,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
138 help = paste("suppress warning in case the input file only contains few values ",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
139 "[default %default]", sep = "")))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
140
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
141 op <- OptionParser(usage = "notos.r [options] spc_name_1 ... spc_name_N CpGoe_file_name_1 ... CpGoe_file_name_N",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
142 description = paste("\nDescription: Notos generates a histogram and a kernel density estimator from files containing CpGo/e ratios. ",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
143 "Moreover, it determines the number of modes of the CpGo/e ratio for each input file. The input files ",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
144 "can either be composed of \n",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
145 "1) CpGo/e ratios separated by linebreaks or\n",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
146 "2) sequence names and CpGo/e ratios with each sequence name put on a separate line together with its CpGo/e ratio ",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
147 "and sequence and CpGo/e being separated by whitespaces on each line.", sep = ""),
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
148 option_list = option_list)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
149 args <- parse_args(op, positional_arguments = c(2, Inf))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
150 num.args <- length(args$args)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
151 use.bstrp <- args$options$`bootstrap`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
152 supp.warn.few <- args$options$`no-warning-few-seqs`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
153
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
154
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
155 # ... check number of arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
156 # ... ... check number of mandatory arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
157 if (num.args < 2) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
158 stop("One species name and one file containing CpGo/e ratios have to be provided")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
159 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
160
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
161 # ... ... check whether number of mandatory arguments is even
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
162 if (num.args %% 2 != 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
163 stop("Number of arguments has to be even")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
164 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
165
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
166 # ... ... check maximum fraction of CpGo/e ratios excluded as outliers
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
167 frac.outl <- args$options$`frac-outl`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
168 if ((frac.outl <= 0) || (frac.outl >= 1)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
169 stop("The maximum fraction of CpGo/e ratios excluded as outliers has to be greater than zero and less than one")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
170 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
171 if (frac.outl >= 0.2) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
172 warning("The maximum fraction of CpGo/e ratios excluded as outliers has been set to a rather large value, resulting in the removal of many CpGo/e ratios")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
173 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
174
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
175
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
176 # ... check numerical arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
177 # ... ... check minimum distance between modes
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
178 min.dist <- args$options$`min-dist`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
179 if (min.dist < 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
180 stop("The minimum distance between modes has to be equal to or larger than zero")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
181 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
182 if (min.dist >= 0.4) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
183 warning("The minimum distance between modes has been set to a rather large value, resulting in a strong reduction of the number of modes")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
184 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
185
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
186 # ... ... check confidence level
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
187 conf.lev <- args$options$`conf-level`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
188 if ((conf.lev <= 0) || (conf.lev >= 1)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
189 stop("The level of the confidence intervals of the mode positions has to be larger than zero and smaller than one.")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
190 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
191 if (conf.lev >= 0.995) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
192 warning("The level of the confidence intervals of the mode positions has been set to a rather high value, resulting in very broad confidence intervals")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
193 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
194
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
195 # ... ... check minimum probability mass of a mode
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
196 mode.mass <- args$options$`mode-mass`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
197 if ((mode.mass < 0) || (mode.mass >= 1)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
198 stop("The minimum probability mass of a mode has to be larger than or equal to zero and smaller than one.")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
199 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
200 if (mode.mass >= 0.3) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
201 warning("The minimum probability mass of a mode has been set to a rather large value, resulting in the elemination of a high number of modes.")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
202 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
203
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
204 # ... ... check bandwidth constant
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
205 band.width <- args$options$`band-width`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
206 if (band.width <= 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
207 stop("The bandwidth constant has to be positive")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
208 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
209 if (band.width >= 5) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
210 warning("The bandwidth constant has to been set to a rather large value, resulting in a strong smoothing")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
211 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
212
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
213 # ... ... check number of boostrap repetitions
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
214 bstrp.reps <- args$options$`bootstrap-reps`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
215 if (bstrp.reps != round(bstrp.reps)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
216 stop("The number of boostrap repetitions has to be a positive integer")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
217 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
218 if (bstrp.reps <= 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
219 stop("The number of boostrap repetitions has to be positive")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
220 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
221 if (bstrp.reps >= 10000) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
222 warning("The number of boostrap repetitions has been set to a rather large value, resulting in a long running time")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
223 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
224
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
225 # ... check file name arguments
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
226 # ... ... check histogram output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
227 outlier.hist.fname <- args$options$`outlier-hist-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
228 if ( file.exists(outlier.hist.fname) && (file.info(outlier.hist.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
229 stop(paste("File name for the outlier histogram output refers to a directory:", outlier.hist.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
230 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
231 v <- strsplit(outlier.hist.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
232 if ((length(v) == 1) || (v[ length(v) ] != "pdf")) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
233 warning(paste("File name for the outlier histogram output does not have a .pdf extension:", outlier.hist.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
234 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
235 g <- gregexpr(pattern ='/', outlier.hist.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
236 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
237 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
238 d <- substr(outlier.hist.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
239 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
240 stop(paste("Path to file for the outlier histogram output is not valid:", outlier.hist.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
241 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
242 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
243
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
244 # ... ... check outlier cutoff output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
245 cutoff.fname <- args$options$`cutoff-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
246 if ( file.exists(cutoff.fname) && (file.info(cutoff.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
247 stop(paste("File name for the outlier cutoff table output refers to a directory:", cutoff.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
248 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
249 v <- strsplit(cutoff.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
250 if (length(v) == 1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
251 stop(paste("File name for the outlier cutoff table output does not have a file extension:", cutoff.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
252 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
253 #if (v[ length(v) ] != "xlsx") {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
254 # warning(paste("File name for the outlier cutoff table output does not have a .xlsx extension:", cutoff.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
255 #}
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
256 g <- gregexpr(pattern ='/', cutoff.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
257 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
258 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
259 d <- substr(cutoff.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
260 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
261 stop(paste("Path to file for the outlier cutoff is not valid:", cutoff.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
262 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
263 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
264
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
265 # ... ... check KDE output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
266 kde.fname <- args$options$`kde-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
267 if ( file.exists(kde.fname) && (file.info(kde.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
268 stop(paste("File name for the KDE output refers to a directory:", kde.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
269 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
270 v <- strsplit(kde.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
271 if ((length(v) == 1) || (v[ length(v) ] != "pdf")) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
272 warning(paste("File name for the KDE output does not have a .pdf extension:", kde.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
273 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
274 g <- gregexpr(pattern ='/', kde.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
275 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
276 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
277 d <- substr(kde.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
278 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
279 stop(paste("Path to file for the KDE output is not valid:", kde.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
280 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
281 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
282
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
283
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
284 # ... ... check peak descriptives output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
285 peak.fname <- args$options$`peak-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
286 if ( file.exists(peak.fname) && (file.info(peak.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
287 stop(paste("File name for the peak descriptives refers to a directory:", peak.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
288 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
289 v <- strsplit(peak.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
290 if ((length(v) == 1) || (v[ length(v) ] != "csv")) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
291 warning(paste("File name for the peak descriptives does not have a .csv extension:", peak.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
292 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
293 g <- gregexpr(pattern ='/', peak.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
294 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
295 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
296 d <- substr(peak.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
297 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
298 stop(paste("Path to file for the peak descriptives is not valid:", peak.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
299 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
300 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
301
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
302 # ... ... check bootstrap results output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
303 bstrp.fname <- args$options$`bootstrap-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
304 if ( file.exists(bstrp.fname) && (file.info(bstrp.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
305 stop(paste("File name for the bootstrap results refers to a directory:", bstrp.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
306 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
307 v <- strsplit(bstrp.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
308 if ((length(v) == 1) || (v[ length(v) ] != "csv")) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
309 warning(paste("File name for the bootstrap results does not have a .csv extension:", bstrp.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
310 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
311 g <- gregexpr(pattern ='/', bstrp.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
312 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
313 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
314 d <- substr(bstrp.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
315 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
316 stop(paste("Path to file for the bootstrap results is not valid:", bstrp.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
317 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
318 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
319
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
320 # ... ... check summary results output file name
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
321 summ.fname <- args$options$`summary-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
322 if ( file.exists(summ.fname) && (file.info(summ.fname)$isdir) ) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
323 stop(paste("File name for the bootstrap results refers to a directory:", summ.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
324 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
325 v <- strsplit(summ.fname, split = ".", fixed = TRUE)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
326 if ((length(v) == 1) || (v[ length(v) ] != "csv")) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
327 warning(paste("File name for the bootstrap results does not have a .csv extension:", summ.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
328 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
329 g <- gregexpr(pattern ='/', summ.fname)[[1]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
330 if (as.vector(g)[1] != -1) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
331 v <- as.vector(g)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
332 d <- substr(summ.fname, 1, v[length(v)])
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
333 if (!file.exists(d)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
334 stop(paste("Path to file for the bootstrap results is not valid:", summ.fname))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
335 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
336 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
337
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
338
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
339 # ... ... check CpGo/e input file names
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
340 num.spec <- num.args / 2
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
341 spec.names <- args$args[1:num.spec]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
342 cpgoe.fnames <- args$args[(num.spec + 1):num.args]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
343 for (i in 1:length(cpgoe.fnames)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
344 if (!file.exists(cpgoe.fnames[i])) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
345 stop(paste("CpGo/e file does not exist:", cpgoe.fnames[i]))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
346 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
347 if (file.info(cpgoe.fnames[i])$isdir) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
348 stop(paste("CpGo/e file name refers to a directory:", cpgoe.fnames[i]))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
349 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
350 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
351
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
352 valleys.fname <- args$options$`valley-file`
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
353
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
354 # remove outliers and output histograms
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
355 # ... set up table with cutoff quantities
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
356 tab.des <- data.frame(matrix(NA, nrow = num.spec, ncol = 6))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
357 names(tab.des) <- c("prop.zero", "prop.out.2iqr", "prop.out.3iqr",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
358 "prop.out.4iqr", "prop.out.5iqr", "used")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
359 rownames(tab.des) <- spec.names
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
360
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
361 # ... set up figure
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
362 t.height <- 6
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
363 t.width <- 20
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
364 pdf(outlier.hist.fname, height = t.height,width = t.width, paper = "special")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
365 par(mfrow = c(1, 3), mgp = c(2, 0.5, 0), mar = c(4.0, 3.0, 1.5, 1))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
366 tmp.fnames <- c()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
367
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
368 # ... iterate through species
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
369 for (i in 1:num.spec) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
370 fname <- cpgoe.fnames[i]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
371 obs <- read.CpGoe(fname, TRUE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
372
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
373
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
374 # check CpGo/e ratios
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
375 for (j in 1:length(obs)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
376 # is format legal?
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
377 val <- as.numeric( obs[j] )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
378 err.str <- paste("Observation", i, "in", fname)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
379 if (!is.finite(val)) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
380 stop(paste(err.str, "could not be converted to a number:", obs[j]))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
381 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
382
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
383 # is ratio too small / large?
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
384 if (val < 0) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
385 stop(paste(err.str, "is negative:", val))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
386 } else {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
387 if (val > MAX.CPGOE) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
388 warning(paste(err.str , "is suspiciously large:", val, "\nthis value is replaced by", MAX.CPGOE))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
389 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
390 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
391 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
392
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
393 # process outliers and store the results
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
394 obs.org <- obs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
395 l <- proc.outliers(obs, frac.outl)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
396 if (!l[["valid"]]) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
397 stop( paste("Too few values in", fname, "(less than 3) after removal of zeros"), call. = FALSE )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
398 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
399 tab.des[i, "prop.zero"] <- l[["prop.zero"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
400 mu.obs <- l[["mu.obs"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
401 me.obs <- l[["me.obs"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
402 ul.mu <- l[["ul.mu"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
403 ll.mu <- l[["ll.mu"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
404 ul.me <- l[["ul.me"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
405 ll.me <- l[["ll.me"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
406 tab.des[i, "prop.out.2iqr"] <- l[["prop2"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
407 tab.des[i, "prop.out.3iqr"] <- l[["prop3"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
408 tab.des[i, "prop.out.4iqr"] <- l[["prop4"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
409 tab.des[i, "prop.out.5iqr"] <- l[["prop5"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
410 obs.cl <- l[["obs.cl"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
411 obs.nz <- l[["obs.nz"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
412 tab.des[i, "used"] <- l[["used"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
413 tab.des[i, "no.obs.raw"] <- length(obs.org)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
414 tab.des[i, "no.obs.nozero"] <- length(obs.nz)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
415 tab.des[i, "no.obs.clean"] <- length(obs.cl)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
416 usedindex <- substr(l[["used"]],1,1)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
417 # Histograms
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
418 # ... histogram 1: original data with zeros
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
419 t.breaks <- seq(0, max(obs.org) + 1, by = 0.03)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
420 t.xlim <- c(0, ul.me["5"] + 0.1)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
421 hist(obs.org, breaks = t.breaks, xlim = t.xlim, xlab = "CpG o/e", main = "",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
422 sub = "Original data", prob = TRUE,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
423 col = grey(0.9), border = grey(0.6))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
424 mtext(paste(spec.names[i]), side = 3, adj = 0)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
425
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
426
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
427 # ... histogram 3: median / iqr based
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
428 t.lty <- rep(3, 4)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
429 t.lty[usedindex] <- 1
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
430
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
431 hist(obs.nz, breaks = t.breaks, xlim = t.xlim, xlab = "CpG o/e", main = "",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
432 sub = "Data without zeros, Q1/3 +- k*IQR, k=2,...,5", prob = TRUE,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
433 col = grey(0.9), border = grey(0.6))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
434 abline(v = me.obs, col = 'blue', lwd = 2)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
435 abline(v = c(ll.me, ul.me), col = "red", lty = rep(t.lty, 2))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
436
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
437 # ... histogram 4: cleaned data
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
438 hist(obs.cl, breaks = t.breaks, xlim = t.xlim, xlab = "CpG o/e", main = "",
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
439 sub = "Cleaned data", prob = TRUE,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
440 col = grey(0.9), border = grey(0.6))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
441 abline(v = me.obs, col = 'blue', lwd = 2)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
442 abline(v = c(ll.me[usedindex], ul.me[usedindex]), col = "red")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
443 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
444 invisible(dev.off())
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
445
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
446 # output cutoff quantities
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
447 write.table(tab.des, file = cutoff.fname, sep = "\t", col.names=NA)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
448
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
449 # plot KDE and output quantities characterizing the peaks and the bootstrap results
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
450 # ... table with quantities characterizing the peaks
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
451 v <- col.names.peaks()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
452 tab1.m <- data.frame(matrix(NA, nrow = num.spec, ncol = length(v)))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
453 names(tab1.m) <- col.names.peaks()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
454 rownames(tab1.m) <- spec.names
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
455
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
456 # ... table for the bootstrap
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
457 tab2.m <- data.frame(matrix(NA, nrow = num.spec, ncol = 7))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
458 names(tab2.m) <- col.names.bs()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
459 rownames(tab2.m) <- spec.names
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
460
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
461 # summary table
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
462 sum1.m <- data.frame(matrix(NA, nrow = num.spec, ncol = 13))
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
463 names(sum1.m) <- c("Modes", "Skewness", "Variance", "Modes too close", "Peak1", "Peak2", "Peak3", "Peak4", "Peak5", "Peak6", "Peak7", "Peak8", "Peak9")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
464 rownames(sum1.m) <- spec.names
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
465
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
466 # ... plotting
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
467 t.height <- 6
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
468 t.width <- 20
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
469 pdf(kde.fname, height = t.height,width = t.width, paper = "special")
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
470 for (i in 1:num.spec) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
471 # read in GcGo/e ratios
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
472 obs <- read.CpGoe(cpgoe.fnames[i], FALSE)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
473 l <- proc.outliers(obs, frac.outl)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
474 obs.cl <- l[["obs.cl"]]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
475
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
476 # check number of values
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
477 fname <- cpgoe.fnames[i]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
478 if (length(obs.cl) < 3) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
479 stop( paste("Too few values in", fname, "(less than 3) after removal of outliers and zeros"), call. = FALSE )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
480 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
481 if (!supp.warn.few & length(obs.cl) < 250) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
482 warning( paste(fname, " contains only few values (", length(obs.cl), ") after removal of outliers and zeros, which may lead to unreliable results", sep = ""), call. = FALSE )
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
483 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
484
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
485 # plotting
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
486 l <- plot.KDE(obs.cl, t.name = spec.names[i], bs.cis = use.bstrp, bstrp.reps = bstrp.reps, conf.lev = conf.lev,
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
487 min.dist = min.dist, mode.mass = mode.mass, band.width = band.width)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
488 tab1.m[i, ] <- l$tab.des
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
489 sum1.m[i, ] <- l$tab.des[c(1, 4, 33, 30, 10+(2*0:8))]
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
490 if (use.bstrp) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
491 tab2.m[i, ] <- l$tab.bs
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
492 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
493 valleys = l$valleys
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
494 }
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
495 invisible(dev.off())
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
496 #sessionInfo()
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
497
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
498 # ... output quantities in tables
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
499 write.table(sum1.m, file = summ.fname, sep = "\t", col.names = NA)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
500 write.table(tab1.m, file = peak.fname, sep = "\t", col.names=NA)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
501 write.table(valleys, file = valleys.fname, sep = "\t", col.names=NA)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
502 if (use.bstrp) {
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
503 write.table(tab2.m, file = bstrp.fname, sep = "\t", col.names=NA)
1535ffddeff4 planemo upload commit a7ac27de550a07fd6a3e3ea3fb0de65f3a10a0e6-dirty
cristian
parents:
diff changeset
504 }