exomiser / svart

API for use in representing and manipulating genomic variation
7 stars 1 forks source link

A method for normalizing start/end coordinate to a given Strand and CoordinateSystem in one call? #49

Closed ielis closed 3 years ago

ielis commented 3 years ago

@julesjacobsen - how about hanging these methods on GenomicRegion to allow normalizing start/end coordinates to a given strand and coordinate system?

default int startOnStrandAndCoordinateSystem(Strand otherStrand, CoordinateSystem otherSystem) {
    int delta = coordinateSystem().startDelta(otherSystem);
    return strand() == otherStrand
            ? start() + delta
            : Coordinates.invertPosition(coordinateSystem(), end(), contig()) + delta;
}

default int endOnStrandAndCoordinateSystem(Strand otherStrand, CoordinateSystem otherSystem) {
    int delta = coordinateSystem().endDelta(otherSystem);
    return strand() == otherStrand
            ? end() + delta
            : Coordinates.invertPosition(coordinateSystem(), start(), contig()) + delta;
}

The methods above would be used instead of constructs like:

GenomicRegion transcript = ...
GenomicRegion variant = ...

GenomicRegion variantOnStrand = variant.withStrand(transcript.strand()).withCoordinateSystem(transcript.coordinateSystem());
int start

which are necessary if you want to get your hands on the coordinates, either as int or as Position. Until now, I needed to access the coordinates to:

I am thinking whether we need to add this method. On one hand it would fit these use cases, on the other hand we might use the chained .toPositiveStrand().toZeroBased() here and only use the primitive-based methods for tasks like identifying overlaps, distances between regions, etc..

ielis commented 3 years ago

Done