Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed Oct 15, 2024
1 parent 08d00ca commit 01ec5b4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/resdk/resources/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def variants(self):
if self._variants is None:
self._variants = self.resolwe.variant.filter(variant_calls__sample=self.id)
return self._variants

def variants_by_experiment(self, experiment):
self.resolwe.variant.filter(variant_calls__sample=self.id, variant_calls__experiment=experiment)

@property
def collection(self):
Expand Down
70 changes: 65 additions & 5 deletions src/resdk/resources/variants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Variant resources."""

from typing import Any

from .base import BaseResource


Expand All @@ -21,14 +23,30 @@ def __init__(self, resolwe, **model_data):
"""Initialize object."""
super().__init__(resolwe, **model_data)
self._annotations = None
self._samples = None
self._calls = None

@property
def annotations(self):
"""Get the annotations for this variant."""
if self._annotations is None:
self._annotations = self.resolwe.variant_annotation.filter(id=self.id)
self._annotations = self.resolwe.variant_annotation.filter(variant=self.id)
return self._annotations

@property
def samples(self):
"""Get samples."""
if self._samples is None:
self._samples = self.resolwe.sample.filter(variant_calls__variant=self.id)
return self._samples

@property
def calls(self):
"""Get variant calls associated with this variant."""
if self._calls is None:
self._calls = self.resolwe.variant_calls.filter(variant=self.id)
return self._calls

def __repr__(self) -> str:
"""Return string representation."""
return (
Expand Down Expand Up @@ -69,26 +87,68 @@ class VariantExperiment(BaseResource):
"contributor",
)

def __repr__(self) -> str:
"""Return string representation."""
return f"VariantExperiment <pk: {self.id}>"


class VariantCall(BaseResource):
"""VariantCall resource."""

endpoint = "variant_calls"

READ_ONLY_FIELDS = BaseResource.READ_ONLY_FIELDS + (
"sample",
"variant",
"experiment",
"sample_id",
"variant_id",
"quality",
"depth_norm_quality",
"alternative_allele_depth",
"depth",
"genotype",
"genotype_quality",
"filter",
"data",
"data_id",
"experiment_id",
)

def __init__(self, resolwe, **model_data: Any):
"""Initialize object."""
super().__init__(resolwe, **model_data)
self._data = None
self._sample = None
self._experiment = None
self._variant = None

@property
def data(self):
"""Get the data object for this variant call."""
if self._data is None:
self._data = self.resolwe.data.get(self.data_id)
return self._data

@property
def sample(self):
"""Get the sample object for this variant call."""
if self._sample is None:
self._sample = self.resolwe.sample.get(self.sample_id)
return self._sample

@property
def experiment(self):
"""Get the experiment object for this variant call."""
if self._experiment is None:
self._experiment = self.resolwe.variant_experiment.get(
id=self.experiment_id
)
return self._experiment

@property
def variant(self):
"""Get the variant object for this variant call."""
if self._variant is None:
self._variant = self.resolwe.variant.get(id=self.variant_id)
return self._variant

def __repr__(self) -> str:
"""Return string representation."""
return f"VariantCall <pk: {self.id}>"

0 comments on commit 01ec5b4

Please sign in to comment.