load("insidetrees/Figure3/tab.splits10000.RData")

tab0.05<-numeric(100)
tab0.1<-numeric(100)
tab0.25<-numeric(100)
tab0.4<-numeric(100)

for (i in 1:250)
 {
 tab0.05[1:ncol(tab.splits10000[[i]]$maf0.05)]<- tab0.05[1:ncol(tab.splits10000[[i]]$maf0.05)]+apply(tab.splits10000[[i]]$maf0.05,FUN=sum,MARGIN=2)
 tab0.1[1:ncol(tab.splits10000[[i]]$maf0.1)]<- tab0.1[1:ncol(tab.splits10000[[i]]$maf0.1)]+apply(tab.splits10000[[i]]$maf0.1,FUN=sum,MARGIN=2)
 tab0.25[1:ncol(tab.splits10000[[i]]$maf0.25)]<- tab0.25[1:ncol(tab.splits10000[[i]]$maf0.25)]+apply(tab.splits10000[[i]]$maf0.25,FUN=sum,MARGIN=2)
 tab0.4[1:ncol(tab.splits10000[[i]]$maf0.4)]<- tab0.4[1:ncol(tab.splits10000[[i]]$maf0.4)]+apply(tab.splits10000[[i]]$maf0.4,FUN=sum,MARGIN=2)
 }


tab0.05<-tab0.05[1:34]
tab0.1<-tab0.1[1:34]
tab0.25<-tab0.25[1:34]
tab0.4<-tab0.4[1:34]

sumtab<-tab0.05+tab0.1+tab0.25+tab0.4

pdf("Figure5.pdf",height=5,width=5)
plot(tab0.05*100/sumtab, type="l",ylim=c(0,100),ylab="Frequency of selection",col=1,xlab="layer",main="Frequency of selection \n depending on MAF and layer")
points(tab0.1*100/sumtab,type="l",col=2)
points(tab0.25*100/sumtab,type="l",col=3)
points(tab0.4*100/sumtab,type="l",col=4)
legend(x=2,y=90,legend=c("MAF=0.05","MAF=0.1","MAF=0.25","MAF=0.4"),col=1:4,lty=1)
dev.off()


