varcode 10.1.2__tar.gz → 10.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {varcode-10.1.2/varcode.egg-info → varcode-10.2.0}/PKG-INFO +1 -1
- {varcode-10.1.2 → varcode-10.2.0}/pyproject.toml +1 -1
- varcode-10.2.0/tests/test_sample_identity.py +386 -0
- varcode-10.2.0/tests/test_vcf_export_integrity.py +168 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf_output.py +11 -12
- {varcode-10.1.2 → varcode-10.2.0}/varcode/__init__.py +6 -0
- varcode-10.2.0/varcode/_sample_vcf.py +338 -0
- varcode-10.2.0/varcode/cli/main.py +17 -0
- varcode-10.2.0/varcode/cli/sample_checks.py +95 -0
- varcode-10.2.0/varcode/sample_identity.py +306 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/vcf.py +1 -0
- varcode-10.2.0/varcode/vcf_output.py +209 -0
- varcode-10.2.0/varcode/version.py +1 -0
- {varcode-10.1.2 → varcode-10.2.0/varcode.egg-info}/PKG-INFO +1 -1
- {varcode-10.1.2 → varcode-10.2.0}/varcode.egg-info/SOURCES.txt +6 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode.egg-info/entry_points.txt +1 -1
- varcode-10.1.2/varcode/vcf_output.py +0 -268
- varcode-10.1.2/varcode/version.py +0 -1
- {varcode-10.1.2 → varcode-10.2.0}/LICENSE +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/MANIFEST.in +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/README.md +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/requirements.txt +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/setup.cfg +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_annotator_divergence_scenarios.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_annotator_haplotypes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_annotator_parity_adversarial.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_annotators.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_bnd_retained_segments.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cli_effects.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cli_genes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cli_records.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cli_without_pkg_resources.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_collection_filtering.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_collection_variants_attr_consistency.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_common.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cosmic_mutations.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_cryptic_exons.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_csv_roundtrip.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_dbnsfp_validation.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_default_structural_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_documentation_examples.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_annotation_errors.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_candidates.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_classes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_collection.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_collection_serialization.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_collection_sort_order.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effect_hypotheses.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_effects_from_mutagenix_variants.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_exacto_fusions.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_exonic_splice_site.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_fast_path.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_frameshift_cterminus_regression.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_frameshift_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_fusion_insertions.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_fusion_partner_candidates.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_genome_contig_validation.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_genome_sequence.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_genomic_layout.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_genotype.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_genotype_from_vcf.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_germline_context.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_germline_effects.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_germline_overlap.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_haplotype_effect.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_local_sv_insertions.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_maf.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_mitochondrial.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_mm10_klf6_frameshift.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_mouse.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_mutant_transcript.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_mutate.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_no_duplicate_variants.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_nonlocal_layout.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_nonlocal_sv_transcripts.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_osteosarc_dataset.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_osteosarc_fusions.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_osteosarc_variants.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_partial_annotators.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_premature_stop_short_description.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_problematic_variants.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_protein_diff_parity.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_read_phase_resolver.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_real_world_callers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_reference.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_reference_mismatch_error.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_reference_segments.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_rna_evidence.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_rna_haplotype_sequences.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_rna_read_phasing_source.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_selenocysteine.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_selenocysteine_proteins.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_silent_aa_pos.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_silent_hgvs_description.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_splice_graph.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_splice_outcomes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_splice_site_effects.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_stop_codon_classification_bugs.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_string_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_structural_serialization.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_structural_variant_annotator.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_structural_variants.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_sv_comparison.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_sv_consequences.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_sv_selenocysteine.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_sv_sequence_changes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_sv_tabular_metadata.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_symbolic_alleles.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_symbolic_sv_padding.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_test_script.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_timings.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_transcript_layout.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_transcript_model.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_transcript_model_start_codons.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_transforms_left_align.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_transforms_pair_breakends.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_variant.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_variant_collection.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf_limits.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf_parsing.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf_phase_resolver.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/tests/test_vcf_spec_examples.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/annotators/__init__.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/annotators/fast.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/annotators/protein_diff.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/annotators/registry.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/__init__.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/effects_script.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/genes_script.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/logging.conf +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/variant_args.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cli/version_info.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/common.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/cryptic_exons.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/csv_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effect_candidates.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effect_hypotheses.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/__init__.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/classify.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/codon_tables.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/common.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_classes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_collection.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_ordering.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_prediction.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_prediction_coding.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/fast_path.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/mutate.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/selenocysteine.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/sequence_change.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/structural.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/structural_serialization.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/transcript_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/effects/translate.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/errors.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/exacto.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/genome.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/genome_sequence.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/genomic_layout.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/genotype.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/germline.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/maf.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/mutant_transcript.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/nucleotides.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/phasing.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/realized_effects.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/reference.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/rna_evidence.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/rna_read_phasing.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/splice_graph.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/splice_outcomes.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/string_helpers.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/structural_variant.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/sv_allele_parser.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/sv_comparison.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/transcript_layout.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/transcript_model.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/transforms/__init__.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/ucsc_reference_names.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/util.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/variant.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/variant_collection.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode/vcf_parsing.py +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode.egg-info/dependency_links.txt +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode.egg-info/requires.txt +0 -0
- {varcode-10.1.2 → varcode-10.2.0}/varcode.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"""Synthetic VCF construction and independently specified sample identities.
|
|
2
|
+
|
|
3
|
+
No downloaded fixtures: the genotype patterns, LOH edits and tumor branches
|
|
4
|
+
used as ground truth are visible here alongside their expected comparisons.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import replace
|
|
8
|
+
import gzip
|
|
9
|
+
import json
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
from varcode import SampleCheckConfig, SampleSpec, check_sample_identity, compare_samples, load_vcf_samples
|
|
17
|
+
from varcode.cli.main import main
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _vcf(tmp_path, name, sample_names, rows, *, reference="GRCh37", metadata=""):
|
|
21
|
+
path = tmp_path / name
|
|
22
|
+
text = (
|
|
23
|
+
'##fileformat=VCFv4.2\n'
|
|
24
|
+
+ ('##reference=%s\n' % reference if reference else '')
|
|
25
|
+
+ metadata
|
|
26
|
+
+ '##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">\n'
|
|
27
|
+
'##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Depth">\n'
|
|
28
|
+
'##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Quality">\n'
|
|
29
|
+
'##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Allele depths">\n'
|
|
30
|
+
'##FORMAT=<ID=AF,Number=A,Type=Float,Description="Allele fraction">\n'
|
|
31
|
+
'##FORMAT=<ID=FT,Number=1,Type=String,Description="Sample filter">\n'
|
|
32
|
+
'#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\t'
|
|
33
|
+
+ '\t'.join(sample_names) + '\n'
|
|
34
|
+
+ ''.join('\t'.join(map(str, row)) + '\n' for row in rows))
|
|
35
|
+
if name.endswith('.gz'):
|
|
36
|
+
with gzip.open(path, 'wt') as out:
|
|
37
|
+
out.write(text)
|
|
38
|
+
else:
|
|
39
|
+
path.write_text(text)
|
|
40
|
+
return path
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _row(i, *calls, alt="C", fmt="GT:DP:GQ", info=".", chrom="1"):
|
|
44
|
+
return [chrom, 1 + i * 200_000, '.', 'A', alt, '.', 'PASS', info, fmt, *calls]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _donor(tmp_path, name="donor.vcf", *, swapped=False, loh=False, role="germline", **kwargs):
|
|
48
|
+
genotypes = ["0/0", "0/1", "1/1"]
|
|
49
|
+
if swapped:
|
|
50
|
+
genotypes = ["1/1", "0/1", "0/0"]
|
|
51
|
+
if loh:
|
|
52
|
+
genotypes = ["0/0", "1/1", "1/1"]
|
|
53
|
+
path = _vcf(tmp_path, name, ["S"], [_row(i, genotypes[i % 3] + ":30:60") for i in range(210)])
|
|
54
|
+
return load_vcf_samples(path, samples=[SampleSpec("S", role=role, **kwargs)])[0]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_same_donor_and_swapped_labels(tmp_path):
|
|
58
|
+
a = _donor(tmp_path, "normal-a.vcf", donor_id="A")
|
|
59
|
+
b = _donor(tmp_path, "normal-b.vcf", swapped=True, donor_id="B")
|
|
60
|
+
mislabeled = _donor(tmp_path, "tumor-b.vcf", role="tumor", donor_id="B")
|
|
61
|
+
report = check_sample_identity([a, b, mislabeled])
|
|
62
|
+
ab, at, bt = report["pairs"]
|
|
63
|
+
assert ab["germline"]["status"] == "discordant"
|
|
64
|
+
assert ab["germline"]["ibs0"] == 140
|
|
65
|
+
assert at["germline"]["status"] == "compatible"
|
|
66
|
+
assert at["flags"] == ["unexpected_donor_compatibility"]
|
|
67
|
+
assert bt["flags"] == ["expected_donor_mismatch"]
|
|
68
|
+
assert report["identity_conflicts"] == 1
|
|
69
|
+
assert report["config"]["min_shared_snps"] == 100
|
|
70
|
+
assert len(report["samples"][0]["sha256"]) == 64
|
|
71
|
+
assert "snps" not in report["samples"][0]
|
|
72
|
+
json.dumps(report, allow_nan=False)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_tumor_loh_is_tolerated_but_exact_normal_comparison_is_stricter(tmp_path):
|
|
76
|
+
a = _donor(tmp_path)
|
|
77
|
+
tumor = _donor(tmp_path, "loh.vcf", loh=True, role="tumor")
|
|
78
|
+
result = compare_samples(a, tumor)["germline"]
|
|
79
|
+
assert result["status"] == "compatible"
|
|
80
|
+
assert result["genotype_concordance"] == pytest.approx(2 / 3)
|
|
81
|
+
assert result["ibs0"] == 0
|
|
82
|
+
tumor.role = "normal"
|
|
83
|
+
assert compare_samples(a, tumor)["germline"]["status"] == "discordant"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_variant_only_tumors_cannot_match_donors_by_automatic_alt_sharing(tmp_path):
|
|
87
|
+
path = _vcf(tmp_path, "ascertained.vcf", ["a", "b"], [
|
|
88
|
+
_row(i, ["0/1:30:60", "1/1:30:60"][i % 2],
|
|
89
|
+
["1/1:30:60", "0/1:30:60"][i % 2]) for i in range(210)])
|
|
90
|
+
a, b = load_vcf_samples(path, kind="somatic", samples=[SampleSpec("a", role="tumor"), SampleSpec("b", role="tumor")])
|
|
91
|
+
result = compare_samples(a, b)["germline"]
|
|
92
|
+
assert result["ibs0"] == 0
|
|
93
|
+
assert result["status"] == "inconclusive"
|
|
94
|
+
assert "too_few_explicit_tumor_comparison_reference_calls" in result["reasons"]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@pytest.mark.parametrize("pattern", ["0/0", "0/1", "1/1", "./.", "0/."])
|
|
98
|
+
def test_uninformative_or_partial_calls_are_inconclusive(tmp_path, pattern):
|
|
99
|
+
path = _vcf(tmp_path, "sparse.vcf", ["a", "b"], [_row(i, pattern + ":30:60", pattern + ":30:60") for i in range(210)])
|
|
100
|
+
a, b = load_vcf_samples(path)
|
|
101
|
+
result = compare_samples(a, b)["germline"]
|
|
102
|
+
assert result["status"] == "inconclusive"
|
|
103
|
+
assert result["reasons"]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_two_alt_heterozygotes_do_not_fake_genotype_diversity(tmp_path):
|
|
107
|
+
rows = [_row(i, ["0/1:30:60", "1/2:30:60"][i % 2], alt="C,G") for i in range(210)]
|
|
108
|
+
sample = load_vcf_samples(_vcf(tmp_path, "heterozygotes.vcf", ["S"], rows))[0]
|
|
109
|
+
result = compare_samples(sample, sample)["germline"]
|
|
110
|
+
assert result["status"] == "inconclusive"
|
|
111
|
+
assert result["reasons"] == ["insufficient_genotype_diversity"]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_absent_records_not_reference_and_linked_sites_not_independent(tmp_path):
|
|
115
|
+
a = _donor(tmp_path)
|
|
116
|
+
b = load_vcf_samples(_vcf(tmp_path, "few.vcf", ["S"], [_row(1, "0/1:30:60")]))[0]
|
|
117
|
+
assert compare_samples(a, b)["germline"]["shared_snps"] == 1
|
|
118
|
+
rows = [_row(i, ["0/0:30:60", "0/1:30:60", "1/1:30:60"][i % 3]) for i in range(210)]
|
|
119
|
+
for i, row in enumerate(rows):
|
|
120
|
+
row[1] = 100 + i
|
|
121
|
+
b = load_vcf_samples(_vcf(tmp_path, "linked.vcf", ["S"], rows))[0]
|
|
122
|
+
result = compare_samples(b, b)["germline"]
|
|
123
|
+
assert result["status"] == "inconclusive"
|
|
124
|
+
assert result["genomic_bins"] == 1
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_alt_indexes_phase_and_chr_aliases_do_not_define_identity(tmp_path):
|
|
128
|
+
one = _vcf(tmp_path, "one.vcf", ["S"], [_row(1, "0|2:30:60", alt="C,G")])
|
|
129
|
+
two = _vcf(tmp_path, "two.vcf.gz", ["S"], [_row(1, "1/0:30:60", alt="G,C", chrom="chr1")], reference="hg19")
|
|
130
|
+
a, b = load_vcf_samples(one)[0], load_vcf_samples(two)[0]
|
|
131
|
+
assert a.snps == b.snps == {("1", 200001): ("A", ("A", "G"))}
|
|
132
|
+
assert compare_samples(a, b)["germline"]["genotype_concordance"] == 1
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_gvcf_blocks_and_unknown_alleles_are_not_imputed(tmp_path):
|
|
136
|
+
rows = [_row(1, "0/1:30:60", alt="C,<NON_REF>"),
|
|
137
|
+
_row(2, "0/2:30:60", alt="C,<NON_REF>"),
|
|
138
|
+
_row(3, "0/0:30:60", alt="<NON_REF>", info="END=800000"),
|
|
139
|
+
_row(4, "0/0:30:60", alt=".")]
|
|
140
|
+
s = load_vcf_samples(_vcf(tmp_path, "gvcf.vcf", ["S"], rows))[0]
|
|
141
|
+
assert s.snps == {("1", 200001): ("A", ("A", "C")), ("1", 800001): ("A", ("A", "A"))}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_filters_missing_quality_and_conflicting_duplicates(tmp_path):
|
|
145
|
+
rows = [_row(1, "0/1:30:60"), _row(1, "1/1:30:60"), _row(1, "0/1:30:60"),
|
|
146
|
+
_row(2, "0/1:2:60"), _row(3, "0/1:30:2"), _row(4, "0/1", fmt="GT"),
|
|
147
|
+
_row(5, "0/1:LowQual", fmt="GT:FT")]
|
|
148
|
+
rows.append(_row(6, "0/1:30:60"))
|
|
149
|
+
rows[-1][6] = "LowQual"
|
|
150
|
+
path = _vcf(tmp_path, "quality.vcf", ["S"], rows)
|
|
151
|
+
a = load_vcf_samples(path)[0]
|
|
152
|
+
assert a.snps == {("1", 200001): None, ("1", 800001): ("A", ("A", "C"))}
|
|
153
|
+
assert a.qc["conflicting_snp_loci"] == 1
|
|
154
|
+
assert a.qc["low_depth"] == a.qc["low_gq"] == a.qc["record_filter"] == a.qc["sample_filter"] == 1
|
|
155
|
+
strict = load_vcf_samples(path, config=SampleCheckConfig(require_quality=True))[0]
|
|
156
|
+
assert strict.qc["missing_quality"] == 1
|
|
157
|
+
assert strict.snps == {("1", 200001): None}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_genotype_independent_bounded_sketch_is_order_independent(tmp_path):
|
|
161
|
+
rows = [_row(i, ["0/0:30:60", "0/1:30:60", "1/1:30:60"][i % 3]) for i in range(300)]
|
|
162
|
+
config = SampleCheckConfig(max_snps=100)
|
|
163
|
+
a = load_vcf_samples(_vcf(tmp_path, "forward.vcf", ["S"], rows), config=config)[0]
|
|
164
|
+
b = load_vcf_samples(_vcf(tmp_path, "reverse.vcf", ["S"], reversed(rows)), config=config)[0]
|
|
165
|
+
assert a.snps == b.snps
|
|
166
|
+
assert len(a.snps) == 100
|
|
167
|
+
assert a.qc["snp_sketch_omissions"] == b.qc["snp_sketch_omissions"] == 200
|
|
168
|
+
assert compare_samples(a, b)["germline"]["status"] == "compatible"
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_reference_conflicts_and_assembly_mismatch(tmp_path):
|
|
172
|
+
a = _donor(tmp_path)
|
|
173
|
+
b = replace(a, assembly="GRCh38")
|
|
174
|
+
pair = compare_samples(a, b)
|
|
175
|
+
assert pair["germline"]["reasons"] == pair["somatic"]["reasons"] == ["assembly_mismatch"]
|
|
176
|
+
b = replace(a, snps={k: ("G", v[1]) for k, v in a.snps.items()})
|
|
177
|
+
result = compare_samples(a, b)["germline"]
|
|
178
|
+
assert result["reference_conflicts"] == 210
|
|
179
|
+
assert result["shared_snps"] == 0
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_somatic_branch_overlap_is_separate_from_donor_identity(tmp_path):
|
|
183
|
+
a = load_vcf_samples(_vcf(tmp_path, "a.vcf", ["T"], [_row(i, "0/1:30:60") for i in range(20)]), kind="somatic")[0]
|
|
184
|
+
b = load_vcf_samples(_vcf(tmp_path, "b.vcf", ["T"], [_row(i, "0/1:30:60") for i in range(10, 80)]), kind="somatic")[0]
|
|
185
|
+
result = compare_samples(a, b)
|
|
186
|
+
assert result["germline"]["status"] == "inconclusive"
|
|
187
|
+
somatic = result["somatic"]
|
|
188
|
+
assert somatic["status"] == "shared_somatic_support"
|
|
189
|
+
assert somatic["shared_variants"] == 10
|
|
190
|
+
assert somatic["fraction_a"] == .5
|
|
191
|
+
assert somatic["fraction_b"] == pytest.approx(1 / 7)
|
|
192
|
+
assert somatic["jaccard"] == .125
|
|
193
|
+
a.tumor_id, b.tumor_id = "first tumor", "second tumor"
|
|
194
|
+
assert compare_samples(a, b)["flags"] == ["unexpected_tumor_overlap"]
|
|
195
|
+
a.tumor_id = b.tumor_id = "same tumor"
|
|
196
|
+
b.somatic.clear()
|
|
197
|
+
b.somatic.update({("small", "2", i, "A", "C"): None for i in range(20)})
|
|
198
|
+
result = compare_samples(a, b)
|
|
199
|
+
assert result["somatic"]["status"] == "low_overlap"
|
|
200
|
+
assert result["flags"] == ["expected_tumor_low_overlap"]
|
|
201
|
+
assert not result["identity_conflict"]
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def test_same_tumor_expectation_implies_same_donor(tmp_path):
|
|
205
|
+
a = _donor(tmp_path, "a.vcf", role="tumor", tumor_id="tumor-A")
|
|
206
|
+
b = _donor(tmp_path, "b.vcf", swapped=True, role="tumor", tumor_id="tumor-A")
|
|
207
|
+
assert compare_samples(a, b)["identity_conflict"]
|
|
208
|
+
a.donor_id, b.donor_id = "donor-A", "donor-B"
|
|
209
|
+
assert "same_tumor_has_different_donor_labels" in compare_samples(a, b)["flags"]
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def test_mixed_tumor_normal_uses_germline_and_somatic_evidence(tmp_path):
|
|
213
|
+
rows = [_row(i, ["0/0:30:60", "0/1:30:60", "1/1:30:60"][i % 3],
|
|
214
|
+
["0/0:30:60", "0/1:30:60", "1/1:30:60"][i % 3]) for i in range(210)]
|
|
215
|
+
rows += [_row(i, "0/1:30:60", "0/0:30:60") for i in range(210, 230)]
|
|
216
|
+
path = _vcf(tmp_path, "mixed.vcf", ["T", "N"], rows,
|
|
217
|
+
metadata="##tumor_sample=T\n##normal_sample=N\n")
|
|
218
|
+
tumor, normal = load_vcf_samples(path, kind="mixed")
|
|
219
|
+
assert tumor.normal_sample == "N"
|
|
220
|
+
assert len(tumor.somatic) == 20
|
|
221
|
+
assert not normal.somatic
|
|
222
|
+
assert tumor.qc["paired_normal_contrast"] == 20
|
|
223
|
+
pair = compare_samples(tumor, normal)
|
|
224
|
+
assert pair["paired_tumor_normal"]
|
|
225
|
+
assert pair["germline"]["status"] == "compatible"
|
|
226
|
+
assert pair["somatic"]["status"] == "inconclusive"
|
|
227
|
+
# Selecting just the tumor still reads its matched normal column.
|
|
228
|
+
selected = load_vcf_samples(path, kind="mixed", samples=[SampleSpec("T")])[0]
|
|
229
|
+
assert selected.somatic == tumor.somatic
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def test_no_gt_somatic_depths_missing_normal_and_vaf_correlation(tmp_path):
|
|
233
|
+
rows = [_row(i, "%d,%d" % (30 - i, i), "30,0", fmt="AD") for i in range(3, 20)]
|
|
234
|
+
rows += [_row(30, "20,10", ".", fmt="AD"), _row(31, "20,10", "20,10", fmt="AD")]
|
|
235
|
+
path = _vcf(tmp_path, "depth.vcf", ["T", "N"], rows)
|
|
236
|
+
specs = [SampleSpec("T", role="tumor"), SampleSpec("N", role="normal")]
|
|
237
|
+
tumor, normal = load_vcf_samples(path, kind="mixed", samples=specs)
|
|
238
|
+
assert len(tumor.somatic) == 17
|
|
239
|
+
assert not tumor.snps and not normal.snps
|
|
240
|
+
assert compare_samples(tumor, normal)["germline"]["status"] == "inconclusive"
|
|
241
|
+
result = compare_samples(tumor, tumor)["somatic"]
|
|
242
|
+
assert result["vaf_correlation"] == pytest.approx(1)
|
|
243
|
+
assert result["vaf_pairs"] == 17
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def test_mixed_unpaired_needs_somatic_flag_and_gt_takes_precedence(tmp_path):
|
|
247
|
+
rows = [_row(1, "0/1:20,10", fmt="GT:AD"),
|
|
248
|
+
_row(2, "0/1:20,10", fmt="GT:AD", info="SOMATIC"),
|
|
249
|
+
_row(3, "0/0:20,10", fmt="GT:AD", info="SOMATIC")]
|
|
250
|
+
sample = load_vcf_samples(_vcf(tmp_path, "mixed.vcf", ["T"], rows), kind="mixed",
|
|
251
|
+
samples=[SampleSpec("T", role="tumor")])[0]
|
|
252
|
+
assert list(sample.somatic) == [("small", "1", 400001, "A", "C")]
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_sv_normalization_deduplicates_reciprocal_breakends(tmp_path):
|
|
256
|
+
rows = [["1", 101, "b1", "A", "A[2:201[", ".", "PASS", ".", "GT:DP:GQ", "0/1:30:60"],
|
|
257
|
+
["2", 201, "b2", "C", "]1:101]C", ".", "PASS", ".", "GT:DP:GQ", "0/1:30:60"],
|
|
258
|
+
_row(2, "0/1:30:60", alt="<DEL>", info="END=400100;IMPRECISE"),
|
|
259
|
+
_row(3, "0/1:30:60", alt="<INS>", info="SVLEN=200")]
|
|
260
|
+
sample = load_vcf_samples(_vcf(tmp_path, "sv.vcf", ["T"], rows), kind="somatic")[0]
|
|
261
|
+
assert len(sample.somatic) == 1
|
|
262
|
+
assert sample.qc["duplicate_somatic_alleles"] == 1
|
|
263
|
+
assert sample.qc["unsupported_or_imprecise_somatic_alleles"] == 2
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@pytest.mark.parametrize("call,fmt", [("0/2", "GT"), ("9/.", "GT"), ("0/1:NaN", "GT:DP"),
|
|
267
|
+
("0/1:-1", "GT:DP"), ("10,2,3", "AD"),
|
|
268
|
+
("1.2", "AF"), ("0/1:30:extra", "GT:DP")])
|
|
269
|
+
def test_malformed_evidence_is_an_error_with_line_number(tmp_path, call, fmt):
|
|
270
|
+
path = _vcf(tmp_path, "invalid.vcf", ["S"], [_row(1, call, fmt=fmt)])
|
|
271
|
+
with pytest.raises(ValueError, match=r"invalid.vcf:\d+:"):
|
|
272
|
+
load_vcf_samples(path)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def test_roles_builds_and_sample_selection_are_explicit(tmp_path):
|
|
276
|
+
path = _vcf(tmp_path, "multi.vcf", ["tumor", "normal"], [])
|
|
277
|
+
with pytest.raises(ValueError, match="Declare tumor/normal"):
|
|
278
|
+
load_vcf_samples(path, kind="somatic")
|
|
279
|
+
with pytest.raises(ValueError, match="contradicts"):
|
|
280
|
+
load_vcf_samples(path, assembly="GRCh38")
|
|
281
|
+
with pytest.raises(ValueError, match="Unknown VCF sample"):
|
|
282
|
+
load_vcf_samples(path, samples=[SampleSpec("missing")])
|
|
283
|
+
path = _vcf(tmp_path, "no-build.vcf", ["S"], [], reference=None)
|
|
284
|
+
with pytest.raises(ValueError, match="Declare assembly"):
|
|
285
|
+
load_vcf_samples(path)
|
|
286
|
+
assert load_vcf_samples(path, assembly="hg38")[0].assembly == "GRCh38"
|
|
287
|
+
path = _vcf(tmp_path, "duplicate.vcf", ["S", "S"], [])
|
|
288
|
+
with pytest.raises(ValueError, match="unique sample"):
|
|
289
|
+
load_vcf_samples(path)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def test_multiallelic_somatic_indexes_and_minimal_indel_representation(tmp_path):
|
|
293
|
+
one = [_row(1, "0/2:10,0,5", alt="C,G", fmt="GT:AD"),
|
|
294
|
+
["1", 99, ".", "GAT", "GA", ".", "PASS", ".", "GT:DP:GQ", "0/1:30:60"]]
|
|
295
|
+
two = [_row(1, "1/0:10,5,0", alt="G,C", fmt="GT:AD"),
|
|
296
|
+
["1", 100, ".", "AT", "A", ".", "PASS", ".", "GT:DP:GQ", "0/1:30:60"]]
|
|
297
|
+
a = load_vcf_samples(_vcf(tmp_path, "one.vcf", ["T"], one), kind="somatic")[0]
|
|
298
|
+
b = load_vcf_samples(_vcf(tmp_path, "two.vcf", ["T"], two), kind="somatic")[0]
|
|
299
|
+
assert a.somatic == b.somatic == {("small", "1", 200001, "A", "G"): 1 / 3,
|
|
300
|
+
("small", "1", 101, "T", ""): None}
|
|
301
|
+
assert compare_samples(a, b)["somatic"]["shared_variants"] == 2
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_conflicting_vafs_and_missing_allele_depths_do_not_gain_evidence(tmp_path):
|
|
305
|
+
rows = [_row(1, "0/1:20,10", fmt="GT:AD"), _row(1, "0/1:10,20", fmt="GT:AD"),
|
|
306
|
+
_row(1, "0/1:20,10", fmt="GT:AD"), _row(2, ".:.,5", fmt="GT:AD")]
|
|
307
|
+
a = load_vcf_samples(_vcf(tmp_path, "repeated.vcf", ["T"], rows), kind="somatic")[0]
|
|
308
|
+
assert a.somatic == {("small", "1", 200001, "A", "C"): None}
|
|
309
|
+
assert a.qc["duplicate_somatic_alleles"] == 2
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def test_constant_vafs_have_no_correlation_even_with_floating_point_roundoff(tmp_path):
|
|
313
|
+
rows = [_row(i, "0/1:20,10", fmt="GT:AD") for i in range(20)]
|
|
314
|
+
sample = load_vcf_samples(_vcf(tmp_path, "constant.vcf", ["T"], rows), kind="somatic")[0]
|
|
315
|
+
result = compare_samples(sample, sample)["somatic"]
|
|
316
|
+
assert result["vaf_pairs"] == 20
|
|
317
|
+
assert result["vaf_correlation"] is None
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def test_multiple_normals_require_pairing_and_limits_are_explicit(tmp_path):
|
|
321
|
+
path = _vcf(tmp_path, "multi.vcf", ["T", "N1", "N2"], [])
|
|
322
|
+
specs = [SampleSpec("T", role="tumor"), SampleSpec("N1", role="normal"), SampleSpec("N2", role="normal")]
|
|
323
|
+
with pytest.raises(ValueError, match="Multiple normals"):
|
|
324
|
+
load_vcf_samples(path, kind="mixed", samples=specs)
|
|
325
|
+
specs[0] = replace(specs[0], normal_sample="N2")
|
|
326
|
+
assert load_vcf_samples(path, kind="mixed", samples=specs)[0].normal_sample == "N2"
|
|
327
|
+
path = _vcf(tmp_path, "limit.vcf", ["T"], [_row(i, "0/1:30:60") for i in range(2)])
|
|
328
|
+
with pytest.raises(ValueError, match="max_somatic_variants exceeded"):
|
|
329
|
+
load_vcf_samples(path, kind="somatic", config=SampleCheckConfig(max_somatic_variants=1))
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
@pytest.mark.parametrize("options", [{"min_depth": -1}, {"max_snps": 10}, {"min_shared_snps": True},
|
|
333
|
+
{"min_somatic_overlap": float("nan")}, {"require_quality": "yes"},
|
|
334
|
+
{"compatible_concordance": .5}, {"max_compatible_ibs0": .5}])
|
|
335
|
+
def test_invalid_config(options):
|
|
336
|
+
with pytest.raises(ValueError):
|
|
337
|
+
SampleCheckConfig(**options)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def test_manifest_cli_json_tsv_and_mismatch_exit(tmp_path):
|
|
341
|
+
_donor(tmp_path, "a.vcf")
|
|
342
|
+
_donor(tmp_path, "b.vcf", swapped=True)
|
|
343
|
+
manifest = tmp_path / "samples.tsv"
|
|
344
|
+
manifest.write_text("path\tsample\trole\tdonor_id\tlabel\n"
|
|
345
|
+
"a.vcf\tS\tnormal\tpatient\ta\n"
|
|
346
|
+
"b.vcf\tS\tnormal\tpatient\tb\n")
|
|
347
|
+
out, table = tmp_path / "report.json", tmp_path / "pairs.tsv"
|
|
348
|
+
completed = subprocess.run([sys.executable, "-m", "varcode.cli.main", "check-samples", "--manifest", str(manifest),
|
|
349
|
+
"--json", str(out), "--tsv", str(table), "--fail-on-mismatch"],
|
|
350
|
+
text=True, capture_output=True)
|
|
351
|
+
assert completed.returncode == 1, completed.stderr
|
|
352
|
+
assert not completed.stdout
|
|
353
|
+
report = json.loads(out.read_text())
|
|
354
|
+
assert report["identity_conflicts"] == 1
|
|
355
|
+
assert report["samples"][0]["path"] == str(tmp_path / "a.vcf")
|
|
356
|
+
assert "expected_donor_mismatch" in table.read_text()
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def test_cli_stdout_inconclusive_and_input_errors(tmp_path, capsys):
|
|
360
|
+
path = _vcf(tmp_path, "empty.vcf", ["a", "b"], [])
|
|
361
|
+
assert main(["check-samples", "--germline", str(path), "--fail-on-mismatch"]) == 0
|
|
362
|
+
captured = capsys.readouterr()
|
|
363
|
+
assert json.loads(captured.out)["pairs"][0]["germline"]["status"] == "inconclusive"
|
|
364
|
+
with pytest.raises(SystemExit) as error:
|
|
365
|
+
main(["check-samples", "--germline", str(path), "--json", str(path)])
|
|
366
|
+
assert error.value.code == 2
|
|
367
|
+
assert path.read_text().startswith("##fileformat")
|
|
368
|
+
with pytest.raises(SystemExit) as error:
|
|
369
|
+
main(["check-samples", "--germline", str(path), "--germline", str(path)])
|
|
370
|
+
assert error.value.code == 2
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def test_annotation_cli_dispatch_preserves_existing_arguments(monkeypatch):
|
|
374
|
+
from varcode.cli import effects_script
|
|
375
|
+
seen = []
|
|
376
|
+
monkeypatch.setattr(effects_script, "main", lambda args: seen.extend(args))
|
|
377
|
+
main(["--vcf", "original.vcf", "--genome", "GRCh38"])
|
|
378
|
+
assert seen == ["--vcf", "original.vcf", "--genome", "GRCh38"]
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def test_no_reference_data_access_for_small_variant_checks(tmp_path, monkeypatch):
|
|
382
|
+
import varcode.reference
|
|
383
|
+
def forbidden(*args, **kwargs):
|
|
384
|
+
raise AssertionError("Sample checks must not resolve annotation releases")
|
|
385
|
+
monkeypatch.setattr(varcode.reference, "infer_genome", forbidden)
|
|
386
|
+
assert _donor(tmp_path).snps
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Generated regression data for #502; no source files or reference downloads."""
|
|
2
|
+
|
|
3
|
+
from io import StringIO
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from varcode import Variant, load_vcf
|
|
12
|
+
from varcode.vcf_output import variants_to_vcf
|
|
13
|
+
from varcode.vcf_parsing import VCFHeader
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _variant(pos=100, alt="C"):
|
|
17
|
+
return Variant("1", pos, "A", alt, genome=81)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _export(variants, metadata, **kwargs):
|
|
21
|
+
out = StringIO()
|
|
22
|
+
variants_to_vcf(variants, metadata, out=out, **kwargs)
|
|
23
|
+
return out.getvalue()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _reload(tmp_path, text):
|
|
27
|
+
path = tmp_path / "export.vcf"
|
|
28
|
+
path.write_text(text)
|
|
29
|
+
return load_vcf(str(path), genome=81)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_samples_and_fields_are_selected_by_name(tmp_path):
|
|
33
|
+
a, b = _variant(2), _variant(10)
|
|
34
|
+
metadata = {
|
|
35
|
+
a: {"sample_info": {"tumor": {"GT": "0/1", "DP": 11, "AD": [6, 5]},
|
|
36
|
+
"normal": {"AD": [22, 0], "DP": 22, "GT": "0/0"}}},
|
|
37
|
+
b: {"sample_info": {"normal": {"GT": "0/0", "DP": 33, "AD": [33, 0]},
|
|
38
|
+
"tumor": {"DP": 44, "AD": [20, 24], "GT": "0/1"}}},
|
|
39
|
+
}
|
|
40
|
+
text = _export(iter([b, a]), metadata)
|
|
41
|
+
rows = [line.split("\t") for line in text.splitlines() if not line.startswith("##")]
|
|
42
|
+
assert rows[0][9:] == ["normal", "tumor"]
|
|
43
|
+
assert [r[1] for r in rows[1:]] == ["2", "10"]
|
|
44
|
+
assert all(r[8].split(":")[0] == "GT" for r in rows[1:])
|
|
45
|
+
loaded = _reload(tmp_path, text)
|
|
46
|
+
for variant in loaded:
|
|
47
|
+
assert loaded.metadata[variant]["sample_info"] == metadata[variant]["sample_info"]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_union_of_samples_and_format_fields_preserves_missing_values(tmp_path):
|
|
51
|
+
a, b, c = [_variant(p) for p in (2, 10, 20)]
|
|
52
|
+
metadata = {
|
|
53
|
+
a: {"sample_info": {"tumor": {"GT": "0|1", "AD": [None, 8]},
|
|
54
|
+
"normal": {"GT": "0/0", "DP": 30}}},
|
|
55
|
+
b: {"sample_info": {"normal": {"GT": "0/1", "DP": 20}}},
|
|
56
|
+
c: {},
|
|
57
|
+
}
|
|
58
|
+
loaded = _reload(tmp_path, _export([a, b, c], metadata))
|
|
59
|
+
assert loaded.samples == ["normal", "tumor"]
|
|
60
|
+
assert loaded.metadata[a]["sample_info"]["tumor"] == {"GT": "0|1", "AD": [None, 8], "DP": None}
|
|
61
|
+
assert loaded.metadata[a]["sample_info"]["normal"] == {"GT": "0/0", "AD": None, "DP": 30}
|
|
62
|
+
assert loaded.metadata[b]["sample_info"]["tumor"] == {"GT": ".", "DP": None}
|
|
63
|
+
row = [r for r in _export([a, b, c], metadata).splitlines() if r.startswith("1\t20\t")][0]
|
|
64
|
+
assert row.split("\t")[8:] == [".", ".", "."]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _multiallelic(tmp_path, identifier="."):
|
|
68
|
+
path = tmp_path / "source.vcf"
|
|
69
|
+
path.write_text(
|
|
70
|
+
'##fileformat=VCFv4.2\n'
|
|
71
|
+
'##INFO=<ID=AC,Number=A,Type=Integer,Description="Counts">\n'
|
|
72
|
+
'##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">\n'
|
|
73
|
+
'##FORMAT=<ID=AD,Number=R,Type=Integer,Description="Depths">\n'
|
|
74
|
+
'##FORMAT=<ID=PL,Number=G,Type=Integer,Description="Likelihoods">\n'
|
|
75
|
+
'#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\ttumor\tnormal\n'
|
|
76
|
+
'1\t100\t' + identifier + '\tA\tG,C\t.\tPASS\tAC=1,1\tGT:AD:PL\t0|2:20,0,10:0,1,2,3,4,5\t0/1:15,8,0:5,4,3,2,1,0\n'
|
|
77
|
+
)
|
|
78
|
+
return load_vcf(str(path), genome=81), VCFHeader.from_path(str(path))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize("identifier", [".", "rs123"])
|
|
82
|
+
def test_multiallelic_order_and_cardinality_survive_reordered_input(tmp_path, identifier):
|
|
83
|
+
variants, header = _multiallelic(tmp_path, identifier)
|
|
84
|
+
text = _export(sorted(variants, key=lambda v: v.alt), variants.metadata, header=header)
|
|
85
|
+
row, = [r for r in text.splitlines() if not r.startswith("#")]
|
|
86
|
+
assert row.split("\t")[4] == "G,C"
|
|
87
|
+
assert 'ID=AC,Number=A,Type=Integer' in text
|
|
88
|
+
loaded = _reload(tmp_path, text)
|
|
89
|
+
for v in loaded:
|
|
90
|
+
for sample in ("tumor", "normal"):
|
|
91
|
+
assert dict(loaded.metadata[v]["sample_info"][sample]) == dict(
|
|
92
|
+
variants.metadata[v]["sample_info"][sample])
|
|
93
|
+
assert loaded.metadata[v]["info"] == variants.metadata[v]["info"]
|
|
94
|
+
assert [v.alt for v in loaded.for_sample("tumor")] == ["C"]
|
|
95
|
+
assert [v.alt for v in loaded.for_sample("normal")] == ["G"]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_filtered_multiallelic_group_is_rejected_before_writing(tmp_path):
|
|
99
|
+
variants, _ = _multiallelic(tmp_path)
|
|
100
|
+
out = StringIO()
|
|
101
|
+
with pytest.raises(ValueError, match="incomplete source ALT list"):
|
|
102
|
+
variants_to_vcf([variants[0]], variants.metadata, out=out)
|
|
103
|
+
assert out.getvalue() == ""
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_old_multiallelic_metadata_is_rejected():
|
|
107
|
+
v = _variant()
|
|
108
|
+
with pytest.raises(ValueError, match="source ALT list"):
|
|
109
|
+
_export([v], {v: {"alt_allele_index": 1, "sample_info": {"tumor": {"GT": "0/2"}}}})
|
|
110
|
+
with pytest.raises(ValueError, match="unavailable ALT"):
|
|
111
|
+
_export([v], {v: {"sample_info": {"tumor": {"GT": "0/2"}}}})
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_conflicting_multiallelic_metadata_is_rejected(tmp_path):
|
|
115
|
+
variants, _ = _multiallelic(tmp_path)
|
|
116
|
+
metadata = {v: dict(variants.metadata[v]) for v in variants}
|
|
117
|
+
metadata[variants[0]]["qual"] = 42
|
|
118
|
+
with pytest.raises(ValueError, match="Conflicting source metadata"):
|
|
119
|
+
_export(variants, metadata)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_missing_info_and_sample_filters_are_valid_vcf(tmp_path):
|
|
123
|
+
v = _variant()
|
|
124
|
+
metadata = {v: {"info": {"X": [1, None], "SOMATIC": False}, "sample_info": {
|
|
125
|
+
"tumor": {"GT": "0/1", "FT": ["LowDepth", "LowGQ"]},
|
|
126
|
+
"normal": {"GT": "0/0", "FT": []}}}}
|
|
127
|
+
text = _export([v], metadata)
|
|
128
|
+
assert "X=1,." in text
|
|
129
|
+
assert "LowDepth;LowGQ" in text
|
|
130
|
+
loaded = _reload(tmp_path, text)
|
|
131
|
+
assert loaded.metadata[v]["info"] == {"X": [1, None]}
|
|
132
|
+
assert loaded.metadata[v]["sample_info"] == metadata[v]["sample_info"]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_empty_input_and_runtime_stdout(capsys):
|
|
136
|
+
variants_to_vcf(iter([]), {})
|
|
137
|
+
assert capsys.readouterr().out == (
|
|
138
|
+
"##fileformat=VCFv4.2\n#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_hash_seed_does_not_change_sample_columns():
|
|
142
|
+
script = '''
|
|
143
|
+
from varcode import Variant
|
|
144
|
+
from varcode.vcf_output import variants_to_vcf
|
|
145
|
+
v = Variant("1", 100, "A", "C", genome=81)
|
|
146
|
+
values = {"tumor": "0/1", "normal": "0/0", "replicate": "1/1"}
|
|
147
|
+
metadata = {v: {"sample_info": {s: {"GT": values[s]} for s in set(values)}}}
|
|
148
|
+
variants_to_vcf([v], metadata)
|
|
149
|
+
'''
|
|
150
|
+
outputs = [subprocess.check_output(
|
|
151
|
+
[sys.executable, "-c", script], text=True,
|
|
152
|
+
cwd=Path(__file__).resolve().parents[1],
|
|
153
|
+
env=dict(os.environ, PYTHONHASHSEED=str(seed))) for seed in (1, 2, 42)]
|
|
154
|
+
assert len(set(outputs)) == 1
|
|
155
|
+
assert outputs[0].splitlines()[-1].split("\t")[9:] == ["0/0", "1/1", "0/1"]
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@pytest.mark.parametrize("index", [0, 1])
|
|
159
|
+
def test_indexed_legacy_metadata_requires_source_alleles(index):
|
|
160
|
+
v = _variant()
|
|
161
|
+
with pytest.raises(ValueError, match="reload the VCF"):
|
|
162
|
+
_export([v], {v: {"alt_allele_index": index, "sample_info": {"s": {"GT": "0/1"}}}})
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_likelihoods_must_agree_with_allele_count_and_ploidy():
|
|
166
|
+
v = _variant()
|
|
167
|
+
with pytest.raises(ValueError, match="ALT/ploidy"):
|
|
168
|
+
_export([v], {v: {"sample_info": {"s": {"GT": "0/1", "PL": [0, 1, 2, 3, 4, 5]}}}})
|
|
@@ -126,16 +126,15 @@ def test_same_samples_produce_samples():
|
|
|
126
126
|
for d in reparsed_metadata.values())
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
def
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Ensures that, if a set of variants have different samples, the reparsed
|
|
133
|
-
collection will not output any samples.
|
|
134
|
-
|
|
135
|
-
See `vcf_output.py` for details as to why this is the way it's done for now.
|
|
136
|
-
"""
|
|
137
|
-
(_, reparsed_variants) = _do_roundtrip_test(
|
|
129
|
+
def test_different_samples_are_preserved():
|
|
130
|
+
variants, reparsed = _do_roundtrip_test(
|
|
138
131
|
['different-samples.1.vcf', 'different-samples.2.vcf'])
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
assert
|
|
132
|
+
original = _merge_metadata_naive(variants)
|
|
133
|
+
exported = _merge_metadata_naive(reparsed)
|
|
134
|
+
assert reparsed.samples == ["metastasis", "normal"]
|
|
135
|
+
for variant in variants:
|
|
136
|
+
for sample, fields in original[variant]["sample_info"].items():
|
|
137
|
+
assert exported[variant]["sample_info"][sample]["GT"] == fields["GT"]
|
|
138
|
+
absent = set(reparsed.samples) - set(original[variant]["sample_info"])
|
|
139
|
+
for sample in absent:
|
|
140
|
+
assert exported[variant]["sample_info"][sample]["GT"] == "."
|
|
@@ -108,9 +108,15 @@ from .effects import (
|
|
|
108
108
|
GermlineAlleleOverlap,
|
|
109
109
|
)
|
|
110
110
|
from .version import __version__
|
|
111
|
+
from .sample_identity import (
|
|
112
|
+
SampleCheckConfig, SampleSpec, SampleFingerprint,
|
|
113
|
+
load_vcf_samples, compare_samples, check_sample_identity,
|
|
114
|
+
)
|
|
111
115
|
|
|
112
116
|
|
|
113
117
|
__all__ = [
|
|
118
|
+
"SampleCheckConfig", "SampleSpec", "SampleFingerprint",
|
|
119
|
+
"load_vcf_samples", "compare_samples", "check_sample_identity",
|
|
114
120
|
"__version__",
|
|
115
121
|
|
|
116
122
|
# basic classes
|