Annotators API¶
Ordinary annotation uses the default without selecting an implementation. See experimental annotators for alternatives and Writing an annotator for extensions.
Annotators¶
varcode.EffectAnnotator
¶
Bases: Protocol
Protocol for an object that annotates variant effects on transcripts.
Conforming objects expose:
name— short identifier (e.g."fast") used in the registry and in serialized provenance.- :meth:
annotate_on_transcript— the per-transcript entry point, returning aMutationEffectorNotImplemented.
Return Python's NotImplemented singleton when this particular input
is unsupported. Public prediction APIs expose it as an Unresolved
effect with a reason, retaining this annotator's provenance. They never
silently replace an experimental result with the default's prediction.
None is invalid; exceptions retain normal error-handling semantics.
Optionally exposes version (string) — used in CSV provenance
headers so readers can detect when a serialized collection came
from a different annotator version. Built-in annotators track
varcode's version; third-party annotators expose their own.
Optionally implement annotate_with_context(variant, transcript,
germline_ctx, phase_resolver=None) with the same return contract.
Without it, nonempty germline context is unsupported. Empty context
calls annotate_on_transcript as usual.
The contract is duck-typed (@runtime_checkable) so third-party annotators
don't need to inherit from varcode just to register.
varcode.FastEffectAnnotator
¶
Annotate point edits and structural variants through one interface.
version = _varcode_version
class-attribute
instance-attribute
¶
Built-in annotators track varcode's own version. Third-party annotators (isovar's plugin, exacto's plugin) expose their own version string here; CSV provenance headers and round-trip warnings read from this field. See #271.
annotate_on_transcript(variant, transcript)
¶
Delegate to the existing per-transcript prediction.
Returns the raw effect class (ExonicSpliceSite /
SpliceDonor / etc. for splice disruptions), not wrapped
in SpliceOutcomeSet. The wrap is applied at the collection
boundary in :func:predict_variant_effects so internal
consumers (notably the protein_diff annotator's dual
dispatch) can still pattern-match on the raw class.
Source code in varcode/annotators/fast.py
annotate_with_context(variant, transcript, germline_ctx, phase_resolver=None)
¶
Use the established patient-baseline path for point edits.
Structural haplotype composition remains experimental in transcript_model.
Do not send an SV's placeholder alleles to the point-edit builder.
Source code in varcode/annotators/fast.py
varcode.ProteinDiffEffectAnnotator
¶
Classify effects by diffing translated mutant protein against the reference protein.
Experimental alternative for point edits. The parity harness compares
it with the default on their shared domain and records intentional
divergences with issue links. Structural variants return
NotImplemented. Shared splice/germline classification helpers do not
depend on this annotator.
annotate_with_context(variant, transcript, germline_ctx, phase_resolver=None)
¶
Share the default's patient-baseline path for point edits.
Source code in varcode/annotators/protein_diff.py
annotate_on_transcript(variant, transcript)
¶
Classify the effect of variant on transcript.
Runs fast first to detect splice-adjacent variants (which
stay fast-classified); for everything else, builds a
:class:MutantTranscript and diffs the translated protein.
Source code in varcode/annotators/protein_diff.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 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 | |
Registry¶
varcode.register_annotator(annotator)
¶
Add an annotator to the process-global registry, keyed by its
.name. Re-registering under the same name overrides the
previous entry — this is deliberate so callers can swap
implementations in tests.
Source code in varcode/annotators/registry.py
varcode.get_annotator(name)
¶
Look up a registered annotator by name. Raises KeyError
if no annotator is registered under that name.
varcode.get_default_annotator()
¶
Return the annotator currently configured as the default.
Current default is "fast" (restored as the default in 7.0.0;
see #397). "protein_diff" stays available as an opt-in.
Source code in varcode/annotators/registry.py
varcode.set_default_annotator(name)
¶
Swap the process-wide default annotator. name must refer
to a registered annotator.
Source code in varcode/annotators/registry.py
varcode.use_annotator(name_or_instance)
¶
Context manager that temporarily swaps the default annotator.
Useful for A/B comparisons and scoped overrides without mutating global state across the codebase::
with varcode.use_annotator("protein_diff"):
effects = variant_collection.effects()
Accepts the same argument shape as the annotator= kwarg:
a registered-name string, or an annotator instance. Passing an
instance registers it temporarily under its .name so that
name-based lookups inside the block find it; on exit the
previous default and any previously-registered annotator under
that name are restored.
Source code in varcode/annotators/registry.py
Experimental transcript model¶
This annotator is opt-in with annotator="transcript_model"; fast remains
the default. The former realized name and public imports remain aliases.
See supported inputs and results before using it.
varcode.TranscriptModelEffectAnnotator
¶
Experimental, opt-in annotator backed by the transcript model.
annotate_with_context(variant, transcript, germline_ctx, phase_resolver=None)
¶
Annotate through the same pipeline with patient germline edits.
Source code in varcode/transcript_model.py
varcode.predict_transcript_model_effect(variants, transcript, germline_variants=(), phase_resolver=None, sequence_provider=None, max_hypotheses=64)
¶
Predict one ordinary top effect with alternatives in .candidates.
Canonical and exon-skip paths resolve from transcript annotation alone.
Intron retention and cryptic sites are also realized when genomic
sequence is available, and remain explicit :class:Unresolved
candidates at sequence-free tier 0. Rule order is never mislabeled as
probability.
Source code in varcode/transcript_model.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 285 286 287 288 289 290 291 292 293 294 295 | |