func (bg *Reader) SetCache(c bgzf.Cache) {
	bg.r.SetCache(c)
}
SetCache sets the cache to be used by the Reader.
package bam
import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	"io"
	"unsafe"
	"github.com/biogo/hts/bgzf"
	"github.com/biogo/hts/sam"
)
type Reader struct {
	r *bgzf.Reader
	h *sam.Header
	c *bgzf.Chunk
	references int32
	omit int
	lastChunk bgzf.Chunk
	buf [0x1000]byte
}
func NewReader(r io.Reader, rd int) (*Reader, error) {
	bg, err := bgzf.NewReader(r, rd)
	if err != nil {
		return nil, err
	}
	h, _ := sam.NewHeader(nil, nil)
	br := &Reader{
		r: bg,
		h: h,
		references: int32(len(h.Refs())),
	}
	err = br.h.DecodeBinary(br.r)
	if err != nil {
		return nil, err
	}
	br.lastChunk.End = br.r.LastChunk().End
	return br, nil
}
func (br *Reader) Header() *sam.Header {
	return br.h
}
type bamRecordFixed struct {
	blockSize int32
	refID     int32
	pos       int32
	nLen      uint8
	mapQ      uint8
	bin       uint16
	nCigar    uint16
	flags     sam.Flags
	lSeq      int32
	nextRefID int32
	nextPos   int32
	tLen      int32
}
var (
	lenFieldSize      = binary.Size(bamRecordFixed{}.blockSize)
	bamFixedRemainder = binary.Size(bamRecordFixed{}) - lenFieldSize
)
func vOffset(o bgzf.Offset) int64 {
	return o.File<<16 | int64(o.Block)
}
func (br *Reader) Omit(o int) {
	br.omit = o
}
const (
	None                  = iota  
	AuxTags                       
	AllVariableLengthData         
)
func (br *Reader) Read() (*sam.Record, error) {
	if br.c != nil && vOffset(br.r.LastChunk().End) >= vOffset(br.c.End) {
		return nil, io.EOF
	}
	b, err := newBuffer(br)
	if err != nil {
		return nil, err
	}
	var rec sam.Record
	refID := b.readInt32()
	rec.Pos = int(b.readInt32())
	nLen := b.readUint8()
	rec.MapQ = b.readUint8()
	b.discard(2)
	nCigar := b.readUint16()
	rec.Flags = sam.Flags(b.readUint16())
	lSeq := int(b.readInt32())
	nextRefID := b.readInt32()
	rec.MatePos = int(b.readInt32())
	rec.TempLen = int(b.readInt32())
	if nLen < 1 {
		return nil, fmt.Errorf("bam: invalid read name length: %d", nLen)
	}
	rec.Name = string(b.unsafeBytes(int(nLen) - 1))
	b.discard(1)
	rec.Cigar = readCigarOps(b.unsafeBytes(int(nCigar) * 4))
	var seq, auxTags []byte
	if br.omit >= AllVariableLengthData {
		goto done
	}
	if lSeq < 0 {
		return nil, fmt.Errorf("bam: invalid sequence length: %d", lSeq)
	}
	seq = b.bytes((lSeq >> 1) + (lSeq & 0x1))
	rec.Seq = sam.Seq{Length: lSeq, Seq: *(*doublets)(unsafe.Pointer(&seq))}
	rec.Qual = b.bytes(lSeq)
	if br.omit >= AuxTags {
		goto done
	}
	auxTags = b.bytes(b.len())
	rec.AuxFields, err = parseAux(auxTags)
	if err != nil {
		return nil, err
	}
done:
	refs := int32(len(br.h.Refs()))
	if refID != -1 {
		if refID < -1 || refID >= refs {
			return nil, errors.New("bam: reference id out of range")
		}
		rec.Ref = br.h.Refs()[refID]
	}
	if nextRefID != -1 {
		if refID == nextRefID {
			rec.MateRef = rec.Ref
			return &rec, nil
		}
		if nextRefID < -1 || nextRefID >= refs {
			return nil, errors.New("bam: mate reference id out of range")
		}
		rec.MateRef = br.h.Refs()[nextRefID]
	}
	return &rec, nil
}