This vignette outlines a workflow of parsing and plotting structural variants from Variant Call Format (VCF) using the StructuralVariantAnnotation
package. StructuralVariantAnnotation
contains useful helper functions for reading and interpreting structural variant calls. The package contains functions for parsing VCFs from a number of popular callers as well as functions for dealing with breakpoints involving two separate genomic loci encoded as GRanges
objects.
The StructuralVariationAnnotation package can be installed from Bioconductor as follows:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("StructuralVariantAnnotation")
The VCF standard describes two types of SV notations. One is by SV types, i.e. insertions, deletions, inversions, translocations, etc. The other is by breakend notations, often labelled with SVTYPE=BND
. To describe a SV with breakend notations, each SV has two positions, each captured by one breakend (except for inversions, which have 4 separate records). Each breakend includes a genomic locus, as well as a half interval extending out to the partner breakend. In VCF BND notations, the ALT
field encodes directional information of the partner breakend.
Unlike breakpoint-centric data structures such as the Pairs
object that rtracklayer
uses to load BEDPE files, this package uses a breakend-centric notation. Breakends are stored in a GRanges object with strand used to indicate breakpoint orientation. Consistent with how breakends are encoded in VCF +
indicates that the breakpoint occurs immediately after the given position, with -
indicating the breakpoint occurs immediately before the given position. Breakpoints are represented using a partner
field containing the name of the breakend at the other side of the breakend. Both single breakends and breakpoints are supported but many-to-many breakend partner mappings supported by the VCF MATEID
field are not: each breakend must have 0 (single breakend) or 1 (breakpoint) partner breakends.
This notation was chosen as it simplifies many common operations, and annotations are breakend-level annotations. These include annotation associated with genomic positions (e.g. genes, repeats, mappability), as well as breakend-level attributes of a breakpoint such as variant allele fractions (e.g. a structural variant can be homozygous at one breakend, but heterzygous at the other breakend).
VCF data is parsed into a VCF
object using the readVCF
function from the Bioconductor package VariantAnnotation
. Simple filters could be applied to a VCF
object to remove unwanted calls. More information about VCF
objects can be found by consulting the vignettes in the VariantAnnotation package with browseVignettes("VariantAnnotation")
.
StructuralVariantAnnotation supports structural variants reported in the following VCF notations:
SVTYPE
of DEL
, INS
, and DUP
.SVTYPE=BND
In addition to parsing spec-compliant VCFs, additional logic has been added to enable parsing of non-compliant variants for the following callers:
SVTYPE=RPL
)INv3
, INV5
fields)SVTYPE=TRA
, CHR2
, CT
fields)SVTYPE=CTX
)Breakpoint ambiguity reported using the spec-defined CIPOS
is, by default, incorporated into the GRanges breakend intervals.
suppressPackageStartupMessages(require(StructuralVariantAnnotation))
suppressPackageStartupMessages(require(VariantAnnotation))
vcf.file <- system.file("extdata", "gridss.vcf", package = "StructuralVariantAnnotation")
vcf <- VariantAnnotation::readVcf(vcf.file, "hg19")
gr <- breakpointRanges(vcf)
partner()
returns the breakpoint GRanges
object with the order rearranged such that the partner breakend on the other side of each breakpoint corresponds with the local breakend.
partner(gr)
#> GRanges object with 4 ranges and 12 metadata columns:
#> seqnames ranges strand | paramRangeID REF
#> <Rle> <IRanges> <Rle> | <factor> <character>
#> gridss2h chr12 84963533 - | NA G
#> gridss39h chr12 4886681 + | NA T
#> gridss39o chr12 84350 - | NA G
#> gridss2o chr1 18992158 + | NA C
#> ALT QUAL FILTER sourceId
#> <character> <numeric> <character> <character>
#> gridss2h ]chr1:18992158]AG 55.00 LOW_QUAL;SINGLE_ASSE.. gridss2h
#> gridss39h T[chr12:84350[ 627.96 . gridss39h
#> gridss39o ]chr12:4886681]G 627.96 . gridss39o
#> gridss2o CA[chr12:84963533[ 55.00 LOW_QUAL;SINGLE_ASSE.. gridss2o
#> partner svtype svLen insSeq insLen HOMLEN
#> <character> <character> <numeric> <character> <integer> <numeric>
#> gridss2h gridss2o BND NA A 1 0
#> gridss39h gridss39o BND 4802330 0 0
#> gridss39o gridss39h BND 4802330 0 0
#> gridss2o gridss2h BND NA A 1 0
#> -------
#> seqinfo: 84 sequences from hg19 genome
Single breakends are loaded using the breakendRanges()
function. The GRanges
object is of the same form as breakpointRanges()
but as the breakend partner is not specified, the partner is NA. A single GRanges object can contain both breakend and breakpoint variants.
colo829_vcf <- VariantAnnotation::readVcf(system.file("extdata", "COLO829T.purple.sv.ann.vcf.gz", package = "StructuralVariantAnnotation"))
colo829_bpgr <- breakpointRanges(colo829_vcf)
colo829_begr <- breakendRanges(colo829_vcf)
colo829_gr <- sort(c(colo829_begr, colo829_bpgr))
colo829_gr[seqnames(colo829_gr) == "6"]
#> GRanges object with 10 ranges and 12 metadata columns:
#> seqnames ranges strand | paramRangeID
#> <Rle> <IRanges> <Rle> | <factor>
#> gridss36_2106o 6 26194117 + | NA
#> gridss36_2106h 6 26194406 + | NA
#> gridss37_233635b 6 65298376 + | NA
#> gridss38_18403o 6 94917253-94917268 + | NA
#> gridss40_299o 6 138774180-138774182 + | NA
#> gridss41_7816o 6 168570432-168570448 + | NA
#> gridss17_45233h 6 26194039-26194041 - | NA
#> gridss38_18403h 6 94917320-94917335 - | NA
#> gridss40_35285o 6 138774059 - | NA
#> gridss41_7816h 6 168570465-168570481 - | NA
#> REF ALT QUAL FILTER
#> <character> <character> <numeric> <character>
#> gridss36_2106o G G]6:26194406] 2500.79 PASS
#> gridss36_2106h A A]6:26194117] 2500.79 PASS
#> gridss37_233635b G GTGTTTTTTTCTCTGTGTTG.. 2871.65 PASS
#> gridss38_18403o T T[6:94917327[ 411.40 PON
#> gridss40_299o T T]15:23712618] 3009.75 PASS
#> gridss41_7816o G G[6:168570473[ 4495.46 PON
#> gridss17_45233h A [3:26431918[A 3842.54 PASS
#> gridss38_18403h T ]6:94917260]T 411.40 PON
#> gridss40_35285o T [15:23717166[GTATATT.. 2213.96 PASS
#> gridss41_7816h T ]6:168570440]T 4495.46 PON
#> sourceId svtype svLen
#> <character> <character> <numeric>
#> gridss36_2106o gridss36_2106o BND 288
#> gridss36_2106h gridss36_2106h BND 288
#> gridss37_233635b gridss37_233635b BND NA
#> gridss38_18403o gridss38_18403o BND -66
#> gridss40_299o gridss40_299o BND NA
#> gridss41_7816o gridss41_7816o BND -32
#> gridss17_45233h gridss17_45233h BND NA
#> gridss38_18403h gridss38_18403h BND -66
#> gridss40_35285o gridss40_35285o BND NA
#> gridss41_7816h gridss41_7816h BND -32
#> insSeq insLen HOMLEN partner
#> <character> <integer> <numeric> <character>
#> gridss36_2106o 0 0 gridss36_2106h
#> gridss36_2106h 0 0 gridss36_2106o
#> gridss37_233635b TGTTTTTTTCTCTGTGTTGT.. 683 0 <NA>
#> gridss38_18403o 0 15 gridss38_18403h
#> gridss40_299o 0 2 gridss40_299h
#> gridss41_7816o 0 16 gridss41_7816h
#> gridss17_45233h 0 2 gridss17_45233o
#> gridss38_18403h 0 15 gridss38_18403o
#> gridss40_35285o GTATATTATC 10 0 gridss40_35285h
#> gridss41_7816h 0 16 gridss41_7816o
#> -------
#> seqinfo: 25 sequences from an unspecified genome
Functions such as findBreakpointOverlaps()
require the GRanges
object to be composed entirely of valid breakpoints. Subsetting a breakpoint GRanges
object can result in one side of a breakpoint getting filtered with the remaining orphaned record no longer valid as its partner no longer exists. Such record can be filtered
colo828_chr6_breakpoints <- colo829_gr[seqnames(colo829_gr) == "6"]
# A call to findBreakpointOverlaps(colo828_chr6_breakpoints, colo828_chr6_breakpoints)
# will fail as there are a) single breakends, and b) breakpoints with missing partners
colo828_chr6_breakpoints <- colo828_chr6_breakpoints[colo828_chr6_breakpoints$partner %in% names(colo828_chr6_breakpoints)]
# As expected, each call on chr6 only overlaps with itself
countBreakpointOverlaps(colo828_chr6_breakpoints, colo828_chr6_breakpoints)
#> [1] 1 1 1 1 1 1
Note that if you did want to include inter-chromosomal breakpoints involving chromosome 6, you would need to update the filtering criteria to include records with chr6 on either side. In such cases, the filtering logic can be simplified by the selfPartnerSingleBreakends
parameter of partner()
. When selfPartnerSingleBreakends=TRUE
, the partner of single breakend events is considered to be the single breakend itself.
colo828_chr6_breakpoints <- colo829_gr[
seqnames(colo829_gr) == "6" |
seqnames(partner(colo829_gr, selfPartnerSingleBreakends=TRUE)) == "6"]
# this way we keep the chr3<->chr6 breakpoint and don't create any orphans
head(colo828_chr6_breakpoints, 1)
#> GRanges object with 1 range and 12 metadata columns:
#> seqnames ranges strand | paramRangeID REF
#> <Rle> <IRanges> <Rle> | <factor> <character>
#> gridss17_45233o 3 26431917-26431919 - | NA T
#> ALT QUAL FILTER sourceId
#> <character> <numeric> <character> <character>
#> gridss17_45233o [6:26194040[T 3882.79 PASS gridss17_45233o
#> svtype svLen insSeq insLen HOMLEN
#> <character> <numeric> <character> <integer> <numeric>
#> gridss17_45233o BND NA 0 2
#> partner
#> <character>
#> gridss17_45233o gridss17_45233h
#> -------
#> seqinfo: 25 sequences from an unspecified genome
findBreakpointOverlaps()
and countBreakpointOverlaps()
are functions for finding and counting overlaps between breakpoint objects. All breakends must have their partner breakend included in the GRanges. A valid overlap requires that breakends on boths sides overlap.
To demonstrate the countBreakpointOverlaps()
function, we use a small subset of data from our structural variant caller benchmarking paper to construct precision recall curves for a pair of callers.
truth_vcf <- readVcf(system.file("extdata", "na12878_chr22_Sudmunt2015.vcf", package = "StructuralVariantAnnotation"))
truth_svgr <- breakpointRanges(truth_vcf)
truth_svgr <- truth_svgr[seqnames(truth_svgr) == "chr22"]
crest_vcf <- readVcf(system.file("extdata", "na12878_chr22_crest.vcf", package = "StructuralVariantAnnotation"))
# Some SV callers don't report QUAL so we need to use a proxy
VariantAnnotation::fixed(crest_vcf)$QUAL <- info(crest_vcf)$left_softclipped_read_count + info(crest_vcf)$left_softclipped_read_count
crest_svgr <- breakpointRanges(crest_vcf)
crest_svgr$caller <- "crest"
hydra_vcf <- readVcf(system.file("extdata", "na12878_chr22_hydra.vcf", package = "StructuralVariantAnnotation"))
hydra_svgr <- breakpointRanges(hydra_vcf)
hydra_svgr$caller <- "hydra"
svgr <- c(crest_svgr, hydra_svgr)
svgr$truth_matches <- countBreakpointOverlaps(svgr, truth_svgr,
# read pair based callers make imprecise calls.
# A margin around the call position is required when matching with the truth set
maxgap=100,
# Since we added a maxgap, we also need to restrict the mismatch between the
# size of the events. We don't want to match a 100bp deletion with a
# 5bp duplication. This will happen if we have a 100bp margin but don't also
# require an approximate size match as well
sizemargin=0.25,
# We also don't want to match a 20bp deletion with a 20bp deletion 80bp away
# by restricting the margin based on the size of the event, we can make sure
# that simple events actually do overlap
restrictMarginToSizeMultiple=0.5,
# HYDRA makes duplicate calls and will sometimes report a variant multiple
# times with slightly different bounds. countOnlyBest prevents these being
# double-counted as multiple true positives.
countOnlyBest=TRUE)
Once we know which calls match the truth set, we can generate Precision-Recall and ROC curves for each caller using one of the many ROC R packages, or directly with dplyr.
suppressPackageStartupMessages(require(dplyr))
suppressPackageStartupMessages(require(ggplot2))
ggplot(as.data.frame(svgr) %>%
dplyr::select(QUAL, caller, truth_matches) %>%
dplyr::group_by(caller, QUAL) %>%
dplyr::summarise(
calls=dplyr::n(),
tp=sum(truth_matches > 0)) %>%
dplyr::group_by(caller) %>%
dplyr::arrange(dplyr::desc(QUAL)) %>%
dplyr::mutate(
cum_tp=cumsum(tp),
cum_n=cumsum(calls),
cum_fp=cum_n - cum_tp,
Precision=cum_tp / cum_n,
Recall=cum_tp/length(truth_svgr))) +
aes(x=Recall, y=Precision, colour=caller) +
geom_point() +
geom_line() +
labs(title="NA12878 chr22 CREST and HYDRA\nSudmunt 2015 truth set")
#> `summarise()` regrouping output by 'caller' (override with `.groups` argument)
The package supports converting GRanges objects to BEDPE files. The BEDPE format is defined by bedtools
. This is achieved using breakpointgr2pairs
and pairs2breakpointgr
functions to convert to and from the GRanges Pairs
notation used by rtracklayer
suppressPackageStartupMessages(require(rtracklayer))
# Export to BEDPE
rtracklayer::export(breakpointgr2pairs(gr), con="gridss.bedpe")
# Import to BEDPE
bedpe.gr <- pairs2breakpointgr(rtracklayer::import("gridss.bedpe"))
One way of visualising paired breakpoints is by circos plots. Here we use the package circlize
to demonstrate breakpoint visualisation. The bedpe2circos
function takes BEDPE-formatted dataframes (see breakpointgr2bedpe()
) and plotting parameters for the circos.initializeWithIdeogram()
and circos.genomicLink()
functions from circlize
.
To generate a simple circos plot of paired breakpoints:
suppressPackageStartupMessages(require(circlize))
colo829_bpgr_with_chr_prefix <- colo829_bpgr
seqlevelsStyle(colo829_bpgr_with_chr_prefix) <- "UCSC"
pairs <- breakpointgr2pairs(colo829_bpgr_with_chr_prefix)
circos.initializeWithIdeogram()
circos.genomicLink(as.data.frame(S4Vectors::first(pairs)), as.data.frame(S4Vectors::second(pairs)))
circos.clear()
Alternatively, the plotting package ggbio
provides flexible track functions which bind with ggplot2
objects. It takes GRanges
objects as input and supports circos plots. To plot structural variant breakpoints in a circos plot using ggbio
, we need to first prepare the breakpoint GRanges. The function requires a special column, indicating the end of the link using GRanges format, which we can add to gr
using plyranges
.
suppressPackageStartupMessages(require(ggbio))
gr.circos <- colo829_bpgr[seqnames(colo829_bpgr) %in% seqlevels(biovizBase::hg19sub)]
seqlevels(gr.circos) <- seqlevels(biovizBase::hg19sub)
mcols(gr.circos)$to.gr <- granges(partner(gr.circos))
We can then plot the breakpoints against reference genomes.
p <- ggbio() +
circle(gr.circos, geom="link", linked.to="to.gr") +
circle(biovizBase::hg19sub, geom='ideo', fill='gray70') +
circle(biovizBase::hg19sub, geom='scale', size=2) +
circle(biovizBase::hg19sub, geom='text', aes(label=seqnames), vjust=0, size=3)
#> Warning in recycleSingleBracketReplacementValue(value, x, nsbs): number of
#> values supplied is not a sub-multiple of the number of values to be replaced
p
sessionInfo()
#> R version 4.0.3 (2020-10-10)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.5 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.12-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.12-bioc/R/lib/libRlapack.so
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] parallel stats4 stats graphics grDevices utils datasets
#> [8] methods base
#>
#> other attached packages:
#> [1] ggbio_1.38.0 circlize_0.4.10
#> [3] ggplot2_3.3.2 dplyr_1.0.2
#> [5] StructuralVariantAnnotation_1.6.0 VariantAnnotation_1.36.0
#> [7] Rsamtools_2.6.0 Biostrings_2.58.0
#> [9] XVector_0.30.0 SummarizedExperiment_1.20.0
#> [11] Biobase_2.50.0 MatrixGenerics_1.2.0
#> [13] matrixStats_0.57.0 rtracklayer_1.50.0
#> [15] GenomicRanges_1.42.0 GenomeInfoDb_1.26.0
#> [17] IRanges_2.24.0 S4Vectors_0.28.0
#> [19] BiocGenerics_0.36.0
#>
#> loaded via a namespace (and not attached):
#> [1] colorspace_1.4-1 ellipsis_0.3.1 biovizBase_1.38.0
#> [4] htmlTable_2.1.0 GlobalOptions_0.1.2 base64enc_0.1-3
#> [7] dichromat_2.0-0 rstudioapi_0.11 farver_2.0.3
#> [10] bit64_4.0.5 AnnotationDbi_1.52.0 xml2_1.3.2
#> [13] splines_4.0.3 knitr_1.30 Formula_1.2-4
#> [16] cluster_2.1.0 dbplyr_1.4.4 png_0.1-7
#> [19] graph_1.68.0 BiocManager_1.30.10 compiler_4.0.3
#> [22] httr_1.4.2 backports_1.1.10 assertthat_0.2.1
#> [25] Matrix_1.2-18 lazyeval_0.2.2 htmltools_0.5.0
#> [28] prettyunits_1.1.1 tools_4.0.3 gtable_0.3.0
#> [31] glue_1.4.2 GenomeInfoDbData_1.2.4 reshape2_1.4.4
#> [34] rappdirs_0.3.1 Rcpp_1.0.5 vctrs_0.3.4
#> [37] xfun_0.18 stringr_1.4.0 lifecycle_0.2.0
#> [40] ensembldb_2.14.0 XML_3.99-0.5 zlibbioc_1.36.0
#> [43] scales_1.1.1 BSgenome_1.58.0 hms_0.5.3
#> [46] ProtGenerics_1.22.0 RBGL_1.66.0 AnnotationFilter_1.14.0
#> [49] RColorBrewer_1.1-2 yaml_2.2.1 curl_4.3
#> [52] memoise_1.1.0 gridExtra_2.3 biomaRt_2.46.0
#> [55] rpart_4.1-15 reshape_0.8.8 latticeExtra_0.6-29
#> [58] stringi_1.5.3 RSQLite_2.2.1 checkmate_2.0.0
#> [61] GenomicFeatures_1.42.0 BiocParallel_1.24.0 shape_1.4.5
#> [64] rlang_0.4.8 pkgconfig_2.0.3 bitops_1.0-6
#> [67] evaluate_0.14 lattice_0.20-41 purrr_0.3.4
#> [70] GenomicAlignments_1.26.0 htmlwidgets_1.5.2 labeling_0.4.2
#> [73] bit_4.0.4 tidyselect_1.1.0 GGally_2.0.0
#> [76] plyr_1.8.6 magrittr_1.5 R6_2.4.1
#> [79] generics_0.0.2 Hmisc_4.4-1 DelayedArray_0.16.0
#> [82] DBI_1.1.0 pillar_1.4.6 foreign_0.8-80
#> [85] withr_2.3.0 survival_3.2-7 RCurl_1.98-1.2
#> [88] nnet_7.3-14 tibble_3.0.4 crayon_1.3.4
#> [91] OrganismDbi_1.32.0 BiocFileCache_1.14.0 rmarkdown_2.5
#> [94] jpeg_0.1-8.1 progress_1.2.2 grid_4.0.3
#> [97] data.table_1.13.2 blob_1.2.1 digest_0.6.27
#> [100] openssl_1.4.3 munsell_0.5.0 askpass_1.1