<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/genome-wide-association-studies-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/"> poissonisfish</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<figure data-shortcode="caption" class="wp-caption"><img data-orig-file="https://poissonisfish.files.wordpress.com/2017/10/maxresdefault.jpg?w=456" data-orig-size="1920,1080" data-medium-file="https://poissonisfish.files.wordpress.com/2017/10/maxresdefault.jpg?w=456?w=300" data-attachment-id="4185" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2017/10/maxresdefault.jpg?w=456" data-permalink="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/maxresdefault/" data-large-file="https://poissonisfish.files.wordpress.com/2017/10/maxresdefault.jpg?w=456?w=1024" alt="maxresdefault" data-image-title="maxresdefault" sizes="(max-width: 1108px) 100vw, 1108px" data-comments-opened="1" class="wp-image-4185" data-recalc-dims="1"><br>
<figcaption class="wp-caption-text">’10 High Cholesterol Foods You Must Avoid’. From: https://www.youtube.com/watch?v=RKZ1Wk8tIZo</figcaption>
</figure>
<p>This time I elaborate on a much more specific subject that will mostly concern biologists and geneticists. I will try my best to outline the approach as to ensure non-experts will still have a basic understanding. This tutorial illustrates the power of genome-wide association (GWA) studies by mapping the genetic determinants of cholesterol levels using three Southeast Asian populations.</p>
<h2>Historical background</h2>
<p>Early since Charles Darwin formulated the theories of natural and sexual selection in the late 1800s, the underlying role of genes, each represented by different alleles (i.e. variants) in different individuals was yet to be elucidated. His younger contemporary fellow Gregor Mendel scratched the surface after identifying the mechanism of trait inheritance, genetic segregation. In the years that followed, the genetic basis of phenotypes (i.e. observable traits) was gradually unraveled by classic geneticists pioneered by Ronald Fisher, who introduced key concepts such as genetic variance. The then emerging concept of genotype (i.e. genetic make-up) required the development of polymorphic genetic markers. In the early days, genotyping was based on determining the allelic composition of loci (loose definition of chromosomal regions), and later of copy number variations (CNVs), short-tandem repeats (STRs) and single nucleotide polymorphisms (SNPs). Humans and many other organisms including plants are diploid (i.e. carry two copies of each chromosome), which implies bi-allelic markers with alleles e.g. <em>A</em> and <em>a</em> distinguish individuals into <em>AA</em> (homozygous dominant), <em>Aa</em> (heterozygous) and <em>aa</em> (homozygous recessive).</p>
<p>The early discovery of the genetic basis for disorders such as sickle cell anemia and haemophilia owes much to their relatively simple genetic architectures – few mutations with high penetrance, thus more easily identified. Understandably then, more complex polygenic diseases that have been around for a long time, such as the neurodegenerative Alzheimer and Parkinson, are still currently under investigation. To characterize such traits, products of the interplay of many genes with small effects, it takes large genetic resources as well as flexible statistical methods, which is no problem in the current era of omics data and high-performance computing.</p>
<h2>Genome-wide association studies</h2>
<p>Genome-wide association (GWA) studies scan an entire species genome for association between up to millions of SNPs and a given trait of interest. Notably, the trait of interest can be virtually any sort of phenotype ascribed to the population, be it qualitative (e.g. disease status) or quantitative (e.g. height). Essentially, given <em>p</em> SNPs and <em>n</em> samples or individuals, a GWA analysis will fit <em>p </em>independent<em> </em>univariate<em> </em>linear models, each based on <em>n</em> samples, using the genotype of each SNP as predictor of the trait of interest. The significance of association (<em>P</em>-value) in each of the <em>p</em> tests is determined from the coefficient estimate <img alt="beta " title="beta " src="https://s0.wp.com/latex.php?latex=%5Cbeta+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> of the corresponding SNP (technically speaking, the significance of association is <img alt="P(beta|H_0: beta=0) " title="P(beta|H_0: beta=0) " src="https://s0.wp.com/latex.php?latex=P%28%5Cbeta%7CH_0%3A+%5Cbeta%3D0%29+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">). Note that because these tests are independent and quite numerous, there is a great computational advantage in setting up a parallelized GWA analysis (as we will do shortly). Quite reasonably, it is necessary to adjust the resulting <em>P-</em>values using multiple hypothesis testing methods such as Bonferroni, Benjamini-Hochberg or false discovery rate (FDR). GWA studies are now commonplace in genetics of many different species.</p>
<h2>Association mapping vs. linkage mapping</h2>
<p>Too often, people cannot tell the difference between association and linkage mapping, or quantitative trait loci (QTL) mapping. Albeit conceptually similar, their are actually opposite in their workings. One of the key differences between the two is that association mapping relies on high-density SNP genotyping of unrelated individuals, whereas linkage mapping relies on the segregation of substantially fewer markers in controlled breeding experiments – unsurprisingly QTL mapping is seldom conducted in humans. Importantly, association mapping gives you point associations in the genome, whereas linkage mapping gives you QTL, chromosomal regions.</p>
<p>The present tutorial covers fundamental aspects to consider when conducting GWA analysis, from the pre-processing of genotype and phenotype data to the interpretation of results. We will use a mixed population of 316 Chinese, Indian and Malay that was recently characterized using high-throughput SNP-chip sequencing, transcriptomics and lipidomics (<a rel="nofollow" href="https://www.nature.com/articles/s41467-017-00413-x" target="_blank">Saw et al., 2017</a>). More specifically, we will search for associations between the >2.5 million SNP markers and cholesterol levels. Finally, we will explore the vicinity of candidate SNPs using the USCS Genome Browser in order to gain functional insights. The methodology shown here is largely based on the tutorial outlined in <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a>. The R scripts and some of the data can be found in my <a rel="nofollow" href="https://github.com/monogenea/GWAStutorial" target="_blank">repository</a>, but you will still need to download the omics data from <a rel="nofollow" href="http://phg.nus.edu.sg/StatGen/public_html/Iomics/downloads/iOmics_data.tar.gz" target="_blank">here</a>. Please follow the instructions in the repo.</p>
<h1>Let’s get started with R</h1>
<h2>Read data</h2>
<p>Let’s first import the PLINK-converted .bed, .fam and .bim Illumina files from each of the three ethnic groups. We will use the function <strong>read.plink</strong> from the package <strong>snpStats</strong> and work on the resulting objects throughout the rest of the tutorial. This function reads .bed, .fam and .bim and creates a list of three elements – <strong>$genotypes</strong>, <strong>$fam</strong> and <strong>$map</strong>. The first contains all SNPs determined from all samples, the second contains information about pedigree and sex, and the third contains the genomic coordinates of the SNPs. At this point we have a total of 323 individuals (110 Chinese, 105 Indian and 108 Malay) and 2,527,458 SNPs. Next, we will change the Illumina SNP IDs stored in <strong>$genotype</strong> to the more conventional rs IDs, which will allow us to zoom in into the genomic regions that surround the candidate SNPs in the USCS Genome Browser. I prepared a table that establishes the correspondence between the two, so that we can easily switch the IDs.</p>
<pre>
library(snpStats)
load(&quot;conversionTable.RData&quot;)

