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
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.
original_protein_sequence
property
¶
Amino acid sequence of a coding transcript (without the nucleotide variant/mutation)
__lt__(other)
¶
Effects are ordered by their associated variants, which have comparison implement in terms of their chromosomal locations.
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=set([]), 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
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=True)
¶
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:
|
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()
¶
Highest priority MutationEffect of all genes/transcripts overlapped by this variant. If this variant doesn't overlap anything, then this this method will return an Intergenic effect.
If multiple effects have the same priority, then return the one which is associated with the longest transcript.
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()
¶
Build a dataframe from the effect collection.
Source code in varcode/effects/effect_collection.py
to_csv(path, include_header=True)
¶
Write this collection to CSV.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Output path.
TYPE:
|
include_header
|
If True (default), prepend
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().
The current CSV format 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
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 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 | |
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.
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.
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. ExonicSpliceSite variants require special treatment since they actually represent two effects -- the splicing modification and whatever else would happen to the exonic sequence if nothing else gets changed. In cases where multiple transcripts give rise to multiple effects, use a variety of filtering and sorting heuristics to pick the canonical transcript.