exomiser / svart

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

Add extensible builder to Base classes? #20

Closed julesjacobsen closed 3 years ago

julesjacobsen commented 3 years ago

Again, an Exomiser discovery - I had gone down the route of using the builder pattern for creating variants and it was a bit of a pain to incorporate the svart api into Exomiser using extension, so I created an experimental build to ease integration which enabled this:

    Variant instance = DefaultVariant.builder()
                .contig(chr1)
                .startPosition(startPosition)
                .id(".")
                .ref(ref)
                .alt(alt)
                .endPosition(endPosition)
                .changeLength(changeLength)
     // then can add other class-specific fields here by inheriting from the BaseVariant.Builder
                .build();
julesjacobsen commented 3 years ago

Added in 92533382fd63253d16f62c8155563fd932b83fd4

Codes like this:

Variant instance = TestVariant.builder().with(chr1, "", Strand.POSITIVE, CoordinateSystem.ONE_BASED, Position.of(5), "GA", "T").build();

Given the inter-relatedness of the input fields it wasn't really feasible to add them separately and ensure a consistent state, but it is possible to read in a BED/ UCSC transcript file which uses absolute genomic coordinates (i.e. 0-based, + strand) and indicates the actual strand.

e.g.

chr    start    end    strand
1    100    200    -

can be parsed as

GenomicRegion region = GenomicRegion.builder().with(chr1, "", Strand.POSITIVE, CoordinateSystem.ZERO_BASED, Position.of(100), Position.of(200)).withStrand(Strand.NEGATIVE).build();