Package htsjdk.beta.plugin.variants

# Class VariantsBundle

java.lang.Object
htsjdk.beta.io.bundle.Bundle
htsjdk.beta.plugin.variants.VariantsBundle

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

public class VariantsBundle extends Bundle implements Serializable
A `Bundle` for variants and variants-related resources that are backed by on disk files. A `VariantsBundle` has a primary resource with content type `BundleResourceType.CT_VARIANT_CONTEXTS`; and an optional index resource. A VariantsBundle can also contain additional resources. Note that this class is merely a convenience class for the case where the variants are backed by files on disk. A bundle that contains variants and related resources can be created manually using the `Bundle` class. This class provides convenient constructors, and validation for JSON interconversions. To create a VariantsBundle for variants sources that are backed by streams or other `BundleResource` types, the `Bundle` and `BundleBuilder` classes can be used to construct such bundles directly.

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`VariantsBundle(IOPath vcfPath)`
Create a `VariantsBundle` containing only a variants resource.
`VariantsBundle(IOPath vcfPath, IOPath indexPath)`
Create a `VariantsBundle` containing only variants and an index.
`VariantsBundle(Collection<BundleResource> resources)`
Create a `VariantsBundle` using the resources in an existing bundle.

## Method Summary

Modifier and Type
Method
Description
`Optional<BundleResource>`
`getIndex()`
Get the optional `BundleResourceType.CT_VARIANTS_INDEX` resource for this `VariantsBundle`.
`BundleResource`
`getVariants()`
`static VariantsBundle`
`getVariantsBundleFromPath(IOPath jsonPath)`
Create a `VariantsBundle` from a JSON string contained in jsonPath.
`static <T extends IOPath>
VariantsBundle`
`getVariantsBundleFromPath(IOPath jsonPath, Function<String,T> ioPathConstructor)`
Create a `VariantsBundle` from a JSON string contained in jsonPath.
`static VariantsBundle`
`getVariantsBundleFromString(String jsonString)`
Create a `VariantsBundle` from a JSON string.
`static <T extends IOPath>
VariantsBundle`
`getVariantsBundleFromString(String jsonString, Function<String,T> ioPathConstructor)`
Create a `VariantsBundle` from a JSON string with all IOPathResources using an IOPath-derived class of type `T`.
`static Optional<IOPath>`
`resolveIndex(IOPath variants)`
Find the companion index for a variants source, and create a new `VariantsBundle` containing the variants and the companion index, if one can be found.
`static <T extends IOPath>
Optional<T>`
`resolveIndex(T variantsHtsPath, Function<String,T> ioPathConstructor)`
Attempts to find the companion index for a variants source based on commonly used file extensions, and create a new `VariantsBundle` containing the variants and the companion index, if one can be found.

### Methods inherited from class htsjdk.beta.io.bundle.Bundle

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

### Methods inherited from class java.lang.Object

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Constructor Details

### VariantsBundle

public VariantsBundle(IOPath vcfPath)
Create a `VariantsBundle` containing only a variants resource.

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

### VariantsBundle

public VariantsBundle(IOPath vcfPath, IOPath indexPath)
Create a `VariantsBundle` containing only variants and an index.

Parameters:
  `vcfPath` - An `IOPath`-derived object that represents a source of variants.
  `indexPath` - An `IOPath`-derived object that represents the companion index for `vcfPath`.

### VariantsBundle

public VariantsBundle(Collection<BundleResource> resources)
Create a `VariantsBundle` using the resources in an existing bundle. A resource with content type `BundleResourceType.CT_VARIANT_CONTEXTS` must be present in the resources, or this constructor will throw.

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

## Method Details

### getVariants

public BundleResource getVariants()

Returns:
  the `BundleResourceType.CT_VARIANT_CONTEXTS` `BundleResource` for this `VariantsBundle`

### getIndex

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

Returns:
  the optional `BundleResourceType.CT_VARIANTS_INDEX` resource for this `VariantsBundle`, or Optional.empty() if no index resource is present in the bundle.

### getVariantsBundleFromPath

public static VariantsBundle getVariantsBundleFromPath(IOPath jsonPath)
Create a `VariantsBundle` from a JSON string contained in jsonPath.

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

### getVariantsBundleFromPath

public static <T extends IOPath> VariantsBundle getVariantsBundleFromPath(IOPath jsonPath, Function<String,T> ioPathConstructor)
Create a `VariantsBundle` from a JSON string contained in jsonPath.

Type Parameters:
  `T` - the IOPath-derived type of the IOPathResources to be used in the new bundle
Parameters:
  `jsonPath` - the path to a file that contains a `Bundle` serialized to JSON. The bundle must contain a resource with content type VARIANT_CONTEXTS.
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type `T`
Returns:
  a `VariantsBundle` created from jsonPath

### getVariantsBundleFromString

public static VariantsBundle getVariantsBundleFromString(String jsonString)
Create a `VariantsBundle` from a JSON string.

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

### getVariantsBundleFromString

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

Type Parameters:
  `T` - the IOPath-derived type of the IOPathResources to be used in the new bundle
Parameters:
  `jsonString` - the string to use to create the `VariantsBundle`
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type `T`
Returns:
  a newly created `VariantsBundle`

### resolveIndex

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

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

### resolveIndex

public static <T extends IOPath> Optional<T> resolveIndex(T variantsHtsPath, Function<String,T> ioPathConstructor)
Attempts to find the companion index for a variants source based on commonly used file extensions, and create a new `VariantsBundle` containing the variants and the companion index, if one can be found. An index can only be resolved for an IOPath that represents a file 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 IOPath to be returned
Parameters:
  `variantsHtsPath` - the IOPath-derived object representing the variants source to use
  `ioPathConstructor` - a function that takes a string and returns an IOPath-derived class of type <T>
Returns:
  a `IOPath`-derived object of type T containing the companion index for `variantsPath`, if it can be found