forked from mskilab-org/fragCounter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frag
executable file
·57 lines (43 loc) · 4.03 KB
/
frag
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
#!/usr/bin/env Rscript
library(optparse)
dr.str = "
███████╗██████╗ █████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗████████╗███████╗██████╗
██╔════╝██╔══██╗██╔══██╗██╔════╝ ██╔════╝██╔═══██╗██║ ██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗
█████╗ ██████╔╝███████║██║ ███╗██║ ██║ ██║██║ ██║██╔██╗ ██║ ██║ █████╗ ██████╔╝
██╔══╝ ██╔══██╗██╔══██║██║ ██║██║ ██║ ██║██║ ██║██║╚██╗██║ ██║ ██╔══╝ ██╔══██╗
██║ ██║ ██║██║ ██║╚██████╔╝╚██████╗╚██████╔╝╚██████╔╝██║ ╚████║ ██║ ███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
"
library(optparse)
options(bitmapType='cairo')
if (!exists('opt'))
{
option_list = list(
make_option(c("-b", "--bam"), type = "character", help = "Path to .bam file"),
make_option(c("-c", "--cov"), type = "character", help = "Path to existing coverage rds or bedgraph"),
make_option(c("-m", "--midpoint"), type = "character", default = "TRUE", help = "If TRUE only count midpoint if FALSE then count bin footprint of every fragment interval"),
make_option(c("-w", "--window"), type = "integer", default = 1000, help = "Window / bin size"),
make_option(c("-d", "--gcmapdir"), type = "character", help = "Mappability / GC content dir"),
make_option(c("-q", "--minmapq"), type = "integer", default = 1, help = "Minimal map quality"),
make_option(c("-p", "--paired"), type = "logical", default = TRUE, help = "Is paired"),
make_option(c("-e", "--exome"), type = "logical", default = FALSE, help = "Use exons as bins instead of fixed window"),
make_option(c("-u", "--use.skel"), type = "logical", default = FALSE, help = "Use user defined regions instead of default exome skeleton"),
make_option(c("-s", "--skeleton"), type = "character", help = "Path to skeleton file"),
make_option(c("-o", "--outdir"), type = "character", default = './', help = "Directory to dump output into"),
make_option(c("-l", "--libdir"), type = "character", default = paste(Sys.getenv('GIT_HOME'), 'isva', sep = '/'), help = "Directory containing this R file")
)
parseobj = OptionParser(option_list=option_list)
opt = parse_args(parseobj)
if (is.null(opt$libdir) | (is.null(opt$bam) & is.null(opt$cov)))
stop(print_help(parseobj))
## keep record of run
writeLines(paste(paste('--', names(opt), ' ', sapply(opt, function(x) paste(x, collapse = ',')), sep = '', collapse = ' '), sep = ''), paste(opt$outdir, 'cmd.args', sep = '/'))
saveRDS(opt, paste(opt$outdir, 'cmd.args.rds', sep = '/'))
}
#############################
suppressWarnings(suppressPackageStartupMessages(library(fragCounter)))
suppressWarnings(suppressPackageStartupMessages(library(skidb)))
suppressWarnings(suppressPackageStartupMessages(library(data.table)))
message(dr.str)
out = fragCounter(bam = opt$bam, cov = opt$cov, window = opt$window, gc.rds.dir = opt$gcmapdir, map.rds.dir = opt$gcmapdir, minmapq = opt$minmapq, paired = opt$paired, outdir = opt$outdir, exome = opt$exome, use.skel = opt$use.skel, skeleton = opt$skeleton)
saveRDS(out, paste(opt$outdir, 'cov.rds', sep = '/'))