Last updated: 2020-12-30

Checks: 7 0

Knit directory: finemap-uk-biobank/

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


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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(20191114) 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 job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version eb112b4. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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:


Untracked files:
    Untracked:  output/udrdata.rds
    Untracked:  scripts/remove_covar_Y.R

Unstaged changes:
    Deleted:    output/BloodCells.Ulist.Scor.ed.rds
    Deleted:    output/BloodCells.Ulist.Scov.ed.rds

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 repository in which changes were made to the R Markdown (analysis/bloodcells_priors.Rmd) and HTML (docs/bloodcells_priors.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd eb112b4 zouyuxin 2020-12-30 wflow_publish(“analysis/bloodcells_priors.Rmd”)
html e7f49d8 zouyuxin 2020-12-18 Build site.
Rmd 63aa212 zouyuxin 2020-12-18 wflow_publish(“analysis/bloodcells_priors.Rmd”)
html 1f7ba20 zouyuxin 2020-12-16 Build site.
Rmd 235a17c zouyuxin 2020-12-16 wflow_publish(“analysis/bloodcells_priors.Rmd”)
html 0b25399 zouyuxin 2020-12-16 Build site.
Rmd f2d525a zouyuxin 2020-12-16 wflow_publish(“analysis/bloodcells_priors.Rmd”)
html 54852ec zouyuxin 2020-12-01 Build site.
Rmd 3dccaea zouyuxin 2020-12-01 wflow_publish(“analysis/bloodcells_priors.Rmd”)
html 9826391 zouyuxin 2020-12-01 Build site.
Rmd 8bc1231 zouyuxin 2020-12-01 wflow_publish(“analysis/bloodcells_priors.Rmd”)

library(data.table)
library(flashr)
library(mixsqp)
library(udr)
  1. Extract 1 snp per region with the strongest signal
regions = fread('/project2/mstephens/yuxin/ukb-bloodcells/regions.csv')
colnames(regions) = c('chr', 'start', 'end', 'length', 'maxlog10p', 'numsnps')
z.strong = c()
z.random = c()
set.seed(2020)
for (i in 1:nrow(regions)){
  dat = readRDS(paste0('/project2/mstephens/yuxin/ukb-bloodcells/zscores/bloodcells_chr',
                       regions$chr[i], '.', regions$start[i], '.', regions$end[i],'.z.rds'))
  z = dat$Z
  strong.id = which.max(apply(abs(z), 1, max))
  z.strong = rbind(z.strong, z[strong.id, ])
  
  null.id = which(apply(abs(z), 1, max) < 2)
  random_idx = sample(null.id, 1, replace = F)
  z.random = rbind(z.random, z[random_idx,])
}
  1. PCA
par(mfrow=c(1,3))
res.svd = svd(z.strong,nv=3,nu=3)
f = res.svd$v
rownames(f) = colnames(z.strong)
U.pca = mashr:::cov_from_factors(t(f), "PCA")
d = diag(res.svd$d[1:3])
U.pca = c(U.pca, list("tPCA"= f %*% d^2 %*% t(f)/nrow(z.strong)))
for(i in 1:3){
  barplot(f[,i], cex.names = 0.7,
          las = 2, main = paste0("EigenVector ", i, ' pve: ', round(res.svd$d[i]^2/sum(res.svd$d^2), 3)))
}

Version Author Date
0b25399 zouyuxin 2020-12-16
  1. FLASH
f.d = flash_set_data(as.matrix(z.strong))
f = flashr::flash(f.d, greedy=TRUE, backfit = T)
saveRDS(f, 'output/BloodCells.flash.model.rds')
f = readRDS('output/BloodCells.flash.model.rds')
nonunique_effects <- function(fl) {
    thresh <- 1/sqrt(ncol(fl$fitted_values))
    vals_above_avg <- colSums(fl$ldf$f > thresh)
    nonuniq_effects <- which(vals_above_avg > 1)
    return(nonuniq_effects)
}
nonunique_effects_id = nonunique_effects(f)
par(mfrow=c(2,3))
for(i in 1:13){
  barplot(f$ldf$f[,i], cex.names = 0.7,
          las = 2, main = paste0("Flash factor ", i, " pve: ", round(f$pve[i], 2)))
}

Version Author Date
0b25399 zouyuxin 2020-12-16

Version Author Date
0b25399 zouyuxin 2020-12-16

Version Author Date
0b25399 zouyuxin 2020-12-16
U.flash = c(mashr:::cov_from_factors(t(as.matrix(f$ldf$f)), "FLASH"),
                list("tFLASH" = t(f$fitted_values) %*% f$fitted_values / nrow(f$fitted_values)))

Ulist = c(U.flash, U.pca, list("XX" = t(as.matrix(z.strong)) %*% as.matrix(z.strong) / nrow(z.strong)))
saveRDS(Ulist, 'output/BloodCells.flash.pca.ulist.rds')
z.random.cov = cov(z.random)
traits = fread('/project2/mstephens/yuxin/ukb-bloodcells/bloodcells.pheno.resid.txt')
Ycov = cov(traits[,3:18])
saveRDS(list(z.random.cov = z.random.cov, Y.cov = Ycov), 'output/BloodCells.cov.rds')
library(udr)
f0 = ud_init(X = as.matrix(z.strong), V = cov2cor(Ycov), U_scaled = list(), U_unconstrained = Ulist, n_rank1=0)
res = ud_fit(f0, control = list(unconstrained.update = "ed", resid.update = 'none', maxiter=5000, minval=1e-12),
    verbose=FALSE)
saveRDS(res, 'output/BloodCells.Ulist.Scor.ed.rds')

ED weights:

fit.ed = readRDS('output/BloodCells.Ulist.Scor.ed.rds')
barplot(fit.ed$w, las=2, cex.names = 0.7)

Version Author Date
e7f49d8 zouyuxin 2020-12-18
1f7ba20 zouyuxin 2020-12-16
0b25399 zouyuxin 2020-12-16
9826391 zouyuxin 2020-12-01

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] udr_0.3-29        mixsqp_0.3-46     flashr_0.6-7      data.table_1.12.8
[5] workflowr_1.6.2  

