load("dups.Rda")
load("analyzeResult.Rda")
library(hapFabia)
library(fabia)
shiftSize <- 5000
segmentSize <- 10000
fileName="KPGP1000_chr1" # without type


lower <- 183316845
upper <- 183386180
a11 <- avibdPos[which(avibdPos>lower)]
a22 <- avibdPos[which(avibdPos<upper)]
a1t <- which(avibdPos>lower)
a2t <- which(avibdPos<upper)
a3t <- intersect(a1t,a2t)

countsA1[a3t,]

avnoSnps[a3t]

posAll <- 598
ibdC <- 182
start <- (posAll-1)*shiftSize
end <- start + segmentSize
pRange <- paste("_",format(start,scientific=FALSE),"_",format(end,scientific=FALSE),sep="")
load(file=paste(fileName,pRange,"_resAnno",".Rda",sep=""))
IBD <- resHapFabia$mergedIBD 
plotOneIBD(IBD,filename=paste(fileName,pRange,"_mat",sep=""),ibdC)


ibdS <- countsA1[a3t,3]
posS <- countsA1[a3t,4]

devAskNewPage(ask=TRUE)

for (i in 1:length(ibdS)) {

posAll <- posS[i]
ibdC <- ibdS[i]
start <- (posAll-1)*shiftSize
end <- start + segmentSize
pRange <- paste("_",format(start,scientific=FALSE),"_",format(end,scientific=FALSE),sep="")
load(file=paste(fileName,pRange,"_resAnno",".Rda",sep=""))
IBD <- resHapFabia$mergedIBD 
plotOneIBD(IBD,filename=paste("",fileName,pRange,"_mat",sep=""),ibdC)

}

devAskNewPage(ask=FALSE)



countsA1[a3t,]
> countsA1[a3t,]
      allCount1 allCount ibdC posAll
 [1,]     79689    90748   16    442
 [2,]     79690    90749   17    442
 [3,]     79703    90765   33    442
 [4,]     79704    90766   34    442
 [5,]     79717    90779   47    442
 [6,]     79718    90780   48    442
 [7,]     79721    90783   51    442
 [8,]     79722    90784   52    442
 [9,]     79740    90806   74    442
[10,]     79752    90818   86    442
[11,]     79753    90819   87    442
[12,]     79771    90840  108    442
[13,]     79772    90841  109    442
[14,]     79784    90854  122    442
[15,]     79790    90861  129    442
[16,]     79791    90862  130    442
[17,]     79792    90863  131    442
[18,]     79798    90870  138    442
[19,]     79805    90877  145    442
[20,]     79822    90897  165    442
[21,]     79832    90907  175    442
[22,]     79833    90908  176    442
[23,]     79836    90912  180    442
[24,]     79839    90915  183    442
[25,]     79842    90919    2    443
[26,]     79843    90920    3    443
[27,]     79873    90955   38    443
[28,]     79874    90956   39    443
[29,]     79875    90957   40    443
[30,]     79903    90990   73    443
[31,]     79904    90991   74    443
[32,]     79905    90992   75    443
[33,]     79914    91007   90    443
[34,]     79915    91008   91    443
[35,]     79916    91009   92    443
[36,]     79950    91047  130    443
[37,]     79959    91057  140    443
[38,]     79967    91067  150    443
[39,]     80000    91106  189    443
> 

posAll <- 442
ibdC <- 51

posAll <- 442
ibdC <- 52

posAll <- 443
ibdC <- 73




posAll <- 443
ibdC <- 73
start <- (posAll-1)*shiftSize
end <- start + segmentSize
pRange <- paste("_",format(start,scientific=FALSE),"_",format(end,scientific=FALSE),sep="")
load(file=paste(fileName,pRange,"_resAnno",".Rda",sep=""))
IBD <- resHapFabia$mergedIBD 
plotOneIBD(IBD,filename=paste("",fileName,pRange,"_mat",sep=""),ibdC)