-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpertf.r
executable file
·94 lines (76 loc) · 2.24 KB
/
pertf.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/Rscript
#Rscript script commondir pwmdir tmpdir outdir bamfile pwmid
#example:
#Rscript pertf.r /cluster/thashim/basepiq/common.r /cluster/thashim/tmppiq/ /scratch/tmp/ /cluster/thashim/130130.mm10.d0/ /cluster/thashim/tmppiq/d0.RData 139
options(echo=TRUE)
args <- commandArgs(trailingOnly = TRUE)
print(args)
#location of common.r containing runtime parameters
commonfile = args[1]
#directory where pwm matches are stored
pwmdir = args[2]
#directory to use as fast temporary storage
tmpdir = args[3]
#location of output calls
outdir = args[4]
#location of the bam RData file made by bam2rdata.r
bamfile = args[5]
#which pwm file to use in pwmdir
pwmid = args[6]
###
# do FW
match.rc = F
dump.chropen = F
two.pass = F
suppressWarnings(source(commonfile))
if(overwrite==F & file.exists( file.path(outdir,paste0(pwmid,'-diag.pdf')))){
stop(paste0('found previous run for ',pwmid,' avoiding overwrite'))
}
debugstring = c('loading pwm','loadbam','clustering','binding outputs')
dump.bed = T
tryCatch({
phase=0
load(paste0(pwmdir,pwmid,'.pwmout.RData'))
if(sum(clengths[1])>0){
phase=1
at<-Sys.time()
source('loadbam.r')
print(Sys.time()-at);at<-Sys.time()
phase=2
source('cluster.r')
print(Sys.time()-at);at<-Sys.time()
phase=3
source('bindcall.r')
print(Sys.time()-at);at<-Sys.time()
}
},error = function(e){
e$message=paste0('error during ',debugstring[phase+1],'\n','Error msg: ',e$message,'\n Args:',paste0(commandArgs(trailingOnly = TRUE),collapse=':'))
stop(e)
})
###
# do RC
match.rc = T
suppressWarnings(source(commonfile))
if(overwrite==F & file.exists( file.path(outdir,paste0(pwmid,'-diag.rc.pdf')))){
stop(paste0('found previous run for ',pwmid,' avoiding overwrite'))
}
debugstring = c('loading pwm.rc','loadbam.rc','clustering.rc','binding outputs.rc')
tryCatch({
phase=0
load(paste0(pwmdir,pwmid,'.pwmout.rc.RData'))
if(sum(clengths[1])>0){
phase=1
at<-Sys.time()
source('loadbam.r')
print(Sys.time()-at);at<-Sys.time()
phase=2
source('cluster.r')
print(Sys.time()-at);at<-Sys.time()
phase=3
source('bindcall.r')
print(Sys.time()-at);at<-Sys.time()
}
},error = function(e){
e$message=paste0('error during ',debugstring[phase+1],'\n','Error msg: ',e$message,'\n Args:',paste0(commandArgs(trailingOnly = TRUE),collapse=':'))
stop(e)
})