pathM &lt;- paste(&quot;Genomics/108Malay_2527458snps&quot;, c(&quot;.bed&quot;, &quot;.bim&quot;, &quot;.fam&quot;), sep = &quot;&quot;)
SNP_M &lt;- read.plink(pathM[1], pathM[2], pathM[3])

pathI &lt;- paste(&quot;Genomics/105Indian_2527458snps&quot;, c(&quot;.bed&quot;, &quot;.bim&quot;, &quot;.fam&quot;), sep = &quot;&quot;)
SNP_I &lt;- read.plink(pathI[1], pathI[2], pathI[3])

pathC &lt;- paste(&quot;Genomics/110Chinese_2527458snps&quot;, c(&quot;.bed&quot;, &quot;.bim&quot;, &quot;.fam&quot;), sep = &quot;&quot;)
SNP_C &lt;- read.plink(pathC[1], pathC[2], pathC[3])

# Merge the three SNP datasets
SNP &lt;- rbind(SNP_M$genotypes, SNP_I$genotypes, SNP_C$genotypes)

# Take one bim map (all 3 maps are based on the same ordered set of SNPs)
map &lt;- SNP_M$map
colnames(map) &lt;- c(&quot;chr&quot;, &quot;SNP&quot;, &quot;gen.dist&quot;, &quot;position&quot;, &quot;A1&quot;, &quot;A2&quot;)

