Writes GWAS summary statistics, fine-mapping results or TWAS weights to a
GWAS-VCF-style file: one record per variant, one SAMPLE per study / fitted
model, and the per-variant statistics as FORMAT fields. The file is written
with VariantAnnotation's writeVcf, so that
package must be installed.
Supports bgzipped VCF (.vcf.gz/.vcf.bgz); BCF (.bcf) additionally needs a
working Rsamtools::asBcf(), which recent Rsamtools releases disable,
so prefer .vcf.bgz.
Usage
writeGwasVcf(obj, filename, ...)
# S4 method for class 'list'
writeGwasVcf(obj, filename, sampleName = NULL, ...)
# S4 method for class 'GwasSumStats'
writeGwasVcf(obj, filename, sampleName = NULL, studyName = NULL)
# S4 method for class 'FineMappingResultBase'
writeGwasVcf(
obj,
filename,
sampleName = NULL,
studyName = NULL,
context = NULL,
trait = NULL,
method = NULL,
splitByContext = FALSE,
splitByTrait = FALSE,
splitByBlock = FALSE
)
# S4 method for class 'TwasWeights'
writeGwasVcf(
obj,
filename,
sampleName = NULL,
studyName = NULL,
context = NULL,
trait = NULL,
method = NULL
)Arguments
- obj
A
GwasSumStats,QtlFineMappingResult,GwasFineMappingResultorTwasWeightsobject, or alistof fine-mapping results or ofTwasWeightsobjects to combine first.- filename
File path for output. Extension determines format:
.vcf.gzor.vcf.bgzfor bgzipped VCF,.bcffor BCF,.vcffor uncompressed VCF.- ...
Additional arguments passed to methods.
- sampleName
Name(s) for the VCF sample column(s). Default
NULLderives them from the object's identity tuple.- studyName
Character or
NULL. Restrict the written records to this study;NULLincludes all studies.- context
Character or
NULL. Restrict the written records to this context;NULLincludes all contexts.- trait
Character or
NULL. Restrict the written records to this trait;NULLincludes all traits.- method
Character or
NULL. Restrict the written records to this method;NULLincludes all methods.- splitByContext
Logical. If
TRUE, write one VCF per context. DefaultFALSE.- splitByTrait
Logical. If
TRUE, write one VCF per trait. DefaultFALSE.- splitByBlock
Logical.
GwasFineMappingResultonly: ifTRUE, write one VCF per LD block instead of joining a study's blocks into one file. DefaultFALSE.
Details
Which FORMAT fields are written depends on the input:
GwasSumStatsES/SE/EZ/NS/AF/MAFfor one study, whichever its variants carry.- a fine-mapping result
the marginal fields (
ES,SE,EZ,LP,NS), the fit's own (AF,WGT,WGTSE,THETA) and the posterior ones (PIP,LBF,LFSR, and aCS/PURpair per credible-set coverage present).TwasWeightsWGT, the prediction weight.
Every fit the selectors match becomes a SAMPLE of ONE file: the records are
the union of their variants, the FORMAT schema is the union of their fields,
and a fit that did not include a variant – or does not report a field –
leaves those cells empty. So two methods over a region, or a dozen weight
methods for one gene, are compared by reading one file rather than a dozen.
Each sample is described in its own ##SAMPLE header line, carrying
the fit's identity tuple and how many variants it contributed.
Cross-validation results are not written – see writeBed for
why – and writing requires the full-data fit.
A GWAS study fine-mapped block by block is ONE fit, so its blocks are
joined into one sample. A BID FORMAT field then names each
variant's LD block – credible-set indices are numbered within a block,
so a set is the (BID, CS) pair – and the per-block header values
(block id, analysis window and whether it was given, V,
cs_index) are packed in block order, separated by |.
readFineMappingResult splits such a sample back into its
blocks.
splitByContext / splitByTrait opt out of that and write one
file per context / trait, at a path decorated with the axis value, holding
the fits that share it. splitByBlock writes one file per LD block
of a GWAS result, each holding every fit's part of that block.