From 303f40dd45c1bef3c3a456a15ee3b34022abf17e Mon Sep 17 00:00:00 2001 From: Xiuwen Zheng Date: Thu, 7 Mar 2024 21:41:39 -0600 Subject: [PATCH] faster snpgdsLDpruning() --- DESCRIPTION | 4 ++-- NEWS | 8 ++++++++ src/genLD.cpp | 26 ++++++++++++-------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 86fc8cd..a1f027c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,8 +2,8 @@ Package: SNPRelate Type: Package Title: Parallel Computing Toolset for Relatedness and Principal Component Analysis of SNP Data -Version: 1.36.1 -Date: 2024-01-19 +Version: 1.37.2 +Date: 2024-03-08 Depends: R (>= 2.15), gdsfmt (>= 1.8.3) LinkingTo: gdsfmt Imports: methods diff --git a/NEWS b/NEWS index e967f23..6139e83 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +CHANGES IN VERSION 1.37.2 +------------------------- + +UTILITIES + + o faster `snpgdsLDpruning()` + + CHANGES IN VERSION 1.36.1 ------------------------- diff --git a/src/genLD.cpp b/src/genLD.cpp index 408ff18..afd81b1 100755 --- a/src/genLD.cpp +++ b/src/genLD.cpp @@ -780,19 +780,18 @@ namespace LD BufSNP.ReadPackedGeno(i, &buf[0]); progress.Forward(1, verbose); // detect LD - int TotalCnt = 0, ValidCnt = 0; - list::iterator it; - for (it=ListGeno.begin(); it != ListGeno.end(); TotalCnt++) + bool to_include = true; + for (list::iterator it=ListGeno.begin(); it != ListGeno.end(); ) { // check whether it is in the sliding window if ((abs(i - it->idx) <= slide_max_n) && (abs(pos_bp[i] - it->pos_bp) <= slide_max_bp)) { - if (fabs(_CalcLD(&(it->genobuf[0]), &buf[0])) <= LD_threshold) - ValidCnt ++; + if (to_include && + (fabs(_CalcLD(&(it->genobuf[0]), &buf[0])) > LD_threshold)) + to_include = false; it ++; } else { - ValidCnt ++; // delete it list::iterator tmp_it = it; it ++; @@ -800,7 +799,7 @@ namespace LD } } // handle - out_SNP[i] = (ValidCnt == TotalCnt); + out_SNP[i] = to_include; if (out_SNP[i]) { ListGeno.push_back(TSNP(i, pos_bp[i], nPackedSamp)); @@ -837,19 +836,18 @@ namespace LD BufSNP.ReadPackedGeno(i, &buf[0]); progress.Forward(1, verbose); // detect LD - int TotalCnt = 0, ValidCnt = 0; - list::iterator it; - for (it=ListGeno.begin(); it != ListGeno.end(); TotalCnt++) + bool to_include = true; + for (list::iterator it=ListGeno.begin(); it != ListGeno.end(); ) { // check whether it is in the sliding window if ((abs(i - it->idx) <= slide_max_n) && (abs(pos_bp[i] - it->pos_bp) <= slide_max_bp)) { - if (fabs(_CalcLD(&(it->genobuf[0]), &buf[0])) <= LD_threshold) - ValidCnt ++; + if (to_include && + (fabs(_CalcLD(&(it->genobuf[0]), &buf[0])) > LD_threshold)) + to_include = false; it++; } else { - ValidCnt ++; // delete it list::iterator tmp_it = it; it++; @@ -857,7 +855,7 @@ namespace LD } } // handle - out_SNP[i] = (ValidCnt == TotalCnt); + out_SNP[i] = to_include; if (out_SNP[i]) { ListGeno.push_front(TSNP(i, pos_bp[i], nPackedSamp));