Last updated: 2019-02-28

Checks: 5 1

Knit directory: drift-workflow/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190211) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    analysis/.Rhistory
    Ignored:    analysis/flash_cache/
    Ignored:    data/datasets/
    Ignored:    data/raw/
    Ignored:    output.tar.gz
    Ignored:    output/admixture/
    Ignored:    output/flash_greedy/
    Ignored:    output/log/
    Ignored:    output/sim/

Untracked files:
    Untracked:  data.tar.gz

Unstaged changes:
    Modified:   analysis/flash.Rmd
    Modified:   analysis/hoa_global.Rmd
    Modified:   code/viz.R
    Modified:   data/meta/HumanOriginsPublic2068.meta
    Modified:   data/meta/write_meta_HumanOriginsPublic2068.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd d01c17c jhmarcus 2019-02-28 added chrom exploration
Rmd 5ee97ed jhmarcus 2019-02-27 updating manhatten plots
Rmd e1b4f85 jhmarcus 2019-02-25 added snakemake rule
html e1b4f85 jhmarcus 2019-02-25 added snakemake rule
html 38a461d jhmarcus 2019-02-24 built all
html b5aafbb jhmarcus 2019-02-24 Build site.
Rmd 63e7173 jhmarcus 2019-02-24 expanded upon mean variance
html 63e7173 jhmarcus 2019-02-24 expanded upon mean variance
Rmd 38b57c5 jhmarcus 2019-02-24 simplified greedy flash global analysis
html 38b57c5 jhmarcus 2019-02-24 simplified greedy flash global analysis
Rmd 403bc6b jhmarcus 2019-02-15 added hide code blocks
html 403bc6b jhmarcus 2019-02-15 added hide code blocks
Rmd b4749ac jhmarcus 2019-02-15 fixed some typos
html b4749ac jhmarcus 2019-02-15 fixed some typos
Rmd 7a2b6c7 jhmarcus 2019-02-15 added backfit
html 7a2b6c7 jhmarcus 2019-02-15 added backfit
Rmd f5ef1af jhmarcus 2019-02-15 added workflows for human origins datasets
html f5ef1af jhmarcus 2019-02-15 added workflows for human origins datasets
Rmd 4afc77e jhmarcus 2019-02-15 init hoa global analysis

Imports

Lets import some needed packages:

library(ggplot2)
library(tidyr)
library(dplyr)
library(RColorBrewer)
library(biomaRt)
library(knitr)
source("../code/viz.R")

Human Origins Global (LD Pruned)

This an analysis of the full Human Origins dataset which includes 2068 sampled from around the world. I filtered out rare variants with global minor allele frequency less than 5%, removed any variants with a missingness level greater than 1%, and removed any SNPs on the sex chromosomes. I then LD pruned the SNPs using standard parameters in plink, resulting in 165468 SNPs.

Greedy

Here is the snakemake rule I used for running flashier:

    run:
        R("""
          # read the genotype matrix
          Y = t(lfa:::read.bed('{params.bed}'))
          # number of individuals
          n = nrow(Y)
          
          # run greedy flash
          flash_fit = flashier::flashier(Y,
                                         greedy.Kmax=20,
                                         prior.type=c('nonnegative', 'point.normal'),
                                         var.type=2,
                                         fix.dim=list(1),
                                         fix.idx=list(1:n),
                                         fix.vals=list(rep(1, n)))
          # save the rds
          saveRDS(flash_fit, '{output.rds}')
          """)

Lets first read the greedy flashier fit

flash_fit = readRDS("../output/flash_greedy/hoa_global_ld/HumanOriginsPublic2068_maf_geno_auto_ldprune.rds")
K = ncol(flash_fit$loadings$normalized.loadings[[1]]) 
n = nrow(flash_fit$loadings$normalized.loadings[[1]])
p = nrow(flash_fit$loadings$normalized.loadings[[2]])
print(K)
[1] 21
print(n)
[1] 2068
print(p)
[1] 165468

Lets now plot the distribution of factors for each drift event

# read factors
delta_df = as.data.frame(flash_fit$loadings$normalized.loadings[[2]])
colnames(delta_df)[1:K] = 1:K 

# add snp meta data
bim_df = read.table("../data/raw/NearEastPublic/HumanOriginsPublic2068_maf_geno_auto_ldprune.bim", header=F)
colnames(bim_df) = c("chrom", "rsid", "cm", "pos", "a1", "a2")
delta_df$chrom = bim_df$chrom
delta_df$pos = bim_df$pos
delta_df$rsid = bim_df$rsid

# gather the data.frame for plotting
delta_gath_df = delta_df %>% 
                gather(K, value, -chrom, -pos, -rsid) %>%
                filter(K!=1)

# plot the factors
K_ = K
p_fct = ggplot(delta_gath_df, aes(x=value)) + 
        geom_histogram() + 
        facet_wrap(~factor(K, levels=2:K_), scales = "free") + 
        labs(fill="K") + 
        scale_x_continuous(breaks = scales::pretty_breaks(n = 3)) +
        scale_y_continuous(breaks = scales::pretty_breaks(n = 3)) + 
        theme_bw()
