[adegenet-forum] trouble accessing @other

Amaranta amaranta.fontcuberta at gmail.com
Thu Oct 25 20:11:12 CEST 2018


Hello,

Thanks a lot for your replies!

For this command, the trick with the "which" worked well.
I wanted to keep my @pop as the another variable with the Populations for
each sample. But the strata approach is very interesting if I do analyses
with multiple population groupings!

Thank you for the help, adegenet forum is great!

Amaranta.

Missatge de Zhian Kamvar <kamvarz at science.oregonstate.edu> del dia dj., 25
d’oct. 2018 a les 3:11:

> Just to pop in here: This looks like a situation that is best solved by
> using the strata slot.
>
> > I want to subset part of the individuals of my genlight object according
> > to a variable stored in the @other slot. I get an error I don't
> understand.
> > I stored 3 categorical variables in the @other slot. It looks like that:
> > *> str(other(asocial.gl <http://asocial.gl>))*
> > List of 3
> >  $ basin : Factor w/ 3 levels "Rhine","Rhone_Valais",..: NA 2 NA 2 2 2 2
> 2
> > 2 2 ...
> >  $ Sgeno : Factor w/ 3 levels "mm","mp","pp": 1 2 3 1 1 1 1 1 1 1 ...
> >  $ Spheno: Factor w/ 2 levels "M","P": 1 2 2 1 1 1 1 1 1 1 ...
>
> Since each element in the list is the same length, you can convert it to a
> data frame and use it as the population strata like so:
>
> strata(asocial.gl) <- data.frame(other(asocial.gl))
>
> When you do this, you can first set the population factor to be "basin"
> and then use adegenet's built-in population-subsetting to extract the
> Rhone_Valias population:
>
> setPop(ascocial.gl) <- ~basin # assigns the "basin" column from the
> strata to be the population factor (make sure you have the strata assigned
> first)
>
> asocial.gl[pop = "Rhone_Valias"] # includes only the individuals in
> Rhone_Valias
>
> Hope that helps!
> Zhian
>
> Date: Thu, 25 Oct 2018 12:33:45 +0100
>> From: Thibaut Jombart <thibautjombart at gmail.com>
>> To: amaranta.fontcuberta at unil.ch
>> Cc: "adegenet-forum at lists.r-forge.r-project.org"
>>         <adegenet-forum at lists.r-forge.r-project.org>
>> Subject: Re: [adegenet-forum] trouble accessing @other
>> Message-ID:
>>         <CANPRA+oJ_0Qa7zt2r=
>> hEw5M3U9+EOr6_Z94faryW0q+vHZntzw at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Hi there,
>>
>> I think the NA in your logical vector may be the problem; can you try
>> wrapping a 'which' around it?
>>
>> to_keep <- which(asocial.gl at other$basin=="Rhone_Valais")
>> asocial.gl[to_keep,]
>>
>> Let us know if it works.
>> Best
>> Thibaut
>>
>> --
>> Dr Thibaut Jombart
>> Associate Professor in Outbreak Analytics, London School of Hygiene and
>> Tropical Medicine
>> Senior Lecturer in Genetic Analysis, Imperial College London
>> President of RECON: repidemicsconsortium.org
>> https://thibautjombart.netlify.com
>> Twitter: @TeebzR
>>
>>
>> On Thu, 25 Oct 2018 at 00:43, Amaranta Fontcuberta <
>> amaranta.fontcuberta at unil.ch> wrote:
>>
>> > Hello,
>> >
>> > I want to subset part of the individuals of my genlight object according
>> > to a variable stored in the @other slot. I get an error I don't
>> understand.
>> > I stored 3 categorical variables in the @other slot. It looks like that:
>> > *> str(other(asocial.gl <http://asocial.gl>))*
>> > List of 3
>> >  $ basin : Factor w/ 3 levels "Rhine","Rhone_Valais",..: NA 2 NA 2 2 2
>> 2 2
>> > 2 2 ...
>> >  $ Sgeno : Factor w/ 3 levels "mm","mp","pp": 1 2 3 1 1 1 1 1 1 1 ...
>> >  $ Spheno: Factor w/ 2 levels "M","P": 1 2 2 1 1 1 1 1 1 1 ...
>> >
>> > When I try to subset my dataset, I get this error:
>> > *> asocial.gl <http://asocial.gl>[asocial.gl at other
>> $basin=="Rhone_Valais",]*
>> > Error in .local(x, i, j, ..., drop = drop) :
>> >   trying to get slot "n.loc" from an object of a basic class ("NULL")
>> with
>> > no slots
>> >
>> > The condition seems to work well, since when I call it alone, it
>> outputs a
>> > list of TRUE, FALSE that corresponds well to the individuals I want to
>> > keep.
>> > *> asocial.gl at other$basin=="Rhone_Valais"*
>> >   [1]    NA FALSE    NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>> >  TRUE  TRUE  TRUE
>> >  [15]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
>> >  TRUE  TRUE  TRUE
>> >  ...
>> >
>> > I use the same subseting command to select according to the @pop slot
>> and
>> > it works well.
>> >
>> >
>> > Any help will be appreciated,
>> >
>> > Thanks a lot in advance,
>> >
>> > Amaranta.
>> > ----------------------------------------------------------
>> > Amaranta Fontcuberta, assistante dipl?m?e
>> > Dept. ?cologie et ?volution
>> > Universit? de Lausanne
>> >
>> > _______________________________________________
>> > adegenet-forum mailing list
>> > adegenet-forum at lists.r-forge.r-project.org
>> >
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: <
>> http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20181025/e9b2eb30/attachment-0001.html
>> >
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> adegenet-forum mailing list
>> adegenet-forum at lists.r-forge.r-project.org
>>
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
>>
>> ------------------------------
>>
>> End of adegenet-forum Digest, Vol 122, Issue 5
>> **********************************************
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20181025/9516be65/attachment-0001.html>


More information about the adegenet-forum mailing list