hts: github.com/biogo/hts/sam Index | Examples | Files

package sam

import "github.com/biogo/hts/sam"

Package sam implements SAM file format reading and writing. The SAM format is described in the SAM specification.

http://samtools.github.io/hts-specs/SAMv1.pdf

Index

Examples

Package Files

auxtags.go cigar.go flag.go header.go parse_header.go program.go read_group.go record.go reference.go sam.go

Constants

const (
    FlagDecimal = iota
    FlagHex
    FlagString
)

Flag format constants.

func IsValidRecord Uses

func IsValidRecord(r *Record) bool

IsValidRecord returns whether the record satisfies the conditions that it has the Unmapped flag set if it not placed; that the MateUnmapped flag is set if it paired its mate is unplaced; that the CIGAR length matches the sequence and quality string lengths if they are non-zero; and that the Paired, ProperPair, Unmapped and MateUnmapped flags are consistent.

type ASCII Uses

type ASCII byte

ASCII is a printable ASCII character included in an Aux tag.

type Aux Uses

type Aux []byte

An Aux represents an auxiliary data field from a SAM alignment record.

func NewAux Uses

func NewAux(t Tag, value interface{}) (Aux, error)

NewAux returns a new Aux with the given tag, type and value. Acceptable value types and their corresponding SAM type are:

A - ASCII
c - int8
C - uint8
s - int16
S - uint16
i - int, uint or int32
I - int, uint or uint32
f - float32
Z - Text or string
H - Hex
B - []int8, []int16, []int32, []uint8, []uint16, []uint32 or []float32

The handling of int and uint types is provided as a convenience - values must fit within either int32 or uint32 and are converted to the smallest possible representation.

func ParseAux Uses

func ParseAux(text []byte) (Aux, error)

ParseAux returns an AUX parsed from the given text.

func (Aux) Kind Uses

func (a Aux) Kind() byte

Kind returns a byte corresponding to the kind of the auxiliary tag. Returned values are in {'A', 'i', 'f', 'Z', 'H', 'B'}.

func (Aux) String Uses

func (a Aux) String() string

String returns the string representation of an Aux type.

func (Aux) Tag Uses

func (a Aux) Tag() Tag

Tag returns the Tag representation of the Aux tag ID.

func (Aux) Type Uses

func (a Aux) Type() byte

Type returns a byte corresponding to the type of the auxiliary tag. Returned values are in {'A', 'c', 'C', 's', 'S', 'i', 'I', 'f', 'Z', 'H', 'B'}.

func (Aux) Value Uses

func (a Aux) Value() interface{}

Value returns v containing the value of the auxiliary tag.

type AuxFields Uses

type AuxFields []Aux

AuxFields is a set of auxiliary fields.

func (AuxFields) Get Uses

func (a AuxFields) Get(tag Tag) Aux

Get returns the auxiliary field identified by the given tag, or nil if no field matches.

type Cigar Uses

type Cigar []CigarOp

Cigar is a set of CIGAR operations.

func ParseCigar Uses

func ParseCigar(b []byte) (Cigar, error)

ParseCigar returns a Cigar parsed from the provided byte slice. ParseCigar will break CIGAR operations longer than 2^28-1 into multiple operations summing to the same length.

func (Cigar) IsValid Uses

func (c Cigar) IsValid(length int) bool

IsValid returns whether the CIGAR string is valid for a record of the given sequence length. Validity is defined by the sum of query consuming operations matching the given length, clipping operations only being present at the ends of alignments, and that CigarBack operations only result in query-consuming positions at or right of the start of the alignment.

func (Cigar) Lengths Uses

func (c Cigar) Lengths() (ref, read int)

Lengths returns the number of reference and read bases described by the Cigar.

func (Cigar) String Uses

func (c Cigar) String() string

String returns the CIGAR string for c.

type CigarOp Uses

type CigarOp uint32

CigarOp is a single CIGAR operation including the operation type and the length of the operation.

func NewCigarOp Uses

func NewCigarOp(t CigarOpType, n int) CigarOp

