public final class ReferenceContext
extends java.lang.Object
implements java.lang.Iterable<java.lang.Byte>, htsjdk.samtools.util.Locatable
BaseUtils
implementation.
The reference interval can be optionally expanded by a configurable number of bases in each direction.
windowLeadingBases = 3 and windowTrailingBases = 5 means 3 bases of extra reference context before
the start of the interval and 5 bases of extra reference context after the end of the interval.
Window boundaries can be set either at construction time or afterwards via setWindow(int, int)
.
A ReferenceContext may have no backing data source and/or interval. In these cases, queries on it will always
return empty arrays / iterators. You can determine whether there is a backing source of reference
data via hasBackingDataSource()
, and whether there is an interval via getInterval()
.Constructor and Description |
---|
ReferenceContext()
Create a ReferenceContext with no backing data source.
|
ReferenceContext(ReferenceContext thatContext,
SimpleInterval interval)
Create a windowed ReferenceContext set up to lazily query the provided interval.
|
ReferenceContext(ReferenceDataSource dataSource,
SimpleInterval interval)
Create a windowless ReferenceContext set up to lazily query the bases spanning just
the provided interval (with no extra bases of context)
|
ReferenceContext(ReferenceDataSource dataSource,
SimpleInterval interval,
int windowLeadingBases,
int windowTrailingBases)
Create a windowed ReferenceContext set up to lazily query the provided interval,
expanded by the specified number of bases in each direction.
|
ReferenceContext(ReferenceDataSource dataSource,
SimpleInterval interval,
SimpleInterval window)
Create a windowed ReferenceContext set up to lazily query the provided interval,
expanded by the specified number of bases in each direction.
|
Modifier and Type | Method and Description |
---|---|
byte |
getBase()
Get the base at the given locus.
|
byte[] |
getBases()
Get all reference bases in this context.
|
byte[] |
getBases(int windowLeadingBases,
int windowTrailingBases)
Get all reference bases in this context with the given leading / trailing bases as the window.
|
byte[] |
getBases(SimpleInterval window)
Get all reference bases in this context with the given window.
|
java.lang.String |
getContig() |
int |
getEnd() |
byte[] |
getForwardBases()
Get the bases in this context, from the beginning of the interval to the end of the window.
|
SimpleInterval |
getInterval()
Get the location on the reference represented by this context, without including
any extra bases of requested context around this interval.
|
java.lang.String |
getKmerAround(int center,
int numBasesOnEachSide)
Get a kmer around a position in reference without altering the internal state of the object
The position must lie within the window
Returns null when, at the ends of a contig, we cannot expand the window to the requested size
|
int |
getStart() |
SimpleInterval |
getWindow()
Get the full expanded window of bases spanned by this context, including any extra
bases of requested context around the current interval.
|
boolean |
hasBackingDataSource()
Determines whether this ReferenceContext has a backing reference data source.
|
java.util.Iterator<java.lang.Byte> |
iterator()
Get an iterator over the reference bases in this context.
|
int |
numWindowLeadingBases()
Get the number of extra bases of context before the start of our interval, as configured
by a call to
setWindow(int, int) or at construction time. |
int |
numWindowTrailingBases()
Get the number of extra bases of context after the end of our interval, as configured
by a call to
setWindow(int, int) or at construction time. |
void |
setWindow(int windowLeadingBases,
int windowTrailingBases)
Set expanded window boundaries, subject to cropping at contig boundaries
Allows the client to request a specific number of extra reference bases to include before
and after the bases within our interval.
|
public ReferenceContext()
public ReferenceContext(ReferenceDataSource dataSource, SimpleInterval interval)
dataSource
- backing reference data source (may be null if there is no reference)interval
- interval to query, if we are accessed by a client (may be null if our location is unknown)public ReferenceContext(ReferenceDataSource dataSource, SimpleInterval interval, int windowLeadingBases, int windowTrailingBases)
dataSource
- backing reference data source (may be null if there is no reference)interval
- our location on the reference (may be null if our location is unknown)windowLeadingBases
- Number of extra reference bases to include before the start of our interval. Must be >= 0.windowTrailingBases
- Number of extra reference bases to include after the end of our interval. Must be >= 0.public ReferenceContext(ReferenceContext thatContext, SimpleInterval interval)
thatReferenceContext
.thatContext
- An existing ReferenceContext
on which to base this new one.interval
- our location on the reference (may be null if our location is unknown)public ReferenceContext(ReferenceDataSource dataSource, SimpleInterval interval, SimpleInterval window)
dataSource
- backing reference data source (may be null if there is no reference)interval
- our location on the reference (may be null if our location is unknown)window
- the expanded location on the reference. May be null if our location is unknown or there is no expanded window
(ie., the interval == window case). Must be null if interval is null. Must contain interval
if both are non-null.public java.lang.String getContig()
getContig
in interface htsjdk.samtools.util.Locatable
public int getStart()
getStart
in interface htsjdk.samtools.util.Locatable
public int getEnd()
getEnd
in interface htsjdk.samtools.util.Locatable
public boolean hasBackingDataSource()
getBases()
and an
empty iterator from iterator()
public java.util.Iterator<java.lang.Byte> iterator()
setWindow(int, int)
before calling this method if you want to configure the amount of extra reference context
to include around the current intervaliterator
in interface java.lang.Iterable<java.lang.Byte>
public byte[] getBases()
setWindow(int, int)
before calling this method if you want to configure the amount of extra reference context
to include around the current intervalpublic byte[] getBases(SimpleInterval window)
ReferenceContext
at all.
Will always return an empty array if there is no backing data source and/or interval to query.public byte[] getBases(int windowLeadingBases, int windowTrailingBases)
window
as a basis for the position.
Does not cache results or modify this ReferenceContext
at all.
Will always return an empty array if there is no backing data source and/or interval to query.public byte[] getForwardBases()
public SimpleInterval getInterval()
public SimpleInterval getWindow()
public void setWindow(int windowLeadingBases, int windowTrailingBases)
getBases()
and iterator()
in addition to the bases spanning our
actual interval.
Note that the true window size may be smaller than requested due to cropping at contig boundaries.
Call @numWindowLeadingBases
and @numWindowTrailingBases
to get the actual
window dimensions.windowLeadingBases
- Number of extra reference bases to include before the start of our interval. Must be >= 0.windowTrailingBases
- Number of extra reference bases to include after the end of our interval. Must be >= 0.public int numWindowLeadingBases()
setWindow(int, int)
or at construction time.
Actual number of bases may be less than originally requested if the interval is near a contig boundary.public int numWindowTrailingBases()
setWindow(int, int)
or at construction time.
Actual number of bases may be less than originally requested if the interval is near a contig boundary.public byte getBase()
public java.lang.String getKmerAround(int center, int numBasesOnEachSide)