R/my_unique.R

Defines functions my_unique

my_unique <- function(hapldata){

if(is.data.frame(hapldata)){hapldata <- as.matrix(hapldata)}

dub       <- duplicated(hapldata,fromLast=FALSE)
coresets  <- hapldata[!dub,,drop=FALSE]
temp      <- which(!dub) # ids of haplotypes

idx <- vector(,dim(hapldata)[1])

for(xx in 1:dim(coresets)[1]){
   comp1   <- coresets[xx,]
   ss      <- apply(hapldata,1,function(x){return(all(comp1==x))})
   idx[ss] <- xx
}
numHap <- dim(coresets)[1]
sizHap <- vector(,numHap)
for(xx in 1:numHap){
sizHap[xx] <- sum(idx==xx)
}

return(list(Matrix=hapldata,uniquematrix=coresets,ids=temp,idx=idx,numHap=numHap,sizHap=sizHap))

}

Try the PopGenome package in your browser

Any scripts or data that you put into this service are public.

PopGenome documentation built on Feb. 1, 2020, 1:07 a.m.