NewCigarOp returns a CIGAR operation of the specified type with length n. Due to a limitation of the BAM format, CIGAR operation lengths are limited to 2^28-1, and NewCigarOp will panic if n is above this or negative.

func (CigarOp) Len Uses

func (co CigarOp) Len() int

Len returns the number of positions affected by the CigarOp CIGAR operation.

func (CigarOp) String Uses

func (co CigarOp) String() string

String returns the string representation of the CigarOp

func (CigarOp) Type Uses

func (co CigarOp) Type() CigarOpType

Type returns the type of the CIGAR operation for the CigarOp.

type CigarOpType Uses

type CigarOpType byte

A CigarOpType represents the type of operation described by a CigarOp.

const (
    CigarMatch       CigarOpType = iota // Alignment match (can be a sequence match or mismatch).
    CigarInsertion                      // Insertion to the reference.
    CigarDeletion                       // Deletion from the reference.
    CigarSkipped                        // Skipped region from the reference.
    CigarSoftClipped                    // Soft clipping (clipped sequences present in SEQ).
    CigarHardClipped                    // Hard clipping (clipped sequences NOT present in SEQ).
    CigarPadded                         // Padding (silent deletion from padded reference).
    CigarEqual                          // Sequence match.
    CigarMismatch                       // Sequence mismatch.
    CigarBack                           // Skip backwards.

)

func (CigarOpType) Consumes Uses

func (ct CigarOpType) Consumes() Consume

Consumes returns the CIGAR operation alignment consumption characteristics for the CigarOpType.

The Consume values for each of the CigarOpTypes is as follows:

                  Query  Reference
CigarMatch          1        1
CigarInsertion      1        0
CigarDeletion       0        1
CigarSkipped        0        1
CigarSoftClipped    1        0
CigarHardClipped    0        0
CigarPadded         0        0
CigarEqual          1        1
CigarMismatch       1        1
CigarBack           0       -1

func (CigarOpType) String Uses

func (ct CigarOpType) String() string

String returns the string representation of a CigarOpType.

type Consume Uses

type Consume struct {
    Query, Reference int
}

Consume describes how CIGAR operations consume alignment bases.

Code:

package main

import (
    "fmt"

    "github.com/biogo/hts/sam"
)

func min(a, b int) int {
    if a > b {
        return b
    }
    return a
}

func max(a, b int) int {
    if a < b {
        return b
    }
    return a
}

// Overlap returns the length of the overlap between the alignment
// of the SAM record and the interval specified.
//
// Note that this will count repeated matches to the same reference
// location if CigarBack operations are used.
func Overlap(r *sam.Record, start, end int) int {
    var overlap int
    pos := r.Pos
    for _, co := range r.Cigar {
        t := co.Type()
        con := t.Consumes()
        lr := co.Len() * con.Reference
        if con.Query == con.Reference {
            o := min(pos+lr, end) - max(pos, start)
            if o > 0 {
                overlap += o
            }
        }
        pos += lr
    }

    return overlap
}