# Rename SNPs present in the conversion table into rs IDs
mappedSNPs &lt;- intersect(map$SNP, names(conversionTable))
newIDs &lt;- conversionTable[match(map$SNP[map$SNP %in% mappedSNPs], names(conversionTable))]
map$SNP[rownames(map) %in% mappedSNPs] &lt;- newIDs
</pre>
<p>Next we import and merge the three lipid data sets (stored as .txt) and determine which samples are present in both SNP and lipid data sets. In the following analyses we will use the subset of samples profiled in both platforms, a total of 319. Finally, we create a list <strong>genData</strong> that stores the merged SNP data (<strong>$SNP</strong>), one of the three <strong>$map</strong> since they are all identical (<strong>$MAP</strong>) and the merged lipid data (<strong>$LIP</strong>). Finally, let’s save RAM for the subsequent steps and remove all files after saving <strong>genData</strong> into a <strong>.RData</strong> file.</p>
<pre>
# Load lipid datasets &amp; match SNP-Lipidomics samples
lipidsMalay &lt;- read.delim(&quot;Lipidomic/117Malay_282lipids.txt&quot;, row.names = 1)
lipidsIndian &lt;- read.delim(&quot;Lipidomic/120Indian_282lipids.txt&quot;, row.names = 1)
lipidsChinese &lt;- read.delim(&quot;Lipidomic/122Chinese_282lipids.txt&quot;, row.names = 1)
all(Reduce(intersect, list(colnames(lipidsMalay),
colnames(lipidsIndian),
colnames(lipidsChinese))) == colnames(lipidsMalay)) # TRUE
lip &lt;- rbind(lipidsMalay, lipidsIndian, lipidsChinese)

matchingSamples &lt;- intersect(rownames(lip), rownames(SNP))
SNP &lt;- SNP[matchingSamples,]
lip &lt;- lip[matchingSamples,]

genData &lt;- list(SNP = SNP, MAP = map, LIP = lip)
save(genData, file = &quot;PhenoGenoMap.RData&quot;)

# Clear memory
rm(list = ls())
</pre>
<h2>Pre-processing</h2>
<p>Let’s reload <strong>genData</strong> and clean it up. In a nutshell, the pre-processing of the data consists in</p>
<ul>
<li>discarding SNPs with call rate<strong> </strong>&lt; 1  or  MAF &lt; 0.1</li>
<li>discarding samples with call rate &lt; 100%, IBD kinship coefficient > 0.1 or inbreeding coefficient |<em>F</em>| > 0.1</li>
</ul>
<p>Call rate is the proportion of SNPs (or samples) that were genotyped. For example, a call rate of 0.95 for a particular SNP (sample) means 5% of the values are missing. Because we have so many SNPs, we can afford to have absolutely no missing values in the <strong>$SNP</strong> matrix by imposing a call rate threshold of 1 for both SNPs and samples. If you want to relax the threshold and tolerate missing values, bear in mind you need to run a whole procedure for imputing those. <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a> describe a PCA-based imputation method that utilizes the 1,000 Genome Project as a proxy, in case you are interested.</p>
<p>Minor-allele frequency (MAF) denotes the proportion of the least common allele for each SNP. Of course, it is harder to detect associations with rare variants and this is why we select against low MAF values. Most GWA studies I have read typically report MAF thresholds of 0.05. Here, I opt for a more stringent 0.1 because again, we have plenty of data and since all this is for illustrative purposes we want to conduct a fast GWA analysis.</p>
<pre>
library(snpStats)
library(doParallel)
library(SNPRelate)
library(GenABEL)
library(dplyr)
source(&quot;GWASfunction.R&quot;)
load(&quot;PhenoGenoMap.RData&quot;)

