-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareEncodeBam.R
executable file
·60 lines (48 loc) · 1.62 KB
/
prepareEncodeBam.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
58
59
60
#!/usr/bin/nohup Rscript
#
# pliu 20180917
#
# download human ENCODE BAM and then index
#
# 30 x 2.1 GHz, ~3 hrs
# ~ 500G
#
suppressMessages(library(Rsamtools))
library(parallel)
main <- function() {
prm = list(
njob_in_para = 30,
bamids = c(
"ENCFF125RAL", "ENCFF739OVZ", "ENCFF802TLC", "ENCFF428VBU",
"ENCFF547YFO", "ENCFF782IVX", "ENCFF709IUX", "ENCFF244ZQA",
"ENCFF343WEZ", "ENCFF444SCT", "ENCFF315VHI", "ENCFF834ITU",
"ENCFF306YQS", "ENCFF521KYZ", "ENCFF800YJR", "ENCFF782TAX",
"ENCFF912SZP", "ENCFF207ZSA", "ENCFF846WOV", "ENCFF588YLF",
"ENCFF048ODN", "ENCFF381BQZ", "ENCFF044SJL", "ENCFF728JKQ",
"ENCFF367VEP", "ENCFF983FHE", "ENCFF904OHO", "ENCFF838JGD",
"ENCFF263OLY", "ENCFF978ACT"
),
enc_url = 'https://www.encodeproject.org/files/',
bamdir = 'input/'
)
if ( ! file.exists(prm$bamdir) ) dir.create(prm$bamdir, recursive=T)
setwd(prm$bamdir)
## download input Bam
mclapply(prm$bamids, dlBamAndIndex, prm, mc.cores=prm$njob_in_para)
}
dlBamAndIndex <- function(bamid, prm) {
fbam_remote = paste0(prm$enc_url, bamid, '/@@download/', bamid, '.bam')
fbam_local = paste0(bamid, '.bam')
fbai_local = paste0(bamid, '.bam.bai')
if ( ! file.exists( fbam_local ) ) {
download.file(fbam_remote, destfile=fbam_local, quiet=F)
} else {
cat('use existing file:', fbam_local, "\n")
}
if ( ! file.exists( fbai_local ) ) {
indexBam(fbam_local)
} else {
cat('use existing file:', fbai_local, "\n")
}
}
system.time( main() )