func main() {
    // Example alignments from the SAM specification:
    //
    // @HD	VN:1.5	SO:coordinate
    // @SQ	SN:ref	LN:45
    // @CO	--------------------------------------------------------
    // @CO	Coor     12345678901234  5678901234567890123456789012345
    // @CO	ref      AGCATGTTAGATAA**GATAGCTGTGCTAGTAGGCAGTCAGCGCCAT
    // @CO	--------------------------------------------------------
    // @CO	+r001/1        TTAGATAAAGGATA*CTG
    // @CO	+r002         aaaAGATAA*GGATA
    // @CO	+r003       gcctaAGCTAA
    // @CO	+r004                     ATAGCT..............TCAGC
    // @CO	-r003                            ttagctTAGGC
    // @CO	-r001/2                                        CAGCGGCAT
    // @CO	--------------------------------------------------------
    // r001	99	ref	7	30	8M2I4M1D3M	=	37	39	TTAGATAAAGGATACTG	*
    // r002	0	ref	9	30	3S6M1P1I4M	*	0	0	AAAAGATAAGGATA	*
    // r003	0	ref	9	30	5S6M	*	0	0	GCCTAAGCTAA	*	SA:Z:ref,29,-,6H5M,17,0;
    // r004	0	ref	16	30	6M14N5M	*	0	0	ATAGCTTCAGC	*
    // r003	2064	ref	29	17	6H5M	*	0	0	TAGGC	*	SA:Z:ref,9,+,5S6M,30,1;
    // r001	147	ref	37	30	9M	=	7	-39	CAGCGGCAT	*	NM:i:1

    const (
        refStart = 0
        refEnd   = 45
    )

    records := []*sam.Record{
        {Name: "r001/1", Pos: 6, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarMatch, 8),
            sam.NewCigarOp(sam.CigarInsertion, 2),
            sam.NewCigarOp(sam.CigarMatch, 4),
            sam.NewCigarOp(sam.CigarDeletion, 1),
            sam.NewCigarOp(sam.CigarMatch, 3),
        }},
        {Name: "r002", Pos: 8, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarSoftClipped, 3),
            sam.NewCigarOp(sam.CigarMatch, 6),
            sam.NewCigarOp(sam.CigarPadded, 1),
            sam.NewCigarOp(sam.CigarInsertion, 1),
            sam.NewCigarOp(sam.CigarMatch, 4),
        }},
        {Name: "r003", Pos: 8, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarSoftClipped, 5),
            sam.NewCigarOp(sam.CigarMatch, 6),
        }},
        {Name: "r004", Pos: 15, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarMatch, 6),
            sam.NewCigarOp(sam.CigarSkipped, 14),
            sam.NewCigarOp(sam.CigarMatch, 5),
        }},
        {Name: "r003", Pos: 28, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarHardClipped, 6),
            sam.NewCigarOp(sam.CigarMatch, 5),
        }},
        {Name: "r001/2", Pos: 36, Cigar: []sam.CigarOp{
            sam.NewCigarOp(sam.CigarMatch, 9),
        }},
    }

    for _, r := range records {
        fmt.Printf("%q overlaps reference by %d letters\n", r.Name, Overlap(r, refStart, refEnd))
    }

}

type Doublet Uses

type Doublet byte

Doublet is a nybble-encode pair of nucleotide bases.

type Flags Uses

type Flags uint16

A Flags represents a BAM record's alignment FLAG field.

const (
    Paired        Flags = 1 << iota // The read is paired in sequencing, no matter whether it is mapped in a pair.
    ProperPair                      // The read is mapped in a proper pair.
    Unmapped                        // The read itself is unmapped; conflictive with ProperPair.
    MateUnmapped                    // The mate is unmapped.
    Reverse                         // The read is mapped to the reverse strand.
    MateReverse                     // The mate is mapped to the reverse strand.
    Read1                           // This is read1.
    Read2                           // This is read2.
    Secondary                       // Not primary alignment.
    QCFail                          // QC failure.
    Duplicate                       // Optical or PCR duplicate.
    Supplementary                   // Supplementary alignment, indicates alignment is part of a chimeric alignment.
)

func (Flags) String Uses

func (f Flags) String() string

String representation of BAM alignment flags:

0x001 - p - Paired
0x002 - P - ProperPair
0x004 - u - Unmapped
0x008 - U - MateUnmapped
0x010 - r - Reverse
0x020 - R - MateReverse
0x040 - 1 - Read1
0x080 - 2 - Read2
0x100 - s - Secondary
0x200 - f - QCFail
0x400 - d - Duplicate
0x800 - S - Supplementary

Note that flag bits are represented high order to the right.

type GroupOrder Uses

type GroupOrder int

GroupOrder indicates the grouping order of a SAM or BAM file.

const (
    GroupUnspecified GroupOrder = iota
    GroupNone
    GroupQuery
    GroupReference
)

func (GroupOrder) String Uses

func (g GroupOrder) String() string

String returns the string representation of a GroupOrder.

type Header struct {
    Version    string
    SortOrder  SortOrder
    GroupOrder GroupOrder

    Comments []string
    // contains filtered or unexported fields
}

Header is a SAM or BAM header.

func MergeHeaders Uses

func MergeHeaders(src []*Header) (h *Header, reflinks [][]*Reference, err error)

