PlinkMatrix: DelayedArray interface to plink bed-type files

Introduction

Many genetic studies employ PLINK for data management and analysis.

This package facilitates interrogation of PLINK bed files through the Bioconductor DelayedArray protocol

Installation

Use Bioconductor 3.23.

BiocManager::install("PlinkMatrix")

Demonstration

The example_PlinkMatrix function will

  • retrieve a zip archive from a cloud store if needed, and place it in the default BiocFileCache cache
  • unzip the cached archive to bed, bim, fam files
  • create the DelayedArray interface to the unzipped archive

The example data are those distributed with tensorQTL, transformed to bed using plink2.

library(PlinkMatrix)
gdemo <- example_PlinkMatrix()
colnames(gdemo) <- gsub("0_", "", colnames(gdemo))
gdemo
## <367759 x 445> DelayedMatrix object of type "double":
##                         HG00096 HG00097 HG00099 ... NA20826 NA20828
##     chr18_10644_C_G_b38       0       0       0   .       0       0
##     chr18_10847_C_A_b38       0       0       0   .       0       0
##     chr18_11275_G_A_b38       0       0       0   .       0       0
##     chr18_11358_G_A_b38       0       0       0   .       0       0
##     chr18_11445_G_A_b38       0       0       0   .       0       0
##                     ...       .       .       .   .       .       .
## chr18_80259028_AG_A_b38       1       2       2   .       0       1
##  chr18_80259147_G_C_b38       0       0       0   .       0       0
##  chr18_80259181_A_G_b38       0       0       0   .       0       0
##  chr18_80259190_C_G_b38       1       0       0   .       1       0
##  chr18_80259245_C_A_b38       0       0       0   .       0       0

Sanity check

We will use ancestry information and approximate PCA to illustrate plausibility of the approach used here.

We have codes for the ancestral origins of samples.

data(g445samples)
table(g445samples$Population.code)
## 
## CEU FIN GBR TSI YRI 
##  89  92  86  91  87

We’ll take a random sample of 1000 SNP and retrieve 10 PCs, then visualize aspects of the reexpression to PCs for discriminating population of ancestry.

library(irlba)
set.seed(1234)
ss <- sort(sample(seq_len(nrow(gdemo)), size = 1000))
pca <- prcomp_irlba(t(gdemo[ss, ]), 10)
pairs(pca$x[, 1:4], col = factor(g445samples$Population.code), pch = 19, cex = .5)

boxplot(split(pca$x[, 2] + pca$x[, 1], g445samples$Population.code))

SummarizedExperiment wrapper; subsetting with GenomicRanges

data(example_GRanges)
library(SummarizedExperiment)
nse <- SummarizedExperiment(list(genotypes = gdemo),
  rowData = example_GRanges, colData = g445samples
)
nse
## class: RangedSummarizedExperiment 
## dim: 367759 445 
## metadata(0):
## assays(1): genotypes
## rownames(367759): chr18_10644_C_G_b38 chr18_10847_C_A_b38 ...
##   chr18_80259190_C_G_b38 chr18_80259245_C_A_b38
## rowData names(0):
## colnames(445): HG00096 HG00097 ... NA20826 NA20828
## colData names(5): Sex Population.code Population.name
##   Superpopulation.code Superpopulation.name
little <- GenomicRanges::GRanges("chr18:1-100000")
subsetByOverlaps(nse, little)
## class: RangedSummarizedExperiment 
## dim: 353 445 
## metadata(0):
## assays(1): genotypes
## rownames(353): chr18_10644_C_G_b38 chr18_10847_C_A_b38 ...
##   chr18_99977_C_T_b38 chr18_99998_G_A_b38
## rowData names(0):
## colnames(445): HG00096 HG00097 ... NA20826 NA20828
## colData names(5): Sex Population.code Population.name
##   Superpopulation.code Superpopulation.name

Session information

sessionInfo()
## R version 4.6.0 (2026-04-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] irlba_2.3.7                 PlinkMatrix_1.0.0          
##  [3] SummarizedExperiment_1.42.0 Biobase_2.72.0             
##  [5] GenomicRanges_1.64.0        Seqinfo_1.2.0              
##  [7] DelayedArray_0.38.1         SparseArray_1.12.0         
##  [9] S4Arrays_1.12.0             abind_1.4-8                
## [11] IRanges_2.46.0              S4Vectors_0.50.0           
## [13] MatrixGenerics_1.24.0       matrixStats_1.5.0          
## [15] BiocGenerics_0.58.0         generics_0.1.4             
## [17] Matrix_1.7-5                Rcpp_1.1.1-1.1             
## [19] BiocStyle_2.40.0           
## 
## loaded via a namespace (and not attached):
##  [1] rappdirs_0.3.4      sass_0.4.10         RSQLite_2.4.6      
##  [4] lattice_0.22-9      magrittr_2.0.5      digest_0.6.39      
##  [7] evaluate_1.0.5      grid_4.6.0          fastmap_1.2.0      
## [10] blob_1.3.0          jsonlite_2.0.0      DBI_1.3.0          
## [13] BiocManager_1.30.27 purrr_1.2.2         httr2_1.2.2        
## [16] jquerylib_0.1.4     cli_3.6.6           rlang_1.2.0        
## [19] dbplyr_2.5.2        XVector_0.52.0      bit64_4.8.0        
## [22] withr_3.0.2         cachem_1.1.0        yaml_2.3.12        
## [25] tools_4.6.0         memoise_2.0.1       dplyr_1.2.1        
## [28] filelock_1.0.3      curl_7.1.0          buildtools_1.0.0   
## [31] vctrs_0.7.3         R6_2.6.1            lifecycle_1.0.5    
## [34] BiocFileCache_3.2.0 bit_4.6.0           pkgconfig_2.0.3    
## [37] pillar_1.11.1       bslib_0.10.0        glue_1.8.1         
## [40] tidyselect_1.2.1    tibble_3.3.1        xfun_0.57          
## [43] sys_3.4.3           knitr_1.51          htmltools_0.5.9    
## [46] rmarkdown_2.31      maketools_1.3.2     compiler_4.6.0