Skip to content

Commit

Permalink
Merge pull request #390 from EGA-archive/genomic_queries
Browse files Browse the repository at this point in the history
Improving indexes
  • Loading branch information
costero-e authored Nov 15, 2024
2 parents ccbe815 + 53d9338 commit 29ce1f2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
10 changes: 6 additions & 4 deletions beacon/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
#client.beacon.genomicVariations.create_index([("$**", "text")])
#client.beacon.genomicVariations.create_index([("caseLevelData.biosampleId", 1)])
#client.beacon.genomicVariations.create_index([("variation.location.interval.end.value", -1), ("variation.location.interval.start.value", 1)])
client.beacon.genomicVariations.create_index([("variantInternalId", 1), ("caseLevelData.biosampleId", 1)])
#client.beacon.genomicVariations.create_index([("identifiers.genomicHGVSId", 1), ("variation.location.interval.start.value", 1), ("caseLevelData.biosampleId", 1), ("variation.referenceBases", 1), ("variation.alternateBases", 1)])
client.beacon.genomicVariations.create_index([("variation.location.interval.end.value", -1), ("variation.location.interval.start.value", 1), ("variation.referenceBases", 1), ("variation.alternateBases", 1)])
client.beacon.genomicVariations.create_index([("molecularAttributes.geneIds", 1), ("variantInternalId", 1), ("variation.variantType", 1)])
client.beacon.genomicVariations.create_index([("variantInternalId", 1)])
client.beacon.genomicVariations.create_index([("variation.location.interval.start.value", 1)])
#client.beacon.genomicVariations.create_index([("variation.location.interval.start.value", 1), ("variation.location.interval.end.value", -1)])
client.beacon.genomicVariations.create_index([("identifiers.genomicHGVSId", 1)])
#client.beacon.genomicVariations.create_index([("datasetId", 1), ("variation.location.interval.start.value", 1), ("variation.referenceBases", 1), ("variation.alternateBases", 1)])
client.beacon.genomicVariations.create_index([("molecularAttributes.geneIds", 1), ("variation.variantType", 1)])
#client.beacon.individuals.create_index([("$**", "text")])
#client.beacon.runs.create_index([("$**", "text")])
#collection_name = client.beacon.analyses
Expand Down
58 changes: 49 additions & 9 deletions beacon/request/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
ValidationError,
field_validator,
Field,
PrivateAttr)
PrivateAttr,
model_validator)
from strenum import StrEnum
from typing import List, Optional, Union
from beacon import conf
Expand Down Expand Up @@ -95,17 +96,30 @@ class RequestParams(CamelModel):

class SequenceQuery(BaseModel):
referenceName: Union[str,int]
start: Union[int, list, str]
start: int
alternateBases:str
referenceBases: str
clinicalRelevance: Optional[str] =None
mateName: Optional[str] =None
assemblyId: Optional[str] =None
@model_validator(mode='after')
@classmethod
def referenceName_must_have_assemblyId_if_not_HGVSId(cls, values):
if values.referenceName in ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','X','Y','MT',1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]:
try:
if values.assemblyId == None:
raise ValueError
else:
pass
except Exception as e:
raise ValueError
else:
raise ValueError

class RangeQuery(BaseModel):
referenceName: Union[str,int]
start: Union[int, str, list]
end: Union[int, str, list]
start: int
end: int
variantType: Optional[str] =None
alternateBases: Optional[str] =None
aminoacidChange: Optional[str] =None
Expand All @@ -114,6 +128,22 @@ class RangeQuery(BaseModel):
clinicalRelevance: Optional[str] =None
mateName: Optional[str] =None
assemblyId: Optional[str] =None
@model_validator(mode='after')
@classmethod
def referenceName_must_have_assemblyId_if_not_HGVSId_2(cls, values):
if values.referenceName in ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','X','Y','MT',1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]:
try:
if values.assemblyId == None:
raise ValueError
else:
pass
except Exception as e:
raise ValueError
else:
raise ValueError

class DatasetsRequested(BaseModel):
datasets: list

class GeneIdQuery(BaseModel):
geneId: str
Expand All @@ -122,7 +152,6 @@ class GeneIdQuery(BaseModel):
aminoacidChange: Optional[str] =None
variantMinLength: Optional[int] =None
variantMaxLength: Optional[int] =None
assemblyId: Optional[str] =None

class BracketQuery(BaseModel):
referenceName: Union[str,int]
Expand All @@ -135,28 +164,39 @@ class BracketQuery(BaseModel):
@field_validator('start')
@classmethod
def start_must_be_array_of_integers(cls, v: list) -> list:
for num in v:
for num in v:# pragma: no cover
if isinstance(num, int):
pass
else:
raise ValueError
@field_validator('end')
@classmethod
def end_must_be_array_of_integers(cls, v: list) -> list:
for num in v:
for num in v:# pragma: no cover
if isinstance(num, int):
pass
else:
raise ValueError
@model_validator(mode='after')
@classmethod
def referenceName_must_have_assemblyId_if_not_HGVSId_3(cls, values):
if values.referenceName in ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','X','Y','MT',1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]:
try:
if values.assemblyId == None:
raise ValueError
else:
pass
except Exception as e:
raise ValueError
else:
raise ValueError

class GenomicAlleleQuery(BaseModel):
genomicAlleleShortForm: str
assemblyId: Optional[str] =None

class AminoacidChangeQuery(BaseModel):
aminoacidChange: str
geneId: str
assemblyId: Optional[str] =None

class RequestParams(CamelModel):
meta: RequestMeta = RequestMeta()
Expand Down

0 comments on commit 29ce1f2

Please sign in to comment.