Genomics and RNA · INTEGRATION

Splice and chromatin variant-effect scores

HardRaw PyTorchAbout 30 min2 public examples plus private tests

SpliceAIDeepSEA

Write and run your solution Sign in

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

ParameterShape and meaning
activationsdictSupplied intermediate tensors.
parametersdictSupplied model parameters, keyed as shown below.
masksdictSupplied masks. Each field below defines what True includes or permits.
structuredictFields 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-06DeepSEA mode only: clamp probabilities to [eps, 1 - eps] before differences and log odds; require 0 < eps < 0.5.
annotation_maskboolDefault FalseSplice 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] and annotation_offset [B] in the common reference grid.
  • Return scores and offsets in order [\mathrm{acceptor\_gain},\mathrm{acceptor\_loss},\mathrm{donor\_gain},\mathrm{donor\_loss}]. Gains maximize alternate-reference; losses maximize reference-alternate over 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}=0 and has_support=False. If annotation_mask=True, suppress a gain whose selected offset equals annotation_offset and suppress a loss whose selected offset differs; offsets remain unchanged.
  • Alternatively supply annotation_candidates[B,J] signed exon-boundary offsets and annotation_valid[B,J], J\ge 1 and \left|\mathrm{offset}\right|<2^{60}; they override annotation_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_offset and annotation_present; no eligible annotation returns \mathrm{offset}=0, annotation_present=False, and disables annotation suppression.
  • Config mode='deepsea': probabilities[B,S,T] contain S orientation/replicate predictions.
  • Clip each probability to [\varepsilon,1-\varepsilon], \varepsilon=10^{-6} by default; compute signed difference and natural-log odds difference, then concatenate \mathrm{mean\_S}(\left|\mathrm{difference}\right|), \mathrm{mean\_S}(\left|\mathrm{log\_odds}\right|) and abs(imputed conservation[B,Q]).
  • Missing conservation uses supplied conservation_impute [Q]. Standardize with supplied feature_mean/positive feature_scale [2T+Q], multiply by classifier_weight[2 T+Q,K] plus classifier_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 of null_effects[T,M] exceeding each magnitude.
  • functional_significance is \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, not p-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.

Write and run your solution Sign in

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.