[adegenet-forum] propShared Alleles

Jombart, Thibaut t.jombart at imperial.ac.uk
Mon Jul 16 14:10:40 CEST 2012


Hi again, 

I can't see the problem:
Your data are:
## original
> datCasted
  ind       l       m
1   1 108/110 110/110
2   2 116/114  90/111
3   3 122/152 122/128
4   4 119/122  69/128

## after conversion
> genind2df(gi,sep="-")
        l       m
1 108-110 110-110
2 114-116 090-111
3 122-152 122-128
4 119-122 069-128

## propShared
> propShared(gi)
  1 2   3   4
1 1 0 0.0 0.0
2 0 1 0.0 0.0
3 0 0 1.0 0.5
4 0 0 0.5 1.0

Which is exactly the expected result (the proportion of identical alleles between pairs of genotypes). 

Cheers

Thibaut


________________________________________
From: Johannes Signer [j.m.signer at gmail.com]
Sent: 16 July 2012 11:08
To: Jombart, Thibaut
Cc: adegenet-forum at lists.r-forge.r-project.org
Subject: Re: [adegenet-forum] propShared Alleles

Hello Thibaut,

thanks for your reply. I used version 1.3-4. I was unable to install 1.3-5 with R 2.15 and 2.15.1.

Best Johannes

install.packages("adegenet",repos="http://r-forge.r-project.org")
Warning message:
package ‘adegenet’ is not available (for R version 2.15.1)

And my session.info<http://session.info>()

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C                 LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] adegenet_1.3-4     ade4_1.5-0         MASS_7.3-18        RColorBrewer_1.0-5
[5] stringr_0.6        plyr_1.7.1

loaded via a namespace (and not attached):
[1] tools_2.15.1


On Fri, Jul 13, 2012 at 6:58 PM, Jombart, Thibaut <t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>> wrote:
Hello,

there was a bug in some old version of propShared. Are you using the latest version of adegenet (stable 1.3-4 or devel 1.3-5)?

Cheers

Thibaut
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org> [adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org>] on behalf of Johannes Signer [j.m.signer at gmail.com<mailto:j.m.signer at gmail.com>]
Sent: 13 July 2012 17:39
To: adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org>
Subject: [adegenet-forum] propShared Alleles

Hello List,

I am trying to calculate individual genetic distances with the function `adegenet::propShared`. I found that results from `propShared` did not correlate very well with other genetic distances such as Rousset'a. Based on this results, I wrote my own function to calculate proportion of shared alleles (see below). Results from this function do not correspond with the results from `propShared`, but correlates better with other Rousset's a. Am I missing something on the methodology of `propShared`?

Thanks a lot for hints,

Best
Johannes

# --------------------------------------------------------------------------------------------------------------------------- #
# Example

# Load packages
library(adegenet)
library(stringr)
library(reshape2)

# Own function to calculate proportion shared alleles
# Following instruction from here: http://helix.biology.mcmaster.ca/brent/node8.html
psa <- function(s) {
    # s - each row is a genotype, first column is id

    # all combinations
    idx <- combn(1:nrow(s), 2)

    # calculate distances
    d <- 1 - apply(idx, 2, function(x) sum(apply(s[x, -1], 2, diff) == 0)) / ncol(s[,-1])

    # create object of class distance
    nams <- unique(c(as.character(idx[1, ]), as.character(idx[2, ])))
    dd <- structure(d, Size = length(nams), Labels = nams, Diag = FALSE, Upper = FALSE, method = "user", class = "dist")
    return(dd)
}



# Example dataset
dat <- data.frame(id=as.character(1:4), x=0, y=0,
    l_1=c(108, 116, 122, 119),
    l_2=c(110, 114, 152, 122),
    m_1=c(110, 90, 122, 69),
    m_2=c(110, 111, 128, 128))


# Create genind
coords <- dat[, 2:3]
datMelted <- melt(dat[, c(1, 4:ncol(dat))])

names(datMelted) <- c("ind", "loci", "allele")

# removing 1 and 2, since it is the same loci
datMelted$loci <- str_sub(as.character(datMelted$loci), end=-3)

# Creating a genind object for the adegenet package
datCasted <- dcast(datMelted, ind ~ loci, paste, collapse="/")
gi <- df2genind(datCasted[, 2:ncol(datCasted)], sep="/", missing="NA", ind=datCasted[, 1])


# calcualte proportion of shared alleles
propShared(gi)
as.matrix(psa(dat[, -c(2,3)]))

# It is my understanding that propShared does not calcualte 1 - porpShared and is the reason for a systematic difference
# However, ind 3 and 4 differ by one of four alleles (= 0.25), but propShared suggests 0.5



More information about the adegenet-forum mailing list