mat1
lapply(mat1, factor)
data.frame(lapply(mat1, factor))
as.integer(data.frame(lapply(mat1, factor)))
data.frame(lapply(mat1, function(c) as.integer(factor(e))))
data.frame(lapply(mat1, function(c) as.integer(factor(c))))
matAll <- cbind(mat1,mat2)
        matAll <- apply(matAll,1:2,as.integer)
        
matAll <- cbind(mat1,mat2)
        
matAll
mat1
mat1 <- as.data.frame(mat1)
        mat2 <- as.data.frame(mat2)
        mat1 <- data.frame(lapply(mat1, function(c) as.integer(factor(c))))
        mat2 <- data.frame(lapply(mat2, function(c) as.integer(factor(c))))
        
        matAll <- cbind(mat1,mat2)

matAll
class(matAll)
as.matrix(matAll)
x
temp
mat1
factor(1:2, levels=(1:3)
)
alleleSize
factor(c(1,3), levels=(1:3))
factor(c('a','b'), levels=(c('a','b','x')))
as.integer(factor(c('a','b'), levels=(c('a','b','x'))))
factor(c('a','b'), levels=(c('a','b','x')))L
as.integer(factor(c('a','b'), levels=(c('a','b','x'))))
as.integer(factor(c('x','a','b'), levels=(c('a','b','x'))))
x
x$all.names
x$all.names
lapply(x$all.names, function(v) 1:length(v))
    x@all.names <- lapply(x@all.names, function(v) 1:length(v))

   temp <- genind2df(x,usepop=FALSE)
        alleleSize <- max(apply(temp,1:2,nchar))/2
        mat1 <- apply(temp, 1:2, substr, 1, alleleSize)
        mat2 <- apply(temp, 1:2, substr, alleleSize+1, alleleSize*2)
        
        matAll <- cbind(mat1,mat2)
        matAll <- apply(matAll,1:2,as.integer)
        matAll[is.na(matAll)] <- 0

matAll
res
matAll
df
q) <- 
q()
n
read.csv("example.csv")
dat <- read.csv("example.csv")
rownames(dat) <- dat[,1]
dat
dat <- dat[,-1]
dat <- dat[,-1]
dat
x <- df2genind(dat, sep="+")
x <- df2genind(dat, sep="\+")
x <- df2genind(dat, sep="\\+")
x
genind2df(x, sep="+")
x
dat
propShared(x)
y <- df2genind(dat)
y <- df2genind(dat)
install.packages("adegenet")
propShared(x)
rm(propShared )
detach("package:adegenet")
library(adegenet)
propShared(x)
x
propShared(x)
q()
y
propShared(x)
x
x@all.names <- lapply(x@all.names, function(v) 1:length(v))

x
 invisible(validObject(x))

  checkType(x)

x <- data.frame()
read.table("/home/master/dev/adegenet/www/files/haplo.txt")
x <- read.table("/home/master/dev/adegenet/www/files/haplo.txt")
x <- df2genind(xm ploidy=1)
x <- df2genind(x, ploidy=1)
x
genind2df(x)
genind2df(x,sep="/")
x$tab
 x@all.names <- lapply(x@all.names, function(v) 1:length(v))

x$all.names
 nAllByInd <- propTyped(x,by="ind") * nLoc(x)

nAllByInd
x
df <- read.table("/home/master/dev/adegenet/www/files/haplo.txt")
dfdf <- 
df
df
nAllByInd
?propTyped
propTyped(x)
propTyped(x,"both")
        nAllByInd <- propTyped(x,"both")

nAllByInd
nAllByInd %*% t(nAllByInd)
nAll <- nAllByInd %*% t(nAllByInd)
X <- x@tab
        X[is.na(X)] <- 0
        M <- X %*% t(X)

M
nAll
X / nAll
dim(X)
dim(nAll)
M
M / nAll
        res <- M / nAll

res
class(res)
colnames(X)
colnames(res)
rownames(res)
        colnames(res) <- rownames(res) <- obj$ind.names

        colnames(res) <- rownames(res) <- x$ind.names

res
df
nAll
1/0
0/0
is.na(0/0)
is.nan(0/0)
is.nan(NA)
is.nan(NA)
propShared <- function(obj){
    x <- obj

    ## convert alleles to integers (alleles may be characters)
    x@all.names <- lapply(x@all.names, function(v) 1:length(v))

    ## check that this is a valid genind
    if(!inherits(x,"genind")) stop("obj must be a genind object.")
    invisible(validObject(x))

    ## check ploidy level
    if(x$ploidy > 2) stop("not implemented for ploidy > 2")
    checkType(x)


    ## if ploidy = 1
    if(x$ploidy == as.integer(1)){
        ## stop("not implemented for ploidy = 1")
        ## compute numbers of alleles used in each comparison
        nAllByInd <- propTyped(x,"both")
        nAll <- nAllByInd %*% t(nAllByInd)

        ## compute numbers of common alleles
        X <- x@tab
        X[is.na(X)] <- 0
        M <- X %*% t(X)

        ## result
        res <- M / nAll
        res[is.nan(res)] <- NA # as 0/0 is NaN (when no common locus typed)
        colnames(res) <- rownames(res) <- x$ind.names
        return(res)
    }

    ## if ploidy = 2
    if(x$ploidy == as.integer(2)){
        ## build a matrix of genotypes (in rows) coded by integers
        ## NAs are coded by 0
        ## The matrix is a cbind of two matrices, storing respectively the
        ## first and the second allele.
        temp <- genind2df(x,usepop=FALSE)
        alleleSize <- max(apply(temp,1:2,nchar))/2
        mat1 <- apply(temp, 1:2, substr, 1, alleleSize)
        mat2 <- apply(temp, 1:2, substr, alleleSize+1, alleleSize*2)

        matAll <- cbind(mat1,mat2)
        matAll <- apply(matAll,1:2,as.integer)
        matAll[is.na(matAll)] <- 0

        n <- nrow(matAll)
        resVec <- double(n*(n-1)/2)
        res <- .C("sharedAll", as.integer(as.matrix(matAll)),
                  n, ncol(matAll), resVec, PACKAGE="adegenet")[[4]]

        attr(res,"Size") <- n
        attr(res,"Diag") <- FALSE
        attr(res,"Upper") <- FALSE
        class(res) <- "dist"
        res <- as.matrix(res)
    } # end if ploidy = 2

    diag(res) <- 1
    rownames(res) <- x@ind.names
    colnames(res) <- x@ind.names
    return(res)
}


propShared(x)
x
?quasieuclid
?lingoes
?caillez
?cailliez
q()
n
