// Add records the SAM record as having being located at the given chunk. func (i *Index) Add(r Record, c bgzf.Chunk, placed, mapped bool) error { refName := r.RefName() rid, ok := i.nameMap[refName] if !ok { rid = len(i.refNames) i.refNames = append(i.refNames, refName) } shim := tabixShim{id: rid, start: r.Start(), end: r.End()} return i.idx.Add(shim, internal.BinFor(r.Start(), r.End()), c, placed, mapped) }
// Bin returns the BAM index bin of the record. func (r *Record) Bin() int { if r.Flags&Unmapped != 0 { return 4680 // reg2bin(-1, 0) } end := r.End() if !internal.IsValidIndexPos(r.Pos) || !internal.IsValidIndexPos(end) { return -1 } return int(internal.BinFor(r.Pos, r.End())) }