-
Notifications
You must be signed in to change notification settings - Fork 47
/
ROSE2_stitchOpt.R
59 lines (40 loc) · 1.44 KB
/
ROSE2_stitchOpt.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
stitchFile = commandArgs(TRUE)[1]
outFolder = commandArgs(TRUE)[2]
name = commandArgs(TRUE)[3]
#print(stitchFile)
#print(outFolder)
#print(name)
stitchTable = read.table(stitchFile,header=TRUE)
xTitle = 'Number of enhancer regions'
xVector =stitchTable$NUM_REGIONS
yVector=stitchTable$MEAN_CONSTIT/stitchTable$MEAN_REGION
yTitle = 'Average fraction of \nenhancer sequence in each region'
yDerivTitle = 'Decrease in fraction of \nenhancer sequence per region'
yDeriv = diff(yVector)
# print('x vector has a length of')
# print(length(xVector))
# print(xVector)
# print(xVector[2:length(xVector)])
# print(length(xVector[2:length(xVector)]))
# print('y spline vector has a length of')
# print(length(yDeriv))
# print(yVector)
# print(yDeriv)
yDerviFit = smooth.spline(xVector[2:length(xVector)],yDeriv)
optX= yDerviFit$x[which.min(yDerviFit$y)]
#get the optimal stitching parameter
optStitch = stitchTable[which(stitchTable[,2]==optX),1]
stitchPDFName = paste(outFolder,name,'_stitch_parameter.pdf',sep='')
#print(stitchPDFName)
pdf(file=stitchPDFName,width=8.5,height=11)
par(mai=c(1,1.5,.2,.5))
par(mfrow=c(2,1))
plot(xVector,yVector,type='l',xlab=xTitle,ylab=yTitle)
abline(v= optX)
stitchText = paste('OPTIMUM STITCHING AT: ',optStitch,'bp',sep='')
text(min(xVector),.8*max(yVector),stitchText,pos=4)
plot(xVector[2:length(xVector)],yDeriv,xlab=xTitle,ylab=yDerivTitle)
lines(yDerviFit,col='blue')
abline(v= optX)
dev.off()
write(optStitch,stdout())