├── .Rbuildignore ├── .travis.yml ├── misc ├── figures │ └── finemap-2causal.png ├── rmd │ ├── figures │ │ ├── plot_caviar-1.png │ │ ├── plot_finemap-1.png │ │ └── plot_paintor-1.png │ ├── caviar.Rmd │ ├── paintor.Rmd │ ├── caviar.md │ ├── paintor.md │ ├── finemap.Rmd │ └── finemap.md ├── learn │ ├── ref-1K │ │ └── readme.md │ └── 02-abf │ │ ├── 02-abf.Rmd │ │ └── 02-abf.md ├── tools-ld-computation.md ├── articles.md ├── scripts │ └── 01-front-fig.R └── install-finemaping-tools.md ├── .gitignore ├── demo ├── caviar.R ├── finemap.R ├── paintor.R ├── bmi.R ├── num-causal-snps.R └── sumstats.R ├── man ├── finemaprPackage.Rd ├── read_ld.Rd ├── read_zscore.Rd ├── proxysnps_ref_ld.Rd ├── proxysnps_ref_vcf.Rd ├── sumstats_bmi.Rd ├── run_paintor.Rd ├── run_finemap.Rd ├── cojo.Rd ├── FinemaprCaviar.Rd ├── finemapr.Rd ├── run_caviar.Rd ├── FinemaprPaintor.Rd ├── Finemapr.Rd └── FinemaprFinemap.Rd ├── R ├── sumstats.R ├── package.R ├── utils.R ├── zzz.R ├── names.R ├── datasets.R ├── classFinemaprCaviar.R ├── read.R ├── files.R ├── abf.R ├── plots.R ├── finemap.R ├── caviar.R ├── paintor.R ├── classMethods.R ├── classFinemaprPaintor.R ├── ld.R ├── cojo.R ├── finemapr.R └── classFinemaprFinemap.R ├── DESCRIPTION ├── inst └── extdata │ ├── region1.z │ └── region1.ld ├── README.md ├── NAMESPACE ├── vignettes └── finemapr.Rmd └── LICENSE /.Rbuildignore: -------------------------------------------------------------------------------- 1 | misc/ 2 | 3 | # runs of tools 4 | run_*/ 5 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | cache: packages 3 | warnings_are_errors: false 4 | -------------------------------------------------------------------------------- /misc/figures/finemap-2causal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/variani/finemapr/HEAD/misc/figures/finemap-2causal.png -------------------------------------------------------------------------------- /misc/rmd/figures/plot_caviar-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/variani/finemapr/HEAD/misc/rmd/figures/plot_caviar-1.png -------------------------------------------------------------------------------- /misc/rmd/figures/plot_finemap-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/variani/finemapr/HEAD/misc/rmd/figures/plot_finemap-1.png -------------------------------------------------------------------------------- /misc/rmd/figures/plot_paintor-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/variani/finemapr/HEAD/misc/rmd/figures/plot_paintor-1.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | \.DS_Store 2 | 3 | # running tools 4 | run_*/ 5 | 6 | # rmd 7 | *\.html 8 | *_cache/ 9 | figures/ 10 | 11 | inst/doc 12 | 13 | # vignettes/ 14 | vignettes/*figures/ 15 | -------------------------------------------------------------------------------- /misc/learn/ref-1K/readme.md: -------------------------------------------------------------------------------- 1 | 2 | ## Example of fetching a region from 1K 3 | 4 | - https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R 5 | - based on http://tabix.iobio.io/ service 6 | -------------------------------------------------------------------------------- /demo/caviar.R: -------------------------------------------------------------------------------- 1 | options(finemapr_caviar = "~/apps/caviar/CAVIAR") 2 | 3 | ex <- example_finemap() 4 | 5 | out <- run_caviar(ex$tab1, ex$ld1, args = "-c 3") 6 | 7 | print(out) 8 | 9 | plot(out) 10 | -------------------------------------------------------------------------------- /demo/finemap.R: -------------------------------------------------------------------------------- 1 | options(finemapr_finemap = "~/apps/finemap/finemap") 2 | 3 | ex <- example_finemap() 4 | 5 | out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 3") 6 | 7 | print(out) 8 | 9 | plot(out) 10 | -------------------------------------------------------------------------------- /man/finemaprPackage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{package} 4 | \name{finemaprPackage} 5 | \alias{finemaprPackage} 6 | \title{Package finemapr.} 7 | \description{ 8 | R wrapper to fine-mappers. 9 | } 10 | -------------------------------------------------------------------------------- /demo/paintor.R: -------------------------------------------------------------------------------- 1 | #options(finemapr_caviar = "~/apps/paintor/CAVIAR") 2 | 3 | ex <- example_finemap() 4 | 5 | #out <- run_paintor(ex$tab1, ex$ld1, ex$n1, args = "-enumerate 3") 6 | out <- finemapr(list(ex$tab1, ex$tab2), list(ex$ld1, ex$ld2), list(ex$n1, ex$n2), method = "paintor", args = "-enumerate 4") 7 | 8 | print(out) 9 | 10 | plot(out) 11 | -------------------------------------------------------------------------------- /man/read_ld.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read.R 3 | \name{read_ld} 4 | \alias{read_ld} 5 | \title{Read LD matrix from a file.} 6 | \usage{ 7 | read_ld(file_ld, snps) 8 | } 9 | \description{ 10 | Read LD matrix from a file. 11 | } 12 | \examples{ 13 | f1 <- system.file("extdata/region1.ld", package = "finemapr") 14 | ld <- read_ld(f1) 15 | 16 | } 17 | -------------------------------------------------------------------------------- /man/read_zscore.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read.R 3 | \name{read_zscore} 4 | \alias{read_zscore} 5 | \title{Read z-scores from a file.} 6 | \usage{ 7 | read_zscore(file_zscore) 8 | } 9 | \description{ 10 | Read z-scores from a file. 11 | } 12 | \examples{ 13 | f1 <- system.file("extdata/region1.z", package = "finemapr") 14 | ztab <- read_zscore(f1) 15 | 16 | } 17 | -------------------------------------------------------------------------------- /misc/tools-ld-computation.md: -------------------------------------------------------------------------------- 1 | ## emeraLD 2 | 3 | - article [emeraLD: Rapid Linkage Disequilibrium Estimation with Massive Data Sets, 2018](https://www.biorxiv.org/content/early/2018/04/15/301366) 4 | - https://github.com/statgen/emeraLD 5 | 6 | > Here, we describe emeraLD (Efficient Methods for Estimation and Random Access of LD), a computational tool that leverages sparsity and haplotype 7 | structure to estimate LD orders of magnitude faster than existing tools. 8 | 9 | -------------------------------------------------------------------------------- /R/sumstats.R: -------------------------------------------------------------------------------- 1 | #' 2 | #' 3 | #' https://data.broadinstitute.org/alkesgroup/sumstats_formatted/readme.txt 4 | #' https://github.com/bulik/ldsc/wiki/Partitioned-Heritability 5 | #' 6 | #' @export 7 | sumstats_bmi <- function() 8 | { 9 | url <- "https://data.broadinstitute.org/alkesgroup/sumstats_formatted/PASS_BMI1.sumstats" 10 | 11 | read_tsv(url, col_types = cols()) %>% 12 | mutate(P = pchisq(CHISQ, df = 1, lower.tail = FALSE)) %>% 13 | select(-CHISQ) 14 | } 15 | -------------------------------------------------------------------------------- /man/proxysnps_ref_ld.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ld.R 3 | \name{proxysnps_ref_ld} 4 | \alias{proxysnps_ref_ld} 5 | \title{https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R} 6 | \usage{ 7 | proxysnps_ref_ld( 8 | vcf, 9 | tol = 1e-10, 10 | measure = c("R.squared", "D.prime"), 11 | verbose = 0 12 | ) 13 | } 14 | \description{ 15 | https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R 16 | } 17 | -------------------------------------------------------------------------------- /man/proxysnps_ref_vcf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ld.R 3 | \name{proxysnps_ref_vcf} 4 | \alias{proxysnps_ref_vcf} 5 | \title{https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R} 6 | \usage{ 7 | proxysnps_ref_vcf( 8 | chr = 16, 9 | start = 53767000, 10 | end = 53768000, 11 | pop = "EUR", 12 | snps = NULL, 13 | verbose = 0 14 | ) 15 | } 16 | \description{ 17 | https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R 18 | } 19 | -------------------------------------------------------------------------------- /man/sumstats_bmi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sumstats.R 3 | \name{sumstats_bmi} 4 | \alias{sumstats_bmi} 5 | \title{https://data.broadinstitute.org/alkesgroup/sumstats_formatted/readme.txt 6 | https://github.com/bulik/ldsc/wiki/Partitioned-Heritability} 7 | \usage{ 8 | sumstats_bmi() 9 | } 10 | \description{ 11 | https://data.broadinstitute.org/alkesgroup/sumstats_formatted/readme.txt 12 | https://github.com/bulik/ldsc/wiki/Partitioned-Heritability 13 | } 14 | -------------------------------------------------------------------------------- /man/run_paintor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/paintor.R 3 | \name{run_paintor} 4 | \alias{run_paintor} 5 | \title{Run Paintor.} 6 | \usage{ 7 | run_paintor( 8 | tab, 9 | ld, 10 | n, 11 | annot, 12 | annotations, 13 | dir_run = "run_paintor", 14 | tool = getOption("finemapr_paintor"), 15 | args = "" 16 | ) 17 | } 18 | \description{ 19 | Run Paintor. 20 | } 21 | \examples{ 22 | ex <- example_finemap() 23 | out <- run_paintor(ex$tab1, ex$ld1) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /demo/bmi.R: -------------------------------------------------------------------------------- 1 | ### par 2 | window <- 500e3 3 | 4 | ### data 5 | ss <- sumstats_bmi() 6 | 7 | ### region 8 | # rs1421085: Chr16: 53800954 (on Assembly GRCh37) 9 | # https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5025863/ 10 | 11 | ld <- ref_ld(chr = 16, start = 53800954 - window/2, end = 53800954 + window/2, verbose = 1) 12 | 13 | snps_region <- rownames(ld) 14 | ss_region <- filter(ss, SNP %in% snps_region) 15 | 16 | ### fine mapping 17 | n <- with(ss_region, round(mean(N), 0)) 18 | 19 | out <- finemapr(ss_region, ld, n, args = "--n-causal-max 3") 20 | 21 | print(out) 22 | 23 | plot(out) 24 | -------------------------------------------------------------------------------- /man/run_finemap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/finemap.R 3 | \name{run_finemap} 4 | \alias{run_finemap} 5 | \title{Run FINEMAP.} 6 | \usage{ 7 | run_finemap( 8 | tab, 9 | ld, 10 | n, 11 | dir_run = "run_finemap", 12 | tool = getOption("finemapr_finemap"), 13 | args = "" 14 | ) 15 | } 16 | \description{ 17 | Run FINEMAP. 18 | } 19 | \examples{ 20 | ex <- example_finemap() 21 | out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 3") 22 | out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 1") 23 | 24 | } 25 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | #' Package finemapr. 2 | #' 3 | #' R wrapper to fine-mappers. 4 | #' 5 | #' @rdname finemaprPackage 6 | #' @name finemaprPackage 7 | #' @docType package 8 | #' 9 | #' @importFrom utils head write.table 10 | #' 11 | #' @importFrom tibble data_frame as_data_frame 12 | #' @importFrom dplyr mutate select select_ arrange filter everything left_join 13 | #' @importFrom magrittr %>% %$% 14 | #' @importFrom readr read_delim write_delim write_lines read_lines read_tsv cols write_file write_tsv 15 | #' 16 | #' @import Matrix 17 | #' @import ggplot2 18 | #' @import ggrepel 19 | #' @importFrom cowplot plot_grid 20 | {} 21 | 22 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | 2 | #------------------ 3 | # data processing 4 | #------------------ 5 | 6 | prepare_zscore_writing <- function(tab) 7 | { 8 | filter(tab, finemap) %>% select(snp, zscore) 9 | } 10 | 11 | merge_tab_snp <- function(tab, snp) 12 | { 13 | select(tab, rank_z, snp) %>% 14 | left_join(snp, by = "snp") %>% 15 | select(snp, rank_z, rank_pp, everything()) %>% 16 | arrange(rank_pp) 17 | } 18 | 19 | #---------------- 20 | # LD 21 | #---------------- 22 | 23 | simulate_ld_diag <- function(snps) 24 | { 25 | ld <- diag(length(snps)) 26 | rownames(ld) <- snps 27 | colnames(ld) <- snps 28 | 29 | return(ld) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /man/cojo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cojo.R 3 | \name{cojo} 4 | \alias{cojo} 5 | \title{Run GCTA-COJO.} 6 | \usage{ 7 | cojo( 8 | tab, 9 | bed, 10 | method = c("select", "cond"), 11 | cmd = "", 12 | snps_cond = NULL, 13 | dir_run = "run_cojo", 14 | tool = getOption("finemapr_cojo"), 15 | args = "" 16 | ) 17 | } 18 | \description{ 19 | http://gcta.freeforums.net/thread/178/conditional-joint-analysis-using-summary 20 | } 21 | \details{ 22 | tab <- "~/git/hemostat/scc/results/sumstats-cojo/sumstats-1.cojo" 23 | bed <- "~/git/hemostat/scc/data/FineMapping/forGCTA_onco_r1.bed" 24 | } 25 | -------------------------------------------------------------------------------- /man/FinemaprCaviar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/classFinemaprCaviar.R 3 | \name{FinemaprCaviar} 4 | \alias{FinemaprCaviar} 5 | \alias{print.FinemaprCaviar} 6 | \alias{plot.FinemaprCaviar} 7 | \alias{plot_snp.FinemaprCaviar} 8 | \title{S3 class FinemaprCaviar.} 9 | \usage{ 10 | print.FinemaprCaviar(x, ...) 11 | 12 | \method{plot}{FinemaprCaviar}(x, ...) 13 | 14 | \method{plot_snp}{FinemaprCaviar}( 15 | x, 16 | lim_prob = c(0, 1.5), 17 | label_size = getOption("finemapr_label_size"), 18 | top_rank = getOption("top_rank"), 19 | ... 20 | ) 21 | } 22 | \description{ 23 | S3 class FinemaprCaviar. 24 | } 25 | -------------------------------------------------------------------------------- /misc/articles.md: -------------------------------------------------------------------------------- 1 | ## Applications 2 | 3 | [Fine-mapping of an expanded set of type 2 diabetes loci to single-variant resolution using high-density imputation and islet-specific epigenome maps, 2018](https://www.biorxiv.org/content/early/2018/01/09/245506) 4 | 5 | - Approximate conditional analysis by GCTA (Online Methods, p. 34) "to delineate **distinct association signals** arising from multiple causal variants in the same locus" 6 | - 6,000 individuals from UK Biobak as a reference panel for LD 7 | - Fine-mapping of distinct signals by (i) ABF; (ii) fGWAS 8 | 9 | [Refining The Accuracy Of Validated Target Identification Through Coding Variant Fine-Mapping In Type 2 Diabetes, 2017](https://www.biorxiv.org/content/early/2017/12/13/144410) 10 | -------------------------------------------------------------------------------- /man/finemapr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/finemapr.R 3 | \name{finemapr} 4 | \alias{finemapr} 5 | \title{Run FINEMAP.} 6 | \usage{ 7 | finemapr( 8 | tab, 9 | ld, 10 | n, 11 | annot, 12 | annotations, 13 | prop_credible = 0.95, 14 | method = c("finemap", "paintor"), 15 | dir_run, 16 | tool, 17 | args = "", 18 | prior_k, 19 | save_ld = FALSE, 20 | ret = c("results", "zscore", "ld") 21 | ) 22 | } 23 | \description{ 24 | Run FINEMAP. 25 | } 26 | \examples{ 27 | ex <- example_finemap() 28 | out <- finemapr(list(ex$tab1, ex$tab2), list(ex$ld1, ex$ld2), list(ex$n1, ex$n2), args = "--n-causal-max 1") 29 | out <- finemapr(list(ex$tab1, ex$tab2), list(ex$ld1, ex$ld2), list(ex$n1, ex$n2), method = "paintor", args = "-enumerate 1") 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/run_caviar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caviar.R 3 | \name{run_caviar} 4 | \alias{run_caviar} 5 | \title{Run CAVIAR.} 6 | \usage{ 7 | run_caviar( 8 | tab, 9 | ld, 10 | dir_run = "run_caviar", 11 | tool = getOption("finemapr_caviar"), 12 | args = "" 13 | ) 14 | } 15 | \description{ 16 | Output file (`*_post`): 17 | column #1 is the variant name; 18 | column #2 is the posterior prob. that the variant is causal 19 | (https://github.com/fhormoz/caviar/issues/1#issuecomment-286521771); 20 | column #3 is the amount that this variant contributes to 21 | 95%-causal credible set. 22 | } 23 | \examples{ 24 | ex <- example_finemap() 25 | out <- run_caviar(ex$tab1, ex$ld1, args = "-c 2") 26 | out <- run_caviar(ex$tab1, ex$ld1, args = "-c 0") 27 | 28 | } 29 | -------------------------------------------------------------------------------- /misc/scripts/01-front-fig.R: -------------------------------------------------------------------------------- 1 | library(devtools) 2 | load_all("~/git/variani/finemapr") 3 | 4 | library(magrittr) 5 | library(dplyr) 6 | 7 | library(ggplot2) 8 | theme_set(theme_linedraw()) 9 | 10 | ### data 11 | file1_z <- system.file("extdata/region1.z", package = "finemapr") 12 | file1_ld <- system.file("extdata/region1.ld", package = "finemapr") 13 | 14 | z1 <- read_zscore(file1_z) 15 | ld1 <- read_ld(file1_ld, snps = z1$snp) 16 | n1 <- 5363 17 | 18 | ### run finemap 19 | options(finemapr_finemap = "~/apps/finemap/finemap") 20 | 21 | out_finemap <- run_finemap(z1, ld1, n1, args = "--n-causal-max 3") 22 | 23 | ### plot 24 | plot(out_finemap, label_size = 3, 25 | lim_prob_config = c(0, 1.6), lim_prob_snp = c(0, 3), lim_prob_ncausal = c(0, 1), 26 | grid_nrow = 1) 27 | 28 | ### save fig. 29 | ggsave("misc/figures/finemap-2causal.png", 30 | width = 9, height = 4, units = "in", dpi = 200) 31 | 32 | -------------------------------------------------------------------------------- /misc/rmd/caviar.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | html_document: 4 | keep_md: true 5 | --- 6 | 7 | 8 | ```{r options, echo = F} 9 | opts_chunk$set(dev = "png", dev.args = list(type = "cairo"), dpi = 192, fig.path = "figures/", comment = NA, results = 'markup', tidy = F, message = F, warning = F, echo = T) 10 | ``` 11 | 12 | ```{r inc, echo = F} 13 | library(devtools) 14 | load_all("~/git/variani/finemapr") 15 | ``` 16 | 17 | ```{r ex} 18 | # specify path to CAVIAR (user-specific) 19 | options(finemapr_caviar = "~/apps/caviar/CAVIAR") 20 | 21 | # load the same example data as for FINEMAP 22 | ex <- example_finemap() 23 | 24 | # run the tool 25 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 26 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 27 | # - arg. `args`: pass other arguments to the tool as a string 28 | out_caviar <- run_caviar(ex$tab1, ex$ld1, args = "-c 3") 29 | ``` 30 | 31 | ```{r print} 32 | print(out_caviar) 33 | ``` 34 | 35 | ```{r plot_caviar, fig.width = 6, fig.height = 3} 36 | plot(out_caviar, label_size = 3) 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /demo/num-causal-snps.R: -------------------------------------------------------------------------------- 1 | # demo: shows how to specify the number of causal loci 2 | # - finemap: note that the argument name `--n-causal-max`/`--n-causal-snps` 3 | # differs by finemap version (http://www.christianbenner.com/) 4 | 5 | ### load example data 6 | ex <- example_finemap() 7 | 8 | ### run finemap 9 | # `--n-causal-max` is missing; the number of causal snps is infered from `prior_k` 10 | out1 <- finemapr(ex$tab1, ex$ld1, ex$n1, method = "finemap", prior_k = rep(1, 4)) 11 | 12 | # values specifed in `--n-causal-max` and `prior_k` are concordant 13 | # (the number of causal snps = 2) 14 | out2 <- finemapr(ex$tab1, ex$ld1, ex$n1, method = "finemap", prior_k = rep(1, 2), args = "--n-causal-max 2") 15 | 16 | # values specifed in `--n-causal-max` and `prior_k` are in conflict, but `prior_k` matters 17 | # (the number of causal snps = 2) 18 | out3 <- finemapr(ex$tab1, ex$ld1, ex$n1, method = "finemap", prior_k = rep(1, 2), args = "--n-causal-max 4") 19 | 20 | # (the number of causal snps = 3) specified in `--n-causal-max` 21 | out4 <- finemapr(ex$tab1, ex$ld1, ex$n1, method = "finemap", args = "--n-causal-max 3") 22 | 23 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: finemapr 2 | Title: R wrapper to fine-mappers 3 | Version: 0.1.0 4 | Date: 2018-02-09 5 | Authors@R: c(person("Andrey", "Ziyatdinov", email = "andrey@example.com", role = c("aut", "cre"))) 6 | Maintainer: Andrey Ziyatdinov 7 | Description: R wrapper to fine-mappers. 8 | License: GPL (>= 3) 9 | URL: https://github.com/variani/finemapr 10 | Imports: 11 | tibble, 12 | dplyr, 13 | readr, 14 | magrittr, 15 | ggplot2, 16 | cowplot, 17 | data.table, 18 | Matrix 19 | Suggests: 20 | proxysnps, 21 | RCurl, 22 | gaston, 23 | rsnps, 24 | testthat, 25 | knitr, 26 | rmarkdown 27 | Collate: 28 | 'package.R' 29 | 'names.R' 30 | 'sumstats.R' 31 | 'abf.R' 32 | 'cojo.R' 33 | 'utils.R' 34 | 'read.R' 35 | 'datasets.R' 36 | 'files.R' 37 | 'plots.R' 38 | 'finemap.R' 39 | 'caviar.R' 40 | 'paintor.R' 41 | 'classMethods.R' 42 | 'classFinemaprPaintor.R' 43 | 'classFinemaprFinemap.R' 44 | 'classFinemaprCaviar.R' 45 | 'finemapr.R' 46 | 'ld.R' 47 | 'zzz.R' 48 | RoxygenNote: 7.1.1 49 | VignetteBuilder: knitr 50 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | finemapr_guess_tool <- function(tool = c("finemap", "caviar", "paintor", "cojo")) 2 | { 3 | tool <- match.arg(tool) 4 | 5 | tool_bin <- switch(tool, 6 | "finemap" = "finemap", 7 | "caviar" = "CAVIAR", 8 | "paintor" = "paintor", 9 | "cojo" = "gcta", 10 | stop()) 11 | 12 | path_apps <- file.path("~/.local/apps/", tool) 13 | file_apps <- file.path(path_apps, tool_bin) 14 | 15 | if(file.exists(file_apps)) { 16 | return(file_apps) 17 | } 18 | 19 | return(tool_bin) 20 | } 21 | 22 | .onLoad <- function(libname, pkgname) { 23 | op <- options() 24 | 25 | op_finemapr <- list( 26 | # paths to tools 27 | finemapr_finemap = finemapr_guess_tool("finemap"), 28 | finemapr_caviar = finemapr_guess_tool("caviar"), 29 | finemapr_paintor = finemapr_guess_tool("paintor"), 30 | finemapr_cojo = finemapr_guess_tool("cojo"), 31 | # plot 32 | finemapr_label_size = 4, 33 | top_rank = 5, 34 | lim_prob = c(0, 1.5) 35 | ) 36 | 37 | ind_set <- !(names(op_finemapr) %in% names(op)) 38 | if(any(ind_set)) { 39 | options(op_finemapr[ind_set]) 40 | } 41 | 42 | invisible() 43 | } 44 | -------------------------------------------------------------------------------- /misc/rmd/paintor.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | html_document: 4 | keep_md: true 5 | --- 6 | 7 | 8 | ```{r options, echo = F} 9 | opts_chunk$set(dev = "png", dev.args = list(type = "cairo"), dpi = 192, fig.path = "figures/", comment = NA, results = 'markup', tidy = F, message = F, warning = F, echo = T) 10 | ``` 11 | 12 | ```{r inc, echo = F} 13 | library(devtools) 14 | load_all("~/git/variani/finemapr") 15 | ``` 16 | 17 | ```{r ex} 18 | # specify path to PAINTOR (user-specific) 19 | options(finemapr_paintor = "~/apps/paintor/PAINTOR") 20 | 21 | # load the same example data as for FINEMAP 22 | ex <- example_finemap() 23 | 24 | # run the tool 25 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 26 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 27 | # - arg. #3 (optional; the default value is 1,000,000): the number of invidivudals 28 | # - arg. `args`: pass other arguments to the tool as a string 29 | out_paintor <- run_paintor(ex$tab1, ex$ld1, ex$n1, args = "-enumerate 3") 30 | ``` 31 | 32 | ```{r print} 33 | print(out_paintor) 34 | ``` 35 | 36 | ```{r plot_paintor, fig.width = 6, fig.height = 3} 37 | plot(out_paintor, label_size = 3) 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /R/names.R: -------------------------------------------------------------------------------- 1 | #----------------- 2 | # Names in table of Z-scores 3 | #----------------- 4 | finemapr_names_tab_snp <- function() "snp" 5 | 6 | finemapr_names_tab_zscore <- function() "zscore" 7 | 8 | finemapr_names_tab_pos <- function() "pos" 9 | 10 | finemapr_names_tab <- function() 11 | { 12 | c(finemapr_names_tab_snp(), 13 | finemapr_names_tab_zscore()) 14 | } 15 | 16 | #----------------- 17 | # Find names 18 | #----------------- 19 | finemapr_find_name <- function(target = c("snp", "zscore", "pos"), 20 | candidates, strict = FALSE) 21 | { 22 | target <- match.arg(target) 23 | 24 | pat <- switch(target, 25 | "snp" = "^snp$|^SNP$|^id$|^ID$|^marker|^Marker", 26 | "zscore" = "^zscore$|^Zscore$|^z$|^Z$", 27 | "pos" = "^pos|^Pos|^bp$|^BP$", 28 | stop("error in switch")) 29 | 30 | matches <- grep(pat, candidates, value = TRUE) 31 | if(length(matches) == 0) { 32 | if(strict) { 33 | stop("matches for '", target, "' not found; `grep` pattern '", pat, "'") 34 | } 35 | } 36 | if(length(matches) > 1) { 37 | stop(">1 matches found (`", paste(matches, collapse = ", "), "`); grep pattern '", pat, "'") 38 | } 39 | 40 | if(length(matches) == 0) { 41 | matches <- NULL 42 | } 43 | 44 | return(matches) 45 | } 46 | -------------------------------------------------------------------------------- /man/FinemaprPaintor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R, R/classFinemaprPaintor.R 3 | \name{filename_zscore.FinemaprPaintor} 4 | \alias{filename_zscore.FinemaprPaintor} 5 | \alias{filename_ld.FinemaprPaintor} 6 | \alias{filename_annot.FinemaprPaintor} 7 | \alias{filename_master.FinemaprPaintor} 8 | \alias{filename_snp.FinemaprPaintor} 9 | \alias{FinemaprPaintor} 10 | \alias{print.FinemaprPaintor} 11 | \alias{process_annot.FinemaprPaintor} 12 | \alias{write_files.FinemaprPaintor} 13 | \alias{run_tool.FinemaprPaintor} 14 | \alias{collect_results.FinemaprPaintor} 15 | \title{S3 class FinemaprPaintor.} 16 | \usage{ 17 | \method{filename_zscore}{FinemaprPaintor}(x, locus = 1) 18 | 19 | \method{filename_ld}{FinemaprPaintor}(x, locus = 1) 20 | 21 | \method{filename_annot}{FinemaprPaintor}(x, locus = 1) 22 | 23 | \method{filename_master}{FinemaprPaintor}(x) 24 | 25 | \method{filename_snp}{FinemaprPaintor}(x, locus) 26 | 27 | print.FinemaprPaintor(x, ...) 28 | 29 | \method{process_annot}{FinemaprPaintor}(x, annots, annotations, ...) 30 | 31 | \method{write_files}{FinemaprPaintor}(x, ...) 32 | 33 | \method{run_tool}{FinemaprPaintor}(x, ...) 34 | 35 | \method{collect_results}{FinemaprPaintor}(x, ...) 36 | } 37 | \description{ 38 | S3 class FinemaprPaintor. 39 | } 40 | -------------------------------------------------------------------------------- /misc/rmd/caviar.md: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | html_document: 4 | keep_md: true 5 | --- 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ```r 14 | # specify path to CAVIAR (user-specific) 15 | options(finemapr_caviar = "~/apps/caviar/CAVIAR") 16 | 17 | # load example data 18 | ex <- example_finemap() 19 | 20 | # run the tool 21 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 22 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 23 | # - arg. `args`: pass other arguments to the tool as a string 24 | out_caviar <- run_caviar(ex$tab1, ex$ld1, args = "-c 3") 25 | ``` 26 | 27 | 28 | ```r 29 | print(out_caviar) 30 | ``` 31 | 32 | ``` 33 | - command: ~/apps/caviar/CAVIAR -c 3 -z region.z -l region.ld -o log 34 | - tables of results: `snp` 35 | - snp: 36 | # A tibble: 50 x 4 37 | rank snp snp_prob_set snp_prob 38 | 39 | 1 1 rs15 0.439 1.00 40 | 2 2 rs47 0.439 1.00 41 | 3 3 rs42 0.0120 0.0274 42 | # ... with 47 more rows 43 | - 95%-causal set (ordered): rs15, rs47, rs42, rs34, rs20, rs5, rs27, rs45, rs38, rs17, rs25, rs18, rs11, rs19, rs44, rs40, rs8, rs24 44 | ``` 45 | 46 | 47 | ```r 48 | plot(out_caviar, label_size = 3) 49 | ``` 50 | 51 | ![](figures/plot_caviar-1.png) 52 | 53 | -------------------------------------------------------------------------------- /inst/extdata/region1.z: -------------------------------------------------------------------------------- 1 | rs1 3.5838388228282 2 | rs2 4.36435707667031 3 | rs3 3.71197172445435 4 | rs4 -1.28317427660188 5 | rs5 -3.82938078539939 6 | rs6 1.52417028887483 7 | rs7 2.53453306847583 8 | rs8 -1.07238461611355 9 | rs9 0.111171763503774 10 | rs10 2.79076362014481 11 | rs11 -4.84573083544716 12 | rs12 4.09843950251981 13 | rs13 4.1462517319445 14 | rs14 3.22912161554024 15 | rs15 10.9151877677707 16 | rs16 2.26566672617849 17 | rs17 -5.58542972445637 18 | rs18 -0.205106276088423 19 | rs19 -0.283760813237599 20 | rs20 -3.8436717827585 21 | rs21 1.06334661116109 22 | rs22 -1.98036414916215 23 | rs23 5.77263135217497 24 | rs24 0.850765199947799 25 | rs25 -0.132626593136605 26 | rs26 4.71837648319816 27 | rs27 -3.70959192223257 28 | rs28 0.9599234730172 29 | rs29 0.973448781412623 30 | rs30 -0.440404260252925 31 | rs31 3.5010970869473 32 | rs32 3.5273605644176 33 | rs33 3.92576185339307 34 | rs34 -4.06128229211626 35 | rs35 1.1558411381328 36 | rs36 1.38757074338373 37 | rs37 3.5878105692393 38 | rs38 -3.14795271299296 39 | rs39 1.74542376873308 40 | rs40 0.925028548728467 41 | rs41 -0.622621973736251 42 | rs42 -4.98516180857357 43 | rs43 -4.50610028076704 44 | rs44 -0.526441742945328 45 | rs45 -3.79253507706063 46 | rs46 -4.55582927175797 47 | rs47 8.79958766387385 48 | rs48 -4.41622891081851 49 | rs49 -0.420783066829481 50 | rs50 -3.86853500499902 51 | -------------------------------------------------------------------------------- /R/datasets.R: -------------------------------------------------------------------------------- 1 | #--------------------------- 2 | # Datasets from finemap 3 | #--------------------------- 4 | 5 | #' @export 6 | example_finemap <- function(dir_example = "~/.local/apps/finemap/example/") 7 | { 8 | ### read 9 | master <- read_delim(file.path(dir_example, "data"), 10 | delim = ";", col_names = TRUE, col_types = cols()) 11 | 12 | ### dataset 1 13 | tab1 <- read_delim(file.path(dir_example, "region1.z"), 14 | delim = " ", col_names = FALSE, col_types = cols()) 15 | names(tab1) <- c("snp", "zscore") 16 | 17 | ld1 <- read_delim(file.path(dir_example, "region1.ld"), 18 | delim = " ", col_names = FALSE, col_types = cols()) 19 | ld1 <- as.matrix(ld1) 20 | rownames(ld1) <- tab1$snp 21 | colnames(ld1) <- tab1$snp 22 | 23 | n1 <- master[["n-ind"]][1] 24 | 25 | ### dataset 2 26 | tab2 <- read_delim(file.path(dir_example, "region2.z"), 27 | delim = " ", col_names = FALSE, col_types = cols()) 28 | names(tab2) <- c("snp", "zscore") 29 | 30 | ld2 <- read_delim(file.path(dir_example, "region2.ld"), 31 | delim = " ", col_names = FALSE, col_types = cols()) 32 | ld2 <- as.matrix(ld2) 33 | rownames(ld2) <- tab2$snp 34 | colnames(ld2) <- tab2$snp 35 | 36 | n2 <- master[["n-ind"]][2] 37 | 38 | ### return 39 | list(tab1 = tab1, ld1 = ld1, n1 = n1, 40 | tab2 = tab2, ld2 = ld2, n2 = n2) 41 | } 42 | -------------------------------------------------------------------------------- /misc/rmd/paintor.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ```r 9 | # specify path to PAINTOR (user-specific) 10 | options(finemapr_paintor = "~/apps/paintor/PAINTOR") 11 | 12 | # load the same example data as for FINEMAP 13 | ex <- example_finemap() 14 | 15 | # run the tool 16 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 17 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 18 | # - arg. #3 (optional; the default value is 1,000,000): the number of invidivudals 19 | # - arg. `args`: pass other arguments to the tool as a string 20 | out_paintor <- run_paintor(ex$tab1, ex$ld1, ex$n1, args = "-enumerate 3") 21 | ``` 22 | 23 | 24 | ```r 25 | print(out_paintor) 26 | ``` 27 | 28 | ``` 29 | - command: ~/apps/paintor/PAINTOR -input region.master -Zhead zscore -LDname ld -annotations dummy_ones -enumerate 3 -num_samples 5363 30 | - tables of results: `snp` 31 | - snp: 32 | # A tibble: 50 x 4 33 | rank snp zscore snp_prob 34 | 35 | 1 1 rs15 10.9151878 1.000000 36 | 2 2 rs47 8.7995877 1.000000 37 | 3 3 rs25 -0.1326266 0.020042 38 | # ... with 47 more rows 39 | - annotations: dummy_ones 40 | - logBF (proportional to the model likelihood): 100.7274 41 | ``` 42 | 43 | 44 | ```r 45 | plot(out_paintor, label_size = 3) 46 | ``` 47 | 48 | ![](figures/plot_paintor-1.png) 49 | 50 | -------------------------------------------------------------------------------- /man/Finemapr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R, R/classMethods.R, R/finemapr.R 3 | \name{plot_zscore.Finemapr} 4 | \alias{plot_zscore.Finemapr} 5 | \alias{Finemapr} 6 | \alias{plot_ncausal} 7 | \alias{print.Finemapr} 8 | \alias{plot.Finemapr} 9 | \alias{plot_snp.Finemapr} 10 | \alias{extract_credible_set.Finemapr} 11 | \alias{process_tab.Finemapr} 12 | \alias{process_ld.Finemapr} 13 | \title{S3 class Finemapr.} 14 | \usage{ 15 | \method{plot_zscore}{Finemapr}( 16 | x, 17 | locus = 1, 18 | label_size = getOption("finemapr_label_size"), 19 | selected, 20 | force = 20, 21 | color_main = "grey75", 22 | color_selected = "aquamarine4", 23 | color_credible = "dodgerblue4", 24 | color_missing = "brown", 25 | plot_missing = FALSE, 26 | ... 27 | ) 28 | 29 | plot_ncausal(x, ...) 30 | 31 | print.Finemapr(x, ...) 32 | 33 | print.Finemapr(x, ...) 34 | 35 | \method{plot}{Finemapr}(x, ...) 36 | 37 | \method{plot_snp}{Finemapr}( 38 | x, 39 | lim_prob = c(0, 1.5), 40 | label_size = getOption("finemapr_label_size"), 41 | top_rank = getOption("top_rank"), 42 | ... 43 | ) 44 | 45 | \method{extract_credible_set}{Finemapr}(x, ...) 46 | 47 | \method{process_tab}{Finemapr}(x, tabs, ...) 48 | 49 | \method{process_ld}{Finemapr}(x, lds, ...) 50 | } 51 | \description{ 52 | S3 class Finemapr. 53 | } 54 | \note{ 55 | Colors: http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf 56 | } 57 | -------------------------------------------------------------------------------- /demo/sumstats.R: -------------------------------------------------------------------------------- 1 | ### inc 2 | library(dplyr) 3 | 4 | library(rsnps) 5 | 6 | ### get data on summary stats from GWAS of BMI 7 | if(!exists("ss")) { 8 | ss <- sumstats_bmi() 9 | } 10 | 11 | ss %>% arrange(P) %>% head(5) 12 | 13 | ncbi_snp_query("rs1421085") # chr16:53,800,954 14 | 15 | ### select SNPs in a region of the top SNP rs1421085 16 | # - not possible, the data of `ss` has no info. about chr/pos 17 | # ss_region <- filter(ss, ...) 18 | 19 | ### get ref. genotypes 20 | if(!exists("vcf")) { 21 | vcf <- ref_vcf(chr = 16, start = 53.800e6, end = 53.801e6, pop = "EUR") 22 | } 23 | 24 | ### compute LD matrix 25 | ld <- ref_ld(vcf) 26 | 27 | image(ld) 28 | 29 | ### overlap snps 30 | ss_region <- data_frame(SNP = rownames(ld)) %>% 31 | left_join(ss, by = "SNP") %>% 32 | filter(!is.na(Z)) 33 | 34 | snps_region <- ss_region$SNP 35 | 36 | ld_region <- ld[snps_region, snps_region] 37 | 38 | ### run fine-mapping analysis 39 | zscore_region <- ss_region %>% select(SNP, Z) 40 | 41 | out <- run_paintor(zscore_region, as.matrix(ld_region), n_avr, args = "-enumerate 3") 42 | 43 | plot(out) 44 | 45 | ### additional example: get ref. genotypes for a given set of snps 46 | if(!exists("vcf_snps")) { 47 | vcf_snps <- ref_vcf(chr = 16, start = 53.800e6, end = 53.801e6, pop = "EUR", 48 | snps = c("rs12446228", "rs9939973", "rs9940128", "rs1421085")) 49 | 50 | # the computation of LD is faster on a reduced set of snps 51 | ld_snps <- ref_ld(vcf_snps) 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /misc/rmd/finemap.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | html_document: 4 | keep_md: true 5 | --- 6 | 7 | 8 | ```{r options, echo = F} 9 | opts_chunk$set(dev = "png", dev.args = list(type = "cairo"), dpi = 192, fig.path = "figures/", comment = NA, results = 'markup', tidy = F, message = F, warning = F, echo = T) 10 | ``` 11 | 12 | ```{r inc, echo = F} 13 | library(devtools) 14 | load_all("~/git/variani/finemapr") 15 | ``` 16 | 17 | ```{r ex} 18 | # specify where the FINEMAP tool is located (user-specific) 19 | # - the user needs to download and install the tool before the analysis 20 | # - here, the tool binary file is stored in `~/apps/finemap/` directory 21 | options(finemapr_finemap = "~/apps/finemap/finemap") 22 | 23 | # load example data from FINEMAP (http://www.christianbenner.com/) 24 | # - data are obtained from the same directory `~/apps/finemap/`, subdirectory `example` 25 | ex <- example_finemap() 26 | 27 | # run the tool 28 | # - simulated data in region 1 (used here in the analysis) assumed 2 causal SNPs 29 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 30 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 31 | # - arg. #3: the number of invidivudals 32 | # - arg. `args`: pass other arguments to the tool as a string 33 | out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 3") 34 | ``` 35 | 36 | ```{r print} 37 | print(out) 38 | ``` 39 | 40 | ```{r plot_finemap, fig.width = 6, fig.height = 9} 41 | plot(out, label_size = 3, grid_ncol = 1) 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /R/classFinemaprCaviar.R: -------------------------------------------------------------------------------- 1 | #' S3 class FinemaprCaviar. 2 | #' 3 | #' @name FinemaprCaviar 4 | #' @rdname FinemaprCaviar 5 | #' 6 | #' @exportClass FinemaprCaviar 7 | 8 | #' @rdname FinemaprCaviar 9 | #' @export 10 | print.FinemaprCaviar <- function(x, ...) 11 | { 12 | cat(" - command:", x$cmd, "\n") 13 | 14 | if(x$status) { 15 | #cat(" - see log output in `log`\n") 16 | cat(" - tables of results: `snp`\n") 17 | 18 | cat(" - snp:\n") 19 | print(x$snp, n = 3) 20 | 21 | cat(" - 95%-causal set (ordered):", paste(x$set, collapse = ", "), "\n") 22 | } 23 | } 24 | 25 | #' @rdname FinemaprCaviar 26 | #' @export 27 | plot.FinemaprCaviar <- function(x, ...) 28 | { 29 | plot_snp(x, ...) 30 | } 31 | 32 | #--------------- 33 | # Custom methods 34 | #--------------- 35 | 36 | #' @rdname FinemaprCaviar 37 | #' @export 38 | plot_snp.FinemaprCaviar <- function(x, lim_prob = c(0, 1.5), 39 | label_size = getOption("finemapr_label_size"), 40 | top_rank = getOption("top_rank"), 41 | ...) 42 | { 43 | ptab <- x$snp 44 | 45 | ptab <- head(ptab, top_rank) 46 | 47 | ptab <- mutate(ptab, 48 | label = paste0(snp, "\n", 49 | "P = ", round(snp_prob, 2), 50 | "; ", "P(set) = ", round(snp_prob_set, 2))) 51 | 52 | ggplot(ptab, aes(snp_prob, rank)) + 53 | geom_vline(xintercept = 1, linetype = 3) + 54 | geom_point() + 55 | geom_segment(aes(xend = snp_prob, yend = rank, x = 0)) + 56 | geom_text(aes(label = label), hjust = 0, nudge_x = 0.025, size = label_size) + 57 | xlim(lim_prob) + 58 | scale_y_continuous(limits = c(top_rank + 0.5, 0.5), trans = "reverse") 59 | } 60 | -------------------------------------------------------------------------------- /R/read.R: -------------------------------------------------------------------------------- 1 | #' Read z-scores from a file. 2 | #' 3 | #' @examples 4 | #' f1 <- system.file("extdata/region1.z", package = "finemapr") 5 | #' ztab <- read_zscore(f1) 6 | #' 7 | #' @export 8 | read_zscore <- function(file_zscore) 9 | { 10 | ### args 11 | stopifnot(!missing(file_zscore)) 12 | stopifnot(file.exists(file_zscore)) 13 | 14 | ### inc 15 | stopifnot(requireNamespace("data.table")) 16 | 17 | ### read 18 | tab <- data.table::fread(file_zscore) %>% as_data_frame 19 | 20 | stopifnot(ncol(tab) >= 2) 21 | 22 | ### processing column names 23 | # scenario 1: first two columns are `snp` and `zscore` 24 | tab <- tab[, 1:2] 25 | 26 | col1_class <- class(tab[[1]]) 27 | col2_class <- class(tab[[2]]) 28 | 29 | stopifnot(col1_class == "character") 30 | stopifnot(col2_class == "numeric") 31 | 32 | names(tab) <- c("snp", "zscore") 33 | 34 | return(tab) 35 | } 36 | 37 | #' Read LD matrix from a file. 38 | #' 39 | #' @examples 40 | #' f1 <- system.file("extdata/region1.ld", package = "finemapr") 41 | #' ld <- read_ld(f1) 42 | #' 43 | #' @export 44 | read_ld <- function(file_ld, snps) 45 | { 46 | ### args 47 | stopifnot(!missing(file_ld)) 48 | stopifnot(file.exists(file_ld)) 49 | 50 | ### vars 51 | missing_snps <- missing(snps) 52 | 53 | ### inc 54 | stopifnot(requireNamespace("data.table")) 55 | 56 | ### read 57 | mat <- data.table::fread(file_ld) %>% as.matrix 58 | 59 | stopifnot(ncol(mat) == nrow(mat)) 60 | 61 | if(!missing_snps) { 62 | stopifnot(nrow(mat) == length(snps)) 63 | 64 | rownames(mat) <- snps 65 | colnames(mat) <- snps 66 | } 67 | 68 | return(mat) 69 | } 70 | -------------------------------------------------------------------------------- /misc/rmd/finemap.md: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | html_document: 4 | keep_md: true 5 | --- 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ```r 14 | # specify where the FINEMAP tool is located (user-specific) 15 | # - the user needs to download and install the tool before the analysis 16 | # - here, the tool binary file is stored in `~/apps/finemap/` directory 17 | options(finemapr_finemap = "~/apps/finemap/finemap") 18 | 19 | # load example data from FINEMAP (http://www.christianbenner.com/) 20 | # - data are obtained from the same directory `~/apps/finemap/`, subdirectory `example` 21 | ex <- example_finemap() 22 | 23 | # run the tool 24 | # - simulated data in region 1 (used here in the analysis) assumed 2 causal SNPs 25 | # - arg. #1: table with SNP name and Z-score in the first 2 columns 26 | # - arg. #2: the LD matrix with colnames/rownames corresponding to SNP names 27 | # - arg. #3: the number of invidivudals 28 | # - arg. `args`: pass other arguments to the tool as a string 29 | out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 3") 30 | ``` 31 | 32 | 33 | ```r 34 | print(out) 35 | ``` 36 | 37 | ``` 38 | - command: ~/apps/finemap/finemap --sss --log --n-causal-max 3 --in-files region.master 39 | - see log output in `log` 40 | - tables of results: `config`, `snp`, `ncausal` 41 | - config: 42 | # A tibble: 8,410 x 4 43 | rank config config_prob config_log10bf 44 | 45 | 1 1 rs15,rs47 0.607 42.7 46 | 2 2 rs15,rs42,rs47 0.0326 43.1 47 | 3 3 rs15,rs34,rs47 0.0222 42.9 48 | # ... with 8,407 more rows 49 | ``` 50 | 51 | 52 | ```r 53 | plot(out, label_size = 3, grid_ncol = 1) 54 | ``` 55 | 56 | ![](figures/plot_finemap-1.png) 57 | 58 | -------------------------------------------------------------------------------- /R/files.R: -------------------------------------------------------------------------------- 1 | #-------------------------- 2 | # File names for paintor 3 | #-------------------------- 4 | 5 | #' @rdname FinemaprPaintor 6 | #' @export 7 | filename_zscore.FinemaprPaintor <- function(x, locus = 1) paste0(locus, ".region") 8 | 9 | #' @rdname FinemaprPaintor 10 | #' @export 11 | filename_ld.FinemaprPaintor <- function(x, locus = 1) paste0(locus, ".region.ld") 12 | 13 | #' @rdname FinemaprPaintor 14 | #' @export 15 | filename_annot.FinemaprPaintor <- function(x, locus = 1) paste0(locus, ".region.annotations") 16 | 17 | #' @rdname FinemaprPaintor 18 | #' @export 19 | filename_master.FinemaprPaintor <- function(x) "region.master" 20 | 21 | #' @rdname FinemaprPaintor 22 | #' @export 23 | filename_snp.FinemaprPaintor <- function(x, locus) paste0(locus, ".region.results") 24 | 25 | #-------------------------- 26 | # File names for finemap 27 | #-------------------------- 28 | 29 | #' @rdname FinemaprFinemap 30 | #' @export 31 | filename_zscore.FinemaprFinemap <- function(x, locus = 1) paste0(locus, ".region.z") 32 | 33 | #' @rdname FinemaprFinemap 34 | #' @export 35 | filename_ld.FinemaprFinemap <- function(x, locus = 1) paste0(locus, ".region.ld") 36 | 37 | #' @rdname FinemaprFinemap 38 | #' @export 39 | filename_snp.FinemaprFinemap <- function(x, locus) paste0(locus, ".region.snp") 40 | 41 | #' @rdname FinemaprFinemap 42 | #' @export 43 | filename_config.FinemaprFinemap <- function(x, locus) paste0(locus, ".region.config") 44 | 45 | #' @rdname FinemaprFinemap 46 | #' @export 47 | filename_k.FinemaprFinemap <- function(x, locus) paste0(locus, ".region.k") 48 | 49 | #' @rdname FinemaprFinemap 50 | #' @export 51 | filename_log.FinemaprFinemap <- function(x, locus) paste0(locus, ".region.log") 52 | 53 | #' @rdname FinemaprFinemap 54 | #' @export 55 | filename_master.FinemaprFinemap <- function(x) "region.master" 56 | -------------------------------------------------------------------------------- /R/abf.R: -------------------------------------------------------------------------------- 1 | 2 | #' @examples 3 | #' ex <- example_finemap() 4 | #' se <- rep(1/sqrt(ex$n1), nrow(ex$tab1)) 5 | #' effect <- ex$tab1$zscore * se 6 | #' out <- abf(effect, se) 7 | #' @export 8 | abf <- function(effect, se, snp = paste0("snp", seq(1, nrow(effect)))) 9 | { 10 | # copmute ABF 11 | W <- 0.21^2 # suggested by Wakefield 12 | pi1 <- 1 / length(effect) # prior on alternative (association) 13 | 14 | tab <- BFDPfunV(effect, se^2, W, pi1) %>% bind_cols 15 | 16 | ### add input to `tab` 17 | ss <- data_frame(snp = snp, effect = effect, se = se) %>% 18 | mutate(zscore = effect / se) 19 | 20 | tab <- bind_cols(ss, tab) 21 | 22 | tab <- mutate(tab, 23 | ABF = ABFfun(zscore, se^2, W), 24 | ABFinv = (1 / ABF)) 25 | 26 | tab <- within(tab, sumABFinv <- sum(ABFinv)) 27 | 28 | tab <- mutate(tab, P1_ABF = ABFinv / sumABFinv) 29 | 30 | # sort by `P1_ABF` 31 | tab <- arrange(tab, desc(P1_ABF)) 32 | 33 | # add cumsum 34 | tab <- mutate(tab, snp_prob_cumsum = cumsum(P1_ABF)) 35 | 36 | return(tab) 37 | } 38 | 39 | 40 | #------------------ 41 | # ABF computation 42 | #------------------ 43 | 44 | # This function calculates BFDP, the approximate Pr( H0 | thetahat ) 45 | # 46 | # http://faculty.washington.edu/jonno/BFDP.R 47 | # 48 | # doi.org/10.1086/519024, p. 120, formula (6) and above 49 | # 50 | # @param thetahat an estiamte of the log relative risk 51 | # @param V the variance of this estimate 52 | # @param W the prior variance 53 | # @param pi1 the prior probability of a non-null association 54 | BFDPfunV <- function(thetahat, V, W, pi1) 55 | { 56 | pH0 <- dnorm(thetahat, m = 0, s = sqrt(V)) 57 | postvar <- V + W 58 | pH1 <- dnorm(thetahat, m = 0, s = sqrt(postvar)) 59 | BF <- pH0/pH1 60 | 61 | PO <- (1-pi1) / pi1 62 | BFDP <- BF * PO / (BF*PO + 1) 63 | 64 | list(BF = BF, pH0 = pH0, pH1 = pH1, BFDP = BFDP) 65 | } 66 | 67 | # This function computes ABF according to Wakefield (doi.org/10.1086/519024) 68 | # 69 | # doi.org/10.1038/ng.2435, Online Methods, Section Bayesian approach 70 | ABFfun <- function(Z, V, W) 71 | { 72 | r <- W / (V + W) 73 | 74 | (1 / sqrt(1 - r)) * exp(-Z*Z*r/2) 75 | } 76 | -------------------------------------------------------------------------------- /misc/install-finemaping-tools.md: -------------------------------------------------------------------------------- 1 | ## FINEMAP 2 | 3 | finemap="finemap_v1.1_x86_64" 4 | appdir="$HOME/.local/apps/finemap/" 5 | 6 | mkdir install_finemap 7 | cd install_finemap 8 | 9 | # make a binary file 10 | wget http://www.christianbenner.com/${finemap}.tgz 11 | tar -xvzf ${finemap}.tgz 12 | cd ${finemap}/ 13 | 14 | # install in a local directory 15 | mkdir -p ${appdir} 16 | cp ${finemap} ${appdir}/finemap 17 | cp -r example ${appdir}/ 18 | 19 | ## CAVIAR 20 | 21 | - https://github.com/fhormoz/caviar 22 | - http://genetics.cs.ucla.edu/caviar/manual.html 23 | 24 | ``` 25 | mkdir install_caviar 26 | cd install_caviar 27 | 28 | # compile 29 | git clone https://github.com/fhormoz/caviar.git 30 | cd caviar/CAVIAR-C++/ 31 | make 32 | 33 | # install in a local directory 34 | mkdir -p ~/apps/caviar 35 | cp *CAVIAR ~/apps/caviar 36 | cp -r sample_data/ ~/apps/caviar/sample_data/ 37 | 38 | # run example 1 39 | ./CAVIAR -c 2 -z sample_data/50_LD.txt -l sample_data/50_Z.txt -o log 40 | # Segmentation fault: 11 41 | 42 | # run example 2 43 | ./CAVIAR -c 2 -z sample_data/DDB1.top100.sig.SNPs.ZScores -l sample_data/DDB1.top100.sig.SNPs.ld -o log 44 | # output files: log_set, log_post, log. 45 | 46 | # run example 3 47 | ./CAVIAR -c 2 -z ~/apps/finemap/example/region1.z -l ~/apps/finemap/example/region1.ld -o log 48 | head log_set # prints two snps: rs15 & rs47 49 | ``` 50 | 51 | ## PAINTOR 52 | 53 | - https://github.com/gkichaev/PAINTOR_V3.0 54 | - running without annotations: https://github.com/gkichaev/PAINTOR_V3.0/issues/11#issuecomment-303135031 55 | 56 | ``` 57 | mkdir install_paintor 58 | cd install_paintor 59 | 60 | # compile 61 | git clone https://github.com/gkichaev/PAINTOR_V3.0.git 62 | cd PAINTOR_V3.0 63 | bash install.sh 64 | 65 | # create example file with 1 region 66 | mkdir SampleData1 67 | cp SampleData/Locus1 SampleData/Locus1.* SampleData1/ 68 | head -n 1 SampleData/input.files > SampleData1/input.files 69 | 70 | # install in a local directory 71 | mkdir -p ~/apps/paintor 72 | cp PAINTOR ~/apps/paintor 73 | cp -r CANVIS ~/apps/paintor/CANVIS 74 | cp -r PAINTOR_Utilities ~/apps/paintor/PAINTOR_Utilities 75 | cp -r SampleData ~/apps/paintor/SampleData 76 | cp -r SampleData1 ~/apps/paintor/SampleData1 77 | 78 | # run example on Locus 1 79 | ./PAINTOR -input SampleData1/input.files -in SampleData1/ -out SampleData1/ -Zhead Zscore -LDname ld -enumerate 2 -annotations DHS 80 | ``` 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # finemapr 2 | 3 | [![travis-ci build status](https://travis-ci.org/variani/finemapr.svg?branch=master)](https://travis-ci.org/variani/finemapr) 4 | 5 | ![](misc/figures/finemap-2causal.png) 6 | 7 | R interface to fine-mappers: 8 | 9 | - FINEMAP http://www.christianbenner.com/ 10 | - CAVIAR https://github.com/fhormoz/caviar 11 | - PAINTOR https://github.com/gkichaev/PAINTOR_V3.0 12 | 13 | By using `finemapr`, your input files are automatically prepared for each tool, the analysis workflow is tool-independent; and exploration of fine-mapping results is powered by R in printing/plotting/data export. 14 | 15 | **Note**: the package is still under development and its current version is not stable. The current work aims at switching from `run_` functions to a more general one, [finemapr](https://github.com/variani/finemapr/blob/master/R/finemapr.R). The later function makes use of S3 method dispatch features. Thus, use this package with caution until the stable release comes out. 16 | 17 | ## Quick start 18 | 19 | ```r 20 | library(finemapr) 21 | library(tidyverse) 22 | 23 | # get some example data 24 | finemapr::example_finemap() %>% attach 25 | 26 | # run finemapping, default tool is finemap 27 | out <- finemapr(z1, ld1, n1, args = "--n-causal-max 3") 28 | 29 | # print & plot results 30 | out 31 | 32 | plot(out, grid_nrow = 1) 33 | ``` 34 | 35 | ## Tool-independent analysis workflow 36 | 37 | ```r 38 | # set up 39 | options(finemapr_ = "") 40 | 41 | # read input files 42 | my_zscores <- read_zscores("") 43 | my_ld <- read_ld("") 44 | 45 | # run analysis 46 | # depreciated, but still works: out <- run_(my_zscores, my_ld, args = "") 47 | out <- finemapr(my_zscores, my_ld, method = "", args = "") 48 | 49 | # explore results 50 | print(out) 51 | head(out$snp) # main table of results 52 | plot(out) 53 | 54 | # export results 55 | write.table(out$snp, "") 56 | ``` 57 | 58 | ## Examples 59 | 60 | See the vignette [Fine-mapping analysis pipeline by `finemapr`](https://variani.github.io/finemapr/vignettes/finemapr.html). 61 | 62 | ## Related projects 63 | 64 | - [FineMapping pipeline using GWAS summary statistics](https://github.com/jinghuazhao/FM-pipeline) 65 | - [Finemapping pipeline that automates the usage of PAINTOR, and CAVIAR BF](https://github.com/theboocock/fine_mapping_pipeline) 66 | 67 | -------------------------------------------------------------------------------- /man/FinemaprFinemap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R, R/classFinemaprFinemap.R 3 | \name{filename_zscore.FinemaprFinemap} 4 | \alias{filename_zscore.FinemaprFinemap} 5 | \alias{filename_ld.FinemaprFinemap} 6 | \alias{filename_snp.FinemaprFinemap} 7 | \alias{filename_config.FinemaprFinemap} 8 | \alias{filename_k.FinemaprFinemap} 9 | \alias{filename_log.FinemaprFinemap} 10 | \alias{filename_master.FinemaprFinemap} 11 | \alias{FinemaprFinemap} 12 | \alias{write_files.FinemaprFinemap} 13 | \alias{run_tool.FinemaprFinemap} 14 | \alias{collect_results.FinemaprFinemap} 15 | \alias{print.FinemaprFinemap} 16 | \alias{plot.FinemaprFinemap} 17 | \alias{plot_ncausal.FinemaprFinemap} 18 | \alias{plot_config.FinemaprFinemap} 19 | \alias{plot_snp.FinemaprFinemap} 20 | \title{S3 class FinemaprFinemap.} 21 | \usage{ 22 | \method{filename_zscore}{FinemaprFinemap}(x, locus = 1) 23 | 24 | \method{filename_ld}{FinemaprFinemap}(x, locus = 1) 25 | 26 | \method{filename_snp}{FinemaprFinemap}(x, locus) 27 | 28 | \method{filename_config}{FinemaprFinemap}(x, locus) 29 | 30 | \method{filename_k}{FinemaprFinemap}(x, locus) 31 | 32 | \method{filename_log}{FinemaprFinemap}(x, locus) 33 | 34 | \method{filename_master}{FinemaprFinemap}(x) 35 | 36 | \method{write_files}{FinemaprFinemap}(x, ...) 37 | 38 | \method{run_tool}{FinemaprFinemap}(x, ...) 39 | 40 | \method{collect_results}{FinemaprFinemap}(x, ...) 41 | 42 | print.FinemaprFinemap(x, ...) 43 | 44 | \method{plot}{FinemaprFinemap}( 45 | x, 46 | grid_nrow = NULL, 47 | grid_ncol = NULL, 48 | label_size = getOption("finemapr_label_size"), 49 | label_size_config = label_size, 50 | label_size_snp = label_size, 51 | top_rank = getOption("top_rank"), 52 | top_rank_config = top_rank, 53 | top_rank_snp = top_rank, 54 | lim_prob = getOption("lim_prob"), 55 | lim_prob_config = lim_prob, 56 | lim_prob_snp = lim_prob, 57 | lim_prob_ncausal = lim_prob, 58 | ... 59 | ) 60 | 61 | \method{plot_ncausal}{FinemaprFinemap}(x, locus = 1, lim_prob = c(0, 1), ...) 62 | 63 | \method{plot_config}{FinemaprFinemap}( 64 | x, 65 | locus = 1, 66 | lim_prob = c(0, 1.5), 67 | label_size = getOption("finemapr_label_size"), 68 | top_rank = getOption("top_rank"), 69 | ... 70 | ) 71 | 72 | \method{plot_snp}{FinemaprFinemap}( 73 | x, 74 | locus = 1, 75 | lim_prob = c(0, 1.5), 76 | label_size = getOption("finemapr_label_size"), 77 | top_rank = getOption("top_rank"), 78 | ... 79 | ) 80 | } 81 | \description{ 82 | S3 class FinemaprFinemap. 83 | } 84 | -------------------------------------------------------------------------------- /R/plots.R: -------------------------------------------------------------------------------- 1 | #------------------------ 2 | # Plot methods 3 | #------------------------ 4 | 5 | 6 | #' @rdname Finemapr 7 | #' 8 | #' @note 9 | #' Colors: http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf 10 | #' 11 | #' @export 12 | plot_zscore.Finemapr <- function(x, locus = 1, 13 | label_size = getOption("finemapr_label_size"), 14 | selected, 15 | # ggrepel 16 | force = 20, 17 | color_main = "grey75", color_selected = "aquamarine4", 18 | color_credible = "dodgerblue4", color_missing = "brown", 19 | plot_missing = FALSE, 20 | ...) 21 | { 22 | ### arg 23 | missing_selected <- missing(selected) 24 | 25 | ### data 26 | tab <- x$tab[[locus]] 27 | tab <- mutate(tab, 28 | pval = pchisq(zscore^2, df = 1, lower.tail = FALSE)) 29 | 30 | if(!plot_missing) { 31 | tab <- filter(tab, finemap) 32 | } 33 | 34 | p <- ggplot(tab, aes(pos, -log10(pval))) + geom_point(color = color_main) 35 | 36 | ### sel snps 37 | if(!missing_selected) { 38 | tab_selected <- filter(tab, snp %in% selected) 39 | #(nrow(tab_selected) == length(selected)) 40 | 41 | if(nrow(tab_selected)) { 42 | p <- p + 43 | geom_point( 44 | data = tab_selected, aes(pos, -log10(pval)), color = color_selected) + 45 | geom_text_repel( 46 | data = tab_selected, aes(label = snp), 47 | force = force, size = label_size, color = color_selected) 48 | } 49 | } 50 | 51 | ### credible set 52 | if(!is.null(x$snps_credible)) { 53 | credible <- x$snps_credible[[locus]] 54 | 55 | tab_credible <- filter(tab, snp %in% credible) 56 | stopifnot(nrow(tab_credible) == length(credible)) 57 | 58 | p <- p + 59 | geom_point( 60 | data = tab_credible, aes(pos, -log10(pval)), color = color_credible) 61 | 62 | tab_credible_top <- filter(tab, snp %in% head(credible, 10)) 63 | p <- p + 64 | geom_text_repel( 65 | data = tab_credible_top, aes(label = snp), 66 | force = force, size = label_size, color = color_credible) 67 | } 68 | 69 | ### missing snps 70 | if(!is.null(x$snps_missing_finemap) & plot_missing) { 71 | snps_missing <- x$snps_missing_finemap[[locus]] 72 | 73 | tab_missing <- filter(tab, snp %in% snps_missing) 74 | stopifnot(nrow(tab_missing) == length(snps_missing)) 75 | 76 | p <- p + 77 | geom_point( 78 | data = tab_missing, aes(pos, -log10(pval)), color = color_missing) 79 | 80 | tab_missing_top <- head(tab_missing, 3) 81 | p <- p + 82 | geom_text_repel( 83 | data = tab_missing_top, aes(label = snp), 84 | force = force, size = label_size, color = color_missing) 85 | } 86 | 87 | ### labs 88 | p <- p + 89 | scale_x_continuous(labels = scales::comma) + 90 | labs(x = "Position (bp)", y = expression(-log[10](P))) 91 | 92 | ### cleaner theme 93 | p <- p + theme(panel.grid.minor = element_blank()) 94 | 95 | return(p) 96 | } 97 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(collect_results,FinemaprFinemap) 4 | S3method(collect_results,FinemaprPaintor) 5 | S3method(extract_credible_set,Finemapr) 6 | S3method(filename_annot,FinemaprPaintor) 7 | S3method(filename_config,FinemaprFinemap) 8 | S3method(filename_k,FinemaprFinemap) 9 | S3method(filename_ld,FinemaprFinemap) 10 | S3method(filename_ld,FinemaprPaintor) 11 | S3method(filename_log,FinemaprFinemap) 12 | S3method(filename_master,FinemaprFinemap) 13 | S3method(filename_master,FinemaprPaintor) 14 | S3method(filename_snp,FinemaprFinemap) 15 | S3method(filename_snp,FinemaprPaintor) 16 | S3method(filename_zscore,FinemaprFinemap) 17 | S3method(filename_zscore,FinemaprPaintor) 18 | S3method(plot,Finemapr) 19 | S3method(plot,FinemaprCaviar) 20 | S3method(plot,FinemaprFinemap) 21 | S3method(plot_config,FinemaprFinemap) 22 | S3method(plot_ncausal,FinemaprFinemap) 23 | S3method(plot_snp,Finemapr) 24 | S3method(plot_snp,FinemaprCaviar) 25 | S3method(plot_snp,FinemaprFinemap) 26 | S3method(plot_zscore,Finemapr) 27 | S3method(process_annot,FinemaprPaintor) 28 | S3method(process_ld,Finemapr) 29 | S3method(process_tab,Finemapr) 30 | S3method(run_tool,FinemaprFinemap) 31 | S3method(run_tool,FinemaprPaintor) 32 | S3method(write_files,FinemaprFinemap) 33 | S3method(write_files,FinemaprPaintor) 34 | export(abf) 35 | export(cojo) 36 | export(collect_results) 37 | export(example_finemap) 38 | export(extract_credible_set) 39 | export(filename_annot) 40 | export(filename_config) 41 | export(filename_k) 42 | export(filename_ld) 43 | export(filename_log) 44 | export(filename_master) 45 | export(filename_snp) 46 | export(filename_zscore) 47 | export(finemapr) 48 | export(plot_config) 49 | export(plot_ncausal) 50 | export(plot_snp) 51 | export(plot_zscore) 52 | export(print.Finemapr) 53 | export(print.FinemaprCaviar) 54 | export(print.FinemaprFinemap) 55 | export(print.FinemaprPaintor) 56 | export(process_annot) 57 | export(process_ld) 58 | export(process_n) 59 | export(process_tab) 60 | export(proxysnps_ref_ld) 61 | export(proxysnps_ref_vcf) 62 | export(read_ld) 63 | export(read_zscore) 64 | export(ref_bed) 65 | export(ref_ld) 66 | export(ref_pop) 67 | export(run_caviar) 68 | export(run_cojo) 69 | export(run_finemap) 70 | export(run_paintor) 71 | export(run_tool) 72 | export(sumstats_bmi) 73 | export(write_files) 74 | exportClasses(Finemapr) 75 | exportClasses(FinemaprCaviar) 76 | exportClasses(FinemaprFinemap) 77 | exportClasses(FinemaprPaintor) 78 | import(Matrix) 79 | import(ggplot2) 80 | import(ggrepel) 81 | importFrom(cowplot,plot_grid) 82 | importFrom(dplyr,arrange) 83 | importFrom(dplyr,everything) 84 | importFrom(dplyr,filter) 85 | importFrom(dplyr,left_join) 86 | importFrom(dplyr,mutate) 87 | importFrom(dplyr,select) 88 | importFrom(dplyr,select_) 89 | importFrom(magrittr,"%$%") 90 | importFrom(magrittr,"%>%") 91 | importFrom(readr,cols) 92 | importFrom(readr,read_delim) 93 | importFrom(readr,read_lines) 94 | importFrom(readr,read_tsv) 95 | importFrom(readr,write_delim) 96 | importFrom(readr,write_file) 97 | importFrom(readr,write_lines) 98 | importFrom(readr,write_tsv) 99 | importFrom(tibble,as_data_frame) 100 | importFrom(tibble,data_frame) 101 | importFrom(utils,head) 102 | importFrom(utils,write.table) 103 | -------------------------------------------------------------------------------- /R/finemap.R: -------------------------------------------------------------------------------- 1 | 2 | #' Run FINEMAP. 3 | #' 4 | #' @examples 5 | #' ex <- example_finemap() 6 | #' out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 3") 7 | #' out <- run_finemap(ex$tab1, ex$ld1, ex$n1, args = "--n-causal-max 1") 8 | #' 9 | #' @export 10 | run_finemap <- function(tab, ld, n, 11 | dir_run = "run_finemap", 12 | tool = getOption("finemapr_finemap"), args = "") 13 | { 14 | ### arg 15 | stopifnot(is.matrix(ld)) 16 | stopifnot(!is.null(rownames(ld))) 17 | stopifnot(!is.null(colnames(ld))) 18 | 19 | ### var 20 | num_ind <- n # use another name for `n` 21 | 22 | ### process input data: `tab` and `ld` 23 | tab <- as_data_frame(tab) 24 | stopifnot(ncol(tab) >= 2) 25 | names(tab)[c(1, 2)] <- c("snp", "zscore") 26 | 27 | tab <- filter(tab, !is.na(zscore)) # exclude missing Z-scores 28 | 29 | snps <- tab$snp 30 | stopifnot(all(snps %in% rownames(ld))) 31 | stopifnot(all(snps %in% colnames(ld))) 32 | 33 | ld <- ld[snps, snps] 34 | 35 | stopifnot(all(round(diag(ld), 4) == 1)) 36 | diag(ld) <- 1 37 | 38 | ### create `dir` 39 | ret_dir_create <- dir.create(dir_run, showWarnings = FALSE, recursive = TRUE) 40 | #stopifnot(ret_dir_create) 41 | 42 | ### write files 43 | write_delim(tab[, 1:2], file.path(dir_run, "region.z"), 44 | delim = " ", col_names = FALSE) 45 | write.table(ld, file.path(dir_run, "region.ld"), 46 | sep = " ", row.names = FALSE, col.names = FALSE) 47 | 48 | lines_master <- c("z;ld;snp;config;log;n-ind", 49 | paste0("region.z;region.ld;region.snp;region.config;region.log;", num_ind)) 50 | write_lines(lines_master, file.path(dir_run, "region.master")) 51 | 52 | ### run tool 53 | tool_input <- paste0("--sss --log ", args, " --in-files region.master") 54 | cmd <- paste(tool, tool_input) 55 | 56 | dir_cur <- getwd() 57 | setwd(dir_run) 58 | 59 | ret_run <- try({ 60 | system(cmd, input = tool_input) 61 | }) 62 | 63 | setwd(dir_cur) 64 | 65 | # executed `tool` ok? 66 | status_run <- ifelse(ret_run == 0, TRUE, FALSE) 67 | 68 | # read log 69 | if(status_run) { 70 | log <- try(read_lines(file.path(dir_run, "region.log"))) 71 | status_run <- ifelse(class(log)[1] == "try-error", FALSE, TRUE) 72 | } 73 | 74 | if(!status_run) { 75 | out <- list(cmd = cmd, ret = ret_run, status = status_run) 76 | 77 | return(out) 78 | } 79 | 80 | # read output tables 81 | snp <- read_delim(file.path(dir_run, "region.snp"), delim = " ") 82 | config <- read_delim(file.path(dir_run, "region.config"), delim = " ") 83 | 84 | # extract output tables 85 | ncausal <- finemap_extract_ncausal(log) 86 | 87 | ### return 88 | out <- list(cmd = cmd, ret = ret_run, status = status_run, log = log, 89 | tab = tab, snp = snp, config = config, ncausal = ncausal) 90 | 91 | oldClass(out) <- c("FinemaprFinemap", "Finemapr", oldClass(out)) 92 | 93 | return(out) 94 | } 95 | 96 | finemap_extract_ncausal <- function(log) 97 | { 98 | lines <- grep("->", log, value = TRUE) 99 | 100 | lines <- gsub("\\(|\\)|>", "", lines) 101 | 102 | splits <- strsplit(lines, "\\s+") 103 | 104 | tab <- data_frame( 105 | ncausal_num = sapply(splits, function(x) as.integer(x[2])), 106 | ncausal_prob = sapply(splits, function(x) as.double(x[4]))) 107 | 108 | tab <- mutate(tab, type = ifelse(duplicated(ncausal_num), "post", "prior")) 109 | 110 | return(tab) 111 | } 112 | 113 | -------------------------------------------------------------------------------- /R/caviar.R: -------------------------------------------------------------------------------- 1 | 2 | #' Run CAVIAR. 3 | #' 4 | #' Output file (`*_post`): 5 | #' column #1 is the variant name; 6 | #' column #2 is the posterior prob. that the variant is causal 7 | #' (https://github.com/fhormoz/caviar/issues/1#issuecomment-286521771); 8 | #' column #3 is the amount that this variant contributes to 9 | #' 95%-causal credible set. 10 | #' 11 | #' @examples 12 | #' ex <- example_finemap() 13 | #' out <- run_caviar(ex$tab1, ex$ld1, args = "-c 2") 14 | #' out <- run_caviar(ex$tab1, ex$ld1, args = "-c 0") 15 | #' 16 | #' @export 17 | run_caviar <- function(tab, ld, 18 | dir_run = "run_caviar", 19 | tool = getOption("finemapr_caviar"), args = "") 20 | { 21 | ### arg 22 | stopifnot(class(ld) == "matrix") 23 | stopifnot(class(dir_run) == "character") 24 | 25 | stopifnot(!is.null(rownames(ld))) 26 | stopifnot(!is.null(colnames(ld))) 27 | 28 | stopifnot(!is.null(tool)) 29 | stopifnot(file.exists(tool)) 30 | 31 | ### var 32 | log_filename <- "log" 33 | log_set <- file.path(dir_run, paste0(log_filename, "_set")) 34 | log_post <- file.path(dir_run, paste0(log_filename, "_post")) 35 | log_log <- file.path(dir_run, paste0(log_filename, ".log")) 36 | 37 | ### process input data: `tab` and `ld` 38 | tab <- as_data_frame(tab) 39 | stopifnot(ncol(tab) >= 2) 40 | names(tab) <- c("snp", "zscore") 41 | 42 | tab <- filter(tab, !is.na(zscore)) # exclude missing Z-scores 43 | 44 | snps <- tab$snp 45 | stopifnot(all(snps %in% rownames(ld))) 46 | stopifnot(all(snps %in% colnames(ld))) 47 | 48 | ld <- ld[snps, snps] 49 | 50 | stopifnot(all(round(diag(ld), 4) == 1)) 51 | diag(ld) <- 1 52 | 53 | ### create `dir` 54 | ret_dir_create <- dir.create(dir_run, showWarnings = FALSE, recursive = TRUE) 55 | 56 | ### write files 57 | write_delim(tab, file.path(dir_run, "region.z"), 58 | delim = " ", col_names = FALSE) 59 | write.table(ld, file.path(dir_run, "region.ld"), 60 | sep = " ", row.names = FALSE, col.names = FALSE) 61 | 62 | ### run tool 63 | tool_input <- paste0(args, " -z region.z -l region.ld -o ", log_filename) 64 | cmd <- paste(tool, tool_input) 65 | 66 | dir_cur <- getwd() 67 | setwd(dir_run) 68 | 69 | ret_run <- try({ 70 | system(cmd, input = tool_input) 71 | }) 72 | 73 | setwd(dir_cur) 74 | 75 | # executed `tool` ok? 76 | status_run <- ifelse(ret_run == 0, TRUE, FALSE) 77 | 78 | # logs 79 | if(status_run) { 80 | if(!all(file.exists(log_log, log_post, log_log))) { 81 | status_run <- FALSE 82 | } 83 | } 84 | 85 | if(!status_run) { 86 | out <- list(cmd = cmd, ret = ret_run, status = status_run) 87 | 88 | return(out) 89 | } 90 | 91 | log <- read_lines(log_log) 92 | 93 | ### read output tables 94 | snp <- read_tsv(file.path(dir_run, paste0(log_filename, "_post"))) 95 | 96 | stopifnot(ncol(snp) == 3) 97 | names(snp) <- c("snp", "snp_prob_set", "snp_prob") 98 | 99 | snp <- arrange(snp, -snp_prob) %>% 100 | mutate(rank = seq(1, n())) %>% 101 | select(rank, everything()) 102 | 103 | # `set` of snps 104 | set <- read_lines(file.path(dir_run, paste0(log_filename, "_set"))) 105 | 106 | # order snps in `set` 107 | set_ordered <- left_join(data_frame(snp = set), snp, by = "snp") %>% 108 | arrange(rank) %$% snp 109 | 110 | ### return 111 | out <- list(cmd = cmd, ret = ret_run, status = status_run, log = log, 112 | tab = tab, snp = snp, set = set_ordered) 113 | 114 | oldClass(out) <- c("FinemaprCaviar", "Finemapr", oldClass(out)) 115 | 116 | return(out) 117 | } 118 | 119 | -------------------------------------------------------------------------------- /misc/learn/02-abf/02-abf.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fine-mapping using Approximate Bayes Factor (ABF) on toy example" 3 | author: "Andrey Ziyatdinov" 4 | date: "`r Sys.Date()`" 5 | output: 6 | html_document: 7 | theme: united 8 | toc: true 9 | number_sections: false 10 | keep_md: true 11 | --- 12 | 13 | ```{r options, echo = F} 14 | opts_chunk$set(dpi = 92, 15 | fig.path = "figures/", comment = NA, results = 'markup', tidy = F, message = F, warning = F, echo = T, cache = F) 16 | ``` 17 | 18 | # About 19 | 20 | Load libraries: 21 | 22 | ```{r inc, cache = FALSE, echo = T} 23 | library(magrittr) 24 | library(dplyr) 25 | 26 | library(ggplot2) 27 | theme_set(theme_minimal()) 28 | 29 | library(devtools) 30 | load_all("~/git/variani/finemapr/") 31 | ``` 32 | 33 | # Wakefield's functions 34 | 35 | ```{r local} 36 | # This function calculates BFDP, the approximate Pr( H0 | thetahat ) 37 | # 38 | # http://faculty.washington.edu/jonno/BFDP.R 39 | # 40 | # doi.org/10.1086/519024, p. 120, formula (6) and above 41 | # 42 | # @param thetahat an estiamte of the log relative risk 43 | # @param V the variance of this estimate 44 | # @param W the prior variance 45 | # @param pi1 the prior probability of a non-null association 46 | BFDPfunV <- function(thetahat, V, W, pi1) 47 | { 48 | pH0 <- dnorm(thetahat, m = 0, s = sqrt(V)) 49 | postvar <- V + W 50 | pH1 <- dnorm(thetahat, m = 0, s = sqrt(postvar)) 51 | BF <- pH0/pH1 52 | 53 | PO <- (1-pi1) / pi1 54 | BFDP <- BF * PO / (BF*PO + 1) 55 | 56 | list(BF = BF, pH0 = pH0, pH1 = pH1, BFDP = BFDP) 57 | } 58 | 59 | # This function computes ABF according to Wakefield (doi.org/10.1086/519024) 60 | # 61 | # doi.org/10.1038/ng.2435, Online Methods, Section Bayesian approach 62 | ABFfun <- function(Z, V, W) 63 | { 64 | r <- W / (V + W) 65 | 66 | (1 / sqrt(1 - r)) * exp(-Z*Z*r/2) 67 | } 68 | ``` 69 | 70 | # Example data set 71 | 72 | ```{r ex} 73 | ex <- example_finemap() 74 | 75 | ss <- ex$tab1 76 | ld <- ex$ld1 # not needed for ABF, be used later on for FINEMAP 77 | N <- 4444 78 | 79 | # simulate standard errors (se) and add effect sizes (effect) 80 | set.seed(1) 81 | ss <- mutate(ss, 82 | se = rnorm(n(), 1/sqrt(N), 0.005), 83 | effect = zscore * se) 84 | 85 | # remove strong signals 86 | ss <- filter(ss, abs(zscore) < 6) 87 | 88 | # sort 89 | ss <- arrange(ss, -abs(zscore)) %>% 90 | mutate(rank = seq(1, n())) %>% select(rank, everything()) 91 | ``` 92 | 93 | # ABF 94 | 95 | ```{r abf} 96 | W <- 0.21^2 # suggested by Wakefield 97 | pi1 <- 1 / nrow(ss) # prior on alternative (association) 98 | 99 | abf <- BFDPfunV(ss$effect, ss$se^2, W, pi1) %>% bind_cols 100 | 101 | abf <- bind_cols(ss, abf) 102 | 103 | abf <- mutate(abf, 104 | ABF = ABFfun(zscore, se^2, W), 105 | ABFinv = (1 / ABF)) 106 | abf <- within(abf, sumABFinv <- sum(ABFinv)) 107 | 108 | abf <- mutate(abf, P1_ABF = ABFinv / sumABFinv) 109 | ``` 110 | 111 | Top 5 SNPs: 112 | 113 | ```{r top5} 114 | head(abf, 5) %>% 115 | select(rank, snp, zscore, BF, ABF, ABFinv, P1_ABF) %>% 116 | pander 117 | ``` 118 | 119 | # FINEMAP 120 | 121 | ```{r finemap} 122 | finemap <- finemapr(ss, ld, n = as.integer(1/0.015^2), 123 | tool = "finemap", args = "--n-causal-max 1") 124 | ``` 125 | 126 | Top 5 SNPs: 127 | 128 | ```{r top5_finemap} 129 | head(finemap$snp[[1]], 5) %>% 130 | pander 131 | ``` 132 | 133 | # Final plot: ABF vs. FINEMAP 134 | 135 | ```{r final_plot} 136 | # join results from two methods 137 | tab <- full_join( 138 | select(finemap$snp[[1]], rank_z, snp, snp_prob) %>% rename(post_finemap = snp_prob), 139 | select(abf, snp, P1_ABF) %>% rename(post_abf = P1_ABF), 140 | by = "snp") %>% 141 | head(9) 142 | 143 | # table for plot 144 | ptab <- gather(tab, method, post_prob, -rank_z, -snp) %>% 145 | mutate( 146 | snp_rank_z = paste0("#", rank_z, "\n", snp), 147 | method = factor(method, labels = c("ABF (Wakefield)", "FINEMAP (Benner)"))) 148 | 149 | # plot 150 | ggplot(ptab, aes(factor(snp_rank_z), post_prob, fill = method)) + 151 | geom_bar(stat = "identity", position = "dodge") + 152 | labs(x = "SNP", y = "Posterior probability") 153 | ``` 154 | -------------------------------------------------------------------------------- /R/paintor.R: -------------------------------------------------------------------------------- 1 | 2 | #' Run Paintor. 3 | #' 4 | #' @examples 5 | #' ex <- example_finemap() 6 | #' out <- run_paintor(ex$tab1, ex$ld1) 7 | #' 8 | #' @export 9 | run_paintor <- function(tab, ld, n, annot, annotations, 10 | dir_run = "run_paintor", 11 | tool = getOption("finemapr_paintor"), args = "") 12 | { 13 | ### arg 14 | stopifnot(class(ld) == "matrix") 15 | stopifnot(class(dir_run) == "character") 16 | 17 | stopifnot(!is.null(rownames(ld))) 18 | stopifnot(!is.null(colnames(ld))) 19 | 20 | stopifnot(!is.null(tool)) 21 | stopifnot(file.exists(tool)) 22 | 23 | ### var 24 | missing_annot <- missing(annot) 25 | 26 | missing_n <- missing(n) 27 | if(!missing_n) { 28 | num_ind <- n # use another name for `n` 29 | } 30 | 31 | ### process input data: `tab` and `ld` 32 | tab <- as_data_frame(tab) 33 | stopifnot(ncol(tab) >= 2) 34 | names(tab)[c(1, 2)] <- c("snp", "zscore") 35 | 36 | tab <- filter(tab, !is.na(zscore)) # exclude missing Z-scores 37 | 38 | snps <- tab$snp 39 | stopifnot(all(snps %in% rownames(ld))) 40 | stopifnot(all(snps %in% colnames(ld))) 41 | 42 | ld <- ld[snps, snps] 43 | 44 | stopifnot(all(round(diag(ld), 4) == 1)) 45 | diag(ld) <- 1 46 | 47 | # `annot` 48 | if(missing_annot) { 49 | # See comment https://github.com/gkichaev/PAINTOR_V3.0/issues/11#issuecomment-303135031 50 | # about running PAINTOR without annotations: 51 | annot <- data_frame(dummy_ones = rep(1, nrow(tab))) 52 | 53 | annotations <- "dummy_ones" 54 | } else { 55 | stop("not missing annot") 56 | } 57 | 58 | ### create `dir` 59 | ret_dir_create <- dir.create(dir_run, showWarnings = FALSE, recursive = TRUE) 60 | 61 | ### write files 62 | write_delim(tab, file.path(dir_run, "region"), 63 | delim = " ", col_names = TRUE) 64 | write.table(ld, file.path(dir_run, "region.ld"), 65 | sep = " ", row.names = FALSE, col.names = FALSE) 66 | write_delim(annot, file.path(dir_run, "region.annotations"), 67 | delim = " ", col_names = TRUE) 68 | 69 | lines_master <- c("region") 70 | write_lines(lines_master, file.path(dir_run, "region.master")) 71 | 72 | ### run tool 73 | annotations_str <- paste(annotations, collapse = ",") 74 | tool_input <- paste0("-input region.master -Zhead zscore -LDname ld ", 75 | "-annotations ", annotations_str, " ", args) 76 | if(!missing_n) { 77 | tool_input <- paste0(tool_input, " -num_samples ", num_ind) 78 | } 79 | 80 | cmd <- paste(tool, tool_input) 81 | 82 | dir_cur <- getwd() 83 | setwd(dir_run) 84 | 85 | ret_run <- try({ 86 | system(cmd, input = tool_input) 87 | }) 88 | 89 | setwd(dir_cur) 90 | 91 | # executed `tool` ok? 92 | status_run <- ifelse(ret_run == 0, TRUE, FALSE) 93 | 94 | # check 95 | if(!status_run) { 96 | out <- list(cmd = cmd, ret = ret_run, status = status_run) 97 | 98 | return(out) 99 | } 100 | 101 | #log <- read_lines(log_log) 102 | 103 | ### read output tables 104 | snp <- read_delim(file.path(dir_run, "region.results"), delim = " ") 105 | 106 | stopifnot(ncol(snp) == 3) 107 | names(snp) <- c("snp", "zscore", "snp_prob") 108 | 109 | snp <- arrange(snp, -snp_prob) %>% 110 | mutate(rank = seq(1, n())) %>% 111 | select(rank, everything()) 112 | 113 | # enrich 114 | dat_enrich <- read_delim(file.path(dir_run, "Enrichment.Values"), delim = " ") 115 | stopifnot(nrow(dat_enrich) == 1) 116 | 117 | gamma_val <- as.numeric(dat_enrich) 118 | 119 | # https://github.com/gkichaev/PAINTOR_V3.0/wiki/4.-Interpretation-of-Output#gamma-estimates 120 | enrich_prob <- c(1 / (1 + exp(gamma_val[1])), 121 | 1 / (1 + exp(gamma_val[1] + gamma_val[-1]))) 122 | 123 | enrich <- data_frame(annot = colnames(dat_enrich), 124 | gamma = gamma_val, enrich_prob) 125 | 126 | # logBF 127 | lines_logbf <- read_lines(file.path(dir_run, "Log.BayesFactor")) 128 | stopifnot(length(lines_logbf) == 1) 129 | logBF <- as.numeric(lines_logbf) 130 | 131 | ### return 132 | out <- list(cmd = cmd, ret = ret_run, status = status_run, #log = log, 133 | annotations = annotations, tab = tab, snp = snp, 134 | enrich = enrich, logBF = logBF) 135 | 136 | oldClass(out) <- c("FinemaprPaintor", "Finemapr", oldClass(out)) 137 | 138 | return(out) 139 | } 140 | 141 | -------------------------------------------------------------------------------- /vignettes/finemapr.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fine-mapping analysis pipeline by `finemapr`" 3 | author: "Andrey Ziyatdinov" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Vignette Title} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>", # NA 16 | dev = "png", dev.args = list(type = "cairo"), dpi = 92, fig.path = "figures/", 17 | fig.width = 4, fig.height = 4, 18 | results = 'markup', tidy = F, message = T, warning = T, echo = T 19 | ) 20 | ``` 21 | 22 | # About `finemapr` 23 | 24 | `finemapr` is an R package that provides an interface to fine-mapping tools: 25 | 26 | - FINEMAP http://www.christianbenner.com/ 27 | - CAVIAR https://github.com/fhormoz/caviar 28 | - PAINTOR https://github.com/gkichaev/PAINTOR_V3.0 29 | 30 | By using `finemapr`, your input files are automatically prepared for each tool, the analysis workflow is tool-independent; and exploration of fine-mapping results is powered by R in printing/plotting/data export. 31 | 32 | 33 | ## Tool-independent scheme of analysis workflow 34 | 35 | ```r 36 | # set up 37 | options(finemapr_ = "") 38 | 39 | # read input files 40 | my_zscores <- read_zscores("") 41 | my_ld <- read_ld("") 42 | 43 | # run analysis 44 | out <- run_(my_zscores, my_ld, args = "") 45 | 46 | # explore results 47 | print(out) 48 | head(out$snp) # main table of results 49 | plot(out) 50 | 51 | # export results 52 | write.table(out$snp, "") 53 | ``` 54 | 55 | # Installation 56 | 57 | The user needs to download and install a fine-mapping tool before the analysis. 58 | An example of installation commands used in `finemapr` by default is given [here](https://github.com/variani/finemapr/blob/master/misc/install-finemaping-tools.md). 59 | 60 | After installing, for example, the FINEMAP tool, the user specify for `finemapr` where the tool is located: 61 | 62 | ```{r, eval = F} 63 | options(finemapr_finemap = "~/apps/finemap/finemap") 64 | ``` 65 | 66 | # Load packages 67 | 68 | We load packages for the analysis conducted in this document. 69 | 70 | ```{r inc} 71 | library(devtools) 72 | load_all("~/git/variani/finemapr") 73 | 74 | library(magrittr) 75 | library(dplyr) 76 | library(ggplot2) 77 | theme_set(theme_linedraw()) 78 | ``` 79 | 80 | # Example data 81 | 82 | We load example data copied from the FINEMAP website (http://www.christianbenner.com/). 83 | This simulated dataset has two causal variants `rs15` and `rs47`. 84 | 85 | ```{r example_data} 86 | file1_z <- system.file("extdata/region1.z", package = "finemapr") 87 | file1_ld <- system.file("extdata/region1.ld", package = "finemapr") 88 | 89 | z1 <- read_zscore(file1_z) 90 | ld1 <- read_ld(file1_ld, snps = z1$snp) 91 | n1 <- 5363 92 | ``` 93 | 94 | ## Explore z-scores 95 | 96 | Top 5 z-scores: 97 | 98 | ```{r top5, results = "asis"} 99 | z1 %>% arrange(-abs(zscore)) %>% head(5) %>% kable(digits = 1) 100 | ``` 101 | 102 | ```{r plot_zscore} 103 | ggplot(z1, aes(zscore)) + geom_histogram() 104 | ``` 105 | 106 | ```{r plot_pval} 107 | mutate(z1, pval = pchisq(zscore^2, df = 1, lower.tail = FALSE)) %>% 108 | ggplot(aes(pval)) + geom_histogram() 109 | ``` 110 | 111 | # Run tools 112 | 113 | ## Run FINEMAP 114 | 115 | ```{r run_finemap} 116 | options(finemapr_finemap = "~/apps/finemap/finemap") 117 | 118 | out_finemap <- run_finemap(z1, ld1, n1, args = "--n-causal-max 3") 119 | ``` 120 | 121 | ```{r print_finemap} 122 | print(out_finemap) 123 | ``` 124 | 125 | ```{r plot_finemap, fig.width = 6, fig.height = 9} 126 | plot(out_finemap, label_size = 3, grid_ncol = 1) 127 | ``` 128 | 129 | ## Run CAVIAR 130 | 131 | ```{r run_caviar} 132 | options(finemapr_caviar = "~/apps/caviar/CAVIAR") 133 | 134 | out_caviar <- run_caviar(z1, ld1, args = "-c 3") 135 | ``` 136 | 137 | ```{r print_caviar} 138 | print(out_caviar) 139 | ``` 140 | 141 | ```{r plot_caviar, fig.width = 6, fig.height = 3} 142 | plot(out_caviar, label_size = 3) 143 | ``` 144 | 145 | ## Run PAINTOR 146 | 147 | ```{r run_paintor} 148 | options(finemapr_paintor = "~/apps/paintor/PAINTOR") 149 | 150 | out_paintor <- run_paintor(z1, ld1, n1, args = "-enumerate 3") 151 | ``` 152 | 153 | ```{r print_paintor} 154 | print(out_paintor) 155 | ``` 156 | 157 | ```{r plot_paintor, fig.width = 6, fig.height = 3} 158 | plot(out_paintor, label_size = 3) 159 | ``` 160 | 161 | # Conclusions 162 | 163 | All three fine-mapping tools estimated the poterior causal probabilities of the two variants, `rs15` and `rs47`, very close to 1. 164 | -------------------------------------------------------------------------------- /R/classMethods.R: -------------------------------------------------------------------------------- 1 | #---------------------- 2 | # Class Declatation 3 | #---------------------- 4 | 5 | #' S3 class Finemapr. 6 | #' 7 | #' @name Finemapr 8 | #' @rdname Finemapr 9 | #' 10 | #' @exportClass Finemapr 11 | 12 | 13 | #---------------------- 14 | # Methods Declatation 15 | #---------------------- 16 | 17 | #' @export plot_ncausal 18 | plot_ncausal <- function(x, ...) UseMethod("plot_ncausal") 19 | 20 | #' @export plot_config 21 | plot_config <- function(x, ...) UseMethod("plot_config") 22 | 23 | #' @export plot_snp 24 | plot_snp <- function(x, ...) UseMethod("plot_snp") 25 | 26 | #' @export plot_zscore 27 | plot_zscore <- function(x, ...) UseMethod("plot_zscore") 28 | 29 | #' @export process_tab 30 | process_tab <- function(x, ...) UseMethod("process_tab") 31 | 32 | #' @export process_ld 33 | process_ld <- function(x, ...) UseMethod("process_ld") 34 | 35 | #' @export process_n 36 | process_n <- function(x, ...) UseMethod("process_n") 37 | 38 | #' @export process_annot 39 | process_annot <- function(x, ...) UseMethod("process_annot") 40 | 41 | #' @export write_files 42 | write_files <- function(x, ...) UseMethod("write_files") 43 | 44 | #' @export run_tool 45 | run_tool <- function(x, ...) UseMethod("run_tool") 46 | 47 | #' @export collect_results 48 | collect_results <- function(x, ...) UseMethod("collect_results") 49 | 50 | #' @export extract_credible_set 51 | extract_credible_set <- function(x, ...) UseMethod("extract_credible_set") 52 | 53 | #------------------------ 54 | # File names 55 | #------------------------ 56 | 57 | #' @export filename_zscore 58 | filename_zscore <- function(x, ...) UseMethod("filename_zscore") 59 | 60 | #' @export filename_ld 61 | filename_ld <- function(x, ...) UseMethod("filename_ld") 62 | 63 | #' @export filename_snp 64 | filename_snp <- function(x, ...) UseMethod("filename_snp") 65 | 66 | #' @export filename_config 67 | filename_config <- function(x, ...) UseMethod("filename_config") 68 | 69 | #' @export filename_k 70 | filename_k <- function(x, ...) UseMethod("filename_k") 71 | 72 | #' @export filename_log 73 | filename_log <- function(x, ...) UseMethod("filename_log") 74 | 75 | #' @export filename_master 76 | filename_master <- function(x, ...) UseMethod("filename_master") 77 | 78 | #' @export filename_annot 79 | filename_annot <- function(x, ...) UseMethod("filename_annot") 80 | 81 | #------------------------ 82 | # Print methods 83 | #------------------------ 84 | 85 | #' @rdname Finemapr 86 | #' @export 87 | print.Finemapr <- function(x, ...) 88 | { 89 | cat(" - command:", x$cmd, "\n") 90 | 91 | if(x$status) { 92 | cat(" - snp:\n") 93 | print(x$snp, n = 3) 94 | } 95 | } 96 | 97 | 98 | #------------------------ 99 | # Plot methods 100 | #------------------------ 101 | 102 | #' @rdname Finemapr 103 | #' @export 104 | print.Finemapr <- function(x, ...) 105 | { 106 | cat(" - cmd:", x$cmd, "\n") 107 | cat(" - #loci:", x$num_loci, "\n") 108 | 109 | ret <- lapply(seq(1, x$num_loci), function(i) { 110 | cat(" - locus:",i, "\n") 111 | cat(" -- snp:\n") 112 | print(x$snp[[i]], n = 3) 113 | cat(" -- ", length(x$snps_credible[[i]]), " snps in ", 114 | 100*x$prop_credible, "% credible set", 115 | ": ", paste(x$snps_credible[[i]], collapse = ", "), "...", 116 | "\n", sep = "") 117 | }) 118 | 119 | return(invisible()) 120 | } 121 | 122 | #' @rdname Finemapr 123 | #' @export 124 | plot.Finemapr <- function(x, ...) 125 | { 126 | plot_snp(x, ...) 127 | } 128 | 129 | 130 | #' @rdname Finemapr 131 | #' @export 132 | plot_snp.Finemapr <- function(x, lim_prob = c(0, 1.5), 133 | label_size = getOption("finemapr_label_size"), 134 | top_rank = getOption("top_rank"), 135 | ...) 136 | { 137 | ptab <- x$snp 138 | 139 | ptab <- head(ptab, top_rank) 140 | 141 | ptab <- mutate(ptab, 142 | label = paste0(snp, "\n", 143 | "P = ", round(snp_prob, 2))) 144 | 145 | ggplot(ptab, aes(snp_prob, rank)) + 146 | geom_vline(xintercept = 1, linetype = 3) + 147 | geom_point() + 148 | geom_segment(aes(xend = snp_prob, yend = rank, x = 0)) + 149 | geom_text(aes(label = label), hjust = 0, nudge_x = 0.025, size = label_size) + 150 | xlim(lim_prob) + 151 | scale_y_continuous(limits = c(top_rank + 0.5, 0.5), trans = "reverse") 152 | } 153 | 154 | #------------------------ 155 | # Other methods 156 | #------------------------ 157 | 158 | #' @rdname Finemapr 159 | #' @export 160 | extract_credible_set.Finemapr <- function(x, ...) 161 | { 162 | lapply(x$snp, function(snp) { 163 | snp_below <- snp %>% filter(snp_prob_cumsum <= x$prop_credible) 164 | snps <- head(snp, nrow(snp_below) + 1) %$% snp 165 | 166 | # the case: the single top snps covers 100% of credibility 167 | #if(length(snps) == 0) { 168 | # snps <- head(snp, 1) %$% snp 169 | #} 170 | 171 | return(snps) 172 | }) 173 | } 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /misc/learn/02-abf/02-abf.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fine-mapping using Approximate Bayes Factor (ABF) on toy example" 3 | author: "Andrey Ziyatdinov" 4 | date: "2018-08-17" 5 | output: 6 | html_document: 7 | theme: united 8 | toc: true 9 | number_sections: false 10 | keep_md: true 11 | --- 12 | 13 | 14 | 15 | # About 16 | 17 | Load libraries: 18 | 19 | 20 | ```r 21 | library(magrittr) 22 | library(dplyr) 23 | 24 | library(ggplot2) 25 | theme_set(theme_minimal()) 26 | 27 | library(devtools) 28 | load_all("~/git/variani/finemapr/") 29 | ``` 30 | 31 | # Wakefield's functions 32 | 33 | 34 | ```r 35 | # This function calculates BFDP, the approximate Pr( H0 | thetahat ) 36 | # 37 | # http://faculty.washington.edu/jonno/BFDP.R 38 | # 39 | # doi.org/10.1086/519024, p. 120, formula (6) and above 40 | # 41 | # @param thetahat an estiamte of the log relative risk 42 | # @param V the variance of this estimate 43 | # @param W the prior variance 44 | # @param pi1 the prior probability of a non-null association 45 | BFDPfunV <- function(thetahat, V, W, pi1) 46 | { 47 | pH0 <- dnorm(thetahat, m = 0, s = sqrt(V)) 48 | postvar <- V + W 49 | pH1 <- dnorm(thetahat, m = 0, s = sqrt(postvar)) 50 | BF <- pH0/pH1 51 | 52 | PO <- (1-pi1) / pi1 53 | BFDP <- BF * PO / (BF*PO + 1) 54 | 55 | list(BF = BF, pH0 = pH0, pH1 = pH1, BFDP = BFDP) 56 | } 57 | 58 | # This function computes ABF according to Wakefield (doi.org/10.1086/519024) 59 | # 60 | # doi.org/10.1038/ng.2435, Online Methods, Section Bayesian approach 61 | ABFfun <- function(Z, V, W) 62 | { 63 | r <- W / (V + W) 64 | 65 | (1 / sqrt(1 - r)) * exp(-Z*Z*r/2) 66 | } 67 | ``` 68 | 69 | # Example data set 70 | 71 | 72 | ```r 73 | ex <- example_finemap() 74 | 75 | ss <- ex$tab1 76 | ld <- ex$ld1 # not needed for ABF, be used later on for FINEMAP 77 | N <- 4444 78 | 79 | # simulate standard errors (se) and add effect sizes (effect) 80 | set.seed(1) 81 | ss <- mutate(ss, 82 | se = rnorm(n(), 1/sqrt(N), 0.005), 83 | effect = zscore * se) 84 | 85 | # remove strong signals 86 | ss <- filter(ss, abs(zscore) < 6) 87 | 88 | # sort 89 | ss <- arrange(ss, -abs(zscore)) %>% 90 | mutate(rank = seq(1, n())) %>% select(rank, everything()) 91 | ``` 92 | 93 | # ABF 94 | 95 | 96 | ```r 97 | W <- 0.21^2 # suggested by Wakefield 98 | pi1 <- 1 / nrow(ss) # prior on alternative (association) 99 | 100 | abf <- BFDPfunV(ss$effect, ss$se^2, W, pi1) %>% bind_cols 101 | 102 | abf <- bind_cols(ss, abf) 103 | 104 | abf <- mutate(abf, 105 | ABF = ABFfun(zscore, se^2, W), 106 | ABFinv = (1 / ABF)) 107 | abf <- within(abf, sumABFinv <- sum(ABFinv)) 108 | 109 | abf <- mutate(abf, P1_ABF = ABFinv / sumABFinv) 110 | ``` 111 | 112 | Top 5 SNPs: 113 | 114 | 115 | ```r 116 | head(abf, 5) %>% 117 | select(rank, snp, zscore, BF, ABF, ABFinv, P1_ABF) %>% 118 | pander 119 | ``` 120 | 121 | 122 | ------------------------------------------------------------------- 123 | rank snp zscore BF ABF ABFinv P1_ABF 124 | ------ ------ -------- ----------- ----------- --------- ---------- 125 | 1 rs23 5.773 8.692e-07 8.692e-07 1150477 0.7282 126 | 127 | 2 rs17 -5.585 2.566e-06 2.566e-06 389741 0.2467 128 | 129 | 3 rs42 -4.985 6.484e-05 6.484e-05 15423 0.009762 130 | 131 | 4 rs11 -4.846 8.525e-05 8.525e-05 11730 0.007425 132 | 133 | 5 rs26 4.718 0.0002211 0.0002211 4522 0.002862 134 | ------------------------------------------------------------------- 135 | 136 | # FINEMAP 137 | 138 | 139 | ```r 140 | finemap <- finemapr(ss, ld, n = as.integer(1/0.015^2), 141 | tool = "finemap", args = "--n-causal-max 1") 142 | ``` 143 | 144 | Top 5 SNPs: 145 | 146 | 147 | ```r 148 | head(finemap$snp[[1]], 5) %>% 149 | pander 150 | ``` 151 | 152 | 153 | -------------------------------------------------------------------- 154 | snp rank_z rank_pp snp_prob snp_prob_cumsum snp_log10bf 155 | ------ -------- --------- ---------- ----------------- ------------- 156 | rs23 1 1 0.7008 0.7009 2.042 157 | 158 | rs17 2 2 0.2642 0.9651 1.227 159 | 160 | rs42 3 3 0.0144 0.9795 -0.1637 161 | 162 | rs11 4 4 0.0077 0.9872 -0.4397 163 | 164 | rs26 5 5 0.0044 0.9916 -0.6838 165 | -------------------------------------------------------------------- 166 | 167 | # Final plot: ABF vs. FINEMAP 168 | 169 | 170 | ```r 171 | # join results from two methods 172 | tab <- full_join( 173 | select(finemap$snp[[1]], rank_z, snp, snp_prob) %>% rename(post_finemap = snp_prob), 174 | select(abf, snp, P1_ABF) %>% rename(post_abf = P1_ABF), 175 | by = "snp") %>% 176 | head(9) 177 | 178 | # table for plot 179 | ptab <- gather(tab, method, post_prob, -rank_z, -snp) %>% 180 | mutate( 181 | snp_rank_z = paste0("#", rank_z, "\n", snp), 182 | method = factor(method, labels = c("ABF (Wakefield)", "FINEMAP (Benner)"))) 183 | 184 | # plot 185 | ggplot(ptab, aes(factor(snp_rank_z), post_prob, fill = method)) + 186 | geom_bar(stat = "identity", position = "dodge") + 187 | labs(x = "SNP", y = "Posterior probability") 188 | ``` 189 | 190 | ![](figures/final_plot-1.png) 191 | -------------------------------------------------------------------------------- /R/classFinemaprPaintor.R: -------------------------------------------------------------------------------- 1 | #' S3 class FinemaprPaintor. 2 | #' 3 | #' @name FinemaprPaintor 4 | #' @rdname FinemaprPaintor 5 | #' 6 | #' @exportClass FinemaprPaintor 7 | 8 | #' @rdname FinemaprPaintor 9 | #' @export 10 | print.FinemaprPaintor <- function(x, ...) 11 | { 12 | cat(" - cmd:", x$cmd, "\n") 13 | cat(" - #loci:", x$num_loci, "\n") 14 | cat(" - annotations:", paste(x$annotations, collapse = ", "), "\n") 15 | cat(" - logBF (proportional to the model likelihood):", x$logBF, "\n") 16 | 17 | ret <- lapply(seq(1, x$num_loci), function(i) { 18 | cat(" - locus:",i, "\n") 19 | cat(" -- snp:\n") 20 | print(x$snp[[i]], n = 3) 21 | cat(" -- ", length(x$snps_credible[[i]]), " snps in ", 22 | 100*x$prop_credible, "% credible set", 23 | ": ", paste(x$snps_credible[[i]], collapse = ", "), "...", 24 | "\n", sep = "") 25 | }) 26 | } 27 | 28 | #--------------------- 29 | # Processing methods 30 | #--------------------- 31 | 32 | #' @rdname FinemaprPaintor 33 | #' @export 34 | process_annot.FinemaprPaintor <- function(x, annots, annotations, ...) 35 | { 36 | missing_annot <- missing(annots) 37 | missing_annotations <- missing(annotations) 38 | 39 | # `annot` 40 | if(missing_annot) { 41 | # See comment https://github.com/gkichaev/PAINTOR_V3.0/issues/11#issuecomment-303135031 42 | # about running PAINTOR without annotations: 43 | x$annot <- lapply(seq(1, x$num_loci), function(locus) { 44 | data_frame(dummy_ones = rep(1, nrow(x$tab[[locus]]))) 45 | }) 46 | x$annotations <- "dummy_ones" 47 | } else { 48 | stop("input annotations: not implemented yet") 49 | 50 | if(class(annots)[1] != "list") { 51 | annots <- list(annots) 52 | } 53 | stopifnot(length(annots) == x$num_loci) 54 | 55 | out_lds <- lapply(seq_along(annots), function(locus) { 56 | annot <- annots[[locus]] 57 | 58 | # check annotations 59 | # ... 60 | 61 | list(annot = annot) 62 | }) 63 | 64 | 65 | x$annot <- lapply(out_annot, function(x) x$annot) 66 | 67 | stopifnot(!missing_annotations) 68 | x$annotations <- annotations 69 | } 70 | 71 | return(x) 72 | } 73 | 74 | #--------------------- 75 | # Finemapping methods 76 | #--------------------- 77 | 78 | #' @rdname FinemaprPaintor 79 | #' @export 80 | write_files.FinemaprPaintor <- function(x, ...) 81 | { 82 | ### create `dir` 83 | ret_dir_create <- dir.create(x$dir_run, showWarnings = FALSE, recursive = TRUE) 84 | #stopifnot(ret_dir_create) 85 | 86 | ### write file of Z-scores 87 | ret <- lapply(seq_along(x$tab), function(locus) { 88 | write_delim( 89 | prepare_zscore_writing(x$tab[[locus]]), 90 | file.path(x$dir_run, filename_zscore(x, locus)), 91 | delim = " ", col_names = TRUE) 92 | }) 93 | 94 | ### write file of ld 95 | ret <- lapply(seq_along(x$ld), function(locus) { 96 | write.table(x$ld[[locus]], 97 | file.path(x$dir_run, filename_ld(x, locus)), 98 | sep = " ", row.names = FALSE, col.names = FALSE) 99 | }) 100 | 101 | ### write file of annotations 102 | ret <- lapply(seq_along(x$annot), function(locus) { 103 | write_delim( 104 | x$annot[[locus]], 105 | file.path(x$dir_run, filename_annot(x, locus)), 106 | delim = " ", col_names = TRUE) 107 | }) 108 | 109 | ### write master file 110 | lines_master <- sapply(seq(1, x$num_loci), function(locus) paste0(locus, ".region")) 111 | write_lines(lines_master, file.path(x$dir_run, filename_master(x))) 112 | } 113 | 114 | #' @rdname FinemaprPaintor 115 | #' @export 116 | run_tool.FinemaprPaintor <- function(x, ...) 117 | { 118 | annotations_str <- paste(x$annotations, collapse = ",") 119 | tool_input <- paste0("-input ", filename_master(x), 120 | " -Zhead ", finemapr_names_tab_zscore(), 121 | " -LDname ld ", # hard-coded extension of LD files 122 | " -annotations ", annotations_str, 123 | " ", x$args) 124 | cmd <- paste(x$tool, tool_input) 125 | 126 | dir_cur <- getwd() 127 | setwd(x$dir_run) 128 | 129 | ret_run <- try({ 130 | system(cmd, input = tool_input) 131 | }) 132 | 133 | setwd(dir_cur) 134 | 135 | ### return 136 | x$cmd <- cmd 137 | x$ret_run <- ret_run 138 | 139 | return(x) 140 | } 141 | 142 | 143 | #' @rdname FinemaprPaintor 144 | #' @export 145 | collect_results.FinemaprPaintor <- function(x, ...) 146 | { 147 | results <- try({ 148 | lapply(seq(1, x$num_loci), function(locus) { 149 | #log <- read_lines(file.path(x$dir_run, filename_log(x, locus))) 150 | 151 | snp <- file.path(x$dir_run, filename_snp(x, locus)) %>% 152 | read_delim(, delim = " ", col_types = cols()) 153 | stopifnot(ncol(snp) == 3) 154 | names(snp) <- c("snp", "zscore", "snp_prob") 155 | 156 | snp <- select(snp, snp, snp_prob) %>% 157 | arrange(-snp_prob) %>% 158 | mutate( 159 | rank_pp = seq(1, n()), 160 | snp_prob_cumsum = cumsum(snp_prob) / sum(snp_prob)) %>% 161 | select(rank_pp, snp, snp_prob, snp_prob_cumsum, everything()) 162 | 163 | snp <- merge_tab_snp(x$tab[[locus]], snp) 164 | 165 | list( 166 | snp = snp) 167 | }) 168 | }) 169 | 170 | ### check status and return 171 | x$status <- ifelse(class(results)[1] == "try-error", 1, 0) 172 | if(x$status == 0) { 173 | #x$log <- lapply(results, function(x) x$log) 174 | x$snp <- lapply(results, function(x) x$snp) 175 | 176 | x$snps_credible <- extract_credible_set(x) 177 | } 178 | 179 | return(x) 180 | } 181 | 182 | -------------------------------------------------------------------------------- /R/ld.R: -------------------------------------------------------------------------------- 1 | 2 | #' @export 3 | ref_ld <- function(chr = 16, start = 53.767e6, end = 53.768e6, mono = FALSE, 4 | pop = "EUR", snps = NULL, 5 | measure = c("r2", "r", "D"), tol = 1e-10, 6 | strict = FALSE, 7 | format = c("Matrix", "matrix"), 8 | verbose = 0) 9 | { 10 | measure <- match.arg(measure) 11 | format <- match.arg(format) 12 | 13 | stopifnot(requireNamespace("gaston")) 14 | 15 | bed <- ref_bed(chr = chr, start = start, end = end, mono = mono, 16 | pop = pop, snps = snps, 17 | strict = strict, verbose = verbose) 18 | 19 | ld <- gaston::LD(bed, c(1, ncol(bed)), measure = measure) 20 | 21 | ld[abs(ld) < tol] <- 0 22 | 23 | # order by `snps` 24 | if(!is.null(snps)) { 25 | snps_ld <- rownames(ld) 26 | snps_select <- lapply(snps, function(x) which(snps_ld == x)) %>% unlist 27 | 28 | ld <- ld[snps_ld, snps_ld] 29 | } 30 | 31 | ld <- switch(format, 32 | "Matrix" = Matrix(ld), 33 | "matrix" = ld, 34 | stop("error in switch by `format`")) 35 | 36 | return(ld) 37 | } 38 | 39 | #' @export 40 | ref_pop <- function() 41 | { 42 | path.package("finemapr") %>% 43 | file.path("inst/extdata/pop_label_phase3_2504_without_rels") %>% 44 | read_delim(delim = " ", col_types = cols()) 45 | } 46 | 47 | #' @export 48 | ref_bed <- function(chr = 16, start = 53.767e6, end = 53.768e6, mono = FALSE, 49 | pop = "EUR", snps = NULL, 50 | strict = FALSE, 51 | verbose = 0) 52 | { 53 | ### inc 54 | stopifnot(requireNamespace("RCurl")) 55 | stopifnot(requireNamespace("gaston")) 56 | 57 | ### agrs 58 | groups_pop <- pop # rename 59 | 60 | ### url 61 | url <- paste0("http://tabix.iobio.io/?cmd=-h%20%27", 62 | "http://bochet.gcc.biostat.washington.edu/beagle/1000_Genomes_phase3_v5a/", 63 | "b37.vcf/", 64 | "chr", chr, ".1kg.phase3.v5a.vcf.gz", 65 | "%27%20", chr, ":", start, "-", end) 66 | 67 | if(verbose) { 68 | cat(" - url:", url, "\n") 69 | } 70 | 71 | ### download vcf 72 | vcf <- RCurl::getURL(url) 73 | stopifnot(vcf != "") 74 | 75 | ### convert from vcf to bed (plink) 76 | file_tmp <- tempfile() 77 | write_file(vcf, file_tmp) 78 | 79 | bed <- gaston::read.vcf(file_tmp) 80 | ret <- unlink(file_tmp) 81 | 82 | ### filter by population labels 83 | pop <- ref_pop() 84 | ids <- with(pop, sample[super_pop %in% groups_pop]) 85 | stopifnot(all(ids %in% bed@ped$id)) 86 | 87 | if(verbose) { 88 | cat(" - #individuals:", nrow(bed), "\n") 89 | } 90 | bed <- bed[bed@ped$id %in% ids, ] 91 | if(verbose) { 92 | cat(" -- #individuals after pop. filter:", nrow(bed), "\n") 93 | } 94 | 95 | ### filter monomorphic snps 96 | if(verbose) { 97 | cat(" - #snps:", ncol(bed), "\n") 98 | } 99 | if(!mono) { 100 | bed <- bed[, bed@sigma > 0] 101 | if(verbose) { 102 | cat(" -- #snps after mono. filter:", ncol(bed), "\n") 103 | } 104 | } 105 | 106 | 107 | ### filter by `snps` 108 | if(!is.null(snps)) { 109 | stopifnot(any(snps %in% bed@snps$id)) 110 | 111 | if(!all(snps %in% bed@snps$id)) { 112 | msg <- paste("not all `snps` are found") 113 | 114 | if(strict) { 115 | stop(msg) 116 | } else { 117 | warning(msg) 118 | } 119 | } 120 | 121 | bed <- bed[, bed@snps$id %in% snps] 122 | } 123 | 124 | return(bed) 125 | } 126 | 127 | #---------------------------- 128 | # Functions from proxysnps 129 | #---------------------------- 130 | 131 | #' 132 | #' https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R 133 | #' 134 | #' @export 135 | proxysnps_ref_vcf <- function(chr = 16, start = 53.767e6, end = 53.768e6, pop = "EUR", 136 | snps = NULL, 137 | verbose = 0) 138 | { 139 | ### inc 140 | stopifnot(requireNamespace("proxysnps")) 141 | 142 | ### get genotypes from the ref. panel 143 | if(verbose) { 144 | cat(" - get reference genotypes\n") 145 | } 146 | vcf <- proxysnps::get_vcf(chrom = chr, start = start, end = end, pop = pop) 147 | 148 | ### filter 149 | if(!is.null(snps)) { 150 | vcf$meta <- filter(vcf$meta, ID %in% snps) 151 | 152 | names_snp <- rownames(vcf$geno) 153 | ind_snps <- names_snp %in% snps 154 | vcf$geno <- vcf$geno[ind_snps, ] 155 | } 156 | 157 | return(vcf) 158 | } 159 | 160 | #' 161 | #' https://github.com/slowkow/proxysnps/blob/master/R/get_vcf.R 162 | #' 163 | #' @export 164 | proxysnps_ref_ld <- function(vcf, tol = 1e-10, measure = c("R.squared", "D.prime"), 165 | verbose = 0) 166 | { 167 | ### args 168 | stopifnot(!missing(vcf)) 169 | measure <- match.arg(measure) 170 | 171 | ### inc 172 | stopifnot(requireNamespace("proxysnps")) 173 | 174 | ### the ref. panel 175 | geno <- vcf$geno 176 | 177 | num_snps <- nrow(geno) 178 | names_snps <- rownames(geno) 179 | 180 | ### build LD matrix 181 | ld_elem <- lapply(seq(1, num_snps), function(i) { 182 | if(verbose) { 183 | cat(" - compute ld for snp:", i, "/", num_snps, "\n") 184 | } 185 | 186 | j_val <- seq(i, num_snps) 187 | list(i = rep(i, length(j_val)), j = j_val, 188 | x = sapply(j_val, function(j) { 189 | ifelse(i == j, 1, proxysnps::compute_ld(geno[i, ], geno[j, ])[[measure]]) 190 | })) 191 | }) 192 | 193 | ld <- sparseMatrix( 194 | i = sapply(ld_elem, function(x) x$i) %>% unlist, 195 | j = sapply(ld_elem, function(x) x$j) %>% unlist, 196 | x = sapply(ld_elem, function(x) x$x) %>% unlist, 197 | symmetric = TRUE, 198 | ) 199 | 200 | ld <- drop0(ld, tol = tol) 201 | 202 | rownames(ld) <- names_snps 203 | colnames(ld) <- names_snps 204 | 205 | return(ld) 206 | } 207 | 208 | -------------------------------------------------------------------------------- /R/cojo.R: -------------------------------------------------------------------------------- 1 | 2 | #' Run GCTA-COJO. 3 | #' 4 | #' http://gcta.freeforums.net/thread/178/conditional-joint-analysis-using-summary 5 | #' 6 | #' tab <- "~/git/hemostat/scc/results/sumstats-cojo/sumstats-1.cojo" 7 | #' bed <- "~/git/hemostat/scc/data/FineMapping/forGCTA_onco_r1.bed" 8 | #' 9 | #' @export 10 | cojo <- function(tab, bed, 11 | method = c("select", "cond"), cmd = "", 12 | snps_cond = NULL, 13 | dir_run = "run_cojo", 14 | tool = getOption("finemapr_cojo"), args = "") 15 | { 16 | ### arg 17 | method <- match.arg(method) 18 | stopifnot(class(dir_run) == "character") 19 | 20 | bed <- normalizePath(bed) 21 | bed <- gsub(".bed$", "", bed) 22 | 23 | is_temp_dir <- missing(dir_run) 24 | 25 | ### process input data: `tab` 26 | names_tab <- c("SNP", "A1", "A2", "freq", "b", "se", "p", "N") 27 | 28 | tab <- switch(class(tab)[1], 29 | "character" = read_tsv(tab, col_types = "cccnnnnn"), 30 | as_data_frame(tab)) 31 | stopifnot(ncol(tab) == length(names_tab)) 32 | stopifnot(all(names(tab) == names_tab)) 33 | 34 | snps <- tab$SNP 35 | 36 | ### create `dir` 37 | if(is_temp_dir) { 38 | dir_run <- tempfile(pattern = "run_cojo") 39 | } 40 | 41 | ret_dir_create <- dir.create(dir_run, showWarnings = FALSE, recursive = TRUE, mode = "777") 42 | 43 | ### write files 44 | write_tsv(tab, file.path(dir_run, "region.ma")) 45 | 46 | ### run tool 47 | tool_input <- paste0(" ", args, " --bfile ", bed, " --cojo-file region.ma", 48 | " --out region") 49 | 50 | if(cmd != "") { 51 | tool_input <- paste0(tool_input, " ", cmd) 52 | } else { 53 | if(method == "select") { 54 | tool_input <- paste0(tool_input, " --cojo-slct") 55 | } else if(method == "cond") { 56 | stopifnot(!is.null(snps_cond)) 57 | write_lines(snps_cond, file.path(dir_run, "cond.snplist")) 58 | 59 | tool_input <- paste0(tool_input, " --cojo-cond cond.snplist") 60 | } 61 | } 62 | 63 | cmd <- paste0(tool, tool_input) 64 | 65 | dir_cur <- getwd() 66 | setwd(dir_run) 67 | 68 | ret_run <- try({ 69 | system(cmd, input = tool_input) 70 | }) 71 | 72 | setwd(dir_cur) 73 | 74 | ### read results 75 | log <- file.path(dir_run, "region.log") %>% read_lines 76 | 77 | file_badsnps <- file.path(dir_run, "region.badsnps") 78 | badsnps <- NULL 79 | if(file.exists(file_badsnps)) { 80 | badsnps <- read_tsv(file_badsnps, col_types = "cccc") 81 | } 82 | 83 | file_badfreqs <- file.path(dir_run, "region.freq.badsnps") 84 | badfreqs <- NULL 85 | if(file.exists(file_badfreqs)) { 86 | badfreqs <- read_tsv(file_badfreqs, col_types = "ccccnn") 87 | } 88 | 89 | jma <- snps_index <- cma <- NULL 90 | if(method == "select") { 91 | file_jma <- file.path(dir_run, "region.jma.cojo") 92 | if(file.exists(file_jma)) { 93 | jma <- read_tsv(file_jma, col_types = "ccncdddddddddd") 94 | snps_index <- rev(jma$SNP) # the last snp is the most signif. 95 | } else { # COJO hasn't selected any snp 96 | jma <- data_frame() 97 | snps_index <- character() 98 | } 99 | } else if(method == "cond") { 100 | cma <- read_tsv(file.path(dir_run, "region.cma.cojo")) 101 | } 102 | 103 | ### clean 104 | if(is_temp_dir) { 105 | unlink(dir_run, recursive = TRUE) 106 | } 107 | 108 | ### return 109 | out <- list(cmd = cmd, ret = ret_run, 110 | tab = tab, 111 | # select 112 | jma = jma, log = log, badsnps = badsnps, badfreqs = badfreqs, 113 | snps = snps, snps_index = snps_index, 114 | # cond 115 | snps_cond = snps_cond, cma = cma) 116 | 117 | oldClass(out) <- c("Cojo", oldClass(out)) 118 | 119 | return(out) 120 | } 121 | 122 | #' @export 123 | run_cojo <- function(tab, bed, 124 | args = "", args2 = "", ...) 125 | { 126 | # step 1: select index snps 127 | cojo_select <- cojo(tab, bed, method = "select", args = args, ...) 128 | 129 | snps_index <- cojo_select$snps_index 130 | 131 | ### step 2: conditional analysis for each index snps (`snps_index`) 132 | cond <- lapply(seq_along(snps_index), function(i) { 133 | snp_i <- snps_index[i] 134 | snps_cond <- snps_index[-i] 135 | 136 | if(length(snps_cond)) { 137 | cojo_cond <- cojo(tab, bed, method = "cond", args = args2, snps_cond = snps_cond, ...) 138 | cma <- cojo_cond$cma 139 | } else { 140 | cma <- cojo_select$tab 141 | } 142 | 143 | # abf 144 | abf <- with(cma, abf(b, se, SNP)) 145 | 146 | snp_below <- abf %>% filter(snp_prob_cumsum <= 0.99) 147 | snps_credible <- head(abf, nrow(snp_below) + 1) %$% snp 148 | 149 | # read results 150 | list( 151 | snp_index = snp_i, snps_cond = snps_cond, 152 | cma = cma, abf = abf, snps_credible = snps_credible) 153 | }) 154 | names(cond) <- snps_index 155 | 156 | ### return 157 | out <- cojo_select 158 | out$cond <- cond 159 | 160 | return(out) 161 | } 162 | 163 | plot.Cojo <- function(x, locus = 1, digits = 1) 164 | { 165 | snp_index <- x$cond[[locus]]$snp_index 166 | p <- subset(x$jma, SNP == snp_index , select = "p", drop = TRUE) 167 | pJ <- subset(x$jma, SNP == snp_index , select = "pJ", drop = TRUE) 168 | pC <- subset(x$cond[[locus]]$cma, SNP == snp_index , select = "pC", drop = TRUE) 169 | 170 | str_index_credible <- ifelse( 171 | snp_index %in% x$cond[[locus]]$fm$snps_credible, 172 | "(inside credible set)", 173 | "(outside credible set)") 174 | 175 | str_pval <- paste0("p = ", format.pval(p, digits = digits), 176 | "; pJ = ", format.pval(pJ, digits = digits), "; ", 177 | "pC = ", format.pval(pC, digits = digits)) 178 | 179 | title <- paste0("Index SNP #", locus, ": ", x$cond[[locus]]$snp_index, 180 | " ", str_index_credible) 181 | 182 | plot_zscore(x$cond[[locus]]$fm, selected = snp_index) + 183 | labs(title = title, subtitle = str_pval) 184 | } 185 | 186 | -------------------------------------------------------------------------------- /R/finemapr.R: -------------------------------------------------------------------------------- 1 | 2 | #' Run FINEMAP. 3 | #' 4 | #' @examples 5 | #' ex <- example_finemap() 6 | #' out <- finemapr(list(ex$tab1, ex$tab2), list(ex$ld1, ex$ld2), list(ex$n1, ex$n2), args = "--n-causal-max 1") 7 | #' out <- finemapr(list(ex$tab1, ex$tab2), list(ex$ld1, ex$ld2), list(ex$n1, ex$n2), method = "paintor", args = "-enumerate 1") 8 | #' 9 | #' @export 10 | finemapr <- function(tab, ld, n, 11 | annot, annotations, 12 | prop_credible = 0.95, 13 | method = c("finemap", "paintor"), 14 | dir_run, 15 | tool, args = "", 16 | # finemap par 17 | prior_k, 18 | # other par 19 | save_ld = FALSE, 20 | ret = c("results", "zscore", "ld")) 21 | { 22 | ### arg 23 | method <- match.arg(method) 24 | ret <- match.arg(ret) 25 | 26 | missing_tab <- missing(tab) 27 | missing_ld <- missing(ld) 28 | missing_n <- missing(n) 29 | 30 | missing_prior_k <- missing(prior_k) 31 | 32 | if(missing(tool)) { 33 | tool <-switch(method, 34 | "finemap" = getOption("finemapr_finemap"), 35 | "paintor" = getOption("finemapr_paintor"), 36 | stop("error in switch")) 37 | } 38 | 39 | ### create an object of class `Finemapr`: basic slots and class attribute 40 | out <- list(method = method, tool = tool, 41 | dir_run = paste("run", method, sep = "_"), args = args, 42 | # finemap slots 43 | prior_k = switch(missing_prior_k + 1, prior_k, NULL), 44 | # other slots 45 | num_loci = ifelse(class(tab)[1] == "list", length(tab), 1), 46 | prop_credible = prop_credible) 47 | 48 | class_finemapr <- switch(out$method, 49 | "finemap" = "FinemaprFinemap", 50 | "paintor" = "FinemaprPaintor", 51 | stop("switch error on `method`")) 52 | oldClass(out) <- c(class_finemapr, "Finemapr", oldClass(out)) 53 | 54 | ### process input 55 | stopifnot(!missing_tab) 56 | out <- process_tab(out, tab) 57 | if(ret == "zscore") return(out) 58 | 59 | stopifnot(!missing_ld) 60 | out <- process_ld(out, ld) 61 | if(ret == "ld") return(out) 62 | 63 | stopifnot(!missing_n) 64 | out <- process_n(out, n) 65 | 66 | if(method == "paintor") { 67 | out <- process_annot(out, annot, annotations) 68 | } 69 | 70 | ### write files 71 | write_files(out) 72 | 73 | #### run 74 | out <- run_tool(out) 75 | 76 | #### read results 77 | out <- collect_results(out) 78 | 79 | ### return 80 | if(!save_ld) { 81 | out$ld <- NULL 82 | } 83 | 84 | return(out) 85 | } 86 | 87 | #' @rdname Finemapr 88 | #' @export 89 | process_tab.Finemapr <- function(x, tabs, ...) 90 | { 91 | ### process input 92 | if(class(tabs)[1] != "list") { 93 | tabs <- list(tabs) 94 | } 95 | 96 | stopifnot(length(tabs) == x$num_loci) 97 | 98 | ### prepare tabels of Z-scores 99 | out_tabs <- lapply(tabs, function(tab) { 100 | tab <- as_data_frame(tab) 101 | 102 | stopifnot(ncol(tab) >= 2) 103 | 104 | names_all <- names(tab) 105 | names_select <- c( 106 | finemapr_find_name("snp", names_all, strict = TRUE), 107 | finemapr_find_name("zscore", names_all, strict = TRUE)) 108 | names_new <- finemapr_names_tab() 109 | 110 | name_pos <- finemapr_find_name("pos", names_all, strict = FALSE) 111 | if(!is.null(name_pos)) { 112 | names_select <- c(names_select, name_pos) 113 | names_new <- c(names_new, finemapr_names_tab_pos()) 114 | } 115 | 116 | tab <- select_(tab, .dots = names_select) 117 | names(tab) <- names_new 118 | 119 | # manage missing Z-scores 120 | snps_zscore_missing <- filter(tab, is.na(zscore)) %$% snp 121 | tab <- filter(tab, !is.na(zscore)) 122 | 123 | # arrange & add `rank_pp` column 124 | tab <- arrange(tab, -abs(zscore)) %>% 125 | mutate(rank_z = seq(1, n())) %>% 126 | select(rank_z, everything()) 127 | 128 | list(tab = tab, 129 | snps_zscore_missing = snps_zscore_missing) 130 | }) 131 | 132 | ### write back to `x` and return 133 | x$tab <- lapply(out_tabs, function(x) x$tab) 134 | x$snps_zscore <- lapply(out_tabs, function(x) x$tab[[finemapr_names_tab_snp()]]) 135 | 136 | x$snps_zscore_missing <- lapply(out_tabs, function(x) x$snps_zscore_missing) 137 | 138 | return(x) 139 | } 140 | 141 | #' @rdname Finemapr 142 | #' @export 143 | process_ld.Finemapr <- function(x, lds, ...) 144 | { 145 | ### process input 146 | if(class(lds)[1] != "list") { 147 | lds <- list(lds) 148 | } 149 | 150 | stopifnot(length(lds) == x$num_loci) 151 | 152 | ### prepare tabels of Z-scores 153 | out_lds <- lapply(seq_along(lds), function(locus) { 154 | ld <- lds[[locus]] 155 | 156 | stopifnot(class(ld) == "matrix") 157 | stopifnot(!is.null(colnames(ld))) 158 | stopifnot(!is.null(rownames(ld))) 159 | 160 | # manage SNP names across variables: ld, zscore 161 | snps_ld <- colnames(ld) 162 | snps_zscore <- x$snps_zscore[[locus]] 163 | 164 | ind <- snps_ld %in% snps_zscore 165 | snps_finemap <- snps_ld[ind] 166 | snps_missing_finemap <- snps_zscore[!(snps_zscore %in% snps_finemap)] 167 | snps_missing_ld <- snps_ld[!ind] 168 | 169 | # check the proportion of `snps_missing_ld` 170 | prop_snps_missing <- length(snps_missing_ld) / 171 | (length(snps_missing_ld) + length(snps_finemap)) 172 | #stopifnot(prop_snps_missing < 0.20) 173 | 174 | # subset LD matrix 175 | ld <- ld[snps_finemap, snps_finemap] 176 | 177 | # some tools require all diagonals to be `1` 178 | stopifnot(all(round(diag(ld), 4) == 1)) 179 | diag(ld) <- 1 180 | 181 | list(ld = ld, 182 | snps_missing_ld = snps_missing_ld, 183 | snps_finemap = snps_finemap, 184 | snps_missing_finemap = snps_missing_finemap) 185 | }) 186 | 187 | x$ld <- lapply(out_lds, function(x) x$ld) 188 | x$snps_missing_ld <- lapply(out_lds, function(x) x$snps_missing_ld) 189 | x$snps_finemap <- lapply(out_lds, function(x) x$snps_finemap) 190 | x$snps_missing_finemap <- lapply(out_lds, function(x) x$snps_missing_finemap) 191 | 192 | for(i in seq(1, x$num_loci)) { 193 | x$tab[[i]] <- mutate(x$tab[[i]], finemap = snp %in% x$snps_finemap[[1]]) 194 | } 195 | 196 | return(x) 197 | } 198 | 199 | process_n.Finemapr <- function(x, ns, ...) 200 | { 201 | ### process input 202 | if(class(ns)[1] != "list") { 203 | ns <- list(ns) 204 | } 205 | 206 | if(length(ns) == 1) { 207 | n <- ns[[1]] 208 | stopifnot(length(n) == 1) 209 | ns <- rep(n, x$num_loci) %>% as.list 210 | } 211 | stopifnot(length(ns) == x$num_loci) 212 | 213 | x$n <- ns 214 | 215 | return(x) 216 | } 217 | -------------------------------------------------------------------------------- /R/classFinemaprFinemap.R: -------------------------------------------------------------------------------- 1 | #' S3 class FinemaprFinemap. 2 | #' 3 | #' @name FinemaprFinemap 4 | #' @rdname FinemaprFinemap 5 | #' 6 | #' @exportClass FinemaprFinemap 7 | 8 | #--------------------- 9 | # Finemapping methods 10 | #--------------------- 11 | 12 | #' @rdname FinemaprFinemap 13 | #' @export 14 | write_files.FinemaprFinemap <- function(x, ...) 15 | { 16 | ### create `dir` 17 | ret_dir_create <- dir.create(x$dir_run, showWarnings = FALSE, recursive = TRUE) 18 | #stopifnot(ret_dir_create) 19 | 20 | ### write file of Z-scores 21 | ret <- lapply(seq_along(x$tab), function(locus) { 22 | write_delim( 23 | prepare_zscore_writing(x$tab[[locus]]), 24 | file.path(x$dir_run, filename_zscore(x, locus)), 25 | delim = " ", col_names = FALSE) 26 | }) 27 | 28 | ### write file of ld 29 | ret <- lapply(seq_along(x$ld), function(locus) { 30 | write.table(x$ld[[locus]], 31 | file.path(x$dir_run, filename_ld(x, locus)), 32 | sep = " ", row.names = FALSE, col.names = FALSE) 33 | }) 34 | 35 | ### write master file 36 | lines_master <- c( 37 | paste0("z;ld;snp;config", 38 | ifelse(is.null(x$prior_k), "", ";k"), 39 | ";log;n-ind"), 40 | sapply(seq(1, x$num_loci), function(locus) { 41 | paste0( 42 | filename_zscore(x, locus), ";", 43 | filename_ld(x, locus), ";", 44 | filename_snp(x, locus), ";", 45 | filename_config(x, locus), ";", 46 | ifelse(is.null(x$prior_k), "", paste0(filename_k(x, locus), ";")), 47 | filename_log(x, locus), ";", 48 | x$n[[locus]]) 49 | })) 50 | write_lines(lines_master, file.path(x$dir_run, filename_master(x))) 51 | 52 | ### write optional files 53 | if(!is.null(x$prior_k)) { 54 | ret <- lapply(seq(1, x$num_loci), function(locus) { 55 | write_lines(paste(x$prior_k, collapse = " "), file.path(x$dir_run, filename_k(x, locus))) 56 | }) 57 | } 58 | } 59 | 60 | #' @rdname FinemaprFinemap 61 | #' @export 62 | run_tool.FinemaprFinemap <- function(x, ...) 63 | { 64 | tool_input <- paste0("--sss --log ", 65 | ifelse(is.null(x$prior_k), "", " --prior-k "), 66 | x$args, " --in-files ", filename_master(x)) 67 | cmd <- paste(x$tool, tool_input) 68 | 69 | dir_cur <- getwd() 70 | setwd(x$dir_run) 71 | 72 | ret_run <- try({ 73 | system(cmd, input = tool_input) 74 | }) 75 | 76 | setwd(dir_cur) 77 | 78 | ### return 79 | x$cmd <- cmd 80 | x$ret_run <- ret_run 81 | 82 | return(x) 83 | } 84 | 85 | #' @rdname FinemaprFinemap 86 | #' @export 87 | collect_results.FinemaprFinemap <- function(x, ...) 88 | { 89 | results <- try({ 90 | lapply(seq(1, x$num_loci), function(locus) { 91 | log <- read_lines(file.path(x$dir_run, filename_log(x, locus))) 92 | 93 | snp <- file.path(x$dir_run, filename_snp(x, locus)) %>% 94 | read_delim(, delim = " ", col_types = cols()) 95 | 96 | snp <- arrange(snp, -snp_prob) %>% 97 | mutate( 98 | rank_pp = seq(1, n()), 99 | snp_prob_cumsum = cumsum(snp_prob) / sum(snp_prob)) %>% 100 | select(rank_pp, snp, snp_prob, snp_prob_cumsum, snp_log10bf) 101 | 102 | snp <- merge_tab_snp(x$tab[[locus]], snp) 103 | 104 | list( 105 | log = log, 106 | snp = snp, 107 | config = file.path(x$dir_run, filename_config(x, locus)) %>% 108 | read_delim(, delim = " ", col_types = cols()), 109 | ncausal = finemap_extract_ncausal(log)) 110 | }) 111 | }) 112 | 113 | ### check status and return 114 | x$status <- ifelse(class(results)[1] == "try-error", 1, 0) 115 | if(x$status == 0) { 116 | x$log <- lapply(results, function(x) x$log) 117 | x$snp <- lapply(results, function(x) x$snp) 118 | x$config <- lapply(results, function(x) x$config) 119 | x$ncausal <- lapply(results, function(x) x$ncausal) 120 | 121 | x$snps_credible <- extract_credible_set(x) 122 | } 123 | 124 | return(x) 125 | } 126 | 127 | #--------------------- 128 | # Print/plot methods 129 | #--------------------- 130 | 131 | #' @rdname FinemaprFinemap 132 | #' @export 133 | print.FinemaprFinemap <- function(x, ...) 134 | { 135 | cat(" - tables of results: `config`, `snp`, `ncausal`\n") 136 | 137 | ret <- lapply(seq(1, x$num_loci), function(i) { 138 | cat(" - locus:",i, "\n") 139 | cat(" -- config:\n") 140 | cat(" -- input snps: ", length(x$snps_finemap[[i]]), " fine-mapped", 141 | " + ", length(x$snps_missing_finemap[[i]]), " missing Z/LD", 142 | " = ", length(x$snps_zscore[[i]]), " in total\n", sep = "") 143 | print(x$config[[i]], n = 3) 144 | cat(" -- snp:\n") 145 | print(x$snp[[i]], n = 3) 146 | cat(" -- ", length(x$snps_credible[[i]]), " snps in ", 147 | 100*x$prop_credible, "% credible set", 148 | ": ", paste(x$snps_credible[[i]], collapse = ", "), "...", 149 | "\n", sep = "") 150 | }) 151 | 152 | return(invisible()) 153 | 154 | cat(" - command:", x$cmd, "\n") 155 | 156 | if(x$status) { 157 | cat(" - see log output in `log`\n") 158 | cat(" - tables of results: `config`, `snp`, `ncausal`\n") 159 | 160 | cat(" - config:\n") 161 | print(x$config, n = 3) 162 | 163 | } 164 | } 165 | 166 | #' @rdname FinemaprFinemap 167 | #' @export 168 | plot.FinemaprFinemap <- function(x, 169 | grid_nrow = NULL, grid_ncol = NULL, 170 | label_size = getOption("finemapr_label_size"), 171 | label_size_config = label_size, label_size_snp = label_size, 172 | top_rank = getOption("top_rank"), 173 | top_rank_config = top_rank, top_rank_snp = top_rank, 174 | lim_prob = getOption("lim_prob"), 175 | lim_prob_config = lim_prob, lim_prob_snp = lim_prob, lim_prob_ncausal = lim_prob, 176 | ...) 177 | { 178 | p1 <- plot_ncausal(x, 179 | lim_prob = lim_prob_ncausal, ...) 180 | p2 <- plot_config(x, 181 | top_rank = top_rank_config, 182 | label_size = label_size_config, 183 | lim_prob = lim_prob_config, ...) 184 | p3 <- plot_snp(x, 185 | top_rank = top_rank_snp, 186 | label_size = label_size_snp, 187 | lim_prob = lim_prob_snp, ...) 188 | 189 | plot_grid(p1, p2, p3, nrow = grid_nrow, ncol = grid_ncol) 190 | } 191 | 192 | #--------------- 193 | # Custom methods 194 | #--------------- 195 | 196 | #' @rdname FinemaprFinemap 197 | #' @export 198 | plot_ncausal.FinemaprFinemap <- function(x, locus = 1, 199 | lim_prob = c(0, 1), # automatic limits 200 | ...) 201 | { 202 | ptab <- x$ncausal[[locus]] 203 | 204 | sum_prop_zero <- filter(ptab, ncausal_num == 0)[["prob"]] %>% sum 205 | if(sum_prop_zero == 0) { 206 | ptab <- filter(ptab, ncausal_num != 0) 207 | } 208 | 209 | ptab <- mutate(ptab, 210 | ncausal_num = factor(ncausal_num, levels = sort(unique(ncausal_num), decreasing = TRUE)), 211 | type = factor(type, levels = c("prior", "post"))) 212 | 213 | p <- ggplot(ptab, aes(ncausal_num, ncausal_prob, fill = type)) + 214 | geom_hline(yintercept = 1, linetype = 3) + 215 | geom_bar(stat = "identity", position = "dodge") + 216 | coord_flip() + theme(legend.position = "top") + 217 | scale_fill_manual(values = c("grey50", "orange")) + 218 | ylim(lim_prob) 219 | 220 | return(p) 221 | } 222 | 223 | #' @rdname FinemaprFinemap 224 | #' @export 225 | plot_config.FinemaprFinemap <- function(x, locus = 1, 226 | lim_prob = c(0, 1.5), 227 | label_size = getOption("finemapr_label_size"), 228 | top_rank = getOption("top_rank"), 229 | ...) 230 | { 231 | ptab <- x$config[[locus]] 232 | 233 | ptab <- head(ptab, top_rank) 234 | 235 | ptab <- mutate(ptab, 236 | label = paste0(config, "\n", 237 | "P = ", round(config_prob, 2), 238 | "; ", "log10(BF) = ", round(config_log10bf, 2))) 239 | 240 | ggplot(ptab, aes(config_prob, rank)) + 241 | geom_vline(xintercept = 1, linetype = 3) + 242 | geom_point() + 243 | geom_segment(aes(xend = config_prob, yend = rank, x = 0)) + 244 | geom_text(aes(label = label), hjust = 0, nudge_x = 0.025, size = label_size) + 245 | xlim(lim_prob) + 246 | scale_y_continuous(limits = c(top_rank + 0.5, 0.5), trans = "reverse") 247 | } 248 | 249 | #' @rdname FinemaprFinemap 250 | #' @export 251 | plot_snp.FinemaprFinemap <- function(x, locus = 1, 252 | lim_prob = c(0, 1.5), 253 | label_size = getOption("finemapr_label_size"), 254 | top_rank = getOption("top_rank"), 255 | ...) 256 | { 257 | ptab <- x$snp[[locus]] 258 | 259 | ptab <- head(ptab, top_rank) 260 | 261 | ptab <- mutate(ptab, 262 | rank = seq(1, n()), 263 | label = paste0(snp, "\n", 264 | "P = ", round(snp_prob, 2), 265 | "; ", "log10(BF) = ", round(snp_log10bf, 2))) 266 | 267 | ggplot(ptab, aes(snp_prob, rank)) + 268 | geom_vline(xintercept = 1, linetype = 3) + 269 | geom_point() + 270 | geom_segment(aes(xend = snp_prob, yend = rank, x = 0)) + 271 | geom_text(aes(label = label), hjust = 0, nudge_x = 0.025, size = label_size) + 272 | xlim(lim_prob) + 273 | scale_y_continuous(limits = c(top_rank + 0.5, 0.5), trans = "reverse") 274 | } 275 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /inst/extdata/region1.ld: -------------------------------------------------------------------------------- 1 | 1 0.958915878348834 0.988406234676078 -0.259844797678395 -0.382653022135109 0.580085291609514 0.921283974315148 -0.412990365660631 0.264158885974777 0.948529077121217 0.209299981205139 0.954849709114191 0.894522340668199 0.940168616393564 0.184522133697024 0.868821973518906 0.221734657014474 0.663805039510673 -0.143447218691015 -0.375967541005191 0.746971744989 0.365161325952025 0.48443456511356 0.730468140396773 0.673670199171113 0.41869337185046 -0.374152883487186 0.717461697695825 0.719648099724783 0.685211908754241 0.976418418879537 0.895591210181543 0.896631204742192 -0.361286884144309 0.668033909177708 0.652781048750955 0.976015757360389 0.484938973117808 0.911505507082877 0.718958463586773 -0.457614963470182 -0.397752390967649 -0.732897973729816 -0.479236220219959 -0.354555920427379 -0.712192812759167 0.166421118660688 -0.755584396504715 -0.459133420246085 -0.624088771832244 2 | 0.958915878348834 1 0.969785715388776 -0.249628948485653 -0.366012082864543 0.576289451736986 0.88153431410239 -0.398092814570541 0.105160110010022 0.898878314636847 0.196126772737131 0.932180524272568 0.873603330083361 0.900974160049992 0.207321851025182 0.830848499334874 0.210994108055469 0.634538478751684 -0.115398972196263 -0.360633054980845 0.716246910037132 0.34256002886307 0.409713454444292 0.700227199011173 0.644195305580449 0.326444913681481 -0.358315475242821 0.687757239476336 0.689451991889649 0.693774284523472 0.935665364556918 0.861368028641668 0.856941503961387 -0.344120415086454 0.660565152967993 0.643256875575958 0.933986712889575 0.445799275640874 0.864553956425919 0.688324325381134 -0.431428516780903 -0.381910374549263 -0.692083999980651 -0.450634025039308 -0.338028909238867 -0.669518389961215 0.195678627749168 -0.716412676371418 -0.430569661007395 -0.582082014300394 3 | 0.988406234676078 0.969785715388776 1 -0.257828916247359 -0.379302784312314 0.54832684779828 0.910346347413542 -0.408270309506842 0.27115011564067 0.934396522662073 0.206372768859463 0.965867470100601 0.90674327226399 0.929603865917094 0.192374777792789 0.858786514253595 0.218560511748563 0.654853799546894 -0.136825481414931 -0.372609877961363 0.737564748133678 0.326499305806978 0.497653504696626 0.721187745650351 0.664763399487566 0.429906328660207 -0.370751640640785 0.708030355440798 0.710533789860845 0.660504793200351 0.964995554287411 0.885650996470911 0.884160286216347 -0.357512544458661 0.683069155527401 0.667254324181404 0.964172891937013 0.474715651983955 0.900752255485674 0.70931903106437 -0.449670675602408 -0.393780400838662 -0.721082362462986 -0.470364438442525 -0.351226583912354 -0.700095259780041 0.176782616982291 -0.744331527704319 -0.450242291309177 -0.610127049900577 4 | -0.259844797678395 -0.249628948485653 -0.257828916247359 1 -0.128153395608402 -0.139379539110059 -0.287704311621747 0.678949250776511 -0.080405701759235 -0.242679993941844 0.0758891262373443 -0.252203819972984 -0.272435046331101 -0.280720130648115 -0.0901982665057285 -0.308498762598236 0.0684917308841777 -0.392885762041944 -0.159331408195816 -0.127829594529351 -0.352119299521025 -0.0958683565553189 -0.141637147001454 -0.353749304511549 -0.389837805944321 -0.123102465134157 -0.128555243206145 -0.342544984949329 -0.350005703352331 -0.168278176905818 -0.262821764342503 -0.264447430161622 -0.242615659161401 -0.128544158553991 -0.359198340710449 -0.3555848932167 -0.259795765479986 -0.289432633541738 -0.245295336253717 -0.356252607063709 0.48605222600608 -0.148500532626267 0.294105766212621 0.456066029785199 -0.126712165175628 0.287241577378231 -0.142687686771452 0.299890467780891 0.460990961039009 0.315809951964561 5 | -0.382653022135109 -0.366012082864543 -0.379302784312314 -0.128153395608402 1 -0.211103606170278 -0.414182414672329 -0.180917354299075 -0.109036242967758 -0.361660176147942 0.073966367428385 -0.365760839694343 -0.387146435651604 -0.407742916541125 -0.0434965151604948 -0.439158121759379 0.0879806555127451 0.275968669091267 0.764633905823257 0.946492303781998 0.270774991279378 -0.108174485310311 -0.187378814427303 0.299215703597156 0.269970675140715 -0.16288266868674 0.933422365536599 0.284658383248052 0.290624052992991 -0.265161381408746 -0.38064621547659 -0.375708294320626 -0.35106752089647 0.916201177524063 0.187274768568002 0.193662883520786 -0.375801808036692 0.322294683889848 -0.346149461314868 0.287640301213875 -0.209862444450443 0.760071769477192 0.392712664330017 -0.219789265006251 0.875931428889538 0.388329055081097 -0.175888633934313 0.402050964728065 -0.217526737238164 0.221926170234028 6 | 0.580085291609514 0.576289451736986 0.54832684779828 -0.139379539110059 -0.211103606170278 1 0.534500849153271 -0.235469225820979 -0.13631037653569 0.556630269757555 0.090285621902192 0.542188228921632 0.453905656549238 0.543499852594633 0.227694712558635 0.502722245305359 0.129830913533694 0.390527702187163 0.119957644145761 -0.215434206345093 0.434533733511582 0.649902607299447 -0.194384438734768 0.423186710263817 0.394650741721098 -0.174226699005713 -0.21436104828446 0.415503576845842 0.413580601751268 0.826779715843693 0.564415445435154 0.504303493317321 0.545351762268711 -0.214433321718388 0.33022541370084 0.339773618879325 0.566979638475493 0.183523909614385 0.553609010359332 0.417888534439893 -0.321267618837198 -0.231159983188497 -0.491971417294722 -0.328409879034009 -0.209642847103982 -0.503109190362281 -0.169170612901843 -0.482839517160104 -0.319564457773858 -0.346787756200073 7 | 0.921283974315148 0.88153431410239 0.910346347413542 -0.287704311621747 -0.414182414672329 0.534500849153271 1 -0.45083507859556 0.245146309106748 0.876058284744181 0.234509436175604 0.879300426419644 0.812008384877436 0.855988411336005 0.154426129514702 0.936475469250184 0.243055240465156 0.716380320934385 -0.188995655020901 -0.409143745952785 0.644195699229897 0.341711963570879 0.44870041267681 0.628306842162483 0.727320850968865 0.386073676967086 -0.409121432812807 0.609220736678785 0.61732545494252 0.631852101815047 0.898478016304498 0.898191676019455 0.82715576252789 -0.397054992608695 0.649213907089917 0.635775774911593 0.899218486938957 0.492785605397124 0.838498994435903 0.617160887003045 -0.493095716888445 -0.25724847890251 -0.656321061245214 -0.514258960358027 -0.389806043095773 -0.63842328923836 0.140546231190317 -0.676440154302622 -0.492018831567249 -0.543257005249675 8 | -0.412990365660631 -0.398092814570541 -0.408270309506842 0.678949250776511 -0.180917354299075 -0.235469225820979 -0.45083507859556 1 -0.107816629024594 -0.392719214531608 0.120221418994352 -0.39514997789915 -0.230416056497639 -0.253549643293054 -0.0352083220563117 -0.295772880652928 0.118791238942925 -0.609570219681912 -0.232044647077705 -0.169290519899749 -0.533192002401318 -0.151672656181735 -0.210497242315567 -0.530821053145709 -0.585278670091868 -0.179133387916063 -0.166901493601962 -0.518102296308399 -0.524427603693704 -0.263779892572702 -0.409195287991391 -0.407339354076644 -0.370174411076938 -0.16447816368291 -0.512707278472249 -0.507120538519508 -0.397131218240919 -0.437354761790741 -0.369570002739153 -0.519227967573749 0.515954615790076 -0.181589506811246 0.280665413448472 0.472700100234848 -0.143827316535308 0.269636521862351 -0.213958732081952 0.287683292423936 0.482122313230438 0.291878785443115 9 | 0.264158885974777 0.105160110010022 0.27115011564067 -0.080405701759235 -0.109036242967758 -0.13631037653569 0.245146309106748 -0.107816629024594 1 0.253164524670867 0.0690815941835067 0.290426057676825 0.276374655681524 0.253360824987749 -0.0878807458966483 0.235649004996498 0.0570491275009775 0.171466273972016 -0.132638799598091 -0.103434105874551 0.192526158734931 -0.0871040220487315 0.573642582879529 0.189628361987799 0.17410987152808 0.647593562743613 -0.105342453231689 0.184372969503271 0.188317247456127 -0.14843365967137 0.259916986383819 0.216145966671841 0.18972723080638 -0.107645692839544 0.181960322122467 0.188949344103418 0.26250149214871 0.223014605189281 0.291220434811279 0.187859477570516 -0.155412510856695 -0.111354063914277 -0.236419908469704 -0.155876448620069 -0.10122715173444 -0.242715879789893 0.131939644168518 -0.232162704808467 -0.152588101458879 -0.230561738627609 10 | 0.948529077121217 0.898878314636847 0.934396522662073 -0.242679993941844 -0.361660176147942 0.556630269757555 0.876058284744181 -0.392719214531608 0.253164524670867 1 0.197064300064829 0.897963975867325 0.837540618508513 0.890237521167491 0.209277260564716 0.824784923357682 0.210663469691087 0.628670923844642 -0.135620421018972 -0.357534496285564 0.706918701633282 0.392080890782839 0.469883417348642 0.691431928091232 0.640513853008201 0.413804168676103 -0.354972466547826 0.678840353528233 0.681024199846205 0.668805885298146 0.92478486607932 0.840406380987309 0.845504222603324 -0.341772139510757 0.631580666977094 0.61428951793318 0.924584368459878 0.441928690790558 0.855287277726827 0.681720493347957 -0.425733008953336 -0.372091805569095 -0.712363094274212 -0.447510887237595 -0.334140935177582 -0.6886996120922 0.130968218280632 -0.706308502510123 -0.426732757697918 -0.573639253491821 11 | 0.209299981205139 0.196126772737131 0.206372768859463 0.0758891262373443 0.073966367428385 0.090285621902192 0.234509436175604 0.120221418994352 0.0690815941835067 0.197064300064829 1 0.206346290471728 0.239971870453819 0.229953075199917 0.0895657002371102 0.25387477332724 0.952960287325485 0.2851537356773 0.0865691908559938 0.056000254156964 0.253932021771759 0.06835910603621 0.1206251595143 0.254772984439438 0.282258467909429 0.101900094345014 0.0595317731356116 0.269507837668157 0.252542618861881 0.13691684168227 0.213211092376333 0.209968318524511 0.190355458149087 0.0619752290801055 0.278414519609558 0.274451126365285 0.208155539024951 0.256779912213788 0.191561216810638 0.256198908931941 0.153930205513287 0.08090812978546 0.213900595743666 0.157884847786756 0.0614653608978046 0.215071164638781 -0.533600530293951 0.207597761080327 0.150145510785862 0.205169480861282 12 | 0.954849709114191 0.932180524272568 0.965867470100601 -0.252203819972984 -0.365760839694343 0.542188228921632 0.879300426419644 -0.39514997789915 0.290426057676825 0.897963975867325 0.206346290471728 1 0.884167655445665 0.898785001944692 0.211146505603973 0.830028196228013 0.211710285136603 0.634240251468159 -0.121670559182995 -0.360146151642616 0.714211441864982 0.305961405313155 0.50449704379806 0.698838433918893 0.642732261611208 0.460149832357348 -0.358429243641504 0.687367942016089 0.687965290530645 0.620620633821239 0.940375080743251 0.869340227622266 0.86574930533451 -0.349251296390743 0.692274478893501 0.686691510867674 0.943987905716507 0.449891117185949 0.874470318251234 0.693189905895554 -0.433318408702092 -0.395196365606983 -0.700279188990884 -0.447107213427667 -0.352176814356685 -0.677570113691058 0.176675830597558 -0.723976154664494 -0.428544690018879 -0.584016904249184 13 | 0.894522340668199 0.873603330083361 0.90674327226399 -0.272435046331101 -0.387146435651604 0.453905656549238 0.812008384877436 -0.230416056497639 0.276374655681524 0.837540618508513 0.239971870453819 0.884167655445665 1 0.960059117470704 0.186024495557931 0.884847681528564 0.226985475884702 0.548331065777622 -0.168960951603098 -0.368376328809403 0.64689437692368 0.263334717697999 0.499303612933898 0.631205934151776 0.567904998736872 0.432736064630631 -0.364839554264625 0.614745727968641 0.622100430071168 0.553610479833939 0.871376981781098 0.801479362691558 0.8069772023099 -0.351399671041573 0.609235807380092 0.605686737376131 0.872214823476892 0.414499394600907 0.808477533473165 0.621156792852798 -0.464773826887131 -0.394352367314565 -0.73605977845415 -0.486963471310087 -0.344643077965233 -0.71508598646008 0.165730370674587 -0.759769344358889 -0.466537337871755 -0.62577504153852 14 | 0.940168616393564 0.900974160049992 0.929603865917094 -0.280720130648115 -0.407742916541125 0.543499852594633 0.855988411336005 -0.253549643293054 0.253360824987749 0.890237521167491 0.229953075199917 0.898785001944692 0.960059117470704 1 0.159670132532653 0.923575998576761 0.237878100845327 0.581528078588426 -0.164677463574978 -0.385343133987035 0.681461528304763 0.341468641420732 0.459899424892659 0.664837807249467 0.601234907541748 0.397592249792733 -0.381799647375748 0.648532882115491 0.654896499757257 0.640347987698131 0.916467749072252 0.837853490942191 0.843899588593159 -0.368965956749825 0.604996970679284 0.591260457619282 0.918051589739375 0.43336242156336 0.857941131915175 0.655392403565968 -0.491575092985228 -0.410751906716745 -0.77785987544119 -0.515195278144816 -0.361047158802351 -0.758063433313506 0.137589494839341 -0.798581707596576 -0.4947616819797 -0.666680141796551 15 | 0.184522133697024 0.207321851025182 0.192374777792789 -0.0901982665057285 -0.0434965151604948 0.227694712558635 0.154426129514702 -0.0352083220563117 -0.0878807458966483 0.209277260564716 0.0895657002371102 0.211146505603973 0.186024495557931 0.159670132532653 1 0.129801133415458 0.080860656540656 0.121837888633684 0.267242178252091 -0.0480014505046212 0.156596506186287 -0.0839075709973898 0.0786095999808551 0.153281392197004 0.124752049055163 0.119945144766283 -0.0456312804981439 0.164572283191726 0.15440881193372 0.178939019433833 0.184970213033004 0.201949829768938 0.243525032048046 -0.0506853118178806 0.147956589100792 0.15363235257343 0.189960722438181 -0.195961999200347 0.0332914271847469 0.156553738501672 0.103377569032828 -0.084595865469178 0.00943770919231906 0.0907526712644418 -0.0495212702076274 0.00059052952781094 -0.145456265971368 0.0178463612508217 0.103769135193177 -0.0254105273726132 16 | 0.868821973518906 0.830848499334874 0.858786514253595 -0.308498762598236 -0.439158121759379 0.502722245305359 0.936475469250184 -0.295772880652928 0.235649004996498 0.824784923357682 0.25387477332724 0.830028196228013 0.884847681528564 0.923575998576761 0.129801133415458 1 0.258342958917321 0.643412923598097 -0.206228375382355 -0.415826859795315 0.588295734291542 0.320618988172719 0.427578407249128 0.571838733609972 0.663267593377719 0.367299601681881 -0.414615123017539 0.549464943052351 0.561643949861054 0.591393417767394 0.845635900460856 0.846926454163487 0.78097695654833 -0.40254256179239 0.592701602026894 0.580660327460084 0.848547950089631 0.44861562774728 0.79191398517371 0.562558554469804 -0.536279211779275 -0.269329465254477 -0.708444961152592 -0.55900924566061 -0.394007952951123 -0.691235127700092 0.114476969400338 -0.726768082367915 -0.536480004284122 -0.593458992738604 17 | 0.221734657014474 0.210994108055469 0.218560511748563 0.0684917308841777 0.0879806555127451 0.129830913533694 0.243055240465156 0.118791238942925 0.0570491275009775 0.210663469691087 0.952960287325485 0.211710285136603 0.226985475884702 0.237878100845327 0.080860656540656 0.258342958917321 1 0.31058442648335 0.115166658176109 0.0770130257480787 0.281821743029277 0.0820986427715983 0.100280249159485 0.28020893576063 0.305077555148526 0.0821381209668113 0.0763393592229923 0.295354044515172 0.277942941124633 0.169403428687264 0.225564760561429 0.220416586020953 0.203615977785953 0.0772964331034564 0.276447862133185 0.272251392534483 0.221008442840432 0.280117283359746 0.206836420668427 0.280749068181896 0.155569011177547 0.0916663721114098 0.221071334674319 0.157579192076488 0.0766137015212243 0.220993080082547 -0.57254891045471 0.215553213492155 0.150416730830445 0.214803981257012 18 | 0.663805039510673 0.634538478751684 0.654853799546894 -0.392885762041944 0.275968669091267 0.390527702187163 0.716380320934385 -0.609570219681912 0.171466273972016 0.628670923844642 0.2851537356773 0.634240251468159 0.548331065777622 0.581528078588426 0.121837888633684 0.643412923598097 0.31058442648335 1 0.399783275482415 0.30526754594588 0.886594722778045 0.257534679220097 0.329370207246662 0.88945521711072 0.971922110858133 0.283040021894292 0.29181790698527 0.857922912239846 0.872339956216545 0.450239526766872 0.647993359878986 0.652500203559138 0.595375425611913 0.291017922798302 0.828240662884638 0.818866065801694 0.652664016578851 0.78980863248807 0.610762341103956 0.868925908607367 -0.684966300977814 0.317033941087716 -0.387988704048984 -0.713093204688258 0.265666494172568 -0.373347680498095 0.0207354938171268 -0.403273935764501 -0.71762747779291 -0.399568627021993 19 | -0.143447218691015 -0.115398972196263 -0.136825481414931 -0.159331408195816 0.764633905823257 0.119957644145761 -0.188995655020901 -0.232044647077705 -0.132638799598091 -0.135620421018972 0.0865691908559938 -0.121670559182995 -0.168960951603098 -0.164677463574978 0.267242178252091 -0.206228375382355 0.115166658176109 0.399783275482415 1 0.81744789084643 0.421798562353861 -0.118535871076098 -0.225715957086468 0.445096966965977 0.408990779727695 -0.203196603349517 0.804033518892178 0.430074059454335 0.435244618934073 0.0388555616015517 -0.143901590964692 -0.148223100884637 -0.113628903888389 0.786621514041196 0.345399721840249 0.352827353857153 -0.138819527130979 0.28530596169604 -0.116871233320936 0.433488424554119 -0.339441046110072 0.637716088128437 0.175724747650888 -0.34699280552203 0.753270467113541 0.168131530861709 -0.210580426956418 0.188082604822626 -0.340144333273043 0.0297220777679978 20 | -0.375967541005191 -0.360633054980845 -0.372609877961363 -0.127829594529351 0.946492303781998 -0.215434206345093 -0.409143745952785 -0.169290519899749 -0.103434105874551 -0.357534496285564 0.056000254156964 -0.360146151642616 -0.368376328809403 -0.385343133987035 -0.0480014505046212 -0.415826859795315 0.0770130257480787 0.30526754594588 0.81744789084643 1 0.313482755347098 -0.124979968910342 -0.180586378802204 0.342623325652989 0.315060635458644 -0.157585804874165 0.985875931781887 0.328382238522347 0.333835869383691 -0.268988059552613 -0.375465281294833 -0.371524827825241 -0.348388658589784 0.96880914158649 0.232984938830251 0.238597710601764 -0.370531011555783 0.359254291253749 -0.343101097799352 0.331313754154029 -0.260728279121535 0.810078767778361 0.38711064857892 -0.270161312034579 0.929037409334762 0.382519798992878 -0.167673294439781 0.394787632531268 -0.265834289471078 0.212050219141917 21 | 0.746971744989 0.716246910037132 0.737564748133678 -0.352119299521025 0.270774991279378 0.434533733511582 0.644195699229897 -0.533192002401318 0.192526158734931 0.706918701633282 0.253932021771759 0.714211441864982 0.64689437692368 0.681461528304763 0.156596506186287 0.588295734291542 0.281821743029277 0.886594722778045 0.421798562353861 0.313482755347098 1 0.288230661327375 0.369432774908166 0.987315889313016 0.904191581471297 0.317308907137194 0.306680090423271 0.965690930416582 0.971856131832889 0.514869137177138 0.738684488861448 0.656529744026396 0.67617037077365 0.30686495495894 0.840199059459948 0.828468284164927 0.741617387566971 0.745104044980146 0.695211836714831 0.968495615364691 -0.645905356423767 0.145527234971426 -0.483608969095153 -0.671844660909516 0.279907439133898 -0.465685177372828 0.0545409091120798 -0.501333187416021 -0.648532687444335 -0.474189502883689 22 | 0.365161325952025 0.34256002886307 0.326499305806978 -0.0958683565553189 -0.108174485310311 0.649902607299447 0.341711963570879 -0.151672656181735 -0.0871040220487315 0.392080890782839 0.06835910603621 0.305961405313155 0.263334717697999 0.341468641420732 -0.0839075709973898 0.320618988172719 0.0820986427715983 0.257534679220097 -0.118535871076098 -0.124979968910342 0.288230661327375 1 -0.139633360454996 0.281969953076618 0.263836058369488 -0.125840657586622 -0.124127029451416 0.279291790434775 0.277188643121788 0.544990943532846 0.361638200166232 0.313164176406721 0.335130510874241 -0.120725464240954 0.187208293987202 0.194984215612279 0.36405373918458 0.208679497546117 0.384635403810881 0.280526027319116 -0.213282593005105 -0.130863970433115 -0.308644967573712 -0.219047787527744 -0.111548252608528 -0.316099047098354 -0.127131836704986 -0.303856655433666 -0.211270725993926 -0.101538648418 23 | 0.48443456511356 0.409713454444292 0.497653504696626 -0.141637147001454 -0.187378814427303 -0.194384438734768 0.44870041267681 -0.210497242315567 0.573642582879529 0.469883417348642 0.1206251595143 0.50449704379806 0.499303612933898 0.459899424892659 0.0786095999808551 0.427578407249128 0.100280249159485 0.329370207246662 -0.225715957086468 -0.180586378802204 0.369432774908166 -0.139633360454996 1 0.362703156135837 0.333174692380569 0.889506402874539 -0.180276377625564 0.355955594408431 0.360656611430742 -0.223862552846237 0.485194993244817 0.476612759513891 0.46441139730109 -0.184141956428586 0.386525033729842 0.396197144139751 0.488451849742663 0.277225772772551 0.390301079632466 0.3621219019142 -0.149219051778637 -0.205874007598509 -0.317867978443814 -0.159092434263333 -0.181303529655239 -0.326038054004122 0.522555827763479 -0.307775264718076 -0.148492611911693 -0.274603210826411 24 | 0.730468140396773 0.700227199011173 0.721187745650351 -0.353749304511549 0.299215703597156 0.423186710263817 0.628306842162483 -0.530821053145709 0.189628361987799 0.691431928091232 0.254772984439438 0.698838433918893 0.631205934151776 0.664837807249467 0.153281392197004 0.571838733609972 0.28020893576063 0.88945521711072 0.445096966965977 0.342623325652989 0.987315889313016 0.281969953076618 0.362703156135837 1 0.915403335886214 0.312238357534303 0.33888295120468 0.978374676621746 0.984907290353996 0.508662191796844 0.728241942730132 0.646364548579423 0.666356764441676 0.339176828345484 0.856057297594607 0.84440269641488 0.731426607320536 0.758730774230411 0.685905282555134 0.982065750807825 -0.657913812946641 0.172209724699038 -0.474108785899419 -0.684203343862642 0.312469227320999 -0.456267630385107 0.0500431779057042 -0.491505516146836 -0.660343385713753 -0.489260260754113 25 | 0.673670199171113 0.644195305580449 0.664763399487566 -0.389837805944321 0.269970675140715 0.394650741721098 0.727320850968865 -0.585278670091868 0.17410987152808 0.640513853008201 0.282258467909429 0.642732261611208 0.567904998736872 0.601234907541748 0.124752049055163 0.663267593377719 0.305077555148526 0.971922110858133 0.408990779727695 0.315060635458644 0.904191581471297 0.263836058369488 0.333174692380569 0.915403335886214 1 0.28542683131525 0.309338712967194 0.884984936938941 0.8979051169696 0.461973083967142 0.661556763984922 0.664144383392465 0.607098142641962 0.308956157137821 0.854337074343823 0.844232520668353 0.665757343466739 0.786289151294477 0.623024203395324 0.895795555413826 -0.720040243409751 0.334356267945383 -0.404861309152581 -0.746073869898642 0.283653302733502 -0.389596076732083 0.0260019814241044 -0.419865242403997 -0.720098951313259 -0.416511188967039 26 | 0.41869337185046 0.326444913681481 0.429906328660207 -0.123102465134157 -0.16288266868674 -0.174226699005713 0.386073676967086 -0.179133387916063 0.647593562743613 0.413804168676103 0.101900094345014 0.460149832357348 0.432736064630631 0.397592249792733 0.119945144766283 0.367299601681881 0.0821381209668113 0.283040021894292 -0.203196603349517 -0.157585804874165 0.317308907137194 -0.125840657586622 0.889506402874539 0.312238357534303 0.28542683131525 1 -0.158823458051792 0.307916318881738 0.309472327825434 -0.211520931690355 0.419513785618954 0.406089171104458 0.40826419460724 -0.162143418457859 0.33086295756726 0.339711591567076 0.42387958672575 0.217277095754027 0.333323661638846 0.311787013310301 -0.100455809944136 -0.181338053126595 -0.254750710559853 -0.112777041493204 -0.157776665808 -0.262447269103119 0.385488694108568 -0.246282452438663 -0.105082756711928 -0.227313046076296 27 | -0.374152883487186 -0.358315475242821 -0.370751640640785 -0.128555243206145 0.933422365536599 -0.21436104828446 -0.409121432812807 -0.166901493601962 -0.105342453231689 -0.354972466547826 0.0595317731356116 -0.358429243641504 -0.364839554264625 -0.381799647375748 -0.0456312804981439 -0.414615123017539 0.0763393592229923 0.29181790698527 0.804033518892178 0.985875931781887 0.306680090423271 -0.124127029451416 -0.180276377625564 0.33888295120468 0.309338712967194 -0.158823458051792 1 0.339532639703857 0.345135123434734 -0.267316479775336 -0.37489180862563 -0.371546811826669 -0.348031787312924 0.98322261216614 0.244280357145677 0.249542152234186 -0.369937710584561 0.367747574306171 -0.343012961000325 0.342725633138577 -0.272839636272754 0.821083562758622 0.384130665953626 -0.282262791199989 0.942992517899551 0.379409477063714 -0.16580295498802 0.392347452835838 -0.27690279632131 0.212190168864166 28 | 0.717461697695825 0.687757239476336 0.708030355440798 -0.342544984949329 0.284658383248052 0.415503576845842 0.609220736678785 -0.518102296308399 0.184372969503271 0.678840353528233 0.269507837668157 0.687367942016089 0.614745727968641 0.648532882115491 0.164572283191726 0.549464943052351 0.295354044515172 0.857922912239846 0.430074059454335 0.328382238522347 0.965690930416582 0.279291790434775 0.355955594408431 0.978374676621746 0.884984936938941 0.307916318881738 0.339532639703857 1 0.977300394021257 0.50211983258737 0.717253027831045 0.632806346658892 0.656652098710083 0.341427446804781 0.844784064501304 0.832561089373352 0.721297423861671 0.74342386655779 0.67544940296398 0.973338986987654 -0.63103261971208 0.16371999969632 -0.452706526842353 -0.653285033916416 0.313468919417279 -0.435160262672476 0.0370820101944234 -0.469881332285759 -0.628494897248526 -0.465509266087149 29 | 0.719648099724783 0.689451991889649 0.710533789860845 -0.350005703352331 0.290624052992991 0.413580601751268 0.61732545494252 -0.524427603693704 0.188317247456127 0.681024199846205 0.252542618861881 0.687965290530645 0.622100430071168 0.654896499757257 0.15440881193372 0.561643949861054 0.277942941124633 0.872339956216545 0.435244618934073 0.333835869383691 0.971856131832889 0.277188643121788 0.360656611430742 0.984907290353996 0.8979051169696 0.309472327825434 0.345135123434734 0.977300394021257 1 0.502550978291677 0.720681096238387 0.638425948827057 0.65941539895681 0.347435439592684 0.855075086681834 0.843194640888188 0.723608834065026 0.757306667778031 0.677159843256275 0.979943546806328 -0.654437780810219 0.176542914870408 -0.467017136063495 -0.679702952257601 0.319727874841667 -0.45001059366782 0.0485450620428454 -0.483972184784014 -0.655910429748318 -0.480757794182705 30 | 0.685211908754241 0.693774284523472 0.660504793200351 -0.168278176905818 -0.265161381408746 0.826779715843693 0.631852101815047 -0.263779892572702 -0.14843365967137 0.668805885298146 0.13691684168227 0.620620633821239 0.553610479833939 0.640347987698131 0.178939019433833 0.591393417767394 0.169403428687264 0.450239526766872 0.0388555616015517 -0.268988059552613 0.514869137177138 0.544990943532846 -0.223862552846237 0.508662191796844 0.461973083967142 -0.211520931690355 -0.267316479775336 0.50211983258737 0.502550978291677 1 0.686190720049552 0.5945793167785 0.654715326046312 -0.251536054978047 0.425047211239932 0.399447387015891 0.68399879876445 0.287756257248728 0.685274041103215 0.500989563245614 -0.361542103415416 -0.29048298767318 -0.577151741047354 -0.375877586646033 -0.251562361059202 -0.594873094133787 -0.213824492443957 -0.577211065277968 -0.362407714653763 -0.455453377183016 31 | 0.976418418879537 0.935665364556918 0.964995554287411 -0.262821764342503 -0.38064621547659 0.564415445435154 0.898478016304498 -0.409195287991391 0.259916986383819 0.92478486607932 0.213211092376333 0.940375080743251 0.871376981781098 0.916467749072252 0.184970213033004 0.845635900460856 0.225564760561429 0.647993359878986 -0.143901590964692 -0.375465281294833 0.738684488861448 0.361638200166232 0.485194993244817 0.728241942730132 0.661556763984922 0.419513785618954 -0.37489180862563 0.717253027831045 0.720681096238387 0.686190720049552 1 0.901096175401883 0.905296722396942 -0.366435117730642 0.690423492001235 0.675333196768039 0.987179801327636 0.481368017270185 0.923037940090324 0.725895673550291 -0.44942281093824 -0.426092657424647 -0.741441457377453 -0.463886292966248 -0.369406750484319 -0.720877064689265 0.16622471439015 -0.764230385928258 -0.442839947219463 -0.628571677583658 32 | 0.895591210181543 0.861368028641668 0.885650996470911 -0.264447430161622 -0.375708294320626 0.504303493317321 0.898191676019455 -0.407339354076644 0.216145966671841 0.840406380987309 0.209968318524511 0.869340227622266 0.801479362691558 0.837853490942191 0.201949829768938 0.846926454163487 0.220416586020953 0.652500203559138 -0.148223100884637 -0.371524827825241 0.656529744026396 0.313164176406721 0.476612759513891 0.646364548579423 0.664144383392465 0.406089171104458 -0.371546811826669 0.632806346658892 0.638425948827057 0.5945793167785 0.901096175401883 1 0.919992619360007 -0.364583059859255 0.678890557688767 0.686093914547343 0.906080835166597 0.513349429938616 0.834395648162983 0.645119599248808 -0.450932879978676 -0.319308939260637 -0.658125865953284 -0.466042951661385 -0.368192412872213 -0.635542795061591 0.180846130384713 -0.682073518144029 -0.448653177672156 -0.542034617976875 33 | 0.896631204742192 0.856941503961387 0.884160286216347 -0.242615659161401 -0.35106752089647 0.545351762268711 0.82715576252789 -0.370174411076938 0.18972723080638 0.845504222603324 0.190355458149087 0.86574930533451 0.8069772023099 0.843899588593159 0.243525032048046 0.78097695654833 0.203615977785953 0.595375425611913 -0.113628903888389 -0.348388658589784 0.67617037077365 0.335130510874241 0.46441139730109 0.666356764441676 0.607098142641962 0.40826419460724 -0.348031787312924 0.656652098710083 0.65941539895681 0.654715326046312 0.905296722396942 0.919992619360007 1 -0.340523142358752 0.618168668483704 0.623697924935213 0.909659550982734 0.445396627244306 0.829256668389775 0.665972532280823 -0.402001396289434 -0.391885314989834 -0.669466721829456 -0.419148462220851 -0.343294572085449 -0.69008987213837 0.174897561405006 -0.69683654416652 -0.403067616964705 -0.564510971016498 34 | -0.361286884144309 -0.344120415086454 -0.357512544458661 -0.128544158553991 0.916201177524063 -0.214433321718388 -0.397054992608695 -0.16447816368291 -0.107645692839544 -0.341772139510757 0.0619752290801055 -0.349251296390743 -0.351399671041573 -0.368965956749825 -0.0506853118178806 -0.40254256179239 0.0772964331034564 0.291017922798302 0.786621514041196 0.96880914158649 0.30686495495894 -0.120725464240954 -0.184141956428586 0.339176828345484 0.308956157137821 -0.162143418457859 0.98322261216614 0.341427446804781 0.347435439592684 -0.251536054978047 -0.366435117730642 -0.364583059859255 -0.340523142358752 1 0.250642284303559 0.25596797848565 -0.364742899900845 0.376959431418308 -0.33741308234441 0.349650634939324 -0.279093272864531 0.82626240029381 0.394124329257904 -0.289224973452083 0.950030416240433 0.390099209287875 -0.171760347849081 0.390252626155417 -0.283959161141026 0.2082477799166 35 | 0.668033909177708 0.660565152967993 0.683069155527401 -0.359198340710449 0.187274768568002 0.33022541370084 0.649213907089917 -0.512707278472249 0.181960322122467 0.631580666977094 0.278414519609558 0.692274478893501 0.609235807380092 0.604996970679284 0.147956589100792 0.592701602026894 0.276447862133185 0.828240662884638 0.345399721840249 0.232984938830251 0.840199059459948 0.187208293987202 0.386525033729842 0.856057297594607 0.854337074343823 0.33086295756726 0.244280357145677 0.844784064501304 0.855075086681834 0.425047211239932 0.690423492001235 0.678890557688767 0.618168668483704 0.250642284303559 1 0.987347153556674 0.681956772921942 0.712957597399449 0.629484771360222 0.866801891851081 -0.620331754629404 0.191858851273468 -0.417190553203101 -0.638621389059015 0.221825285029295 -0.398875955108039 0.0566052856879318 -0.434563476632155 -0.614042257956323 -0.396005837063972 36 | 0.652781048750955 0.643256875575958 0.667254324181404 -0.3555848932167 0.193662883520786 0.339773618879325 0.635775774911593 -0.507120538519508 0.188949344103418 0.61428951793318 0.274451126365285 0.686691510867674 0.605686737376131 0.591260457619282 0.15363235257343 0.580660327460084 0.272251392534483 0.818866065801694 0.352827353857153 0.238597710601764 0.828468284164927 0.194984215612279 0.396197144139751 0.84440269641488 0.844232520668353 0.339711591567076 0.249542152234186 0.832561089373352 0.843194640888188 0.399447387015891 0.675333196768039 0.686093914547343 0.623697924935213 0.25596797848565 0.987347153556674 1 0.666555398869286 0.699671187221731 0.611688912088962 0.855296107158209 -0.612124308972159 0.198279080052584 -0.403226451306195 -0.629640671230453 0.226579026790324 -0.384505181664086 0.0631118353579109 -0.421321273759441 -0.605846098292444 -0.383324126296314 37 | 0.976015757360389 0.933986712889575 0.964172891937013 -0.259795765479986 -0.375801808036692 0.566979638475493 0.899218486938957 -0.397131218240919 0.26250149214871 0.924584368459878 0.208155539024951 0.943987905716507 0.872214823476892 0.918051589739375 0.189960722438181 0.848547950089631 0.221008442840432 0.652664016578851 -0.138819527130979 -0.370531011555783 0.741617387566971 0.36405373918458 0.488451849742663 0.731426607320536 0.665757343466739 0.42387958672575 -0.369937710584561 0.721297423861671 0.723608834065026 0.68399879876445 0.987179801327636 0.906080835166597 0.909659550982734 -0.364742899900845 0.681956772921942 0.666555398869286 1 0.49262938336852 0.934522154018279 0.738013281052354 -0.465280145097683 -0.428531780952396 -0.75792008513267 -0.480037712750193 -0.372296319595101 -0.737090914181736 0.177747657240092 -0.781410641120598 -0.460757994409669 -0.643694762588859 38 | 0.484938973117808 0.445799275640874 0.474715651983955 -0.289432633541738 0.322294683889848 0.183523909614385 0.492785605397124 -0.437354761790741 0.223014605189281 0.441928690790558 0.256779912213788 0.449891117185949 0.414499394600907 0.43336242156336 -0.195961999200347 0.44861562774728 0.280117283359746 0.78980863248807 0.28530596169604 0.359254291253749 0.745104044980146 0.208679497546117 0.277225772772551 0.758730774230411 0.786289151294477 0.217277095754027 0.367747574306171 0.74342386655779 0.757306667778031 0.287756257248728 0.481368017270185 0.513349429938616 0.445396627244306 0.376959431418308 0.712957597399449 0.699671187221731 0.49262938336852 1 0.525273295809595 0.770681695568595 -0.671215022651201 0.352072622848547 -0.325176023216699 -0.67942787630013 0.352386049300122 -0.305233195674399 0.0711764002152342 -0.345375054361235 -0.691959767726643 -0.348617918789771 39 | 0.911505507082877 0.864553956425919 0.900752255485674 -0.245295336253717 -0.346149461314868 0.553609010359332 0.838498994435903 -0.369570002739153 0.291220434811279 0.855287277726827 0.191561216810638 0.874470318251234 0.808477533473165 0.857941131915175 0.0332914271847469 0.79191398517371 0.206836420668427 0.610762341103956 -0.116871233320936 -0.343101097799352 0.695211836714831 0.384635403810881 0.390301079632466 0.685905282555134 0.623024203395324 0.333323661638846 -0.343012961000325 0.67544940296398 0.677159843256275 0.685274041103215 0.923037940090324 0.834395648162983 0.829256668389775 -0.33741308234441 0.629484771360222 0.611688912088962 0.934522154018279 0.525273295809595 1 0.692366166306687 -0.524926056157319 -0.400043677390823 -0.781654551767242 -0.532726097274393 -0.346098897820305 -0.757908077844587 0.189642766014375 -0.807641122450106 -0.517611583856173 -0.674386981809089 40 | 0.718958463586773 0.688324325381134 0.70931903106437 -0.356252607063709 0.287640301213875 0.417888534439893 0.617160887003045 -0.519227967573749 0.187859477570516 0.681720493347957 0.256198908931941 0.693189905895554 0.621156792852798 0.655392403565968 0.156553738501672 0.562558554469804 0.280749068181896 0.868925908607367 0.433488424554119 0.331313754154029 0.968495615364691 0.280526027319116 0.3621219019142 0.982065750807825 0.895795555413826 0.311787013310301 0.342725633138577 0.973338986987654 0.979943546806328 0.500989563245614 0.725895673550291 0.645119599248808 0.665972532280823 0.349650634939324 0.866801891851081 0.855296107158209 0.738013281052354 0.770681695568595 0.692366166306687 1 -0.673589664938344 0.176498723383006 -0.482770241572973 -0.696784218781399 0.322082765601029 -0.465184193612586 0.0562065051898883 -0.500221824486579 -0.673584464540044 -0.495129175632522 41 | -0.457614963470182 -0.431428516780903 -0.449670675602408 0.48605222600608 -0.209862444450443 -0.321267618837198 -0.493095716888445 0.515954615790076 -0.155412510856695 -0.425733008953336 0.153930205513287 -0.433318408702092 -0.464773826887131 -0.491575092985228 0.103377569032828 -0.536279211779275 0.155569011177547 -0.684966300977814 -0.339441046110072 -0.260728279121535 -0.645905356423767 -0.213282593005105 -0.149219051778637 -0.657913812946641 -0.720040243409751 -0.100455809944136 -0.272839636272754 -0.63103261971208 -0.654437780810219 -0.361542103415416 -0.44942281093824 -0.450932879978676 -0.402001396289434 -0.279093272864531 -0.620331754629404 -0.612124308972159 -0.465280145097683 -0.671215022651201 -0.524926056157319 -0.673589664938344 1 -0.29372964056256 0.624471476346195 0.947460641178517 -0.254268998369729 0.607336900697084 -0.299579465236803 0.63683261035944 0.928850378515124 0.632797912350173 42 | -0.397752390967649 -0.381910374549263 -0.393780400838662 -0.148500532626267 0.760071769477192 -0.231159983188497 -0.25724847890251 -0.181589506811246 -0.111354063914277 -0.372091805569095 0.08090812978546 -0.395196365606983 -0.394352367314565 -0.410751906716745 -0.084595865469178 -0.269329465254477 0.0916663721114098 0.317033941087716 0.637716088128437 0.810078767778361 0.145527234971426 -0.130863970433115 -0.205874007598509 0.172209724699038 0.334356267945383 -0.181338053126595 0.821083562758622 0.16371999969632 0.176542914870408 -0.29048298767318 -0.426092657424647 -0.319308939260637 -0.391885314989834 0.82626240029381 0.191858851273468 0.198279080052584 -0.428531780952396 0.352072622848547 -0.400043677390823 0.176498723383006 -0.29372964056256 1 0.48468431787521 -0.324608180812244 0.866190382144824 0.474607691730833 -0.21166579251832 0.492788742397047 -0.318441077378944 0.315384656887017 43 | -0.732897973729816 -0.692083999980651 -0.721082362462986 0.294105766212621 0.392712664330017 -0.491971417294722 -0.656321061245214 0.280665413448472 -0.236419908469704 -0.712363094274212 0.213900595743666 -0.700279188990884 -0.73605977845415 -0.77785987544119 0.00943770919231906 -0.708444961152592 0.221071334674319 -0.387988704048984 0.175724747650888 0.38711064857892 -0.483608969095153 -0.308644967573712 -0.317867978443814 -0.474108785899419 -0.404861309152581 -0.254750710559853 0.384130665953626 -0.452706526842353 -0.467017136063495 -0.577151741047354 -0.741441457377453 -0.658125865953284 -0.669466721829456 0.394124329257904 -0.417190553203101 -0.403226451306195 -0.75792008513267 -0.325176023216699 -0.781654551767242 -0.482770241572973 0.624471476346195 0.48468431787521 1 0.647986073982395 0.414082378957174 0.976926511119193 -0.455970408468452 0.978172433389237 0.630258608839122 0.84054918321957 44 | -0.479236220219959 -0.450634025039308 -0.470364438442525 0.456066029785199 -0.219789265006251 -0.328409879034009 -0.514258960358027 0.472700100234848 -0.155876448620069 -0.447510887237595 0.157884847786756 -0.447107213427667 -0.486963471310087 -0.515195278144816 0.0907526712644418 -0.55900924566061 0.157579192076488 -0.713093204688258 -0.34699280552203 -0.270161312034579 -0.671844660909516 -0.219047787527744 -0.159092434263333 -0.684203343862642 -0.746073869898642 -0.112777041493204 -0.282262791199989 -0.653285033916416 -0.679702952257601 -0.375877586646033 -0.463886292966248 -0.466042951661385 -0.419148462220851 -0.289224973452083 -0.638621389059015 -0.629640671230453 -0.480037712750193 -0.67942787630013 -0.532726097274393 -0.696784218781399 0.947460641178517 -0.324608180812244 0.647986073982395 1 -0.288552712463366 0.631637196302644 -0.305296499825447 0.661074634007214 0.975362715072461 0.664084821236865 45 | -0.354555920427379 -0.338028909238867 -0.351226583912354 -0.126712165175628 0.875931428889538 -0.209642847103982 -0.389806043095773 -0.143827316535308 -0.10122715173444 -0.334140935177582 0.0614653608978046 -0.352176814356685 -0.344643077965233 -0.361047158802351 -0.0495212702076274 -0.394007952951123 0.0766137015212243 0.265666494172568 0.753270467113541 0.929037409334762 0.279907439133898 -0.111548252608528 -0.181303529655239 0.312469227320999 0.283653302733502 -0.157776665808 0.942992517899551 0.313468919417279 0.319727874841667 -0.251562361059202 -0.369406750484319 -0.368192412872213 -0.343294572085449 0.950030416240433 0.221825285029295 0.226579026790324 -0.372296319595101 0.352386049300122 -0.346098897820305 0.322082765601029 -0.254268998369729 0.866190382144824 0.414082378957174 -0.288552712463366 1 0.409940467975098 -0.174538734295995 0.422612925468928 -0.28355493201721 0.22997710053132 46 | -0.712192812759167 -0.669518389961215 -0.700095259780041 0.287241577378231 0.388329055081097 -0.503109190362281 -0.63842328923836 0.269636521862351 -0.242715879789893 -0.6886996120922 0.215071164638781 -0.677570113691058 -0.71508598646008 -0.758063433313506 0.00059052952781094 -0.691235127700092 0.220993080082547 -0.373347680498095 0.168131530861709 0.382519798992878 -0.465685177372828 -0.316099047098354 -0.326038054004122 -0.456267630385107 -0.389596076732083 -0.262447269103119 0.379409477063714 -0.435160262672476 -0.45001059366782 -0.594873094133787 -0.720877064689265 -0.635542795061591 -0.69008987213837 0.390099209287875 -0.398875955108039 -0.384505181664086 -0.737090914181736 -0.305233195674399 -0.757908077844587 -0.465184193612586 0.607336900697084 0.474607691730833 0.976926511119193 0.631637196302644 0.409940467975098 1 -0.460114835632762 0.958732342612471 0.616506009673305 0.820666119003489 47 | 0.166421118660688 0.195678627749168 0.176782616982291 -0.142687686771452 -0.175888633934313 -0.169170612901843 0.140546231190317 -0.213958732081952 0.131939644168518 0.130968218280632 -0.533600530293951 0.176675830597558 0.165730370674587 0.137589494839341 -0.145456265971368 0.114476969400338 -0.57254891045471 0.0207354938171268 -0.210580426956418 -0.167673294439781 0.0545409091120798 -0.127131836704986 0.522555827763479 0.0500431779057042 0.0260019814241044 0.385488694108568 -0.16580295498802 0.0370820101944234 0.0485450620428454 -0.213824492443957 0.16622471439015 0.180846130384713 0.174897561405006 -0.171760347849081 0.0566052856879318 0.0631118353579109 0.177747657240092 0.0711764002152342 0.189642766014375 0.0562065051898883 -0.299579465236803 -0.21166579251832 -0.455970408468452 -0.305296499825447 -0.174538734295995 -0.460114835632762 1 -0.446508549750278 -0.298491594898373 -0.42096231127663 48 | -0.755584396504715 -0.716412676371418 -0.744331527704319 0.299890467780891 0.402050964728065 -0.482839517160104 -0.676440154302622 0.287683292423936 -0.232162704808467 -0.706308502510123 0.207597761080327 -0.723976154664494 -0.759769344358889 -0.798581707596576 0.0178463612508217 -0.726768082367915 0.215553213492155 -0.403273935764501 0.188082604822626 0.394787632531268 -0.501333187416021 -0.303856655433666 -0.307775264718076 -0.491505516146836 -0.419865242403997 -0.246282452438663 0.392347452835838 -0.469881332285759 -0.483972184784014 -0.577211065277968 -0.764230385928258 -0.682073518144029 -0.69683654416652 0.390252626155417 -0.434563476632155 -0.421321273759441 -0.781410641120598 -0.345375054361235 -0.807641122450106 -0.500221824486579 0.63683261035944 0.492788742397047 0.978172433389237 0.661074634007214 0.422612925468928 0.958732342612471 -0.446508549750278 1 0.644991545879095 0.862299022100869 49 | -0.459133420246085 -0.430569661007395 -0.450242291309177 0.460990961039009 -0.217526737238164 -0.319564457773858 -0.492018831567249 0.482122313230438 -0.152588101458879 -0.426732757697918 0.150145510785862 -0.428544690018879 -0.466537337871755 -0.4947616819797 0.103769135193177 -0.536480004284122 0.150416730830445 -0.71762747779291 -0.340144333273043 -0.265834289471078 -0.648532687444335 -0.211270725993926 -0.148492611911693 -0.660343385713753 -0.720098951313259 -0.105082756711928 -0.27690279632131 -0.628494897248526 -0.655910429748318 -0.362407714653763 -0.442839947219463 -0.448653177672156 -0.403067616964705 -0.283959161141026 -0.614042257956323 -0.605846098292444 -0.460757994409669 -0.691959767726643 -0.517611583856173 -0.673584464540044 0.928850378515124 -0.318441077378944 0.630258608839122 0.975362715072461 -0.28355493201721 0.616506009673305 -0.298491594898373 0.644991545879095 1 0.647586781077702 50 | -0.624088771832244 -0.582082014300394 -0.610127049900577 0.315809951964561 0.221926170234028 -0.346787756200073 -0.543257005249675 0.291878785443115 -0.230561738627609 -0.573639253491821 0.205169480861282 -0.584016904249184 -0.62577504153852 -0.666680141796551 -0.0254105273726132 -0.593458992738604 0.214803981257012 -0.399568627021993 0.0297220777679978 0.212050219141917 -0.474189502883689 -0.101538648418 -0.274603210826411 -0.489260260754113 -0.416511188967039 -0.227313046076296 0.212190168864166 -0.465509266087149 -0.480757794182705 -0.455453377183016 -0.628571677583658 -0.542034617976875 -0.564510971016498 0.2082477799166 -0.396005837063972 -0.383324126296314 -0.643694762588859 -0.348617918789771 -0.674386981809089 -0.495129175632522 0.632797912350173 0.315384656887017 0.84054918321957 0.664084821236865 0.22997710053132 0.820666119003489 -0.42096231127663 0.862299022100869 0.647586781077702 1 51 | --------------------------------------------------------------------------------