Skip to content

Commit

Permalink
Merge pull request #54 from dglemos/update/search_output
Browse files Browse the repository at this point in the history
Update search to return the confidence
  • Loading branch information
seeta-ramaraju authored Oct 17, 2024
2 parents df85b5d + 9147595 commit 93e641c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
echo "host=127.0.0.1" >> /home/runner/work/config.ini
echo "port=3306" >> /home/runner/work/config.ini
- name: Run tests
- name: Run Tests
run: |
export SECRET_KEY=$(openssl rand -base64 12)
python manage.py makemigrations
python manage.py migrate
python manage.py test gene2phenotype_app.tests
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
PROJECT_CONFIG_PATH: /home/runner/work/config.ini
working-directory: gene2phenotype_project
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ def check_entry(self, input_json_data):

def get_entry_info_from_json_data(self, json_data):
"""
Extracts specific information from a given JSON data structure related to genotype, disease, and panel.
Extracts specific information from a given JSON data structure.
This method parses the provided `json_data` dictionary to extract the following fields:
- "genotype": Retrieved from the "allelic_requirement" key.
- "disease": Retrieved from the nested "disease_name" key inside the "disease" dictionary.
- "panel": Retrieved from the "panels" key.
- "confidence": Retrieved from the key "level" inside the "confidence" dictionary.
If any of the keys are missing, the method returns `None` for the corresponding fields.
Expand All @@ -251,13 +252,16 @@ def get_entry_info_from_json_data(self, json_data):
Returns:
dict: A dictionary containing the extracted fields with the following keys:
- "genotype" (str or None): The value of the "allelic_requirement" field, or `None` if not present.
- "disease" (str or None): The value of the "disease_name" field inside the "disease" dictionary, or `None` if not present.
- "genotype" (str): The allelic requirement (genotype) value, or empty string if not present.
- "disease" (str): The disease name, or empty string if not present.
- "panel" (list): The list of panels, or empty list if not present.
- "confidence" (str): The confidence level, or empty string if not present.
"""
return {
"genotype": json_data.get("allelic_requirement"),
"disease": json_data.get("disease", {}).get("disease_name"),
"panel": json_data.get("panels")
"panel": json_data.get("panels"),
"confidence": json_data.get("confidence", {}).get("level")
}

@transaction.atomic
Expand Down
16 changes: 9 additions & 7 deletions gene2phenotype_project/gene2phenotype_app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_queryset(self):
return LocusGenotypeDisease.objects.none()

base_locus = Q(locus__name=search_query, is_deleted=0)
base_locus_2 = Q(locus__locusidentifier__isnull=False, locus__locusidentifier__identifier=search_query)
base_locus_2 = Q(locus__locusidentifier__isnull=False, locus__locusidentifier__identifier=search_query, is_deleted=0)
base_locus_3 = Q(locus__locusattrib__isnull=False, locus__locusattrib__value=search_query, locus__locusattrib__is_deleted=0)
base_disease = Q(disease__name__regex=fr"(?i)(?<![\w]){search_query}(?![\w])", is_deleted=0)
base_disease_2 = Q(disease__diseasesynonym__synonym__regex=fr"(?i)(?<![\w]){search_query}(?![\w])", is_deleted=0)
Expand Down Expand Up @@ -141,26 +141,26 @@ def get_queryset(self):

if not queryset.exists():
self.handle_no_permission('g2p_id', search_query)

elif search_type == 'draft' and user.is_authenticated:
queryset = CurationData.objects.filter(
gene_symbol=search_query
).order_by('stable_id__stable_id').distinct()

# to extend the queryset being annotated when it is draft,
# want to return username so curator can see who is curating
# adding the curator email, incase of the notification.
queryset = queryset.annotate(first_name=F('user_id__first_name'), last_name=F('user_id__last_name'), user_email=F('user__email'))

for obj in queryset:
obj.json_data_info = CurationDataSerializer.get_entry_info_from_json_data(self, obj.json_data)

if not queryset.exists():
self.handle_no_permission("draft", search_query)

else:
self.handle_no_permission('Search type is not valid', None)

new_queryset = []
if queryset.exists():
if search_type != 'draft':
Expand Down Expand Up @@ -197,7 +197,8 @@ def list(self, request, *args, **kwargs):
'genotype':lgd.genotype.value,
'disease':lgd.disease.name,
'mechanism':lgd.molecular_mechanism.mechanism.value,
'panel':lgd.panels
'panel':lgd.panels,
'confidence': lgd.confidence.value
}
list_output.append(data)
else:
Expand All @@ -212,6 +213,7 @@ def list(self, request, *args, **kwargs):
"genotype": c_data.json_data_info["genotype"],
"disease_name" : c_data.json_data_info["disease"],
"panels" : c_data.json_data_info["panel"],
"confidence" : c_data.json_data_info["confidence"],
"curator_email": c_data.user_email
}
list_output.append(data)
Expand Down

0 comments on commit 93e641c

Please sign in to comment.