[R-sig-genetics] Genuine object repooling issue
Bhuller, Ravneet
ravneet.bhuller13 at imperial.ac.uk
Mon Jan 23 10:08:22 CET 2017
Dear Zhian,
Many thanks for all the help.
You helped me earlier also in another problem.
Really appreciate your help and support.
Best wishes,
Rav
> On 22 Jan 2017, at 15:09, Zhian Kamvar <zkamvar at gmail.com> wrote:
>
> Hi,
>
> You've got the right idea with make.unique, but you're trying to use repool on only one population at a time.
>
> First and foremost: don't use row.names(x$tab) or nrow(x$tab), use indNames(x) and nInd(x), respectively.
>
>
> Your procedure needs to be done in three steps:
>
> 1. sample the individuals
> 2. rename the individuals
> 3. repool the populations
>
> Taking the example you gave, this should work:
>
> MySamp8 <- lapply(obj, function(x) x[sample(nInd(x), 8, replace= TRUE)])
> MySamp8 <- lapply(MySamp8, function(x){ indNames(x) <- make.unique(indNames(x)); return(x)})
> repool(MySamp8)
>
>
> Here it is using a custom function:
>
> sample_genind_with_replacement <- function(x, n = 8){
> y <- x[sample(nInd(x), n, replace = TRUE)]
> indNames(y) <- make.unique(indNames(y))
> return(y)
> }
> MySamp8 <- lapply(obj, sample_genind_with_replacement, n = 8)
> repool(MySamp8)
>
>
> Best,
> Zhian
>
>> On Jan 19, 2017, at 07:50 , Bhuller, Ravneet <ravneet.bhuller13 at imperial.ac.uk> wrote:
>>
>> Dear Members,
>>
>> I am working with a genind object which is subset into populations. I want to sample 8 individuals randomly with replacement per population and repool them in a way that each population has unique individual names.
>>
>> I am doing the following steps:
>>
>> obj<- seppop(niger.data.genind)
>>
>> MySamp8 <- lapply(obj, function(x) x[sample(1:nrow(x$tab), 8, replace= TRUE)])
>>
>> new_samp8<- lapply(MySamp8, function(x) repool(MySamp8[make.unique(row.names(x$tab))]))
>>
>> But I am getting the following error:
>>
>> Error in repool(MySamp8[make.unique(row.names(x$tab))]): x is does not contain only valid genind objects.
>>
>> Please if any one can guide me how can I get valid genind objects to repool them in a way that each population has unique individual names.
>>
>> Many thanks for your time,
>>
>> Rav
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-genetics mailing list
>> R-sig-genetics at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-genetics
>
More information about the R-sig-genetics
mailing list