loaded via a namespace (and not attached):
 [1] softImpute_1.4   tidyselect_1.1.0 xfun_0.8         ashr_2.2-51     
 [5] purrr_0.3.4      reshape2_1.4.3   lattice_0.20-38  colorspace_2.0-0
 [9] vctrs_0.3.6      htmltools_0.3.6  yaml_2.2.0       rlang_0.4.9     
[13] later_0.8.0      pillar_1.4.7     glue_1.4.2       lifecycle_0.2.0 
[17] plyr_1.8.6       mashr_0.2.40     stringr_1.4.0    munsell_0.5.0   
[21] gtable_0.3.0     mvtnorm_1.1-1    evaluate_0.14    knitr_1.23      
[25] httpuv_1.5.1     invgamma_1.1     irlba_2.3.3      Rcpp_1.0.5      
[29] promises_1.0.1   scales_1.1.1     rmeta_3.0        abind_1.4-5     
[33] truncnorm_1.0-8  fs_1.3.1         ggplot2_3.3.2    digest_0.6.27   
[37] stringi_1.4.6    dplyr_0.8.3      ebnm_0.1-24      grid_3.6.1      
[41] rprojroot_2.0.2  tools_3.6.1      magrittr_2.0.1   tibble_3.0.4    
[45] crayon_1.3.4     whisker_0.3-2    pkgconfig_2.0.3  ellipsis_0.3.1  
[49] Matrix_1.2-18    SQUAREM_2020.5   assertthat_0.2.1 rmarkdown_1.13  
[53] R6_2.5.0         git2r_0.26.1     compiler_3.6.1