Last updated: 2023-11-06
Checks: 6 1
Knit directory: analysis_pipelines/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks 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(20200524)
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 0e89459. 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:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Untracked files:
Untracked: analysis/test_sldsc_splicingAnnot.Rmd
Untracked: code/compute_ldscore_generic_annot.sbatch
Untracked: code/extract_baselineLD_generic_annot.R
Untracked: code/ldsc_make_binary_annot_compute_ldscores_bedfiles.sbatch
Untracked: code/make_ldsc_binary_annots_from_bedfiles.R
Untracked: code/sldsc_annot_generic_baselineLD_separate.sbatch
Untracked: scripts/tmp.R
Unstaged changes:
Modified: analysis/mapgen_finemapping_ukbb_ld.Rmd
Modified: analysis/mapgen_torus_enrichment_heart_atlas.Rmd
Modified: analysis/sldsc_example_GTEx_QTLs.Rmd
Modified: analysis/sldsc_pipeline.Rmd
Modified: code/extract_baselineLDv2.2_generic_annot.R
Modified: code/mapgen_trackplots.R
Modified: scripts/run_finemapping.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 repository in which changes were
made to the R Markdown
(analysis/mapgen_finemapping_ukbb_ld.Rmd
) and HTML
(docs/mapgen_finemapping_ukbb_ld.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 |
---|---|---|---|---|
html | 0e89459 | kevinlkx | 2023-10-27 | Build site. |
Rmd | 7937f92 | kevinlkx | 2023-10-27 | wflow_publish("analysis/mapgen_finemapping_ukbb_ld.Rmd") |
html | c3fd810 | kevinlkx | 2023-10-27 | Build site. |
Rmd | 0437fe6 | kevinlkx | 2023-10-27 | wflow_publish("analysis/mapgen_finemapping_ukbb_ld.Rmd") |
html | e882df5 | kevinlkx | 2023-10-27 | Build site. |
Rmd | 62f3d8a | kevinlkx | 2023-10-27 | wflow_publish("analysis/mapgen_finemapping_ukbb_ld.Rmd") |
library(mapgen)
library(tidyverse)
library(susieR)
library(ggplot2)
Load an example asthma GWAS summary statistics
gwas.file <- '/project2/xinhe/shared_data/mapgen/example_data/GWAS/aoa_v3_gwas_ukbsnps_susie_input.txt.gz'
gwas.sumstats <- vroom::vroom(gwas.file, col_names = TRUE, show_col_types = FALSE)
head(gwas.sumstats)
# A tibble: 6 × 10
chr pos beta se a0 a1 snp pval zscore locus
<dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl>
1 1 693731 0.00277 0.0156 A G rs12238997 0.859 0.178 1
2 1 707522 0.00337 0.0169 G C rs371890604 0.841 0.200 1
3 1 717587 -0.0538 0.0429 G A rs144155419 0.210 -1.25 1
4 1 723329 0.00182 0.128 A T rs189787166 0.989 0.0143 1
5 1 729679 0.00577 0.0142 C G rs4951859 0.684 0.407 1
6 1 730087 -0.00465 0.0220 T C rs148120343 0.832 -0.212 1
n = 336210
LD blocks
LD_blocks <- readRDS(system.file('extdata', 'LD.blocks.EUR.hg19.rds', package='mapgen'))
head(LD_blocks, 3)
chr start end locus
1 1 10583 1892607 1
2 1 1892607 3582736 2
3 1 3582736 4380811 3
Process GWAS summary statistics
gwas.sumstats <- process_gwas_sumstats(gwas.sumstats,
chr='chr',
pos='pos',
beta='beta',
se='se',
a0='a0',
a1='a1',
snp='snp',
pval='pval',
LD_Blocks=LD_blocks)
Cleaning summary statistics...
Assigning GWAS SNPs to LD blocks...
Select GWAS significant loci with -log10(pval) < 5e-8
if(max(gwas.sumstats$pval) <= 1){
gwas.sumstats <- gwas.sumstats %>% dplyr::mutate(pval = -log10(pval))
}
sig.loci <- gwas.sumstats %>% dplyr::filter(pval > -log10(5e-8)) %>% dplyr::pull(locus) %>% unique()
sumstats.sigloci <- gwas.sumstats[gwas.sumstats$locus %in% sig.loci, ]
cat(length(sig.loci), "significant loci.\n")
19 significant loci.
Load LD matrix, match variants between GWAS and LD matrix
locus <- sig.loci[2]
LDREF <- load_UKBB_LDREF(LD_blocks, locus = locus,
LDREF.dir = "/project2/mstephens/wcrouse/UKB_LDR_0.1_b37", prefix = "ukb_b37_0.1")
matched.sumstat.LD.res <- match_gwas_LDREF(gwas.sumstats, LDREF$R, LDREF$var_info)
sumstats.locus <- matched.sumstat.LD.res$sumstats
R.locus <- matched.sumstat.LD.res$R
Run SuSiE with LD matrices
LD_matrices <- list(R.locus)
names(LD_matrices) <- locus
susie.locus.res <- run_finemapping(sumstats.locus, LD_matrices = LD_matrices, priortype = 'uniform', n = n, L = 10)
Finemapping locus 193...
Run susie_rss...
susie.locus.res[[1]]$sets
$cs
$cs$L2
[1] 464 485 498 499 508 517 530 564 574 593 597 615 628 630 636
[16] 644 649 653 654 668 672 682 684 689 690 726 729 731 732 733
[31] 738 747 771 773 778 789 804 835 841 852 856 859 873 881 882
[46] 889 893 903 905 909 921 923 924 926 929 947 956 960 965 984
[61] 987 1010 1014 1018 1034 1062 1067 1146
$cs$L1
[1] 602 632 637 660 706 711 714 734 735 739 740 749 751 759 763 766 768 769 775
[20] 779 782 787 790 791 794 797 812 813 814 854 857 865 894 895 896 899 916 932
$purity
min.abs.corr mean.abs.corr median.abs.corr
L2 0.7923272 0.9172110 0.9318115
L1 0.5835378 0.8666369 0.8125560
$cs_index
[1] 2 1
$coverage
[1] 0.9517707 0.9512414
$requested_coverage
[1] 0.95
susie_plot(susie.locus.res[[1]], y='PIP')
susie.locus.sumstats <- merge_susie_sumstats(susie.locus.res, sumstats.locus)
condz <- LD_diagnosis_rss(sumstats.locus$zscore, R = R.locus, n = n)
Estimate consistency between the z-scores and LD matrix in susie_rss model using regularized LD ...
Estimated lambda = 7.436622e-05
Compute expected z-scores based on conditional distribution of other z-scores ...
condz$plot
Version | Author | Date |
---|---|---|
e882df5 | kevinlkx | 2023-10-27 |
Flip alleles for 10 variants with abs(z-scores) > 2
seed = 1
set.seed(seed)
flip_index <- sample(which(sumstats.locus$zscore > 2), 10)
sumstats.locus.flip <- sumstats.locus
sumstats.locus.flip$zscore[flip_index] <- -sumstats.locus$zscore[flip_index]
sumstats.locus.flip[flip_index, ]
# A tibble: 10 × 10
chr pos beta se a0 a1 snp pval zscore locus
<int> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl>
1 2 102985950 0.0746 0.0108 T C rs3771171 11.2 -6.89 193
2 2 102854882 0.0282 0.0105 C T rs3755282 2.13 -2.67 193
3 2 102839199 0.0271 0.0104 C T rs6715919 2.04 -2.61 193
4 2 103194558 0.0537 0.0124 A G rs74263644 4.83 -4.33 193
5 2 103247758 0.0703 0.0213 T C rs76605545 3.00 -3.29 193
6 2 102959080 0.0381 0.0177 G A rs13016771 1.50 -2.15 193
7 2 102945755 0.0283 0.0100 G T rs150341880 2.33 -2.83 193
8 2 103237631 0.0363 0.0102 T C rs2012454 3.41 -3.55 193
9 2 102918018 0.0262 0.0119 G A rs4577297 1.56 -2.21 193
10 2 102965332 0.0765 0.0108 G C rs17027006 11.8 -7.05 193
cat(length(flip_index), "Allele switched variants:", sort(sumstats.locus.flip$snp[flip_index]), "\n")
10 Allele switched variants: rs13016771 rs150341880 rs17027006 rs2012454 rs3755282 rs3771171 rs4577297 rs6715919 rs74263644 rs76605545
Run SuSiE including variants with flipped alleles
LD_matrices <- list(R.locus)
names(LD_matrices) <- locus
susie.locus.res <- run_finemapping(sumstats.locus.flip, LD_matrices = LD_matrices, priortype = 'uniform', n = n, L = 10)
Finemapping locus 193...
Run susie_rss...
Warning in susie_suff_stat(XtX = XtX, Xty = Xty, n = n, yty = (n - 1) * : IBSS algorithm did not converge in 100 iterations!
Please check consistency between summary statistics and LD matrix.
See https://stephenslab.github.io/susieR/articles/susierss_diagnostic.html
susie.locus.res[[1]]$sets
$cs
$cs$L1
[1] 768
$cs$L2
[1] 766
$cs$L5
[1] 764
$purity
min.abs.corr mean.abs.corr median.abs.corr
L1 1 1 1
L2 1 1 1
L5 1 1 1
$cs_index
[1] 1 2 5
$coverage
[1] 1 1 1
$requested_coverage
[1] 0.95
susie_plot(susie.locus.res[[1]], y='PIP')
susie.locus.sumstats <- merge_susie_sumstats(susie.locus.res, sumstats.locus)
Compares observed z scores vs the expected z scores
condz <- LD_diagnosis_rss(sumstats.locus.flip$zscore, R = R.locus, n = n)
Estimate consistency between the z-scores and LD matrix in susie_rss model using regularized LD ...
Estimated lambda = 0.3195599
Compute expected z-scores based on conditional distribution of other z-scores ...
condz$plot
The possible allele switched variants are labeled as red points (logLR > 2 and abs(z) > 2).
detected_index <- which(condz$conditional_dist$logLR > 2 & abs(condz$conditional_dist$z) > 2)
cat(sprintf("Detected %d variants with possible allele switched", length(detected_index)), "\n")
Detected 10 variants with possible allele switched
cat("Possible allele switched variants:", sort(sumstats.locus.flip$snp[detected_index]), "\n")
Possible allele switched variants: rs13016771 rs150341880 rs17027006 rs2012454 rs3755282 rs3771171 rs4577297 rs6715919 rs74263644 rs76605545
condz$conditional_dist$flipped <- 0
condz$conditional_dist$flipped[flip_index] <- 1
condz$conditional_dist$detected <- 0
condz$conditional_dist$detected[detected_index] <- 1
cat(sprintf("%d out of %d flipped variants detecte by kriging_rss. \n",
length(intersect(detected_index, flip_index)), length(flip_index)))
10 out of 10 flipped variants detecte by kriging_rss.
condz$conditional_dist[union(flip_index, detected_index),]
z condmean condvar z_std_diff logLR flipped detected
820 -6.885113 6.714560 0.3269829 -23.782961 9.627679 1 1
458 -2.674648 2.647015 0.3673281 -8.780521 8.338206 1 1
393 -2.609874 2.609901 0.3229037 -9.185765 8.360083 1 1
1515 -4.332197 3.929706 0.3614657 -13.741893 8.300118 1 1
1605 -3.291488 2.690636 0.4585908 -8.833702 7.726878 1 1
743 -2.150657 2.265469 0.3324752 -7.658820 8.257533 1 1
697 -2.828630 2.753038 0.3239093 -9.807364 8.379124 1 1
1592 -3.545367 3.522010 0.3320191 -12.265259 8.542509 1 1
579 -2.205385 2.007778 0.3299552 -7.334673 8.182472 1 1
766 -7.054485 6.753350 0.3287578 -24.081724 9.521240 1 1
ggplot(condz$conditional_dist, aes(x = condmean, y = z, col = factor(flipped))) +
geom_point() +
scale_colour_manual(values = c("0" = "black", "1" = "red")) +
labs(x = "Expected", y = "Observed z scores", color = "Allele flipped") +
theme_bw()
ggplot(condz$conditional_dist, aes(x = condmean, y = z, col = factor(detected))) +
geom_point() +
scale_colour_manual(values = c("0" = "black", "1" = "red")) +
labs(x = "Expected", y = "Observed z scores", color = "Possible allele switched") +
theme_bw()
Version | Author | Date |
---|---|---|
c3fd810 | kevinlkx | 2023-10-27 |
sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /software/openblas-0.3.13-el7-x86_64/lib/libopenblas_haswellp-r0.3.13.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
[4] LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] susieR_0.12.27 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0
[5] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.1.8
[9] ggplot2_3.4.1 tidyverse_1.3.2 mapgen_0.5.6
loaded via a namespace (and not attached):
[1] googledrive_2.0.0 colorspace_2.1-0
[3] rjson_0.2.21 ellipsis_0.3.2
[5] rprojroot_2.0.3 XVector_0.38.0
[7] GenomicRanges_1.48.0 fs_1.6.1
[9] rstudioapi_0.14 farver_2.1.1
[11] bit64_4.0.5 fansi_1.0.4
[13] lubridate_1.9.2 xml2_1.3.3
[15] codetools_0.2-18 cachem_1.0.6
[17] knitr_1.42 jsonlite_1.8.4
[19] workflowr_1.7.0 Rsamtools_2.12.0
[21] broom_1.0.3 dbplyr_2.3.0
[23] compiler_4.2.0 httr_1.4.4
[25] backports_1.4.1 RcppZiggurat_0.1.6
[27] assertthat_0.2.1 Matrix_1.5-3
[29] fastmap_1.1.0 gargle_1.3.0
[31] cli_3.6.0 later_1.3.0
[33] htmltools_0.5.4 tools_4.2.0
[35] gtable_0.3.1 glue_1.6.2
[37] GenomeInfoDbData_1.2.9 Rcpp_1.0.10
[39] Biobase_2.58.0 cellranger_1.1.0
[41] jquerylib_0.1.4 vctrs_0.5.2
[43] Biostrings_2.66.0 rtracklayer_1.58.0
[45] xfun_0.37 plyranges_1.18.0
[47] rvest_1.0.3 timechange_0.2.0
[49] lifecycle_1.0.3 irlba_2.3.5
[51] restfulr_0.0.15 XML_3.99-0.13
[53] googlesheets4_1.0.1 zlibbioc_1.44.0
[55] scales_1.2.1 vroom_1.6.1
[57] hms_1.1.2 promises_1.2.0.1
[59] MatrixGenerics_1.10.0 parallel_4.2.0
[61] SummarizedExperiment_1.28.0 yaml_2.3.7
[63] sass_0.4.5 reshape_0.8.9
[65] stringi_1.7.12 highr_0.10
[67] BiocIO_1.8.0 S4Vectors_0.36.1
[69] BiocGenerics_0.44.0 BiocParallel_1.32.5
[71] GenomeInfoDb_1.34.9 rlang_1.0.6
[73] pkgconfig_2.0.3 matrixStats_0.63.0
[75] bitops_1.0-7 evaluate_0.20
[77] lattice_0.20-45 labeling_0.4.2
[79] GenomicAlignments_1.34.0 Rfast_2.0.6
[81] bit_4.0.5 tidyselect_1.2.0
[83] plyr_1.8.7 magrittr_2.0.3
[85] R6_2.5.1 IRanges_2.32.0
[87] generics_0.1.3 DelayedArray_0.24.0
[89] DBI_1.1.3 pillar_1.8.1
[91] haven_2.5.1 whisker_0.4
[93] withr_2.5.0 RCurl_1.98-1.10
[95] mixsqp_0.3-43 modelr_0.1.10
[97] crayon_1.5.2 utf8_1.2.3
[99] tzdb_0.3.0 rmarkdown_2.20
[101] grid_4.2.0 readxl_1.4.2
[103] data.table_1.14.6 git2r_0.30.1
[105] reprex_2.0.2 digest_0.6.31
[107] httpuv_1.6.5 stats4_4.2.0
[109] munsell_0.5.0 bslib_0.4.2