Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Last active November 13, 2025 18:33
Show Gist options
  • Select an option

  • Save vjcitn/f72009db9ab209f056024a558785b918 to your computer and use it in GitHub Desktop.

Select an option

Save vjcitn/f72009db9ab209f056024a558785b918 to your computer and use it in GitHub Desktop.
DelayedArray back end for plink2 bed, before I learned about BEDMatrix
library(DelayedArray)
setClass("plBedSeed",
contains="Array",
slots = c(
dim = "integer",
bedreaderRef = "ANY",
dimnames = "list"
)
)
plBedSeed = function(bedreaderRef) {
dims = as.integer(unlist(bedreaderRef$shape))
props = bedreaderRef$properties
dimnames = list(seq_len(length(props$fid)), props$sid)
new("plBedSeed", dim=dims, bedreaderRef=bedreaderRef, dimnames=dimnames)
}
setMethod("extract_array", c("plBedSeed"), function(x, index) {
reticulate::py_require("numpy")
np = reticulate::import("numpy")
br = slot(x, "bedreaderRef")
as.matrix(b3$read(np$s_[as.integer(index[[2]]-1)])[index[[1]],,drop=FALSE])
})
setClass("plBedArray", contains="DelayedArray", representation(seed="plBedSeed"))
plBedArray = function(bedreaderRef)
DelayedArray(plBedSeed(bedreaderRef))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment