Class BAMFileSpan

  • All Implemented Interfaces:
    SAMFileSpan, Serializable, Cloneable

    public class BAMFileSpan
    extends Object
    implements SAMFileSpan, Serializable
    An ordered list of chunks, capable of representing a set of discontiguous regions in the BAM file. FileSpans are mutable within the package, but perceived as immutable outside the package. Some operations on FileSpans assume that the spans are sorted. In these cases, sort order will be validated.
    See Also:
    Serialized Form
    • Constructor Detail

      • BAMFileSpan

        public BAMFileSpan()
        Create a new empty list of chunks.
      • BAMFileSpan

        public BAMFileSpan​(Chunk chunk)
        Convenience constructor to construct a BAM file span from a single chunk.
        Parameters:
        chunk - Chunk to use as the sole region in this span.
      • BAMFileSpan

        public BAMFileSpan​(List<Chunk> chunks)
        Create a new chunk list from the given list of chunks.
        Parameters:
        chunks - Constituent chunks.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Does this chunk list map to any position within the BAM file?
        Specified by:
        isEmpty in interface SAMFileSpan
        Returns:
        True iff the ChunkList points to any data within the BAM.
      • clone

        public BAMFileSpan clone()
        Deep clone the given chunk list.
        Overrides:
        clone in class Object
        Returns:
        A copy of the chunk list.
      • removeContentsBefore

        public SAMFileSpan removeContentsBefore​(SAMFileSpan fileSpan)
        Creates a new file span by removing all chunks before the given file span starts. If a chunk in the chunk list starts before and ends after the given chunk, the first portion of the chunk will be deleted.
        Specified by:
        removeContentsBefore in interface SAMFileSpan
        Parameters:
        fileSpan - The filespan before which to eliminate.
        Returns:
        A new BAMFileSpan which contains the portion of the chunk list after the given chunk.
      • removeContentsAfter

        public SAMFileSpan removeContentsAfter​(SAMFileSpan fileSpan)
        Creates a new file span by removing all chunks after the given file span ends. If a chunk in the chunk list starts before and ends after the given chunk, the second portion of the chunk will be deleted.
        Parameters:
        fileSpan - The filespan after which to eliminate.
        Returns:
        A new BAMFileSpan which contains the portion of the chunk list before the given chunk.
      • getContentsFollowing

        public SAMFileSpan getContentsFollowing()
        Gets a file span over the data immediately following this span.
        Specified by:
        getContentsFollowing in interface SAMFileSpan
        Returns:
        The a pointer to data immediately following this span.
      • add

        protected void add​(BAMFileSpan span)
        Merge one span into another
        Parameters:
        span - - span with chunks to add to this one
      • add

        protected void add​(Chunk chunk)
        Adds a new chunk to this list. Visible only within the BAm.
        Parameters:
        chunk - Chunk to add.
      • toCoordinateArray

        public long[] toCoordinateArray()
        Convert the chunk list to an array of offsets, paired in [start,end) format.
        Returns:
        Array of offsets.
      • getFirstOffset

        public long getFirstOffset()
        Find the first offset in the chunk list
        Returns:
        The first offset in the span
      • getChunks

        public List<Chunk> getChunks()
        Gets the constituent chunks stored in this span.
        Returns:
        An unmodifiable list of chunks.
      • getSingleChunk

        protected Chunk getSingleChunk()
        Checks that there is only a single chunk for this span and returns it.
        Returns:
        The single chunk stored in this span
      • toChunkList

        protected static SAMFileSpan toChunkList​(long[] coordinateArray)
        The list of chunks is often represented as an array of longs where every even-numbered index is a start coordinate and every odd-numbered index is a stop coordinate. Convert from that format back to a list of chunks.
        Parameters:
        coordinateArray - List of chunks to convert.
        Returns:
        A list of chunks.
      • toString

        public String toString()
        Creates a string representation of this chunk list.
        Overrides:
        toString in class Object
      • merge

        public static BAMFileSpan merge​(BAMFileSpan[] spans)
        Returns:
        A single BAMFileSpan that is an intelligent merge of the input spans, i.e. contiguous, overlapping and contained chunks are intelligently merged, and the chunks are sorted.