# Use SNP call rate of 100%, MAF of 0.1 (very stringent)
maf &lt;- 0.1
callRate &lt;- 1
SNPstats &lt;- col.summary(genData$SNP)

maf_call &lt;- with(SNPstats, MAF > maf &amp; Call.rate == callRate)
genData$SNP &lt;- genData$SNP[,maf_call]
genData$MAP &lt;- genData$MAP[maf_call,]
SNPstats &lt;- SNPstats[maf_call,]
</pre>
<p>Next, we need to consider samples that exhibit excessive heterozygosity – technically speaking, deviations from the Hardy-Weinberg equilibrium (HWE),</p>
<p><img alt="p^2 + 2pq + q^2 = 1 " title="p^2 + 2pq + q^2 = 1 " src="https://s0.wp.com/latex.php?latex=p%5E2+%2B+2pq+%2B+q%5E2+%3D+1+&bg=f9f9f9&%23038;fg=555555&%23038;s=2" class="latex"></p>
<p>where <img alt="p " title="p " src="https://s0.wp.com/latex.php?latex=p+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> and <img alt="q " title="q " src="https://s0.wp.com/latex.php?latex=q+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> are the frequencies of two alleles <em>A</em> and <em>a</em> that sum up to one, and <img alt="2pq " title="2pq " src="https://s0.wp.com/latex.php?latex=2pq+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> the frequency of heterozygous individuals, assuming bi-allelic SNPs. As such, we determine the inbreeding coefficient |<em>F|,</em></p>
<p><img alt="|F| = 1 - frac{H}{2pq} " title="|F| = 1 - frac{H}{2pq} " src="https://s0.wp.com/latex.php?latex=%7CF%7C+%3D+1+-+%5Cfrac%7BH%7D%7B2pq%7D+&bg=f9f9f9&%23038;fg=555555&%23038;s=2" class="latex"></p>
<p>where <em>H </em>and <img alt="2pq " title="2pq " src="https://s0.wp.com/latex.php?latex=2pq+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> are the observed and expected heterozygosity (i.e. proportion of heterozygous SNPs per sample), respectively. You will note that in practice, rather than using the proportions we will use counts which still gives us the same results. Overall, large and small |<em>F</em>| might indicate poor sample quality or inbreeding, respectively. We will exclude samples with |<em>F</em>|> 0.1 as described in <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a>.</p>
<pre>
# Sample call rate &amp; heterozygosity
callMat &lt;- !is.na(genData$SNP)
Sampstats &lt;- row.summary(genData$SNP)
hetExp &lt;- callMat %*% (2 * SNPstats$MAF * (1 - SNPstats$MAF)) # Hardy-Weinberg heterozygosity (expected)
hetObs &lt;- with(Sampstats, Heterozygosity * (ncol(genData$SNP)) * Call.rate)
Sampstats$hetF &lt;- 1-(hetObs/hetExp)
# Use sample call rate of 100%, het threshold of 0.1 (very stringent)
het &lt;- 0.1 # Set cutoff for inbreeding coefficient;
het_call &lt;- with(Sampstats, abs(hetF) &lt; het &amp; Call.rate == 1)
genData$SNP &lt;- genData$SNP[het_call,]
genData$LIP &lt;- genData$LIP[het_call,]
</pre>
<p>Finally, we will investigate relatedness among samples using the kinship coefficient based on identity by descent (IBD). Please note that these functions from the package <strong>SNPRelate </strong>require GDS files. For this reason we first need to aggregate the .bed, .fam and .bim files from the three populations into <strong>convertGDS</strong>. The function <strong>snpgdsBED2GDS2 </strong>creates the GDS necessary for this part of the analysis. To determine the kinship coefficient between pairs of samples we will use a subset of uncorrelated SNPs in order to have unbiased estimates. For this purpose, we will use linkage disequilibrium (LD) as a measure of correlation between markers. LD ranges from 0 to 1, the higher its value the more likely two SNPs co-segregate and therefore correlate. Here, we will utilize the subset of SNPs with LD &lt; 0.2 (<em>p</em> ~ 12,000) to determine the IBD kinship coefficient. It took me about 2 hours to calculate the LD with the function <strong>snpgdsLDpruning</strong>, so be patient. Next, following <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a>, we will exclude all samples with kinship coefficients > 0.1.</p>
<pre>
# LD and kinship coeff
ld &lt;- .2
kin &lt;- .1
snpgdsBED2GDS(bed.fn = &quot;convertGDS.bed&quot;, bim.fn = &quot;convertGDS.bim&quot;,
fam.fn = &quot;convertGDS.fam&quot;, out.gdsfn = &quot;myGDS&quot;, cvt.chr = &quot;char&quot;)
genofile &lt;- snpgdsOpen(&quot;myGDS&quot;, readonly = F)
gds.ids &lt;- read.gdsn(index.gdsn(genofile, &quot;sample.id&quot;))
gds.ids &lt;- sub(&quot;-1&quot;, &quot;&quot;, gds.ids)
add.gdsn(genofile, &quot;sample.id&quot;, gds.ids, replace = T)
geno.sample.ids &lt;- rownames(genData$SNP)
# First filter for LD
snpSUB &lt;- snpgdsLDpruning(genofile, ld.threshold = ld,
sample.id = geno.sample.ids,
snp.id = colnames(genData$SNP))
snpset.ibd &lt;- unlist(snpSUB, use.names = F)
# And now filter for MoM
ibd &lt;- snpgdsIBDMoM(genofile, kinship = T,
sample.id = geno.sample.ids,
snp.id = snpset.ibd,
num.thread = 1)
ibdcoef &lt;- snpgdsIBDSelection(ibd)
ibdcoef &lt;- ibdcoef[ibdcoef$kinship >= kin,]

