Using Bioconductor to Analyze your 23andme Data

Bioconductor is one of the open source projects of which I am most fond. The documentation is excellent, the community wonderful, the development fast-paced, and the software very well written.

There’s a new package in the development branch (due to be released as 2.10 very soon) called gwascat. gwascat is a package that serves as an interface to the NHGRI’s database of genome-wide association studies.

Loading the package with library(gwascat) creates a GRanges instance of SNPs and their diseases. GRanges is a fundamental data structure in Bioconductor (specifically the GenomicRanges package) that is designed to hold ranges on genomes efficiently, as well as metadata about the ranges. In this case, the object gwrngs holds SNP ranges (well, locations) and metadata provided by the GWA studies in NHGRI’s database.

While I really do like 23andme’s interface to one’s genotype information and research, the gwascat package offers some nice data mining power. I’ll briefly introduce it here, and perhaps add additional details later on.

23andme Raw Data

When I was considering 23andme, I ultimately persuaded by the fact that they release their raw genotype calls to users. Unfortunately they do so without SNP call confidence data, but in a personal correspondence with a 23andme representative they stated:

Data reproducibility of our genotyping platforms is estimated at about 99.9%. Average call rate is about 99%. When samples do not meet sufficient call rate thresholds, we repeat the analysis, and/or request a new sample. We do not return data to customers that does not meet our quality thresholds.

The 99.9% figure sounds like a lot, but considering there are 960,545 SNPs being called, it’s not that high.

To retrieve raw data, simply click the “Account” link at the top of the page (after you’ve signed in) and click “Browse Raw Data”. There should be a download link. If you’ve never used GPG to encrypt a file, now is the time to learn; keep your SNP data encrypted.

The file 23andme provides has four columns: rs ID, chromosome, position, and genotype.

Loading Raw Data into R

Use read.table to load this data in R. It’s a lot of data, so providing this function with information about the type of data can speed this up quite a bit. Here is the code I used:

You may notice that chromosome has the class “character” - this is because there are chromosomes X, Y, and MT (for mitochondrial). For later plotting purposes, it’s good to make this an ordered factor:

Where are the SNPs 23andme Genotypes?

Using Hadley Wickham’s excellent ggplot2 package, we can look at the distribution of SNPs by chromosome:

ggplot(d)+ geom_bar(aes(chrom))

This isn’t providing information on SNP density as much as it is chromosome length (except X). We’ll take a more detailed look a bit later.

Another really wonderful aspect of Bioconductor is that the project isn’t just a repository of code: it also stores annotation, full genomes, and experimental data. Such packaged data is the foundating of reproducible bioinformatics, as you no longer have to worry about keeping track of data versions and storing downloaded data yourself. If you need to work with cutting edge data from Ensembl or UCSC tracks, the packages biomaRt and rtracklayer work well.

A Quick Demonstration of GenomicRanges and Bioconductor Annotation Packages

Suppose I want to see if any of my SNPs fall in the APOE gene region. For this, I’ll need transcript annotation data. If I wished to create a fresh database of exon, gene, transcript, and splicing data, I could with the GenomicFeature package. This package has methods for building transcriptDb objects from the Known Gene track from UCSC, as well as Ensembl databases. However, I’ll just use a pre-packaged version, TxDb.Hsapiens.UCSC.hg18.knownGene. I use hg18 rather than hg19 because this is the build that 23andme’s coordinates reference.

Holy GRangeList batman! These are the transcripts grouped by gene. There are other methods for grouping by CDS and exons (cdsBy and exonsBy).

The names of the list elements are Entrez gene IDs. We can look up specific genes with another Bioconductor annotation package, org.Hs.eg.db. There are org.* annotation packages for many organisms. You can forge your own and interact with them with the AnnotationDbi package. I’m using a development version of this package that has a new slick SQL-like interface; it will be widely available with the upcoming 2.10 release.

Suppose I want to convert the Entrez Gene IDs to gene names. The “eg” in org.Hs.eg.db refers to Entrez Gene IDs. Printing the org.Hs.eg.db object gives a nice list of information. Let’s look for the APOE gene’s Entrez Gene ID.

If I had used tx.by.gene[348] the 348th element of the list would have been returned, not the transcript data for the APOE gene (which has Entrez Gene ID “348”).

Now, do any SNPs fall in this region? Let’s build a GRanges object from my genotyping data, and look for overlaps. Before I do, it’s worth mentioning another gotcha about working with bioinformatics data: chromosome naming schemes. Different databases use all sorts of schemes, and you should always check them. 23andme returns just numbers, X, Y, and MT. Let’s change it to use the same as the Bioconductor annotation.

# CAREFUL: use levels() to check that you're making new factor names# that correspond to the old ones!
levels(d$chrom)<- paste("chr", c(1:22,"X","Y","M"), sep="")
my.snps <- with(d, GRanges(seqnames=chrom,
IRanges(start=position, width=1),
rsid=rsid, genotype=genotype))# this goes into metadata

Now, let’s find overlaps using, well, findOverlaps:

apoe.i <- findOverlaps(tx.by.gene["348"], my.snps)

apoe.i is an object of class RangesMatching. Note that had we not matched chromosome names, Bioconductor gives us a nice warning that sequence names don’t match. We could look at the slots of apoe.i but output can be seen with matchMatrix:

Now, we can verify that these SNPs are in the APOE gene using the UCSC Genome Browser (and actually pull open a browser to this spot from R using rtracklayer, but I’ll save that for another time). Be sure to use hg18/build 36! Note that my genotype information is there.

The ApoE4 allele is rs429358(C) + rs7412(C). The most common allele (ApoE3, or e3/e3) is rs429358(T) + rs7412(C) which is what I have (that’s a relief). There’s a lot of established research that shows homozygous ApoE4 (that is rs429358(C/C) + rs7412(C/C)) leads to substantially higher risk of Alzeheimer’s. According to SNPedia, James Watson requested he not learn his genotype at this locus, and Steven Pinker requested his ApoE data be removed from his PGP10 data.

Looking for Risk Variants using gwascat

We can use the metadata provided by gwascat to further look for interesting variants in our 23andme data. I would recommend interpreting this data with caution, as summarizing these findings in a single element metadata data frame is hard: there’s definitely lost information.

The gwrngsGRanges object has lots of metadata you should scan through with elementMetadata(gwrngs). The Strongest.SNP.Risk.Allele is useful for seeing what you’re at risk for. First, using the rs ID as a key, let’s join our SNP data with the gwrngs metadata:

Now that you have this data frame, you can mine it endlessly. You may want to sort by Risk.Allele.Frequency and whether you have the risk. Because there are quite a few columns in the element metadata, it’s nice to define a quick-summary subset:

One interesting rs ID that popped up in this list of my data is rs10166942, which is lightly linked to migraines (from which I suffer).

Making Graphics with ggbio

ggbio is a new-ish (Bioconductor 2.9) package that produces really nice graphics. Let’s plot the location of all SNPs that gwascat tells me my allele is the “risk” allele (again, strange word choice as some “Disease.Traits” are height). gwascat uses hg19, and ggbio doesn’t have ideogram cytobanding and chromosome position information for hg18 bundled with it (yet?) so we’ll need to work with that.

library(ggbio)
p <- plotOverview(hg19IdeogramCyto, cytoband=FALSE)

Now, let’s take the gwrngs object and subset by my risk alleles. Notice how these assignment function elementMetadata<- is overloaded here: