Skip to content

Commit 523a221

Browse files
committed
seqGetData, get_list (if matrix)
1 parent ecfb441 commit 523a221

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

DESCRIPTION

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

R/Utilities.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
# R expressions called in C internally
1313
.lang_eval <- list(
14-
new_rle = quote(new("Rle", values=values, lengths=lengths))
14+
new_rle = quote(new("Rle", values=values, lengths=lengths)),
15+
as_List = quote(as(object, "List"))
1516
)
1617

1718
# Compressed Lists in IRanges

src/GetData.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,10 @@ static SEXP get_list(SEXP len, SEXP val, size_t elmsize, bool is_factor)
826826
}
827827
vv = ZeroLen;
828828
} else {
829-
vv = Rf_allocVector(TYPEOF(val), nn);
829+
if (elmsize <= 1)
830+
vv = Rf_allocVector(TYPEOF(val), nn);
831+
else
832+
vv = Rf_allocMatrix(TYPEOF(val), elmsize, psel[i]);
830833
if (is_factor)
831834
{
832835
SET_CLASS(vv, GET_CLASS(val));
@@ -866,6 +869,24 @@ static SEXP get_list(SEXP len, SEXP val, size_t elmsize, bool is_factor)
866869

867870
// .List_IRanges_value
868871
extern "C" SEXP OBJ_CompressedList = NULL;
872+
// as(, "List")
873+
extern "C" SEXP LANG_AS_LIST = NULL;
874+
875+
/// create a S4Vectors::List object
876+
inline static SEXP as_s4vectors_list(SEXP x)
877+
{
878+
// LANG_AS_LIST = quote(as(object, "List"))
879+
SEXP epr = PROTECT(LANG_AS_LIST);
880+
// set parameters
881+
SETCADR(epr, x); // parameter: object
882+
// call
883+
SEXP rv = PROTECT(Rf_eval(epr, R_GlobalEnv));
884+
// free
885+
SETCADR(epr, R_NilValue); // parameter: object
886+
// output
887+
UNPROTECT(2);
888+
return rv;
889+
}
869890

870891
/// convert to a compressed list in IRanges
871892
static SEXP get_list2(SEXP len, SEXP val, bool is_factor)
@@ -1013,8 +1034,11 @@ static SEXP get_info(CFileInfo &File, TVarMap &Var, void *param)
10131034
// convert to a list
10141035
size_t d2 = (Var.NDim < 2) ? 1 : dimcnt[1];
10151036
if ((P->tolist == TRUE) || (d2 != 1))
1037+
{
10161038
rv_ans = get_list(I32, val, d2, is_factor);
1017-
else
1039+
if (P->tolist == NA_INTEGER)
1040+
rv_ans = as_s4vectors_list(rv_ans);
1041+
} else
10181042
rv_ans = get_list2(I32, val, is_factor);
10191043
} else {
10201044
// create `list(length, data)`

src/SeqArray.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,7 @@ COREARRAY_DLL_EXPORT SEXP SEQ_ProgressAdd(SEXP ref, SEXP inc)
15671567
// ===========================================================
15681568

15691569
extern SEXP LANG_NEW_RLE;
1570+
extern SEXP LANG_AS_LIST;
15701571
extern SEXP OBJ_CompressedList;
15711572

15721573
COREARRAY_DLL_EXPORT SEXP SEQ_Pkg_Init(SEXP dim_name, SEXP proc_cnt,
@@ -1584,6 +1585,7 @@ COREARRAY_DLL_EXPORT SEXP SEQ_Pkg_Init(SEXP dim_name, SEXP proc_cnt,
15841585
R_Process_Index = INTEGER(proc_idx);
15851586
// lang_eval
15861587
LANG_NEW_RLE = VECTOR_ELT(lang_eval, 0);
1588+
LANG_AS_LIST = VECTOR_ELT(lang_eval, 1);
15871589
// Compressed Lists in IRanges
15881590
OBJ_CompressedList = list_val;
15891591
// return

0 commit comments

Comments
 (0)