--- 
title: "DelayedDataFrame"
subtitle: on-disk data representation in `DataFrame` metaphor
author: 
- name: Qian Liu
  affiliation: Bioconductor Core Team, RPCCC, Buffalo
date: "`r Sys.Date()`"
output: ioslides_presentation
---

## DelayedDataFrame class

- Extends: DataFrame 
```{r, DataFrameClass}
library(DelayedDataFrame)
(ddf <- DelayedDataFrame())
```

- `lazyIndex` slot  
Saves the mapping indexes for each column.

```{r, nulllist}
lazyIndex(ddf)
```

## Constructor: 

Each argument in "`...`" is coerced to a `DataFrame` and combined column-wise.
```
DelayedDataFrame(..., row.names=FALSE, check.names=TRUE)
```

```{r, constructor}
(obj <- DelayedDataFrame(letters, LETTERS, row.names=LETTERS))
```
--- 

```{r, constructor1}
lazyIndex(obj)
```

## On-disk data representation in `DataFrame` format

- Genomic Data Structure (GDS)  

CoreArray Genomic Data Structure (GDS) is designed for large-scale
datasets (for available random-access memory). The _Bioconductor_
package `gdsfmt` has provided a high-level R interface to GDS.

--- 


```{r GDS}
file <- SeqArray::seqExampleFileName("gds")
f <- gdsfmt::openfn.gds(file)
f
```

```{r GDSclose, echo=FALSE}
closefn.gds(f)
```

---

- GDSArray  

`GDSArray` is an _R_ and _Bioconductor_ package, that represents GDS
files as `DelayedArray` instances.

```{r, GDSArray}
library(GDSArray)
gdsnodes(file)
```

---

Use `GDSArray` to represent the GDS nodes for variant annotation.

```{r, GDSArray1}
varid <- GDSArray(file, "annotation/id")
AA <- GDSArray(file, "annotation/info/AA")
```

```{r, GDSArray2}
varid
```

--- 
```{r, GDSArrayStr, tidy=TRUE}
seed(varid)
```

---

Construct a `DelayedDataFrame` object with `GDSArray` columns.

```{r, ddfgds}
(ddf <- DelayedDataFrame(varid, AA))
```

## subsetting

- `listData`: unchanged

```{r, subset}
(ddf1 <- ddf[1:20,])
identical(ddf@listData, ddf1@listData)
```

--- 

- `lazyIndex`: updated
- `nrows`: updated
- `rownames`: updated (if not NULL)

```{r, subset1}
lazyIndex(ddf1)
nrow(ddf1)
```

## `lazyIndex` realization

```{r, coercion}
as(ddf1, "DataFrame")
```

## Availability

The development version is available to download through github: 

```{r getDevel, eval=FALSE}
devtools::install_github("Bioconductor/DelayedDataFrame")
```