MergeHeaders returns a new Header resulting from the merge of the source Headers, and a mapping between the references in the source and the References in the returned Header. Sort order is set to unknown and group order is set to none. If a single Header is passed to MergeHeaders, the mapping between source and destination headers, reflink, is returned as nil. The returned Header contains the read groups and programs of the first Header in src.

func NewHeader Uses

func NewHeader(text []byte, r []*Reference) (*Header, error)

NewHeader returns a new Header based on the given text and list of References. If there is a conflict between the text and the given References NewHeader will return a non-nil error.

func (*Header) AddProgram Uses

func (bh *Header) AddProgram(p *Program) error

AddProgram adds p to the Header.

func (*Header) AddReadGroup Uses

func (bh *Header) AddReadGroup(rg *ReadGroup) error

AddReadGroup adds rg to the Header.

func (*Header) AddReference Uses

func (bh *Header) AddReference(r *Reference) error

AddReference adds r to the Header.

func (*Header) Clone Uses

func (bh *Header) Clone() *Header

Clone returns a deep copy of the receiver.

func (*Header) DecodeBinary Uses

func (bh *Header) DecodeBinary(r io.Reader) error

DecodeBinary unmarshals a Header from the given io.Reader. The byte stream must be in the format described in the SAM specification, section 4.2.

func (*Header) EncodeBinary Uses

func (bh *Header) EncodeBinary(w io.Writer) error

EncodeBinary writes a binary encoding of the Header to the given io.Writer. The format of the encoding is defined in the SAM specification, section 4.2.

func (*Header) Get Uses

func (bh *Header) Get(t Tag) string

Get returns the string representation of the value associated with the given header line tag. If the tag is not present the empty string is returned.

func (*Header) MarshalBinary Uses

func (bh *Header) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler.

func (*Header) MarshalText Uses

func (bh *Header) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Header) Progs Uses

func (bh *Header) Progs() []*Program

Progs returns the Header's list of Programs. The returned slice should not be altered.

func (*Header) RGs Uses

func (bh *Header) RGs() []*ReadGroup

RGs returns the Header's list of ReadGroups. The returned slice should not be altered.

func (*Header) Refs Uses

func (bh *Header) Refs() []*Reference

Refs returns the Header's list of References. The returned slice should not be altered.

func (*Header) RemoveProgram Uses

func (bh *Header) RemoveProgram(p *Program) error

RemoveProgram removes p from the Header and makes it available to add to another Header.

func (*Header) RemoveReadGroup Uses

func (bh *Header) RemoveReadGroup(rg *ReadGroup) error

RemoveReadGroup removes rg from the Header and makes it available to add to another Header.

func (*Header) RemoveReference Uses

func (bh *Header) RemoveReference(r *Reference) error

RemoveReference removes r from the Header and makes it available to add to another Header.

func (*Header) Set Uses

func (bh *Header) Set(t Tag, value string) error

Set sets the value associated with the given header line tag to the specified value. If value is the empty string and the tag may be absent, it is deleted or set to a meaningful default (SO:UnknownOrder and GO:GroupUnspecified), otherwise an error is returned.

func (*Header) Tags Uses

func (bh *Header) Tags(fn func(t Tag, value string))

Tags applies the function fn to each of the tag-value pairs of the Header. The SO and GO tags are only used if they are set to the non-default values. The function fn must not add or delete tags held by the receiver during iteration.

func (*Header) UnmarshalBinary Uses

func (bh *Header) UnmarshalBinary(b []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Header) UnmarshalText Uses

func (bh *Header) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Header) Validate Uses

func (bh *Header) Validate(r *Record) error

Validate checks r against the Header for record validity according to the SAM specification:

- a program auxiliary field must refer to a program listed in the header
- a read group auxiliary field must refer to a read group listed in the
  header and these must agree on platform unit and library.

type Hex Uses

type Hex []byte

Hex is a byte slice represented as a hex string in an Aux tag.

type Iterator Uses

type Iterator struct {
    // contains filtered or unexported fields
}

Iterator wraps a Reader to provide a convenient loop interface for reading SAM/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 Uses

func NewIterator(r RecordReader) *Iterator