p_fct

Version Author Date
38b57c5 jhmarcus 2019-02-24
f5ef1af jhmarcus 2019-02-15

We can see the later factors tend to get sparser! Here is a plot of the “proportion of variance explained” of each factor:

qplot(2:K, flash_fit$pve[2:K]) + ylab("Proportion of Varaince Explained") + xlab("K") + theme_bw()

Version Author Date
38b57c5 jhmarcus 2019-02-24
print(flash_fit$pve)
 [1] 0.4763895014 0.0180272272 0.0221803113 0.0102965471 0.0025143344
 [6] 0.0045277929 0.0015659276 0.0014218575 0.0011760893 0.0008608887
[11] 0.0007633150 0.0006690835 0.0005002149 0.0002133497 0.0001920124
[16] 0.0002281114 0.0001847405 0.0002903768 0.0002700529 0.0001573717
[21] 0.0001176524

It looks like the PVE drops off at around 14 or so? I setup the flashier run so it estimates a SNP specific precision term. Here is a histogram of fitted variances:

qplot(1/flash_fit$fit$est.tau) + xlab("Estimated Variance") + ylab("Count") + theme_bw()

Version Author Date
38b57c5 jhmarcus 2019-02-24

Lets now look the the fitted means:

mu = sqrt(flash_fit$loadings$scale.constant[1]) * delta_df$`1`
qplot(mu) + xlab("Estimated Mean") + ylab("Count") + theme_bw()

Version Author Date
38b57c5 jhmarcus 2019-02-24

These plots looks about reasonable as each of the SNP variances should roughly be interpreted as average heterozygosity \(\approx 2p(1-p)\)? The mean term should roughly be interpreted as the mean minor allele frequency at the SNP and thus we should see a quadratic relationship with the estimated variance:

d1 = flash_fit$loadings$scale.constant[1]
mv_df = data.frame(var=1/flash_fit$fit$est.tau, mu=mu, chrom=bim_df$chrom)
p_mv = ggplot(mv_df, aes(x=mu, y=var)) + 
       geom_point() + 
       xlab("Rescaled Estimated Mean") + ylab("Estimated Variance") + 
       scale_alpha(guide = "none") + 
       stat_function(fun = function(x){return(2*x*(1-x))}, color="red") + 
       xlim(0, .5) + 
       theme_bw()
p_mv

Version Author Date
63e7173 jhmarcus 2019-02-24
38b57c5 jhmarcus 2019-02-24

Most of the SNPs have a mean-variance relationship expected under a simple Binomial model for the genotypes i.e. \(y_{ij} \sim Binomial(2, p_{ij})\). I wonder if there is anything “special” going on with the high variance SNP (will explore this later). Lets now take a look at the loadings. First we setup a data.frame that we can work with:

# read the meta data
meta_df = read.table("../data/meta/HumanOriginsPublic2068.meta", sep="\t", header=T)

# setup loadings data.frame
l_df = as.data.frame(flash_fit$loadings$normalized.loadings[[1]])
K = ncol(l_df)
l_df = cbind(l_df, meta_df)
pops = unique(l_df$Simple.Population.ID) # all unique pop labels

# join with the meta data
l_df = l_df %>% arrange(Region, Simple.Population.ID) # sort by region then by population
l_df$ID = factor(l_df$ID, levels = l_df$ID) # make sure the ids are sorted
colnames(l_df)[1:K] = 1:K

head(l_df)
           1            2           3          4            5            6
1 0.02198997 3.983040e-06 0.009742430 0.02223268 2.480331e-05 1.933025e-05
2 0.02198997 3.907523e-06 0.009734339 0.02268403 2.577005e-05 1.894343e-05
3 0.02198997 3.849485e-06 0.006489710 0.02495816 2.398744e-05 2.021861e-05
4 0.02198997 3.869767e-06 0.009428810 0.02313380 2.421315e-05 1.971725e-05
5 0.02198997 3.889654e-06 0.009863181 0.02289416 2.525070e-05 2.054919e-05
6 0.02198997 3.977201e-06 0.009502596 0.02229676 2.420936e-05 2.011595e-05
            7            8            9         10           11
1 0.011770312 3.967352e-05 2.832321e-05 0.05538038 3.960260e-05
2 0.010829446 4.011844e-05 2.957381e-05 0.04942202 4.264933e-05
3 0.010805872 3.752266e-05 2.607744e-05 0.05509969 4.206464e-05
4 0.010939192 3.790906e-05 2.729509e-05 0.05984811 3.902960e-05
5 0.008271378 3.933508e-05 2.670218e-05 0.05788346 3.936151e-05
6 0.011583697 3.722886e-05 2.807376e-05 0.05629556 3.791417e-05
           12           13           14         15           16
