Proposal: String representation/RleMatrix
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- r
- Domaine
- bioinformatics
Piste de recherche
Commencez par l’exemple R reproductible de l’issue et examinez comment les assays CollapsedVcf sont représentés, en particulier les list-matrices et le comportement de RleArray/RleMatrix de DelayedArray. La proposition nécessite une représentation convenue et un plan de compatibilité avant l’implémentation ; le travail sera considéré comme terminé lorsqu’un design confirmé réduira l’utilisation de la mémoire sans perte d’information et sera validé sur les workflows concernés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- R
- Étoiles
- 32
- Forks
- 21
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de Bioconductor/VariantAnnotation
-
refactor the package Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
Bioconductor/VariantAnnotation#115 · 4 commentaires ·
-
Bioconductor/VariantAnnotation#114 · 1 réaction · 2 personnes assignées ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Bioconductor/VariantAnnotation#113 · 2 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
-
ensemblVEP::parseCSQToGRanges Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
Bioconductor/VariantAnnotation#88 · 2 commentaires ·
Toutes les issues de Bioconductor/VariantAnnotation
Issues similaires
-
area:livestock bug priority:low
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
eduaguilera/whep#1313 ·
-
rules
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
The-Strategy-Unit/nhp_reskit#229 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
epiforecasts/EpiNow2#1547 ·