Skip to content

Commit

Permalink
dataset variable in request parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Nov 2, 2024
1 parent 4c6468f commit d9ff62a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion beacon/conf/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
beacon_id = 'org.ega-archive.beacon-ri-demo' # ID of the Beacon
beacon_name = 'Beacon Reference Implementation demo' # Name of the Beacon service
api_version = 'v2.0.0' # Version of the Beacon implementation
uri = 'https://beacon-ri-demo.ega-archive.org/api/'
uri = 'http://beaconprod:5050/api/'
environment = 'test'
description = r"This Beacon is based on synthetic data hosted at the <a href='https://ega-archive.org/datasets/EGAD00001003338'>EGA</a>. The dataset contains 2504 samples including genetic data based on 1K Genomes data, and 76 individual attributes and phenotypic data derived from UKBiobank."
version = api_version_yaml['api_version']
Expand Down
4 changes: 2 additions & 2 deletions beacon/connections/mongo/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def get_analyses(self, entry_id: Optional[str], qparams: RequestParams, dataset:
collection = 'analyses'
mongo_collection = client.beacon.analyses
parameters_as_filters=False
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True and query_parameters != {'$and': []}:# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
query_parameters={}
elif query_parameters != {'$and': []}:
query=query_parameters
Expand Down
4 changes: 2 additions & 2 deletions beacon/connections/mongo/biosamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def get_biosamples(self, entry_id: Optional[str], qparams: RequestParams, datase
collection = 'biosamples'
mongo_collection = client.beacon.biosamples
parameters_as_filters=False
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True and query_parameters != {'$and': []}:# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
query_parameters={}
elif query_parameters != {'$and': []}:
query=query_parameters
Expand Down
4 changes: 2 additions & 2 deletions beacon/connections/mongo/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def get_list_of_datasets(self):
@log_with_args_mongo(level)
def get_dataset_with_id(self, entry_id: Optional[str], qparams: RequestParams):
limit = qparams.query.pagination.limit
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
else:
query={}
query = query_id(self, query, entry_id)
Expand Down
24 changes: 12 additions & 12 deletions beacon/connections/mongo/g_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def get_variants(self, entry_id: Optional[str], qparams: RequestParams, dataset:
collection = 'g_variants'
mongo_collection = client.beacon.genomicVariations
parameters_as_filters=False
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True and query_parameters != {'$and': []}:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
elif query_parameters != {'$and': []}:
query=query_parameters
Expand All @@ -41,9 +41,9 @@ def get_variant_with_id(self, entry_id: Optional[str], qparams: RequestParams, d
collection = 'g_variants'
mongo_collection = client.beacon.genomicVariations
query = {"$and": [{"variantInternalId": entry_id}]}
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
Expand All @@ -63,9 +63,9 @@ def get_biosamples_of_variant(self, entry_id: Optional[str], qparams: RequestPar
collection = 'g_variants'
mongo_collection = client.beacon.biosamples
query = {"$and": [{"variantInternalId": entry_id}]}
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
Expand Down Expand Up @@ -110,9 +110,9 @@ def get_runs_of_variant(self, entry_id: Optional[str], qparams: RequestParams, d
collection = 'g_variants'
mongo_collection = client.beacon.runs
query = {"$and": [{"variantInternalId": entry_id}]}
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
Expand Down Expand Up @@ -156,9 +156,9 @@ def get_analyses_of_variant(self, entry_id: Optional[str], qparams: RequestParam
collection = 'g_variants'
mongo_collection = client.beacon.analyses
query = {"$and": [{"variantInternalId": entry_id}]}
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
Expand Down Expand Up @@ -202,9 +202,9 @@ def get_individuals_of_variant(self, entry_id: Optional[str], qparams: RequestPa
collection = 'g_variants'
mongo_collection = client.beacon.individuals
query = {"$and": [{"variantInternalId": entry_id}]}
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, query, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
Expand Down
10 changes: 5 additions & 5 deletions beacon/connections/mongo/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def get_individuals(self, entry_id: Optional[str], qparams: RequestParams, datas
collection = 'individuals'
mongo_collection = client.beacon.individuals
parameters_as_filters=False
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True and query_parameters != {'$and': []}:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
elif query_parameters != {'$and': []}:
query=query_parameters
Expand All @@ -39,7 +39,7 @@ def get_individual_with_id(self, entry_id: Optional[str], qparams: RequestParams
collection = 'individuals'
idq="id"
mongo_collection = client.beacon.individuals
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
query = apply_filters(self, query, qparams.query.filters, collection, {}, dataset)
query = query_id(self, query, entry_id)
schema = DefaultSchemas.INDIVIDUALS
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_variants_of_individual(self, entry_id: Optional[str], qparams: RequestPa
queryHGVS["$in"]=listHGVS
query["identifiers.genomicHGVSId"]=queryHGVS
mongo_collection = client.beacon.genomicVariations
query, parameters_as_filters = apply_request_parameters(self, query, qparams)
query, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
query = apply_filters(self, query, qparams.query.filters, collection, {}, dataset)
schema = DefaultSchemas.GENOMICVARIATIONS
include = qparams.query.include_resultset_responses
Expand All @@ -100,7 +100,7 @@ def get_biosamples_of_individual(self, entry_id: Optional[str], qparams: Request
collection = 'biosamples'
mongo_collection = client.beacon.biosamples
query = {"individualId": entry_id}
query, parameters_as_filters = apply_request_parameters(self, query, qparams)
query, parameters_as_filters = apply_request_parameters(self, query, qparams, dataset)
query = apply_filters(self, query, qparams.query.filters, collection, {}, dataset)
schema = DefaultSchemas.BIOSAMPLES
include = qparams.query.include_resultset_responses
Expand Down
26 changes: 13 additions & 13 deletions beacon/connections/mongo/request_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def generate_position_filter_end(self, key: str, value: List[int]) -> List[Alpha
return filters

@log_with_args(level)
def apply_request_parameters(self, query: Dict[str, List[dict]], qparams: RequestParams):
def apply_request_parameters(self, query: Dict[str, List[dict]], qparams: RequestParams, dataset: str):
collection = 'g_variants'
if len(qparams.query.request_parameters) > 0 and "$and" not in query:
query["$and"] = []
Expand All @@ -85,45 +85,45 @@ def apply_request_parameters(self, query: Dict[str, List[dict]], qparams: Reques
v = v.split(',')
filters = generate_position_filter_start(self, k, v)
for filter in filters:
subquery["$and"].append(apply_alphanumeric_filter({}, filter, collection))
subquery["$and"].append(apply_alphanumeric_filter({}, filter, collection, dataset))
elif k == "end":
if isinstance(v, str):
v = v.split(',')
filters = generate_position_filter_end(self, k, v)
for filter in filters:
subquery["$and"].append(apply_alphanumeric_filter({}, filter, collection))
subquery["$and"].append(apply_alphanumeric_filter({}, filter, collection, dataset))
elif k == "datasets":
pass
elif k == "variantMinLength":
try:
subquery["$and"].append(apply_alphanumeric_filter({}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value='min'+v
), collection))
), collection, dataset))
except KeyError:
raise web.HTTPNotFound
elif k == "variantMaxLength":
try:
subquery["$and"].append(apply_alphanumeric_filter({}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value='max'+v
), collection))
), collection, dataset))
except KeyError:
raise web.HTTPNotFound
elif k == "mateName" or k == 'referenceName':
try:
subqueryor["$or"].append(apply_alphanumeric_filter({}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value='max'+v
), collection))
), collection, dataset))
except KeyError:
raise web.HTTPNotFound
elif k != 'filters':
try:
subquery["$and"].append(apply_alphanumeric_filter({}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value=v
), collection))
), collection, dataset))
except KeyError:
raise web.HTTPNotFound

