[adegenet-forum] propShared Alleles
Johannes Signer
j.m.signer at gmail.com
Fri Jul 13 18:39:49 CEST 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20120713/704f5a9a/attachment.html>
More information about the adegenet-forum
mailing list