[adegenet-forum] select loci with specific genotype in genind object
Jombart, Thibaut
t.jombart at imperial.ac.uk
Thu Apr 10 17:35:07 CEST 2014
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
http://sites.google.com/site/thibautjombart/
http://adegenet.r-forge.r-project.org/
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Sara Bonanomi [bonanomi.sara85 at gmail.com]
Sent: 10 April 2014 15:26
To: 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
More information about the adegenet-forum
mailing list