# Filter samples out
related.samples &lt;- NULL
while (nrow(ibdcoef) > 0) {
# count the number of occurrences of each and take the top one
sample.counts &lt;- arrange(count(c(ibdcoef$ID1, ibdcoef$ID2)), -freq)
rm.sample &lt;- sample.counts[1, 'x']
cat(&quot;Removing sample&quot;, as.character(rm.sample), 'too closely related to', sample.counts[1, 'freq'],'other samples.\n')

# remove from ibdcoef and add to list
ibdcoef &lt;- ibdcoef[ibdcoef$ID1 != rm.sample &amp; ibdcoef$ID2 != rm.sample,]
related.samples &lt;- c(as.character(rm.sample), related.samples)
}
genData$SNP &lt;- genData$SNP[!(rownames(genData$SNP) %in% related.samples),]
genData$LIP &lt;- genData$LIP[!(rownames(genData$LIP) %in% related.samples),]
</pre>
<p>After pre-processing, we are left with 316 samples (110 Chinese, 100 Indian and 106 Malay) characterised by 795,668 SNP markers and 282 lipid species. Note that your sample size might differ slightly as the LD pruning procedure is stochastic.</p>
<h2>Analysis</h2>
<h3>Principal Component Analysis</h3>
<p>Now that we are done with the pre-processing, it might be a good idea to examine the largest sources of variation in the genotype data and look out for outliers or clustering patterns, using <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/01/23/principal-component-analysis-in-r/" target="_blank">Principal Component Analysis (PCA)</a>. Because we are working with S4 objects, we will be using the PCA function from <strong>SNPRelate</strong>, <strong>snpgdsPCA</strong>. Let’s plot the first two principal components (PCs).</p>
<pre>
# PCA
pca &lt;- snpgdsPCA(genofile, sample.id = geno.sample.ids, snp.id = snpset.ibd, num.thread = 1)
pctab &lt;- data.frame(sample.id = pca$sample.id,
PC1 = pca$eigenvect[,1],
PC2 = pca$eigenvect[,2],
stringsAsFactors = F)

origin &lt;- read.delim(&quot;countryOrigin.txt&quot;, sep = &quot;\t&quot;)
origin &lt;- origin[match(pca$sample.id, origin$sample.id),]

pcaCol &lt;- rep(rgb(0,0,0,.3), length(pca$sample.id)) # Set black for chinese
pcaCol[origin$Country == &quot;I&quot;] &lt;- rgb(1,0,0,.3) # red for indian
pcaCol[origin$Country == &quot;M&quot;] &lt;- rgb(0,.7,0,.3) # green for malay

