Proposal: String representation/RleMatrix
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- r
調査の方向性
issue の再現可能な R 例から始め、CollapsedVcf assay がどのように表現されているか、特に list-matrices と DelayedArray の RleArray/RleMatrix の挙動を確認します。実装前に、合意された表現と互換性計画が必要です。完了の条件は、情報を失うことなくメモリ使用量を削減し、影響を受ける workflow に対して検証された設計が確認されることです。
索引モデルが issue の本文から書いたものです。
説明
I'd like to propose a couple of potential optimisations, particularly useful for cases where many entries are the same (e.g. AD: NA NA for GT: "./."). I'm working with a file which compresses nicely to .rds (~40MB) but is very large when in memory (17GB). This size becomes difficult to work with on a local machine or interactively.
Looping over the individual assays in a CompressedVcf I see that the largest ones are those which are matrices of lists (e.g. AD, AF, MBQ, ...). In theory (I think) they contain the same scale of information as GT, but their representation makes them much larger.
I appreciate that this list format makes working with the data cleaner than storing the entries as delimited strings (as I believe they natively are in the VCF) which likely requires parsing the string and splitting into a list-like structure anyway, but this is a tradeoff between size and usability, and applies to the entire dataset even if a user is only interested in a subset.
Would there be interest in a representation of CollapsedVcf list-matrices as either delimited strings (in which case they could be stored as RleMatrix for an additional compression boost; or RleListMatrix (which doesn't exist, but here's an open issue: https://github.com/Bioconductor/DelayedArray/issues/62)? I'm not well-versed enough in the Rle side to know if Rle provides a benefit when stored in a list, but it's an option.
Below is a comparison of object sizes for a toy example 'assay' constructed as a matrix of list elements and the size savings are potentially very large (in this case 1/62 the size).
## create a matrix of list elements
x <- matrix(
replicate(
2e4,
c(
sample(c(NA, 1, 2), 1, prob = c(100, 1, 1)),
sample(c(NA, 1, 2), 1, prob = c(100, 1, 1))
),
simplify = FALSE),
ncol = 10
)
head(x)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [2,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [3,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [4,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [5,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [6,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
#> [,8] [,9] [,10]
#> [1,] Numeric,2 Numeric,2 Numeric,2
#> [2,] Numeric,2 Numeric,2 Numeric,2
#> [3,] Numeric,2 Numeric,2 Numeric,2
#> [4,] Numeric,2 Numeric,2 Numeric,2
#> [5,] Numeric,2 Numeric,2 Numeric,2
#> [6,] Numeric,2 Numeric,2 Numeric,2
## collapse to singleton strings (credit: @lawremi)
v <- unlist(x)
v[is.na(v)] <- "."
x_str <- matrix(
S4Vectors::unstrsplit(
c(relist(v, x)), ","),
nrow(x), ncol(x))
head(x_str)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
#> [2,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
#> [3,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
#> [4,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
#> [5,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
#> [6,] ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,." ".,."
suppressMessages(library(DelayedArray))
## Rle representation of matrix of list doesn't work
as(x, "RleArray")
#> Error in .Call2("Rle_constructor", values, lengths, PACKAGE = "S4Vectors"): Rle of type 'list' is not supported
## Rle representation of string matrix
x_rle <- as(x_str, "RleArray")
x_rle
#> <2000 x 10> matrix of class RleMatrix and type "character":
#> [,1] [,2] [,3] ... [,9] [,10]
#> [1,] ".,." ".,." ".,." . ".,." ".,."
#> [2,] ".,." ".,." ".,." . ".,." ".,."
#> [3,] ".,." ".,." ".,." . ".,." ".,."
#> [4,] ".,." ".,." ".,." . ".,." ".,."
#> [5,] ".,." ".,." ".,." . ".,." ".,."
#> ... . . . . . .
#> [1996,] ".,." ".,." ".,1" . ".,." ".,."
#> [1997,] ".,." ".,." ".,." . "2,." ".,."
#> [1998,] ".,." ".,." ".,." . ".,." ".,."
#> [1999,] "1,." ".,." "1,." . ".,." ".,."
#> [2000,] "2,." ".,." ".,." . ".,." ".,."
## compare sizes
pryr::object_size(x)
#> Registered S3 method overwritten by 'pryr':
#> method from
#> print.bytes Rcpp
#> 1.44 MB
pryr::object_size(x_str)
#> 161 kB
pryr::object_size(x_rle)
#> 23 kB
Created on 2020-02-28 by the reprex package (v0.3.0)
I'm not across this package enough to have any insights into implementation issues or how this might affect other aspects of the inner workings (or user-side workings) but this approach reduces a 1.71GB CollapsedVcf into a 20MB object of the same class without destroying any information. Credit to @lawremi for guidance towards optimising the conversion and on structural advice.
- 主要言語
- R
- スター
- 32
- フォーク
- 21
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Bioconductor/VariantAnnotation のほかの issue
-
refactor the package オープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
Bioconductor/VariantAnnotation#115 · コメント 4 件 ·
-
Bioconductor/VariantAnnotation#114 · リアクション 1 件 · 担当者 2 名 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Bioconductor/VariantAnnotation#113 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
Bioconductor/VariantAnnotation#88 · コメント 2 件 ·
Bioconductor/VariantAnnotation の 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