Rebuild a TwasWeights from a file
exportToBed or exportToVcf wrote, or from any
file in the same vocabulary.
A merged table reads back as a multi-row collection, one row per
(study, context, trait, method) tuple. A fitted model whose
weights were a MATRIX – a joint fit, one column per member – was
published as one block per member with trait naming it, so it
reads back as one row per member with joint_traits keeping the
membership. The weights are identical either way; only the packing
differs.
Usage
readTwasWeights(
path,
region = NULL,
format = c("auto", "bed", "vcf"),
studyName = NULL,
context = NULL,
trait = NULL,
method = NULL,
dataType = NULL,
weightStandardized = NULL,
sampleSelect = NULL
)Arguments
- path
Path to the published file. Bgzipped and tabix-indexed files can be read by region.
- region
Optional region to restrict the read to – a
"chr:start-end"string, aGRanges, or a one-rowdata.framewith chrom/start/end. Ignored with a warning when the file is not tabix-indexed.- format
"auto"(default) reads a.vcf/.bcfpath as a VCF and anything else as a published table;"bed"/"vcf"say so explicitly for a file named otherwise.- studyName, context, trait, method
Identity values for a file that did not record them. Each FILLS IN the corresponding column when the file lacks it; a value that disagrees with what the file does record is an error rather than a silent override.
- dataType
Optional assay / modality label, same fill-in rule.
- weightStandardized
Whether the published weights are on the standardized genotype scale. Required when the file does not record it: the scale is not recoverable from the weights themselves.
- sampleSelect
For a multi-sample VCF, which samples to read. Each sample is one fitted model. Defaults to all of them.
What is required, and what is not
Variant ids that encode coordinates (or the columns to build them from)
and a WGT column – a weight is the whole content of a
TwasWeights. The four identity axes must be recorded or supplied,
because the collection is keyed by them. Everything else is optional and
carried through if present.
Cross-validation metrics are never published (they describe a model
scored on held-out folds, which is not per-variant and not
data-secure to express per sample), so a read-back collection has no
cvResult and no fitted models.
Examples
data(twasWeightsExample)
path <- file.path(tempdir(), "weights.bed")
exportToBed(twasWeightsExample, path)
#> exportToBed: skipping 2 fine-mapping-derived row(s) (susie, susie_inf). Those weights are the fine-mapping posterior re-expressed -- export the fine-mapping result instead, which carries the posterior, its standard error and the credible sets.
readTwasWeights(path)
#> TwasWeights: 9 entries
#> 1 studies, 1 contexts, 1 traits, 9 methods
#> LD reference: NULL (individual-level fit)