blachlylab / dhtslib

D bindings and OOP wrappers for htslib
MIT License
7 stars 1 forks source link

Coordinate/Coordinates improvements #82

Closed charlesgregory closed 3 years ago

charlesgregory commented 3 years ago

Should we have functions for adding/subtracting from a Coordinate and by extension Coordinates? i.e

Coordinate!(Basis.zero) coord = ZB(0);
coord = coord.offset(1);

assert(coord == ZB(1));

coord = coord.offset(-2); // invariant error as value is < 0

For coordinate pairs:

Coordinates!(Coordsystem.zbho) coords = ZBHO(0, 1);

assert(coords.offset(1) = ZBHO(1, 2));
assert(coords.offsetStart(1) = ZBHO(1, 1)); // invariant error as end value == start value
assert(coords.offsetEnd(1) = ZBHO(0, 2)); 

Also thinking of set ops with coordinates.

Coordinates!(Coordsystem.zbho) coords = ZBHO(0, 3);
Coordinates!(Coordsystem.zbho) coords2 = ZBHO(2, 5);

auto newcoords = coords.intersect(coords2);

assert(newcoords == ZBHO(2, 3));

Another thought for improving coordinates.d is allowing the specification of maximum end coordinate. This would require us to store that value but we would gain the ability to check if a coordinate system is invalid due to the end coordinate being too large. This would probably only make sense for ChromCoordinates where a chromosome name is involved.

jblachly commented 3 years ago

It is reasonable, but these types of checks are in the runtime, rather than enforced at compile time , so conceptually they are a little bit different

charlesgregory commented 3 years ago

That is true. Checks for valid coordinates would have to be enforced at run time. A performance hit but likely small or we could have such checks only be present in debug mode.

charlesgregory commented 3 years ago

addressed in #88