png(&quot;PCApopulation.png&quot;, width = 500, height = 500)
plot(pctab$PC1, pctab$PC2, xlab = &quot;PC1&quot;, ylab = &quot;PC2&quot;, col = pcaCol, pch = 16)
abline(h = 0, v = 0, lty = 2, col = &quot;grey&quot;)
legend(&quot;top&quot;, legend = c(&quot;Chinese&quot;, &quot;Indian&quot;, &quot;Malay&quot;), col = 1:3, pch = 16, bty = &quot;n&quot;)
dev.off()
</pre>
<h2><img data-orig-file="https://poissonisfish.files.wordpress.com/2017/10/pcapopulation1.png?w=456" data-orig-size="500,500" data-medium-file="https://poissonisfish.files.wordpress.com/2017/10/pcapopulation1.png?w=456?w=300" data-attachment-id="3242" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2017/10/pcapopulation1.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/pcapopulation/" data-large-file="https://poissonisfish.files.wordpress.com/2017/10/pcapopulation1.png?w=456?w=500" alt="PCApopulation" data-image-title="PCApopulation" sizes="(max-width: 500px) 100vw, 500px" data-comments-opened="1" class="wp-image-3242" data-recalc-dims="1"></h2>
<p>As expected, the 795,668 SNP markers clearly delineate the three populations. The results also suggest that Chinese and Malay are closer to each other than to Indian (this observation would be much better addressed with e.g. hierarchical clustering). Also, no obvious outliers are identified with the first two PCs. All good to proceed to GWA.</p>
<h3>Genome-Wide Association</h3>
<p>Finally, the <span>pièce de résistance</span>. From the set of 282 lipids species I chose cholesterol, one of the most familiar, as the trait of interest. You are completely free to select a different lipid species and proceed. We are going to use the GWA function provided in <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a> with some minor modifications. I recommend you to open the script <strong>GWASfunction.R</strong>  and skim through. This is an excellent, well documented parallelized implementation. Note that the <strong>glm </strong>function is used to determine the significance of association between each SNP and the trait of interest. In case you are wondering, <strong>glm</strong> is much more versatile than <strong>lm</strong> since it conducts Gaussian, Poisson, binomial and multinomial regression / classification, depending on how your trait of interest is distributed (all lipids in the phenotype file are Gaussian). This GWA function will not create a variable, but rather write a .txt summary table listing the coefficient estimate <img alt="beta " title="beta " src="https://s0.wp.com/latex.php?latex=%5Cbeta+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">, <em>t</em> and the corresponding <em>P</em>-value for each SNP, alongside with the corresponding genomic coordinates. Running the GWA function took me approximately 1.5 hours with my MacBook Pro mid-2012 (8Gb, 2.9 GHz Intel Core i7).</p>
<pre>
# Choose trait for association analysis, use colnames(genData$LIP) for listing
# NOTE: Ignore the first column of genData$LIP (gender)
target &lt;- &quot;Cholesterol&quot;

phenodata &lt;- data.frame(&quot;id&quot; = rownames(genData$LIP),
&quot;phenotype&quot; = scale(genData$LIP[,target]), stringsAsFactors = F)

# Conduct GWAS (will take a while)
start &lt;- Sys.time()
GWAA(genodata = genData$SNP, phenodata = phenodata, filename = paste(target, &quot;.txt&quot;, sep = &quot;&quot;))
Sys.time() - start # benchmark
</pre>
<p>Once finished, we can visualize the results using the so-called Manhattan plots. All we need is to load the .txt summary table written in the previous step, add a column with <img alt="-log_{10} (P) " title="-log_{10} (P) " src="https://s0.wp.com/latex.php?latex=-%5Clog_%7B10%7D+%28P%29+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> and plot these significance estimates against the genomic coordinates of all SNPs.</p>
<pre>
# Manhattan plot
GWASout &lt;- read.table(paste(target, &quot;.txt&quot;, sep = &quot;&quot;), header = T, colClasses = c(&quot;character&quot;, rep(&quot;numeric&quot;,4)))
GWASout$type &lt;- rep(&quot;typed&quot;, nrow(GWASout))
GWASout$Neg_logP &lt;- -log10(GWASout$p.value)
GWASout &lt;- merge(GWASout, genData$MAP[,c(&quot;SNP&quot;, &quot;chr&quot;, &quot;position&quot;)])
GWASout &lt;- GWASout[order(GWASout$Neg_logP, decreasing = T),]

