Skip to content

bigdatagenomics/convert

Repository files navigation

convert

Maven Central API Documentation

Hacking convert

Install

To build

$ mvn install

About convert

The Converter interface, inspired by Apache Commons Convert (sandbox component, never released), provides for converting from a source type S to a target type T, with a conversion stringency and SLF4J logger given as context.

public interface Converter<S, T> {
  T convert(S source, ConversionStringency stringency, Logger logger) throws ConversionException;
  // ...
}

Rather than implement a custom converter registry, convert relies on dependency injection via Google Guice.

Use the @Inject annotation to inject converters into class constructors:

final class MyClass {
  private final Converter<String, OntologyTerm ontologyTermConverter;
  private final ConversionStringency stringency = ConversionStringency.STRICT;
  private static final logger = LoggerFactory.getLogger(MyClass.class);

  @Inject
  MyClass(final Converter<String, OntologyTerm> ontologyTermConverter) {
    this.ontologyTermConverter = ontologyTermConverter;
  }

  void doIt() {
    OntologyTerm ontologyTerm = ontologyTermConverter.convert("SO:0000110", stringency, logger);
  }
}

The Guice injector handles construction of the converter instances, managing nested converter dependencies as necessary (if say, a Gff3Record to Feature converter depends on a String to Strand converter).

Some converters may require late bindings; for those a converter factory is available via injection:

final class MyClass {
  private final AlignmentRecordToSamRecordFactory alignmentRecordToSamRecordFactory;
  private final ConversionStringency stringency = ConversionStringency.STRICT;
  private static final logger = LoggerFactory.getLogger(MyClass.class);

  @Inject
  MyClass(final AlignmentRecordToSamRecordFactory alignmentRecordToSamRecordFactory) {
    this.alignmentRecordToSamRecordFactory = alignmentRecordToSamRecordFactory;
  }

  void doIt() {
    AlignmentRecord alignmentRecord = ...;
    SAMFileHeader header = ...;
    Converter<AlignmentRecord, SAMRecord> converter = alignmentRecordToSamRecordFactory.create(header);
    SAMRecord record = converter.convert(alignmentRecord, stringency, logger);
  }
}

About

Conversions to and from Big Data Genomics Avro Formats. Apache 2 licensed.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages