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

Update gene scores to three decimal places #63

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
30 changes: 6 additions & 24 deletions gene2phenotype_project/gene2phenotype_app/serializers/locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,41 +174,23 @@ def badonyi_score(self):
"""
Retrieve the Badonyi scores for the current gene, organizing the results
in a dictionary where each key is the score's attribute (description_attrib.value)
and the value is the score.

This method filters `GeneStats` objects associated with the current gene (via `self.id`),
then creates a dictionary where the key is the `description_attrib.value` and the value
is the `score`.
and the value is the score rounded to three decimal places.

Returns:
-------
dict
A dictionary where:
- Key: The value of `description_attrib` (score's attribute) from each `GeneStats` object.
- Value: The score associated with that attribute.

Example:
-------
{
"gain_of_function": 1.5,
"loss_of_function": 0.7,
...
}

Notes:
-----
- Each unique attribute will have its own entry in the dictionary.
dictionary
- Key: The value of `description_attrib` (score's attribute) from each `GeneStats` object.
- Value: The score associated with that attribute.
"""

result_data = {}
badonyi_stats_objs = GeneStats.objects.filter(gene=self.id)

for badonyi_obj in badonyi_stats_objs:
key = badonyi_obj.description_attrib.value
result_data[key] = badonyi_obj.score
result_data[key] = round(badonyi_obj.score, 3)

return result_data


class Meta:
model = Locus
Expand Down
Loading