Tuple to dataclass - #2
Conversation
…write degenerate in the same flow.
| raise IndexError(f'Position {position} exceeds locus length.') | ||
|
|
||
| :arg int coordinate: Coordinate. | ||
| def to_position(self, coord: Coord) -> Point: |
There was a problem hiding this comment.
Change function name to to_point ?
| self._inverted = inverted | ||
| self.boundary = location[0], location[1] - 1 | ||
| self._end = self.boundary[1] - self.boundary[0] | ||
| self._end = location[1] - location[0] # one-based length of the locus |
There was a problem hiding this comment.
Maybe better with name self._range?
|
|
||
| def __post_init__(self) -> None: | ||
| LocusPoint.__post_init__(self) | ||
| if self.region not in ("", "u", "d"): |
| self._orientation = -1 if inverted else 1 | ||
| self._offsets = _offsets(locations, self._orientation) | ||
| # one-based length of the MultiLocus | ||
| self._end = sum(end - start for start, end in locations) |
There was a problem hiding this comment.
self._end or self._range
|
|
||
| def _direction(self, index): | ||
| def _validate_point(self, index: int, position: int, offset: int, region: str) -> None: | ||
| """Validate if a multi locus Point is valid under HGVS rules. |
There was a problem hiding this comment.
Validate the position, offset and region values relatively to multi locus information.
| :arg int offset: Offset. | ||
| :arg str region: Region. | ||
| """ | ||
| if region == 'u': |
There was a problem hiding this comment.
How about split the function to make it less complex.
| if offset != 0 and position not in (0, self._end - 1): | ||
| raise ValueError(f'Position {position} is not at a locus boundary.') | ||
| if offset < 0 and position != 0: | ||
| raise IndexError(f'Offset {offset} should be at a locus start.') |
There was a problem hiding this comment.
IndexError or ValueError
| _check_int(self.offset) | ||
| if self.region not in self.allowed_regions: | ||
| raise ValueError( | ||
| f'Region {self.region} is invalid, it must be a string from {self.allowed_regions}.' |
There was a problem hiding this comment.
Display the region strings without list.
|
|
||
| b0 = self._noncoding.to_position(cds[0]) | ||
| b1 = self._noncoding.to_position(cds[1]) | ||
| cds_start = self._noncoding.to_position(Coord(cds[0])) |
| b1 = self._noncoding.to_position(cds[1]) | ||
| cds_start = self._noncoding.to_position(Coord(cds[0])) | ||
| cds_end = self._noncoding.to_position(Coord(cds[1] - 1)) | ||
| exon_start = self._noncoding.to_position(Coord(locations[0][0])) |
There was a problem hiding this comment.
transcript_start/end?
| region = noncoding_point.region | ||
|
|
||
| if region == 'u': | ||
| if self._exons[0] == self._coding[0]: |
There was a problem hiding this comment.
explain for missing 5'/ 3' UTR
| if region == 'u': | ||
| position = 1 | ||
| if region == 'd': | ||
| if self._coding[1] == self._exons[1]: |
There was a problem hiding this comment.
if position in upstream and downstream has been checked at the crossmapper level, maybe the downstream position assigning can be simplified as position = self._exons[1]? the same as the upstream.
Pull Request Details
Refactor the crossmapper position API from tuple-based values to typed dataclasses, adding validation for dataclass values and class initialization inputs.
Coord,Locus.Point,MultiLocus.Point,GenomicPoint,NonCodingPoint,CodingPoint, andProteinPointdataclasses.Breaking Changes:
Validation
locus,multi_locus, andcrossmapper.