Effects API¶
See effect annotation for result access and the effect catalog for individual consequence classes.
Effects¶
varcode.MutationEffect(variant)
¶
Bases: Serializable
Base class for mutation effects.
Source code in varcode/effects/effect_classes.py
short_description: str
property
¶
A short but human-readable description of the effect. Defaults to class name for most of the non-coding effects, but is more informative for coding ones.
orf
property
¶
The selected reference ORF, or None for ordinary annotation.
reference_transcript
property
¶
Original annotated RNA, including when an extra coding frame is used.
original_protein_sequence: str | None
property
¶
Pre-somatic protein: the assembled patient baseline when supplied, otherwise the reference protein. None means unavailable.
mutant_protein_sequence: str | None
property
writable
¶
Protein from the assembled transcript, when one is available.
baseline_transcript: MutantTranscript | None = None
class-attribute
instance-attribute
¶
The actual pre-somatic transcript used for a composed comparison.
None means no baseline model was retained. A model whose sequence is None instead records an explicitly unavailable product. The model uses the same MutantTranscript representation as the post-somatic product.
__reduce__()
¶
Pickle and copy through to_dict(), plus the attributes set after construction.
Source code in varcode/effects/effect_classes.py
__lt__(other)
¶
Effects are ordered by their associated variants, which have comparison implement in terms of their chromosomal locations.
format_short_description(*, deletion_notation: Literal['sequence', 'range'] = 'sequence') -> str
¶
Render the short description with a protein deletion display choice.
| PARAMETER | DESCRIPTION |
|---|---|
deletion_notation
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A display label. This does not change the effect or its archive. |
Source code in varcode/effects/effect_classes.py
varcode.NonsilentCodingMutation(variant, transcript, aa_mutation_start_offset, aa_mutation_end_offset, aa_ref)
¶
Bases: CodingMutation
All coding mutations other than silent codon substitutions
variant : Variant
transcript : Transcript
aa_mutation_start_offset : int Offset of first modified amino acid in protein (starting from 0)
aa_mutation_end_offset : int Offset after last mutated amino acid (half-open coordinates)
aa_ref : str Amino acid string of what used to be at aa_mutation_start_offset in the wildtype (unmutated) protein.
Source code in varcode/effects/effect_classes.py
varcode.MultiOutcomeEffect(variant)
¶
Bases: MutationEffect
Marker base class for effects that represent a set of plausible outcomes rather than a single deterministic effect.
Subclasses must expose:
- :attr:
candidates— tuple of :class:~varcode.effect_candidates.EffectCandidateobjects in producer order. Each entry pairs an inner :class:MutationEffect(concrete or placeholder) with its provenance —source(producer) andevidencedict. The :attr:effectshelper unwraps to the inner Effects when callers don't need provenance. - :attr:
priority_class— effect class whose priority this set adopts (read by :func:varcode.effects.effect_priority).
Downstream consumers filter for multi-outcome results with
isinstance(effect, MultiOutcomeEffect), so new wrappers (RNA
evidence #259, germline-aware #268, SV-at-breakpoint) implement
the same protocol uniformly (#382).
External integrations (RNA evidence, SpliceAI scoring, etc.)
attach extra candidates post-hoc via the _extra_candidates
slot — subclasses that override :attr:candidates must include
those extras in their returned tuple. The
:meth:_combine_with_extra_candidates helper does the right
thing.
Picking the candidate
Two orthogonal "best candidate" notions are available; pick the one that matches your question:
-
Most likely: the first candidate after producer ordering. Producers preserve their own deterministic order. :attr:
most_likely_candidatereturns the wrapped :class:EffectCandidate(provenance + inner effect); :attr:most_likely_effectreturns just the inner :class:MutationEffect. Always equal tocandidates[0]/effects[0]. -
Highest priority: top by varcode's effect-priority ordering (see :func:
~varcode.effects.effect_priority) — the most protein-disruptive candidate regardless of producer order. :attr:highest_priority_candidateand :attr:highest_priority_effectare the analogous accessors. Use this for clinical / functional filtering ("flag if any candidate is at least a frameshift"), since a disruptive candidate sitting behind a less-disruptive primary candidate should still light up.
The two coincide when producer order and priority ranking agree, which is common but not guaranteed. Pick consciously.
Source code in varcode/effects/effect_classes.py
effects
property
¶
Tuple of inner :class:MutationEffect objects, in
:attr:candidates order. Convenience for callers that don't
need per-candidate provenance — equivalent to
tuple(c.effect for c in self.candidates).
most_likely_candidate
property
¶
The first :class:EffectCandidate in producer order.
Pairs the inner effect with its source / evidence
provenance.
For just the inner :class:MutationEffect, use
:attr:most_likely_effect. For the most protein-disruptive
candidate (independent of producer order), use
:attr:highest_priority_candidate.
most_likely_effect
property
¶
The :class:MutationEffect of :attr:most_likely_candidate.
Equivalent to most_likely_candidate.effect /
effects[0] — given here so callers that don't need
provenance don't have to reach through the wrapper.
highest_priority_candidate
property
¶
The :class:EffectCandidate whose inner effect has the
highest :func:~varcode.effects.effect_priority (most
protein-disruptive). Pure priority ranking — producer order
deliberately doesn't factor in, so a frameshift sitting
behind a less-disruptive primary candidate still surfaces
here.
Ties on priority resolve to the first matching entry of
:attr:candidates, preserving the subclass's candidate order.
Behavior is deterministic.
highest_priority_effect
property
¶
The inner :class:MutationEffect of
:attr:highest_priority_candidate. Use when you want the
worst-case effect for clinical / functional filtering and
don't need provenance.
varcode.EffectCollection(effects, distinct=False, sort_key=None, sources=None, annotator=None, annotator_version=None, annotated_at=None)
¶
Bases: Collection
Collection of MutationEffect objects and helpers for grouping or filtering them.
| PARAMETER | DESCRIPTION |
|---|---|
effects
|
Collection of any class which is compatible with the sort key
TYPE:
|
distinct
|
Only keep distinct entries or allow duplicates.
TYPE:
|
sort_key
|
Function which maps each element to a sorting criterion.
If None (the default), effects are sorted by priority with
the most severe effects first. Pass an explicit sort_key to
override this behaviour, or
TYPE:
|
sources
|
Set of files from which this collection was generated.
TYPE:
|
annotator
|
Name of the :class:
TYPE:
|
annotator_version
|
Version string of the annotator (typically the varcode
version for built-in annotators).
TYPE:
|
annotated_at
|
ISO-8601 UTC timestamp recording when the annotation ran.
Populated by :func:
TYPE:
|
Source code in varcode/effects/effect_collection.py
orf_annotations
property
¶
Detailed native annotations for the extra ORF effects in this collection.
to_proteome(*, sample_id=None, run_id=None)
¶
Export ordinary and ncORF outcomes to ORFdata's shared Proteome.
All supplied alternatives and omitted outcomes are retained. Requires
the optional orf dependency. See :func:varcode.to_proteome for
the source identity, reference and offline provenance contracts.
Source code in varcode/effects/effect_collection.py
gene_counts()
¶
Returns number of elements overlapping each gene name. Expects the derived class (VariantCollection or EffectCollection) to have an implementation of groupby_gene_name.
Source code in varcode/effects/effect_collection.py
filter_by_transcript_expression(transcript_expression_dict, min_expression_value=0.0)
¶
Filters effects to those which have an associated transcript whose expression value in the transcript_expression_dict argument is greater than min_expression_value.
| PARAMETER | DESCRIPTION |
|---|---|
transcript_expression_dict
|
Dictionary mapping Ensembl transcript IDs to expression estimates (either FPKM or TPM)
TYPE:
|
min_expression_value
|
Threshold above which we'll keep an effect in the result collection
TYPE:
|
Source code in varcode/effects/effect_collection.py
filter_by_gene_expression(gene_expression_dict, min_expression_value=0.0)
¶
Filters effects to those which have an associated gene whose expression value in the gene_expression_dict argument is greater than min_expression_value.
| PARAMETER | DESCRIPTION |
|---|---|
gene_expression_dict
|
Dictionary mapping Ensembl gene IDs to expression estimates (either FPKM or TPM)
TYPE:
|
min_expression_value
|
Threshold above which we'll keep an effect in the result collection
TYPE:
|
Source code in varcode/effects/effect_collection.py
filter_by_effect_priority(min_priority_class)
¶
Create a new EffectCollection containing only effects whose priority falls below the given class.
Source code in varcode/effects/effect_collection.py
drop_silent_and_noncoding(keep_unresolved: bool = True) -> EffectCollection
¶
Keep effects with a protein-changing candidate or unresolved SV outcome.
| PARAMETER | DESCRIPTION |
|---|---|
keep_unresolved
|
Keep effects whose protein-change status is None (default True). False requires a positive prediction of protein change. Candidate sets are retained intact if any alternative qualifies; their order and provenance are unchanged.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectCollection
|
Filtered collection retaining complete qualifying outcome sets. |
Source code in varcode/effects/effect_collection.py
detailed_string()
¶
Create a long string with all transcript effects for each mutation, grouped by gene (if a mutation affects multiple genes).
Source code in varcode/effects/effect_collection.py
top_priority_effect() -> MutationEffect
¶
Select one effect using Varcode's severity and transcript heuristics.
| RETURNS | DESCRIPTION |
|---|---|
MutationEffect
|
Selected effect, retaining complete splice outcome sets. This is
a ranking summary, not evidence that the selected transcript or
outcome is expressed. See :func: |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
The collection is empty. This method does not synthesize an Intergenic effect for an empty or filtered collection. |
Source code in varcode/effects/effect_collection.py
top_priority_effect_per_variant()
¶
Highest priority effect for each unique variant
Source code in varcode/effects/effect_collection.py
top_priority_effect_per_transcript_id()
¶
Highest priority effect for each unique transcript ID
Source code in varcode/effects/effect_collection.py
top_priority_effect_per_gene_id()
¶
Highest priority effect for each unique gene ID
Source code in varcode/effects/effect_collection.py
effect_expression(expression_levels)
¶
| PARAMETER | DESCRIPTION |
|---|---|
expression_levels
|
Dictionary mapping transcript IDs to length-normalized expression levels (either FPKM or TPM)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OrderedDict
|
Mapping from each transcript effect to an expression quantity. Effects that don't have an associated transcript (e.g. Intergenic) are excluded. |
Source code in varcode/effects/effect_collection.py
top_expression_effect(expression_levels)
¶
Return effect whose transcript has the highest expression level. If none of the effects are expressed or have associated transcripts, then return None. In case of ties, add lexicographical sorting by effect priority and transcript length.
Source code in varcode/effects/effect_collection.py
to_dataframe(include_archive=False, *, deletion_notation='sequence')
¶
Build a summary; optionally retain full graphs in effect_json.
deletion_notation="range" renders protein deletion labels using
endpoint positions instead of the default full deleted sequence.
See :meth:MutationEffect.format_short_description.
Source code in varcode/effects/effect_collection.py
to_csv(path, include_header=True, *, deletion_notation='sequence')
¶
Write this collection to CSV.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Output path.
TYPE:
|
include_header
|
If True (default), prepend
TYPE:
|
deletion_notation
|
Display pure protein deletions as
TYPE:
|
Source code in varcode/effects/effect_collection.py
from_csv(path, genome=None)
classmethod
¶
Rebuild an EffectCollection from a CSV previously written by
EffectCollection.to_csv().
ORF and start-loss exports include an effect_json column. Those rows
restore the saved graphs without reannotation; edited identity columns
that disagree with their archives raise.
Ordinary summary CSV records (contig, start, ref, alt, transcript_id) but not enough per-effect state to reconstruct effects byte-for-byte. This method takes the pragmatic semantic round-trip path: rebuild each Variant, re-annotate against the recorded transcript, and emit the resulting effect. The resulting collection should match the original whenever annotation is deterministic for a given (variant, transcript) pair.
Prefer from_json for byte-for-byte round-trip or for
larger collections (≳10k effects); per-row re-annotation makes
CSV loading significantly slower than JSON. Emits a warning
when the CSV header reports a different major varcode version
than the one currently installed — annotation logic can change
across major versions and the reconstructed effects may differ
from the ones that were written.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the CSV file. Lines starting with '#' are treated as
comments and parsed as
TYPE:
|
genome
|
Reference genome to associate with the loaded variants and
to look up transcripts by ID. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectCollection
|
|
Source code in varcode/effects/effect_collection.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
varcode.EffectCandidate(effect: Any, source: str = 'varcode', evidence: Mapping[str, Any] = dict())
dataclass
¶
Bases: DataclassSerializable
One plausible effect for a variant, paired with provenance.
| PARAMETER | DESCRIPTION |
|---|---|
effect
|
The effect this candidate represents. Guaranteed to be a
:class:
TYPE:
|
source
|
Name of the tool or annotator that produced this candidate.
Defaults to
TYPE:
|
evidence
|
Open-ended provenance dict. Shape is source-specific; the convention is that keys match the source's native field names. Consumers that need a particular shape should type-check at the call site rather than rely on a rigid schema here.
TYPE:
|
short_description: str
property
¶
Convenience passthrough to self.effect.short_description.
Lets callers build tables without unpacking
candidate.effect.short_description everywhere.
varcode.candidates_from_effects(effects: Tuple[Any, ...], source: str = 'varcode') -> Tuple[EffectCandidate, ...]
¶
Wrap a tuple of :class:MutationEffect instances as
:class:EffectCandidate objects with a shared source string.
Convenience for the common case where a producer has a tuple of
Effects and wants to lift it into the wrapped form without
setting evidence fields. Callers with producer-specific metadata
construct :class:EffectCandidate directly.
Source code in varcode/effect_candidates.py
Splice candidates¶
See splice variants for the distinction between signal disruption and candidate consequences. The scores below are sequence heuristics, not probabilities that a candidate is expressed.
varcode.SpliceCandidateRNAEvidence(candidate: EffectCandidate, rna_evidence: Tuple[EffectCandidate, ...] = tuple())
dataclass
¶
Bases: DataclassSerializable
RNA observations supporting one visible splice candidate.
varcode.enumerate_cryptic_exon_candidates(contig: str, sequence: str, sequence_start: int, variant=None, donor_threshold: float = 0.7, acceptor_threshold: float = 0.7, min_intron_length: int = 30, max_intron_length: int = 10000, score_fn: Optional[ScoreFn] = None) -> List[CrypticExonCandidate]
¶
Scan sequence for candidate cryptic exons — (acceptor,
donor) pairs that could form a new internal exon on the
rearranged allele.
| PARAMETER | DESCRIPTION |
|---|---|
contig
|
Chromosome / contig the sequence lives on (for reporting; not used for scoring).
TYPE:
|
sequence
|
The genomic sequence to scan — typically the region around an SV breakpoint, or a long-read-assembled rearranged allele.
TYPE:
|
sequence_start
|
1-based genomic start position of
TYPE:
|
variant
|
Source variant for provenance on returned candidates.
TYPE:
|
donor_threshold
|
Minimum score to accept a site. Defaults (0.7) are chosen to be liberal — motif-based scoring has high false-positive rates, so the point is to enumerate candidates for downstream scoring, not to be the final caller.
TYPE:
|
acceptor_threshold
|
Minimum score to accept a site. Defaults (0.7) are chosen to be liberal — motif-based scoring has high false-positive rates, so the point is to enumerate candidates for downstream scoring, not to be the final caller.
TYPE:
|
min_intron_length
|
A donor following an acceptor must leave an intron in this
length range for the candidate to be reported. Narrow
defaults keep the output tractable; callers that want
everything pass
TYPE:
|
max_intron_length
|
A donor following an acceptor must leave an intron in this
length range for the candidate to be reported. Narrow
defaults keep the output tractable; callers that want
everything pass
TYPE:
|
score_fn
|
Override the default motif scorer. Signature
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list of :class:`CrypticExonCandidate`
|
One entry per accepted (acceptor, donor) pair forming a plausible internal exon. Empty list when nothing scores above threshold. |
Source code in varcode/cryptic_exons.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
varcode.enumerate_from_structural_variant(variant, flank: int = 500, score_fn: Optional[ScoreFn] = None, **kwargs) -> List[CrypticExonCandidate]
¶
Convenience wrapper: enumerate candidates in the genomic region around an SV breakpoint.
Reads flank bp either side of each of the variant's
breakpoints (see :attr:StructuralVariant.breakpoints, which
covers both ends of every junction the variant creates). If the
variant carries an alt_assembly (long-read resolution), scans
that instead of the reference.
Returns the combined, sorted candidate list.
Source code in varcode/cryptic_exons.py
varcode.score_donor(window: str) -> float
¶
Score a 9-bp window as a candidate 5' splice site (donor).
Returns a ratio in [0, 1]. Anchor mismatches (GT at +1/+2)
force the score to 0, since biologically a donor without GT is
not a donor under the canonical (U2-type) spliceosome.
Source code in varcode/cryptic_exons.py
varcode.score_acceptor(window: str) -> float
¶
Score a 4-bp window as a candidate 3' splice site (acceptor).
Returns a ratio in [0, 1]. Anchor mismatches (AG at -2/-1)
force the score to 0.
Source code in varcode/cryptic_exons.py
Protein collections¶
See protein collections and FASTA for varcode.to_proteome(),
offline provenance, alternatives and reference composition.
Priority ordering¶
varcode.effect_priority(effect)
¶
Returns the integer priority for a given transcript effect.
Effects may opt out of class-based priority lookup by exposing a
priority_class attribute — used by wrapper classes like
:class:varcode.splice_outcomes.SpliceOutcomeSet to delegate to
the wrapped effect's class.
Shared transcript comparisons rank by their most severe retained candidate. Selecting an effect never drops its other hypotheses.
Source code in varcode/effects/effect_ordering.py
varcode.top_priority_effect(effects)
¶
Given a collection of variant transcript effects, return the top priority object, retaining complete splice outcome sets. Raw ExonicSpliceSite effects select their higher-priority consequence. In cases where multiple transcripts give rise to multiple effects, use a variety of filtering and sorting heuristics to pick the canonical transcript.