Transcription of Practical course using the software ||||| Introduction …
1 Practical course using thesoftware Introduction to genetic data analysis inThibaut Jombart AbstractThis Practical course is meant as a short Introduction to genetic dataanalysis using [10]. After describing the main types of data, we illus-trate how to perform some basic population genetics analyses, and then gothrough constructing trees from genetic distances and performing standardmultivariate analyses. The Practical uses mostly the packagesadegenet[6],ape[9] andade4[1, 3, 2], but others likegenetics[11] andhierfstat[5] arealso Let s Loading the packages .. How to get information? ..32 Handling the Data formats .. Importing / exporting data .. Manipulating data ..83 Basic population genetics94 Making Hierarchical clustering .. ape and phylogenies .. 135 Multivariate ade4 .. Principal Component Analysis (PCA) .. Principal Coordinates Analysis (PCoA).
2 1921 Let s Loading the packagesBefore going further, we shall make sure that all we need is installed on thecomputer. Launch, and make sure that the version being used is at by typing:> [1] "R version (2010-10-15)"The next thing to do is check that relevant packages are installed. To loadan installed package, use thelibraryinstruction; for instance:> library(adegenet)loadsadegenetif it is installed (and issues an error otherwise). To get theversion of a package, use:> packageDescription("adegenet", fields = "Version")[1] " "adegenetversion should read or case a package would not be installed, you can install it To install all the required dependencies, specifydep= instance, the following instruction should installadegenetwith all its de-pendencies (it can take up to a few minutes, so don t run it unlessadegenetis not installed):> ("adegenet", dep = TRUE) using the previous instructions, load (and install if required) the pack-agesadegenet,ade4,ape,genetics, How to get information?
3 There are several ways of getting information about R in general, or aboutadegenetin particular. The used to look for helpon a given topic. For instance:> ("Hardy-Weinberg")replies that there is a theadegenetpackage,other similar functions ingeneticsandpegas. To get help for a given func-tion, use?foowhere foo is the function of interest. For instance (quotescan be removed):>`?`(spca)3will open the manpage of the spatial principal component analysis [7]. Atthe end of a manpage, an example section often shows how to use a func-tion. This can be copied and pasted to the console, or directly executedfrom the console usingexample. For further questions concerning R, thefunctionRSiteSearchis a powerful tool to make an online research usingkeywords in R s archives (mailing lists and manpages).adegenethas a few extra documentation sources. Information can befound from the website ( ), inthe documents section, including two tutorials, a manual which includesall manpages of the package, and a dedicated mailing list with searchablearchives.
4 To open the website from, use:> adegenetWeb()The same can be done for tutorials, usingadegenetTutorial(see manpageto choose the tutorial to open).You will also find a listing of the main functions of the package typing:>`?`(adegenet)Note that you can also browse help pages as html pages, using :> ()To go to theadegenetpage, click packages , adegenet , and adegenet-package .Lastly, several mailing lists are available to find different kinds of infor-mation on R; to name a few:R-help ( ): general ques-tions about RR-sig-genetics ( ):genetics in Radegenet forum ( ): adegenet and multivariate analysis ofgenetic markers42 Handling the Data formatsTwo principal types of genetic data can be handled in R. The first one is(preferably aligned)DNA sequences, and the second one isgenetic sequences can be used to calibrate models of evolution and computegenetic distances, which can in turn be used for phylogenetic reconstructionor in multivariate analyses.
5 In, DNA sequences are best handled asDNAbinobjects, in theapepackage. See?DNAbinfor more details about thisclass. After loadingape, we load the datasetwoodmouse:> library(ape)> data(woodmouse)> woodmouse15 DNA sequences in binary format stored in a sequences of same length: 965 Labels: No305 No304 No306 No0906S No0908S No0909S ..Base composition:a c g ,unclassandattributesto explore the content of theDNAbinobject. Convert the dataset to a matrix of characters is the size of this new object ( )? Compare it to theoriginalDNAbinobject. Why is this class optimal for handling DNA se-quences? genetic markers are features of DNA sequences that vary between indi-viduals. There is not a single type of genetic marker: some are codominant(all alleles are visible), some are dominant (some alleles hide the presence ofothers); some have many alleles (like microsatellites), and others are most of-ten binary (like SNPs).
6 In general, codominant (more informative) markersare the rule, and dominant markers become more and more types of markers can be handled inusing the classgenindimplemented inadegenet. This class uses the S4 system of class definitionand methods, with whichusers are generally not familiar. Load thedataset nancycats:> library(adegenet)> data(nancycats)> nancycats######################## Genind object ########################- genotypes of individuals -5S4 class: genind@call: genind(tab = truenames(nancycats)$tab, pop = truenames(nancycats)$pop)@tab: 237 x 108 matrix of vector of 237 individual vector of 9 locus number of alleles per locus factor for the 108 columns of @ list of 9 components yielding allele names for each locus@ploidy: 2@type: codomOptionnal contents:@pop: factor giving the population of each factor giving the population of each individual@other: a list containing: xyUsually, the slots of S4 objects can be accessed by @ , which replaces the$ operator used in S3 classes ( in lists).
7 Forgenindobjects, both canbe used. Documentation of the class can be accessed by typing? genind-class . Usingnamesand @ (or $), browse the content ofnancycats; whatinformation is contained in this object?A more simple dataset can be used to understand how information iscoded. Here, we create a simple dataset with two diploid individuals (inrows), and two markers (columns).> dat <- (locus1 = c("A/T", "T/T"), locus2 = c("G/G",+ "C/G"))> datlocus1 locus21 A/T G/G2 T/T C/G> x <- df2genind(dat, sep = "/")> x######################## Genind object ########################- genotypes of individuals -S4 class: genind@call: df2genind(X = dat, sep = "/")@tab: 2 x 4 matrix of vector of 2 individual vector of 2 locus number of alleles per locus factor for the 4 columns of @ list of 2 components yielding allele names for each locus@ploidy: 2@type: codomOptionnal contents:@pop: - empty - empty -@other: - empty -Look at the @tab component of the genind object.
8 To extract this tablewith original labels, usetruenames. How is information stored? Does theEuclidean distance between the rows of this matrix make some biologicalsense? This is a canonical way of storing information for any dominantmarkers, irrespective of the degree of sometimes happens that analyses are performed at a population level,rather than at an individual level. In such cases,genpopobjects are objects contain allele numbers per populations rather than relativefrequencies, but are otherwise similar beobtained fromgenindobjects usinggenind2genpop. Use this function tocompute allele counts for the cat colonies of Nancy (datanancycats), andcompare the the structure of the obtained object to Importing / exporting dataDNA sequences with usual formats are read markers come in a wider variety of be used to import some of the most frequent, and less twisted , it is also possible to convert data from a to a genindusingdf2genind.
9 using the example above, create a with twotetraploid ( 4 alleles) individuals and two loci. Note that alleles can begiven any name, and do not need to be letters. Then, useddf2genindtoconvert it to agenindobject. Usetruenamesandgenind2dfto check thatthe data conversion has also happens that genetic markers are derived from DNA such a case, only sites that vary between individuals are retained; theseare called Single Nucleotide Polymorphism (SNPs). They can be extractedfromDNAbinobjects usingDNAbin2genind. Use this function to extract thepolymorphic sites from thewoodmousedataset. The locus names correspondto the position of the polymorphic site. Use this information to plot thedistribution of polymorphism along the DNA sequence; you should arrive atsomething along the lines of (usingdensitywith a width of 30) (x = x, width = 30)Position on DNA sequenceDensity of polymorphism (SNPs)|||||||||||||||||||||||||||||||||| ||||||||||||||||||||||What can we say about the distribution of SNPs on the DNA sequence?
10 Manipulating dataIt is often useful to be able to manipulate genetic marker data in differentways. There is no particular manipulation forDNAbinobjects, which areessentially matrices or benefit from different facilitiesfor manipulating data. First, the [ operator can be used to subset individualsand alleles; this is done like for a matrix, and is based on the @tab slot. Forinstance, to retain only the first 10 individuals of thenancycatsdataset,use:> nancycats[1:10, ]######################## Genind object ########################- genotypes of individuals -S4 class: genind@call: .local(x = x, i = i, j = j, drop = drop)@tab: 10 x 108 matrix of vector of 10 individual vector of 9 locus number of alleles per locus factor for the 108 columns of @ list of 9 components yielding allele names for each locus@ploidy: 2@type: codom8 Optionnal contents:@pop: factor giving the population of each factor giving the population of each individual@other: a list containing: xyData can be split by population usingseppop, and by locus of the population is obtained or set beused to gather the genotypes stored in differentgenindobjects into a singlegenind.]