/usr/share/ray/scripts/plot-coverage-distribution.R is in ray-extra 2.3.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | #!/usr/bin/Rscript
#
# input: PREFIX.CoverageDistribution.txt
# output: PREFIX.CoverageDistribution.txt.pdf
arguments=commandArgs(trailingOnly = TRUE)
file=arguments[1]
r=read.table(file)
derivatives=c()
i=2
derivatives[1]=0
# 1. find the places where dy/dx = 0
# 2. find the zero with maximum y
# 3. find the x left of the peak zero with min y
while(i<=length(r[[1]])){
xi=r[[1]][i]
yi=log(r[[2]][i])
xi1=r[[1]][i-1]
yi1=log(r[[2]][i-1])
derivative=(yi-yi1)/(xi-xi1)
derivatives[i]=derivative
i=i+1
}
minimums=c()
maximums=c()
i=2
while(i<=length(r[[1]])){
derivative=derivatives[i]
lastDerivative=derivatives[i-1]
if(lastDerivative>0&&derivative<0){
maximums=c(maximums,i)
}
if(lastDerivative<0&&derivative>0){
minimums=c(minimums,i)
}
i=i+1
}
#print("Derivatives computed")
i=1
peakI=maximums[1]
while(i<=length(maximums)){
index=maximums[i]
y=r[[2]][index]
if(y>r[[2]][peakI]){
peakI=index
}
i=i+1
}
i=peakI
minI=peakI
while(i>=1){
y=r[[2]][i]
if(y<r[[2]][minI]){
minI=i
}
i=i-1
}
i=1
maxI=peakI
while(i<=length(r[[1]])){
if(i<peakI){
i=i+1
next
}
derivative=derivatives[i]
if(r[[2]][i]<r[[2]][minI]/2){
maxI=i
break
}
if(derivative>0){
maxI=i
break
}
i=i+1
}
#print("Found peak")
#print(r[[1]][peakI])
#print(r[[1]][minI])
#print(zeros)
#print("Found minimum")
outputFile=paste(file,".png",sep="")
png(outputFile)
xMax=500
par(mfrow=c(2,1))
plot(r[[1]],log(r[[2]])/log(10),type='l',col='black',xlim=c(0,2*r[[1]][maxI]),xlab="Coverage value",ylab="Number of vertices (log scale, base 10)",
main=paste("Distribution of coverage values\n",file,sep=""))
grid(lty=1,lwd=2)
points(c(r[[1]][peakI]),log(c(r[[2]][peakI])),col="red")
points(c(r[[1]][minI]),log(c(r[[2]][minI])),col="red")
points(c(r[[1]][maxI]),log(c(r[[2]][maxI])),col="red")
#print("Points showed")
#par(new=TRUE)
#print("Before second")
scale=1
plot(r[[1]],derivatives,type='l',col='green',xlim=c(0,2*r[[1]][maxI]),ylim=c(-scale,scale),xlab="Coverage value",ylab="Derivative")
#legend("topright",col=c("black","green"),lty=1,legend=c("Signal","Derivative"))
#print("Done legend")
grid(lty=1,lwd=2)
#scale=0.1
#plot(r[[1]],secondDerivatives,type='l',col='blue',ylim=c(-scale,scale),
#xlim=c(0,500),xlab="Coverage value",ylab="Second derivative")
#grid(lty=1,lwd=2)
#plot(r[[1]],integrals,type='l',col='red',xlim=c(0,500),xlab="Coverage value",ylim=c(0,integrals[length(r[[1]])-1]))
#grid(lty=1,lwd=2)
dev.off()
|