NewIterator returns a Iterator to read from r.

i, err := NewIterator(r)
if err != nil {
	return err
}
for i.Next() {
	fn(i.Record())
}
return i.Error()

func (*Iterator) Error Uses

func (i *Iterator) Error() error

Error returns the first non-EOF error that was encountered by the Iterator.

func (*Iterator) Next Uses

func (i *Iterator) Next() bool

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.

func (*Iterator) Record Uses

func (i *Iterator) Record() *Record

Record returns the most recent record read by a call to Next.

type Program Uses

type Program struct {
    // contains filtered or unexported fields
}

Program represents a SAM program.

func NewProgram Uses

func NewProgram(uid, name, command, prev, v string) *Program

NewProgram returns a Program with the given unique ID, name, command, previous program ID in the pipeline and version.

func (*Program) Clone Uses

func (p *Program) Clone() *Program

Clone returns a deep copy of the Program.

func (*Program) Command Uses

func (p *Program) Command() string

Command returns the program's command line.

func (*Program) Get Uses

func (p *Program) Get(t Tag) string

Get returns the string representation of the value associated with the given program line tag. If the tag is not present the empty string is returned.

func (*Program) ID Uses

func (p *Program) ID() int

ID returns the header ID for the Program.

func (*Program) Name Uses

func (p *Program) Name() string

Name returns the program's name.

func (*Program) Previous Uses

func (p *Program) Previous() string

Previous returns the unique ID for the previous program in the pipeline.

func (*Program) Set Uses

func (p *Program) Set(t Tag, value string) error

Set sets the value associated with the given program line tag to the specified value. If value is the empty string and the tag may be absent, it is deleted.

func (*Program) SetUID Uses

func (r *Program) SetUID(uid string) error

SetUID sets the unique program ID to uid.

func (*Program) String Uses

func (p *Program) String() string

String returns a string representation of the program according to the SAM specification section 1.3,

func (*Program) Tags Uses

func (p *Program) Tags(fn func(t Tag, value string))

Tags applies the function fn to each of the tag-value pairs of the Program. The function fn must not add or delete tags held by the receiver during iteration.

func (*Program) UID Uses

func (p *Program) UID() string

UID returns the unique program ID for the program.

func (*Program) Version Uses

func (p *Program) Version() string

Version returns the version of the program.

type ReadGroup Uses

type ReadGroup struct {
    // contains filtered or unexported fields
}

ReadGroup represents a sequencing read group.

func NewReadGroup Uses

func NewReadGroup(name, center, desc, lib, prog, plat, unit, sample, flow, key string, date time.Time, size int) (*ReadGroup, error)

NewReadGroup returns a ReadGroup with the given name, center, description, library, program, platform, unique platform unit, sample name, flow order, key, date of read group production, and predicted median insert size sequence.

func (*ReadGroup) Clone Uses

func (r *ReadGroup) Clone() *ReadGroup

Clone returns a deep copy of the ReadGroup.

func (*ReadGroup) Get Uses

func (r *ReadGroup) Get(t Tag) string

Get returns the string representation of the value associated with the given read group line tag. If the tag is not present the empty string is returned.

func (*ReadGroup) ID Uses

func (r *ReadGroup) ID() int

ID returns the header ID for the ReadGroup.

func (*ReadGroup) Library Uses

func (r *ReadGroup) Library() string

Library returns the library name for the read group.

func (*ReadGroup) Name Uses

func (r *ReadGroup) Name() string

Name returns the read group's name.

func (*ReadGroup) PlatformUnit Uses

func (r *ReadGroup) PlatformUnit() string

PlatformUnit returns the unique platform unit for the read group.

func (*ReadGroup) Set Uses

func (r *ReadGroup) Set(t Tag, value string) error

Set sets the value associated with the given read group line tag to the specified value. If value is the empty string and the tag may be absent, it is deleted.

func (*ReadGroup) SetName Uses

func (r *ReadGroup) SetName(n string) error

SetName sets the read group's name to n.

func (*ReadGroup) String Uses

func (r *ReadGroup) String() string

String returns a string representation of the read group according to the SAM specification section 1.3,

