████████╗██████╗ ██╗ ██╗██╗ ██╗ █████╗ ██████╗ ██╗
╚══██╔══╝██╔══██╗██║ ██║██║ ██║██╔══██╗██╔══██╗██║
██║ ██████╔╝██║ ██║██║ ██║███████║██████╔╝██║
██║ ██╔══██╗██║ ██║╚██╗ ██╔╝██╔══██║██╔══██╗██║
██║ ██║ ██║╚██████╔╝ ╚████╔╝ ██║ ██║██║ ██║██║
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝
Structural variant comparison tool for VCFs
Given benchmark and comparsion sets of SVs, calculate the recall, precision, and f-measure.
Truvari has some big changes. In order to keep up with the retirement of Python 2.7 https://pythonclock.org/ We're now only supporting Python 3.
Additionally, we now package Truvari so it and its dependencies can be installed directly. See Installation below. This will enable us to refactor the code for easier maintenance and reusability.
Finally, we now automatically report genotype comparisons in the summary stats.
Truvari uses Python 3.7 and can be installed with pip:
$ pip install Truvari
$ truvari -b base_calls.vcf -c compare_calls.vcf -o output_dir/
- tp-call.vcf -- annotated true positive calls from the COMP
- tp-base.vcf -- anotated true positive calls form the BASE
- fn.vcf -- false negative calls from BASE
- fp.vcf -- false positive calls from COMP
- base-filter.vcf -- size filtered calls from BASE
- call-filter.vcf -- size filtered calls from COMP
- summary.txt -- json output of performance stats
- log.txt -- run log
- giab_report.txt -- (optional) Summary of GIAB benchmark calls. See "Using the GIAB Report" below.
The following stats are generated for benchmarking your call set.
Metric | Definition |
---|---|
TP-base | Number of matching calls from the base vcf |
TP-call | Number of matching calls from the comp vcf |
FP | Number of non-matching calls from the comp vcf |
FN | Number of non-matching calls from the base vcf |
precision | TP-call / (TP-call + FP) |
recall | TP-base / (TP-base + FN) |
f1 | 2 * ((recall * precision) / (recall + precision)) |
base cnt | Number of calls in the base vcf |
call cnt | Number of calls in the comp vcf |
base size filtered | Number of base vcf calls outside of (sizemin, sizemax) |
call size filtered | Number of comp vcf calls outside of (sizemin, sizemax) |
base gt filtered | Number of base calls not passing the no-ref parameter filter |
call gt filtered | Number of comp calls not passing the no-ref parameter filter |
TP-call_TP-gt | TP-call's with genotype match |
TP-call_FP-gt | TP-call's without genotype match |
TP-base_TP-gt | TP-base's with genotype match |
TP-base_FP-gt | TP-base's without genotype match |
gt_precision | TP-call_TP-gt / (TP-call_TP-gt + FP + TP-call_FP-gt) |
gt_recall | TP-base_TP-gt / (TP-base_TP-gt / FN) |
gt_f1 | (gt_recall * gt_precision) / (gt_recall + gt_precision) |
Input:
BaseCall - Benchmark TruthSet of SVs
CompCalls - Comparison SVs from another program
Build IntervalTree of CompCalls
For each BaseCall:
Fetch CompCalls overlapping within *refdist*.
If typematch and LevDistRatio >= *pctsim* \
and SizeRatio >= *pctsize* and PctRecOvl >= *pctovl*:
Add CompCall to list of Neighbors
Sort list of Neighbors by TruScore ((2*sim + 1*size + 1*ovl) / 3.0)
Take CompCall with highest TruScore and BaseCall as TPs
Only use a CompCall once if not --multimatch
If no neighbors: BaseCall is FN
For each CompCall:
If not used: mark as FP
Parameter | Default | Definition |
---|---|---|
refdist | 500 | Maximum distance comparison calls must be within from base call's start/end |
pctsim | 0.7 | Levenshtein distance ratio between the REF/ALT haplotype sequences of base and comparison call. See "Comparing Haplotype Sequences of Variants" below. |
pctsize | 0.7 | Ratio of min(base_size, comp_size)/max(base_size, comp_size) |
pctovl | 0.0 | Ratio of two calls' (overlapping bases)/(longest span) |
typeignore | False | Types don't need to match to compare calls. |
If the base or comp vcfs do not have sequence resolved calls, simply set --pctsim=0
to turn off
sequence comparison.
--sizemin
is the minimum size of a base call or comparison call to be considered.
--sizefilt
is the minimum size of a call to be added into the IntervalTree for searching. It should
be less than sizemin
for edge case variants.
For example: sizemin
is 50 and sizefilt
is 30. A 50bp base call is 98% similar to a 49bp call at
the same position.
These two calls should be considered matching. If we instead removed calls less than sizemin
, we'd
incorrectly classify the 50bp base call as a false negative.
This does have the side effect of artificially inflating specificity. If that same 49bp call in the
above were below the similarity threshold, it would not be classified as a FP due to the sizemin
threshold. So we're giving the call a better chance to be useful and less chance to be detrimental
to final statistics.
Anno | Definition |
---|---|
TruScore | Truvari score for similarity of match. `((2*sim + 1*size + 1*ovl) / 3.0)` |
PctSeqSimilarity | Pct sequence similarity between this variant and its closest match |
PctSizeSimilarity | Pct size similarity between this variant and it's closest match |
PctRecOverlap | Percent reciprocal overlap of the two calls' coordinates |
StartDistance | Distance of this call's start from matching call's start |
EndDistance | Distance of this call's end from matching call's end |
SizeDiff | Difference in size(basecall) and size(compcall) |
NumNeighbors | Number of comparison calls that were in the neighborhood (REFDIST) of the base call |
NumThresholdNeighbors | Number of comparison calls that passed threshold matching of the base call |
NumNeighbors and NumThresholdNeighbors are also added to the FN vcf.
When running against the GIAB SV benchmark (link below), you can create a detailed report of calls summarized by the GIAB VCF's SVTYPE, SVLEN, Technology, and Repeat annotations.
To create this report.
- Run truvari with the flag
--giabreport
. - In your output directory, you will find a file named
giab_report.txt
. - Next, make a copy of the Truvari Report Template Google Sheet.
- Finally, paste ALL of the information inside
giab_report.txt
into the "RawData" tab. Be careful not to alter the report text in any way. If successul, the "Formatted" tab you will have a fully formated report.
While Truvari can use other benchmark sets, this formatted report currently only works with GIAB SV v0.5 and v0.6. Work will need to be done to ensure Truvari can parse future GIAB SV releases.
GIAB v0.6 Download Link
If an --includebed
is provided, only base and comp calls contained within the defined regions are used
for comparison. This is similar to pre-filtering your base/comp calls using:
(zgrep "#" my_calls.vcf.gz && bedtools intersect -u -a my_calls.vcf.gz -b include.bed) | bgzip > filtered.vcf.gz
with the exception that Truvari requires the start and the end to be contained in the same includebed region
whereas bedtools intersect
does not.
If an --includebed
is not provided, the comparison is restricted to only the contigs present in the base VCF
header. Therefore, any comparison calls on contigs not in the base calls will not be counted toward summary
statistics and will not be present in any output vcfs.
While many SV overlapping approaches match changes within regions with metrics such as reciprocal overlap and start/end distances, few account for the possibility to represent the same sequence change in multiple ways.
For example, consider a tandem repeat expansion of the reference sequence 'AB'. Here, we'll represent the 'insertion' sequence as lower-case 'ab', though it should be considered equivalent to 'AB'. Three equally valid descriptions of this variant would be:
#POS INS Haplotype
0 ab abAB
1 ba AbaB
2 ab ABab
Therefore, to compare the sequence similarity, Truvari builds the haplotypes over the range of a pair of calls'
min(starts):max(ends)
before making the the sequence change introduced by the variants. In python, this line
looks like:
hap1_seq = ref.get_seq(a1_chrom, start + 1, a1_start).seq + a1_seq + ref.get_seq(a1_chrom, a1_end + 1, end).seq
Where a1_seq1
is the longer of the REF or ALT allele.
Future versions of Truvari may take this concept further to reconstruct haplotypes based on phasing information between variants in order to allow for more flexibilty in complex multi-allelic representations.
Find more details and discussions about Truvari on the WIKI page.