Skip to content

Commit

Permalink
Implements collections of bundles. (#1702)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnbroad authored Aug 13, 2024
1 parent 9e89d3c commit 204a0db
Show file tree
Hide file tree
Showing 49 changed files with 909 additions and 482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FASTADecoderV1_0 implements HaploidReferenceDecoder {
public FASTADecoderV1_0(final Bundle inputBundle) {
this.inputBundle = inputBundle;
this.displayName = inputBundle.getPrimaryResource().getDisplayName();
final BundleResource referenceResource = inputBundle.getOrThrow(BundleResourceType.HAPLOID_REFERENCE);
final BundleResource referenceResource = inputBundle.getOrThrow(BundleResourceType.CT_HAPLOID_REFERENCE);
if (referenceResource.getIOPath().isPresent()) {
referenceSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(
referenceResource.getIOPath().get().toPath(), true);
Expand Down Expand Up @@ -129,7 +129,7 @@ public void close() {
* @return true if input {@link Bundle} contains a reads index resource
*/
private static boolean bundleContainsIndex(final Bundle inputBundle) {
return inputBundle.get(BundleResourceType.READS_INDEX).isPresent();
return inputBundle.get(BundleResourceType.CT_READS_INDEX).isPresent();
}

}
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/beta/codecs/reads/ReadsCodecUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public static SamInputResource bundleToSamInputResource(
final ReadsDecoderOptions readsDecoderOptions) {
final SamInputResource samInputResource = readsToSamInputResource(
inputBundle,
BundleResourceType.ALIGNED_READS,
BundleResourceType.CT_ALIGNED_READS,
readsDecoderOptions);
indexToSamInputResource(
inputBundle,
BundleResourceType.READS_INDEX,
BundleResourceType.CT_READS_INDEX,
readsDecoderOptions,
samInputResource);
return samInputResource;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static void readsDecoderOptionsToSamReaderFactory(
*/
@InternalAPI
public static boolean bundleContainsIndex(final Bundle inputBundle) {
return inputBundle.get(BundleResourceType.READS_INDEX).isPresent();
return inputBundle.get(BundleResourceType.CT_READS_INDEX).isPresent();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/beta/codecs/reads/bam/BAMCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_BAM} codecs.
* Base class for {@link BundleResourceType#FMT_READS_BAM} codecs.
*/
@InternalAPI
public abstract class BAMCodec implements ReadsCodec {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/beta/codecs/reads/bam/BAMDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_BAM} decoders.
* Base class for {@link BundleResourceType#FMT_READS_BAM} decoders.
*/
@InternalAPI
public abstract class BAMDecoder implements ReadsDecoder {
Expand All @@ -21,7 +21,7 @@ public abstract class BAMDecoder implements ReadsDecoder {

/**
* Create a BAM decoder for the given input bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS}, and the resource must be an
* have content type {@link BundleResourceType#CT_ALIGNED_READS}, and the resource must be an
* appropriate format and version for this encoder (to find an encoder for a bundle, see
* {@link htsjdk.beta.plugin.registry.ReadsResolver}.
*
Expand All @@ -34,7 +34,7 @@ public BAMDecoder(final Bundle inputBundle, final ReadsDecoderOptions readsDecod
ValidationUtils.nonNull(readsDecoderOptions, "readsDecoderOptions");

this.inputBundle = inputBundle;
this.displayName = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
this.readsDecoderOptions = readsDecoderOptions;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/beta/codecs/reads/bam/BAMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_BAM} encoders.
* Base class for {@link BundleResourceType#FMT_READS_BAM} encoders.
*/
public abstract class BAMEncoder implements ReadsEncoder {
private final Bundle outputBundle;
Expand All @@ -21,7 +21,7 @@ public abstract class BAMEncoder implements ReadsEncoder {
* InternalAPI
*
* Create a BAM encoder for the given output bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* NOTE: callers that provide an output stream resource should provide a buffered output stream
Expand All @@ -36,7 +36,7 @@ public BAMEncoder(final Bundle outputBundle, final ReadsEncoderOptions readsEnco

this.outputBundle = outputBundle;
this.readsEncoderOptions = readsEncoderOptions;
this.displayName = outputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = outputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class BAMDecoderV1_0 extends BAMDecoder {

/**
* Create a V1.0 BAM decoder for the given input bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS}, and the resource must be an
* have content type {@link BundleResourceType#CT_ALIGNED_READS}, and the resource must be an
* appropriate format and version for this encoder (to find an encoder for a bundle, see
* {@link htsjdk.beta.plugin.registry.ReadsResolver}.
* {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param inputBundle bundle to decoder
* @param readsDecoderOptions options to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class BAMEncoderV1_0 extends BAMEncoder {

/**
* Create a V1.0 BAM encoder for the given output bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param outputBundle bundle to encode
Expand Down Expand Up @@ -87,9 +87,9 @@ private SAMFileWriter getBAMFileWriter(

final boolean preSorted = readsEncoderOptions.isPreSorted();

final BundleResource readsResource = getOutputBundle().getOrThrow(BundleResourceType.ALIGNED_READS);
final Optional<BundleResource> optIndexResource = getOutputBundle().get(BundleResourceType.READS_INDEX);
final Optional<BundleResource> optMD5Resource = getOutputBundle().get(BundleResourceType.MD5);
final BundleResource readsResource = getOutputBundle().getOrThrow(BundleResourceType.CT_ALIGNED_READS);
final Optional<BundleResource> optIndexResource = getOutputBundle().get(BundleResourceType.CT_READS_INDEX);
final Optional<BundleResource> optMD5Resource = getOutputBundle().get(BundleResourceType.CT_MD5);

//TODO: BAMFileWriter currently only supports writing an index to a plain file, so for now
// throw if an index is requested on any other type
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/beta/codecs/reads/cram/CRAMCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_CRAM} codecs.
* Base class for {@link BundleResourceType#FMT_READS_CRAM} codecs.
*/
@InternalAPI
public abstract class CRAMCodec implements ReadsCodec {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/beta/codecs/reads/cram/CRAMDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_CRAM} decoders.
* Base class for {@link BundleResourceType#FMT_READS_CRAM} decoders.
*/
@InternalAPI
public abstract class CRAMDecoder implements ReadsDecoder {
Expand All @@ -57,7 +57,7 @@ public CRAMDecoder(final Bundle inputBundle, final ReadsDecoderOptions readsDeco

this.inputBundle = inputBundle;
this.readsDecoderOptions = readsDecoderOptions;
this.displayName = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();

samReader = getSamReaderForCRAM(inputBundle, readsDecoderOptions);
samFileHeader = samReader.getFileHeader();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/htsjdk/beta/codecs/reads/cram/CRAMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_CRAM} decoders.
* Base class for {@link BundleResourceType#FMT_READS_CRAM} decoders.
*/
@InternalAPI
public abstract class CRAMEncoder implements ReadsEncoder {
Expand All @@ -34,7 +34,7 @@ public abstract class CRAMEncoder implements ReadsEncoder {
* InternalAPI
*
* Create a CRAM encoder for the given output bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param outputBundle bundle to encode
Expand All @@ -47,7 +47,7 @@ public CRAMEncoder(final Bundle outputBundle, final ReadsEncoderOptions readsEnc

this.outputBundle = outputBundle;
this.readsEncoderOptions = readsEncoderOptions;
this.displayName = outputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = outputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
}

@Override
Expand Down Expand Up @@ -128,7 +128,7 @@ private CRAMFileWriter getCRAMWriter(final SAMFileHeader samFileHeader, final Re
// the CRAMFileWriter constructors assume presorted; so if we're presorted, use the CRAMFileWriters
// directly so we can support writing to a stream
if (readsEncoderOptions.isPreSorted()) {
final BundleResource outputResource = outputBundle.getOrThrow(BundleResourceType.ALIGNED_READS);
final BundleResource outputResource = outputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS);
if (outputResource.getIOPath().isPresent()) {
cramFileWriter = new CRAMFileWriter(
outputResource.getIOPath().get().getOutputStream(),
Expand All @@ -149,9 +149,9 @@ private CRAMFileWriter getCRAMWriter(final SAMFileHeader samFileHeader, final Re
final SAMFileWriterFactory samFileWriterFactory = new SAMFileWriterFactory();
final boolean preSorted = readsEncoderOptions.isPreSorted();

final BundleResource readsResource = getOutputBundle().getOrThrow(BundleResourceType.ALIGNED_READS);
final Optional<BundleResource> optIndexResource = getOutputBundle().get(BundleResourceType.READS_INDEX);
final Optional<BundleResource> optMD5Resource = getOutputBundle().get(BundleResourceType.MD5);
final BundleResource readsResource = getOutputBundle().getOrThrow(BundleResourceType.CT_ALIGNED_READS);
final Optional<BundleResource> optIndexResource = getOutputBundle().get(BundleResourceType.CT_READS_INDEX);
final Optional<BundleResource> optMD5Resource = getOutputBundle().get(BundleResourceType.CT_MD5);

//TODO: SamFileWriterFactory code paths currently only support writing an index to a plain file, so
// for now throw if an index is requested on any other type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CRAMDecoderV2_1 extends CRAMDecoder {

/**
* Create a new V2.1 CRAM decoder. The primary resource in the input
* bundle must have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* bundle must have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param bundle the input {@link Bundle} to decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CRAMEncoderV2_1 extends CRAMEncoder {

/**
* Create a CRAM encoder for the given output bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param outputBundle bundle to encode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CRAMDecoderV3_0 extends CRAMDecoder {

/**
* Create a new CRAM V3.0 decoder. The primary resource in the input
* bundle must have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* bundle must have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param bundle input {@link Bundle} to decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CRAMEncoderV3_0 extends CRAMEncoder {

/**
* Create a new CRAM CRAM v3.0 encoder for the given output bundle. The primary resource in the
* bundle must have content type {@link BundleResourceType#ALIGNED_READS} (to find an encoder for a bundle,
* bundle must have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find an encoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* @param outputBundle output {@link Bundle} to encode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* Base class for concrete implementations of reads codecs that handle
* {@link BundleResourceType#READS_HTSGET_BAM} codecs.
* {@link BundleResourceType#FMT_READS_HTSGET_BAM} codecs.
*
* Note: writing to htsget is not supported, so there is no Htsget encoder.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Base class for concrete implementations of reads decoders that handle
* {@link BundleResourceType#READS_HTSGET_BAM} decoding.
* {@link BundleResourceType#FMT_READS_HTSGET_BAM} decoding.
*/
public abstract class HtsgetBAMDecoder implements ReadsDecoder {
private final Bundle inputBundle;
Expand All @@ -19,7 +19,7 @@ public abstract class HtsgetBAMDecoder implements ReadsDecoder {
public HtsgetBAMDecoder(final Bundle inputBundle, final ReadsDecoderOptions readsDecoderOptions) {
this.inputBundle = inputBundle;
this.readsDecoderOptions = readsDecoderOptions;
this.displayName = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import java.util.Optional;

/**
* Version 1.2 of {@link BundleResourceType#READS_HTSGET_BAM} codec.
* Version 1.2 of {@link BundleResourceType#FMT_READS_HTSGET_BAM} codec.
*/
public class HtsgetBAMCodecV1_2 extends HtsgetBAMCodec {

@Override
public HtsgetBAMDecoder getDecoder(final Bundle inputBundle,
final ReadsDecoderOptions decodeOptions) {
final BundleResource readsResource = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS);
final BundleResource readsResource = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS);
final Optional<IOPath> inputPath = readsResource.getIOPath();
if (!inputPath.isPresent()) {
throw new IllegalArgumentException("The reads source must be a IOPath");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import java.util.Optional;

/**
* Version 1.2 of {@link BundleResourceType#READS_HTSGET_BAM} decoder.
* Version 1.2 of {@link BundleResourceType#FMT_READS_HTSGET_BAM} decoder.
*/
public class HtsgetBAMDecoderV1_2 extends HtsgetBAMDecoder {

final HtsgetBAMFileReader htsgetReader;

public HtsgetBAMDecoderV1_2(final Bundle inputBundle, final ReadsDecoderOptions decoderOptions) {
super(inputBundle, decoderOptions);
final BundleResource readsResource = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS);
final BundleResource readsResource = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS);
if (!readsResource.getIOPath().isPresent()) {
throw new IllegalArgumentException(String.format(
"Htsget requires an IOPath input resource. The bundle resource %s doesn't contain the required IOPath.",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/beta/codecs/reads/sam/SAMCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_SAM} codecs.
* Base class for {@link BundleResourceType#FMT_READS_SAM} codecs.
*/
@InternalAPI
public abstract class SAMCodec implements ReadsCodec {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/beta/codecs/reads/sam/SAMDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_SAM} decoders.
* Base class for {@link BundleResourceType#FMT_READS_SAM} decoders.
*/
@InternalAPI
public abstract class SAMDecoder implements ReadsDecoder {
Expand All @@ -21,7 +21,7 @@ public abstract class SAMDecoder implements ReadsDecoder {

/**
* Create a SAM decoder for the given input bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS}, and the resource must be an
* have content type {@link BundleResourceType#CT_ALIGNED_READS}, and the resource must be an
* appropriate format and version for this encoder (to find an encoder for a bundle, see
* {@link htsjdk.beta.plugin.registry.ReadsResolver}.
*
Expand All @@ -33,7 +33,7 @@ public SAMDecoder(final Bundle inputBundle, final ReadsDecoderOptions readsDecod
ValidationUtils.nonNull(inputBundle,"inputBundle");
ValidationUtils.nonNull(readsDecoderOptions, "readsDecoderOptions");
this.inputBundle = inputBundle;
this.displayName = inputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = inputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
this.readsDecoderOptions = readsDecoderOptions;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/beta/codecs/reads/sam/SAMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* InternalAPI
*
* Base class for {@link BundleResourceType#READS_SAM} encoders.
* Base class for {@link BundleResourceType#FMT_READS_SAM} encoders.
*/
public abstract class SAMEncoder implements ReadsEncoder {
private final Bundle outputBundle;
Expand All @@ -20,7 +20,7 @@ public abstract class SAMEncoder implements ReadsEncoder {
* InternalAPI
*
* Create a SAM encoder for the given output bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS} (to find a decoder for a bundle,
* have content type {@link BundleResourceType#CT_ALIGNED_READS} (to find a decoder for a bundle,
* see {@link htsjdk.beta.plugin.registry.ReadsResolver}).
*
* NOTE: callers that provide an output stream resource should provide a buffered output stream
Expand All @@ -32,7 +32,7 @@ public abstract class SAMEncoder implements ReadsEncoder {
public SAMEncoder(final Bundle outputBundle, final ReadsEncoderOptions readsEncoderOptions) {
this.outputBundle = outputBundle;
this.readsEncoderOptions = readsEncoderOptions;
this.displayName = outputBundle.getOrThrow(BundleResourceType.ALIGNED_READS).getDisplayName();
this.displayName = outputBundle.getOrThrow(BundleResourceType.CT_ALIGNED_READS).getDisplayName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SAMDecoderV1_0 extends SAMDecoder {

/**
* Create a V1.0 SAM decoder for the given input bundle. The primary resource in the bundle must
* have content type {@link BundleResourceType#ALIGNED_READS}, and the resource must be an
* have content type {@link BundleResourceType#CT_ALIGNED_READS}, and the resource must be an
* appropriate format and version for this encoder (to find an encoder for a bundle, see
* {@link htsjdk.beta.plugin.registry.ReadsResolver}.
*
Expand Down
Loading

0 comments on commit 204a0db

Please sign in to comment.