func (*ReadGroup) Tags Uses

func (r *ReadGroup) Tags(fn func(t Tag, value string))

Tags applies the function fn to each of the tag-value pairs of the read group. The function fn must not add or delete tags held by the receiver during iteration.

func (*ReadGroup) Time Uses

func (r *ReadGroup) Time() time.Time

Time returns the time the read group was produced.

type Reader Uses

type Reader struct {
    // contains filtered or unexported fields
}

Reader implements SAM format reading.

func NewReader Uses

func NewReader(r io.Reader) (*Reader, error)

NewReader returns a new Reader, reading from the given io.Reader.

func (*Reader) Header Uses

func (r *Reader) Header() *Header

Header returns the SAM Header held by the Reader.

func (*Reader) Read Uses

func (r *Reader) Read() (*Record, error)

Read returns the next sam.Record in the SAM stream.

type Record Uses

type Record struct {
    Name      string
    Ref       *Reference
    Pos       int
    MapQ      byte
    Cigar     Cigar
    Flags     Flags
    MateRef   *Reference
    MatePos   int
    TempLen   int
    Seq       Seq
    Qual      []byte
    AuxFields AuxFields
}

Record represents a SAM/BAM record.

func NewRecord Uses

func NewRecord(name string, ref, mRef *Reference, p, mPos, tLen int, mapQ byte, co []CigarOp, seq, qual []byte, aux []Aux) (*Record, error)

NewRecord returns a Record, checking for consistency of the provided attributes.

func (*Record) Bin Uses

func (r *Record) Bin() int

Bin returns the BAM index bin of the record.

func (*Record) End Uses

func (r *Record) End() int

End returns the highest query-consuming coordinate end of the alignment. The position returned by End is not valid if r.Cigar.IsValid(r.Seq.Length) is false.

func (*Record) Len Uses

func (r *Record) Len() int

Len returns the length of the alignment.

func (*Record) LessByCoordinate Uses

func (r *Record) LessByCoordinate(other *Record) bool

LessByCoordinate returns true if the receiver sorts by coordinate before other according to the SAM specification.

func (*Record) LessByName Uses

func (r *Record) LessByName(other *Record) bool

LessByName returns true if the receiver sorts by record name before other.

func (*Record) MarshalSAM Uses

func (r *Record) MarshalSAM(flags int) ([]byte, error)

MarshalSAM formats a Record as SAM using the specified flag format. Acceptable formats are FlagDecimal, FlagHex and FlagString.

func (*Record) MarshalText Uses

func (r *Record) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It calls MarshalSAM with FlagDecimal.

func (*Record) RefID Uses

func (r *Record) RefID() int

RefID returns the reference ID for the Record.

func (*Record) Start Uses

func (r *Record) Start() int

Start returns the lower-coordinate end of the alignment.

func (*Record) Strand Uses

func (r *Record) Strand() int8

Strand returns an int8 indicating the strand of the alignment. A positive return indicates alignment in the forward orientation, a negative returns indicates alignment in the reverse orientation.

func (*Record) String Uses

func (r *Record) String() string

String returns a string representation of the Record.

func (*Record) Tag Uses

func (r *Record) Tag(tag []byte) (v Aux, ok bool)

Tag returns an Aux tag whose tag ID matches the first two bytes of tag and true. If no tag matches, nil and false are returned.

func (*Record) UnmarshalSAM Uses

func (r *Record) UnmarshalSAM(h *Header, b []byte) error

UnmarshalSAM parses a SAM format alignment line in the provided []byte, using references from the provided Header. If a nil Header is passed to UnmarshalSAM and the SAM data include non-empty refence and mate reference names, fake references with zero length and an ID of -1 are created to hold the reference names.

func (*Record) UnmarshalText Uses

func (r *Record) UnmarshalText(b []byte) error

UnmarshalText implements the encoding.TextUnmarshaler. It calls UnmarshalSAM with a nil Header.

type RecordReader Uses

type RecordReader interface {
    Read() (*Record, error)
}

RecordReader wraps types that can read SAM Records.

type Reference Uses

