Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed fields for API's variantdata requests #137

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions core/api/utils/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create_or_get_filter_obj(filter_value):
if core.models.Filter.objects.filter(filter__iexact=filter_value).exists():
return core.models.Filter.objects.filter(filter__iexact=filter_value).last()
filter_serializer = core.api.serializers.CreateFilterSerializer(
data={"filter": filter_value}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this in low case, is it possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can apply lowercase to all the fields prior to sending the request

data={"Filter": filter_value}
)
if filter_serializer.is_valid():
filter_obj = filter_serializer.save()
Expand Down Expand Up @@ -62,13 +62,13 @@ def store_variant_in_sample(v_data):

def get_variant_id(data):
"""look out for the necessary reference ids to create the variance instance"""
chr_obj = core.utils.variants.get_if_chromosomes_exists(data["Chromosome"])
chr_obj = core.utils.variants.get_if_chromosomes_exists(data["chromosome"])
if chr_obj is None:
return {"ERROR": core.config.ERROR_CHROMOSOME_NOT_DEFINED_IN_DATABASE}
variant_obj = core.models.Variant.objects.filter(
chromosomeID_id=chr_obj,
pos__iexact=data["Variant"]["pos"],
alt__iexact=data["Variant"]["alt"],
pos__iexact=data["pos"],
alt__iexact=data["alt"],
).last()
if variant_obj is None:
# Create the variant
Expand All @@ -78,9 +78,9 @@ def get_variant_id(data):
variant_dict = {}
variant_dict["chromosomeID_id"] = chr_obj.get_chromosome_id()
variant_dict["filterID_id"] = filter_obj.get_filter_id()
variant_dict["pos"] = data["Variant"]["pos"]
variant_dict["alt"] = data["Variant"]["alt"]
variant_dict["ref"] = data["Variant"]["ref"]
variant_dict["pos"] = data["pos"]
variant_dict["alt"] = data["alt"]
variant_dict["ref"] = data["ref"]
variant_serializer = core.api.serializers.CreateVariantSerializer(
data=variant_dict
)
Expand All @@ -99,12 +99,12 @@ def get_variant_analysis_defined(s_obj):
def get_required_variant_ann_id(data):
"""Look for the ids that variant annotation needs"""
v_ann_ids = {}
gene_obj = core.utils.variants.get_gene_obj_from_gene_name(data["Gene"])
gene_obj = core.utils.variants.get_gene_obj_from_gene_name(data["gene"])

if gene_obj is None:
return {"ERROR": core.config.ERROR_GENE_NOT_DEFINED_IN_DATABASE}
v_ann_ids["geneID_id"] = gene_obj.get_gene_id()
effect_obj = create_or_get_effect_obj(data["Effect"])
effect_obj = create_or_get_effect_obj(data["effect"])
if isinstance(effect_obj, dict):
return effect_obj
v_ann_ids["geneID_id"] = gene_obj.get_gene_id()
Expand All @@ -122,6 +122,8 @@ def split_variant_data(data, sample_obj, date):
split_data["variant_in_sample"]["variantID_id"] = variant_id
split_data["variant_in_sample"]["analysis_date"] = date

var_keys = ["dp", "ref_dp", "alt_dp", "af"]
data["VariantInSample"] = {x: y for x, y in data.items() if x in var_keys}
split_data["variant_in_sample"].update(data["VariantInSample"])

v_ann_id = get_required_variant_ann_id(data)
Expand All @@ -130,6 +132,8 @@ def split_variant_data(data, sample_obj, date):
split_data["variant_ann"] = v_ann_id
split_data["variant_ann"]["variantID_id"] = variant_id

annot_keys = ["hgvs_c", "hgvs_p", "hgvs_p_1_letter"]
data["VariantAnnotation"] = {x: y for x, y in data.items() if x in annot_keys}
split_data["variant_ann"].update(data["VariantAnnotation"])
return split_data

Expand Down
2 changes: 2 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def intranet(request):
intra_data["ena_graph"] = core.utils.public_db.percentage_graphic(
len(sample_lab_objs), len(ena_acc), ""
)
else:
intra_data = f"No samples found for selected laboratory: {lab_name}"
return render(request, "core/intranet.html", {"intra_data": intra_data})
else:
# loged user belongs to Relecov Manager group
Expand Down
4 changes: 4 additions & 0 deletions dashboard/utils/var_lineage_variation_over_time_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def create_lineages_variations_graphic(date_range=None):
id="periodTime",
options=[
{"label": "Select Period", "value": ""},
{"label": "Last 4 years", "value": "1460"},
{"label": "Last 2 years", "value": "730"},
{"label": "Last year", "value": "365"},
{"label": "Last 6 months", "value": "180"},
{"label": "Last 3 months", "value": "90"},
{"label": "Last month", "value": "30"},
{"label": "Last week", "value": "7"},
],
),
],
Expand Down
Loading