png(paste(target, &quot;.png&quot;, sep = &quot;&quot;), height = 500,width = 1000)
GWAS_Manhattan(GWASout)
dev.off()
</pre>
<p>In addition, a full (resp. dashed) line indicate the levels of Bonferroni-adjusted <img alt="alpha = 0.05 " title="alpha = 0.05 " src="https://s0.wp.com/latex.php?latex=%5Calpha+%3D+0.05+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> for 1,000,000 (resp. 10,000) tests.<img data-orig-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol1.png?w=456" data-orig-size="1000,500" data-medium-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol1.png?w=456?w=300" data-attachment-id="3243" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2017/10/cholesterol1.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/cholesterol/" data-large-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol1.png?w=456?w=1000" alt="Cholesterol" data-image-title="Cholesterol" sizes="(max-width: 1000px) 100vw, 1000px" data-comments-opened="1" class="wp-image-3243" data-recalc-dims="1"></p>
<p>We see that a total of four SNPs pass the ‘relaxed’ Bonferroni threshold (none passes the ‘hard’ threshold). These are SNPs rs7527051 (Chr. 1), rs12140539 (co-localized with the first, Chr. 1), rs9509213 (Chr. 13) and rs2250402 (Chr. 15).</p>
<p>Before proceeding with these four hits, it is helpful to constrast the distribution of the resulting <em>P</em>-values against that expected by chance, as to ensure there is no confounding systemic bias. This is easily addressed with a quantile-quantile (Q-Q) plot. As the name suggests, it compares two distributions based on their quantiles. In the present case, we want to contrast the distribution of our <em>t</em> statistics against that obtained by chance. If two distributions are identical in shape, the Q-Q plot will display a <img alt="x = y " title="x = y " src="https://s0.wp.com/latex.php?latex=x+%3D+y+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> line. Therefore, the Q-Q plot from a reliable GWA analysis will display a <img alt="x = y " title="x = y " src="https://s0.wp.com/latex.php?latex=x+%3D+y+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> line with only few deviating values that are suggestive of association. Otherwise, if the line is shifted up or down the GWA analysis might be impaired by confounding factors.<strong> </strong>We will draw a Q-Q plot using the function <strong>estlambda</strong> from the package <strong>GenABEL</strong>.</p>
<pre>
# QQ plot using GenABEL estlambda function
png(paste(target, &quot;_QQplot.png&quot;, sep = &quot;&quot;), width = 500, height = 500)
lambda &lt;- estlambda(GWASout$t.value**2, plot = T, method = &quot;median&quot;)
dev.off()
</pre>
<p><img data-orig-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol_qqplot2.png?w=456" data-orig-size="500,500" data-medium-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol_qqplot2.png?w=456?w=300" data-attachment-id="3244" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2017/10/cholesterol_qqplot2.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/cholesterol_qqplot/" data-large-file="https://poissonisfish.files.wordpress.com/2017/10/cholesterol_qqplot2.png?w=456?w=500" alt="Cholesterol_QQplot" data-image-title="Cholesterol_QQplot" sizes="(max-width: 500px) 100vw, 500px" data-comments-opened="1" class="wp-image-3244" data-recalc-dims="1"></p>
<p>The resulting Q-Q plot clearly depicts a trend line (<img alt="lambda = 0.99 " title="lambda = 0.99 " src="https://s0.wp.com/latex.php?latex=%5Clambda+%3D+0.99+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">, red) overlapping with <img alt="x = y " title="x = y " src="https://s0.wp.com/latex.php?latex=x+%3D+y+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> (black) and a slight deviation in the right tail, so we can be confident about our results.</p>
<h3>Functional insights into candidate markers</h3>
<p>Finally, we will try to find the functional relevance of these four candidate SNPs by searching for genes in their vicinity, using the <a rel="nofollow" href="https://genome.ucsc.edu/" target="_blank">USCS Genome Browser</a> (enter Genome Browser, insert the SNP ID in the text box, enter and zoom out). I found that rs9509213 (Chr. 13) lands right on <em>CRYL1</em> (crystalline lambda 1, intron sequence), rendering it an interesting candidate for follow-up studies.</p>
<p><img data-orig-file="https://poissonisfish.files.wordpress.com/2017/10/screen-shot-2017-10-08-at-17-58-52.png?w=456" data-orig-size="1241,567" data-medium-file="https://poissonisfish.files.wordpress.com/2017/10/screen-shot-2017-10-08-at-17-58-52.png?w=456?w=300" data-attachment-id="3817" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2017/10/screen-shot-2017-10-08-at-17-58-52.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/screen-shot-2017-10-08-at-17-58-52/" data-large-file="https://poissonisfish.files.wordpress.com/2017/10/screen-shot-2017-10-08-at-17-58-52.png?w=456?w=1024" alt="Screen Shot 2017-10-08 at 17.58.52" data-image-title="Screen Shot 2017-10-08 at 17.58.52" sizes="(max-width: 1108px) 100vw, 1108px" data-comments-opened="1" class="wp-image-3817" data-recalc-dims="1"></p>
<p>The SNP rs9509213 is shown as a black text box in the bottom of the figure, and its coordinates are highlighted by a vertical yellow line. The <em>CRYL1</em> gene model is shown on top, below the chromosome model (topmost).</p>
<p>Interestingly, there is a recent <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5400530/" target="_blank">publication</a> that found ‘<em>POE, HP, and CRYL1 have all been associated with Alzheimer’s Disease, the pathology of which involves lipid and cholesterol pathways.’</em>.</p>
<p>Finally, I would like to remark on the need of experimental validation of gene candidates to validate the resulting SNP-trait associations. In this particular case, one could test the effect of overexpressing or knocking-out the ortholog of <em>CRYL1</em> in cholesterol levels of mice.</p>
<h3>Wrap-up</h3>
<p>To sum up, we have covered some of the most fundamental aspects of GWA analysis:</p>
<ul>
<li>Pre-processing of genotype data based on call rates, MAF, kinship and heterozygosity</li>
<li>Investigation of population structure with PCA of the genotype data</li>
<li>GWA and visualisation with Manhattan plots</li>
<li>Q-Q plots</li>
<li>Functional insights into the resulting candidate SNPs</li>
</ul>
<p>I did not cover many other aspects of GWA, such as fine-mapping using LD plots. I encourage you to choose a different lipid species from the phenotype data, run the analysis and interpret the results. Also noteworthy, the state-of-the-art of GWA is now almost-fully based on <a rel="nofollow" href="http://www.nature.com/ng/journal/v42/n4/full/ng.546.html" target="_blank">mixed-effect linear models</a> (MLM) that consider kinship and cryptic relatedness as random factors, hence much more powerful that <strong>glm</strong>. My next post might cover MLM.</p>
<p>I would like to thank <a rel="nofollow" href="https://www.nature.com/articles/s41467-017-00413-x" target="_blank">Saw et al., 2017</a> for providing unrestricted access to their <a rel="nofollow" href="http://phg.nus.edu.sg/#iomics" target="_blank">omics data</a>. If it wasn’t for such conscientious scientists and their transparent research endeavours this whole tutorial would simply not exist. I also reiterate that this tutorial is largely based on the guide outlined in <a rel="nofollow" href="http://onlinelibrary.wiley.com/doi/10.1002/sim.6605/full" target="_blank">Reed et al., 2015</a>, an excellent reference along with <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pubmed/23711206" target="_blank">Sikorska et al., 2013</a>.</p>
<p>Have fun and keep your cholesterol in check. Any feedback or suggestions are welcome!</p>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/poissonisfish.wordpress.com/3115/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/poissonisfish.wordpress.com/3115/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/"> poissonisfish</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/53hOjhkmknc" height="1"></a></div>