Skip to content

Commit

Permalink
faster snpgdsLDpruning()
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxwen committed Mar 8, 2024
1 parent bc58568 commit 303f40d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
CHANGES IN VERSION 1.37.2
-------------------------

UTILITIES

o faster `snpgdsLDpruning()`


CHANGES IN VERSION 1.36.1
-------------------------

Expand Down
26 changes: 12 additions & 14 deletions src/genLD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,27 +780,26 @@ namespace LD
BufSNP.ReadPackedGeno(i, &buf[0]);
progress.Forward(1, verbose);
// detect LD
int TotalCnt = 0, ValidCnt = 0;
list<TSNP>::iterator it;
for (it=ListGeno.begin(); it != ListGeno.end(); TotalCnt++)
bool to_include = true;
for (list<TSNP>::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<TSNP>::iterator tmp_it = it;
it ++;
ListGeno.erase(tmp_it);
}
}
// handle
out_SNP[i] = (ValidCnt == TotalCnt);
out_SNP[i] = to_include;
if (out_SNP[i])
{
ListGeno.push_back(TSNP(i, pos_bp[i], nPackedSamp));
Expand Down Expand Up @@ -837,27 +836,26 @@ namespace LD
BufSNP.ReadPackedGeno(i, &buf[0]);
progress.Forward(1, verbose);
// detect LD
int TotalCnt = 0, ValidCnt = 0;
list<TSNP>::iterator it;
for (it=ListGeno.begin(); it != ListGeno.end(); TotalCnt++)
bool to_include = true;
for (list<TSNP>::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<TSNP>::iterator tmp_it = it;
it++;
ListGeno.erase(tmp_it);
}
}
// handle
out_SNP[i] = (ValidCnt == TotalCnt);
out_SNP[i] = to_include;
if (out_SNP[i])
{
ListGeno.push_front(TSNP(i, pos_bp[i], nPackedSamp));
Expand Down

0 comments on commit 303f40d

Please sign in to comment.