Objects of class snpclone are used to hold variant data from high-throughput sequencing projects for analysis in poppr. The R package poppr was designed for the analysis of clonal or partially clonal populations. The snpclone extends the object of class genlight from the adegenet package. It therefore includes much of the functionality of the genlight object. Before you can analyze your snpclone object, you'll have to learn how to work with it. Here we explore how to work with objects of class snpclone.

Creation

The creation of snpclone objects is covered elsewhere. Here we use the pinfsc50 dataset read in as a VCF file and converted to an object of class snpclone.

# Load libraries
library(vcfR)
library(pinfsc50)
library(poppr)

# Determine file locations
vcf_file <- system.file("extdata", "pinf_sc50.vcf.gz",
                        package = "pinfsc50")

# Read data into memory
vcf <- read.vcfR(vcf_file, verbose = FALSE)

# Convert to genlight object
my.genlight <- vcfR2genlight(vcf)

# Convert to snpclone object
my.snpclone <- poppr::as.snpclone(my.genlight)
my.snpclone

The last command consists of the name of our snpclone object. This invokes the 'show' method for the class snpclone. The 'show' method summarizes the information contained in our object. Because the snpclone object 'extends' the genlight object, it also extends its methods. This is why the object declares itself to be a genlight object. It is indeed a genlight object, and more, as we'll see below. We'll see other 'methods' that act on objects of class snpclone throughout this document.

snpclone structure

The snpclone object is based on the genlight object. In programming terms the snpclone object 'extends' the genlight object. This means that it has everything the genlight object has and more. We can see that it extends the genlight class, as well as any othre classes, with the extends() function.

extends('snpclone')

This demonstrates that the snpclone class has superclass of genlight. This can also be seen with the selectSuperClasses() function.

selectSuperClasses('snpclone')

Knowing about superclasses is important when looking for documentation on a class. For example, the documentation for the snpclone class may only include documentation for its extensions to the genlight object. More information may be found in the documentation for the genlight class. But you need to know to look there before you can.

Objects of class snpclone contain data. This data is contained in 'slots' of the object. Before we can access or set any of the slots, we need to know what slots are available.

slotNames('snpclone')

Here we see the names of the available slots. Some of these are optional and not necessary. More detailed information can be found with ?snpclone.

The above information can also be summarized all at once with the getClassDef() function.

getClassDef("snpclone")

Note that many of these slots are optional and do not necessarily need to be populated. For example, the 'pop' slot only needs to be populated if methods that make population level summaries are desired.

snpclone Methods

Once you have your snpclone object, you'll want to begin to work with it. This typically means you'll need to learn the methods that act on an object. Objects of class snpclone include methods that act on ('show' and 'set') the slots. A first step in familiarizing yourself with these methods may be to query all of them.

methods(class='snpclone')

This displays methods associated with the snpclone class. Note that some methods include the assignment operator (method<-). This means you should be able to set the values of this slot. Slots that do not include the assignment operator are only available for viewing. For example, if we wanted to see the names of our samples we would query indNames().

indNames(my.snpclone)

If we want to change a name we can use the brackets to subset the data.

indNames(my.snpclone)[2] <- "DDR7602_us1"
indNames(my.snpclone)

Subsetting snpclone objects

Methods are also defined to help subset the snpclone object. A method that may have appeared odd above is the bracket ('['). Users familiar with R will recognize the brackets as a way to subset vectors as well as matrices and matrix-like objects. This allows the programmer to provide a familiar behaviour to the objects they create. Objects of class snpclone may be subset using the brackets where values before a comma represent rows (samples) and values after the comma represent columns (variants).

my.snpclone[1:4, 1:100]

Export from snpclone objects

There are a number of ways to export data from snpclone objects, and they are covered elsewhere. One of the simplest methods is to convert the data to a matrix. This also provides a way to validate your data was converted to a snpclone object correctly: if you get it in, you should be able to get it out.

x <- as.matrix(my.snpclone)
x[1:4, 1:6]

More information

Documentation on genlight and snpclone objects can be found in their respective 'man' pages.

?genlight
?snpclone

Information about the adegenet and poppr packages can also be found in their man pages.

?adegenet
package?poppr

More information on objects of class genlight can be found in the 'genomics' tutorial at the adegenet tutorials page. More information on adegenet can be found at the adegenet wiki.



knausb/vcfR_docs documentation built on May 20, 2019, 12:52 p.m.