Documentation ¶
Overview ¶
Package bam implements BAM file format reading, writing and indexing. The BAM format is described in the SAM specification.
Index ¶
- func WriteIndex(w io.Writer, idx *Index) error
- type Index
- func (i *Index) Add(r *sam.Record, c bgzf.Chunk) error
- func (i *Index) Chunks(r *sam.Reference, beg, end int) ([]bgzf.Chunk, error)
- func (i *Index) MergeChunks(s index.MergeStrategy)
- func (i *Index) NumRefs() int
- func (i *Index) ReferenceStats(id int) (stats index.ReferenceStats, ok bool)
- func (i *Index) Unmapped() (n uint64, ok bool)
- type Iterator
- type Reader
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a BAI index.
func (*Index) Add ¶
Add records the SAM record as having being located at the given chunk.
Example ¶
package main import ( "io" "log" "os" "github.com/biogo/hts/bam" ) func main() { // Create a BAI for the BAM read from standard in and write it to standard out. br, err := bam.NewReader(os.Stdin, 1) if err != nil { log.Fatalf("failed to open BAM: %v", err) } var bai bam.Index for { r, err := br.Read() if err == io.EOF { break } if err != nil { log.Fatalf("failed to read BAM record: %v", err) } err = bai.Add(r, br.LastChunk()) if err != nil { log.Fatalf("failed to add record to BAM index: %v", err) } } err = bam.WriteIndex(os.Stdout, &bai) if err != nil { log.Fatalf("failed to write BAM index: %v", err) } }
Output:
func (*Index) Chunks ¶
Chunks returns a []bgzf.Chunk that corresponds to the given genomic interval.
func (*Index) MergeChunks ¶
func (i *Index) MergeChunks(s index.MergeStrategy)
MergeChunks applies the given MergeStrategy to all bins in the Index.
func (*Index) ReferenceStats ¶
func (i *Index) ReferenceStats(id int) (stats index.ReferenceStats, ok bool)
ReferenceStats returns the index statistics for the given reference and true if the statistics are valid.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator wraps a Reader to provide a convenient loop interface for reading BAM data. Successive calls to the Next method will step through the features of the provided Reader. Iteration stops unrecoverably at EOF or the first error.
func NewIterator ¶
NewIterator returns a Iterator to read from r, limiting the reads to the provided chunks.
i, err := NewIterator(r, bai.Chunks(ref, beg, end)) if err != nil { return err } for i.Next() { fn(i.Record()) } return i.Close()
func (*Iterator) Error ¶
Error returns the first non-EOF error that was encountered by the Iterator.
func (*Iterator) Next ¶
Next advances the Iterator past the next record, which will then be available through the Record method. It returns false when the iteration stops, either by reaching the end of the input or an error. After Next returns false, the Error method will return any error that occurred during iteration, except that if it was io.EOF, Error will return nil.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader implements BAM data reading.
func NewReader ¶
NewReader returns a new Reader using the given io.Reader and setting the read concurrency to rd. If rd is zero concurrency is set to GOMAXPROCS.
func (*Reader) LastChunk ¶
LastChunk returns the bgzf.Chunk corresponding to the last Read operation.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements BAM data writing.
func NewWriter ¶
NewWriter returns a new Writer using the given SAM header. Write concurrency is set to wc.
func NewWriterLevel ¶
NewWriterLevel returns a new Writer using the given SAM header. Write concurrency is set to wc and compression level is set to level. Valid values for level are described in the compress/gzip documentation.