Skip to contents

Writes GWAS summary statistics, fine-mapping results or TWAS weights to a GWAS-VCF-style file via VariantAnnotation and Rsamtools: one record per variant, one SAMPLE per study / fitted model, and the per-variant statistics as FORMAT fields. 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

exportToVcf(x, outputPath, sampleName = NULL, ...)

# S4 method for class 'list'
exportToVcf(x, outputPath, sampleName = NULL, ...)

# S4 method for class 'GwasSumStats'
exportToVcf(x, outputPath, sampleName = NULL, studyName = NULL)

# S4 method for class 'FineMappingResultBase'
exportToVcf(
  x,
  outputPath,
  sampleName = NULL,
  studyName = NULL,
  context = NULL,
  trait = NULL,
  method = NULL,
  splitByContext = FALSE,
  splitByTrait = FALSE
)

# S4 method for class 'TwasWeights'
exportToVcf(
  x,
  outputPath,
  sampleName = NULL,
  studyName = NULL,
  context = NULL,
  trait = NULL,
  method = NULL
)

Arguments

x

A GwasSumStats, QtlFineMappingResult, GwasFineMappingResult or TwasWeights object, or a list of fine-mapping results or of TwasWeights objects to combine first.

outputPath

File path for output. Extension determines format: .vcf.gz or .vcf.bgz for bgzipped VCF, .bcf for BCF, .vcf for uncompressed VCF.

sampleName

Name(s) for the VCF sample column(s). Default NULL derives them from the object's identity tuple.

...

Additional arguments passed to methods.

studyName

Character or NULL. Restrict the written records to this study; NULL includes all studies.

context

Character or NULL. Restrict the written records to this context; NULL includes all contexts.

trait

Character or NULL. Restrict the written records to this trait; NULL includes all traits.

method

Character or NULL. Restrict the written records to this method; NULL includes all methods.

splitByContext

Logical. If TRUE, write one VCF per context. Default FALSE.

splitByTrait

Logical. If TRUE, write one VCF per trait. Default FALSE.

Value

Invisible path(s) to the written file(s).

Details

Which FORMAT fields are written depends on the input:

GwasSumStats

ES / SS / AF for one study.

a fine-mapping result

the marginal fields (ES, SE, LP, SS, AF) plus the posterior ones (PIP, LBF, LFSR, and a CS/PUR pair per credible-set coverage present).

TwasWeights

WGT, 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 exported – see exportToBed for why – and an export requires the full-data fit.

splitByContext / splitByTrait opt out of that and write one single-sample file per fit, at a path decorated with the axis value.

See also

Examples

data(gwasSumStatsS4Example)
exportToVcf(
  gwasSumStatsS4Example, outputPath = tempfile(fileext = ".vcf"))