[adegenet-forum] read.genepop (adegenet 2.0.0 with R v. 3.2.1)
Paul Maier
maierpa at gmail.com
Wed Jul 15 20:15:52 CEST 2015
On closer inspection, it appears the new version stores missing data as
alleles (i.e. *.00 in @tab). So using tab to replace the allele counts
doesn't work. For example, x at tab <- tab(x, NA.method="mean") does nothing
because missing data is stored as normal data. Here's a workaround I
created, although probably not the most clever method, it fixed my problem.
Hopefully this helps someone!
Paul
# Fix missing values to reflect depracated option, missing = "mean"
x at tab <- x at tab[,-grep("\\.00",colnames(x at tab))] #remove "00" alleles
rep <- gsub("([^\\.]+)\\.\\d+","\\1",colnames(x at tab)) #locus names
loci <- unique(x at loc.fac) #unique locus names
x at loc.fac <- as.factor(rep)
for (i in 1:length(x at all.names))
if ("00" %in% x at all.names[[i]]) #remove "00" from allele names
x at all.names[[i]] <- x at all.names[[i]][-which(x at all.names[[i]]=="00")]
for (i in 1:length(x at loc.n.all)) #remove "00" from allele counts
x at loc.n.all[[i]] <- length(x at all.names[[i]])
for (i in 1:length(loci)) { #replace missing data with mean allele counts
df <- data.frame(x at tab[,which(loci[i] == rep)]) #df, alleles for one locus
for (j in 1:nrow(df)) {
if (sum(df[j,]) == 0) {
for (k in 1:length(df[j,])) { #mean allele counts from rows with data
df[j,k] <- round(mean( df[which(apply(df,1,sum) != 0),k] ))
}
x at tab[j,which(loci[i] == rep)] <- as.numeric(df[j,])
}
}
}
----------------------------------------------
Paul Maier
San Diego State, PhD Student
US Geological Survey, Biologist
The Biodiversity Group, Science Advisor
On Tue, Jul 14, 2015 at 2:30 PM, Paul Maier <maierpa at gmail.com> wrote:
> Thanks, Thibaut, for clearing that up.
> Paul
>
>
> ----------------------------------------------
> Paul Maier
>
> San Diego State, PhD Student
> US Geological Survey, Biologist
> The Biodiversity Group, Science Advisor
>
>
> On Tue, Jul 14, 2015 at 1:01 PM, Jombart, Thibaut <
> t.jombart at imperial.ac.uk> wrote:
>
>>
>> Hello,
>>
>> yes, this change is on purpose. adegenet 2.0.0 includes a lot of reforms
>> of the code, with some breaking backward compatibility.
>>
>> Here is a good example: storing replacement of missing values inside a
>> genind object was bad practice - one ends up not knowing if all values are
>> genuine, or if some are merely NAs that have been replaced. In the new
>> version, missing data are stored as missing, but they can be easily
>> replaced when extracting a table of allele counts or frequencies (see
>> ?tab).
>>
>> Cheers
>> Thibaut
>>
>>
>> ==============================
>> Dr Thibaut Jombart
>> MRC Centre for Outbreak Analysis and Modelling
>> Department of Infectious Disease Epidemiology
>> Imperial College - School of Public Health
>> Norfolk Place, London W2 1PG, UK
>> Tel. : 0044 (0)20 7594 3658
>> http://sites.google.com/site/thibautjombart/
>> http://sites.google.com/site/therepiproject/
>> http://adegenet.r-forge.r-project.org/
>> Twitter: @thibautjombart
>>
>>
>> ------------------------------
>> *From:* adegenet-forum-bounces at lists.r-forge.r-project.org [
>> adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Paul
>> Maier [maierpa at gmail.com]
>> *Sent:* 14 July 2015 20:50
>> *To:* adegenet-forum at lists.r-forge.r-project.org
>> *Subject:* [adegenet-forum] read.genepop (adegenet 2.0.0 with R v. 3.2.1)
>>
>> Hi all,
>> It appears the new version of this function (read.genepop) doesn't have
>> the 'missing' option. Can someone either post an older version of adegenet
>> compatible with R 3.2.1, or post R code for the earlier version of the
>> read.genepop function? I hadn't anticipated trying to figure this out
>> manually.
>> Thanks!
>> Paul
>>
>> ----------------------------------------------
>> Paul Maier
>>
>> San Diego State, PhD Student
>> US Geological Survey, Biologist
>> The Biodiversity Group, Science Advisor
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20150715/4d02bebd/attachment-0001.html>
More information about the adegenet-forum
mailing list