Skip to content

Commit

Permalink
Merge pull request #14 from EGA-archive/iso8601duration
Browse files Browse the repository at this point in the history
Refactoring the iso8601duration alphanumeric filter
  • Loading branch information
costero-e authored Nov 18, 2024
2 parents 7a17f2a + 918e9c8 commit dc9fd97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion beacon/conf/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
default_beacon_granularity = "record" # boolean, count or record
security_levels = ['PUBLIC', 'REGISTERED', 'CONTROLLED']
documentation_url = 'https://b2ri-documentation-demo.ega-archive.org/'
alphanumeric_terms = ['libraryStrategy', 'molecularAttributes.geneIds', 'diseases.ageOfOnset.iso8601duration', 'molecularAttributes.aminoacidChanges']
alphanumeric_terms = ['libraryStrategy', 'molecularAttributes.geneIds', 'diseases.ageOfOnset.iso8601duration', 'molecularAttributes.aminoacidChanges','phenotypicFeatures.onset.iso8601duration']
cors_urls = ["http://localhost:3000","https://cancer-beacon-demo.ega-archive.org", "https://beacon-network-demo2.ega-archive.org", "https://beacon.ega-archive.org"]


Expand Down
32 changes: 26 additions & 6 deletions beacon/connections/mongo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,18 +938,21 @@ def apply_alphanumeric_filter(self, query: dict, filter: AlphanumericFilter, col
age_in_number = age_in_number+char
except Exception:# pragma: no cover
continue
new_age_list=[]
new_age_list=''

if "=" in filter.operator:
z = int(age_in_number)# pragma: no cover
else:
z = int(age_in_number)+1
while z < 150:
newagechar="P"+str(z)+"Y"
new_age_list.append(newagechar)
if new_age_list == '':
new_age_list+=newagechar
else:
new_age_list+='|'+newagechar
z+=1
dict_in={}
dict_in["$in"]=new_age_list
dict_in["$regex"]=new_age_list
query[filter.id] = dict_in
query=cross_query(self, query, scope, collection, {}, dataset)
elif '<' in filter.operator:
Expand All @@ -960,17 +963,34 @@ def apply_alphanumeric_filter(self, query: dict, filter: AlphanumericFilter, col
age_in_number = age_in_number+char
except Exception:# pragma: no cover
continue
new_age_list=[]
new_age_list=''
if "=" in filter.operator:
z = int(age_in_number)# pragma: no cover
else:
z = int(age_in_number)-1
while z > 0:
newagechar="P"+str(z)+"Y"
new_age_list.append(newagechar)
if new_age_list == '':
new_age_list+=newagechar
else:
new_age_list+='|'+newagechar
z-=1
dict_in={}
dict_in["$in"]=new_age_list
dict_in["$regex"]=new_age_list
query[filter.id] = dict_in
query=cross_query(self, query, scope, collection, {}, dataset)
elif '=' in filter.operator:
age_in_number=""
for char in filter.value:
try:
int(char)
age_in_number = age_in_number+char
except Exception:# pragma: no cover
continue
z = int(age_in_number)# pragma: no cover
newagechar="P"+str(z)+"Y"
dict_in={}
dict_in["$regex"]=newagechar
query[filter.id] = dict_in
query=cross_query(self, query, scope, collection, {}, dataset)
else:
Expand Down

0 comments on commit dc9fd97

Please sign in to comment.