[adegenet-forum] select loci with specific genotype in genind object

Jombart, Thibaut t.jombart at imperial.ac.uk
Mon Apr 14 17:01:23 CEST 2014


Forgot to Cc the forum...
________________________________________
From: Jombart, Thibaut
Sent: 14 April 2014 16:00
To: Sara Bonanomi
Subject: RE: [adegenet-forum] select loci with specific genotype in genind object

Hi again,

I have two more answers.

1) >is there a way to get loci with both alleleles 01 and 02 (in my case)?

Yes, using what I explained before. Just replace "01" by c("01","02").

2) >once I selected only the loci with allele "01", then I would get a genind object only with those loci.
>So first I did:
>a<-which(sapply(alleles(mydata), function(e) "01" %in% e))
>#then:
> newdata <-mydata[,a]

This can't work because "a" gives loci to keep, and the columns of "mydata" are not loci, but alleles.
One way to do it is use something like (see previous message):
##
posi <- grep("140",locNames(microbov, withAlleles=TRUE))
newdata <- microbov[,posi]
##

but this will keep only alleles, not entire loci. To keep loci use something along the lines of:

> mydata <- microbov
> a<-which(sapply(alleles(mydata), function(e) any(c("01","140") %in% e)))

> a
L15 L18 L25 L28
 15  18  25  28

> newdata <- mydata[loc=names(a)]

Cheers

Thibaut


________________________________________
From: Sara Bonanomi [bonanomi.sara85 at gmail.com]
Sent: 13 April 2014 17:31
To: Jombart, Thibaut
Subject: Re: [adegenet-forum] select loci with specific genotype in genind object

Hi again,

I have two more questions:

1) is there a way to get loci with both alleleles 01 and 02 (in my case)?
I want this combination because afterwards I want to assess which of these two alleles most highlight the originality of x pop using loadingplot...

2)once I selected only the loci with allele "01", then I would get a genind object only with those loci.
So first I did:

a<-which(sapply(alleles(mydata), function(e) "01" %in% e))

#then:

newdata <-mydata[,a]

but if I look: newdata$all.names  I can see loci with others alleles, while I should get only the loci with allele 01.  ???

Thank you,

Best regards

Sara










2014-04-13 10:38 GMT+02:00 Jombart, Thibaut <t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>>:
No worries!
________________________________________
From: Sara Bonanomi [bonanomi.sara85 at gmail.com<mailto:bonanomi.sara85 at gmail.com>]
Sent: 12 April 2014 14:56
To: Jombart, Thibaut
Subject: Re: [adegenet-forum] select loci with specific genotype in genind object

Thank you very much :-)




2014-04-10 17:35 GMT+02:00 Jombart, Thibaut <t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk><mailto:t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>>>:
Hello,

yes, there are a few functions that can be helpful here. Most of them are probably documented in the 'basics' tutorial:
- 'alleles' to pull the lists of alleles for each locus
- 'locNames' to pull the locus names, with an option to get alleles too
- seploc which allows for separating loci
- []: which you can use to isolate specific loci

Example using some of these:

> data(microbov)

## list alleles per locus (just first 3)
> alleles(microbov)[1:3]
$L01
    1     2     3     4     5     6     7     8     9
"167" "171" "173" "175" "177" "179" "181" "183" "185"

$L02
    1     2     3     4     5     6     7
"137" "139" "141" "143" "145" "147" "149"

$L03
   01    02    03    04    05    06    07    08    09    10    11    12
"137" "139" "141" "143" "145" "147" "149" "151" "153" "155" "157" "159"


## to get loci having e.g. alleles 140:
## (TRUE = this locus has an allele "140")
> sapply(alleles(microbov), function(e) "140" %in% e)
  L01   L02   L03   L04   L05   L06   L07   L08   L09   L10   L11   L12   L13
FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
  L14   L15   L16   L17   L18   L19   L20   L21   L22   L23   L24   L25   L26
FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
  L27   L28   L29   L30
FALSE  TRUE FALSE FALSE

## which loci are these?
> which(sapply(alleles(microbov), function(e) "140" %in% e))
L15 L18 L25 L28
 15  18  25  28

## if you want to get the position of the alleles "140" across all loci:
## this is a vector of all allele names (locus.allele)
> head(locNames(microbov, withAlleles=TRUE))
[1] "INRA63.167" "INRA63.171" "INRA63.173" "INRA63.175" "INRA63.177"
[6] "INRA63.179"

## position of those having an allele 140:
> grep("140",locNames(microbov, withAlleles=TRUE))
[1] 161 200 289 324

## there full names:
> posi <- grep("140",locNames(microbov, withAlleles=TRUE))
> locNames(microbov, withAlleles=TRUE)[posi]
[1] "BM2113.140"  "INRA37.140"  "HAUT27.140"  "TGLA122.140"


You can use this type of subsetting to isolate specific contributions.

Best
Thibaut

--
######################################
Dr Thibaut JOMBART
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - School of Public Health
St Mary’s Campus
Norfolk Place
London W2 1PG
United Kingdom
Tel. : 0044 (0)20 7594 3658
t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk><mailto:t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>>
http://sites.google.com/site/thibautjombart/
http://adegenet.r-forge.r-project.org/
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org><mailto: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><mailto:adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org>>] on behalf of Sara Bonanomi [bonanomi.sara85 at gmail.com<mailto:bonanomi.sara85 at gmail.com><mailto:bonanomi.sara85 at gmail.com<mailto:bonanomi.sara85 at gmail.com>>]
Sent: 10 April 2014 15:26
To: adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org><mailto:adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org>>
Subject: [adegenet-forum] select loci with specific genotype in genind object

Hi all,


In my genind object I would like to select only the loci with a certain genotype (e.g. 0102). Then I wanna check the allele contribution ($var.contr).

 If I digit: mygenindobject$all.names I get a list with xx components yielding allele names for each locus.

For instance:



$L262

   1    2

"01" "02"



Then, to get the loci only the loci with a certain genotype (e.g. 0102) , I have tried with the subset function: selectLoci<-subset(mydata$all.names, 1=="01" & 2=="02", select=c(1,2)) But then I get: named list ()

 Is there a specific function in adegenet to subset the data? Could you please help me?


Thank you very much,


Best


Jasmine



--
Sara Bonanomi
PhD Student
DTU Aqua

Technical University of Denmark<http://www.dtu.dk/english.aspx>
National Institute <http://www.aqua.dtu.dk/> of Aquatic Resources<http://www.aqua.dtu.dk/>
Vejlsøvej 39 8600 Silkeborg
Alternative email: sarb at aqua.dtu.dk<mailto:sarb at aqua.dtu.dk><mailto:sofer at aqua.dtu.dk<mailto:sofer at aqua.dtu.dk>>
Mobile: +45 52 73 54 58<tel:%2B45%2052%2073%2054%2058>[X]+45 52 73 54 58
Call
Send SMS
Add to Skype
You'll need Skype CreditFree via Skype



--
Sara Bonanomi
PhD Student
DTU Aqua

Technical University of Denmark<http://www.dtu.dk/english.aspx>
National Institute <http://www.aqua.dtu.dk/> of Aquatic Resources<http://www.aqua.dtu.dk/>
Vejlsøvej 39 8600 Silkeborg
Alternative email: sarb at aqua.dtu.dk<mailto:sofer at aqua.dtu.dk>
Mobile: +45 52 73 54 58[X]+45 52 73 54 58
Call
Send SMS
Add to Skype
You'll need Skype CreditFree via Skype


More information about the adegenet-forum mailing list