stephenslab / susieR

R package for "sum of single effects" regression.
https://stephenslab.github.io/susieR
Other
169 stars 42 forks source link

Susie with sparse LD matrices #225

Open nlapier2 opened 2 months ago

nlapier2 commented 2 months ago

This is perhaps an atypical usage of susie-rss, but it would be nice if it were able to natively handle sparse LD matrices, e.g. from the Matrix library in R.

For example,

zscores = 1:5
R = diag(5)
N = 10000
library(susieR)
res = susie_rss(zscores, R, n=N)

runs just fine, but then

library(Matrix)
Rs = Matrix(R, sparse=T)
res = susie_rss(zscores, Rs, n=N)

yields

Error: Not compatible with requested type: [type=S4; target=double].

I ran into this issue when attempting to run susie on an LD matrix with a block diagonal structure (because it spanned multiple loci) that I was trying to exploit for faster computation and lower memory usage.

Incidentally, I seem to have been able to use sparse matrices in the cTWAS version of susie(-rss) -- not sure why.

pcarbo commented 2 months ago

@nlapier2 It appears that susie_rss does not currently support "R" being a sparse matrix.

As a temporary workaround, what about running susie_rss separately on each of the blocks?

jhchung commented 2 months ago

A separate, but related question when using sparse LD matricies.

If there are a lot of null entries (e.g getting ld from a precomputed LD reference with minimum R2 cutoffs), i usually set these to 0. How does the credible set purity calculation take this into account? If it takes the upper triangle, will that mean the minimum purity will be 0?

i think this is related to issue #122

pcarbo commented 2 months ago

@jhchung Correct; if SNPs i, j are in the same CS and R[i,j] = 0, then the minimum correlation of the CS will be zero.