Genomics and RNA
DeepSEA Variant Effects
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Combine paired genomic predictions, conservation features, and supplied null effects into learned variant scores and empirical significance measures.
Function signature
deepsea_variant_effects(
activations: dict,
parameters: dict,
masks: dict,
eps: float = 1e-06,
) -> dict[str, torch.Tensor]Worked example
One channel and four null effects
The prediction changes from 0.25 to 0.5: probability difference 0.25, log-odds difference \log 3. Features are [0.25,\log 3,2]; the supplied classifier gives logit 1 and probability about 0.7311. Effect magnitude is 0.25\log3\approx0.2747. Two of four null effects strictly exceed it, giving e-value 0.5 and functional significance 0.5\times0.2=0.1.
import torch
activations = {
'reference': torch.tensor([[[0.25]]], dtype=torch.float64, requires_grad=True),
'alternate': torch.tensor([[[0.5]]], dtype=torch.float64, requires_grad=True),
'conservation': torch.tensor([[2.0]], dtype=torch.float64, requires_grad=True),
'conservation_impute': torch.tensor([0.0], dtype=torch.float64, requires_grad=True),
'feature_mean': torch.tensor([0.0, 0.0, 0.0], dtype=torch.float64, requires_grad=True),
'null_effects': torch.tensor([[0.0, 0.1, 0.5, 1.0]], dtype=torch.float64),
'conservation_evalues': torch.tensor([[0.2]], dtype=torch.float64, requires_grad=True),
}
parameters = {
'feature_scale': torch.tensor([1.0, 1.0, 1.0], dtype=torch.float64, requires_grad=True),
'classifier_weight': torch.tensor([[4.0], [0.0], [0.0]], dtype=torch.float64, requires_grad=True),
'classifier_bias': torch.tensor([0.0], dtype=torch.float64, requires_grad=True),
}
masks = {
'conservation_valid': torch.tensor([[True]], dtype=torch.bool),
}
eps = 1e-06
result = deepsea_variant_effects(activations=activations, parameters=parameters, masks=masks, eps=eps)Expected return
{
'scores': torch.tensor([[0.7310585786300049]], dtype=torch.float64),
'difference': torch.tensor([[[0.25]]], dtype=torch.float64),
'log_odds': torch.tensor([[[1.0986122886681096]]], dtype=torch.float64),
'features': torch.tensor([[0.25, 1.0986122886681096, 2.0]], dtype=torch.float64),
'standardized': torch.tensor([[0.25, 1.0986122886681096, 2.0]], dtype=torch.float64),
'evalues': torch.tensor([[0.5]], dtype=torch.float64),
'functional_significance': torch.tensor([0.1], dtype=torch.float64),
}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. |
epsfloatDefault 1e-06 | Clamp each reference and alternate probability to [eps, 1 - eps] before probability differences and natural-log odds; require 0 < eps < 0.5. |
Return
dict[str, torch.Tensor]
Return exactly the named fields applicable to this operation.
Required behavior
- reference and alternate have shape
[B,S,T], with S aligned prediction replicates. Clamp both to[\varepsilon,1-\varepsilon], where eps defaults to10^{-6}and lies in(0,0.5). Compute signed probability differences and signed alternate-minus-reference log odds. - Feature order is: mean absolute probability difference across S for every channel; mean absolute log-odds difference across S; absolute conservation values. Replace invalid conservation entries with the supplied per-feature imputation value before taking absolute values.
- Standardize with supplied feature_mean and positive feature_scale. Apply the supplied classifier_weight and classifier_bias, followed by sigmoid, to produce scores.
- For each prediction channel, effect magnitude is mean(abs(difference) * abs(log_odds)) across replicates. evalues are the fraction of null_effects strictly GREATER than this magnitude; ties do not count.
- functional_significance is geometric_mean(evalues over prediction channels) multiplied by geometric_mean(conservation_evalues over conservation channels). Do not add a pseudocount or take a single combined geometric mean.
- For probability
p, log odds are\log p-\log(1-p). The classifier usessigmoid(z)=1/(1+e^{-z}). - The geometric mean of
nnonnegative factors is(\prod_i a_i)^{1/n}; a zero factor makes the group mean zero. For positive factors, averaging logarithms is numerically stable.
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 deepsea_variant_effects(
activations: dict,
parameters: dict,
masks: dict,
eps: float = 1e-06,
) -> dict[str, torch.Tensor]:
"""Return dict[str, torch.Tensor]:
scores: (B,K).
difference: (B, S, T).
log_odds: (B, S, T).
features: (B, 2T+Q).
standardized: (B, 2T+Q).
evalues: (B, T).
functional_significance: (B,)."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement deepsea_variant_effects")
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.