Package htsjdk.samtools.cram.ref

# Class ReferenceSource

java.lang.Object
htsjdk.samtools.cram.ref.ReferenceSource

All Implemented Interfaces:
  `CRAMReferenceSource`

public class ReferenceSource extends Object implements CRAMReferenceSource
Used to represent a CRAM reference, the backing source for which can either be a file or the EBI ENA reference service. NOTE: In a future release, this class will be renamed and the functionality it contains will be refactored and distributed into one or more separate reference source implementations, each corresponding to the type of resource backing the reference.

## Constructor Summary

Constructors
Constructor
Description
`ReferenceSource(ReferenceSequenceFile rsFile)`
`ReferenceSource(File file)`
`ReferenceSource(Path path)`

## Method Summary

Modifier and Type
Method
Description
`static CRAMReferenceSource`
`getDefaultCRAMReferenceSource()`
Attempts to construct a default CRAMReferenceSource for use with CRAM files when one has not been explicitly provided.
`int`
`getDownloadTriesBeforeFailing()`
`byte[]`
`getReferenceBases(SAMSequenceRecord record, boolean tryNameVariants)`
Get the reference bases for an entire reference contig.
`byte[]`
`getReferenceBasesByRegion(SAMSequenceRecord sequenceRecord, int zeroBasedStart, int requestedRegionLength)`
Get the reference bases for a region of a reference contig.
`void`
`setDownloadTriesBeforeFailing(int downloadTriesBeforeFailing)`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ReferenceSource

public ReferenceSource(File file)

### ReferenceSource

public ReferenceSource(Path path)

### ReferenceSource

public ReferenceSource(ReferenceSequenceFile rsFile)

## Method Details

### getDefaultCRAMReferenceSource

public static CRAMReferenceSource getDefaultCRAMReferenceSource()
Attempts to construct a default CRAMReferenceSource for use with CRAM files when one has not been explicitly provided.

Returns:
  CRAMReferenceSource if one can be acquired. Guaranteed to not be null if none of the listed exceptions is thrown.
Throws:
  `IllegalArgumentException` - if the reference_fasta environment variable refers to a a file that doesn't exist

  Construct a default reference source to use when an explicit reference has not been provided by checking for fallback sources in this order:

  - Defaults.REFERENCE_FASTA - the value of the system property "reference_fasta". If set, must refer to a valid reference file.
  - ENA Reference Service if it is enabled

### getReferenceBases

public byte[] getReferenceBases(SAMSequenceRecord record, boolean tryNameVariants)
Description copied from interface: `CRAMReferenceSource`
Get the reference bases for an entire reference contig.

Specified by:
  `getReferenceBases` in interface `CRAMReferenceSource`
Parameters:
  `record` - the SAMSequenceRecord identifying the reference being requested
  `tryNameVariants` - if true, attempt to match the requested sequence name against the reference by using common name variations, such as adding or removing a leading "chr" prefix from the requested name. if false, use exact match
Returns:
  the upper-cased, normalized (see `Utils.normalizeBase(byte)`) bases representing the requested sequence, or null if the sequence cannot be found

### getReferenceBasesByRegion

public byte[] getReferenceBasesByRegion(SAMSequenceRecord sequenceRecord, int zeroBasedStart, int requestedRegionLength)
Description copied from interface: `CRAMReferenceSource`
Get the reference bases for a region of a reference contig. If the sequence can be retrieved, but is not long enough to satisfy the requested length, it is permissible to return fewer bases than the `requestedRegionLength`. It is the caller's responsibility to detect and handle this case.

Specified by:
  `getReferenceBasesByRegion` in interface `CRAMReferenceSource`
Parameters:
  `sequenceRecord` - the SAMSequenceRecord for the reference contig being requested
  `zeroBasedStart` - the zero based offset of the starting reference base, must be >= 0
  `requestedRegionLength` - the length of the requested reference region
Returns:
  the bases for the reference region, or null if the sequence cannot be found.

### getDownloadTriesBeforeFailing

public int getDownloadTriesBeforeFailing()

### setDownloadTriesBeforeFailing

public void setDownloadTriesBeforeFailing(int downloadTriesBeforeFailing)