Genomics and RNA · INTEGRATION
Splice and chromatin variant-effect scores
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Compare aligned reference and alternate genomic predictions. In splice mode, each score is the largest signed acceptor or donor change over valid positions, with its location relative to the variant. In DeepSEA mode, each score is a supplied classifier’s probability computed from absolute prediction changes and conservation; empirical tail proportions are returned separately.
Function signature
variant_effect_scoring(
activations: dict,
parameters: dict,
masks: dict,
structure: dict,
mode: str = 'splice',
eps: float = 1e-06,
annotation_mask: bool = False,
) -> dict[str, torch.Tensor]Worked example
Splice gains, losses, and locations
Take one sequence with reference probabilities [[0.7,0.2,0.1],[0.5,0.3,0.2]] and alternate probabilities [[0.5,0.4,0.1],[0.6,0.1,0.3]], in [neither, acceptor, donor] order. Both positions are valid, anchor=1, annotation_offset=0, and annotation_mask=False. Acceptor changes are [0.2,-0.2]; donor changes are [0,0.1]. Thus scores=[0.2,0.2,0.1,0] and offsets=[-1,0,0,-1] in gain/loss order. has_support=True, the nearest annotation offset is 0, and annotation_present=True. These arrays describe the single batch item.
Parameters
| Parameter | Shape and meaning |
|---|---|
activationsdict | Supplied intermediate tensors. |
parametersdict | Supplied model parameters, keyed as shown below. |
masksdict | Supplied masks. Each field below defines what True includes or permits. |
structuredict | Fields supplied together in this dictionary. |
modestrDefault 'splice' | Choose "splice" for local acceptor/donor gain/loss scores or "deepsea" for the specified ensemble/classifier significance calculation. |
epsfloatDefault 1e-06 | DeepSEA mode only: clamp probabilities to [eps, 1 - eps] before differences and log odds; require 0 < eps < 0.5. |
annotation_maskboolDefault False | Splice mode only: apply the stated annotation-aware gain/loss suppression when True. |
Return
dict[str, torch.Tensor]
Return exactly the named fields applicable to this operation.
Required behavior
- Config
mode='splice'(default):reference/alternate[B,L,3] use channels[\mathrm{neither},\mathrm{acceptor},\mathrm{donor}],valid_mask[B,L],anchor[B]andannotation_offset[B]in the commonreferencegrid. - Return
scoresandoffsetsin order[\mathrm{acceptor\_gain},\mathrm{acceptor\_loss},\mathrm{donor\_gain},\mathrm{donor\_loss}]. Gains maximizealternate-reference; losses maximizereference-alternateover valid positions. Keep signed maxima (do not rectify); ties select the first valid index. \mathrm{Offset}=\mathrm{index}-\mathrm{anchor}. No support gives\mathrm{scores}=0,\mathrm{offsets}=0andhas_support=False. Ifannotation_mask=True, suppress a gain whose selected offset equalsannotation_offsetand suppress a loss whose selected offset differs;offsetsremain unchanged.- Alternatively supply
annotation_candidates[B,J] signed exon-boundaryoffsetsandannotation_valid[B,J],J\ge 1and\left|\mathrm{offset}\right|<2^{60}; they overrideannotation_offset. - Select the smallest absolute offset, breaking ties by the smaller signed offset (the earlier genomic boundary), as in SpliceAI's sorted boundary union. Return
nearest_annotation_offsetandannotation_present; no eligible annotation returns\mathrm{offset}=0,annotation_present=False, and disables annotation suppression. - Config
mode='deepsea': probabilities[B,S,T] containSorientation/replicate predictions. - Clip each probability to
[\varepsilon,1-\varepsilon],\varepsilon=10^{-6}by default; compute signeddifferenceand natural-log oddsdifference, then concatenate\mathrm{mean\_S}(\left|\mathrm{difference}\right|),\mathrm{mean\_S}(\left|\mathrm{log\_odds}\right|)and abs(imputedconservation[B,Q]). - Missing
conservationuses suppliedconservation_impute[Q]. Standardize with suppliedfeature_mean/positivefeature_scale[2T+Q], multiply byclassifier_weight[2 T+Q,K] plusclassifier_bias[K], and apply sigmoid. - Also form
\mathrm{magnitude}=\mathrm{mean\_S}(\left|\mathrm{difference}\right|\cdot \left|\mathrm{log\_odds}\right|);evalues[B,T] are the strict fraction ofnull_effects[T,M] exceeding each magnitude. functional_significanceis\mathrm{geometric\_mean\_T}(\mathrm{evalues})\cdot \mathrm{geometric\_mean\_Q}(\mathrm{conservation\_evalues}), with exact zero if any factor is zero.E-values are empirical tail proportions, notp-values.- All resources and fitted coefficients are supplied; finite background sampling, natural-log convention and averaging order are explicit.
Why this matters
A splice score locates the strongest predicted gain or loss along a sequence. DeepSEA instead combines effect magnitudes across outputs with supplied conservation and classifier resources. Both summarize model predictions; neither supplies clinical calibration.
Starter code
You write the body of this function in the BioTorch workspace. Your code runs in an isolated PyTorch sandbox; Run checks the public examples and Submit grades the full test suite, including gradients.
import torch
def variant_effect_scoring(
activations: dict,
parameters: dict,
masks: dict,
structure: dict,
mode: str = 'splice',
eps: float = 1e-06,
annotation_mask: bool = False,
) -> dict[str, torch.Tensor]:
"""Return dict[str, torch.Tensor]:
scores: Splice mode: (B, 4). DeepSEA mode: (B, K).
offsets: (B, 4). Returned only for mode="splice".
has_support: (B,). Returned only for mode="splice".
nearest_annotation_offset: (B,). Returned only for mode="splice".
annotation_present: (B,). Returned only for mode="splice".
difference: (B, S, T). Returned only for mode="deepsea".
log_odds: (B, S, T). Returned only for mode="deepsea".
features: (B, 2T+Q). Returned only for mode="deepsea".
standardized: (B, 2T+Q). Returned only for mode="deepsea".
evalues: (B, T). Returned only for mode="deepsea".
functional_significance: (B,). Returned only for mode="deepsea"."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement variant_effect_scoring")
Ready to implement it?
3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Related exercises
Sources and further reading
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.