1 0.014925313 6.531321e-05 7.771835e-05 0.06157679 7.687870e-05
2 0.009683119 8.181238e-05 7.817497e-05 0.04760745 7.947480e-05
3 0.011611347 7.275697e-05 7.761959e-05 0.06522022 7.812401e-05
4 0.016421998 6.915482e-05 7.413616e-05 0.07187187 8.095212e-05
5 0.015993345 6.391435e-05 7.548730e-05 0.07753460 8.029139e-05
6 0.015481074 6.697399e-05 7.687836e-05 0.06055225 7.798898e-05
            17           18           19           20           21
1 0.0001113319 0.0004044934 8.802684e-05 8.731966e-05 8.756886e-05
2 0.0001220043 0.0002632577 3.821495e-04 1.139101e-04 8.716143e-05
3 0.0022902140 0.0002782860 9.505465e-05 2.280344e-04 8.567540e-05
4 0.0001352564 0.0001225972 8.289963e-05 7.181312e-04 8.324215e-05
5 0.0001010870 0.0001548211 1.957986e-04 7.474813e-03 8.673768e-05
6 0.0001327867 0.0005840805 7.520526e-05 9.241005e-05 8.510847e-05
             ID Simple.Population.ID Verbose.Population.ID Region Country
1 Algerian43A22             Algerian              Algerian Africa Algeria
2 Algerian43A21             Algerian              Algerian Africa Algeria
3 Algerian43A34             Algerian              Algerian Africa Algeria
4 Algerian43A13             Algerian              Algerian Africa Algeria
5 Algerian43A24             Algerian              Algerian Africa Algeria
6 Algerian43A32             Algerian              Algerian Africa Algeria
  Latitude Longitude Samples Passed.QC Contributor
1     36.8         3       7         7 David Comas
2     36.8         3       7         7 David Comas
3     36.8         3       7         7 David Comas
4     36.8         3       7         7 David Comas
5     36.8         3       7         7 David Comas
6     36.8         3       7         7 David Comas

Its hard to find a color scale that can sufficiently visualize all of the loadings in a single plot. Instead I just split the loadings up into two plots (K=2,…,11) and (K=12,…,21). Lets first visualize loadings 2 through 12:

# gather the data.frame for plotting
l_gath_df = l_df %>% 
            gather(K, value, -ID, -Verbose.Population.ID, -Simple.Population.ID, 
                   -Region, -Country, -Latitude, -Longitude, -Samples,
                   -Passed.QC,  -Contributor) %>% 
            filter(K %in% paste0(2:11))

# Africa
africa_pops = get_pops(meta_df, "Africa")
p_africa = positive_structure_plot(l_gath_df %>% filter(Region == "Africa"), 
                                   africa_pops, colset="Set3", label_size=5) +
           ggtitle("Africa") + theme(plot.title = element_text(size=6))

# America
america_pops = get_pops(meta_df, "America")
p_america = positive_structure_plot(l_gath_df %>% filter(Region == "America"), 
                                    america_pops, colset="Set3", label_size=5) + 
            ggtitle("America") + theme(plot.title = element_text(size=6))

# Central Asia Siberia
central_asia_siberia_pops = get_pops(meta_df, "CentralAsiaSiberia")
p_central_asia_siberia = positive_structure_plot(l_gath_df %>% filter(Region == "CentralAsiaSiberia"), 
                                                 central_asia_siberia_pops, colset="Set3", label_size=5) + 
                         ggtitle("CentralAsiaSiberia") + theme(plot.title = element_text(size=6))

