Closed SoleilChenxu closed 1 year ago
You need to create corr
with corr <- as_SFBM(corr0, tmp)
for the first chromosome, and then you just add more data to it for the other chromosomes.
Is this your question?
Oh yes that makes sense. Now I understand, because I only take chromosome 21 and 22 for example because of the partition limit. Is it possible to run the LD_matrix by choromosome and in parallel? Thanks!
What do you mean exactly by "run the LD_matrix"?
I mean the step to calculate the correlations between variants. In the tutorial this step is processed from chromosome 1 to chromosome 22 right?
for (chr in 1:22) {
# print(chr)
## indices in 'df_beta'
ind.chr <- which(df_beta$chr == chr)
## indices in 'G'
ind.chr2 <- df_beta$`_NUM_ID_`[ind.chr]
corr0 <- snp_cor(G, ind.col = ind.chr2, size = 3 / 1000,
infos.pos = POS2[ind.chr2], ncores = NCORES)
if (chr == 1) {
ld <- Matrix::colSums(corr0^2)
corr <- as_SFBM(corr0, tmp, compact = TRUE)
} else {
ld <- c(ld, Matrix::colSums(corr0^2))
corr$add_columns(corr0, nrow(corr))
}
}
My question is whether I could calculate the correlation several times and merge the data later.
Yes, you could compute corr0
with snp_corr()
for each chromosome separately (or use the ones precomputed).
And then merge all those with $add_columns
.
It's what I actually do in most of my papers.
Okay this helps. Thank you very much!
Hi Privefl, i got the error when calculating LD matrix about no function in _corr$addcolumns(corr0, nrow(corr)). I was confusing if i could do the same for chr 2 to 22 as chr1 instead of using if...else function. That is, for all chromosomes, _ld <- Matrix::colSums(corr0^2) corr <- as_SFBM(corr0, tmp)_
Thanks in advance for your anwser.