Skip to content

Commit 8faa9b9

Browse files
authored
feat: Add start and end validator to TxSegment class (#425)
closes #424
1 parent b75729a commit 8faa9b9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/cool_seq_tool/mappers/exon_genomic_coords.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ class TxSegment(BaseModelForbidExtra):
6969
default=True, description="If the position occurs on an exon"
7070
)
7171

72+
@model_validator(mode="before")
73+
def check_seg_pos(cls, values: dict) -> dict: # noqa: N805
74+
"""Ensure that only one of `start` or `end` is set in the
75+
genomic_location field
76+
77+
:param values: The values in the TxSegment class
78+
:raises ValueError: If `start` and `end` are both set in
79+
`genomic_location`
80+
:return: Values in model
81+
"""
82+
loc = values.get("genomic_location")
83+
start = getattr(loc, "start", None)
84+
end = getattr(loc, "end", None)
85+
if start and end:
86+
err_msg = "Only one of `start` or `end` may be set as this describes the start or end of a transcript segment"
87+
raise ValueError(err_msg)
88+
return values
89+
7290
model_config = ConfigDict(
7391
json_schema_extra={
7492
"example": {

0 commit comments

Comments
 (0)