options(showHeadLines=3)
options(showTailLines=3)

Introduction

GDSArray is a Bioconductor package that represents GDS files as objects derived from the DelayedArray package and DelayedArray class. It converts a GDS node in the file to a DelayedArray-derived data structure. The rich common methods and data operations defined on GDSArray makes it more R-user-friendly than working with the GDS file directly.

Package installation

  1. Download the package from Bioconductor.
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("GDSArray")
  1. Load the package into R session.
library(GDSArray)

GDS format introduction

Genomic Data Structure (GDS)

The Bioconductor package gdsfmt has provided a high-level R interface to CoreArray Genomic Data Structure (GDS) data files, which is designed for large-scale datasets, especially for data which are much larger than the available random-access memory.

More details about GDS format can be found in the vignettes of the gdsfmt, SNPRelate, and SeqArray packages.

GDSArray, GDSMatrix, and GDSFile

GDSArray represents GDS files as DelayedArray instances. It has methods like dim, dimnames defined, and it inherits array-like operations and methods from DelayedArray, e.g., the subsetting method of [.

GDSArray, GDSMatrix, and DelayedArray

The GDSArray() constructor takes as arguments the file path and the GDS node inside the GDS file. The GDSArray() constructor always returns the object with rows being features (genes / variants / snps) and the columns being "samples". This is consistent with the assay data inside SummarizedExperiment. FIXME: should GDSArray() return that dim?

file <- gdsExampleFileName("seqgds")
GDSArray(file, "genotype/data")

A GDSMatrix is a 2-dimensional GDSArray, and will be returned from the GDSArray() constructor automatically if the input GDS node is 2-dimensional.

GDSArray(file, "annotation/format/DP/data")

GDSFile

The GDSFile is a light-weight class to represent GDS files. It has the $ completion method to complete any possible gds nodes. It could be used as a convenient GDSArray constructor if the slot of current_path in GDSFile object represents a valid gds node. Otherwise, it will return the GDSFile object with an updated current_path.

gf <- GDSFile(file)
gf$annotation$info
gf$annotation$info$AC

Try typing in gf$ann and pressing tab key for the completion.

GDSArray methods

slot accessors.

gt <- GDSArray(file, "genotype/data")
seed(gt)
gdsfile(gt)

Available GDS nodes

gdsnodes() takes the GDS file path or GDSFile object as input, and returns all nodes that can be converted to GDSArray instances. The returned GDS node names can be used as input for the GDSArray(name=) constructor.

gdsnodes(file)
identical(gdsnodes(file), gdsnodes(gf))
varname <- gdsnodes(file)[2]
GDSArray(file, varname)

dim(), dimnames()

The dimnames(GDSArray) returns an unnamed list, with the value of NULL or dimension names with length being the same as return from dim(GDSArray).

dp <- GDSArray(file, "annotation/format/DP/data")
dim(dp)
class(dimnames(dp))
lengths(dimnames(dp))

[ subsetting

GDSArray instances can be subset, following the usual R conventions, with numeric or logical vectors; logical vectors are recycled to the appropriate length.

dp[1:3, 10:15]
dp[c(TRUE, FALSE), ]

some numeric calculation

log(dp)
dp[rowMeans(dp) < 60, ]

Internals: GDSArraySeed

The GDSArraySeed class represents the 'seed' for the GDSArray object. It is not exported from the GDSArray package. Seed objects should contain the GDS file path, node name, and are expected to satisfy the seed contract for implementing a DelayedArray backend, i.e. to support dim() and dimnames().

seed <- GDSArray:::GDSArraySeed(file, "genotype/data")
seed

The seed can be used to construct a GDSArray instance.

GDSArray(seed)

The DelayedArray() constructor with GDSArraySeed object as argument will return the same content as the GDSArray() constructor over the same GDSArraySeed.

class(DelayedArray(seed))

sessionInfo

sessionInfo()


Bioconductor/GDSArray documentation built on June 29, 2024, 12:57 p.m.