-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstep10-region_cuts.R
57 lines (45 loc) · 1.47 KB
/
step10-region_cuts.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library('derfinder')
library('getopt')
library('devtools')
library('GenomicRanges')
## Specify parameters
spec <- matrix(c(
'maindir', 'm', 1, 'character', 'Main directory',
'chr', 'c', 1, 'character', 'Chromosome under analysis',
'help' , 'h', 0, 'logical', 'Display help'
), byrow=TRUE, ncol=5)
opt <- getopt(spec)
## if help was asked for print a friendly message
## and exit with a non-zero error code
if (!is.null(opt$help)) {
cat(getopt(spec, usage=TRUE))
q(status=1)
}
## Input options used
maindir <- opt$maindir
chr <- opt$chr
## Load data
message(paste(Sys.time(), 'loading', paste0(chr, 'covInfo.Rdata')))
load(file.path(maindir, 'CoverageInfo', paste0(chr, 'CovInfo.Rdata')))
chrCov <- get(paste0(chr, 'CovInfo'))
## Calculate mean
message(paste(Sys.time(), 'calculating mean'))
meanCov <- Reduce('+', chrCov$coverage) / length(chrCov$coverage)
## Loop over several cutoffs
region_cuts <- lapply(seq(0.025, 0.5, by = 0.025), function(cutoff) {
message(paste(Sys.time(), 'finding regions with cutoff', cutoff))
## Find regions
regs <- findRegions(position = meanCov > cutoff,
fstats = meanCov[meanCov > cutoff], chr = chr, cutoff = cutoff,
maxClusterGap = 3000L)
names(regs) <- NULL
return(regs)
})
names(region_cuts) <- seq(0.025, 0.5, by = 0.025)
## Save results
save(region_cuts, file = paste0('region_cuts-', chr, '.Rdata'))
## Reproducibility info
proc.time()
message(Sys.time())
options(width = 120)
devtools::session_info()