Skip to content

Commit ca4747e

Browse files
committed
new .buffer_position()
1 parent 4842250 commit ca4747e

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SeqArray
22
Type: Package
33
Title: Data management of large-scale whole-genome sequence variant calls using GDS files
4-
Version: 1.47.6
5-
Date: 2025-03-24
4+
Version: 1.47.7
5+
Date: 2025-03-31
66
Depends: R (>= 3.5.0), gdsfmt (>= 1.31.1)
77
Imports: methods, parallel, digest, IRanges, GenomicRanges, GenomeInfoDb, Biostrings,
88
S4Vectors

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ useDynLib(SeqArray,
1616
SEQ_Apply_Variant, SEQ_Apply_Sample, SEQ_BApply_Variant,
1717
SEQ_ConvBED2GDS,
1818
SEQ_SelectFlag, SEQ_ResetChrom,
19-
SEQ_IntAssign, SEQ_AppendFill, SEQ_ClearVarMap,
19+
SEQ_IntAssign, SEQ_AppendFill, SEQ_ClearVarMap, SEQ_BufferPosition,
2020
SEQ_Pkg_Init,
2121
SEQ_bgzip_create, SEQ_Progress, SEQ_ProgressAdd,
2222
SEQ_Unit_SlidingWindows,

R/Internal.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ process_count <- 1L
245245

246246

247247

248+
#######################################################################
249+
# Get or clear the memory buffer storing variant positions (return pointer or NULL)
250+
#
251+
.buffer_position <- function(gdsfile, clear=FALSE)
252+
{
253+
.Call(SEQ_BufferPosition, gdsfile, clear)
254+
}
255+
256+
257+
248258
#######################################################################
249259
# Open and close a connection,
250260
# Please always call '.close_conn' after '.open_bin' and '.open_text'

src/Index.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Index.cpp: Indexing Objects
44
//
5-
// Copyright (C) 2016-2024 Xiuwen Zheng
5+
// Copyright (C) 2016-2025 Xiuwen Zheng
66
//
77
// This file is part of SeqArray.
88
//
@@ -933,6 +933,14 @@ vector<C_Int32> &CFileInfo::Position()
933933
return _Position;
934934
}
935935

936+
void CFileInfo::ClearPosition()
937+
{
938+
if (!_Root)
939+
throw ErrSeqArray(ERR_FILE_ROOT);
940+
_Position.clear();
941+
std::vector<C_Int32>().swap(_Position);
942+
}
943+
936944
CGenoIndex &CFileInfo::GenoIndex()
937945
{
938946
if (_GenoIndex.Empty())

src/Index.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Index.h: Indexing Objects
44
//
5-
// Copyright (C) 2016-2022 Xiuwen Zheng
5+
// Copyright (C) 2016-2025 Xiuwen Zheng
66
//
77
// This file is part of SeqArray.
88
//
@@ -414,6 +414,8 @@ class COREARRAY_DLL_LOCAL CFileInfo
414414
void ResetChromosome();
415415
/// return _Position which has been initialized
416416
vector<C_Int32> &Position();
417+
/// clear the buffer for variant positions
418+
void ClearPosition();
417419

418420
/// return _GenoIndex which has been initialized
419421
CGenoIndex &GenoIndex();

src/SeqArray.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SeqArray.cpp: the C++ codes for the SeqArray package
44
//
5-
// Copyright (C) 2013-2024 Xiuwen Zheng
5+
// Copyright (C) 2013-2025 Xiuwen Zheng
66
//
77
// This file is part of SeqArray.
88
//
@@ -1362,6 +1362,29 @@ COREARRAY_DLL_EXPORT SEXP SEQ_ClearVarMap(SEXP gdsfile)
13621362

13631363

13641364

1365+
// ===========================================================
1366+
// Clear VarMap in a GDS file
1367+
// ===========================================================
1368+
1369+
COREARRAY_DLL_EXPORT SEXP SEQ_BufferPosition(SEXP gdsfile, SEXP clear)
1370+
{
1371+
int clear_flag = Rf_asLogical(clear);
1372+
COREARRAY_TRY
1373+
CFileInfo &File = GetFileInfo(gdsfile);
1374+
if (clear_flag == 1) // TRUE
1375+
{
1376+
File.ClearPosition();
1377+
rv_ans = R_NilValue;
1378+
} else {
1379+
vector<C_Int32> &pos = File.Position();
1380+
SEXP n = Rf_ScalarInteger(pos.size()); // # of positions
1381+
rv_ans = R_MakeExternalPtr(&pos[0], R_NilValue, n);
1382+
}
1383+
COREARRAY_CATCH
1384+
}
1385+
1386+
1387+
13651388
// ===========================================================
13661389
// Get system configuration
13671390
// ===========================================================
@@ -1653,7 +1676,7 @@ COREARRAY_DLL_EXPORT void R_init_SeqArray(DllInfo *info)
16531676
CALL(SEQ_SelectFlag, 2), CALL(SEQ_ResetChrom, 1),
16541677

16551678
CALL(SEQ_IntAssign, 2), CALL(SEQ_AppendFill, 3),
1656-
CALL(SEQ_ClearVarMap, 1),
1679+
CALL(SEQ_ClearVarMap, 1), CALL(SEQ_BufferPosition, 2),
16571680

16581681
CALL(SEQ_bgzip_create, 1),
16591682
CALL(SEQ_ToVCF_Init, 6), CALL(SEQ_ToVCF_Done, 0),

0 commit comments

Comments
 (0)