# East Asia
east_asia_pops = get_pops(meta_df, "EastAsia")
p_east_asia = positive_structure_plot(l_gath_df %>% filter(Region == "EastAsia"), 
                                      east_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("EastAsia") + theme(plot.title = element_text(size=6))

# South Asia
south_asia_pops = get_pops(meta_df, "SouthAsia")
p_south_asia= positive_structure_plot(l_gath_df %>% filter(Region == "SouthAsia"),
                                      south_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("SouthAsia") + theme(plot.title = element_text(size=6))

# West Eurasia
west_eurasia_pops = get_pops(meta_df, "WestEurasia")
p_west_eurasia = positive_structure_plot(l_gath_df %>% filter(Region == "WestEurasia"), 
                                         west_eurasia_pops, colset="Set3", label_size=5) + 
                 ggtitle("WestEurasia") + theme(plot.title = element_text(size=6))

# Oceania
oceania_pops = get_pops(meta_df, "Oceania")
p_oceania = positive_structure_plot(l_gath_df %>% filter(Region == "Oceania"), 
                                    oceania_pops, colset="Set3", label_size=5) + 
            ggtitle("Oceania") + theme(plot.title = element_text(size=6))

# Global
p = cowplot::plot_grid(p_africa, p_west_eurasia, p_central_asia_siberia, p_america, p_east_asia, p_south_asia, p_oceania, 
                       rel_heights = c(1.2, 1.3, 1, 1, 1, 1, 1.1),
                       nrow = 7, align = "v") 
p

Version Author Date
38b57c5 jhmarcus 2019-02-24

Lets now visualize loadings 12 to 21 (be careful: there is no connection to the colors in the last plot):

# gather the data.frame for plotting
l_gath_df = l_df %>% 
            gather(K, value, -ID, -Verbose.Population.ID, -Simple.Population.ID, 
                   -Region, -Country, -Latitude, -Longitude, -Samples,
                   -Passed.QC,  -Contributor) %>% 
            filter(K %in% paste0(12:21))

# Africa
africa_pops = get_pops(meta_df, "Africa")
p_africa = positive_structure_plot(l_gath_df %>% filter(Region == "Africa"), 
                                   africa_pops, colset="Set3", label_size=5) +
           ggtitle("Africa") + theme(plot.title = element_text(size=6))

# America
america_pops = get_pops(meta_df, "America")
p_america = positive_structure_plot(l_gath_df %>% filter(Region == "America"), 
                                    america_pops, colset="Set3", label_size=5) + 
            ggtitle("America") + theme(plot.title = element_text(size=6))

# Central Asia Siberia
central_asia_siberia_pops = get_pops(meta_df, "CentralAsiaSiberia")
p_central_asia_siberia = positive_structure_plot(l_gath_df %>% filter(Region == "CentralAsiaSiberia"), 
                                                 central_asia_siberia_pops, colset="Set3", label_size=5) + 
                         ggtitle("CentralAsiaSiberia") + theme(plot.title = element_text(size=6))

# East Asia
east_asia_pops = get_pops(meta_df, "EastAsia")
p_east_asia = positive_structure_plot(l_gath_df %>% filter(Region == "EastAsia"), 
                                      east_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("EastAsia") + theme(plot.title = element_text(size=6))

# South Asia
south_asia_pops = get_pops(meta_df, "SouthAsia")
p_south_asia= positive_structure_plot(l_gath_df %>% filter(Region == "SouthAsia"),
                                      south_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("SouthAsia") + theme(plot.title = element_text(size=6))

# West Eurasia
west_eurasia_pops = get_pops(meta_df, "WestEurasia")
p_west_eurasia = positive_structure_plot(l_gath_df %>% filter(Region == "WestEurasia"), 
                                         west_eurasia_pops, colset="Set3", label_size=5) + 
                 ggtitle("WestEurasia") + theme(plot.title = element_text(size=6))

# Oceania
oceania_pops = get_pops(meta_df, "Oceania")
p_oceania = positive_structure_plot(l_gath_df %>% filter(Region == "Oceania"), 
                                    oceania_pops, colset="Set3", label_size=5) + 
            ggtitle("Oceania") + theme(plot.title = element_text(size=6))

# Global
p = cowplot::plot_grid(p_africa, p_west_eurasia, p_central_asia_siberia, p_america, p_east_asia, p_south_asia, p_oceania, 
                       rel_heights = c(1.2, 1.3, 1, 1, 1, 1, 1.1),
                       nrow = 7, align = "v") 
p

Version Author Date
38b57c5 jhmarcus 2019-02-24

Its kinda interesting to see that some populations have zero loading on later factors. Its also interesting to see a lot of population specific factors arising. This would be difficult to visualize see if using a single plot for all the factors.

ADMIXTURE

Lets visualize ADMIXTURE with 9 factors which should roughly align to the first plot i.e. FLASH with 2,…,11 (be careful: there is no connection to the colors in the last plot):

l_df = read.table("../output/admixture/hoa_global_ld/HumanOriginsPublic2068_maf_geno_auto_ldprune.K9r1.Q", sep=" ", header=F)
K = ncol(l_df)
l_df = cbind(l_df, meta_df)
pops = unique(l_df$Simple.Population.ID) # all unique pop labels
l_df = l_df %>% arrange(Region, Simple.Population.ID) # sort by region then by population
l_df$ID = factor(l_df$ID, levels = l_df$ID) # make sure the ids are sorted
colnames(l_df)[1:K] = 1:K

# gather the data.frame for plotting
l_gath_df = l_df %>% 
            gather(K, value, -ID, -Verbose.Population.ID, -Simple.Population.ID, 
                   -Region, -Country, -Latitude, -Longitude, -Samples,
                   -Passed.QC,  -Contributor) 

# Africa
africa_pops = get_pops(meta_df, "Africa")
p_africa = positive_structure_plot(l_gath_df %>% filter(Region == "Africa"), 
                                   africa_pops, colset="Set3", label_size=5) +
           ggtitle("Africa") + theme(plot.title = element_text(size=6))

# America
america_pops = get_pops(meta_df, "America")
p_america = positive_structure_plot(l_gath_df %>% filter(Region == "America"), 
                                    america_pops, colset="Set3", label_size=5) + 
            ggtitle("America") + theme(plot.title = element_text(size=6))

# Central Asia Siberia
central_asia_siberia_pops = get_pops(meta_df, "CentralAsiaSiberia")
p_central_asia_siberia = positive_structure_plot(l_gath_df %>% filter(Region == "CentralAsiaSiberia"), 
                                                 central_asia_siberia_pops, colset="Set3", label_size=5) + 
                         ggtitle("CentralAsiaSiberia") + theme(plot.title = element_text(size=6))

# East Asia
east_asia_pops = get_pops(meta_df, "EastAsia")
p_east_asia = positive_structure_plot(l_gath_df %>% filter(Region == "EastAsia"), 
                                      east_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("EastAsia") + theme(plot.title = element_text(size=6))

# South Asia
south_asia_pops = get_pops(meta_df, "SouthAsia")
p_south_asia= positive_structure_plot(l_gath_df %>% filter(Region == "SouthAsia"),
                                      south_asia_pops, colset="Set3", label_size=5) + 
              ggtitle("SouthAsia") + theme(plot.title = element_text(size=6))

# West Eurasia
west_eurasia_pops = get_pops(meta_df, "WestEurasia")
p_west_eurasia = positive_structure_plot(l_gath_df %>% filter(Region == "WestEurasia"), 
                                         west_eurasia_pops, colset="Set3", label_size=5) + 
                 ggtitle("WestEurasia") + theme(plot.title = element_text(size=6))

# Oceania
oceania_pops = get_pops(meta_df, "Oceania")
p_oceania = positive_structure_plot(l_gath_df %>% filter(Region == "Oceania"), 
                                    oceania_pops, colset="Set3", label_size=5) + 
            ggtitle("Oceania") + theme(plot.title = element_text(size=6))
# Global
p = cowplot::plot_grid(p_africa, p_west_eurasia, p_central_asia_siberia, p_america, p_east_asia, p_south_asia, p_oceania, 
                       rel_heights = c(1.2, 1.3, 1, 1, 1, 1, 1.1),
                       nrow = 7, align = "v") 
p

There is a lot that one can compare between the ADMIXTURE and FLASH results. A high level observation seems that the ADMIXTURE results look a bit more clustered i.e. the Americas and East Asia look like they are explained mostly by 1 or 2 factors whereas FLASH uses 3-4. Its hard to tell be it seems that this is true in many of the super regions … ADMIXTURE tends use fewer factors to explain population structure in each region, leading to a more clustered result?

SNP Weights

Lets take a closer look at the drift factors to see if they are clustering in particular regions of the genome. As a first pass I take the top 5% of SNPs weighted on each drift event (to be clear I ignore the sign of each SNP). I would like to use the lfsr here but I will return to later. I then made a Manhatten plot for each chromosome and factor:

delta_thresh_df = delta_df %>%
                  gather(K, value, -chrom, -pos, -rsid) %>%
                  filter(K %in% paste0(2:11)) %>% 
                  group_by(K) %>%
                  summarise(t_95 = quantile(abs(value), probs = .95)[1],
                            t_99 = quantile(abs(value), probs = .99)[1])

# gather the data.frame for plotting
delta_gath_df = delta_df %>% 
                gather(K, value, -chrom, -pos, -rsid) %>%
                filter(K %in% paste0(2:11)) %>% 
                inner_join(delta_thresh_df, on="K") %>%
                filter(abs(value) > t_95) %>%
                filter(chrom %in% 1:22)
Joining, by = "K"
p = ggplot(delta_gath_df, aes(x=pos, y=abs(value), color=factor(K))) + geom_point(size=.5, alpha=.7) + 
    scale_color_brewer(palette = "Set3") + 
    facet_grid(factor(K, levels=2:11)~factor(chrom, levels = 1:22), scales="free") +
    geom_hline(data=delta_gath_df %>% distinct(chrom, K, t_99), aes(yintercept = t_99), linetype="dashed") +
    theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
          panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
    guides(color=FALSE) +
    xlab("Position") + 
    ylab("|Factor|")
p

We can see there are some regions on the chromosomes that are peaky as well as some regions that have no “outliers” at all. I then took the top 5 outliers in each factor and annotated them with some functional information:

grch37.snp = useMart(biomart="ENSEMBL_MART_SNP", host="grch37.ensembl.org", path="/biomart/martservice",dataset="hsapiens_snp")
grch37 = useMart(biomart="ENSEMBL_MART_ENSEMBL", host="grch37.ensembl.org", path="/biomart/martservice", dataset="hsapiens_gene_ensembl")

delta_tophit_df = delta_df %>%
                  gather(K, value, -chrom, -pos, -rsid) %>%
                  filter(K %in% paste0(2:21)) %>% 
                  group_by(K) %>%
                  top_n(5, abs(value))

table1 <- getBM(attributes=c('refsnp_id', 'chrom_start', 'minor_allele_freq', 'ensembl_gene_stable_id',
                             'consequence_type_tv', "associated_gene"), 
                filters = "snp_filter", 
                values = delta_tophit_df$rsid, 
                mart = grch37.snp)

table1$ensembl_gene_id = table1$ensembl_gene_stable_id
table2 <- getBM(attributes = c("ensembl_gene_id", "external_gene_name", "description"),
                filters = "ensembl_gene_id", 
                values =  table1$ensembl_gene_stable_id, 
                mart = grch37)

anno_df = table1 %>% left_join(table2, on="ensembl_gene_id") %>% mutate(rsid=refsnp_id) %>% 
          inner_join(delta_tophit_df, on="rsid") 
Joining, by = "ensembl_gene_id"
Joining, by = "rsid"
Warning: Column `rsid` joining character vector and factor, coercing into
character vector
print(unique(anno_df$external_gene_name))
 [1] "CCNL2"          "CYP4B1"         NA               "RP11-280O1.2"  
 [5] "KIAA1614"       "C1orf132"       "CD34"           "FRMD4A"        
 [9] "SGPL1"          "CCSER2"         "HPSE2"          "NAV2"          
[13] "SLC22A10"       "STT3A-AS1"      "STT3A"          "HOXC13-AS"     
[17] "CNOT2"          "RP11-114H23.1"  "APPL2"          "LINC00641"     
[21] "HERC2"          "RP11-109D20.1"  "SORD"           "PRKCB"         
[25] "PKD1L2"         "RP11-1407O15.2" "CACNB1"         "RP11-515E23.1" 
[29] "RP11-1055B8.4"  "MFSD12"         "IL1R1"          "TMEM87B"       
[33] "RAB3GAP1"       "ZRANB3"         "ITGB6"          "TLK1"          
[37] "PARD3B"         "SF3A1"          "DRG1"           "TEF"           
[41] "KAT2B"          "SEMA3F"         "FRMD4B"         "MYH15"         
[45] "RP11-103J17.1"  "RP11-696N14.1"  "SLC45A2"        "NDUFAF2"       
[49] "DPYSL3"         "UNC5A"          "AKAP12"         "TIAM2"         
[53] "TMEM248"        "SMARCA2"        "GLIS3"          "RCL1"          
[57] "PTPN3"          "TNFSF8"        
kable(anno_df %>% dplyr::select(rsid, chrom, pos, external_gene_name, K, value) %>% arrange(desc(K, value)))
rsid chrom pos external_gene_name K value
rs857832 1 158740336 NA 9 0.0114801
rs11717349 3 50223977 SEMA3F 9 0.0114268
rs11733992 4 37098598 RP11-103J17.1 9 0.0132286
rs11733992 4 37098598 RP11-103J17.1 9 0.0132286
rs2859136 6 36109901 NA 9 0.0116692
rs201874034 10 14381634 FRMD4A 8 0.0121035
rs7083883 10 72593611 SGPL1 8 0.0121500
rs12987602 2 160960788 ITGB6 8 0.0127913
rs12987602 2 160960788 ITGB6 8 0.0127913
rs12987602 2 160960788 ITGB6 8 0.0127913
rs12495912 3 128281563 NA 8 0.0130564
rs10264873 7 66404770 TMEM248 8 0.0141428
rs10264873 7 66404770 TMEM248 8 0.0141428
rs11178168 12 70673667 CNOT2 7 0.0120869
rs11178168 12 70673667 CNOT2 7 0.0120869
rs11178168 12 70673667 CNOT2 7 0.0120869
rs11151771 18 70175449 NA 7 0.0130394
rs1229966 4 100213433 RP11-696N14.1 7 0.0139657
rs1229966 4 100213433 RP11-696N14.1 7 0.0139657
rs7028891 9 117645015 NA 7 0.0120868
rs1322067 9 117660933 TNFSF8 7 -0.0132333
rs1322067 9 117660933 TNFSF8 7 -0.0132333
rs2094224 14 21638784 NA 6 0.0117880
rs12184962 14 21671316 LINC00641 6 0.0118419
rs12184962 14 21671316 LINC00641 6 0.0118419
rs12184962 14 21671316 LINC00641 6 0.0118419
rs80533 22 41085969 NA 6 0.0124500
rs9611566 22 41768625 TEF 6 0.0125844
rs6916552 6 155412045 TIAM2 6 0.0122710
rs2366148 12 54331903 HOXC13-AS 5 0.0100104
rs2366148 12 54331903 HOXC13-AS 5 0.0100104
rs2470686 15 45341718 RP11-109D20.1 5 0.0105256
rs2470686 15 45341718 RP11-109D20.1 5 0.0105256
rs2470686 15 45341718 SORD 5 0.0105256
rs2470686 15 45341718 SORD 5 0.0105256
rs9908046 17 53563782 RP11-515E23.1 5 0.0110059
rs9908046 17 53563782 RP11-515E23.1 5 0.0110059
rs3744146 17 79363728 RP11-1055B8.4 5 0.0104628
rs5749071 22 30742125 SF3A1 5 0.0101114
rs5749071 22 30742125 SF3A1 5 0.0101114
rs5749071 22 30742125 SF3A1 5 0.0101114
rs3744146 17 79363728 RP11-1055B8.4 5 0.0104628
rs1240747 1 1329803 CCNL2 4 0.0129103
rs1240747 1 1329803 CCNL2 4 0.0129103
rs1240747 1 1329803 CCNL2 4 0.0129103
rs12441154 15 48390956 NA 4 -0.0116978
rs6497455 16 20283920 NA 4 -0.0112176
rs185146 5 33952106 SLC45A2 4 0.0109695
rs2148359 9 7385508 NA 4 -0.0113081
rs6428891 1 116873176 NA 3 0.0093046
rs10741783 11 19625932 NAV2 3 0.0095619
rs1572510 13 105381134 NA 3 0.0093867
rs692713 5 176253435 UNC5A 3 0.0093205
rs172447 9 4859106 RCL1 3 0.0097213
rs2235767 1 207983167 C1orf132 21 0.0180402
rs3820521 1 208060464 CD34 21 0.0175024
rs3820521 1 208060464 CD34 21 0.0175024
rs3820521 1 208060464 CD34 21 0.0175024
rs56347056 10 86259872 CCSER2 21 0.0173553
rs56347056 10 86259872 CCSER2 21 0.0173553
rs137269 22 35167444 NA 21 0.0191699
rs5999613 22 35280188 NA 21 0.0175980
rs503288 11 125461787 STT3A-AS1 20 0.0155133
rs503288 11 125461787 STT3A-AS1 20 0.0155133
rs503288 11 125461787 STT3A 20 0.0155133
rs503288 11 125461787 STT3A 20 0.0155133
rs12303948 12 105591569 APPL2 20 0.0167013
rs12303948 12 105591569 APPL2 20 0.0167013
rs12303948 12 105591569 APPL2 20 0.0167013
rs12303948 12 105591569 APPL2 20 0.0167013
rs12303948 12 105591569 APPL2 20 0.0167013
rs7323848 13 42079965 NA 20 0.0173892
rs16990385 4 34847300 NA 20 0.0164637
rs7035991 9 2094908 SMARCA2 20 0.0154711
rs16990385 4 34847300 NA 20 0.0164637
rs4657449 1 165465281 RP11-280O1.2 2 0.0104690
rs4657449 1 165465281 RP11-280O1.2 2 0.0104690
rs12441154 15 48390956 NA 2 0.0110577
rs12609922 19 57569951 NA 2 0.0107482
rs6437783 3 108172817 MYH15 2 0.0103993
rs6437783 3 108172817 MYH15 2 0.0103993
rs2148359 9 7385508 NA 2 0.0108050
rs6656573 1 163634947 NA 19 0.0145442
rs13376701 1 163770504 NA 19 0.0150934
rs10827877 10 20103046 NA 19 0.0155978
rs73119690 12 50428969 NA 19 0.0146244
rs16954698 16 81157353 PKD1L2 19 0.0148618
rs16954698 16 81157353 PKD1L2 19 0.0148618
rs569501 11 124271566 NA 18 0.0153963
rs17106725 5 146806365 DPYSL3 18 0.0160691
rs17106725 5 146806365 DPYSL3 18 0.0160691
rs10516028 5 166042592 NA 18 0.0156062
rs13213850 6 246178 NA 18 0.0152063
rs12336101 9 112143287 PTPN3 18 0.0153654
rs12286785 11 106026300 NA 17 0.0151204
rs1626537 11 110195612 NA 17 0.0146078
rs199553189 17 45323125 NA 17 0.0142453
rs678179 18 76089945 NA 17 0.0150289
rs17034367 2 67999876 NA 17 0.0145329
rs79336712 11 7189168 NA 16 0.0137840
rs2273248 22 31816439 DRG1 16 0.0136611
rs2273248 22 31816439 DRG1 16 0.0136611
rs2273248 22 31816439 DRG1 16 0.0136611
rs16885614 4 31670568 NA 16 0.0152543
rs17081009 6 151597033 AKAP12 16 0.0154250
rs1973815 7 144730377 NA 16 0.0134115
rs7545466 1 180892498 KIAA1614 15 0.0126254
rs3845416 1 180896031 KIAA1614 15 0.0123808
rs11189628 10 100240681 HPSE2 15 -0.0127590
rs16531 17 37349655 CACNB1 15 0.0130201
rs16531 17 37349655 CACNB1 15 0.0130201
rs16531 17 37349655 CACNB1 15 0.0130201
rs10182333 2 112841856 TMEM87B 15 -0.0128510
rs2297810 1 47280859 CYP4B1 14 -0.0121187
rs2297810 1 47280859 CYP4B1 14 -0.0121187
rs2297810 1 47280859 CYP4B1 14 -0.0121187
rs2297810 1 47280859 CYP4B1 14 -0.0121187
rs2297810 1 47280859 CYP4B1 14 -0.0121187
rs3847673 12 75968877 RP11-114H23.1 14 0.0118319
rs3847673 12 75968877 RP11-114H23.1 14 0.0118319
rs2929402 3 20096110 KAT2B 14 0.0123302
rs2929402 3 20096110 KAT2B 14 0.0123302
rs2061510 8 47676859 NA 14 0.0130766
rs10974315 9 4070279 GLIS3 14 0.0129599
rs10974315 9 4070279 GLIS3 14 0.0129599
rs6591765 11 62918253 SLC22A10 13 0.0126936
rs6591765 11 62918253 SLC22A10 13 0.0126936
rs4787651 16 24025666 PRKCB 13 0.0138686
rs3755295 2 102768294 IL1R1 13 0.0136692
rs34266487 3 69419614 FRMD4B 13 0.0124040
rs34266487 3 69419614 FRMD4B 13 0.0124040
rs7494942 15 28364059 HERC2 12 0.0128747
rs7494942 15 28364059 HERC2 12 0.0128747
rs7494942 15 28364059 HERC2 12 0.0128747
rs6730157 2 135907088 RAB3GAP1 12 0.0139051
rs6730157 2 135907088 RAB3GAP1 12 0.0139051
rs6730157 2 135907088 ZRANB3 12 0.0139051
rs6730157 2 135907088 ZRANB3 12 0.0139051
rs1519528 2 136973781 NA 12 0.0128935
rs185146 5 33952106 SLC45A2 12 0.0131700
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs371156 6 32209963 NA 12 -0.0129518
rs11085023 19 3571446 MFSD12 11 -0.0135666
rs11085023 19 3571446 MFSD12 11 -0.0135666
rs11085023 19 3571446 MFSD12 11 -0.0135666
rs78813632 2 172032197 TLK1 11 0.0128129
rs1841504 5 60413392 NDUFAF2 11 0.0119575
rs1841504 5 60413392 NDUFAF2 11 0.0119575
rs7040408 9 76955137 NA 11 -0.0118599
rs10117120 9 102292520 NA 11 0.0118910
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
rs787583 18 72884470 NA 10 0.0132670
rs3977 2 199134456 NA 10 0.0120080
rs1207425 2 206155107 PARD3B 10 0.0120639
rs10500023 7 112864760 NA 10 0.0120991
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
rs8066255 17 36410559 RP11-1407O15.2 10 0.0128793
We can see many of these top outliers are in genes (but we have to consider the array design to know if this is unusual). Its cool to see a couple very interesting genes pop up including HERC2 (eye color) and SLC45A2 (skin color) which have been previously studied for their selection signatures. Its also fun to look at some of the rsids on https://popgen.uchicago.edu/ggv/ to get a sense of what kind of allele frequency distributions define each factor.

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS  10.14.2

Matrix products: default
BLAS/LAPACK: /Users/jhmarcus/miniconda3/lib/R/lib/libRblas.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.21         biomaRt_2.38.0     RColorBrewer_1.1-2
[4] dplyr_0.8.0.1      tidyr_0.8.2        ggplot2_3.1.0     

loaded via a namespace (and not attached):
 [1] progress_1.2.0       tidyselect_0.2.5     xfun_0.4            
 [4] reshape2_1.4.3       purrr_0.3.0          colorspace_1.4-0    
 [7] htmltools_0.3.6      stats4_3.5.1         yaml_2.2.0          
[10] blob_1.1.1           XML_3.98-1.12        rlang_0.3.1         
[13] pillar_1.3.1         glue_1.3.0           withr_2.1.2         
[16] DBI_1.0.0            BiocGenerics_0.28.0  bit64_0.9-7         
[19] plyr_1.8.4           stringr_1.4.0        munsell_0.5.0       
[22] gtable_0.2.0         workflowr_1.2.0      flashier_0.1.0      
[25] evaluate_0.12        memoise_1.1.0        labeling_0.3        
[28] Biobase_2.42.0       IRanges_2.16.0       curl_3.3            
[31] parallel_3.5.1       AnnotationDbi_1.44.0 highr_0.7           
[34] Rcpp_1.0.0           scales_1.0.0         backports_1.1.3     
[37] S4Vectors_0.20.1     fs_1.2.6             bit_1.1-14          
[40] hms_0.4.2            digest_0.6.18        stringi_1.2.4       
[43] cowplot_0.9.4        grid_3.5.1           rprojroot_1.3-2     
[46] tools_3.5.1          bitops_1.0-6         magrittr_1.5        
[49] lazyeval_0.2.1       RCurl_1.95-4.11      tibble_2.0.1        
[52] RSQLite_2.1.1        crayon_1.3.4         whisker_0.3-2       
[55] pkgconfig_2.0.2      prettyunits_1.0.2    assertthat_0.2.0    
[58] rmarkdown_1.11       httr_1.4.0           R6_2.4.0            
[61] git2r_0.23.0         compiler_3.5.1