Skip to content

Commit

Permalink
spreading all types of resultset responses
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Oct 10, 2024
1 parent c79d6ea commit d65a7c7
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 100 deletions.
6 changes: 0 additions & 6 deletions beacon/connections/mongo/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def get_analyses(self, entry_id: Optional[str], qparams: RequestParams, dataset:
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100
if include not in ['ALL', 'NONE']:
include = 'ALL'
idq="biosampleId"
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
Expand All @@ -49,8 +47,6 @@ def get_analysis_with_id(self, entry_id: Optional[str], qparams: RequestParams,
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -70,8 +66,6 @@ def get_variants_of_analysis(self, entry_id: Optional[str], qparams: RequestPara
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
idq="caseLevelData.biosampleId"
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
10 changes: 0 additions & 10 deletions beacon/connections/mongo/biosamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def get_biosamples(self, entry_id: Optional[str], qparams: RequestParams, datase
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100
if include not in ['ALL', 'NONE']:
include = 'ALL'
idq="id"
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
Expand All @@ -49,8 +47,6 @@ def get_biosample_with_id(self, entry_id: Optional[str], qparams: RequestParams,
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -67,8 +63,6 @@ def get_variants_of_biosample(self, entry_id: Optional[str], qparams: RequestPar
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="caseLevelData.biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -84,8 +78,6 @@ def get_analyses_of_biosample(self, entry_id: Optional[str], qparams: RequestPar
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
idq="biosampleId"
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
Expand All @@ -102,8 +94,6 @@ def get_runs_of_biosample(self, entry_id: Optional[str], qparams: RequestParams,
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
idq="biosampleId"
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
10 changes: 0 additions & 10 deletions beacon/connections/mongo/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def get_individuals_of_cohort(self, entry_id: Optional[str], qparams: RequestPar
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -88,8 +86,6 @@ def get_analyses_of_cohort(self, entry_id: Optional[str], qparams: RequestParams
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand Down Expand Up @@ -127,8 +123,6 @@ def get_variants_of_cohort(self,entry_id: Optional[str], qparams: RequestParams,
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="caseLevelData.biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -150,8 +144,6 @@ def get_runs_of_cohort(self, entry_id: Optional[str], qparams: RequestParams, da
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -173,7 +165,5 @@ def get_biosamples_of_cohort(self, entry_id: Optional[str], qparams: RequestPara
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
10 changes: 0 additions & 10 deletions beacon/connections/mongo/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def get_variants_of_dataset(self, entry_id: Optional[str], qparams: RequestParam
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -122,8 +120,6 @@ def get_biosamples_of_dataset(self, entry_id: Optional[str], qparams: RequestPar
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -146,8 +142,6 @@ def get_individuals_of_dataset(self, entry_id: Optional[str], qparams: RequestPa
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -170,8 +164,6 @@ def get_runs_of_dataset(self, entry_id: Optional[str], qparams: RequestParams, d
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
list_of_records = (
[r for r in docs] if docs else []
Expand All @@ -197,7 +189,5 @@ def get_analyses_of_dataset(self, entry_id: Optional[str], qparams: RequestParam
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
4 changes: 4 additions & 0 deletions beacon/connections/mongo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def cross_query(self, query: dict, scope: str, collection: str, request_paramete
def apply_filters(self, query: dict, filters: List[dict], collection: str, query_parameters: dict) -> dict:
request_parameters = query_parameters
total_query={}
LOG.debug(filters)
LOG.debug(query_parameters)
if len(filters) >= 1:
total_query["$and"] = []
if query != {} and request_parameters == {}:
Expand Down Expand Up @@ -385,6 +387,8 @@ def apply_filters(self, query: dict, filters: List[dict], collection: str, query
if total_query["$and"] == [{'$or': []}] or total_query['$and'] == []:
total_query = {}
if total_query == {} and query != {}:
LOG.debug('ene')
LOG.debug(query)
total_query=query
return total_query

Expand Down
87 changes: 57 additions & 30 deletions beacon/connections/mongo/g_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from beacon.response.schemas import DefaultSchemas
from beacon.connections.mongo.__init__ import client
from beacon.connections.mongo.utils import get_docs_by_response_type
from beacon.logs.logs import log_with_args
from beacon.logs.logs import log_with_args, LOG
from beacon.conf.conf import level
from beacon.connections.mongo.filters import apply_filters
from beacon.connections.mongo.request_parameters import apply_request_parameters
Expand Down Expand Up @@ -63,21 +63,24 @@ 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, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
query = apply_filters(self, query, qparams.query.filters, collection,query_parameters)
biosample_ids = client.beacon.genomicVariations \
.find_one(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_id=biosample_ids["caseLevelData"]
.find(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_ids=list(biosample_ids)
biosample_id=biosample_ids[0]["caseLevelData"]
try:
finalid=biosample_id[0]["biosampleId"]
finalids=[]
for bioid in biosample_id:
finalids.append({"id": bioid})
except Exception:# pragma: no cover
finalid=biosample_id["biosampleId"]
query = {"id": finalid}
finalids=[]
query = {"$and": [{"$or": finalids}]}
query = apply_filters(self, query, qparams.query.filters, collection, {})
schema = DefaultSchemas.BIOSAMPLES
include = qparams.query.include_resultset_responses
Expand All @@ -94,21 +97,24 @@ 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, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
query = apply_filters(self, query, qparams.query.filters, collection,query_parameters)
biosample_ids = client.beacon.genomicVariations \
.find_one(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_id=biosample_ids["caseLevelData"]
.find(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_ids=list(biosample_ids)
biosample_id=biosample_ids[0]["caseLevelData"]
try:
finalid=biosample_id[0]["biosampleId"]
finalids=[]
for bioid in biosample_id:
finalids.append(bioid)
except Exception:# pragma: no cover
finalid=biosample_id["biosampleId"]
query = {"biosampleId": finalid}
finalids=[]
query = {"$and": [{"$or": finalids}]}
query = apply_filters(self, query, qparams.query.filters, collection, {})
schema = DefaultSchemas.RUNS
include = qparams.query.include_resultset_responses
Expand All @@ -125,21 +131,24 @@ 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, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
if parameters_as_filters == True:
query, parameters_as_filters = apply_request_parameters(self, {}, qparams)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
query = apply_filters(self, query, qparams.query.filters, collection,query_parameters)
biosample_ids = client.beacon.genomicVariations \
.find_one(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_id=biosample_ids["caseLevelData"]
.find(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_ids=list(biosample_ids)
biosample_id=biosample_ids[0]["caseLevelData"]
try:
finalid=biosample_id[0]["biosampleId"]
finalids=[]
for bioid in biosample_id:
finalids.append(bioid)
except Exception:# pragma: no cover
finalid=biosample_id["biosampleId"]
query = {"biosampleId": finalid}
finalids=[]
query = {"$and": [{"$or": finalids}]}
query = apply_filters(self, query, qparams.query.filters, collection, {})
schema = DefaultSchemas.ANALYSES
include = qparams.query.include_resultset_responses
Expand All @@ -156,26 +165,44 @@ 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, {}, qparams)
query_parameters, parameters_as_filters = apply_request_parameters(self, query, qparams)
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, query, qparams)# pragma: no cover
query_parameters={}# pragma: no cover
else:
query=query_parameters
query = apply_filters(self, query, qparams.query.filters, collection,query_parameters)
biosample_ids = client.beacon.genomicVariations \
.find_one(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_id=biosample_ids["caseLevelData"]
.find(query, {"caseLevelData.biosampleId": 1, "_id": 0})
biosample_ids=list(biosample_ids)
biosample_id=biosample_ids[0]["caseLevelData"]
try:
finalid=biosample_id[0]["biosampleId"]
finalids=[]
for bioid in biosample_id:
finalids.append(bioid["biosampleId"])
except Exception:# pragma: no cover
finalid=biosample_id["biosampleId"]
query = {"id": finalid}
finalids=[]
finalquery={}
finalquery["$or"]=[]
for finalid in finalids:
query = {"id": finalid}
finalquery["$or"].append(query)
individual_id = client.beacon.biosamples \
.find_one(query, {"individualId": 1, "_id": 0})
finalid=individual_id["individualId"]
query = {"id": finalid}
query = apply_filters(self, query, qparams.query.filters, collection, {})
.find(finalquery, {"individualId": 1, "_id": 0})
try:
finalids=[]
for indid in individual_id:
finalids.append(indid["individualId"])
except Exception:# pragma: no cover
finalids=[]
finalquery={}
finalquery["$or"]=[]
for finalid in finalids:
query = {"id": finalid}
finalquery["$or"].append(query)
superfinalquery={}
superfinalquery["$and"]=[finalquery]
query = apply_filters(self, superfinalquery, qparams.query.filters, collection, {})
schema = DefaultSchemas.INDIVIDUALS
include = qparams.query.include_resultset_responses
limit = qparams.query.pagination.limit
Expand Down
8 changes: 0 additions & 8 deletions beacon/connections/mongo/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def get_individuals(self, entry_id: Optional[str], qparams: RequestParams, datas
if limit > 100 or limit == 0:
limit = 100
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -50,8 +48,6 @@ def get_individual_with_id(self, entry_id: Optional[str], qparams: RequestParams
skip = qparams.query.pagination.skip
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -73,8 +69,6 @@ def get_variants_of_individual(self, entry_id: Optional[str], qparams: RequestPa
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="caseLevelData.biosampleId"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset

Expand All @@ -92,7 +86,5 @@ def get_biosamples_of_individual(self, entry_id: Optional[str], qparams: Request
if limit > 100 or limit == 0:
limit = 100# pragma: no cover
idq="id"
if include not in ['ALL', 'NONE']:
include = 'ALL'
count, dataset_count, docs = get_docs_by_response_type(self, include, query, dataset, limit, skip, mongo_collection, idq)
return schema, count, dataset_count, docs, dataset
Loading

0 comments on commit d65a7c7

Please sign in to comment.