|
a |
|
b/man/LDRefBlend.Rd |
|
|
1 |
% Generated by roxygen2: do not edit by hand |
|
|
2 |
% Please edit documentation in R/shaPRS.R |
|
|
3 |
\name{LDRefBlend} |
|
|
4 |
\alias{LDRefBlend} |
|
|
5 |
\title{Generate shaPRS specific LD reference panel} |
|
|
6 |
\usage{ |
|
|
7 |
LDRefBlend(pop1LDmatrix, pop2LDmatrix, sumstatsData, memoryEfficiency = 5) |
|
|
8 |
} |
|
|
9 |
\arguments{ |
|
|
10 |
\item{pop1LDmatrix}{LD reference matrix in RDS (dsCMatrix) format for target population} |
|
|
11 |
|
|
|
12 |
\item{pop2LDmatrix}{LD reference matrix in RDS (dsCMatrix) format for other population} |
|
|
13 |
|
|
|
14 |
\item{sumstatsData}{summary data with required columns of SE_A, SE_B, A1.x, A1.y, and lFDR} |
|
|
15 |
|
|
|
16 |
\item{memoryEfficiency}{larger numbers result in longer runs but lower memory usage (default 5)} |
|
|
17 |
} |
|
|
18 |
\value{ |
|
|
19 |
returns a PRS specific LD matrix |
|
|
20 |
} |
|
|
21 |
\description{ |
|
|
22 |
Generates a PRS specific LD reference matrix by blending together two LD ref panels according to |
|
|
23 |
shaPRS produced lFDR and standard errors |
|
|
24 |
} |
|
|
25 |
\examples{ |
|
|
26 |
sumstatsData = readRDS(file = system.file("extdata", "sumstatsData_toy.rds", package = "shaPRS") ) |
|
|
27 |
|
|
|
28 |
# read SNP map files (same toy data for the example) |
|
|
29 |
pop1_map_rds = readRDS(file = system.file("extdata", "my_data.rds", package = "shaPRS") ) |
|
|
30 |
pop2_map_rds = readRDS(file = system.file("extdata", "my_data2.rds", package = "shaPRS") ) |
|
|
31 |
|
|
|
32 |
# use chrom 21 as an example |
|
|
33 |
chromNum=21 |
|
|
34 |
|
|
|
35 |
# load the two chromosomes from each population ( same toy data for the example) |
|
|
36 |
pop1LDmatrix = readRDS(file = system.file("extdata", "LDref.rds", package = "shaPRS") ) |
|
|
37 |
pop2LDmatrix = readRDS(file = system.file("extdata", "LDref2.rds", package = "shaPRS") ) |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
# 2. grab the RSids from the map for the SNPS on this chrom, |
|
|
41 |
# each LD mat has a potentially different subset of SNPs |
|
|
42 |
# this is guaranteed to be the same order as the pop1LDmatrix |
|
|
43 |
pop1_chrom_SNPs = pop1_map_rds[ which(pop1_map_rds$chr == chromNum),] |
|
|
44 |
# this is guaranteed to be the same order as the pop2LDmatrix |
|
|
45 |
pop2_chrom_SNPs = pop2_map_rds[ which(pop2_map_rds$chr == chromNum),] |
|
|
46 |
pop1_chrom_SNPs$pop1_id = 1:nrow(pop1_chrom_SNPs) |
|
|
47 |
pop2_chrom_SNPs$pop2_id = 1:nrow(pop2_chrom_SNPs) |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
# intersect the 2 SNP lists so that we only use the ones common to both LD matrices by merging them |
|
|
51 |
chrom_SNPs_df <- merge(pop1_chrom_SNPs,pop2_chrom_SNPs, by = "rsid") |
|
|
52 |
|
|
|
53 |
# align the two LD matrices |
|
|
54 |
chrom_SNPs_df = alignStrands(chrom_SNPs_df, A1.x ="a1.x", A2.x ="a0.x", A1.y ="a1.y", A2.y ="a0.y") |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
# align the summary for phe A and B |
|
|
58 |
sumstatsData = alignStrands(sumstatsData) |
|
|
59 |
|
|
|
60 |
# subset sumstats data to the same chrom |
|
|
61 |
sumstatsData = sumstatsData[which(sumstatsData$CHR == chromNum ),] |
|
|
62 |
|
|
|
63 |
# merge sumstats with common LD map data |
|
|
64 |
sumstatsData <- merge(chrom_SNPs_df,sumstatsData, by.x="rsid", by.y = "SNP") |
|
|
65 |
|
|
|
66 |
# remove duplicates |
|
|
67 |
sumstatsData = sumstatsData[ !duplicated(sumstatsData$rsid) ,] |
|
|
68 |
# use the effect alleles for the sumstats data with the effect allele of the LD mat |
|
|
69 |
# as we are aligning the LD mats against each other, not against the summary stats |
|
|
70 |
# we only use the lFDR /SE from the sumstats, |
|
|
71 |
# which are directionless, so those dont need to be aligned |
|
|
72 |
sumstatsData$A1.x =sumstatsData$a1.x |
|
|
73 |
sumstatsData$A1.y =sumstatsData$a1.y |
|
|
74 |
|
|
|
75 |
# make sure the sumstats is ordered the same way as the LD matrix: |
|
|
76 |
sumstatsData = sumstatsData[order(sumstatsData$pop1_id), ] |
|
|
77 |
# it doesn't matter which matrix to use to order the sumstats as they are the same |
|
|
78 |
|
|
|
79 |
# subset the LD matrices to the SNPs we actually have |
|
|
80 |
pop1LDmatrix = pop1LDmatrix[sumstatsData$pop1_id,sumstatsData$pop1_id] |
|
|
81 |
pop2LDmatrix = pop2LDmatrix[sumstatsData$pop2_id,sumstatsData$pop2_id] |
|
|
82 |
|
|
|
83 |
# generate the blended LD matrix |
|
|
84 |
cormat = LDRefBlend(pop1LDmatrix,pop2LDmatrix, sumstatsData) |
|
|
85 |
|
|
|
86 |
# create a new map file that matches the SNPs common to both LD panels |
|
|
87 |
map_rds_new = pop1_map_rds[which(pop1_map_rds$chr == chromNum),] |
|
|
88 |
map_rds_new2 = map_rds_new[which(map_rds_new$rsid \%in\% sumstatsData$rsid),] |
|
|
89 |
|
|
|
90 |
# save the new LD matrix to a location of your choice |
|
|
91 |
# saveRDS(cormat,file =paste0(<YOUR LOCATION>,"/LD_chr",chromNum,".rds")) |
|
|
92 |
|
|
|
93 |
# save its Map file too |
|
|
94 |
# saveRDS(map_rds_new2,file = paste0(<YOUR LOCATION>,"/LD_chr",chromNum,"_map.rds")) |
|
|
95 |
|
|
|
96 |
} |