-
Notifications
You must be signed in to change notification settings - Fork 43
/
01-read_galp.R
executable file
·36 lines (32 loc) · 1.09 KB
/
01-read_galp.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
library(GenomicAlignments)
library(GenomicRanges)
library(getopt)
### Used for getting information from shell script
args <- commandArgs(trailingOnly = TRUE)
hh <- paste(unlist(args), collapse = " ")
listoptions <- unlist(strsplit(hh, "--"))[-1]
options.args <- sapply(listoptions, function(x) {
unlist(strsplit(x, " "))[-1]
})
options.names <- sapply(listoptions, function(x) {
option <- unlist(strsplit(x, " "))[1]
})
names(options.args) <- unlist(options.names)
id <- options.args[1]
bamdir <- options.args[2]
galpdir <- options.args[3]
###
### Read GAlignmentPairs
bamfile <- file.path(bamdir, id)
indexed.bam <- gsub("$", ".bai", bamfile)
if (!file.exists(indexed.bam)) {
indexBam(bamfile)
}
param <- ScanBamParam(flag = scanBamFlag(isDuplicate = FALSE,
isSecondaryAlignment = FALSE,
isUnmappedQuery = FALSE),
mapqFilter = 30)
sample <- gsub(".bam", "", id)
galp.file <- file.path(galpdir, paste0(sample, ".rds"))
galp <- readGAlignmentPairs(bamfile, param = param)
saveRDS(galp, galp.file)