Expand Down Expand Up @@ -155,45 +155,45 @@ def apply_request_parameters(self, query: Dict[str, List[dict]], qparams: Reques
v = v.split(',')
filters = generate_position_filter_start(self, k, v)
for filter in filters:
query["$and"].append(apply_alphanumeric_filter(self, {}, filter, collection))
query["$and"].append(apply_alphanumeric_filter(self, {}, filter, collection, dataset))
elif k == "end":
if isinstance(v, str):
v = v.split(',')
filters = generate_position_filter_end(self, k, v)
for filter in filters:
query["$and"].append(apply_alphanumeric_filter(self, {}, filter, collection))
query["$and"].append(apply_alphanumeric_filter(self, {}, filter, collection, dataset))
elif k == "datasets":
pass
elif k == "variantMinLength":
try:
query["$and"].append(apply_alphanumeric_filter(self, {}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value='min'+v
), collection))
), collection, dataset))
except KeyError:# pragma: no cover
raise web.HTTPNotFound
elif k == "variantMaxLength":
try:
query["$and"].append(apply_alphanumeric_filter(self, {}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value='max'+v
), collection))
), collection, dataset))
except KeyError:# pragma: no cover
raise web.HTTPNotFound
elif k == "mateName" or k == 'referenceName':
try:
subqueryor["$or"].append(apply_alphanumeric_filter(self, {}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value=v
), collection))
), collection, dataset))
except KeyError:# pragma: no cover
raise web.HTTPNotFound
elif k != 'filters':
try:
query["$and"].append(apply_alphanumeric_filter(self, {}, AlphanumericFilter(
id=VARIANTS_PROPERTY_MAP[k],
value=v
), collection))
), collection, dataset))
except KeyError:# pragma: no cover
raise web.HTTPNotFound

Expand Down
4 changes: 2 additions & 2 deletions beacon/connections/mongo/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def get_runs(self, entry_id: Optional[str], qparams: RequestParams, dataset: str
collection = 'runs'
mongo_collection = client.beacon.runs
parameters_as_filters=False
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query, parameters_as_filters = apply_request_parameters(self, {}, qparams, dataset)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query={}
Expand Down

0 comments on commit d9ff62a

Please sign in to comment.