type Reference struct {
    // contains filtered or unexported fields
}

Reference is a mapping reference.

func NewReference Uses

func NewReference(name, assemID, species string, length int, md5 []byte, uri *url.URL) (*Reference, error)

NewReference returns a new Reference based on the given parameters. Only name and length are mandatory and length must be a valid reference length according to the SAM specification, [1, 1<<31).

func (*Reference) AssemblyID Uses

func (r *Reference) AssemblyID() string

AssemblyID returns the assembly ID of the reference.

func (*Reference) Clone Uses

func (r *Reference) Clone() *Reference

Clone returns a deep copy of the Reference.

func (*Reference) Get Uses

func (r *Reference) Get(t Tag) string

Get returns the string representation of the value associated with the given reference line tag. If the tag is not present the empty string is returned.

func (*Reference) ID Uses

func (r *Reference) ID() int

ID returns the header ID of the Reference.

func (*Reference) Len Uses

func (r *Reference) Len() int

Len returns the length of the reference sequence.

func (*Reference) MD5 Uses

func (r *Reference) MD5() []byte

MD5 returns a 16 byte slice holding the MD5 sum of the reference sequence.

func (*Reference) Name Uses

func (r *Reference) Name() string

Name returns the reference name.

func (*Reference) Set Uses

func (r *Reference) Set(t Tag, value string) error

Set sets the value associated with the given reference line tag to the specified value. If value is the empty string and the tag may be absent, it is deleted.

func (*Reference) SetLen Uses

func (r *Reference) SetLen(l int) error

SetLen sets the length of the reference sequence to l. The given length must be a valid SAM reference length.

func (*Reference) SetName Uses

func (r *Reference) SetName(n string) error

SetName sets the reference name to n.

func (*Reference) Species Uses

func (r *Reference) Species() string

Species returns the reference species.

func (*Reference) String Uses

func (r *Reference) String() string

String returns a string representation of the Reference according to the SAM specification section 1.3,

func (*Reference) Tags Uses

func (r *Reference) Tags(fn func(t Tag, value string))

Tags applies the function fn to each of the tag-value pairs of the Reference. The function fn must not add or delete tags held by the receiver during iteration.

func (*Reference) URI Uses

func (r *Reference) URI() string

URI returns the URI of the reference.

type Seq Uses

type Seq struct {
    Length int
    Seq    []Doublet
}

Seq is a nybble-encode pair of nucleotide sequence.

func NewSeq Uses

func NewSeq(s []byte) Seq

NewSeq returns a new Seq based on the given byte slice.

func (Seq) At Uses

func (ns Seq) At(pos int) byte

At returns the base at the given position. At panics unless 0 <= pos < ns.Length.

func (Seq) Expand Uses

func (ns Seq) Expand() []byte

Expand returns the byte encoded form of the receiver.

type SortOrder Uses

type SortOrder int

SortOrder indicates the sort order of a SAM or BAM file.

const (
    UnknownOrder SortOrder = iota
    Unsorted
    QueryName
    Coordinate
)

func (SortOrder) String Uses

func (so SortOrder) String() string

String returns the string representation of a SortOrder.

type Tag Uses

type Tag [2]byte

A Tag represents an auxiliary or header tag label.

func NewTag Uses

func NewTag(tag string) Tag

NewTag returns a Tag from the tag string. It panics is len(tag) != 2.

func (Tag) String Uses

func (t Tag) String() string

String returns a string representation of a Tag.

type Text Uses

type Text []byte

Text is a byte slice represented as a string in an Aux tag.

type Writer Uses

type Writer struct {
    // contains filtered or unexported fields
}

Writer implements SAM format writing.

func NewWriter Uses

func NewWriter(w io.Writer, h *Header, flags int) (*Writer, error)

NewWriter returns a Writer to the given io.Writer using h for the SAM header. The format of flags for SAM lines can be FlagDecimal, FlagHex or FlagString.

func (*Writer) Write Uses

func (w *Writer) Write(r *Record) error

Write writes r to the SAM stream.

Package sam imports 16 packages (graph) and is imported by 32 packages. Updated 2020-01-08. Refresh now. Tools for package owners.