How to implement a realization backend
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- r
调研方向
先从 Implementing A DelayedArray Backend vignette 开始,然后阅读 R/RealizationSink-class.R 和 R/read_block.R。将提议的 ADSRealizationSink 工作流与 HDF5Array 中的 R/writeHDF5Array.R 和 R/writeTENxMatrix.R 进行比较。在 vignette 中记录 realization backend 及其 coercion method,并与当前 API 保持一致,即视为完成。
由索引模型根据 Issue 内容生成。
描述
The Implementing A DelayedArray Backend vignette only covers how to implement a backend for read access only. Backends that support saving DelayedArray objects (a.k.a. realization backends) are not covered yet. Reasons for this are various: no demand so far, exact procedure still kind of a work-in-progress and subject to changes, lack of time, etc...
In the meantime, I'm putting some material here (and will move it to the Implementing A DelayedArray Backend vignette as time allows).
Say we want to implement a realization backend for the ADS format (the imaginary format made up for the Implementing A DelayedArray Backend vignette), the 2 core things we need to implement are:
-
A RealizationSink subclass for the ADS backend. RealizationSink is a virtual class defined in the DelayedArray package (in
R/RealizationSink-class.R). By analogy with the HDF5RealizationSink class defined in the HDF5Array package (inR/writeHDF5Array.R), let's assume that the RealizationSink subclass for the ADS backend will be called ADSRealizationSink. -
Coercion methods from ADSRealizationSink to ADSArraySeed, ADSArray, and DelayedArray.
RealizationSink subclass
The purpose of an ADSRealizationSink object is to point to a new ADS dataset and allow writing blocks of data to it. The class definition for ADSRealizationSink would typically look something like:
setClass("ADSRealizationSink",
contains="RealizationSink",
representation(
dim="integer", # Naming this slot "dim" makes dim() work out of the box.
dimnames="list",
type="character", # Single string.
## Additional slots would typically include the path or connection to a file....
...
)
)
Then we need a constructor function for these objects. The constructor should be named as the class and its first 3 arguments should be dim, dimnames, and type. It can have more arguments but those are optional and calling ADSRealizationSink() with the first 3 arguments only (i.e. ADSRealizationSink(dim, dimnames, type)) should work. Furthermore, every call to ADSRealizationSink() should create a new dataset that is ready to be written to.
ADSRealizationSink objects must support the following operations (via defining appropriate methods):
dim(),dimnames(), andtype(). These should return the values that were passed to the call toADSRealizationSink()that was used to create the object.write_block(). This is a generic defined in the DelayedArray package inR/read_block.R.close(). This base R S3 generic is promoted to S4 generic in the DelayedArray package inR/RealizationSink-class.R. A default method for RealizationSink objects is provided and does nothing (no-op). Implement a method for ADSRealizationSink objects only if some connection needs to be closed and/or other resources need to be released after writing the data is complete and before the ADSRealizationSink object can be turned into an ADSArraySeed object for reading.
Coercion methods from ADSRealizationSink to ADSArraySeed, ADSArray, and DelayedArray
From ADSRealizationSink to ADSArraySeed
Think of an ADSRealizationSink object as a "write" connection to an ADS data set. Think of an ADSArraySeed object as a "read only" connection to an ADS data set. The purpose of the coercion from ADSRealizationSink to ADSArraySeed is to change the nature of this connection from "write" to "read only" and to produce an object that can be wrapped into a DelayedArray object.
From ADSRealizationSink to ADSArray and DelayedArray
setAs("ADSRealizationSink", "ADSArray",
function(from) DelayedArray(as(from, "ADSArraySeed"))
)
setAs("ADSRealizationSink", "DelayedArray", function(from) as(from, "ADSArray"))
A basic example
Once we have the above (i.e. ADSRealizationSink objects, ADSRealizationSink() constructor, and the 3 coercion methods), we can realize an arbitrary DelayedArray object x as a new pristine ADSArray object x2 by using the simple code below:
realize_as_ADSArray <- function(x)
{
sink <- ADSRealizationSink(dim(x), dimnames(x), type(x))
DelayedArray:::BLOCK_write_to_sink(x, sink)
close(sink)
as(sink, "DelayedArray") # a pristine ADSArray object semantically equivalent to `x`
}
DelayedArray:::BLOCK_write_to_sink() reads blocks from x, realizes them in memory, and writes them to sink (with write_block()).
Note that realize_as_ADSArray() also works on an ordinary array or any array-like object that supports extract_array(), not just on a DelayedArray object.
Add some convenience
Now we can build some convenience on top of this.
One basic convenience is a coercion method from ANY to ADSArray that just does what realize_as_ADSArray() does:
setAs("ANY", "ADSArray", function(from) realize_as_ADSArray(from))
Unfortunately, trying to coerce a DelayedArray or DelayedMatrix object to ADSArray would produce a broken object if we didn't also have the following coercion methods:
setAs("DelayedArray", "ADSArray", function(from) realize_as_ADSArray(from))
setAs("DelayedMatrix", "ADSArray", function(from) realize_as_ADSArray(from))
So in the same way that an array-like object x (ordinary array or DelayedArray object) can be realized as an HDF5Array or RleArray object with as(x, "HDF5Array") or as(x, "RleArray"), now it can also be realized as an ADSArray object with as(x, "ADSArray").
Real examples of realization backends
Refer to R/writeHDF5Array.R and R/writeTENxMatrix.R in the HDF5Array package for the implementation of the HDF5Array and TENxMatrix realization backends.
Note that you can use supportedRealizationBackends() to see the list of realization backends currently supported.
- 主要语言
- R
- 星标
- 29
- 派生
- 12
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Bioconductor/DelayedArray 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 38/100
Bioconductor/DelayedArray#129 · 11 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
Bioconductor/DelayedArray#127 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
Bioconductor/DelayedArray#125 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 45/100
Bioconductor/DelayedArray#123 ·
-
难度 5/5 一周以上 新手友好度 20/100
Bioconductor/DelayedArray#122 ·
查看 Bioconductor/DelayedArray 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
briandconnelly/airnow#9 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
OHDSI/CohortConstructor#774 ·
-
pre-review R TeX Track: 5 (DSAIS)
难度 1/5 1 小时以内 新手友好度 60/100
openjournals/joss-reviews#11330 · 7 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100