# Class ReadsBundle<T extends IOPath>

java.lang.Object
htsjdk.beta.io.bundle.Bundle
htsjdk.beta.plugin.reads.ReadsBundle<T>

Type Parameters:
  `T` - The type to use when creating a `ReadsBundle` new IOPathResources for a `ReadsBundle`. Note that resources that are put into a `ReadsBundle` using the {`ReadsBundle(Collection)`} constructor may have tIOPathResources that do not conform to this type.

All Implemented Interfaces:
  `Serializable, Iterable<BundleResource>`

public class ReadsBundle<T extends IOPath> extends Bundle implements Serializable
A class for creating a `Bundle` for reads and reads-related resources. A `ReadsBundle` has a primary resource with content type `BundleResourceType.CT_ALIGNED_READS`; and an optional index resource. ReadsBundles can also contain other resources. `ReadsBundle` is primarily a convenience layer for the common case where a `Bundle` contains reads and related resources backed by `IOPathResource`s. It provides convenient constructors, and validation for JSON interconversions. For reads sources that are backed by streams or other `BundleResource` types, the `Bundle` and `BundleBuilder` classes can be used directly.

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ReadsBundle(Collection<BundleResource> resources)`
Create a `ReadsBundle` using the resources in an existing bundle.
``
`ReadsBundle(T reads)`
Create a `ReadsBundle` containing only a reads resource.
``
`ReadsBundle(T reads, T index)`
Create a `ReadsBundle` containing only reads and an index.

## Method Summary

Modifier and Type
Method
Description
`Optional<BundleResource>`
`getIndex()`
Get the optional `BundleResourceType.CT_READS_INDEX` resource for this `ReadsBundle`.
`BundleResource`
`getReads()`
return the `BundleResourceType.CT_ALIGNED_READS` `BundleResource` for this `ReadsBundle`
`static ReadsBundle<IOPath>`
`getReadsBundleFromPath(IOPath jsonPath)`
Create a `ReadsBundle` from a JSON string contained in jsonPath.
`static ReadsBundle<IOPath>`
`getReadsBundleFromString(String jsonString)`
Create a `ReadsBundle` from a JSON string.
`static <T extends IOPath>
ReadsBundle<T>`
`getReadsBundleFromString(String jsonString, Function<String,T> ioPathConstructor)`
Create a `ReadsBundle` from a JSON string with all IOPathResources using an IOPath-derived class of type `T`.
`static ReadsBundle<IOPath>`
`resolveIndex(IOPath reads)`
Find the companion index for a reads source, and create a new `ReadsBundle` containing the reads and the companion index, if one can be found.
`static <T extends IOPath>
ReadsBundle<T>`
`resolveIndex(T reads, Function<String,T> ioPathConstructor)`
Find the companion index for a reads source, and create a new `ReadsBundle` containing the reads and the companion index, if one can be found.

### Methods inherited from class Bundle

`equals, equalsIgnoreOrder, get, getOrThrow, getPrimaryContentType, getPrimaryResource, getResources, hashCode, iterator, toString`

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface Iterable

`forEach, spliterator`

## Constructor Details

### ReadsBundle

public ReadsBundle(T reads)
Create a `ReadsBundle` containing only a reads resource.

Parameters:
  `reads` - An `IOPath`-derived object that represents a source of reads.

### ReadsBundle

public ReadsBundle(T reads, T index)
Create a `ReadsBundle` containing only reads and an index.

Parameters:
  `reads` - An `IOPath`-derived object that represents a source of reads.

### ReadsBundle

protected ReadsBundle(Collection<BundleResource> resources)
Create a `ReadsBundle` using the resources in an existing bundle. A resource with content type `BundleResourceType.CT_ALIGNED_READS` must be present in the resources, or this constructor will throw. Note that this constructor allows existing `IOPathResource`s that do not conform to the type `T` to be included in the resulting `ReadsBundle`.

Parameters:
  `resources` - collection of `BundleResource`. the collection must include a resource with content type `BundleResourceType.CT_ALIGNED_READS`.
Throws:
  `IllegalArgumentException` - if no resource with content type `BundleResourceType.CT_ALIGNED_READS` is included in the input `BundleResource` collection

## Method Details

### getReads

public BundleResource getReads()
return the `BundleResourceType.CT_ALIGNED_READS` `BundleResource` for this `ReadsBundle`

Returns:
  the `BundleResourceType.CT_ALIGNED_READS` `BundleResource` for this `ReadsBundle`

### getIndex

public Optional<BundleResource> getIndex()
Get the optional `BundleResourceType.CT_READS_INDEX` resource for this `ReadsBundle`.

Returns:
  the optional `BundleResourceType.CT_READS_INDEX` resrouce for this `ReadsBundle`, or Optional.empty if no index resource is present in the bundle.

### getReadsBundleFromPath

public static ReadsBundle<IOPath> getReadsBundleFromPath(IOPath jsonPath)
Create a `ReadsBundle` from a JSON string contained in jsonPath.

Parameters:
  `jsonPath` - the path to a file that contains `Bundle` serialized to JSON. The bundle must contain a resource with content type READS.
Returns:
  a `ReadsBundle` created from jsonPath

### getReadsBundleFromString

public static ReadsBundle<IOPath> getReadsBundleFromString(String jsonString)
Create a `ReadsBundle` from a JSON string.

Parameters:
  `jsonString` - the jsonString to use to create the `ReadsBundle`
Returns:
  a `ReadsBundle`

### getReadsBundleFromString

public static <T extends IOPath> ReadsBundle<T> getReadsBundleFromString(String jsonString, Function<String,T> ioPathConstructor)
Create a `ReadsBundle` from a JSON string with all IOPathResources using an IOPath-derived class of type `T`.

Type Parameters:
  `T` - the type of
Parameters:
  `jsonString` - the string to use to create the `ReadsBundle`
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type `T`
Returns:
  a newly created `ReadsBundle`

### resolveIndex

public static ReadsBundle<IOPath> resolveIndex(IOPath reads)
Find the companion index for a reads source, and create a new `ReadsBundle` containing the reads and the companion index, if one can be found.

Parameters:
  `reads` - the reads source to use
Returns:
  a `ReadsBundle` containing reads and companion index, if it can be found

### resolveIndex

public static <T extends IOPath> ReadsBundle<T> resolveIndex(T reads, Function<String,T> ioPathConstructor)
Find the companion index for a reads source, and create a new `ReadsBundle` containing the reads and the companion index, if one can be found. An index can only be resolved for an IOPath that represents on a file system for which an NIO provider is installed. Remote paths that use a protocol scheme for which no NIO file system is available will (silently) not be resolved.

Type Parameters:
  `T` - the IOPath-derived type of the IOPathResources in the new bundle
Parameters:
  `reads` - the reads source to use
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type <T>
Returns:
  a `ReadsBundle` containing reads and companion index, if it can be found