Skip to content

Commit

Permalink
Relecov core linting after file and import updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Shettland committed Jul 18, 2024
1 parent 5d72ba8 commit c24f4bf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
27 changes: 19 additions & 8 deletions relecov_core/api/utils/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import relecov_core.models
import relecov_core.utils.samples


def prepare_fields_in_sample(s_data):
"""Add sample state and set to None GISAID and ENA if not set"""
if not relecov_core.models.SampleState.objects.filter(state__exact="Defined").exists():
if not relecov_core.models.SampleState.objects.filter(
state__exact="Defined"
).exists():
return {"ERROR": ERROR_INTIAL_SETTINGS_NOT_DEFINED}
s_data["state"] = (
relecov_core.models.SampleState.objects.filter(state__exact="Defined").last().get_state_id()
relecov_core.models.SampleState.objects.filter(state__exact="Defined")
.last()
.get_state_id()
)
if "biosample_accession_ENA" not in s_data:
s_data["biosample_accession_ENA"] = None
Expand Down Expand Up @@ -49,15 +54,21 @@ def split_sample_data(data):

# add user and state to sample data
split_data["sample"]["state"] = (
relecov_core.models.SampleState.objects.filter(state__exact="Defined").last().get_state_id()
relecov_core.models.SampleState.objects.filter(state__exact="Defined")
.last()
.get_state_id()
)
split_data["sample"]["user"] = relecov_core.utils.samples.get_user_id_from_collecting_institution(
split_data["sample"]["collecting_institution"]
split_data["sample"]["user"] = (
relecov_core.utils.samples.get_user_id_from_collecting_institution(
split_data["sample"]["collecting_institution"]
)
)
if relecov_core.models.Sample.objects.all().exists():
last_unique_value = relecov_core.models.Sample.objects.all().last().get_unique_id()
split_data["sample"]["sample_unique_id"] = relecov_core.utils.samples.increase_unique_value(
last_unique_value
last_unique_value = (
relecov_core.models.Sample.objects.all().last().get_unique_id()
)
split_data["sample"]["sample_unique_id"] = (
relecov_core.utils.samples.increase_unique_value(last_unique_value)
)
else:
split_data["sample"]["sample_unique_id"] = "AAA-0001"
Expand Down
15 changes: 10 additions & 5 deletions relecov_core/api/utils/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
ERROR_UNABLE_TO_STORE_IN_DATABASE,
)


def create_or_get_filter_obj(filter_value):
"""Return the filter instance or create if not exists"""
if relecov_core.models.Filter.objects.filter(filter__iexact=filter_value).exists():
return relecov_core.models.Filter.objects.filter(filter__iexact=filter_value).last()
return relecov_core.models.Filter.objects.filter(
filter__iexact=filter_value
).last()
filter_serializer = CreateFilterSerializer(data={"filter": filter_value})
if filter_serializer.is_valid():
filter_obj = filter_serializer.save()
Expand All @@ -28,7 +31,9 @@ def create_or_get_filter_obj(filter_value):
def create_or_get_effect_obj(effect_value):
"""Return the effect instance or create if not exists"""
if relecov_core.models.Effect.objects.filter(effect__iexact=effect_value).exists():
return relecov_core.models.Effect.objects.filter(effect__iexact=effect_value).last()
return relecov_core.models.Effect.objects.filter(
effect__iexact=effect_value
).last()
effect_serializer = CreateEffectSerializer(data={"effect": effect_value})
if effect_serializer.is_valid():
effect_obj = effect_serializer.save()
Expand Down Expand Up @@ -90,9 +95,9 @@ def get_variant_id(data):


def get_variant_analysis_defined(s_obj):
return relecov_core.models.VariantInSample.objects.filter(sampleID_id=s_obj).values_list(
"analysis_date", flat=True
)
return relecov_core.models.VariantInSample.objects.filter(
sampleID_id=s_obj
).values_list("analysis_date", flat=True)


def get_required_variant_ann_id(data):
Expand Down
1 change: 1 addition & 0 deletions relecov_core/utils/plotly_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def gauge_graphic(data):
plot_div = plot(graph, output_type="div", config={"displaylogo": False})
return plot_div


# FIXME: This function es never called within the platform
def bullet_graphic(value, title):
point = str(value)
Expand Down

0 comments on commit c24f4bf

Please sign in to comment.