Contents

1 Introduction

Many genetic studies employ PLINK for data management and analysis.

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

2 Installation

Use Bioconductor 3.23.

BiocManager::install("PlinkMatrix")

3 Demonstration

The example_PlinkMatrix function will

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

4 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))

5 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

6 Session information

sessionInfo()
## R Under development (unstable) (2026-11-13 r90887)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04.1 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.25-bioc/R/lib/libRblas.so 
## LAPACK: /home/biocbuild/bbs-3.25-bioc/R/lib/libRlapack.so;  LAPACK version 3.12.1
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [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: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] irlba_2.4.1                 PlinkMatrix_1.3.0          
##  [3] SummarizedExperiment_1.45.0 Biobase_2.75.0             
##  [5] GenomicRanges_1.67.0        Seqinfo_1.5.0              
##  [7] DelayedArray_0.41.0         SparseArray_1.15.0         
##  [9] S4Arrays_1.15.0             abind_1.4-8                
## [11] IRanges_2.49.0              S4Vectors_0.53.0           
## [13] MatrixGenerics_1.27.0       matrixStats_1.5.0          
## [15] BiocGenerics_0.61.0         generics_0.1.4             
## [17] Matrix_1.7-6                Rcpp_1.1.2                 
## [19] BiocStyle_2.43.0           
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.5.0          RSQLite_3.53.3      lattice_0.23-1     
##  [4] magrittr_2.0.5      digest_0.6.39       evaluate_1.0.5     
##  [7] grid_4.7.0          bookdown_0.48       fastmap_1.2.0      
## [10] blob_1.3.0          jsonlite_2.0.0      DBI_1.3.0          
## [13] tinytex_0.61        BiocManager_1.30.27 purrr_1.2.2        
## [16] httr2_1.3.0         jquerylib_0.1.4     cli_3.6.6          
## [19] rlang_1.3.0         dbplyr_2.6.0        XVector_0.55.0     
## [22] bit64_4.8.6         withr_3.0.3         cachem_1.1.0       
## [25] yaml_2.3.12         otel_0.3.0          tools_4.7.0        
## [28] memoise_2.0.1       dplyr_1.2.1         filelock_1.0.3     
## [31] curl_8.2.0          vctrs_0.7.3         R6_2.6.1           
## [34] magick_2.9.1        lifecycle_1.0.5     BiocFileCache_3.5.0
## [37] bit_4.6.0           pkgconfig_2.0.3     pillar_1.11.1      
## [40] bslib_0.12.0        glue_1.8.1          tidyselect_1.2.1   
## [43] tibble_3.3.1        xfun_0.62           knitr_1.52         
## [46] htmltools_0.5.9     rmarkdown_2.32      compiler_4.7.0