From bonanomi.sara85 at gmail.com Thu Apr 10 16:26:18 2014 From: bonanomi.sara85 at gmail.com (Sara Bonanomi) Date: Thu, 10 Apr 2014 16:26:18 +0200 Subject: [adegenet-forum] select loci with specific genotype in genind object Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From t.jombart at imperial.ac.uk Thu Apr 10 17:35:07 2014 From: t.jombart at imperial.ac.uk (Jombart, Thibaut) Date: Thu, 10 Apr 2014 15:35:07 +0000 Subject: [adegenet-forum] select loci with specific genotype in genind object In-Reply-To: References: Message-ID: <2CB2DA8E426F3541AB1907F98ABA657075F7EDA4@icexch-m1.ic.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 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 From bonanomi.sara85 at gmail.com Sun Apr 13 18:32:53 2014 From: bonanomi.sara85 at gmail.com (Sara Bonanomi) Date: Sun, 13 Apr 2014 18:32:53 +0200 Subject: [adegenet-forum] adegenet-forum Digest, Vol 68, Issue 1 In-Reply-To: References: Message-ID: 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-11 12:00 GMT+02:00 < adegenet-forum-request at lists.r-forge.r-project.org>: > Send adegenet-forum mailing list submissions to > adegenet-forum at lists.r-forge.r-project.org > > To subscribe or unsubscribe via the World Wide Web, visit > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum > > or, via email, send a message with subject or body 'help' to > adegenet-forum-request at lists.r-forge.r-project.org > > You can reach the person managing the list at > adegenet-forum-owner at lists.r-forge.r-project.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of adegenet-forum digest..." > > > Today's Topics: > > 1. select loci with specific genotype in genind object > (Sara Bonanomi) > 2. Re: select loci with specific genotype in genind object > (Jombart, Thibaut) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 10 Apr 2014 16:26:18 +0200 > From: Sara Bonanomi > To: adegenet-forum at lists.r-forge.r-project.org > Subject: [adegenet-forum] select loci with specific genotype in genind > object > Message-ID: > V+RLTCf7S7uqd3B9PncSGY7xbZw at mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > 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 > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20140410/c8bb71b3/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Thu, 10 Apr 2014 15:35:07 +0000 > From: "Jombart, Thibaut" > To: Sara Bonanomi , > "adegenet-forum at lists.r-forge.r-project.org" > > Subject: Re: [adegenet-forum] select loci with specific genotype in > genind object > Message-ID: > <2CB2DA8E426F3541AB1907F98ABA657075F7EDA4 at icexch-m1.ic.ac.uk> > Content-Type: text/plain; charset="Windows-1252" > > 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 > > > ------------------------------ > > _______________________________________________ > 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 68, Issue 1 > ********************************************* > -- *Sara Bonanomi*PhD Student DTU Aqua Technical University of Denmark National Institute *o**f* Aquatic Resources Vejls?vej 39 8600 Silkeborg Alternative email: sarb at aqua.dtu.dk Mobile: +45 52 73 54 58+45 52 73 54 58 Call Send SMS Add to Skype You'll need Skype CreditFree via Skype -------------- next part -------------- An HTML attachment was scrubbed... URL: From t.jombart at imperial.ac.uk Mon Apr 14 17:01:23 2014 From: t.jombart at imperial.ac.uk (Jombart, Thibaut) Date: Mon, 14 Apr 2014 15:01:23 +0000 Subject: [adegenet-forum] select loci with specific genotype in genind object In-Reply-To: <2CB2DA8E426F3541AB1907F98ABA657087BC618C@icexch-m1.ic.ac.uk> References: <2CB2DA8E426F3541AB1907F98ABA657075F7EDA4@icexch-m1.ic.ac.uk> <2CB2DA8E426F3541AB1907F98ABA657075F7F4E1@icexch-m1.ic.ac.uk>, , <2CB2DA8E426F3541AB1907F98ABA657087BC618C@icexch-m1.ic.ac.uk> Message-ID: <2CB2DA8E426F3541AB1907F98ABA657087BC619C@icexch-m1.ic.ac.uk> 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 >: No worries! ________________________________________ From: Sara Bonanomi [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 >>: 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 -- Sara Bonanomi PhD Student DTU Aqua Technical University of Denmark National Institute of Aquatic Resources Vejls?vej 39 8600 Silkeborg Alternative email: sarb 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 -- Sara Bonanomi PhD Student DTU Aqua Technical University of Denmark National Institute of Aquatic Resources Vejls?vej 39 8600 Silkeborg Alternative email: sarb 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