-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d599238
commit 2787170
Showing
12 changed files
with
1,652 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""".. Ignore pydocstyle D400. | ||
=================================== | ||
Resolwe Bioinformatics Variants App | ||
=================================== | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""".. Ignore pydocstyle D400. | ||
=============================== | ||
Variants Base App Configuration | ||
=============================== | ||
""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class VariantsConfig(AppConfig): | ||
"""App configuration.""" | ||
|
||
name = "resolwe_bio.variants" | ||
label = "resolwe_bio_variants" | ||
verbose_name = "Resolwe Bioinformatics Variants Base" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""Handle variants related commands.""" | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from resolwe.flow.executors.socket_utils import Message, Response | ||
from resolwe.flow.managers.listener.plugin import ( | ||
ListenerPlugin, | ||
listener_plugin_manager, | ||
) | ||
|
||
from .models import Variant, VariantCall, VariantExperiment | ||
|
||
if TYPE_CHECKING: | ||
from resolwe.flow.managers.listener.listener import Processor | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class VariantCommands(ListenerPlugin): | ||
"""Listener handlers related to the variants application.""" | ||
|
||
plugin_manager = listener_plugin_manager | ||
|
||
def add_variants( | ||
self, data_id: int, message: Message[dict], manager: "Processor" | ||
) -> Response[int]: | ||
"""Handle connecting variants with the samples. | ||
If the reported variant does not exist in the file it is created. | ||
""" | ||
data = manager.data(data_id) | ||
sample = data.entity | ||
metadata, variants_data = message.message_data | ||
species, genome_assembly = metadata["species"], metadata["genome_assembly"] | ||
|
||
variant_calls = list() | ||
variant_cache = dict() | ||
experiment = VariantExperiment.objects.create( | ||
variant_data_source=metadata["variant_data_source"], | ||
contributor=data.contributor, | ||
) | ||
|
||
# Bulk create variants. The consequesce of ignore_conflicts flag is that the | ||
# database does not returt the ids of the created objects. So first create all | ||
# the variants and then create the variant calls. | ||
for variant_data in variants_data: | ||
key = { | ||
"species": species, | ||
"genome_assembly": genome_assembly, | ||
"chromosome": variant_data["chromosome"], | ||
"position": variant_data["position"], | ||
"reference": variant_data["reference"], | ||
"alternative": variant_data["alternative"], | ||
} | ||
# To reduce the hits to the database use cache for variants. | ||
key_tuple = tuple(key.values()) | ||
if key_tuple not in variant_cache: | ||
variant_cache[key_tuple] = Variant.objects.get_or_create(**key)[0] | ||
variant = variant_cache[key_tuple] | ||
|
||
variant_calls.append( | ||
VariantCall( | ||
variant=variant, | ||
data=data, | ||
sample=sample, | ||
quality=variant_data["quality"], | ||
depth=variant_data["depth"], | ||
genotype=variant_data["genotype"], | ||
filter=variant_data["filter"], | ||
experiment=experiment, | ||
) | ||
) | ||
|
||
VariantCall.objects.bulk_create(variant_calls) |
Oops, something went wrong.