Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving indexes #390

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading