id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
15,000
biogo/hts
bgzf/reader.go
cacheHasBlockFor
func (bg *Reader) cacheHasBlockFor(base int64) (exists bool, next int64) { bg.mu.RLock() defer bg.mu.RUnlock() if bg.cache == nil { return false, -1 } return bg.cache.Peek(base) }
go
func (bg *Reader) cacheHasBlockFor(base int64) (exists bool, next int64) { bg.mu.RLock() defer bg.mu.RUnlock() if bg.cache == nil { return false, -1 } return bg.cache.Peek(base) }
[ "func", "(", "bg", "*", "Reader", ")", "cacheHasBlockFor", "(", "base", "int64", ")", "(", "exists", "bool", ",", "next", "int64", ")", "{", "bg", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "bg", ".", "mu", ".", "RUnlock", "(", ")", "\n", "if", "bg", ".", "cache", "==", "nil", "{", "return", "false", ",", "-", "1", "\n", "}", "\n", "return", "bg", ".", "cache", ".", "Peek", "(", "base", ")", "\n", "}" ]
// cacheHasBlockFor returns whether the Reader's cache has a block // for the given base offset. If the requested Block exists, the base // offset of the following Block is returned.
[ "cacheHasBlockFor", "returns", "whether", "the", "Reader", "s", "cache", "has", "a", "block", "for", "the", "given", "base", "offset", ".", "If", "the", "requested", "Block", "exists", "the", "base", "offset", "of", "the", "following", "Block", "is", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L648-L655
15,001
biogo/hts
bgzf/reader.go
cachedBlockFor
func (bg *Reader) cachedBlockFor(base int64) (Block, error) { blk := bg.cache.Get(base) if blk != nil { if !blk.ownedBy(bg) { return nil, ErrContaminatedCache } err := blk.seek(0) if err != nil { return nil, err } } return blk, nil }
go
func (bg *Reader) cachedBlockFor(base int64) (Block, error) { blk := bg.cache.Get(base) if blk != nil { if !blk.ownedBy(bg) { return nil, ErrContaminatedCache } err := blk.seek(0) if err != nil { return nil, err } } return blk, nil }
[ "func", "(", "bg", "*", "Reader", ")", "cachedBlockFor", "(", "base", "int64", ")", "(", "Block", ",", "error", ")", "{", "blk", ":=", "bg", ".", "cache", ".", "Get", "(", "base", ")", "\n", "if", "blk", "!=", "nil", "{", "if", "!", "blk", ".", "ownedBy", "(", "bg", ")", "{", "return", "nil", ",", "ErrContaminatedCache", "\n", "}", "\n", "err", ":=", "blk", ".", "seek", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "blk", ",", "nil", "\n", "}" ]
// cachedBlockFor returns a non-nil Block if the Reader has access to a // cache and the cache holds the block with the given base and the // correct owner, otherwise it returns nil. If the Block's owner is not // correct, or the Block cannot seek to the start of its data, a non-nil // error is returned.
[ "cachedBlockFor", "returns", "a", "non", "-", "nil", "Block", "if", "the", "Reader", "has", "access", "to", "a", "cache", "and", "the", "cache", "holds", "the", "block", "with", "the", "given", "base", "and", "the", "correct", "owner", "otherwise", "it", "returns", "nil", ".", "If", "the", "Block", "s", "owner", "is", "not", "correct", "or", "the", "Block", "cannot", "seek", "to", "the", "start", "of", "its", "data", "a", "non", "-", "nil", "error", "is", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L662-L674
15,002
biogo/hts
bgzf/reader.go
cachePut
func (bg *Reader) cachePut(b Block) (evicted Block, retained bool) { if b == nil || !b.hasData() { return b, false } return bg.cache.Put(b) }
go
func (bg *Reader) cachePut(b Block) (evicted Block, retained bool) { if b == nil || !b.hasData() { return b, false } return bg.cache.Put(b) }
[ "func", "(", "bg", "*", "Reader", ")", "cachePut", "(", "b", "Block", ")", "(", "evicted", "Block", ",", "retained", "bool", ")", "{", "if", "b", "==", "nil", "||", "!", "b", ".", "hasData", "(", ")", "{", "return", "b", ",", "false", "\n", "}", "\n", "return", "bg", ".", "cache", ".", "Put", "(", "b", ")", "\n", "}" ]
// cachePut puts the given Block into the cache if it exists, it returns // the Block that was evicted or b if it was not retained, and whether // the Block was retained by the cache.
[ "cachePut", "puts", "the", "given", "Block", "into", "the", "cache", "if", "it", "exists", "it", "returns", "the", "Block", "that", "was", "evicted", "or", "b", "if", "it", "was", "not", "retained", "and", "whether", "the", "Block", "was", "retained", "by", "the", "cache", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L679-L684
15,003
biogo/hts
bgzf/reader.go
keep
func (bg *Reader) keep(b Block) { if b == nil || !b.hasData() { return } bg.mu.RLock() defer bg.mu.RUnlock() if bg.cache != nil { bg.cache.Put(b) } }
go
func (bg *Reader) keep(b Block) { if b == nil || !b.hasData() { return } bg.mu.RLock() defer bg.mu.RUnlock() if bg.cache != nil { bg.cache.Put(b) } }
[ "func", "(", "bg", "*", "Reader", ")", "keep", "(", "b", "Block", ")", "{", "if", "b", "==", "nil", "||", "!", "b", ".", "hasData", "(", ")", "{", "return", "\n", "}", "\n", "bg", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "bg", ".", "mu", ".", "RUnlock", "(", ")", "\n", "if", "bg", ".", "cache", "!=", "nil", "{", "bg", ".", "cache", ".", "Put", "(", "b", ")", "\n", "}", "\n", "}" ]
// keep puts the given Block into the cache if it exists.
[ "keep", "puts", "the", "given", "Block", "into", "the", "cache", "if", "it", "exists", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L687-L696
15,004
biogo/hts
bgzf/reader.go
End
func (t *Tx) End() Chunk { c := Chunk{Begin: t.begin, End: t.r.lastChunk.End} t.r = nil return c }
go
func (t *Tx) End() Chunk { c := Chunk{Begin: t.begin, End: t.r.lastChunk.End} t.r = nil return c }
[ "func", "(", "t", "*", "Tx", ")", "End", "(", ")", "Chunk", "{", "c", ":=", "Chunk", "{", "Begin", ":", "t", ".", "begin", ",", "End", ":", "t", ".", "r", ".", "lastChunk", ".", "End", "}", "\n", "t", ".", "r", "=", "nil", "\n", "return", "c", "\n", "}" ]
// End returns the Chunk spanning the transaction. After return the Tx is // no longer valid.
[ "End", "returns", "the", "Chunk", "spanning", "the", "transaction", ".", "After", "return", "the", "Tx", "is", "no", "longer", "valid", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L709-L713
15,005
biogo/hts
internal/index_write.go
WriteIndex
func WriteIndex(w io.Writer, idx *Index, typ string) error { idx.sort() err := writeIndices(w, idx.Refs, typ) if err != nil { return err } if idx.Unmapped != nil { err = binary.Write(w, binary.LittleEndian, *idx.Unmapped) } return err }
go
func WriteIndex(w io.Writer, idx *Index, typ string) error { idx.sort() err := writeIndices(w, idx.Refs, typ) if err != nil { return err } if idx.Unmapped != nil { err = binary.Write(w, binary.LittleEndian, *idx.Unmapped) } return err }
[ "func", "WriteIndex", "(", "w", "io", ".", "Writer", ",", "idx", "*", "Index", ",", "typ", "string", ")", "error", "{", "idx", ".", "sort", "(", ")", "\n", "err", ":=", "writeIndices", "(", "w", ",", "idx", ".", "Refs", ",", "typ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "idx", ".", "Unmapped", "!=", "nil", "{", "err", "=", "binary", ".", "Write", "(", "w", ",", "binary", ".", "LittleEndian", ",", "*", "idx", ".", "Unmapped", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// WriteIndex writes the Index to the given io.Writer.
[ "WriteIndex", "writes", "the", "Index", "to", "the", "given", "io", ".", "Writer", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/internal/index_write.go#L16-L26
15,006
biogo/hts
cram/encoding/itf8/itf.go
Len
func Len(v int32) int { u := uint32(v) switch { case u < 0x80: return 1 case u < 0x4000: return 2 case u < 0x200000: return 3 case u < 0x10000000: return 4 default: return 5 } }
go
func Len(v int32) int { u := uint32(v) switch { case u < 0x80: return 1 case u < 0x4000: return 2 case u < 0x200000: return 3 case u < 0x10000000: return 4 default: return 5 } }
[ "func", "Len", "(", "v", "int32", ")", "int", "{", "u", ":=", "uint32", "(", "v", ")", "\n", "switch", "{", "case", "u", "<", "0x80", ":", "return", "1", "\n", "case", "u", "<", "0x4000", ":", "return", "2", "\n", "case", "u", "<", "0x200000", ":", "return", "3", "\n", "case", "u", "<", "0x10000000", ":", "return", "4", "\n", "default", ":", "return", "5", "\n", "}", "\n", "}" ]
// Len returns the number of bytes required to encode u.
[ "Len", "returns", "the", "number", "of", "bytes", "required", "to", "encode", "u", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/encoding/itf8/itf.go#L14-L28
15,007
biogo/hts
cram/encoding/itf8/itf.go
Decode
func Decode(b []byte) (v int32, n int, ok bool) { if len(b) == 0 { return 0, 0, false } n = bits.LeadingZeros8(^(b[0] & 0xf0)) + 1 if len(b) < n { return 0, n, false } switch n { case 1: v = int32(b[0]) case 2: v = int32(b[1]) | int32(b[0]&0x3f)<<8 case 3: v = int32(b[2]) | int32(b[1])<<8 | int32(b[0]&0x1f)<<16 case 4: v = int32(b[3]) | int32(b[2])<<8 | int32(b[1])<<16 | int32(b[0]&0x0f)<<24 case 5: v = int32(b[4]&0x0f) | int32(b[3])<<4 | int32(b[2])<<12 | int32(b[1])<<20 | int32(b[0]&0x0f)<<28 } return v, n, true }
go
func Decode(b []byte) (v int32, n int, ok bool) { if len(b) == 0 { return 0, 0, false } n = bits.LeadingZeros8(^(b[0] & 0xf0)) + 1 if len(b) < n { return 0, n, false } switch n { case 1: v = int32(b[0]) case 2: v = int32(b[1]) | int32(b[0]&0x3f)<<8 case 3: v = int32(b[2]) | int32(b[1])<<8 | int32(b[0]&0x1f)<<16 case 4: v = int32(b[3]) | int32(b[2])<<8 | int32(b[1])<<16 | int32(b[0]&0x0f)<<24 case 5: v = int32(b[4]&0x0f) | int32(b[3])<<4 | int32(b[2])<<12 | int32(b[1])<<20 | int32(b[0]&0x0f)<<28 } return v, n, true }
[ "func", "Decode", "(", "b", "[", "]", "byte", ")", "(", "v", "int32", ",", "n", "int", ",", "ok", "bool", ")", "{", "if", "len", "(", "b", ")", "==", "0", "{", "return", "0", ",", "0", ",", "false", "\n", "}", "\n", "n", "=", "bits", ".", "LeadingZeros8", "(", "^", "(", "b", "[", "0", "]", "&", "0xf0", ")", ")", "+", "1", "\n", "if", "len", "(", "b", ")", "<", "n", "{", "return", "0", ",", "n", ",", "false", "\n", "}", "\n", "switch", "n", "{", "case", "1", ":", "v", "=", "int32", "(", "b", "[", "0", "]", ")", "\n", "case", "2", ":", "v", "=", "int32", "(", "b", "[", "1", "]", ")", "|", "int32", "(", "b", "[", "0", "]", "&", "0x3f", ")", "<<", "8", "\n", "case", "3", ":", "v", "=", "int32", "(", "b", "[", "2", "]", ")", "|", "int32", "(", "b", "[", "1", "]", ")", "<<", "8", "|", "int32", "(", "b", "[", "0", "]", "&", "0x1f", ")", "<<", "16", "\n", "case", "4", ":", "v", "=", "int32", "(", "b", "[", "3", "]", ")", "|", "int32", "(", "b", "[", "2", "]", ")", "<<", "8", "|", "int32", "(", "b", "[", "1", "]", ")", "<<", "16", "|", "int32", "(", "b", "[", "0", "]", "&", "0x0f", ")", "<<", "24", "\n", "case", "5", ":", "v", "=", "int32", "(", "b", "[", "4", "]", "&", "0x0f", ")", "|", "int32", "(", "b", "[", "3", "]", ")", "<<", "4", "|", "int32", "(", "b", "[", "2", "]", ")", "<<", "12", "|", "int32", "(", "b", "[", "1", "]", ")", "<<", "20", "|", "int32", "(", "b", "[", "0", "]", "&", "0x0f", ")", "<<", "28", "\n", "}", "\n", "return", "v", ",", "n", ",", "true", "\n", "}" ]
// Decode decodes the ITF-8 encoding in b and returns the int32 value, its // width in bytes and whether the decoding was successful. If the encoding // is invalid, the expected length of b and false are returned. If b has zero // length, zero, zero and false are returned.
[ "Decode", "decodes", "the", "ITF", "-", "8", "encoding", "in", "b", "and", "returns", "the", "int32", "value", "its", "width", "in", "bytes", "and", "whether", "the", "decoding", "was", "successful", ".", "If", "the", "encoding", "is", "invalid", "the", "expected", "length", "of", "b", "and", "false", "are", "returned", ".", "If", "b", "has", "zero", "length", "zero", "zero", "and", "false", "are", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/encoding/itf8/itf.go#L34-L55
15,008
biogo/hts
cram/encoding/itf8/itf.go
Encode
func Encode(b []byte, v int32) int { u := uint32(v) switch { case u < 0x80: b[0] = byte(u) return 1 case u < 0x4000: _ = b[1] b[0] = byte(u>>8)&0x3f | 0x80 b[1] = byte(u) return 2 case u < 0x200000: _ = b[2] b[0] = byte(u>>16)&0x1f | 0xc0 b[1] = byte(u >> 8) b[2] = byte(u) return 3 case u < 0x10000000: _ = b[3] b[0] = byte(u>>24)&0x0f | 0xe0 b[1] = byte(u >> 16) b[2] = byte(u >> 8) b[3] = byte(u) return 4 default: _ = b[4] b[0] = byte(u>>28) | 0xf0 b[1] = byte(u >> 20) b[2] = byte(u >> 12) b[3] = byte(u >> 2) b[4] = byte(u) return 5 } }
go
func Encode(b []byte, v int32) int { u := uint32(v) switch { case u < 0x80: b[0] = byte(u) return 1 case u < 0x4000: _ = b[1] b[0] = byte(u>>8)&0x3f | 0x80 b[1] = byte(u) return 2 case u < 0x200000: _ = b[2] b[0] = byte(u>>16)&0x1f | 0xc0 b[1] = byte(u >> 8) b[2] = byte(u) return 3 case u < 0x10000000: _ = b[3] b[0] = byte(u>>24)&0x0f | 0xe0 b[1] = byte(u >> 16) b[2] = byte(u >> 8) b[3] = byte(u) return 4 default: _ = b[4] b[0] = byte(u>>28) | 0xf0 b[1] = byte(u >> 20) b[2] = byte(u >> 12) b[3] = byte(u >> 2) b[4] = byte(u) return 5 } }
[ "func", "Encode", "(", "b", "[", "]", "byte", ",", "v", "int32", ")", "int", "{", "u", ":=", "uint32", "(", "v", ")", "\n", "switch", "{", "case", "u", "<", "0x80", ":", "b", "[", "0", "]", "=", "byte", "(", "u", ")", "\n", "return", "1", "\n", "case", "u", "<", "0x4000", ":", "_", "=", "b", "[", "1", "]", "\n", "b", "[", "0", "]", "=", "byte", "(", "u", ">>", "8", ")", "&", "0x3f", "|", "0x80", "\n", "b", "[", "1", "]", "=", "byte", "(", "u", ")", "\n", "return", "2", "\n", "case", "u", "<", "0x200000", ":", "_", "=", "b", "[", "2", "]", "\n", "b", "[", "0", "]", "=", "byte", "(", "u", ">>", "16", ")", "&", "0x1f", "|", "0xc0", "\n", "b", "[", "1", "]", "=", "byte", "(", "u", ">>", "8", ")", "\n", "b", "[", "2", "]", "=", "byte", "(", "u", ")", "\n", "return", "3", "\n", "case", "u", "<", "0x10000000", ":", "_", "=", "b", "[", "3", "]", "\n", "b", "[", "0", "]", "=", "byte", "(", "u", ">>", "24", ")", "&", "0x0f", "|", "0xe0", "\n", "b", "[", "1", "]", "=", "byte", "(", "u", ">>", "16", ")", "\n", "b", "[", "2", "]", "=", "byte", "(", "u", ">>", "8", ")", "\n", "b", "[", "3", "]", "=", "byte", "(", "u", ")", "\n", "return", "4", "\n", "default", ":", "_", "=", "b", "[", "4", "]", "\n", "b", "[", "0", "]", "=", "byte", "(", "u", ">>", "28", ")", "|", "0xf0", "\n", "b", "[", "1", "]", "=", "byte", "(", "u", ">>", "20", ")", "\n", "b", "[", "2", "]", "=", "byte", "(", "u", ">>", "12", ")", "\n", "b", "[", "3", "]", "=", "byte", "(", "u", ">>", "2", ")", "\n", "b", "[", "4", "]", "=", "byte", "(", "u", ")", "\n", "return", "5", "\n", "}", "\n", "}" ]
// Encode encodes v as an ITF-8 into b, which must be large enough, and // and returns the number of bytes written.
[ "Encode", "encodes", "v", "as", "an", "ITF", "-", "8", "into", "b", "which", "must", "be", "large", "enough", "and", "and", "returns", "the", "number", "of", "bytes", "written", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/encoding/itf8/itf.go#L59-L92
15,009
biogo/hts
sam/auxtags.go
Get
func (a AuxFields) Get(tag Tag) Aux { for _, f := range a { if f.Tag() == tag { return f } } return nil }
go
func (a AuxFields) Get(tag Tag) Aux { for _, f := range a { if f.Tag() == tag { return f } } return nil }
[ "func", "(", "a", "AuxFields", ")", "Get", "(", "tag", "Tag", ")", "Aux", "{", "for", "_", ",", "f", ":=", "range", "a", "{", "if", "f", ".", "Tag", "(", ")", "==", "tag", "{", "return", "f", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Get returns the auxiliary field identified by the given tag, or nil // if no field matches.
[ "Get", "returns", "the", "auxiliary", "field", "identified", "by", "the", "given", "tag", "or", "nil", "if", "no", "field", "matches", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/auxtags.go#L481-L488
15,010
biogo/hts
sam/parse_header.go
DecodeBinary
func (bh *Header) DecodeBinary(r io.Reader) error { var ( lText, nRef int32 err error ) var magic [4]byte err = binary.Read(r, binary.LittleEndian, &magic) if err != nil { return err } if magic != bamMagic { return errors.New("sam: magic number mismatch") } err = binary.Read(r, binary.LittleEndian, &lText) if err != nil { return err } if lText < 0 { return errors.New("sam: invalid text length") } text := make([]byte, lText) n, err := r.Read(text) if err != nil { return err } if n != int(lText) { return errors.New("sam: truncated header") } err = bh.UnmarshalText(text) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &nRef) if err != nil { return err } if nRef < 0 { return errors.New("sam: invalid reference count field") } refs, err := readRefRecords(r, nRef) if err != nil { return err } for _, r := range refs { err = bh.AddReference(r) if err != nil { return err } } return nil }
go
func (bh *Header) DecodeBinary(r io.Reader) error { var ( lText, nRef int32 err error ) var magic [4]byte err = binary.Read(r, binary.LittleEndian, &magic) if err != nil { return err } if magic != bamMagic { return errors.New("sam: magic number mismatch") } err = binary.Read(r, binary.LittleEndian, &lText) if err != nil { return err } if lText < 0 { return errors.New("sam: invalid text length") } text := make([]byte, lText) n, err := r.Read(text) if err != nil { return err } if n != int(lText) { return errors.New("sam: truncated header") } err = bh.UnmarshalText(text) if err != nil { return err } err = binary.Read(r, binary.LittleEndian, &nRef) if err != nil { return err } if nRef < 0 { return errors.New("sam: invalid reference count field") } refs, err := readRefRecords(r, nRef) if err != nil { return err } for _, r := range refs { err = bh.AddReference(r) if err != nil { return err } } return nil }
[ "func", "(", "bh", "*", "Header", ")", "DecodeBinary", "(", "r", "io", ".", "Reader", ")", "error", "{", "var", "(", "lText", ",", "nRef", "int32", "\n", "err", "error", "\n", ")", "\n", "var", "magic", "[", "4", "]", "byte", "\n", "err", "=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "magic", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "magic", "!=", "bamMagic", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "err", "=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "lText", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "lText", "<", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "text", ":=", "make", "(", "[", "]", "byte", ",", "lText", ")", "\n", "n", ",", "err", ":=", "r", ".", "Read", "(", "text", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "n", "!=", "int", "(", "lText", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "err", "=", "bh", ".", "UnmarshalText", "(", "text", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "nRef", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "nRef", "<", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "refs", ",", "err", ":=", "readRefRecords", "(", "r", ",", "nRef", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "refs", "{", "err", "=", "bh", ".", "AddReference", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/parse_header.go#L35-L85
15,011
biogo/hts
bgzf/cache/cache.go
Free
func Free(n int, c Cache) bool { empty := c.Cap() - c.Len() if n <= empty { return true } c.Drop(n - empty) return c.Cap()-c.Len() >= n }
go
func Free(n int, c Cache) bool { empty := c.Cap() - c.Len() if n <= empty { return true } c.Drop(n - empty) return c.Cap()-c.Len() >= n }
[ "func", "Free", "(", "n", "int", ",", "c", "Cache", ")", "bool", "{", "empty", ":=", "c", ".", "Cap", "(", ")", "-", "c", ".", "Len", "(", ")", "\n", "if", "n", "<=", "empty", "{", "return", "true", "\n", "}", "\n", "c", ".", "Drop", "(", "n", "-", "empty", ")", "\n", "return", "c", ".", "Cap", "(", ")", "-", "c", ".", "Len", "(", ")", ">=", "n", "\n", "}" ]
// Free attempts to drop as many blocks from c as needed allow // n successful Put calls on c. It returns a boolean indicating // whether n slots were made available.
[ "Free", "attempts", "to", "drop", "as", "many", "blocks", "from", "c", "as", "needed", "allow", "n", "successful", "Put", "calls", "on", "c", ".", "It", "returns", "a", "boolean", "indicating", "whether", "n", "slots", "were", "made", "available", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L23-L30
15,012
biogo/hts
bgzf/cache/cache.go
NewLRU
func NewLRU(n int) Cache { if n < 1 { return nil } c := LRU{ table: make(map[int64]*node, n), cap: n, } c.root.next = &c.root c.root.prev = &c.root return &c }
go
func NewLRU(n int) Cache { if n < 1 { return nil } c := LRU{ table: make(map[int64]*node, n), cap: n, } c.root.next = &c.root c.root.prev = &c.root return &c }
[ "func", "NewLRU", "(", "n", "int", ")", "Cache", "{", "if", "n", "<", "1", "{", "return", "nil", "\n", "}", "\n", "c", ":=", "LRU", "{", "table", ":", "make", "(", "map", "[", "int64", "]", "*", "node", ",", "n", ")", ",", "cap", ":", "n", ",", "}", "\n", "c", ".", "root", ".", "next", "=", "&", "c", ".", "root", "\n", "c", ".", "root", ".", "prev", "=", "&", "c", ".", "root", "\n", "return", "&", "c", "\n", "}" ]
// NewLRU returns an LRU cache with n slots. If n is less than 1 // a nil cache is returned.
[ "NewLRU", "returns", "an", "LRU", "cache", "with", "n", "slots", ".", "If", "n", "is", "less", "than", "1", "a", "nil", "cache", "is", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L70-L81
15,013
biogo/hts
bgzf/cache/cache.go
Resize
func (c *LRU) Resize(n int) { c.mu.Lock() if n < len(c.table) { c.drop(len(c.table) - n) } c.cap = n c.mu.Unlock() }
go
func (c *LRU) Resize(n int) { c.mu.Lock() if n < len(c.table) { c.drop(len(c.table) - n) } c.cap = n c.mu.Unlock() }
[ "func", "(", "c", "*", "LRU", ")", "Resize", "(", "n", "int", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "n", "<", "len", "(", "c", ".", "table", ")", "{", "c", ".", "drop", "(", "len", "(", "c", ".", "table", ")", "-", "n", ")", "\n", "}", "\n", "c", ".", "cap", "=", "n", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Resize changes the capacity of the cache to n, dropping excess blocks // if n is less than the number of cached blocks.
[ "Resize", "changes", "the", "capacity", "of", "the", "cache", "to", "n", "dropping", "excess", "blocks", "if", "n", "is", "less", "than", "the", "number", "of", "cached", "blocks", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L116-L123
15,014
biogo/hts
bgzf/cache/cache.go
Drop
func (c *LRU) Drop(n int) { c.mu.Lock() c.drop(n) c.mu.Unlock() }
go
func (c *LRU) Drop(n int) { c.mu.Lock() c.drop(n) c.mu.Unlock() }
[ "func", "(", "c", "*", "LRU", ")", "Drop", "(", "n", "int", ")", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "c", ".", "drop", "(", "n", ")", "\n", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Drop evicts n elements from the cache according to the cache eviction policy.
[ "Drop", "evicts", "n", "elements", "from", "the", "cache", "according", "to", "the", "cache", "eviction", "policy", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L126-L130
15,015
biogo/hts
bgzf/cache/cache.go
Peek
func (c *LRU) Peek(base int64) (exist bool, next int64) { c.mu.RLock() defer c.mu.RUnlock() n, exist := c.table[base] if !exist { return false, -1 } next = n.b.NextBase() return exist, next }
go
func (c *LRU) Peek(base int64) (exist bool, next int64) { c.mu.RLock() defer c.mu.RUnlock() n, exist := c.table[base] if !exist { return false, -1 } next = n.b.NextBase() return exist, next }
[ "func", "(", "c", "*", "LRU", ")", "Peek", "(", "base", "int64", ")", "(", "exist", "bool", ",", "next", "int64", ")", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n\n", "n", ",", "exist", ":=", "c", ".", "table", "[", "base", "]", "\n", "if", "!", "exist", "{", "return", "false", ",", "-", "1", "\n", "}", "\n", "next", "=", "n", ".", "b", ".", "NextBase", "(", ")", "\n", "return", "exist", ",", "next", "\n", "}" ]
// Peek returns a boolean indicating whether a Block exists in the Cache for // the given base offset and the expected offset for the subsequent Block in // the BGZF stream.
[ "Peek", "returns", "a", "boolean", "indicating", "whether", "a", "Block", "exists", "in", "the", "Cache", "for", "the", "given", "base", "offset", "and", "the", "expected", "offset", "for", "the", "subsequent", "Block", "in", "the", "BGZF", "stream", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L155-L165
15,016
biogo/hts
bgzf/cache/cache.go
NewFIFO
func NewFIFO(n int) Cache { if n < 1 { return nil } c := FIFO{ table: make(map[int64]*node, n), cap: n, } c.root.next = &c.root c.root.prev = &c.root return &c }
go
func NewFIFO(n int) Cache { if n < 1 { return nil } c := FIFO{ table: make(map[int64]*node, n), cap: n, } c.root.next = &c.root c.root.prev = &c.root return &c }
[ "func", "NewFIFO", "(", "n", "int", ")", "Cache", "{", "if", "n", "<", "1", "{", "return", "nil", "\n", "}", "\n", "c", ":=", "FIFO", "{", "table", ":", "make", "(", "map", "[", "int64", "]", "*", "node", ",", "n", ")", ",", "cap", ":", "n", ",", "}", "\n", "c", ".", "root", ".", "next", "=", "&", "c", ".", "root", "\n", "c", ".", "root", ".", "prev", "=", "&", "c", ".", "root", "\n", "return", "&", "c", "\n", "}" ]
// NewFIFO returns a FIFO cache with n slots. If n is less than 1 // a nil cache is returned.
[ "NewFIFO", "returns", "a", "FIFO", "cache", "with", "n", "slots", ".", "If", "n", "is", "less", "than", "1", "a", "nil", "cache", "is", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L198-L209
15,017
biogo/hts
bgzf/cache/cache.go
NewRandom
func NewRandom(n int) Cache { if n < 1 { return nil } return &Random{ table: make(map[int64]bgzf.Block, n), cap: n, } }
go
func NewRandom(n int) Cache { if n < 1 { return nil } return &Random{ table: make(map[int64]bgzf.Block, n), cap: n, } }
[ "func", "NewRandom", "(", "n", "int", ")", "Cache", "{", "if", "n", "<", "1", "{", "return", "nil", "\n", "}", "\n", "return", "&", "Random", "{", "table", ":", "make", "(", "map", "[", "int64", "]", "bgzf", ".", "Block", ",", "n", ")", ",", "cap", ":", "n", ",", "}", "\n", "}" ]
// NewRandom returns a random eviction cache with n slots. If n is less than 1 // a nil cache is returned.
[ "NewRandom", "returns", "a", "random", "eviction", "cache", "with", "n", "slots", ".", "If", "n", "is", "less", "than", "1", "a", "nil", "cache", "is", "returned", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L322-L330
15,018
biogo/hts
bgzf/cache/cache.go
Len
func (c *Random) Len() int { c.mu.RLock() defer c.mu.RUnlock() return len(c.table) }
go
func (c *Random) Len() int { c.mu.RLock() defer c.mu.RUnlock() return len(c.table) }
[ "func", "(", "c", "*", "Random", ")", "Len", "(", ")", "int", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n\n", "return", "len", "(", "c", ".", "table", ")", "\n", "}" ]
// Len returns the number of elements held by the cache.
[ "Len", "returns", "the", "number", "of", "elements", "held", "by", "the", "cache", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L341-L346
15,019
biogo/hts
bgzf/cache/cache.go
Stats
func (s *StatsRecorder) Stats() Stats { s.mu.RLock() defer s.mu.RUnlock() return s.stats }
go
func (s *StatsRecorder) Stats() Stats { s.mu.RLock() defer s.mu.RUnlock() return s.stats }
[ "func", "(", "s", "*", "StatsRecorder", ")", "Stats", "(", ")", "Stats", "{", "s", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "s", ".", "stats", "\n", "}" ]
// Stats returns the current statistics for the cache.
[ "Stats", "returns", "the", "current", "statistics", "for", "the", "cache", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L476-L480
15,020
biogo/hts
bgzf/cache/cache.go
Reset
func (s *StatsRecorder) Reset() { s.mu.Lock() s.stats = Stats{} s.mu.Unlock() }
go
func (s *StatsRecorder) Reset() { s.mu.Lock() s.stats = Stats{} s.mu.Unlock() }
[ "func", "(", "s", "*", "StatsRecorder", ")", "Reset", "(", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "stats", "=", "Stats", "{", "}", "\n", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Reset zeros the statistics kept by the StatsRecorder.
[ "Reset", "zeros", "the", "statistics", "kept", "by", "the", "StatsRecorder", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L483-L487
15,021
biogo/hts
bgzf/cache/cache.go
Get
func (s *StatsRecorder) Get(base int64) bgzf.Block { s.mu.Lock() s.stats.Gets++ blk := s.Cache.Get(base) if blk == nil { s.stats.Misses++ } s.mu.Unlock() return blk }
go
func (s *StatsRecorder) Get(base int64) bgzf.Block { s.mu.Lock() s.stats.Gets++ blk := s.Cache.Get(base) if blk == nil { s.stats.Misses++ } s.mu.Unlock() return blk }
[ "func", "(", "s", "*", "StatsRecorder", ")", "Get", "(", "base", "int64", ")", "bgzf", ".", "Block", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "stats", ".", "Gets", "++", "\n", "blk", ":=", "s", ".", "Cache", ".", "Get", "(", "base", ")", "\n", "if", "blk", "==", "nil", "{", "s", ".", "stats", ".", "Misses", "++", "\n", "}", "\n", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "blk", "\n", "}" ]
// Get returns the Block in the underlying Cache with the specified base or a nil // Block if it does not exist. It updates the gets and misses statistics.
[ "Get", "returns", "the", "Block", "in", "the", "underlying", "Cache", "with", "the", "specified", "base", "or", "a", "nil", "Block", "if", "it", "does", "not", "exist", ".", "It", "updates", "the", "gets", "and", "misses", "statistics", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L491-L500
15,022
biogo/hts
bgzf/cache/cache.go
Put
func (s *StatsRecorder) Put(b bgzf.Block) (evicted bgzf.Block, retained bool) { s.mu.Lock() s.stats.Puts++ blk, retained := s.Cache.Put(b) if retained { s.stats.Retains++ if blk != nil { s.stats.Evictions++ } } s.mu.Unlock() return blk, retained }
go
func (s *StatsRecorder) Put(b bgzf.Block) (evicted bgzf.Block, retained bool) { s.mu.Lock() s.stats.Puts++ blk, retained := s.Cache.Put(b) if retained { s.stats.Retains++ if blk != nil { s.stats.Evictions++ } } s.mu.Unlock() return blk, retained }
[ "func", "(", "s", "*", "StatsRecorder", ")", "Put", "(", "b", "bgzf", ".", "Block", ")", "(", "evicted", "bgzf", ".", "Block", ",", "retained", "bool", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "stats", ".", "Puts", "++", "\n", "blk", ",", "retained", ":=", "s", ".", "Cache", ".", "Put", "(", "b", ")", "\n", "if", "retained", "{", "s", ".", "stats", ".", "Retains", "++", "\n", "if", "blk", "!=", "nil", "{", "s", ".", "stats", ".", "Evictions", "++", "\n", "}", "\n", "}", "\n", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "blk", ",", "retained", "\n", "}" ]
// Put inserts a Block into the underlying Cache, returning the Block and eviction // status according to the underlying cache behavior. It updates the puts, retains and // evictions statistics.
[ "Put", "inserts", "a", "Block", "into", "the", "underlying", "Cache", "returning", "the", "Block", "and", "eviction", "status", "according", "to", "the", "underlying", "cache", "behavior", ".", "It", "updates", "the", "puts", "retains", "and", "evictions", "statistics", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/cache/cache.go#L505-L517
15,023
biogo/hts
sam/read_group.go
NewReadGroup
func NewReadGroup(name, center, desc, lib, prog, plat, unit, sample, flow, key string, date time.Time, size int) (*ReadGroup, error) { if !validInt32(size) { return nil, errors.New("sam: length overflow") } return &ReadGroup{ id: -1, // This is altered by a Header when added. name: name, center: center, description: desc, date: date, flowOrder: flow, keySeq: key, library: lib, program: prog, insertSize: size, platform: plat, platformUnit: unit, sample: sample, }, nil }
go
func NewReadGroup(name, center, desc, lib, prog, plat, unit, sample, flow, key string, date time.Time, size int) (*ReadGroup, error) { if !validInt32(size) { return nil, errors.New("sam: length overflow") } return &ReadGroup{ id: -1, // This is altered by a Header when added. name: name, center: center, description: desc, date: date, flowOrder: flow, keySeq: key, library: lib, program: prog, insertSize: size, platform: plat, platformUnit: unit, sample: sample, }, nil }
[ "func", "NewReadGroup", "(", "name", ",", "center", ",", "desc", ",", "lib", ",", "prog", ",", "plat", ",", "unit", ",", "sample", ",", "flow", ",", "key", "string", ",", "date", "time", ".", "Time", ",", "size", "int", ")", "(", "*", "ReadGroup", ",", "error", ")", "{", "if", "!", "validInt32", "(", "size", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "&", "ReadGroup", "{", "id", ":", "-", "1", ",", "// This is altered by a Header when added.", "name", ":", "name", ",", "center", ":", "center", ",", "description", ":", "desc", ",", "date", ":", "date", ",", "flowOrder", ":", "flow", ",", "keySeq", ":", "key", ",", "library", ":", "lib", ",", "program", ":", "prog", ",", "insertSize", ":", "size", ",", "platform", ":", "plat", ",", "platformUnit", ":", "unit", ",", "sample", ":", "sample", ",", "}", ",", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L37-L56
15,024
biogo/hts
sam/read_group.go
SetName
func (r *ReadGroup) SetName(n string) error { if r.owner != nil { id, exists := r.owner.seenGroups[n] if exists { if id != r.id { return errors.New("sam: name exists") } return nil } delete(r.owner.seenGroups, r.name) r.owner.seenGroups[n] = r.id } r.name = n return nil }
go
func (r *ReadGroup) SetName(n string) error { if r.owner != nil { id, exists := r.owner.seenGroups[n] if exists { if id != r.id { return errors.New("sam: name exists") } return nil } delete(r.owner.seenGroups, r.name) r.owner.seenGroups[n] = r.id } r.name = n return nil }
[ "func", "(", "r", "*", "ReadGroup", ")", "SetName", "(", "n", "string", ")", "error", "{", "if", "r", ".", "owner", "!=", "nil", "{", "id", ",", "exists", ":=", "r", ".", "owner", ".", "seenGroups", "[", "n", "]", "\n", "if", "exists", "{", "if", "id", "!=", "r", ".", "id", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "delete", "(", "r", ".", "owner", ".", "seenGroups", ",", "r", ".", "name", ")", "\n", "r", ".", "owner", ".", "seenGroups", "[", "n", "]", "=", "r", ".", "id", "\n", "}", "\n", "r", ".", "name", "=", "n", "\n", "return", "nil", "\n", "}" ]
// SetName sets the read group's name to n.
[ "SetName", "sets", "the", "read", "group", "s", "name", "to", "n", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L75-L89
15,025
biogo/hts
sam/read_group.go
Clone
func (r *ReadGroup) Clone() *ReadGroup { if r == nil { return nil } cr := *r if len(cr.otherTags) != 0 { cr.otherTags = make([]tagPair, len(cr.otherTags)) } copy(cr.otherTags, r.otherTags) cr.id = -1 cr.owner = nil return &cr }
go
func (r *ReadGroup) Clone() *ReadGroup { if r == nil { return nil } cr := *r if len(cr.otherTags) != 0 { cr.otherTags = make([]tagPair, len(cr.otherTags)) } copy(cr.otherTags, r.otherTags) cr.id = -1 cr.owner = nil return &cr }
[ "func", "(", "r", "*", "ReadGroup", ")", "Clone", "(", ")", "*", "ReadGroup", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "cr", ":=", "*", "r", "\n", "if", "len", "(", "cr", ".", "otherTags", ")", "!=", "0", "{", "cr", ".", "otherTags", "=", "make", "(", "[", "]", "tagPair", ",", "len", "(", "cr", ".", "otherTags", ")", ")", "\n", "}", "\n", "copy", "(", "cr", ".", "otherTags", ",", "r", ".", "otherTags", ")", "\n", "cr", ".", "id", "=", "-", "1", "\n", "cr", ".", "owner", "=", "nil", "\n", "return", "&", "cr", "\n", "}" ]
// Clone returns a deep copy of the ReadGroup.
[ "Clone", "returns", "a", "deep", "copy", "of", "the", "ReadGroup", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L92-L104
15,026
biogo/hts
sam/read_group.go
Tags
func (r *ReadGroup) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(idTag, r.name) if r.center != "" { fn(centerTag, r.center) } if r.description != "" { fn(descriptionTag, r.description) } if !r.date.IsZero() { fn(dateTag, r.date.Format(iso8601TimeDateN)) } if r.flowOrder != "" { fn(flowOrderTag, r.flowOrder) } if r.keySeq != "" { fn(keySequenceTag, r.keySeq) } if r.library != "" { fn(libraryTag, r.library) } if r.program != "" { fn(programTag, r.program) } if r.insertSize != 0 { fn(insertSizeTag, fmt.Sprint(r.insertSize)) } if r.platform != "" { fn(platformTag, r.platform) } if r.platformUnit != "" { fn(platformUnitTag, r.platformUnit) } if r.sample != "" { fn(sampleTag, r.sample) } for _, tp := range r.otherTags { fn(tp.tag, tp.value) } }
go
func (r *ReadGroup) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(idTag, r.name) if r.center != "" { fn(centerTag, r.center) } if r.description != "" { fn(descriptionTag, r.description) } if !r.date.IsZero() { fn(dateTag, r.date.Format(iso8601TimeDateN)) } if r.flowOrder != "" { fn(flowOrderTag, r.flowOrder) } if r.keySeq != "" { fn(keySequenceTag, r.keySeq) } if r.library != "" { fn(libraryTag, r.library) } if r.program != "" { fn(programTag, r.program) } if r.insertSize != 0 { fn(insertSizeTag, fmt.Sprint(r.insertSize)) } if r.platform != "" { fn(platformTag, r.platform) } if r.platformUnit != "" { fn(platformUnitTag, r.platformUnit) } if r.sample != "" { fn(sampleTag, r.sample) } for _, tp := range r.otherTags { fn(tp.tag, tp.value) } }
[ "func", "(", "r", "*", "ReadGroup", ")", "Tags", "(", "fn", "func", "(", "t", "Tag", ",", "value", "string", ")", ")", "{", "if", "fn", "==", "nil", "{", "return", "\n", "}", "\n", "fn", "(", "idTag", ",", "r", ".", "name", ")", "\n", "if", "r", ".", "center", "!=", "\"", "\"", "{", "fn", "(", "centerTag", ",", "r", ".", "center", ")", "\n", "}", "\n", "if", "r", ".", "description", "!=", "\"", "\"", "{", "fn", "(", "descriptionTag", ",", "r", ".", "description", ")", "\n", "}", "\n", "if", "!", "r", ".", "date", ".", "IsZero", "(", ")", "{", "fn", "(", "dateTag", ",", "r", ".", "date", ".", "Format", "(", "iso8601TimeDateN", ")", ")", "\n", "}", "\n", "if", "r", ".", "flowOrder", "!=", "\"", "\"", "{", "fn", "(", "flowOrderTag", ",", "r", ".", "flowOrder", ")", "\n", "}", "\n", "if", "r", ".", "keySeq", "!=", "\"", "\"", "{", "fn", "(", "keySequenceTag", ",", "r", ".", "keySeq", ")", "\n", "}", "\n", "if", "r", ".", "library", "!=", "\"", "\"", "{", "fn", "(", "libraryTag", ",", "r", ".", "library", ")", "\n", "}", "\n", "if", "r", ".", "program", "!=", "\"", "\"", "{", "fn", "(", "programTag", ",", "r", ".", "program", ")", "\n", "}", "\n", "if", "r", ".", "insertSize", "!=", "0", "{", "fn", "(", "insertSizeTag", ",", "fmt", ".", "Sprint", "(", "r", ".", "insertSize", ")", ")", "\n", "}", "\n", "if", "r", ".", "platform", "!=", "\"", "\"", "{", "fn", "(", "platformTag", ",", "r", ".", "platform", ")", "\n", "}", "\n", "if", "r", ".", "platformUnit", "!=", "\"", "\"", "{", "fn", "(", "platformUnitTag", ",", "r", ".", "platformUnit", ")", "\n", "}", "\n", "if", "r", ".", "sample", "!=", "\"", "\"", "{", "fn", "(", "sampleTag", ",", "r", ".", "sample", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "fn", "(", "tp", ".", "tag", ",", "tp", ".", "value", ")", "\n", "}", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L118-L159
15,027
biogo/hts
sam/read_group.go
Get
func (r *ReadGroup) Get(t Tag) string { switch t { case idTag: return r.Name() case centerTag: return r.center case descriptionTag: return r.description case dateTag: return r.date.Format(iso8601TimeDateN) case flowOrderTag: if r.flowOrder == "" { return "*" } return r.flowOrder case keySequenceTag: return r.keySeq case libraryTag: return r.library case programTag: return r.program case insertSizeTag: return fmt.Sprint(r.insertSize) case platformTag: return r.platform case platformUnitTag: return r.platformUnit case sampleTag: return r.sample } for _, tp := range r.otherTags { if t == tp.tag { return tp.value } } return "" }
go
func (r *ReadGroup) Get(t Tag) string { switch t { case idTag: return r.Name() case centerTag: return r.center case descriptionTag: return r.description case dateTag: return r.date.Format(iso8601TimeDateN) case flowOrderTag: if r.flowOrder == "" { return "*" } return r.flowOrder case keySequenceTag: return r.keySeq case libraryTag: return r.library case programTag: return r.program case insertSizeTag: return fmt.Sprint(r.insertSize) case platformTag: return r.platform case platformUnitTag: return r.platformUnit case sampleTag: return r.sample } for _, tp := range r.otherTags { if t == tp.tag { return tp.value } } return "" }
[ "func", "(", "r", "*", "ReadGroup", ")", "Get", "(", "t", "Tag", ")", "string", "{", "switch", "t", "{", "case", "idTag", ":", "return", "r", ".", "Name", "(", ")", "\n", "case", "centerTag", ":", "return", "r", ".", "center", "\n", "case", "descriptionTag", ":", "return", "r", ".", "description", "\n", "case", "dateTag", ":", "return", "r", ".", "date", ".", "Format", "(", "iso8601TimeDateN", ")", "\n", "case", "flowOrderTag", ":", "if", "r", ".", "flowOrder", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "r", ".", "flowOrder", "\n", "case", "keySequenceTag", ":", "return", "r", ".", "keySeq", "\n", "case", "libraryTag", ":", "return", "r", ".", "library", "\n", "case", "programTag", ":", "return", "r", ".", "program", "\n", "case", "insertSizeTag", ":", "return", "fmt", ".", "Sprint", "(", "r", ".", "insertSize", ")", "\n", "case", "platformTag", ":", "return", "r", ".", "platform", "\n", "case", "platformUnitTag", ":", "return", "r", ".", "platformUnit", "\n", "case", "sampleTag", ":", "return", "r", ".", "sample", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "return", "tp", ".", "value", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L163-L199
15,028
biogo/hts
sam/read_group.go
Set
func (r *ReadGroup) Set(t Tag, value string) error { switch t { case idTag: r.name = value case centerTag: r.center = value case descriptionTag: r.description = value case dateTag: if value == "" { r.date = time.Time{} return nil } date, err := parseISO8601(value) if err != nil { return err } r.date = date case flowOrderTag: if value == "" || value == "*" { r.flowOrder = "" return nil } r.flowOrder = value case keySequenceTag: r.keySeq = value case libraryTag: r.library = value case programTag: r.program = value case insertSizeTag: if value == "" { r.insertSize = 0 return nil } i, err := strconv.Atoi(value) if err != nil { return err } if !validInt32(i) { return errBadLen } r.insertSize = i case platformTag: r.platform = value case platformUnitTag: r.platformUnit = value case sampleTag: r.sample = value default: if value == "" { for i, tp := range r.otherTags { if t == tp.tag { copy(r.otherTags[i:], r.otherTags[i+1:]) r.otherTags = r.otherTags[:len(r.otherTags)-1] return nil } } } else { for i, tp := range r.otherTags { if t == tp.tag { r.otherTags[i].value = value return nil } } r.otherTags = append(r.otherTags, tagPair{tag: t, value: value}) } } return nil }
go
func (r *ReadGroup) Set(t Tag, value string) error { switch t { case idTag: r.name = value case centerTag: r.center = value case descriptionTag: r.description = value case dateTag: if value == "" { r.date = time.Time{} return nil } date, err := parseISO8601(value) if err != nil { return err } r.date = date case flowOrderTag: if value == "" || value == "*" { r.flowOrder = "" return nil } r.flowOrder = value case keySequenceTag: r.keySeq = value case libraryTag: r.library = value case programTag: r.program = value case insertSizeTag: if value == "" { r.insertSize = 0 return nil } i, err := strconv.Atoi(value) if err != nil { return err } if !validInt32(i) { return errBadLen } r.insertSize = i case platformTag: r.platform = value case platformUnitTag: r.platformUnit = value case sampleTag: r.sample = value default: if value == "" { for i, tp := range r.otherTags { if t == tp.tag { copy(r.otherTags[i:], r.otherTags[i+1:]) r.otherTags = r.otherTags[:len(r.otherTags)-1] return nil } } } else { for i, tp := range r.otherTags { if t == tp.tag { r.otherTags[i].value = value return nil } } r.otherTags = append(r.otherTags, tagPair{tag: t, value: value}) } } return nil }
[ "func", "(", "r", "*", "ReadGroup", ")", "Set", "(", "t", "Tag", ",", "value", "string", ")", "error", "{", "switch", "t", "{", "case", "idTag", ":", "r", ".", "name", "=", "value", "\n", "case", "centerTag", ":", "r", ".", "center", "=", "value", "\n", "case", "descriptionTag", ":", "r", ".", "description", "=", "value", "\n", "case", "dateTag", ":", "if", "value", "==", "\"", "\"", "{", "r", ".", "date", "=", "time", ".", "Time", "{", "}", "\n", "return", "nil", "\n", "}", "\n", "date", ",", "err", ":=", "parseISO8601", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "r", ".", "date", "=", "date", "\n", "case", "flowOrderTag", ":", "if", "value", "==", "\"", "\"", "||", "value", "==", "\"", "\"", "{", "r", ".", "flowOrder", "=", "\"", "\"", "\n", "return", "nil", "\n", "}", "\n", "r", ".", "flowOrder", "=", "value", "\n", "case", "keySequenceTag", ":", "r", ".", "keySeq", "=", "value", "\n", "case", "libraryTag", ":", "r", ".", "library", "=", "value", "\n", "case", "programTag", ":", "r", ".", "program", "=", "value", "\n", "case", "insertSizeTag", ":", "if", "value", "==", "\"", "\"", "{", "r", ".", "insertSize", "=", "0", "\n", "return", "nil", "\n", "}", "\n", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "validInt32", "(", "i", ")", "{", "return", "errBadLen", "\n", "}", "\n", "r", ".", "insertSize", "=", "i", "\n", "case", "platformTag", ":", "r", ".", "platform", "=", "value", "\n", "case", "platformUnitTag", ":", "r", ".", "platformUnit", "=", "value", "\n", "case", "sampleTag", ":", "r", ".", "sample", "=", "value", "\n", "default", ":", "if", "value", "==", "\"", "\"", "{", "for", "i", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "copy", "(", "r", ".", "otherTags", "[", "i", ":", "]", ",", "r", ".", "otherTags", "[", "i", "+", "1", ":", "]", ")", "\n", "r", ".", "otherTags", "=", "r", ".", "otherTags", "[", ":", "len", "(", "r", ".", "otherTags", ")", "-", "1", "]", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "else", "{", "for", "i", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "r", ".", "otherTags", "[", "i", "]", ".", "value", "=", "value", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "r", ".", "otherTags", "=", "append", "(", "r", ".", "otherTags", ",", "tagPair", "{", "tag", ":", "t", ",", "value", ":", "value", "}", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L203-L272
15,029
biogo/hts
sam/read_group.go
String
func (r *ReadGroup) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "@RG\tID:%s", r.name) if r.center != "" { fmt.Fprintf(&buf, "\tCN:%s", r.center) } if r.description != "" { fmt.Fprintf(&buf, "\tDS:%s", r.description) } if (r.date != time.Time{}) { fmt.Fprintf(&buf, "\tDT:%s", r.date.Format(iso8601TimeDateN)) } if r.flowOrder != "" { fmt.Fprintf(&buf, "\tFO:%s", r.flowOrder) } if r.keySeq != "" { fmt.Fprintf(&buf, "\tKS:%s", r.keySeq) } if r.library != "" { fmt.Fprintf(&buf, "\tLB:%s", r.library) } if r.program != "" { fmt.Fprintf(&buf, "\tPG:%s", r.program) } if r.insertSize != 0 { fmt.Fprintf(&buf, "\tPI:%d", r.insertSize) } if r.platform != "" { fmt.Fprintf(&buf, "\tPL:%s", r.platform) } if r.platformUnit != "" { fmt.Fprintf(&buf, "\tPU:%s", r.platformUnit) } if r.sample != "" { fmt.Fprintf(&buf, "\tSM:%s", r.sample) } for _, tp := range r.otherTags { fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value) } return buf.String() }
go
func (r *ReadGroup) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "@RG\tID:%s", r.name) if r.center != "" { fmt.Fprintf(&buf, "\tCN:%s", r.center) } if r.description != "" { fmt.Fprintf(&buf, "\tDS:%s", r.description) } if (r.date != time.Time{}) { fmt.Fprintf(&buf, "\tDT:%s", r.date.Format(iso8601TimeDateN)) } if r.flowOrder != "" { fmt.Fprintf(&buf, "\tFO:%s", r.flowOrder) } if r.keySeq != "" { fmt.Fprintf(&buf, "\tKS:%s", r.keySeq) } if r.library != "" { fmt.Fprintf(&buf, "\tLB:%s", r.library) } if r.program != "" { fmt.Fprintf(&buf, "\tPG:%s", r.program) } if r.insertSize != 0 { fmt.Fprintf(&buf, "\tPI:%d", r.insertSize) } if r.platform != "" { fmt.Fprintf(&buf, "\tPL:%s", r.platform) } if r.platformUnit != "" { fmt.Fprintf(&buf, "\tPU:%s", r.platformUnit) } if r.sample != "" { fmt.Fprintf(&buf, "\tSM:%s", r.sample) } for _, tp := range r.otherTags { fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value) } return buf.String() }
[ "func", "(", "r", "*", "ReadGroup", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "name", ")", "\n", "if", "r", ".", "center", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "center", ")", "\n", "}", "\n", "if", "r", ".", "description", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "description", ")", "\n", "}", "\n", "if", "(", "r", ".", "date", "!=", "time", ".", "Time", "{", "}", ")", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "date", ".", "Format", "(", "iso8601TimeDateN", ")", ")", "\n", "}", "\n", "if", "r", ".", "flowOrder", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "flowOrder", ")", "\n", "}", "\n", "if", "r", ".", "keySeq", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "keySeq", ")", "\n", "}", "\n", "if", "r", ".", "library", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "library", ")", "\n", "}", "\n", "if", "r", ".", "program", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "program", ")", "\n", "}", "\n", "if", "r", ".", "insertSize", "!=", "0", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "insertSize", ")", "\n", "}", "\n", "if", "r", ".", "platform", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "platform", ")", "\n", "}", "\n", "if", "r", ".", "platformUnit", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "platformUnit", ")", "\n", "}", "\n", "if", "r", ".", "sample", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "sample", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "tp", ".", "tag", ",", "tp", ".", "value", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// String returns a string representation of the read group according to the // SAM specification section 1.3,
[ "String", "returns", "a", "string", "representation", "of", "the", "read", "group", "according", "to", "the", "SAM", "specification", "section", "1", ".", "3" ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/read_group.go#L276-L316
15,030
biogo/hts
cram/encoding/ltf8/ltf.go
Len
func Len(v int64) int { u := uint64(v) switch { case u < 0x80: return 1 case u < 0x4000: return 2 case u < 0x200000: return 3 case u < 0x10000000: return 4 case u < 0x800000000: return 5 case u < 0x40000000000: return 6 case u < 0x2000000000000: return 7 case u < 0x100000000000000: return 8 default: return 9 } }
go
func Len(v int64) int { u := uint64(v) switch { case u < 0x80: return 1 case u < 0x4000: return 2 case u < 0x200000: return 3 case u < 0x10000000: return 4 case u < 0x800000000: return 5 case u < 0x40000000000: return 6 case u < 0x2000000000000: return 7 case u < 0x100000000000000: return 8 default: return 9 } }
[ "func", "Len", "(", "v", "int64", ")", "int", "{", "u", ":=", "uint64", "(", "v", ")", "\n", "switch", "{", "case", "u", "<", "0x80", ":", "return", "1", "\n", "case", "u", "<", "0x4000", ":", "return", "2", "\n", "case", "u", "<", "0x200000", ":", "return", "3", "\n", "case", "u", "<", "0x10000000", ":", "return", "4", "\n", "case", "u", "<", "0x800000000", ":", "return", "5", "\n", "case", "u", "<", "0x40000000000", ":", "return", "6", "\n", "case", "u", "<", "0x2000000000000", ":", "return", "7", "\n", "case", "u", "<", "0x100000000000000", ":", "return", "8", "\n", "default", ":", "return", "9", "\n", "}", "\n", "}" ]
// Len returns the number of bytes required to encode v.
[ "Len", "returns", "the", "number", "of", "bytes", "required", "to", "encode", "v", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/encoding/ltf8/ltf.go#L14-L36
15,031
biogo/hts
internal/index_read.go
ReadIndex
func ReadIndex(r io.Reader, n int32, typ string) (Index, error) { var ( idx Index err error ) idx.Refs, err = readIndices(r, n, typ) if err != nil { return idx, err } var nUnmapped uint64 err = binary.Read(r, binary.LittleEndian, &nUnmapped) if err == nil { idx.Unmapped = &nUnmapped } else if err != io.EOF { return idx, err } idx.IsSorted = true // Set the index of the last record to max int to // prevent addition of records out of order. This // means that the only way to append to an index is // to re-index and add to that created index. // TODO(kortschak) See if index appending is feasible // and needed. idx.LastRecord = int(^uint(0) >> 1) return idx, nil }
go
func ReadIndex(r io.Reader, n int32, typ string) (Index, error) { var ( idx Index err error ) idx.Refs, err = readIndices(r, n, typ) if err != nil { return idx, err } var nUnmapped uint64 err = binary.Read(r, binary.LittleEndian, &nUnmapped) if err == nil { idx.Unmapped = &nUnmapped } else if err != io.EOF { return idx, err } idx.IsSorted = true // Set the index of the last record to max int to // prevent addition of records out of order. This // means that the only way to append to an index is // to re-index and add to that created index. // TODO(kortschak) See if index appending is feasible // and needed. idx.LastRecord = int(^uint(0) >> 1) return idx, nil }
[ "func", "ReadIndex", "(", "r", "io", ".", "Reader", ",", "n", "int32", ",", "typ", "string", ")", "(", "Index", ",", "error", ")", "{", "var", "(", "idx", "Index", "\n", "err", "error", "\n", ")", "\n", "idx", ".", "Refs", ",", "err", "=", "readIndices", "(", "r", ",", "n", ",", "typ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "idx", ",", "err", "\n", "}", "\n", "var", "nUnmapped", "uint64", "\n", "err", "=", "binary", ".", "Read", "(", "r", ",", "binary", ".", "LittleEndian", ",", "&", "nUnmapped", ")", "\n", "if", "err", "==", "nil", "{", "idx", ".", "Unmapped", "=", "&", "nUnmapped", "\n", "}", "else", "if", "err", "!=", "io", ".", "EOF", "{", "return", "idx", ",", "err", "\n", "}", "\n", "idx", ".", "IsSorted", "=", "true", "\n\n", "// Set the index of the last record to max int to", "// prevent addition of records out of order. This", "// means that the only way to append to an index is", "// to re-index and add to that created index.", "// TODO(kortschak) See if index appending is feasible", "// and needed.", "idx", ".", "LastRecord", "=", "int", "(", "^", "uint", "(", "0", ")", ">>", "1", ")", "\n\n", "return", "idx", ",", "nil", "\n", "}" ]
// ReadIndex reads the Index from the given io.Reader.
[ "ReadIndex", "reads", "the", "Index", "from", "the", "given", "io", ".", "Reader", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/internal/index_read.go#L17-L44
15,032
biogo/hts
bgzf/writer.go
NewWriter
func NewWriter(w io.Writer, wc int) *Writer { bg, _ := NewWriterLevel(w, gzip.DefaultCompression, wc) return bg }
go
func NewWriter(w io.Writer, wc int) *Writer { bg, _ := NewWriterLevel(w, gzip.DefaultCompression, wc) return bg }
[ "func", "NewWriter", "(", "w", "io", ".", "Writer", ",", "wc", "int", ")", "*", "Writer", "{", "bg", ",", "_", ":=", "NewWriterLevel", "(", "w", ",", "gzip", ".", "DefaultCompression", ",", "wc", ")", "\n", "return", "bg", "\n", "}" ]
// NewWriter returns a new Writer. Writes to the returned writer are // compressed and written to w. // // The number of concurrent write compressors is specified by wc.
[ "NewWriter", "returns", "a", "new", "Writer", ".", "Writes", "to", "the", "returned", "writer", "are", "compressed", "and", "written", "to", "w", ".", "The", "number", "of", "concurrent", "write", "compressors", "is", "specified", "by", "wc", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L43-L46
15,033
biogo/hts
bgzf/writer.go
NewWriterLevel
func NewWriterLevel(w io.Writer, level, wc int) (*Writer, error) { if level < gzip.DefaultCompression || level > gzip.BestCompression { return nil, fmt.Errorf("bgzf: invalid compression level: %d", level) } wc++ // We count one for the active compressor. if wc < 2 { wc = 2 } bg := &Writer{ w: w, waiting: make(chan *compressor, wc), queue: make(chan *compressor, wc), } bg.Header.OS = 0xff // Set default OS to unknown. c := make([]compressor, wc) for i := range c { c[i].Header = &bg.Header c[i].level = level c[i].waiting = bg.waiting c[i].flush = make(chan *compressor, 1) c[i].qwg = &bg.qwg bg.waiting <- &c[i] } bg.active = <-bg.waiting bg.wg.Add(1) go func() { defer bg.wg.Done() for qw := range bg.queue { if !writeOK(bg, <-qw.flush) { break } } }() return bg, nil }
go
func NewWriterLevel(w io.Writer, level, wc int) (*Writer, error) { if level < gzip.DefaultCompression || level > gzip.BestCompression { return nil, fmt.Errorf("bgzf: invalid compression level: %d", level) } wc++ // We count one for the active compressor. if wc < 2 { wc = 2 } bg := &Writer{ w: w, waiting: make(chan *compressor, wc), queue: make(chan *compressor, wc), } bg.Header.OS = 0xff // Set default OS to unknown. c := make([]compressor, wc) for i := range c { c[i].Header = &bg.Header c[i].level = level c[i].waiting = bg.waiting c[i].flush = make(chan *compressor, 1) c[i].qwg = &bg.qwg bg.waiting <- &c[i] } bg.active = <-bg.waiting bg.wg.Add(1) go func() { defer bg.wg.Done() for qw := range bg.queue { if !writeOK(bg, <-qw.flush) { break } } }() return bg, nil }
[ "func", "NewWriterLevel", "(", "w", "io", ".", "Writer", ",", "level", ",", "wc", "int", ")", "(", "*", "Writer", ",", "error", ")", "{", "if", "level", "<", "gzip", ".", "DefaultCompression", "||", "level", ">", "gzip", ".", "BestCompression", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "level", ")", "\n", "}", "\n", "wc", "++", "// We count one for the active compressor.", "\n", "if", "wc", "<", "2", "{", "wc", "=", "2", "\n", "}", "\n", "bg", ":=", "&", "Writer", "{", "w", ":", "w", ",", "waiting", ":", "make", "(", "chan", "*", "compressor", ",", "wc", ")", ",", "queue", ":", "make", "(", "chan", "*", "compressor", ",", "wc", ")", ",", "}", "\n", "bg", ".", "Header", ".", "OS", "=", "0xff", "// Set default OS to unknown.", "\n\n", "c", ":=", "make", "(", "[", "]", "compressor", ",", "wc", ")", "\n", "for", "i", ":=", "range", "c", "{", "c", "[", "i", "]", ".", "Header", "=", "&", "bg", ".", "Header", "\n", "c", "[", "i", "]", ".", "level", "=", "level", "\n", "c", "[", "i", "]", ".", "waiting", "=", "bg", ".", "waiting", "\n", "c", "[", "i", "]", ".", "flush", "=", "make", "(", "chan", "*", "compressor", ",", "1", ")", "\n", "c", "[", "i", "]", ".", "qwg", "=", "&", "bg", ".", "qwg", "\n", "bg", ".", "waiting", "<-", "&", "c", "[", "i", "]", "\n", "}", "\n", "bg", ".", "active", "=", "<-", "bg", ".", "waiting", "\n\n", "bg", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "defer", "bg", ".", "wg", ".", "Done", "(", ")", "\n", "for", "qw", ":=", "range", "bg", ".", "queue", "{", "if", "!", "writeOK", "(", "bg", ",", "<-", "qw", ".", "flush", ")", "{", "break", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "bg", ",", "nil", "\n", "}" ]
// NewWriterLevel returns a new Writer using the specified compression level // instead of gzip.DefaultCompression. Allowable level options are integer // values between between gzip.BestSpeed and gzip.BestCompression inclusive. // // The number of concurrent write compressors is specified by wc.
[ "NewWriterLevel", "returns", "a", "new", "Writer", "using", "the", "specified", "compression", "level", "instead", "of", "gzip", ".", "DefaultCompression", ".", "Allowable", "level", "options", "are", "integer", "values", "between", "between", "gzip", ".", "BestSpeed", "and", "gzip", ".", "BestCompression", "inclusive", ".", "The", "number", "of", "concurrent", "write", "compressors", "is", "specified", "by", "wc", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L53-L90
15,034
biogo/hts
bgzf/writer.go
Next
func (bg *Writer) Next() (int, error) { if bg.closed { return 0, ErrClosed } if err := bg.Error(); err != nil { return 0, err } return bg.active.next, nil }
go
func (bg *Writer) Next() (int, error) { if bg.closed { return 0, ErrClosed } if err := bg.Error(); err != nil { return 0, err } return bg.active.next, nil }
[ "func", "(", "bg", "*", "Writer", ")", "Next", "(", ")", "(", "int", ",", "error", ")", "{", "if", "bg", ".", "closed", "{", "return", "0", ",", "ErrClosed", "\n", "}", "\n", "if", "err", ":=", "bg", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "bg", ".", "active", ".", "next", ",", "nil", "\n", "}" ]
// Next returns the index of the start of the next write within the // decompressed data block.
[ "Next", "returns", "the", "index", "of", "the", "start", "of", "the", "next", "write", "within", "the", "decompressed", "data", "block", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L176-L185
15,035
biogo/hts
bgzf/writer.go
Write
func (bg *Writer) Write(b []byte) (int, error) { if bg.closed { return 0, ErrClosed } err := bg.Error() if err != nil { return 0, err } c := bg.active var n int for ; len(b) > 0 && err == nil; err = bg.Error() { var _n int if c.next == 0 || c.next+len(b) <= len(c.block) { _n = copy(c.block[c.next:], b) b = b[_n:] c.next += _n n += _n } if c.next == len(c.block) || _n == 0 { bg.queue <- c bg.qwg.Add(1) go c.writeBlock() c = <-bg.waiting } } bg.active = c return n, bg.Error() }
go
func (bg *Writer) Write(b []byte) (int, error) { if bg.closed { return 0, ErrClosed } err := bg.Error() if err != nil { return 0, err } c := bg.active var n int for ; len(b) > 0 && err == nil; err = bg.Error() { var _n int if c.next == 0 || c.next+len(b) <= len(c.block) { _n = copy(c.block[c.next:], b) b = b[_n:] c.next += _n n += _n } if c.next == len(c.block) || _n == 0 { bg.queue <- c bg.qwg.Add(1) go c.writeBlock() c = <-bg.waiting } } bg.active = c return n, bg.Error() }
[ "func", "(", "bg", "*", "Writer", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "bg", ".", "closed", "{", "return", "0", ",", "ErrClosed", "\n", "}", "\n", "err", ":=", "bg", ".", "Error", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "c", ":=", "bg", ".", "active", "\n", "var", "n", "int", "\n", "for", ";", "len", "(", "b", ")", ">", "0", "&&", "err", "==", "nil", ";", "err", "=", "bg", ".", "Error", "(", ")", "{", "var", "_n", "int", "\n", "if", "c", ".", "next", "==", "0", "||", "c", ".", "next", "+", "len", "(", "b", ")", "<=", "len", "(", "c", ".", "block", ")", "{", "_n", "=", "copy", "(", "c", ".", "block", "[", "c", ".", "next", ":", "]", ",", "b", ")", "\n", "b", "=", "b", "[", "_n", ":", "]", "\n", "c", ".", "next", "+=", "_n", "\n", "n", "+=", "_n", "\n", "}", "\n\n", "if", "c", ".", "next", "==", "len", "(", "c", ".", "block", ")", "||", "_n", "==", "0", "{", "bg", ".", "queue", "<-", "c", "\n", "bg", ".", "qwg", ".", "Add", "(", "1", ")", "\n", "go", "c", ".", "writeBlock", "(", ")", "\n", "c", "=", "<-", "bg", ".", "waiting", "\n", "}", "\n", "}", "\n", "bg", ".", "active", "=", "c", "\n\n", "return", "n", ",", "bg", ".", "Error", "(", ")", "\n", "}" ]
// Write writes the compressed form of b to the underlying io.Writer. // Decompressed data blocks are limited to BlockSize, so individual // byte slices may span block boundaries, however the Writer attempts // to keep each write within a single data block.
[ "Write", "writes", "the", "compressed", "form", "of", "b", "to", "the", "underlying", "io", ".", "Writer", ".", "Decompressed", "data", "blocks", "are", "limited", "to", "BlockSize", "so", "individual", "byte", "slices", "may", "span", "block", "boundaries", "however", "the", "Writer", "attempts", "to", "keep", "each", "write", "within", "a", "single", "data", "block", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L191-L221
15,036
biogo/hts
bgzf/writer.go
Flush
func (bg *Writer) Flush() error { if bg.closed { return ErrClosed } if err := bg.Error(); err != nil { return err } if bg.active.next == 0 { return nil } var c *compressor c, bg.active = bg.active, <-bg.waiting bg.queue <- c bg.qwg.Add(1) go c.writeBlock() return bg.Error() }
go
func (bg *Writer) Flush() error { if bg.closed { return ErrClosed } if err := bg.Error(); err != nil { return err } if bg.active.next == 0 { return nil } var c *compressor c, bg.active = bg.active, <-bg.waiting bg.queue <- c bg.qwg.Add(1) go c.writeBlock() return bg.Error() }
[ "func", "(", "bg", "*", "Writer", ")", "Flush", "(", ")", "error", "{", "if", "bg", ".", "closed", "{", "return", "ErrClosed", "\n", "}", "\n", "if", "err", ":=", "bg", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "bg", ".", "active", ".", "next", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "var", "c", "*", "compressor", "\n", "c", ",", "bg", ".", "active", "=", "bg", ".", "active", ",", "<-", "bg", ".", "waiting", "\n", "bg", ".", "queue", "<-", "c", "\n", "bg", ".", "qwg", ".", "Add", "(", "1", ")", "\n", "go", "c", ".", "writeBlock", "(", ")", "\n\n", "return", "bg", ".", "Error", "(", ")", "\n", "}" ]
// Flush writes unwritten data to the underlying io.Writer. Flush does not block.
[ "Flush", "writes", "unwritten", "data", "to", "the", "underlying", "io", ".", "Writer", ".", "Flush", "does", "not", "block", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L224-L243
15,037
biogo/hts
bgzf/writer.go
Wait
func (bg *Writer) Wait() error { if err := bg.Error(); err != nil { return err } bg.qwg.Wait() return bg.Error() }
go
func (bg *Writer) Wait() error { if err := bg.Error(); err != nil { return err } bg.qwg.Wait() return bg.Error() }
[ "func", "(", "bg", "*", "Writer", ")", "Wait", "(", ")", "error", "{", "if", "err", ":=", "bg", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "bg", ".", "qwg", ".", "Wait", "(", ")", "\n", "return", "bg", ".", "Error", "(", ")", "\n", "}" ]
// Wait waits for all pending writes to complete and returns the subsequent // error state of the Writer.
[ "Wait", "waits", "for", "all", "pending", "writes", "to", "complete", "and", "returns", "the", "subsequent", "error", "state", "of", "the", "Writer", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L247-L253
15,038
biogo/hts
bgzf/writer.go
Error
func (bg *Writer) Error() error { bg.m.Lock() defer bg.m.Unlock() return bg.err }
go
func (bg *Writer) Error() error { bg.m.Lock() defer bg.m.Unlock() return bg.err }
[ "func", "(", "bg", "*", "Writer", ")", "Error", "(", ")", "error", "{", "bg", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "bg", ".", "m", ".", "Unlock", "(", ")", "\n", "return", "bg", ".", "err", "\n", "}" ]
// Error returns the error state of the Writer.
[ "Error", "returns", "the", "error", "state", "of", "the", "Writer", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L256-L260
15,039
biogo/hts
bgzf/writer.go
Close
func (bg *Writer) Close() error { if !bg.closed { c := bg.active bg.queue <- c bg.qwg.Add(1) <-bg.waiting c.writeBlock() bg.closed = true close(bg.queue) bg.wg.Wait() if bg.err == nil { _, bg.err = bg.w.Write([]byte(magicBlock)) } } return bg.err }
go
func (bg *Writer) Close() error { if !bg.closed { c := bg.active bg.queue <- c bg.qwg.Add(1) <-bg.waiting c.writeBlock() bg.closed = true close(bg.queue) bg.wg.Wait() if bg.err == nil { _, bg.err = bg.w.Write([]byte(magicBlock)) } } return bg.err }
[ "func", "(", "bg", "*", "Writer", ")", "Close", "(", ")", "error", "{", "if", "!", "bg", ".", "closed", "{", "c", ":=", "bg", ".", "active", "\n", "bg", ".", "queue", "<-", "c", "\n", "bg", ".", "qwg", ".", "Add", "(", "1", ")", "\n", "<-", "bg", ".", "waiting", "\n", "c", ".", "writeBlock", "(", ")", "\n", "bg", ".", "closed", "=", "true", "\n", "close", "(", "bg", ".", "queue", ")", "\n", "bg", ".", "wg", ".", "Wait", "(", ")", "\n", "if", "bg", ".", "err", "==", "nil", "{", "_", ",", "bg", ".", "err", "=", "bg", ".", "w", ".", "Write", "(", "[", "]", "byte", "(", "magicBlock", ")", ")", "\n", "}", "\n", "}", "\n", "return", "bg", ".", "err", "\n", "}" ]
// Close closes the Writer, waiting for any pending writes before returning // the final error of the Writer.
[ "Close", "closes", "the", "Writer", "waiting", "for", "any", "pending", "writes", "before", "returning", "the", "final", "error", "of", "the", "Writer", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/writer.go#L272-L287
15,040
biogo/hts
sam/record.go
NewRecord
func NewRecord(name string, ref, mRef *Reference, p, mPos, tLen int, mapQ byte, co []CigarOp, seq, qual []byte, aux []Aux) (*Record, error) { if !(validPos(p) && validPos(mPos) && validTmpltLen(tLen) && validLen(len(seq)) && (qual == nil || validLen(len(qual)))) { return nil, errors.New("sam: value out of range") } if len(name) == 0 || len(name) > 254 { return nil, errors.New("sam: name absent or too long") } if qual != nil && len(qual) != len(seq) { return nil, errors.New("sam: sequence/quality length mismatch") } if ref != nil { if ref.id < 0 { return nil, errors.New("sam: linking to invalid reference") } } else { if p != -1 { return nil, errors.New("sam: specified position != -1 without reference") } } if mRef != nil { if mRef.id < 0 { return nil, errors.New("sam: linking to invalid mate reference") } } else { if mPos != -1 { return nil, errors.New("sam: specified mate position != -1 without mate reference") } } r := &Record{ Name: name, Ref: ref, Pos: p, MapQ: mapQ, Cigar: co, MateRef: mRef, MatePos: mPos, TempLen: tLen, Seq: NewSeq(seq), Qual: qual, AuxFields: aux, } return r, nil }
go
func NewRecord(name string, ref, mRef *Reference, p, mPos, tLen int, mapQ byte, co []CigarOp, seq, qual []byte, aux []Aux) (*Record, error) { if !(validPos(p) && validPos(mPos) && validTmpltLen(tLen) && validLen(len(seq)) && (qual == nil || validLen(len(qual)))) { return nil, errors.New("sam: value out of range") } if len(name) == 0 || len(name) > 254 { return nil, errors.New("sam: name absent or too long") } if qual != nil && len(qual) != len(seq) { return nil, errors.New("sam: sequence/quality length mismatch") } if ref != nil { if ref.id < 0 { return nil, errors.New("sam: linking to invalid reference") } } else { if p != -1 { return nil, errors.New("sam: specified position != -1 without reference") } } if mRef != nil { if mRef.id < 0 { return nil, errors.New("sam: linking to invalid mate reference") } } else { if mPos != -1 { return nil, errors.New("sam: specified mate position != -1 without mate reference") } } r := &Record{ Name: name, Ref: ref, Pos: p, MapQ: mapQ, Cigar: co, MateRef: mRef, MatePos: mPos, TempLen: tLen, Seq: NewSeq(seq), Qual: qual, AuxFields: aux, } return r, nil }
[ "func", "NewRecord", "(", "name", "string", ",", "ref", ",", "mRef", "*", "Reference", ",", "p", ",", "mPos", ",", "tLen", "int", ",", "mapQ", "byte", ",", "co", "[", "]", "CigarOp", ",", "seq", ",", "qual", "[", "]", "byte", ",", "aux", "[", "]", "Aux", ")", "(", "*", "Record", ",", "error", ")", "{", "if", "!", "(", "validPos", "(", "p", ")", "&&", "validPos", "(", "mPos", ")", "&&", "validTmpltLen", "(", "tLen", ")", "&&", "validLen", "(", "len", "(", "seq", ")", ")", "&&", "(", "qual", "==", "nil", "||", "validLen", "(", "len", "(", "qual", ")", ")", ")", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "name", ")", "==", "0", "||", "len", "(", "name", ")", ">", "254", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "qual", "!=", "nil", "&&", "len", "(", "qual", ")", "!=", "len", "(", "seq", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "ref", "!=", "nil", "{", "if", "ref", ".", "id", "<", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "{", "if", "p", "!=", "-", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "mRef", "!=", "nil", "{", "if", "mRef", ".", "id", "<", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "{", "if", "mPos", "!=", "-", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "r", ":=", "&", "Record", "{", "Name", ":", "name", ",", "Ref", ":", "ref", ",", "Pos", ":", "p", ",", "MapQ", ":", "mapQ", ",", "Cigar", ":", "co", ",", "MateRef", ":", "mRef", ",", "MatePos", ":", "mPos", ",", "TempLen", ":", "tLen", ",", "Seq", ":", "NewSeq", "(", "seq", ")", ",", "Qual", ":", "qual", ",", "AuxFields", ":", "aux", ",", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// NewRecord returns a Record, checking for consistency of the provided // attributes.
[ "NewRecord", "returns", "a", "Record", "checking", "for", "consistency", "of", "the", "provided", "attributes", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L34-L76
15,041
biogo/hts
sam/record.go
IsValidRecord
func IsValidRecord(r *Record) bool { if (r.Ref == nil || r.Pos == -1) && r.Flags&Unmapped == 0 { return false } if r.Flags&Paired != 0 && (r.MateRef == nil || r.MatePos == -1) && r.Flags&MateUnmapped == 0 { return false } if r.Flags&(Unmapped|ProperPair) == Unmapped|ProperPair { return false } if r.Flags&(Paired|MateUnmapped|ProperPair) == Paired|MateUnmapped|ProperPair { return false } if len(r.Qual) != 0 && r.Seq.Length != len(r.Qual) { return false } if cigarLen := r.Len(); cigarLen < 0 || (r.Seq.Length != 0 && r.Seq.Length != cigarLen) { return false } return true }
go
func IsValidRecord(r *Record) bool { if (r.Ref == nil || r.Pos == -1) && r.Flags&Unmapped == 0 { return false } if r.Flags&Paired != 0 && (r.MateRef == nil || r.MatePos == -1) && r.Flags&MateUnmapped == 0 { return false } if r.Flags&(Unmapped|ProperPair) == Unmapped|ProperPair { return false } if r.Flags&(Paired|MateUnmapped|ProperPair) == Paired|MateUnmapped|ProperPair { return false } if len(r.Qual) != 0 && r.Seq.Length != len(r.Qual) { return false } if cigarLen := r.Len(); cigarLen < 0 || (r.Seq.Length != 0 && r.Seq.Length != cigarLen) { return false } return true }
[ "func", "IsValidRecord", "(", "r", "*", "Record", ")", "bool", "{", "if", "(", "r", ".", "Ref", "==", "nil", "||", "r", ".", "Pos", "==", "-", "1", ")", "&&", "r", ".", "Flags", "&", "Unmapped", "==", "0", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "Flags", "&", "Paired", "!=", "0", "&&", "(", "r", ".", "MateRef", "==", "nil", "||", "r", ".", "MatePos", "==", "-", "1", ")", "&&", "r", ".", "Flags", "&", "MateUnmapped", "==", "0", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "Flags", "&", "(", "Unmapped", "|", "ProperPair", ")", "==", "Unmapped", "|", "ProperPair", "{", "return", "false", "\n", "}", "\n", "if", "r", ".", "Flags", "&", "(", "Paired", "|", "MateUnmapped", "|", "ProperPair", ")", "==", "Paired", "|", "MateUnmapped", "|", "ProperPair", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "r", ".", "Qual", ")", "!=", "0", "&&", "r", ".", "Seq", ".", "Length", "!=", "len", "(", "r", ".", "Qual", ")", "{", "return", "false", "\n", "}", "\n", "if", "cigarLen", ":=", "r", ".", "Len", "(", ")", ";", "cigarLen", "<", "0", "||", "(", "r", ".", "Seq", ".", "Length", "!=", "0", "&&", "r", ".", "Seq", ".", "Length", "!=", "cigarLen", ")", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L83-L103
15,042
biogo/hts
sam/record.go
Tag
func (r *Record) Tag(tag []byte) (v Aux, ok bool) { if len(tag) < 2 { panic("sam: tag too short") } for _, aux := range r.AuxFields { if aux.matches(tag) { return aux, true } } return nil, false }
go
func (r *Record) Tag(tag []byte) (v Aux, ok bool) { if len(tag) < 2 { panic("sam: tag too short") } for _, aux := range r.AuxFields { if aux.matches(tag) { return aux, true } } return nil, false }
[ "func", "(", "r", "*", "Record", ")", "Tag", "(", "tag", "[", "]", "byte", ")", "(", "v", "Aux", ",", "ok", "bool", ")", "{", "if", "len", "(", "tag", ")", "<", "2", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "aux", ":=", "range", "r", ".", "AuxFields", "{", "if", "aux", ".", "matches", "(", "tag", ")", "{", "return", "aux", ",", "true", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L107-L117
15,043
biogo/hts
sam/record.go
Bin
func (r *Record) Bin() int { if r.Flags&(Unmapped|MateUnmapped) == Unmapped|MateUnmapped { return 4680 // reg2bin(-1, 0) } return int(internal.BinFor(r.Pos, r.End())) }
go
func (r *Record) Bin() int { if r.Flags&(Unmapped|MateUnmapped) == Unmapped|MateUnmapped { return 4680 // reg2bin(-1, 0) } return int(internal.BinFor(r.Pos, r.End())) }
[ "func", "(", "r", "*", "Record", ")", "Bin", "(", ")", "int", "{", "if", "r", ".", "Flags", "&", "(", "Unmapped", "|", "MateUnmapped", ")", "==", "Unmapped", "|", "MateUnmapped", "{", "return", "4680", "// reg2bin(-1, 0)", "\n", "}", "\n", "return", "int", "(", "internal", ".", "BinFor", "(", "r", ".", "Pos", ",", "r", ".", "End", "(", ")", ")", ")", "\n", "}" ]
// Bin returns the BAM index bin of the record.
[ "Bin", "returns", "the", "BAM", "index", "bin", "of", "the", "record", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L130-L135
15,044
biogo/hts
sam/record.go
LessByName
func (r *Record) LessByName(other *Record) bool { return r.Name < other.Name }
go
func (r *Record) LessByName(other *Record) bool { return r.Name < other.Name }
[ "func", "(", "r", "*", "Record", ")", "LessByName", "(", "other", "*", "Record", ")", "bool", "{", "return", "r", ".", "Name", "<", "other", ".", "Name", "\n", "}" ]
// LessByName returns true if the receiver sorts by record name before other.
[ "LessByName", "returns", "true", "if", "the", "receiver", "sorts", "by", "record", "name", "before", "other", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L176-L178
15,045
biogo/hts
sam/record.go
LessByCoordinate
func (r *Record) LessByCoordinate(other *Record) bool { rRefName := r.Ref.Name() oRefName := other.Ref.Name() switch { case oRefName == "*": return true case rRefName == "*": return false } return (rRefName < oRefName) || (rRefName == oRefName && r.Pos < other.Pos) }
go
func (r *Record) LessByCoordinate(other *Record) bool { rRefName := r.Ref.Name() oRefName := other.Ref.Name() switch { case oRefName == "*": return true case rRefName == "*": return false } return (rRefName < oRefName) || (rRefName == oRefName && r.Pos < other.Pos) }
[ "func", "(", "r", "*", "Record", ")", "LessByCoordinate", "(", "other", "*", "Record", ")", "bool", "{", "rRefName", ":=", "r", ".", "Ref", ".", "Name", "(", ")", "\n", "oRefName", ":=", "other", ".", "Ref", ".", "Name", "(", ")", "\n", "switch", "{", "case", "oRefName", "==", "\"", "\"", ":", "return", "true", "\n", "case", "rRefName", "==", "\"", "\"", ":", "return", "false", "\n", "}", "\n", "return", "(", "rRefName", "<", "oRefName", ")", "||", "(", "rRefName", "==", "oRefName", "&&", "r", ".", "Pos", "<", "other", ".", "Pos", ")", "\n", "}" ]
// LessByCoordinate returns true if the receiver sorts by coordinate before other // according to the SAM specification.
[ "LessByCoordinate", "returns", "true", "if", "the", "receiver", "sorts", "by", "coordinate", "before", "other", "according", "to", "the", "SAM", "specification", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L182-L192
15,046
biogo/hts
sam/record.go
String
func (r *Record) String() string { end := r.End() return fmt.Sprintf("%s %v %v %d %s:%d..%d (%d) %d %s:%d %d %s %v %v", r.Name, r.Flags, r.Cigar, r.MapQ, r.Ref.Name(), r.Pos, end, r.Bin(), end-r.Pos, r.MateRef.Name(), r.MatePos, r.TempLen, r.Seq.Expand(), r.Qual, r.AuxFields, ) }
go
func (r *Record) String() string { end := r.End() return fmt.Sprintf("%s %v %v %d %s:%d..%d (%d) %d %s:%d %d %s %v %v", r.Name, r.Flags, r.Cigar, r.MapQ, r.Ref.Name(), r.Pos, end, r.Bin(), end-r.Pos, r.MateRef.Name(), r.MatePos, r.TempLen, r.Seq.Expand(), r.Qual, r.AuxFields, ) }
[ "func", "(", "r", "*", "Record", ")", "String", "(", ")", "string", "{", "end", ":=", "r", ".", "End", "(", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Name", ",", "r", ".", "Flags", ",", "r", ".", "Cigar", ",", "r", ".", "MapQ", ",", "r", ".", "Ref", ".", "Name", "(", ")", ",", "r", ".", "Pos", ",", "end", ",", "r", ".", "Bin", "(", ")", ",", "end", "-", "r", ".", "Pos", ",", "r", ".", "MateRef", ".", "Name", "(", ")", ",", "r", ".", "MatePos", ",", "r", ".", "TempLen", ",", "r", ".", "Seq", ".", "Expand", "(", ")", ",", "r", ".", "Qual", ",", "r", ".", "AuxFields", ",", ")", "\n", "}" ]
// String returns a string representation of the Record.
[ "String", "returns", "a", "string", "representation", "of", "the", "Record", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L195-L214
15,047
biogo/hts
sam/record.go
UnmarshalText
func (r *Record) UnmarshalText(b []byte) error { return r.UnmarshalSAM(nil, b) }
go
func (r *Record) UnmarshalText(b []byte) error { return r.UnmarshalSAM(nil, b) }
[ "func", "(", "r", "*", "Record", ")", "UnmarshalText", "(", "b", "[", "]", "byte", ")", "error", "{", "return", "r", ".", "UnmarshalSAM", "(", "nil", ",", "b", ")", "\n", "}" ]
// UnmarshalText implements the encoding.TextUnmarshaler. It calls UnmarshalSAM with // a nil Header.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnmarshaler", ".", "It", "calls", "UnmarshalSAM", "with", "a", "nil", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L218-L220
15,048
biogo/hts
sam/record.go
MarshalSAM
func (r *Record) MarshalSAM(flags int) ([]byte, error) { if flags < FlagDecimal || flags > FlagString { return nil, errors.New("sam: flag format option out of range") } if r.Qual != nil && len(r.Qual) != r.Seq.Length { return nil, errors.New("sam: sequence/quality length mismatch") } var buf bytes.Buffer fmt.Fprintf(&buf, "%s\t%v\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", r.Name, formatFlags(r.Flags, flags), r.Ref.Name(), r.Pos+1, r.MapQ, r.Cigar, formatMate(r.Ref, r.MateRef), r.MatePos+1, r.TempLen, formatSeq(r.Seq), formatQual(r.Qual), ) for _, t := range r.AuxFields { fmt.Fprintf(&buf, "\t%v", samAux(t)) } return buf.Bytes(), nil }
go
func (r *Record) MarshalSAM(flags int) ([]byte, error) { if flags < FlagDecimal || flags > FlagString { return nil, errors.New("sam: flag format option out of range") } if r.Qual != nil && len(r.Qual) != r.Seq.Length { return nil, errors.New("sam: sequence/quality length mismatch") } var buf bytes.Buffer fmt.Fprintf(&buf, "%s\t%v\t%s\t%d\t%d\t%s\t%s\t%d\t%d\t%s\t%s", r.Name, formatFlags(r.Flags, flags), r.Ref.Name(), r.Pos+1, r.MapQ, r.Cigar, formatMate(r.Ref, r.MateRef), r.MatePos+1, r.TempLen, formatSeq(r.Seq), formatQual(r.Qual), ) for _, t := range r.AuxFields { fmt.Fprintf(&buf, "\t%v", samAux(t)) } return buf.Bytes(), nil }
[ "func", "(", "r", "*", "Record", ")", "MarshalSAM", "(", "flags", "int", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "flags", "<", "FlagDecimal", "||", "flags", ">", "FlagString", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "r", ".", "Qual", "!=", "nil", "&&", "len", "(", "r", ".", "Qual", ")", "!=", "r", ".", "Seq", ".", "Length", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\\t", "\\t", "\\t", "\\t", "\\t", "\\t", "\\t", "\\t", "\\t", "\"", ",", "r", ".", "Name", ",", "formatFlags", "(", "r", ".", "Flags", ",", "flags", ")", ",", "r", ".", "Ref", ".", "Name", "(", ")", ",", "r", ".", "Pos", "+", "1", ",", "r", ".", "MapQ", ",", "r", ".", "Cigar", ",", "formatMate", "(", "r", ".", "Ref", ",", "r", ".", "MateRef", ")", ",", "r", ".", "MatePos", "+", "1", ",", "r", ".", "TempLen", ",", "formatSeq", "(", "r", ".", "Seq", ")", ",", "formatQual", "(", "r", ".", "Qual", ")", ",", ")", "\n", "for", "_", ",", "t", ":=", "range", "r", ".", "AuxFields", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "samAux", "(", "t", ")", ")", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// MarshalSAM formats a Record as SAM using the specified flag format. Acceptable // formats are FlagDecimal, FlagHex and FlagString.
[ "MarshalSAM", "formats", "a", "Record", "as", "SAM", "using", "the", "specified", "flag", "format", ".", "Acceptable", "formats", "are", "FlagDecimal", "FlagHex", "and", "FlagString", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L334-L359
15,049
biogo/hts
sam/record.go
NewSeq
func NewSeq(s []byte) Seq { return Seq{ Length: len(s), Seq: contract(s), } }
go
func NewSeq(s []byte) Seq { return Seq{ Length: len(s), Seq: contract(s), } }
[ "func", "NewSeq", "(", "s", "[", "]", "byte", ")", "Seq", "{", "return", "Seq", "{", "Length", ":", "len", "(", "s", ")", ",", "Seq", ":", "contract", "(", "s", ")", ",", "}", "\n", "}" ]
// NewSeq returns a new Seq based on the given byte slice.
[ "NewSeq", "returns", "a", "new", "Seq", "based", "on", "the", "given", "byte", "slice", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L455-L460
15,050
biogo/hts
sam/record.go
Expand
func (ns Seq) Expand() []byte { s := make([]byte, ns.Length) for i := range s { if i&1 == 0 { s[i] = n16TableRev[ns.Seq[i>>1]>>4] } else { s[i] = n16TableRev[ns.Seq[i>>1]&0xf] } } return s }
go
func (ns Seq) Expand() []byte { s := make([]byte, ns.Length) for i := range s { if i&1 == 0 { s[i] = n16TableRev[ns.Seq[i>>1]>>4] } else { s[i] = n16TableRev[ns.Seq[i>>1]&0xf] } } return s }
[ "func", "(", "ns", "Seq", ")", "Expand", "(", ")", "[", "]", "byte", "{", "s", ":=", "make", "(", "[", "]", "byte", ",", "ns", ".", "Length", ")", "\n", "for", "i", ":=", "range", "s", "{", "if", "i", "&", "1", "==", "0", "{", "s", "[", "i", "]", "=", "n16TableRev", "[", "ns", ".", "Seq", "[", "i", ">>", "1", "]", ">>", "4", "]", "\n", "}", "else", "{", "s", "[", "i", "]", "=", "n16TableRev", "[", "ns", ".", "Seq", "[", "i", ">>", "1", "]", "&", "0xf", "]", "\n", "}", "\n", "}", "\n\n", "return", "s", "\n", "}" ]
// Expand returns the byte encoded form of the receiver.
[ "Expand", "returns", "the", "byte", "encoded", "form", "of", "the", "receiver", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/record.go#L481-L492
15,051
biogo/hts
bgzf/index/index.go
NewChunkReader
func NewChunkReader(r *bgzf.Reader, chunks []bgzf.Chunk) (*ChunkReader, error) { b := r.Blocked r.Blocked = true if len(chunks) != 0 { err := r.Seek(chunks[0].Begin) if err != nil { return nil, err } } return &ChunkReader{r: r, wasBlocked: b, chunks: chunks}, nil }
go
func NewChunkReader(r *bgzf.Reader, chunks []bgzf.Chunk) (*ChunkReader, error) { b := r.Blocked r.Blocked = true if len(chunks) != 0 { err := r.Seek(chunks[0].Begin) if err != nil { return nil, err } } return &ChunkReader{r: r, wasBlocked: b, chunks: chunks}, nil }
[ "func", "NewChunkReader", "(", "r", "*", "bgzf", ".", "Reader", ",", "chunks", "[", "]", "bgzf", ".", "Chunk", ")", "(", "*", "ChunkReader", ",", "error", ")", "{", "b", ":=", "r", ".", "Blocked", "\n", "r", ".", "Blocked", "=", "true", "\n", "if", "len", "(", "chunks", ")", "!=", "0", "{", "err", ":=", "r", ".", "Seek", "(", "chunks", "[", "0", "]", ".", "Begin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "ChunkReader", "{", "r", ":", "r", ",", "wasBlocked", ":", "b", ",", "chunks", ":", "chunks", "}", ",", "nil", "\n", "}" ]
// NewChunkReader returns a ChunkReader to read from r, limiting the reads to // the provided chunks. The provided bgzf.Reader will be put into Blocked mode.
[ "NewChunkReader", "returns", "a", "ChunkReader", "to", "read", "from", "r", "limiting", "the", "reads", "to", "the", "provided", "chunks", ".", "The", "provided", "bgzf", ".", "Reader", "will", "be", "put", "into", "Blocked", "mode", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/index/index.go#L45-L55
15,052
biogo/hts
bgzf/index/index.go
Close
func (r *ChunkReader) Close() error { r.r.Blocked = r.wasBlocked r.r = nil return nil }
go
func (r *ChunkReader) Close() error { r.r.Blocked = r.wasBlocked r.r = nil return nil }
[ "func", "(", "r", "*", "ChunkReader", ")", "Close", "(", ")", "error", "{", "r", ".", "r", ".", "Blocked", "=", "r", ".", "wasBlocked", "\n", "r", ".", "r", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// Close returns the bgzf.Reader to its original blocking mode and releases it. // The bgzf.Reader is not closed.
[ "Close", "returns", "the", "bgzf", ".", "Reader", "to", "its", "original", "blocking", "mode", "and", "releases", "it", ".", "The", "bgzf", ".", "Reader", "is", "not", "closed", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/index/index.go#L120-L124
15,053
biogo/hts
sam/header.go
String
func (so SortOrder) String() string { if so < Unsorted || so > Coordinate { return sortOrder[UnknownOrder] } return sortOrder[so] }
go
func (so SortOrder) String() string { if so < Unsorted || so > Coordinate { return sortOrder[UnknownOrder] } return sortOrder[so] }
[ "func", "(", "so", "SortOrder", ")", "String", "(", ")", "string", "{", "if", "so", "<", "Unsorted", "||", "so", ">", "Coordinate", "{", "return", "sortOrder", "[", "UnknownOrder", "]", "\n", "}", "\n", "return", "sortOrder", "[", "so", "]", "\n", "}" ]
// String returns the string representation of a SortOrder.
[ "String", "returns", "the", "string", "representation", "of", "a", "SortOrder", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L54-L59
15,054
biogo/hts
sam/header.go
String
func (g GroupOrder) String() string { if g < GroupNone || g > GroupReference { return groupOrder[GroupUnspecified] } return groupOrder[g] }
go
func (g GroupOrder) String() string { if g < GroupNone || g > GroupReference { return groupOrder[GroupUnspecified] } return groupOrder[g] }
[ "func", "(", "g", "GroupOrder", ")", "String", "(", ")", "string", "{", "if", "g", "<", "GroupNone", "||", "g", ">", "GroupReference", "{", "return", "groupOrder", "[", "GroupUnspecified", "]", "\n", "}", "\n", "return", "groupOrder", "[", "g", "]", "\n", "}" ]
// String returns the string representation of a GroupOrder.
[ "String", "returns", "the", "string", "representation", "of", "a", "GroupOrder", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L86-L91
15,055
biogo/hts
sam/header.go
NewHeader
func NewHeader(text []byte, r []*Reference) (*Header, error) { var err error bh := &Header{ refs: r, seenRefs: set{}, seenGroups: set{}, seenProgs: set{}, } for i, r := range bh.refs { if r.owner != nil || r.id >= 0 { return nil, errUsedReference } r.owner = bh r.id = int32(i) } if text != nil { err = bh.UnmarshalText(text) if err != nil { return nil, err } } return bh, nil }
go
func NewHeader(text []byte, r []*Reference) (*Header, error) { var err error bh := &Header{ refs: r, seenRefs: set{}, seenGroups: set{}, seenProgs: set{}, } for i, r := range bh.refs { if r.owner != nil || r.id >= 0 { return nil, errUsedReference } r.owner = bh r.id = int32(i) } if text != nil { err = bh.UnmarshalText(text) if err != nil { return nil, err } } return bh, nil }
[ "func", "NewHeader", "(", "text", "[", "]", "byte", ",", "r", "[", "]", "*", "Reference", ")", "(", "*", "Header", ",", "error", ")", "{", "var", "err", "error", "\n", "bh", ":=", "&", "Header", "{", "refs", ":", "r", ",", "seenRefs", ":", "set", "{", "}", ",", "seenGroups", ":", "set", "{", "}", ",", "seenProgs", ":", "set", "{", "}", ",", "}", "\n", "for", "i", ",", "r", ":=", "range", "bh", ".", "refs", "{", "if", "r", ".", "owner", "!=", "nil", "||", "r", ".", "id", ">=", "0", "{", "return", "nil", ",", "errUsedReference", "\n", "}", "\n", "r", ".", "owner", "=", "bh", "\n", "r", ".", "id", "=", "int32", "(", "i", ")", "\n", "}", "\n", "if", "text", "!=", "nil", "{", "err", "=", "bh", ".", "UnmarshalText", "(", "text", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "bh", ",", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L120-L142
15,056
biogo/hts
sam/header.go
Tags
func (bh *Header) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(versionTag, bh.Version) if bh.SortOrder != UnknownOrder { fn(sortOrderTag, bh.SortOrder.String()) } if bh.GroupOrder != GroupNone { fn(groupOrderTag, bh.GroupOrder.String()) } for _, tp := range bh.otherTags { fn(tp.tag, tp.value) } }
go
func (bh *Header) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(versionTag, bh.Version) if bh.SortOrder != UnknownOrder { fn(sortOrderTag, bh.SortOrder.String()) } if bh.GroupOrder != GroupNone { fn(groupOrderTag, bh.GroupOrder.String()) } for _, tp := range bh.otherTags { fn(tp.tag, tp.value) } }
[ "func", "(", "bh", "*", "Header", ")", "Tags", "(", "fn", "func", "(", "t", "Tag", ",", "value", "string", ")", ")", "{", "if", "fn", "==", "nil", "{", "return", "\n", "}", "\n", "fn", "(", "versionTag", ",", "bh", ".", "Version", ")", "\n", "if", "bh", ".", "SortOrder", "!=", "UnknownOrder", "{", "fn", "(", "sortOrderTag", ",", "bh", ".", "SortOrder", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "bh", ".", "GroupOrder", "!=", "GroupNone", "{", "fn", "(", "groupOrderTag", ",", "bh", ".", "GroupOrder", ".", "String", "(", ")", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "bh", ".", "otherTags", "{", "fn", "(", "tp", ".", "tag", ",", "tp", ".", "value", ")", "\n", "}", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L148-L162
15,057
biogo/hts
sam/header.go
Get
func (bh *Header) Get(t Tag) string { switch t { case versionTag: return bh.Version case sortOrderTag: return bh.SortOrder.String() case groupOrderTag: return bh.GroupOrder.String() } for _, tp := range bh.otherTags { if t == tp.tag { return tp.value } } return "" }
go
func (bh *Header) Get(t Tag) string { switch t { case versionTag: return bh.Version case sortOrderTag: return bh.SortOrder.String() case groupOrderTag: return bh.GroupOrder.String() } for _, tp := range bh.otherTags { if t == tp.tag { return tp.value } } return "" }
[ "func", "(", "bh", "*", "Header", ")", "Get", "(", "t", "Tag", ")", "string", "{", "switch", "t", "{", "case", "versionTag", ":", "return", "bh", ".", "Version", "\n", "case", "sortOrderTag", ":", "return", "bh", ".", "SortOrder", ".", "String", "(", ")", "\n", "case", "groupOrderTag", ":", "return", "bh", ".", "GroupOrder", ".", "String", "(", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "bh", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "return", "tp", ".", "value", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L166-L181
15,058
biogo/hts
sam/header.go
Clone
func (bh *Header) Clone() *Header { c := &Header{ Version: bh.Version, SortOrder: bh.SortOrder, GroupOrder: bh.GroupOrder, otherTags: append([]tagPair(nil), bh.otherTags...), Comments: append([]string(nil), bh.Comments...), seenRefs: make(set, len(bh.seenRefs)), seenGroups: make(set, len(bh.seenGroups)), seenProgs: make(set, len(bh.seenProgs)), } if len(bh.refs) != 0 { c.refs = make([]*Reference, len(bh.refs)) } if len(bh.rgs) != 0 { c.rgs = make([]*ReadGroup, len(bh.rgs)) } if len(bh.progs) != 0 { c.progs = make([]*Program, len(bh.progs)) } for i, r := range bh.refs { if r == nil { continue } c.refs[i] = new(Reference) *c.refs[i] = *r c.refs[i].owner = c } for i, r := range bh.rgs { c.rgs[i] = new(ReadGroup) *c.rgs[i] = *r c.rgs[i].owner = c } for i, p := range bh.progs { c.progs[i] = new(Program) *c.progs[i] = *p c.progs[i].owner = c } for k, v := range bh.seenRefs { c.seenRefs[k] = v } for k, v := range bh.seenGroups { c.seenGroups[k] = v } for k, v := range bh.seenProgs { c.seenProgs[k] = v } return c }
go
func (bh *Header) Clone() *Header { c := &Header{ Version: bh.Version, SortOrder: bh.SortOrder, GroupOrder: bh.GroupOrder, otherTags: append([]tagPair(nil), bh.otherTags...), Comments: append([]string(nil), bh.Comments...), seenRefs: make(set, len(bh.seenRefs)), seenGroups: make(set, len(bh.seenGroups)), seenProgs: make(set, len(bh.seenProgs)), } if len(bh.refs) != 0 { c.refs = make([]*Reference, len(bh.refs)) } if len(bh.rgs) != 0 { c.rgs = make([]*ReadGroup, len(bh.rgs)) } if len(bh.progs) != 0 { c.progs = make([]*Program, len(bh.progs)) } for i, r := range bh.refs { if r == nil { continue } c.refs[i] = new(Reference) *c.refs[i] = *r c.refs[i].owner = c } for i, r := range bh.rgs { c.rgs[i] = new(ReadGroup) *c.rgs[i] = *r c.rgs[i].owner = c } for i, p := range bh.progs { c.progs[i] = new(Program) *c.progs[i] = *p c.progs[i].owner = c } for k, v := range bh.seenRefs { c.seenRefs[k] = v } for k, v := range bh.seenGroups { c.seenGroups[k] = v } for k, v := range bh.seenProgs { c.seenProgs[k] = v } return c }
[ "func", "(", "bh", "*", "Header", ")", "Clone", "(", ")", "*", "Header", "{", "c", ":=", "&", "Header", "{", "Version", ":", "bh", ".", "Version", ",", "SortOrder", ":", "bh", ".", "SortOrder", ",", "GroupOrder", ":", "bh", ".", "GroupOrder", ",", "otherTags", ":", "append", "(", "[", "]", "tagPair", "(", "nil", ")", ",", "bh", ".", "otherTags", "...", ")", ",", "Comments", ":", "append", "(", "[", "]", "string", "(", "nil", ")", ",", "bh", ".", "Comments", "...", ")", ",", "seenRefs", ":", "make", "(", "set", ",", "len", "(", "bh", ".", "seenRefs", ")", ")", ",", "seenGroups", ":", "make", "(", "set", ",", "len", "(", "bh", ".", "seenGroups", ")", ")", ",", "seenProgs", ":", "make", "(", "set", ",", "len", "(", "bh", ".", "seenProgs", ")", ")", ",", "}", "\n", "if", "len", "(", "bh", ".", "refs", ")", "!=", "0", "{", "c", ".", "refs", "=", "make", "(", "[", "]", "*", "Reference", ",", "len", "(", "bh", ".", "refs", ")", ")", "\n", "}", "\n", "if", "len", "(", "bh", ".", "rgs", ")", "!=", "0", "{", "c", ".", "rgs", "=", "make", "(", "[", "]", "*", "ReadGroup", ",", "len", "(", "bh", ".", "rgs", ")", ")", "\n", "}", "\n", "if", "len", "(", "bh", ".", "progs", ")", "!=", "0", "{", "c", ".", "progs", "=", "make", "(", "[", "]", "*", "Program", ",", "len", "(", "bh", ".", "progs", ")", ")", "\n", "}", "\n\n", "for", "i", ",", "r", ":=", "range", "bh", ".", "refs", "{", "if", "r", "==", "nil", "{", "continue", "\n", "}", "\n", "c", ".", "refs", "[", "i", "]", "=", "new", "(", "Reference", ")", "\n", "*", "c", ".", "refs", "[", "i", "]", "=", "*", "r", "\n", "c", ".", "refs", "[", "i", "]", ".", "owner", "=", "c", "\n", "}", "\n", "for", "i", ",", "r", ":=", "range", "bh", ".", "rgs", "{", "c", ".", "rgs", "[", "i", "]", "=", "new", "(", "ReadGroup", ")", "\n", "*", "c", ".", "rgs", "[", "i", "]", "=", "*", "r", "\n", "c", ".", "rgs", "[", "i", "]", ".", "owner", "=", "c", "\n", "}", "\n", "for", "i", ",", "p", ":=", "range", "bh", ".", "progs", "{", "c", ".", "progs", "[", "i", "]", "=", "new", "(", "Program", ")", "\n", "*", "c", ".", "progs", "[", "i", "]", "=", "*", "p", "\n", "c", ".", "progs", "[", "i", "]", ".", "owner", "=", "c", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "bh", ".", "seenRefs", "{", "c", ".", "seenRefs", "[", "k", "]", "=", "v", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "bh", ".", "seenGroups", "{", "c", ".", "seenGroups", "[", "k", "]", "=", "v", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "bh", ".", "seenProgs", "{", "c", ".", "seenProgs", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "return", "c", "\n", "}" ]
// Clone returns a deep copy of the receiver.
[ "Clone", "returns", "a", "deep", "copy", "of", "the", "receiver", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L237-L287
15,059
biogo/hts
sam/header.go
MergeHeaders
func MergeHeaders(src []*Header) (h *Header, reflinks [][]*Reference, err error) { switch len(src) { case 0: return nil, nil, nil case 1: return src[0], nil, nil } reflinks = make([][]*Reference, len(src)) h = src[0].Clone() h.SortOrder = UnknownOrder h.GroupOrder = GroupUnspecified for i, add := range src { if i == 0 { reflinks[i] = h.refs continue } links := make([]*Reference, len(add.refs)) for id, r := range add.refs { r = r.Clone() err := h.AddReference(r) if err != nil { return nil, nil, err } if r.owner != h { // r was not actually added, so use the ref // that h owns. for _, hr := range h.refs { if equalRefs(r, hr) { r = hr break } } } links[id] = r } reflinks[i] = links } return h, reflinks, nil }
go
func MergeHeaders(src []*Header) (h *Header, reflinks [][]*Reference, err error) { switch len(src) { case 0: return nil, nil, nil case 1: return src[0], nil, nil } reflinks = make([][]*Reference, len(src)) h = src[0].Clone() h.SortOrder = UnknownOrder h.GroupOrder = GroupUnspecified for i, add := range src { if i == 0 { reflinks[i] = h.refs continue } links := make([]*Reference, len(add.refs)) for id, r := range add.refs { r = r.Clone() err := h.AddReference(r) if err != nil { return nil, nil, err } if r.owner != h { // r was not actually added, so use the ref // that h owns. for _, hr := range h.refs { if equalRefs(r, hr) { r = hr break } } } links[id] = r } reflinks[i] = links } return h, reflinks, nil }
[ "func", "MergeHeaders", "(", "src", "[", "]", "*", "Header", ")", "(", "h", "*", "Header", ",", "reflinks", "[", "]", "[", "]", "*", "Reference", ",", "err", "error", ")", "{", "switch", "len", "(", "src", ")", "{", "case", "0", ":", "return", "nil", ",", "nil", ",", "nil", "\n", "case", "1", ":", "return", "src", "[", "0", "]", ",", "nil", ",", "nil", "\n", "}", "\n", "reflinks", "=", "make", "(", "[", "]", "[", "]", "*", "Reference", ",", "len", "(", "src", ")", ")", "\n", "h", "=", "src", "[", "0", "]", ".", "Clone", "(", ")", "\n", "h", ".", "SortOrder", "=", "UnknownOrder", "\n", "h", ".", "GroupOrder", "=", "GroupUnspecified", "\n", "for", "i", ",", "add", ":=", "range", "src", "{", "if", "i", "==", "0", "{", "reflinks", "[", "i", "]", "=", "h", ".", "refs", "\n", "continue", "\n", "}", "\n", "links", ":=", "make", "(", "[", "]", "*", "Reference", ",", "len", "(", "add", ".", "refs", ")", ")", "\n", "for", "id", ",", "r", ":=", "range", "add", ".", "refs", "{", "r", "=", "r", ".", "Clone", "(", ")", "\n", "err", ":=", "h", ".", "AddReference", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "if", "r", ".", "owner", "!=", "h", "{", "// r was not actually added, so use the ref", "// that h owns.", "for", "_", ",", "hr", ":=", "range", "h", ".", "refs", "{", "if", "equalRefs", "(", "r", ",", "hr", ")", "{", "r", "=", "hr", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "links", "[", "id", "]", "=", "r", "\n", "}", "\n", "reflinks", "[", "i", "]", "=", "links", "\n", "}", "\n\n", "return", "h", ",", "reflinks", ",", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L297-L336
15,060
biogo/hts
sam/header.go
MarshalBinary
func (bh *Header) MarshalBinary() ([]byte, error) { b := &bytes.Buffer{} err := bh.EncodeBinary(b) if err != nil { return nil, err } return b.Bytes(), nil }
go
func (bh *Header) MarshalBinary() ([]byte, error) { b := &bytes.Buffer{} err := bh.EncodeBinary(b) if err != nil { return nil, err } return b.Bytes(), nil }
[ "func", "(", "bh", "*", "Header", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "b", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "err", ":=", "bh", ".", "EncodeBinary", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "b", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// MarshalBinary implements the encoding.BinaryMarshaler.
[ "MarshalBinary", "implements", "the", "encoding", ".", "BinaryMarshaler", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L368-L375
15,061
biogo/hts
sam/header.go
EncodeBinary
func (bh *Header) EncodeBinary(w io.Writer) error { wb := &errWriter{w: w} binary.Write(wb, binary.LittleEndian, bamMagic) text, _ := bh.MarshalText() binary.Write(wb, binary.LittleEndian, int32(len(text))) wb.Write(text) binary.Write(wb, binary.LittleEndian, int32(len(bh.refs))) if !validInt32(len(bh.refs)) { return errors.New("sam: value out of range") } var name []byte for _, r := range bh.refs { name = append(name, []byte(r.name)...) name = append(name, 0) binary.Write(wb, binary.LittleEndian, int32(len(name))) wb.Write(name) name = name[:0] binary.Write(wb, binary.LittleEndian, r.lRef) } if wb.err != nil { return wb.err } return nil }
go
func (bh *Header) EncodeBinary(w io.Writer) error { wb := &errWriter{w: w} binary.Write(wb, binary.LittleEndian, bamMagic) text, _ := bh.MarshalText() binary.Write(wb, binary.LittleEndian, int32(len(text))) wb.Write(text) binary.Write(wb, binary.LittleEndian, int32(len(bh.refs))) if !validInt32(len(bh.refs)) { return errors.New("sam: value out of range") } var name []byte for _, r := range bh.refs { name = append(name, []byte(r.name)...) name = append(name, 0) binary.Write(wb, binary.LittleEndian, int32(len(name))) wb.Write(name) name = name[:0] binary.Write(wb, binary.LittleEndian, r.lRef) } if wb.err != nil { return wb.err } return nil }
[ "func", "(", "bh", "*", "Header", ")", "EncodeBinary", "(", "w", "io", ".", "Writer", ")", "error", "{", "wb", ":=", "&", "errWriter", "{", "w", ":", "w", "}", "\n\n", "binary", ".", "Write", "(", "wb", ",", "binary", ".", "LittleEndian", ",", "bamMagic", ")", "\n", "text", ",", "_", ":=", "bh", ".", "MarshalText", "(", ")", "\n", "binary", ".", "Write", "(", "wb", ",", "binary", ".", "LittleEndian", ",", "int32", "(", "len", "(", "text", ")", ")", ")", "\n", "wb", ".", "Write", "(", "text", ")", "\n", "binary", ".", "Write", "(", "wb", ",", "binary", ".", "LittleEndian", ",", "int32", "(", "len", "(", "bh", ".", "refs", ")", ")", ")", "\n\n", "if", "!", "validInt32", "(", "len", "(", "bh", ".", "refs", ")", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "name", "[", "]", "byte", "\n", "for", "_", ",", "r", ":=", "range", "bh", ".", "refs", "{", "name", "=", "append", "(", "name", ",", "[", "]", "byte", "(", "r", ".", "name", ")", "...", ")", "\n", "name", "=", "append", "(", "name", ",", "0", ")", "\n", "binary", ".", "Write", "(", "wb", ",", "binary", ".", "LittleEndian", ",", "int32", "(", "len", "(", "name", ")", ")", ")", "\n", "wb", ".", "Write", "(", "name", ")", "\n", "name", "=", "name", "[", ":", "0", "]", "\n", "binary", ".", "Write", "(", "wb", ",", "binary", ".", "LittleEndian", ",", "r", ".", "lRef", ")", "\n", "}", "\n", "if", "wb", ".", "err", "!=", "nil", "{", "return", "wb", ".", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L379-L405
15,062
biogo/hts
sam/header.go
AddReference
func (bh *Header) AddReference(r *Reference) error { if dupID, dup := bh.seenRefs[r.name]; dup { er := bh.refs[dupID] if equalRefs(er, r) { return nil } else if !equalRefs(r, &Reference{id: -1, name: er.name, lRef: er.lRef}) { return errDupReference } if r.md5 == "" { r.md5 = er.md5 } if r.assemID == "" { r.assemID = er.assemID } if r.species == "" { r.species = er.species } if r.uri == nil { r.uri = er.uri } bh.refs[dupID] = r return nil } if r.owner != nil || r.id >= 0 { return errUsedReference } r.owner = bh r.id = int32(len(bh.refs)) bh.seenRefs[r.name] = r.id bh.refs = append(bh.refs, r) return nil }
go
func (bh *Header) AddReference(r *Reference) error { if dupID, dup := bh.seenRefs[r.name]; dup { er := bh.refs[dupID] if equalRefs(er, r) { return nil } else if !equalRefs(r, &Reference{id: -1, name: er.name, lRef: er.lRef}) { return errDupReference } if r.md5 == "" { r.md5 = er.md5 } if r.assemID == "" { r.assemID = er.assemID } if r.species == "" { r.species = er.species } if r.uri == nil { r.uri = er.uri } bh.refs[dupID] = r return nil } if r.owner != nil || r.id >= 0 { return errUsedReference } r.owner = bh r.id = int32(len(bh.refs)) bh.seenRefs[r.name] = r.id bh.refs = append(bh.refs, r) return nil }
[ "func", "(", "bh", "*", "Header", ")", "AddReference", "(", "r", "*", "Reference", ")", "error", "{", "if", "dupID", ",", "dup", ":=", "bh", ".", "seenRefs", "[", "r", ".", "name", "]", ";", "dup", "{", "er", ":=", "bh", ".", "refs", "[", "dupID", "]", "\n", "if", "equalRefs", "(", "er", ",", "r", ")", "{", "return", "nil", "\n", "}", "else", "if", "!", "equalRefs", "(", "r", ",", "&", "Reference", "{", "id", ":", "-", "1", ",", "name", ":", "er", ".", "name", ",", "lRef", ":", "er", ".", "lRef", "}", ")", "{", "return", "errDupReference", "\n", "}", "\n", "if", "r", ".", "md5", "==", "\"", "\"", "{", "r", ".", "md5", "=", "er", ".", "md5", "\n", "}", "\n", "if", "r", ".", "assemID", "==", "\"", "\"", "{", "r", ".", "assemID", "=", "er", ".", "assemID", "\n", "}", "\n", "if", "r", ".", "species", "==", "\"", "\"", "{", "r", ".", "species", "=", "er", ".", "species", "\n", "}", "\n", "if", "r", ".", "uri", "==", "nil", "{", "r", ".", "uri", "=", "er", ".", "uri", "\n", "}", "\n", "bh", ".", "refs", "[", "dupID", "]", "=", "r", "\n", "return", "nil", "\n", "}", "\n", "if", "r", ".", "owner", "!=", "nil", "||", "r", ".", "id", ">=", "0", "{", "return", "errUsedReference", "\n", "}", "\n", "r", ".", "owner", "=", "bh", "\n", "r", ".", "id", "=", "int32", "(", "len", "(", "bh", ".", "refs", ")", ")", "\n", "bh", ".", "seenRefs", "[", "r", ".", "name", "]", "=", "r", ".", "id", "\n", "bh", ".", "refs", "=", "append", "(", "bh", ".", "refs", ",", "r", ")", "\n", "return", "nil", "\n", "}" ]
// AddReference adds r to the Header.
[ "AddReference", "adds", "r", "to", "the", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L482-L513
15,063
biogo/hts
sam/header.go
RemoveReference
func (bh *Header) RemoveReference(r *Reference) error { if r.id < 0 || int(r.id) >= len(bh.refs) || bh.refs[r.id] != r { return errInvalidReference } bh.refs = append(bh.refs[:r.id], bh.refs[r.id+1:]...) for i := range bh.refs[r.id:] { bh.refs[i+int(r.id)].id-- } r.id = -1 delete(bh.seenRefs, r.name) return nil }
go
func (bh *Header) RemoveReference(r *Reference) error { if r.id < 0 || int(r.id) >= len(bh.refs) || bh.refs[r.id] != r { return errInvalidReference } bh.refs = append(bh.refs[:r.id], bh.refs[r.id+1:]...) for i := range bh.refs[r.id:] { bh.refs[i+int(r.id)].id-- } r.id = -1 delete(bh.seenRefs, r.name) return nil }
[ "func", "(", "bh", "*", "Header", ")", "RemoveReference", "(", "r", "*", "Reference", ")", "error", "{", "if", "r", ".", "id", "<", "0", "||", "int", "(", "r", ".", "id", ")", ">=", "len", "(", "bh", ".", "refs", ")", "||", "bh", ".", "refs", "[", "r", ".", "id", "]", "!=", "r", "{", "return", "errInvalidReference", "\n", "}", "\n", "bh", ".", "refs", "=", "append", "(", "bh", ".", "refs", "[", ":", "r", ".", "id", "]", ",", "bh", ".", "refs", "[", "r", ".", "id", "+", "1", ":", "]", "...", ")", "\n", "for", "i", ":=", "range", "bh", ".", "refs", "[", "r", ".", "id", ":", "]", "{", "bh", ".", "refs", "[", "i", "+", "int", "(", "r", ".", "id", ")", "]", ".", "id", "--", "\n", "}", "\n", "r", ".", "id", "=", "-", "1", "\n", "delete", "(", "bh", ".", "seenRefs", ",", "r", ".", "name", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveReference removes r from the Header and makes it // available to add to another Header.
[ "RemoveReference", "removes", "r", "from", "the", "Header", "and", "makes", "it", "available", "to", "add", "to", "another", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L517-L528
15,064
biogo/hts
sam/header.go
AddReadGroup
func (bh *Header) AddReadGroup(rg *ReadGroup) error { if _, ok := bh.seenGroups[rg.name]; ok { return errDupReadGroup } if rg.owner != nil || rg.id >= 0 { return errUsedReadGroup } rg.owner = bh rg.id = int32(len(bh.rgs)) bh.seenGroups[rg.name] = rg.id bh.rgs = append(bh.rgs, rg) return nil }
go
func (bh *Header) AddReadGroup(rg *ReadGroup) error { if _, ok := bh.seenGroups[rg.name]; ok { return errDupReadGroup } if rg.owner != nil || rg.id >= 0 { return errUsedReadGroup } rg.owner = bh rg.id = int32(len(bh.rgs)) bh.seenGroups[rg.name] = rg.id bh.rgs = append(bh.rgs, rg) return nil }
[ "func", "(", "bh", "*", "Header", ")", "AddReadGroup", "(", "rg", "*", "ReadGroup", ")", "error", "{", "if", "_", ",", "ok", ":=", "bh", ".", "seenGroups", "[", "rg", ".", "name", "]", ";", "ok", "{", "return", "errDupReadGroup", "\n", "}", "\n", "if", "rg", ".", "owner", "!=", "nil", "||", "rg", ".", "id", ">=", "0", "{", "return", "errUsedReadGroup", "\n", "}", "\n", "rg", ".", "owner", "=", "bh", "\n", "rg", ".", "id", "=", "int32", "(", "len", "(", "bh", ".", "rgs", ")", ")", "\n", "bh", ".", "seenGroups", "[", "rg", ".", "name", "]", "=", "rg", ".", "id", "\n", "bh", ".", "rgs", "=", "append", "(", "bh", ".", "rgs", ",", "rg", ")", "\n", "return", "nil", "\n", "}" ]
// AddReadGroup adds rg to the Header.
[ "AddReadGroup", "adds", "rg", "to", "the", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L531-L543
15,065
biogo/hts
sam/header.go
RemoveReadGroup
func (bh *Header) RemoveReadGroup(rg *ReadGroup) error { if rg.id < 0 || int(rg.id) >= len(bh.refs) || bh.rgs[rg.id] != rg { return errInvalidReadGroup } bh.rgs = append(bh.rgs[:rg.id], bh.rgs[rg.id+1:]...) for i := range bh.rgs[rg.id:] { bh.rgs[i+int(rg.id)].id-- } rg.id = -1 delete(bh.seenGroups, rg.name) return nil }
go
func (bh *Header) RemoveReadGroup(rg *ReadGroup) error { if rg.id < 0 || int(rg.id) >= len(bh.refs) || bh.rgs[rg.id] != rg { return errInvalidReadGroup } bh.rgs = append(bh.rgs[:rg.id], bh.rgs[rg.id+1:]...) for i := range bh.rgs[rg.id:] { bh.rgs[i+int(rg.id)].id-- } rg.id = -1 delete(bh.seenGroups, rg.name) return nil }
[ "func", "(", "bh", "*", "Header", ")", "RemoveReadGroup", "(", "rg", "*", "ReadGroup", ")", "error", "{", "if", "rg", ".", "id", "<", "0", "||", "int", "(", "rg", ".", "id", ")", ">=", "len", "(", "bh", ".", "refs", ")", "||", "bh", ".", "rgs", "[", "rg", ".", "id", "]", "!=", "rg", "{", "return", "errInvalidReadGroup", "\n", "}", "\n", "bh", ".", "rgs", "=", "append", "(", "bh", ".", "rgs", "[", ":", "rg", ".", "id", "]", ",", "bh", ".", "rgs", "[", "rg", ".", "id", "+", "1", ":", "]", "...", ")", "\n", "for", "i", ":=", "range", "bh", ".", "rgs", "[", "rg", ".", "id", ":", "]", "{", "bh", ".", "rgs", "[", "i", "+", "int", "(", "rg", ".", "id", ")", "]", ".", "id", "--", "\n", "}", "\n", "rg", ".", "id", "=", "-", "1", "\n", "delete", "(", "bh", ".", "seenGroups", ",", "rg", ".", "name", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveReadGroup removes rg from the Header and makes it // available to add to another Header.
[ "RemoveReadGroup", "removes", "rg", "from", "the", "Header", "and", "makes", "it", "available", "to", "add", "to", "another", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L547-L558
15,066
biogo/hts
sam/header.go
AddProgram
func (bh *Header) AddProgram(p *Program) error { if _, ok := bh.seenProgs[p.uid]; ok { return errDupProgram } if p.owner != nil || p.id >= 0 { return errUsedProgram } p.owner = bh p.id = int32(len(bh.progs)) bh.seenProgs[p.uid] = p.id bh.progs = append(bh.progs, p) return nil }
go
func (bh *Header) AddProgram(p *Program) error { if _, ok := bh.seenProgs[p.uid]; ok { return errDupProgram } if p.owner != nil || p.id >= 0 { return errUsedProgram } p.owner = bh p.id = int32(len(bh.progs)) bh.seenProgs[p.uid] = p.id bh.progs = append(bh.progs, p) return nil }
[ "func", "(", "bh", "*", "Header", ")", "AddProgram", "(", "p", "*", "Program", ")", "error", "{", "if", "_", ",", "ok", ":=", "bh", ".", "seenProgs", "[", "p", ".", "uid", "]", ";", "ok", "{", "return", "errDupProgram", "\n", "}", "\n", "if", "p", ".", "owner", "!=", "nil", "||", "p", ".", "id", ">=", "0", "{", "return", "errUsedProgram", "\n", "}", "\n", "p", ".", "owner", "=", "bh", "\n", "p", ".", "id", "=", "int32", "(", "len", "(", "bh", ".", "progs", ")", ")", "\n", "bh", ".", "seenProgs", "[", "p", ".", "uid", "]", "=", "p", ".", "id", "\n", "bh", ".", "progs", "=", "append", "(", "bh", ".", "progs", ",", "p", ")", "\n", "return", "nil", "\n", "}" ]
// AddProgram adds p to the Header.
[ "AddProgram", "adds", "p", "to", "the", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L561-L573
15,067
biogo/hts
sam/header.go
RemoveProgram
func (bh *Header) RemoveProgram(p *Program) error { if p.id < 0 || int(p.id) >= len(bh.progs) || bh.progs[p.id] != p { return errInvalidProgram } bh.progs = append(bh.progs[:p.id], bh.progs[p.id+1:]...) for i := range bh.progs[p.id:] { bh.progs[i+int(p.id)].id-- } p.id = -1 delete(bh.seenProgs, p.uid) return nil }
go
func (bh *Header) RemoveProgram(p *Program) error { if p.id < 0 || int(p.id) >= len(bh.progs) || bh.progs[p.id] != p { return errInvalidProgram } bh.progs = append(bh.progs[:p.id], bh.progs[p.id+1:]...) for i := range bh.progs[p.id:] { bh.progs[i+int(p.id)].id-- } p.id = -1 delete(bh.seenProgs, p.uid) return nil }
[ "func", "(", "bh", "*", "Header", ")", "RemoveProgram", "(", "p", "*", "Program", ")", "error", "{", "if", "p", ".", "id", "<", "0", "||", "int", "(", "p", ".", "id", ")", ">=", "len", "(", "bh", ".", "progs", ")", "||", "bh", ".", "progs", "[", "p", ".", "id", "]", "!=", "p", "{", "return", "errInvalidProgram", "\n", "}", "\n", "bh", ".", "progs", "=", "append", "(", "bh", ".", "progs", "[", ":", "p", ".", "id", "]", ",", "bh", ".", "progs", "[", "p", ".", "id", "+", "1", ":", "]", "...", ")", "\n", "for", "i", ":=", "range", "bh", ".", "progs", "[", "p", ".", "id", ":", "]", "{", "bh", ".", "progs", "[", "i", "+", "int", "(", "p", ".", "id", ")", "]", ".", "id", "--", "\n", "}", "\n", "p", ".", "id", "=", "-", "1", "\n", "delete", "(", "bh", ".", "seenProgs", ",", "p", ".", "uid", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveProgram removes p from the Header and makes it // available to add to another Header.
[ "RemoveProgram", "removes", "p", "from", "the", "Header", "and", "makes", "it", "available", "to", "add", "to", "another", "Header", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/header.go#L577-L588
15,068
biogo/hts
sam/reference.go
NewReference
func NewReference(name, assemID, species string, length int, md5 []byte, uri *url.URL) (*Reference, error) { if !validLen(length) { return nil, errors.New("sam: length out of range") } if name == "" { return nil, errors.New("sam: no name provided") } var h string if md5 != nil { if len(md5) != 16 { return nil, errors.New("sam: invalid md5 sum length") } h = string(md5[:]) } return &Reference{ id: -1, // This is altered by a Header when added. name: name, lRef: int32(length), md5: h, assemID: assemID, species: species, uri: uri, }, nil }
go
func NewReference(name, assemID, species string, length int, md5 []byte, uri *url.URL) (*Reference, error) { if !validLen(length) { return nil, errors.New("sam: length out of range") } if name == "" { return nil, errors.New("sam: no name provided") } var h string if md5 != nil { if len(md5) != 16 { return nil, errors.New("sam: invalid md5 sum length") } h = string(md5[:]) } return &Reference{ id: -1, // This is altered by a Header when added. name: name, lRef: int32(length), md5: h, assemID: assemID, species: species, uri: uri, }, nil }
[ "func", "NewReference", "(", "name", ",", "assemID", ",", "species", "string", ",", "length", "int", ",", "md5", "[", "]", "byte", ",", "uri", "*", "url", ".", "URL", ")", "(", "*", "Reference", ",", "error", ")", "{", "if", "!", "validLen", "(", "length", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "name", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "h", "string", "\n", "if", "md5", "!=", "nil", "{", "if", "len", "(", "md5", ")", "!=", "16", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "h", "=", "string", "(", "md5", "[", ":", "]", ")", "\n", "}", "\n", "return", "&", "Reference", "{", "id", ":", "-", "1", ",", "// This is altered by a Header when added.", "name", ":", "name", ",", "lRef", ":", "int32", "(", "length", ")", ",", "md5", ":", "h", ",", "assemID", ":", "assemID", ",", "species", ":", "species", ",", "uri", ":", "uri", ",", "}", ",", "nil", "\n", "}" ]
// 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).
[ "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", ")", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L33-L56
15,069
biogo/hts
sam/reference.go
SetName
func (r *Reference) SetName(n string) error { if r.owner != nil { id, exists := r.owner.seenRefs[n] if exists { if id != r.id { return errors.New("sam: name exists") } return nil } delete(r.owner.seenRefs, r.name) r.owner.seenRefs[n] = r.id } r.name = n return nil }
go
func (r *Reference) SetName(n string) error { if r.owner != nil { id, exists := r.owner.seenRefs[n] if exists { if id != r.id { return errors.New("sam: name exists") } return nil } delete(r.owner.seenRefs, r.name) r.owner.seenRefs[n] = r.id } r.name = n return nil }
[ "func", "(", "r", "*", "Reference", ")", "SetName", "(", "n", "string", ")", "error", "{", "if", "r", ".", "owner", "!=", "nil", "{", "id", ",", "exists", ":=", "r", ".", "owner", ".", "seenRefs", "[", "n", "]", "\n", "if", "exists", "{", "if", "id", "!=", "r", ".", "id", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "delete", "(", "r", ".", "owner", ".", "seenRefs", ",", "r", ".", "name", ")", "\n", "r", ".", "owner", ".", "seenRefs", "[", "n", "]", "=", "r", ".", "id", "\n", "}", "\n", "r", ".", "name", "=", "n", "\n", "return", "nil", "\n", "}" ]
// SetName sets the reference name to n.
[ "SetName", "sets", "the", "reference", "name", "to", "n", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L75-L89
15,070
biogo/hts
sam/reference.go
MD5
func (r *Reference) MD5() []byte { if r == nil || r.md5 == "" { return nil } return []byte(r.md5) }
go
func (r *Reference) MD5() []byte { if r == nil || r.md5 == "" { return nil } return []byte(r.md5) }
[ "func", "(", "r", "*", "Reference", ")", "MD5", "(", ")", "[", "]", "byte", "{", "if", "r", "==", "nil", "||", "r", ".", "md5", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "[", "]", "byte", "(", "r", ".", "md5", ")", "\n", "}" ]
// MD5 returns a 16 byte slice holding the MD5 sum of the reference sequence.
[ "MD5", "returns", "a", "16", "byte", "slice", "holding", "the", "MD5", "sum", "of", "the", "reference", "sequence", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L108-L113
15,071
biogo/hts
sam/reference.go
URI
func (r *Reference) URI() string { if r == nil { return "" } return fmt.Sprintf("%s", r.uri) }
go
func (r *Reference) URI() string { if r == nil { return "" } return fmt.Sprintf("%s", r.uri) }
[ "func", "(", "r", "*", "Reference", ")", "URI", "(", ")", "string", "{", "if", "r", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "uri", ")", "\n", "}" ]
// URI returns the URI of the reference.
[ "URI", "returns", "the", "URI", "of", "the", "reference", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L116-L121
15,072
biogo/hts
sam/reference.go
SetLen
func (r *Reference) SetLen(l int) error { if !validLen(l) { return errors.New("sam: length out of range") } r.lRef = int32(l) return nil }
go
func (r *Reference) SetLen(l int) error { if !validLen(l) { return errors.New("sam: length out of range") } r.lRef = int32(l) return nil }
[ "func", "(", "r", "*", "Reference", ")", "SetLen", "(", "l", "int", ")", "error", "{", "if", "!", "validLen", "(", "l", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "r", ".", "lRef", "=", "int32", "(", "l", ")", "\n", "return", "nil", "\n", "}" ]
// SetLen sets the length of the reference sequence to l. The given length // must be a valid SAM reference length.
[ "SetLen", "sets", "the", "length", "of", "the", "reference", "sequence", "to", "l", ".", "The", "given", "length", "must", "be", "a", "valid", "SAM", "reference", "length", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L133-L139
15,073
biogo/hts
sam/reference.go
Tags
func (r *Reference) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(refNameTag, r.Name()) fn(refLengthTag, fmt.Sprint(r.lRef)) if r.assemID != "" { fn(assemblyIDTag, r.assemID) } if r.md5 != "" { fn(md5Tag, fmt.Sprintf("%x", []byte(r.md5))) } if r.species != "" { fn(speciesTag, r.species) } if r.uri != nil { fn(uriTag, r.uri.String()) } for _, tp := range r.otherTags { fn(tp.tag, tp.value) } }
go
func (r *Reference) Tags(fn func(t Tag, value string)) { if fn == nil { return } fn(refNameTag, r.Name()) fn(refLengthTag, fmt.Sprint(r.lRef)) if r.assemID != "" { fn(assemblyIDTag, r.assemID) } if r.md5 != "" { fn(md5Tag, fmt.Sprintf("%x", []byte(r.md5))) } if r.species != "" { fn(speciesTag, r.species) } if r.uri != nil { fn(uriTag, r.uri.String()) } for _, tp := range r.otherTags { fn(tp.tag, tp.value) } }
[ "func", "(", "r", "*", "Reference", ")", "Tags", "(", "fn", "func", "(", "t", "Tag", ",", "value", "string", ")", ")", "{", "if", "fn", "==", "nil", "{", "return", "\n", "}", "\n", "fn", "(", "refNameTag", ",", "r", ".", "Name", "(", ")", ")", "\n", "fn", "(", "refLengthTag", ",", "fmt", ".", "Sprint", "(", "r", ".", "lRef", ")", ")", "\n", "if", "r", ".", "assemID", "!=", "\"", "\"", "{", "fn", "(", "assemblyIDTag", ",", "r", ".", "assemID", ")", "\n", "}", "\n", "if", "r", ".", "md5", "!=", "\"", "\"", "{", "fn", "(", "md5Tag", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "[", "]", "byte", "(", "r", ".", "md5", ")", ")", ")", "\n", "}", "\n", "if", "r", ".", "species", "!=", "\"", "\"", "{", "fn", "(", "speciesTag", ",", "r", ".", "species", ")", "\n", "}", "\n", "if", "r", ".", "uri", "!=", "nil", "{", "fn", "(", "uriTag", ",", "r", ".", "uri", ".", "String", "(", ")", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "fn", "(", "tp", ".", "tag", ",", "tp", ".", "value", ")", "\n", "}", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L144-L165
15,074
biogo/hts
sam/reference.go
Get
func (r *Reference) Get(t Tag) string { switch t { case refNameTag: return r.Name() case refLengthTag: return fmt.Sprint(r.lRef) case assemblyIDTag: return r.assemID case md5Tag: if r.md5 == "" { return "" } return fmt.Sprintf("%x", []byte(r.md5)) case speciesTag: return r.species case uriTag: if r.uri == nil { return "" } return r.uri.String() } for _, tp := range r.otherTags { if t == tp.tag { return tp.value } } return "" }
go
func (r *Reference) Get(t Tag) string { switch t { case refNameTag: return r.Name() case refLengthTag: return fmt.Sprint(r.lRef) case assemblyIDTag: return r.assemID case md5Tag: if r.md5 == "" { return "" } return fmt.Sprintf("%x", []byte(r.md5)) case speciesTag: return r.species case uriTag: if r.uri == nil { return "" } return r.uri.String() } for _, tp := range r.otherTags { if t == tp.tag { return tp.value } } return "" }
[ "func", "(", "r", "*", "Reference", ")", "Get", "(", "t", "Tag", ")", "string", "{", "switch", "t", "{", "case", "refNameTag", ":", "return", "r", ".", "Name", "(", ")", "\n", "case", "refLengthTag", ":", "return", "fmt", ".", "Sprint", "(", "r", ".", "lRef", ")", "\n", "case", "assemblyIDTag", ":", "return", "r", ".", "assemID", "\n", "case", "md5Tag", ":", "if", "r", ".", "md5", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "[", "]", "byte", "(", "r", ".", "md5", ")", ")", "\n", "case", "speciesTag", ":", "return", "r", ".", "species", "\n", "case", "uriTag", ":", "if", "r", ".", "uri", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "r", ".", "uri", ".", "String", "(", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "return", "tp", ".", "value", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L169-L196
15,075
biogo/hts
sam/reference.go
Set
func (r *Reference) Set(t Tag, value string) error { switch t { case refNameTag: if value == "*" { r.name = "" return nil } r.name = value case refLengthTag: l, err := strconv.Atoi(value) if err != nil { return errBadHeader } if !validLen(l) { return errBadLen } r.lRef = int32(l) case assemblyIDTag: r.assemID = value case md5Tag: if value == "" { r.md5 = "" return nil } hb := [16]byte{} n, err := hex.Decode(hb[:], []byte(value)) if err != nil { return err } if n != 16 { return errBadHeader } r.md5 = string(hb[:]) case speciesTag: r.species = value case uriTag: if value == "" { r.uri = nil return nil } uri, err := url.Parse(value) if err != nil { return err } r.uri = uri if r.uri.Scheme != "http" && r.uri.Scheme != "ftp" { r.uri.Scheme = "file" } default: if value == "" { for i, tp := range r.otherTags { if t == tp.tag { copy(r.otherTags[i:], r.otherTags[i+1:]) r.otherTags = r.otherTags[:len(r.otherTags)-1] return nil } } } else { for i, tp := range r.otherTags { if t == tp.tag { r.otherTags[i].value = value return nil } } r.otherTags = append(r.otherTags, tagPair{tag: t, value: value}) } } return nil }
go
func (r *Reference) Set(t Tag, value string) error { switch t { case refNameTag: if value == "*" { r.name = "" return nil } r.name = value case refLengthTag: l, err := strconv.Atoi(value) if err != nil { return errBadHeader } if !validLen(l) { return errBadLen } r.lRef = int32(l) case assemblyIDTag: r.assemID = value case md5Tag: if value == "" { r.md5 = "" return nil } hb := [16]byte{} n, err := hex.Decode(hb[:], []byte(value)) if err != nil { return err } if n != 16 { return errBadHeader } r.md5 = string(hb[:]) case speciesTag: r.species = value case uriTag: if value == "" { r.uri = nil return nil } uri, err := url.Parse(value) if err != nil { return err } r.uri = uri if r.uri.Scheme != "http" && r.uri.Scheme != "ftp" { r.uri.Scheme = "file" } default: if value == "" { for i, tp := range r.otherTags { if t == tp.tag { copy(r.otherTags[i:], r.otherTags[i+1:]) r.otherTags = r.otherTags[:len(r.otherTags)-1] return nil } } } else { for i, tp := range r.otherTags { if t == tp.tag { r.otherTags[i].value = value return nil } } r.otherTags = append(r.otherTags, tagPair{tag: t, value: value}) } } return nil }
[ "func", "(", "r", "*", "Reference", ")", "Set", "(", "t", "Tag", ",", "value", "string", ")", "error", "{", "switch", "t", "{", "case", "refNameTag", ":", "if", "value", "==", "\"", "\"", "{", "r", ".", "name", "=", "\"", "\"", "\n", "return", "nil", "\n", "}", "\n", "r", ".", "name", "=", "value", "\n", "case", "refLengthTag", ":", "l", ",", "err", ":=", "strconv", ".", "Atoi", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errBadHeader", "\n", "}", "\n", "if", "!", "validLen", "(", "l", ")", "{", "return", "errBadLen", "\n", "}", "\n", "r", ".", "lRef", "=", "int32", "(", "l", ")", "\n", "case", "assemblyIDTag", ":", "r", ".", "assemID", "=", "value", "\n", "case", "md5Tag", ":", "if", "value", "==", "\"", "\"", "{", "r", ".", "md5", "=", "\"", "\"", "\n", "return", "nil", "\n", "}", "\n", "hb", ":=", "[", "16", "]", "byte", "{", "}", "\n", "n", ",", "err", ":=", "hex", ".", "Decode", "(", "hb", "[", ":", "]", ",", "[", "]", "byte", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "n", "!=", "16", "{", "return", "errBadHeader", "\n", "}", "\n", "r", ".", "md5", "=", "string", "(", "hb", "[", ":", "]", ")", "\n", "case", "speciesTag", ":", "r", ".", "species", "=", "value", "\n", "case", "uriTag", ":", "if", "value", "==", "\"", "\"", "{", "r", ".", "uri", "=", "nil", "\n", "return", "nil", "\n", "}", "\n", "uri", ",", "err", ":=", "url", ".", "Parse", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "r", ".", "uri", "=", "uri", "\n", "if", "r", ".", "uri", ".", "Scheme", "!=", "\"", "\"", "&&", "r", ".", "uri", ".", "Scheme", "!=", "\"", "\"", "{", "r", ".", "uri", ".", "Scheme", "=", "\"", "\"", "\n", "}", "\n", "default", ":", "if", "value", "==", "\"", "\"", "{", "for", "i", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "copy", "(", "r", ".", "otherTags", "[", "i", ":", "]", ",", "r", ".", "otherTags", "[", "i", "+", "1", ":", "]", ")", "\n", "r", ".", "otherTags", "=", "r", ".", "otherTags", "[", ":", "len", "(", "r", ".", "otherTags", ")", "-", "1", "]", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "else", "{", "for", "i", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "if", "t", "==", "tp", ".", "tag", "{", "r", ".", "otherTags", "[", "i", "]", ".", "value", "=", "value", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "r", ".", "otherTags", "=", "append", "(", "r", ".", "otherTags", ",", "tagPair", "{", "tag", ":", "t", ",", "value", ":", "value", "}", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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.
[ "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", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L200-L268
15,076
biogo/hts
sam/reference.go
String
func (r *Reference) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "@SQ\tSN:%s\tLN:%d", r.name, r.lRef) if r.md5 != "" { fmt.Fprintf(&buf, "\tM5:%x", []byte(r.md5)) } if r.assemID != "" { fmt.Fprintf(&buf, "\tAS:%s", r.assemID) } if r.species != "" { fmt.Fprintf(&buf, "\tSP:%s", r.species) } if r.uri != nil { fmt.Fprintf(&buf, "\tUR:%s", r.uri) } for _, tp := range r.otherTags { fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value) } return buf.String() }
go
func (r *Reference) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "@SQ\tSN:%s\tLN:%d", r.name, r.lRef) if r.md5 != "" { fmt.Fprintf(&buf, "\tM5:%x", []byte(r.md5)) } if r.assemID != "" { fmt.Fprintf(&buf, "\tAS:%s", r.assemID) } if r.species != "" { fmt.Fprintf(&buf, "\tSP:%s", r.species) } if r.uri != nil { fmt.Fprintf(&buf, "\tUR:%s", r.uri) } for _, tp := range r.otherTags { fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value) } return buf.String() }
[ "func", "(", "r", "*", "Reference", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\\t", "\"", ",", "r", ".", "name", ",", "r", ".", "lRef", ")", "\n", "if", "r", ".", "md5", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "[", "]", "byte", "(", "r", ".", "md5", ")", ")", "\n", "}", "\n", "if", "r", ".", "assemID", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "assemID", ")", "\n", "}", "\n", "if", "r", ".", "species", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "species", ")", "\n", "}", "\n", "if", "r", ".", "uri", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "r", ".", "uri", ")", "\n", "}", "\n", "for", "_", ",", "tp", ":=", "range", "r", ".", "otherTags", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\\t", "\"", ",", "tp", ".", "tag", ",", "tp", ".", "value", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// String returns a string representation of the Reference according to the // SAM specification section 1.3,
[ "String", "returns", "a", "string", "representation", "of", "the", "Reference", "according", "to", "the", "SAM", "specification", "section", "1", ".", "3" ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L272-L291
15,077
biogo/hts
sam/reference.go
Clone
func (r *Reference) Clone() *Reference { if r == nil { return nil } cr := *r if len(cr.otherTags) != 0 { cr.otherTags = make([]tagPair, len(cr.otherTags)) } copy(cr.otherTags, r.otherTags) cr.owner = nil cr.id = -1 if r.uri != nil { cr.uri = &url.URL{} *cr.uri = *r.uri if r.uri.User != nil { cr.uri.User = &url.Userinfo{} *cr.uri.User = *r.uri.User } } return &cr }
go
func (r *Reference) Clone() *Reference { if r == nil { return nil } cr := *r if len(cr.otherTags) != 0 { cr.otherTags = make([]tagPair, len(cr.otherTags)) } copy(cr.otherTags, r.otherTags) cr.owner = nil cr.id = -1 if r.uri != nil { cr.uri = &url.URL{} *cr.uri = *r.uri if r.uri.User != nil { cr.uri.User = &url.Userinfo{} *cr.uri.User = *r.uri.User } } return &cr }
[ "func", "(", "r", "*", "Reference", ")", "Clone", "(", ")", "*", "Reference", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "cr", ":=", "*", "r", "\n", "if", "len", "(", "cr", ".", "otherTags", ")", "!=", "0", "{", "cr", ".", "otherTags", "=", "make", "(", "[", "]", "tagPair", ",", "len", "(", "cr", ".", "otherTags", ")", ")", "\n", "}", "\n", "copy", "(", "cr", ".", "otherTags", ",", "r", ".", "otherTags", ")", "\n", "cr", ".", "owner", "=", "nil", "\n", "cr", ".", "id", "=", "-", "1", "\n", "if", "r", ".", "uri", "!=", "nil", "{", "cr", ".", "uri", "=", "&", "url", ".", "URL", "{", "}", "\n", "*", "cr", ".", "uri", "=", "*", "r", ".", "uri", "\n", "if", "r", ".", "uri", ".", "User", "!=", "nil", "{", "cr", ".", "uri", ".", "User", "=", "&", "url", ".", "Userinfo", "{", "}", "\n", "*", "cr", ".", "uri", ".", "User", "=", "*", "r", ".", "uri", ".", "User", "\n", "}", "\n", "}", "\n", "return", "&", "cr", "\n", "}" ]
// Clone returns a deep copy of the Reference.
[ "Clone", "returns", "a", "deep", "copy", "of", "the", "Reference", "." ]
aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64
https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/reference.go#L294-L314
15,078
reviewdog/errorformat
errorformat.go
NewScanner
func (errorformat *Errorformat) NewScanner(r io.Reader) *Scanner { return &Scanner{ Errorformat: errorformat, source: bufio.NewScanner(r), qi: &qfinfo{}, mlpoped: true, } }
go
func (errorformat *Errorformat) NewScanner(r io.Reader) *Scanner { return &Scanner{ Errorformat: errorformat, source: bufio.NewScanner(r), qi: &qfinfo{}, mlpoped: true, } }
[ "func", "(", "errorformat", "*", "Errorformat", ")", "NewScanner", "(", "r", "io", ".", "Reader", ")", "*", "Scanner", "{", "return", "&", "Scanner", "{", "Errorformat", ":", "errorformat", ",", "source", ":", "bufio", ".", "NewScanner", "(", "r", ")", ",", "qi", ":", "&", "qfinfo", "{", "}", ",", "mlpoped", ":", "true", ",", "}", "\n", "}" ]
// NewScanner returns a new Scanner to read from r.
[ "NewScanner", "returns", "a", "new", "Scanner", "to", "read", "from", "r", "." ]
c8010a9cc20d220a81add2d6b05768465ee0cdbd
https://github.com/reviewdog/errorformat/blob/c8010a9cc20d220a81add2d6b05768465ee0cdbd/errorformat.go#L48-L55
15,079
reviewdog/errorformat
errorformat.go
Scan
func (s *Scanner) Scan() bool { for s.source.Scan() { line := s.source.Text() status, fields := s.parseLine(line) switch status { case qffail: continue case qfendmultiline: s.mlpoped = true s.entry = s.qi.qflist[len(s.qi.qflist)-1] return true case qfignoreline: continue } var lastml *Entry // last multiline entry which isn't poped out if !s.mlpoped { lastml = s.qi.qflist[len(s.qi.qflist)-1] } qfl := &Entry{ Filename: fields.namebuf, Lnum: fields.lnum, Col: fields.col, Nr: fields.enr, Pattern: fields.pattern, Text: fields.errmsg, Vcol: fields.useviscol, Valid: fields.valid, Type: rune(fields.etype), Lines: fields.lines, } if qfl.Filename == "" && s.qi.currfile != "" { qfl.Filename = s.qi.currfile } s.qi.qflist = append(s.qi.qflist, qfl) if s.qi.multiline { s.mlpoped = false // mark multiline entry is not poped // if there is last multiline entry which isn't poped out yet, pop it out now. if lastml != nil { s.entry = lastml return true } continue } // multiline flag doesn't be reset with new entry. // %Z or nomach are the only way to reset multiline flag. s.entry = qfl return true } // pop last not-ended multiline entry if !s.mlpoped { s.mlpoped = true s.entry = s.qi.qflist[len(s.qi.qflist)-1] return true } return false }
go
func (s *Scanner) Scan() bool { for s.source.Scan() { line := s.source.Text() status, fields := s.parseLine(line) switch status { case qffail: continue case qfendmultiline: s.mlpoped = true s.entry = s.qi.qflist[len(s.qi.qflist)-1] return true case qfignoreline: continue } var lastml *Entry // last multiline entry which isn't poped out if !s.mlpoped { lastml = s.qi.qflist[len(s.qi.qflist)-1] } qfl := &Entry{ Filename: fields.namebuf, Lnum: fields.lnum, Col: fields.col, Nr: fields.enr, Pattern: fields.pattern, Text: fields.errmsg, Vcol: fields.useviscol, Valid: fields.valid, Type: rune(fields.etype), Lines: fields.lines, } if qfl.Filename == "" && s.qi.currfile != "" { qfl.Filename = s.qi.currfile } s.qi.qflist = append(s.qi.qflist, qfl) if s.qi.multiline { s.mlpoped = false // mark multiline entry is not poped // if there is last multiline entry which isn't poped out yet, pop it out now. if lastml != nil { s.entry = lastml return true } continue } // multiline flag doesn't be reset with new entry. // %Z or nomach are the only way to reset multiline flag. s.entry = qfl return true } // pop last not-ended multiline entry if !s.mlpoped { s.mlpoped = true s.entry = s.qi.qflist[len(s.qi.qflist)-1] return true } return false }
[ "func", "(", "s", "*", "Scanner", ")", "Scan", "(", ")", "bool", "{", "for", "s", ".", "source", ".", "Scan", "(", ")", "{", "line", ":=", "s", ".", "source", ".", "Text", "(", ")", "\n", "status", ",", "fields", ":=", "s", ".", "parseLine", "(", "line", ")", "\n", "switch", "status", "{", "case", "qffail", ":", "continue", "\n", "case", "qfendmultiline", ":", "s", ".", "mlpoped", "=", "true", "\n", "s", ".", "entry", "=", "s", ".", "qi", ".", "qflist", "[", "len", "(", "s", ".", "qi", ".", "qflist", ")", "-", "1", "]", "\n", "return", "true", "\n", "case", "qfignoreline", ":", "continue", "\n", "}", "\n", "var", "lastml", "*", "Entry", "// last multiline entry which isn't poped out", "\n", "if", "!", "s", ".", "mlpoped", "{", "lastml", "=", "s", ".", "qi", ".", "qflist", "[", "len", "(", "s", ".", "qi", ".", "qflist", ")", "-", "1", "]", "\n", "}", "\n", "qfl", ":=", "&", "Entry", "{", "Filename", ":", "fields", ".", "namebuf", ",", "Lnum", ":", "fields", ".", "lnum", ",", "Col", ":", "fields", ".", "col", ",", "Nr", ":", "fields", ".", "enr", ",", "Pattern", ":", "fields", ".", "pattern", ",", "Text", ":", "fields", ".", "errmsg", ",", "Vcol", ":", "fields", ".", "useviscol", ",", "Valid", ":", "fields", ".", "valid", ",", "Type", ":", "rune", "(", "fields", ".", "etype", ")", ",", "Lines", ":", "fields", ".", "lines", ",", "}", "\n", "if", "qfl", ".", "Filename", "==", "\"", "\"", "&&", "s", ".", "qi", ".", "currfile", "!=", "\"", "\"", "{", "qfl", ".", "Filename", "=", "s", ".", "qi", ".", "currfile", "\n", "}", "\n", "s", ".", "qi", ".", "qflist", "=", "append", "(", "s", ".", "qi", ".", "qflist", ",", "qfl", ")", "\n", "if", "s", ".", "qi", ".", "multiline", "{", "s", ".", "mlpoped", "=", "false", "// mark multiline entry is not poped", "\n", "// if there is last multiline entry which isn't poped out yet, pop it out now.", "if", "lastml", "!=", "nil", "{", "s", ".", "entry", "=", "lastml", "\n", "return", "true", "\n", "}", "\n", "continue", "\n", "}", "\n", "// multiline flag doesn't be reset with new entry.", "// %Z or nomach are the only way to reset multiline flag.", "s", ".", "entry", "=", "qfl", "\n", "return", "true", "\n", "}", "\n", "// pop last not-ended multiline entry", "if", "!", "s", ".", "mlpoped", "{", "s", ".", "mlpoped", "=", "true", "\n", "s", ".", "entry", "=", "s", ".", "qi", ".", "qflist", "[", "len", "(", "s", ".", "qi", ".", "qflist", ")", "-", "1", "]", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Scan advances the Scanner to the next entry matched with errorformat, which // will then be available through the Entry method. It returns false // when the scan stops by reaching the end of the input.
[ "Scan", "advances", "the", "Scanner", "to", "the", "next", "entry", "matched", "with", "errorformat", "which", "will", "then", "be", "available", "through", "the", "Entry", "method", ".", "It", "returns", "false", "when", "the", "scan", "stops", "by", "reaching", "the", "end", "of", "the", "input", "." ]
c8010a9cc20d220a81add2d6b05768465ee0cdbd
https://github.com/reviewdog/errorformat/blob/c8010a9cc20d220a81add2d6b05768465ee0cdbd/errorformat.go#L166-L221
15,080
reviewdog/errorformat
errorformat.go
Match
func (efm *Efm) Match(s string) *Match { ms := efm.regex.FindStringSubmatch(s) if len(ms) == 0 { return nil } match := &Match{} names := efm.regex.SubexpNames() for i, name := range names { if i == 0 { continue } m := ms[i] switch name { case "f": match.F = m case "n": match.N = mustAtoI(m) case "l": match.L = mustAtoI(m) case "c": match.C = mustAtoI(m) case "t": match.T = m[0] case "m": match.M = m case "r": match.R = m case "p": match.P = m case "v": match.V = mustAtoI(m) case "s": match.S = m } } return match }
go
func (efm *Efm) Match(s string) *Match { ms := efm.regex.FindStringSubmatch(s) if len(ms) == 0 { return nil } match := &Match{} names := efm.regex.SubexpNames() for i, name := range names { if i == 0 { continue } m := ms[i] switch name { case "f": match.F = m case "n": match.N = mustAtoI(m) case "l": match.L = mustAtoI(m) case "c": match.C = mustAtoI(m) case "t": match.T = m[0] case "m": match.M = m case "r": match.R = m case "p": match.P = m case "v": match.V = mustAtoI(m) case "s": match.S = m } } return match }
[ "func", "(", "efm", "*", "Efm", ")", "Match", "(", "s", "string", ")", "*", "Match", "{", "ms", ":=", "efm", ".", "regex", ".", "FindStringSubmatch", "(", "s", ")", "\n", "if", "len", "(", "ms", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "match", ":=", "&", "Match", "{", "}", "\n", "names", ":=", "efm", ".", "regex", ".", "SubexpNames", "(", ")", "\n", "for", "i", ",", "name", ":=", "range", "names", "{", "if", "i", "==", "0", "{", "continue", "\n", "}", "\n", "m", ":=", "ms", "[", "i", "]", "\n", "switch", "name", "{", "case", "\"", "\"", ":", "match", ".", "F", "=", "m", "\n", "case", "\"", "\"", ":", "match", ".", "N", "=", "mustAtoI", "(", "m", ")", "\n", "case", "\"", "\"", ":", "match", ".", "L", "=", "mustAtoI", "(", "m", ")", "\n", "case", "\"", "\"", ":", "match", ".", "C", "=", "mustAtoI", "(", "m", ")", "\n", "case", "\"", "\"", ":", "match", ".", "T", "=", "m", "[", "0", "]", "\n", "case", "\"", "\"", ":", "match", ".", "M", "=", "m", "\n", "case", "\"", "\"", ":", "match", ".", "R", "=", "m", "\n", "case", "\"", "\"", ":", "match", ".", "P", "=", "m", "\n", "case", "\"", "\"", ":", "match", ".", "V", "=", "mustAtoI", "(", "m", ")", "\n", "case", "\"", "\"", ":", "match", ".", "S", "=", "m", "\n", "}", "\n", "}", "\n", "return", "match", "\n", "}" ]
// Match returns match against given string.
[ "Match", "returns", "match", "against", "given", "string", "." ]
c8010a9cc20d220a81add2d6b05768465ee0cdbd
https://github.com/reviewdog/errorformat/blob/c8010a9cc20d220a81add2d6b05768465ee0cdbd/errorformat.go#L521-L557
15,081
appc/docker2aci
lib/internal/util/util.go
Quote
func Quote(l []string) []string { var quoted []string for _, s := range l { quoted = append(quoted, fmt.Sprintf("%q", s)) } return quoted }
go
func Quote(l []string) []string { var quoted []string for _, s := range l { quoted = append(quoted, fmt.Sprintf("%q", s)) } return quoted }
[ "func", "Quote", "(", "l", "[", "]", "string", ")", "[", "]", "string", "{", "var", "quoted", "[", "]", "string", "\n\n", "for", "_", ",", "s", ":=", "range", "l", "{", "quoted", "=", "append", "(", "quoted", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ")", ")", "\n", "}", "\n\n", "return", "quoted", "\n", "}" ]
// Quote takes a slice of strings and returns another slice with them quoted.
[ "Quote", "takes", "a", "slice", "of", "strings", "and", "returns", "another", "slice", "with", "them", "quoted", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/util/util.go#L37-L45
15,082
appc/docker2aci
lib/internal/util/util.go
ReverseImages
func ReverseImages(s acirenderer.Images) acirenderer.Images { var o acirenderer.Images for i := len(s) - 1; i >= 0; i-- { o = append(o, s[i]) } return o }
go
func ReverseImages(s acirenderer.Images) acirenderer.Images { var o acirenderer.Images for i := len(s) - 1; i >= 0; i-- { o = append(o, s[i]) } return o }
[ "func", "ReverseImages", "(", "s", "acirenderer", ".", "Images", ")", "acirenderer", ".", "Images", "{", "var", "o", "acirenderer", ".", "Images", "\n", "for", "i", ":=", "len", "(", "s", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "o", "=", "append", "(", "o", ",", "s", "[", "i", "]", ")", "\n", "}", "\n\n", "return", "o", "\n", "}" ]
// ReverseImages takes an acirenderer.Images and reverses it.
[ "ReverseImages", "takes", "an", "acirenderer", ".", "Images", "and", "reverses", "it", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/util/util.go#L48-L55
15,083
appc/docker2aci
lib/internal/util/util.go
IndexOf
func IndexOf(list []string, el string) int { for i, x := range list { if el == x { return i } } return -1 }
go
func IndexOf(list []string, el string) int { for i, x := range list { if el == x { return i } } return -1 }
[ "func", "IndexOf", "(", "list", "[", "]", "string", ",", "el", "string", ")", "int", "{", "for", "i", ",", "x", ":=", "range", "list", "{", "if", "el", "==", "x", "{", "return", "i", "\n", "}", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// IndexOf returns the index of el in list, or -1 if it's not found.
[ "IndexOf", "returns", "the", "index", "of", "el", "in", "list", "or", "-", "1", "if", "it", "s", "not", "found", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/util/util.go#L63-L70
15,084
appc/docker2aci
lib/internal/docker/docker.go
SplitReposName
func SplitReposName(name string) (indexName, remoteName string) { i := strings.IndexRune(name, '/') if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != "localhost") { indexName, remoteName = defaultIndexURL, name } else { indexName, remoteName = name[:i], name[i+1:] } if indexName == defaultIndexURL && !strings.ContainsRune(remoteName, '/') { remoteName = defaultRepoPrefix + remoteName } return }
go
func SplitReposName(name string) (indexName, remoteName string) { i := strings.IndexRune(name, '/') if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != "localhost") { indexName, remoteName = defaultIndexURL, name } else { indexName, remoteName = name[:i], name[i+1:] } if indexName == defaultIndexURL && !strings.ContainsRune(remoteName, '/') { remoteName = defaultRepoPrefix + remoteName } return }
[ "func", "SplitReposName", "(", "name", "string", ")", "(", "indexName", ",", "remoteName", "string", ")", "{", "i", ":=", "strings", ".", "IndexRune", "(", "name", ",", "'/'", ")", "\n", "if", "i", "==", "-", "1", "||", "(", "!", "strings", ".", "ContainsAny", "(", "name", "[", ":", "i", "]", ",", "\"", "\"", ")", "&&", "name", "[", ":", "i", "]", "!=", "\"", "\"", ")", "{", "indexName", ",", "remoteName", "=", "defaultIndexURL", ",", "name", "\n", "}", "else", "{", "indexName", ",", "remoteName", "=", "name", "[", ":", "i", "]", ",", "name", "[", "i", "+", "1", ":", "]", "\n", "}", "\n", "if", "indexName", "==", "defaultIndexURL", "&&", "!", "strings", ".", "ContainsRune", "(", "remoteName", ",", "'/'", ")", "{", "remoteName", "=", "defaultRepoPrefix", "+", "remoteName", "\n", "}", "\n", "return", "\n", "}" ]
// SplitReposName breaks a repo name into an index name and remote name.
[ "SplitReposName", "breaks", "a", "repo", "name", "into", "an", "index", "name", "and", "remote", "name", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/docker/docker.go#L39-L50
15,085
appc/docker2aci
lib/common/common.go
ParseDockerURL
func ParseDockerURL(arg string) (*ParsedDockerURL, error) { r, err := reference.ParseNormalizedNamed(arg) if err != nil { return nil, err } var tag, digest string switch x := r.(type) { case reference.Canonical: digest = x.Digest().String() case reference.NamedTagged: tag = x.Tag() default: tag = defaultTag } indexURL, remoteName := docker.SplitReposName(reference.FamiliarName(r)) return &ParsedDockerURL{ OriginalName: arg, IndexURL: indexURL, ImageName: remoteName, Tag: tag, Digest: digest, }, nil }
go
func ParseDockerURL(arg string) (*ParsedDockerURL, error) { r, err := reference.ParseNormalizedNamed(arg) if err != nil { return nil, err } var tag, digest string switch x := r.(type) { case reference.Canonical: digest = x.Digest().String() case reference.NamedTagged: tag = x.Tag() default: tag = defaultTag } indexURL, remoteName := docker.SplitReposName(reference.FamiliarName(r)) return &ParsedDockerURL{ OriginalName: arg, IndexURL: indexURL, ImageName: remoteName, Tag: tag, Digest: digest, }, nil }
[ "func", "ParseDockerURL", "(", "arg", "string", ")", "(", "*", "ParsedDockerURL", ",", "error", ")", "{", "r", ",", "err", ":=", "reference", ".", "ParseNormalizedNamed", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "tag", ",", "digest", "string", "\n", "switch", "x", ":=", "r", ".", "(", "type", ")", "{", "case", "reference", ".", "Canonical", ":", "digest", "=", "x", ".", "Digest", "(", ")", ".", "String", "(", ")", "\n", "case", "reference", ".", "NamedTagged", ":", "tag", "=", "x", ".", "Tag", "(", ")", "\n", "default", ":", "tag", "=", "defaultTag", "\n", "}", "\n\n", "indexURL", ",", "remoteName", ":=", "docker", ".", "SplitReposName", "(", "reference", ".", "FamiliarName", "(", "r", ")", ")", "\n\n", "return", "&", "ParsedDockerURL", "{", "OriginalName", ":", "arg", ",", "IndexURL", ":", "indexURL", ",", "ImageName", ":", "remoteName", ",", "Tag", ":", "tag", ",", "Digest", ":", "digest", ",", "}", ",", "nil", "\n", "}" ]
// ParseDockerURL takes a Docker URL and returns a ParsedDockerURL with its // index URL, image name, and tag.
[ "ParseDockerURL", "takes", "a", "Docker", "URL", "and", "returns", "a", "ParsedDockerURL", "with", "its", "index", "URL", "image", "name", "and", "tag", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/common/common.go#L84-L109
15,086
appc/docker2aci
lib/common/common.go
ValidateLayerId
func ValidateLayerId(id string) error { if ok := validId.MatchString(id); !ok { return fmt.Errorf("invalid layer ID %q", id) } return nil }
go
func ValidateLayerId(id string) error { if ok := validId.MatchString(id); !ok { return fmt.Errorf("invalid layer ID %q", id) } return nil }
[ "func", "ValidateLayerId", "(", "id", "string", ")", "error", "{", "if", "ok", ":=", "validId", ".", "MatchString", "(", "id", ")", ";", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateLayerId validates a layer ID
[ "ValidateLayerId", "validates", "a", "layer", "ID" ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/common/common.go#L112-L117
15,087
appc/docker2aci
lib/internal/backend/file/file.go
getAncestry
func getAncestry(file *os.File, imgID string, debug log.Logger) ([]string, error) { var ancestry []string deps := make(map[string]bool) curImgID := imgID var err error for curImgID != "" { if deps[curImgID] { return nil, fmt.Errorf("dependency loop detected at image %q", curImgID) } deps[curImgID] = true ancestry = append(ancestry, curImgID) debug.Printf("Getting ancestry for layer %q", curImgID) curImgID, err = getParent(file, curImgID, debug) if err != nil { return nil, err } } return ancestry, nil }
go
func getAncestry(file *os.File, imgID string, debug log.Logger) ([]string, error) { var ancestry []string deps := make(map[string]bool) curImgID := imgID var err error for curImgID != "" { if deps[curImgID] { return nil, fmt.Errorf("dependency loop detected at image %q", curImgID) } deps[curImgID] = true ancestry = append(ancestry, curImgID) debug.Printf("Getting ancestry for layer %q", curImgID) curImgID, err = getParent(file, curImgID, debug) if err != nil { return nil, err } } return ancestry, nil }
[ "func", "getAncestry", "(", "file", "*", "os", ".", "File", ",", "imgID", "string", ",", "debug", "log", ".", "Logger", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "ancestry", "[", "]", "string", "\n", "deps", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n\n", "curImgID", ":=", "imgID", "\n\n", "var", "err", "error", "\n", "for", "curImgID", "!=", "\"", "\"", "{", "if", "deps", "[", "curImgID", "]", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "curImgID", ")", "\n", "}", "\n", "deps", "[", "curImgID", "]", "=", "true", "\n", "ancestry", "=", "append", "(", "ancestry", ",", "curImgID", ")", "\n", "debug", ".", "Printf", "(", "\"", "\"", ",", "curImgID", ")", "\n", "curImgID", ",", "err", "=", "getParent", "(", "file", ",", "curImgID", ",", "debug", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "ancestry", ",", "nil", "\n", "}" ]
// getAncestry computes an image ancestry, returning an ordered list // of dependencies starting from the topmost image to the base. // It checks for dependency loops via duplicate detection in the image // chain and errors out in such cases.
[ "getAncestry", "computes", "an", "image", "ancestry", "returning", "an", "ordered", "list", "of", "dependencies", "starting", "from", "the", "topmost", "image", "to", "the", "base", ".", "It", "checks", "for", "dependency", "loops", "via", "duplicate", "detection", "in", "the", "image", "chain", "and", "errors", "out", "in", "such", "cases", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/backend/file/file.go#L459-L479
15,088
appc/docker2aci
lib/internal/internal.go
GenerateACI
func GenerateACI(layerNumber int, manhash string, layerData types.DockerImageData, dockerURL *common.ParsedDockerURL, outputDir string, layerFile *os.File, curPwl []string, compression common.Compression, debug log.Logger) (string, *schema.ImageManifest, error) { manifest, err := GenerateManifest(layerData, manhash, dockerURL, debug) if err != nil { return "", nil, fmt.Errorf("error generating the manifest: %v", err) } imageName := strings.Replace(dockerURL.ImageName, "/", "-", -1) aciPath := generateACIPath(outputDir, imageName, layerData.ID, dockerURL.Tag, layerData.OS, layerData.Architecture, layerNumber) manifest, err = writeACI(layerFile, *manifest, curPwl, aciPath, compression) if err != nil { return "", nil, fmt.Errorf("error writing ACI: %v", err) } if err := ValidateACI(aciPath); err != nil { return "", nil, fmt.Errorf("invalid ACI generated: %v", err) } return aciPath, manifest, nil }
go
func GenerateACI(layerNumber int, manhash string, layerData types.DockerImageData, dockerURL *common.ParsedDockerURL, outputDir string, layerFile *os.File, curPwl []string, compression common.Compression, debug log.Logger) (string, *schema.ImageManifest, error) { manifest, err := GenerateManifest(layerData, manhash, dockerURL, debug) if err != nil { return "", nil, fmt.Errorf("error generating the manifest: %v", err) } imageName := strings.Replace(dockerURL.ImageName, "/", "-", -1) aciPath := generateACIPath(outputDir, imageName, layerData.ID, dockerURL.Tag, layerData.OS, layerData.Architecture, layerNumber) manifest, err = writeACI(layerFile, *manifest, curPwl, aciPath, compression) if err != nil { return "", nil, fmt.Errorf("error writing ACI: %v", err) } if err := ValidateACI(aciPath); err != nil { return "", nil, fmt.Errorf("invalid ACI generated: %v", err) } return aciPath, manifest, nil }
[ "func", "GenerateACI", "(", "layerNumber", "int", ",", "manhash", "string", ",", "layerData", "types", ".", "DockerImageData", ",", "dockerURL", "*", "common", ".", "ParsedDockerURL", ",", "outputDir", "string", ",", "layerFile", "*", "os", ".", "File", ",", "curPwl", "[", "]", "string", ",", "compression", "common", ".", "Compression", ",", "debug", "log", ".", "Logger", ")", "(", "string", ",", "*", "schema", ".", "ImageManifest", ",", "error", ")", "{", "manifest", ",", "err", ":=", "GenerateManifest", "(", "layerData", ",", "manhash", ",", "dockerURL", ",", "debug", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "imageName", ":=", "strings", ".", "Replace", "(", "dockerURL", ".", "ImageName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "aciPath", ":=", "generateACIPath", "(", "outputDir", ",", "imageName", ",", "layerData", ".", "ID", ",", "dockerURL", ".", "Tag", ",", "layerData", ".", "OS", ",", "layerData", ".", "Architecture", ",", "layerNumber", ")", "\n\n", "manifest", ",", "err", "=", "writeACI", "(", "layerFile", ",", "*", "manifest", ",", "curPwl", ",", "aciPath", ",", "compression", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "ValidateACI", "(", "aciPath", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "aciPath", ",", "manifest", ",", "nil", "\n", "}" ]
// GenerateACI takes a Docker layer and generates an ACI from it.
[ "GenerateACI", "takes", "a", "Docker", "layer", "and", "generates", "an", "ACI", "from", "it", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L67-L86
15,089
appc/docker2aci
lib/internal/internal.go
setLabel
func setLabel(labels map[appctypes.ACIdentifier]string, key, val string) { if key != "" && val != "" { labels[*appctypes.MustACIdentifier(key)] = val } }
go
func setLabel(labels map[appctypes.ACIdentifier]string, key, val string) { if key != "" && val != "" { labels[*appctypes.MustACIdentifier(key)] = val } }
[ "func", "setLabel", "(", "labels", "map", "[", "appctypes", ".", "ACIdentifier", "]", "string", ",", "key", ",", "val", "string", ")", "{", "if", "key", "!=", "\"", "\"", "&&", "val", "!=", "\"", "\"", "{", "labels", "[", "*", "appctypes", ".", "MustACIdentifier", "(", "key", ")", "]", "=", "val", "\n", "}", "\n", "}" ]
// setLabel sets the label entries associated with non-empty key // to the single non-empty value. It replaces any existing values // associated with key.
[ "setLabel", "sets", "the", "label", "entries", "associated", "with", "non", "-", "empty", "key", "to", "the", "single", "non", "-", "empty", "value", ".", "It", "replaces", "any", "existing", "values", "associated", "with", "key", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L178-L182
15,090
appc/docker2aci
lib/internal/internal.go
setOSArch
func setOSArch(labels map[appctypes.ACIdentifier]string, os, arch string) error { // Translate arch tuple into the appc arch tuple. appcOS, appcArch, err := appctypes.ToAppcOSArch(os, arch, "") if err != nil { return err } // Set translated labels. setLabel(labels, "os", appcOS) setLabel(labels, "arch", appcArch) return nil }
go
func setOSArch(labels map[appctypes.ACIdentifier]string, os, arch string) error { // Translate arch tuple into the appc arch tuple. appcOS, appcArch, err := appctypes.ToAppcOSArch(os, arch, "") if err != nil { return err } // Set translated labels. setLabel(labels, "os", appcOS) setLabel(labels, "arch", appcArch) return nil }
[ "func", "setOSArch", "(", "labels", "map", "[", "appctypes", ".", "ACIdentifier", "]", "string", ",", "os", ",", "arch", "string", ")", "error", "{", "// Translate arch tuple into the appc arch tuple.", "appcOS", ",", "appcArch", ",", "err", ":=", "appctypes", ".", "ToAppcOSArch", "(", "os", ",", "arch", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Set translated labels.", "setLabel", "(", "labels", ",", "\"", "\"", ",", "appcOS", ")", "\n", "setLabel", "(", "labels", ",", "\"", "\"", ",", "appcArch", ")", "\n", "return", "nil", "\n", "}" ]
// setOSArch translates the given OS and architecture strings into // the compatible with application container specification and sets // the respective label entries. // // Returns an error if label translation fails.
[ "setOSArch", "translates", "the", "given", "OS", "and", "architecture", "strings", "into", "the", "compatible", "with", "application", "container", "specification", "and", "sets", "the", "respective", "label", "entries", ".", "Returns", "an", "error", "if", "label", "translation", "fails", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L189-L200
15,091
appc/docker2aci
lib/internal/internal.go
setAnnotation
func setAnnotation(annotations *appctypes.Annotations, key, val string) { if key != "" && val != "" { annotations.Set(*appctypes.MustACIdentifier(key), val) } }
go
func setAnnotation(annotations *appctypes.Annotations, key, val string) { if key != "" && val != "" { annotations.Set(*appctypes.MustACIdentifier(key), val) } }
[ "func", "setAnnotation", "(", "annotations", "*", "appctypes", ".", "Annotations", ",", "key", ",", "val", "string", ")", "{", "if", "key", "!=", "\"", "\"", "&&", "val", "!=", "\"", "\"", "{", "annotations", ".", "Set", "(", "*", "appctypes", ".", "MustACIdentifier", "(", "key", ")", ",", "val", ")", "\n", "}", "\n", "}" ]
// setAnnotation sets the annotation entries associated with non-empty // key to the single non-empty value. It replaces any existing values // associated with key.
[ "setAnnotation", "sets", "the", "annotation", "entries", "associated", "with", "non", "-", "empty", "key", "to", "the", "single", "non", "-", "empty", "value", ".", "It", "replaces", "any", "existing", "values", "associated", "with", "key", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L205-L209
15,092
appc/docker2aci
lib/internal/internal.go
ValidateACI
func ValidateACI(aciPath string) error { aciFile, err := os.Open(aciPath) if err != nil { return err } defer aciFile.Close() tr, err := aci.NewCompressedTarReader(aciFile) if err != nil { return err } defer tr.Close() if err := aci.ValidateArchive(tr.Reader); err != nil { return err } return nil }
go
func ValidateACI(aciPath string) error { aciFile, err := os.Open(aciPath) if err != nil { return err } defer aciFile.Close() tr, err := aci.NewCompressedTarReader(aciFile) if err != nil { return err } defer tr.Close() if err := aci.ValidateArchive(tr.Reader); err != nil { return err } return nil }
[ "func", "ValidateACI", "(", "aciPath", "string", ")", "error", "{", "aciFile", ",", "err", ":=", "os", ".", "Open", "(", "aciPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "aciFile", ".", "Close", "(", ")", "\n\n", "tr", ",", "err", ":=", "aci", ".", "NewCompressedTarReader", "(", "aciFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "tr", ".", "Close", "(", ")", "\n\n", "if", "err", ":=", "aci", ".", "ValidateArchive", "(", "tr", ".", "Reader", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ValidateACI checks whether the ACI in aciPath is valid.
[ "ValidateACI", "checks", "whether", "the", "ACI", "in", "aciPath", "is", "valid", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L446-L464
15,093
appc/docker2aci
lib/internal/internal.go
WriteManifest
func WriteManifest(outputWriter *tar.Writer, manifest schema.ImageManifest) error { b, err := json.Marshal(manifest) if err != nil { return err } hdr := getGenericTarHeader() hdr.Name = "manifest" hdr.Mode = 0644 hdr.Size = int64(len(b)) hdr.Typeflag = tar.TypeReg if err := outputWriter.WriteHeader(hdr); err != nil { return err } if _, err := outputWriter.Write(b); err != nil { return err } return nil }
go
func WriteManifest(outputWriter *tar.Writer, manifest schema.ImageManifest) error { b, err := json.Marshal(manifest) if err != nil { return err } hdr := getGenericTarHeader() hdr.Name = "manifest" hdr.Mode = 0644 hdr.Size = int64(len(b)) hdr.Typeflag = tar.TypeReg if err := outputWriter.WriteHeader(hdr); err != nil { return err } if _, err := outputWriter.Write(b); err != nil { return err } return nil }
[ "func", "WriteManifest", "(", "outputWriter", "*", "tar", ".", "Writer", ",", "manifest", "schema", ".", "ImageManifest", ")", "error", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "manifest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "hdr", ":=", "getGenericTarHeader", "(", ")", "\n", "hdr", ".", "Name", "=", "\"", "\"", "\n", "hdr", ".", "Mode", "=", "0644", "\n", "hdr", ".", "Size", "=", "int64", "(", "len", "(", "b", ")", ")", "\n", "hdr", ".", "Typeflag", "=", "tar", ".", "TypeReg", "\n\n", "if", "err", ":=", "outputWriter", ".", "WriteHeader", "(", "hdr", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "outputWriter", ".", "Write", "(", "b", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WriteManifest writes a schema.ImageManifest entry on a tar.Writer.
[ "WriteManifest", "writes", "a", "schema", ".", "ImageManifest", "entry", "on", "a", "tar", ".", "Writer", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L743-L763
15,094
appc/docker2aci
lib/internal/internal.go
WriteRootfsDir
func WriteRootfsDir(tarWriter *tar.Writer) error { hdr := getGenericTarHeader() hdr.Name = "rootfs" hdr.Mode = 0755 hdr.Size = int64(0) hdr.Typeflag = tar.TypeDir return tarWriter.WriteHeader(hdr) }
go
func WriteRootfsDir(tarWriter *tar.Writer) error { hdr := getGenericTarHeader() hdr.Name = "rootfs" hdr.Mode = 0755 hdr.Size = int64(0) hdr.Typeflag = tar.TypeDir return tarWriter.WriteHeader(hdr) }
[ "func", "WriteRootfsDir", "(", "tarWriter", "*", "tar", ".", "Writer", ")", "error", "{", "hdr", ":=", "getGenericTarHeader", "(", ")", "\n", "hdr", ".", "Name", "=", "\"", "\"", "\n", "hdr", ".", "Mode", "=", "0755", "\n", "hdr", ".", "Size", "=", "int64", "(", "0", ")", "\n", "hdr", ".", "Typeflag", "=", "tar", ".", "TypeDir", "\n\n", "return", "tarWriter", ".", "WriteHeader", "(", "hdr", ")", "\n", "}" ]
// WriteRootfsDir writes a "rootfs" dir entry on a tar.Writer.
[ "WriteRootfsDir", "writes", "a", "rootfs", "dir", "entry", "on", "a", "tar", ".", "Writer", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/internal/internal.go#L766-L774
15,095
appc/docker2aci
lib/docker2aci.go
GetIndexName
func GetIndexName(dockerURL string) string { index, _ := docker.SplitReposName(dockerURL) return index }
go
func GetIndexName(dockerURL string) string { index, _ := docker.SplitReposName(dockerURL) return index }
[ "func", "GetIndexName", "(", "dockerURL", "string", ")", "string", "{", "index", ",", "_", ":=", "docker", ".", "SplitReposName", "(", "dockerURL", ")", "\n", "return", "index", "\n", "}" ]
// GetIndexName returns the docker index server from a docker URL.
[ "GetIndexName", "returns", "the", "docker", "index", "server", "from", "a", "docker", "URL", "." ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/docker2aci.go#L130-L133
15,096
appc/docker2aci
lib/docker2aci.go
squashLayers
func squashLayers(images []acirenderer.Image, aciRegistry acirenderer.ACIRegistry, parsedDockerURL common.ParsedDockerURL, outputDir string, compression common.Compression, debug log.Logger) (path string, err error) { debug.Println("Squashing layers...") debug.Println("Rendering ACI...") renderedACI, err := acirenderer.GetRenderedACIFromList(images, aciRegistry) if err != nil { return "", fmt.Errorf("error rendering squashed image: %v", err) } manifests, err := getManifests(renderedACI, aciRegistry) if err != nil { return "", fmt.Errorf("error getting manifests: %v", err) } squashedFilename := getSquashedFilename(parsedDockerURL) squashedImagePath := filepath.Join(outputDir, squashedFilename) squashedTempFile, err := ioutil.TempFile(outputDir, "docker2aci-squashedFile-") if err != nil { return "", err } defer func() { if err == nil { err = squashedTempFile.Close() } else { // remove temp file on error // we ignore its error to not mask the real error os.Remove(squashedTempFile.Name()) } }() debug.Println("Writing squashed ACI...") if err := writeSquashedImage(squashedTempFile, renderedACI, aciRegistry, manifests, compression); err != nil { return "", fmt.Errorf("error writing squashed image: %v", err) } debug.Println("Validating squashed ACI...") if err := internal.ValidateACI(squashedTempFile.Name()); err != nil { return "", fmt.Errorf("error validating image: %v", err) } if err := os.Rename(squashedTempFile.Name(), squashedImagePath); err != nil { return "", err } debug.Println("ACI squashed!") return squashedImagePath, nil }
go
func squashLayers(images []acirenderer.Image, aciRegistry acirenderer.ACIRegistry, parsedDockerURL common.ParsedDockerURL, outputDir string, compression common.Compression, debug log.Logger) (path string, err error) { debug.Println("Squashing layers...") debug.Println("Rendering ACI...") renderedACI, err := acirenderer.GetRenderedACIFromList(images, aciRegistry) if err != nil { return "", fmt.Errorf("error rendering squashed image: %v", err) } manifests, err := getManifests(renderedACI, aciRegistry) if err != nil { return "", fmt.Errorf("error getting manifests: %v", err) } squashedFilename := getSquashedFilename(parsedDockerURL) squashedImagePath := filepath.Join(outputDir, squashedFilename) squashedTempFile, err := ioutil.TempFile(outputDir, "docker2aci-squashedFile-") if err != nil { return "", err } defer func() { if err == nil { err = squashedTempFile.Close() } else { // remove temp file on error // we ignore its error to not mask the real error os.Remove(squashedTempFile.Name()) } }() debug.Println("Writing squashed ACI...") if err := writeSquashedImage(squashedTempFile, renderedACI, aciRegistry, manifests, compression); err != nil { return "", fmt.Errorf("error writing squashed image: %v", err) } debug.Println("Validating squashed ACI...") if err := internal.ValidateACI(squashedTempFile.Name()); err != nil { return "", fmt.Errorf("error validating image: %v", err) } if err := os.Rename(squashedTempFile.Name(), squashedImagePath); err != nil { return "", err } debug.Println("ACI squashed!") return squashedImagePath, nil }
[ "func", "squashLayers", "(", "images", "[", "]", "acirenderer", ".", "Image", ",", "aciRegistry", "acirenderer", ".", "ACIRegistry", ",", "parsedDockerURL", "common", ".", "ParsedDockerURL", ",", "outputDir", "string", ",", "compression", "common", ".", "Compression", ",", "debug", "log", ".", "Logger", ")", "(", "path", "string", ",", "err", "error", ")", "{", "debug", ".", "Println", "(", "\"", "\"", ")", "\n", "debug", ".", "Println", "(", "\"", "\"", ")", "\n", "renderedACI", ",", "err", ":=", "acirenderer", ".", "GetRenderedACIFromList", "(", "images", ",", "aciRegistry", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "manifests", ",", "err", ":=", "getManifests", "(", "renderedACI", ",", "aciRegistry", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "squashedFilename", ":=", "getSquashedFilename", "(", "parsedDockerURL", ")", "\n", "squashedImagePath", ":=", "filepath", ".", "Join", "(", "outputDir", ",", "squashedFilename", ")", "\n\n", "squashedTempFile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "outputDir", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "err", "==", "nil", "{", "err", "=", "squashedTempFile", ".", "Close", "(", ")", "\n", "}", "else", "{", "// remove temp file on error", "// we ignore its error to not mask the real error", "os", ".", "Remove", "(", "squashedTempFile", ".", "Name", "(", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "debug", ".", "Println", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "writeSquashedImage", "(", "squashedTempFile", ",", "renderedACI", ",", "aciRegistry", ",", "manifests", ",", "compression", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "debug", ".", "Println", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "internal", ".", "ValidateACI", "(", "squashedTempFile", ".", "Name", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "Rename", "(", "squashedTempFile", ".", "Name", "(", ")", ",", "squashedImagePath", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "debug", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "squashedImagePath", ",", "nil", "\n", "}" ]
// squashLayers receives a list of ACI layer file names ordered from base image // to application image and squashes them into one ACI
[ "squashLayers", "receives", "a", "list", "of", "ACI", "layer", "file", "names", "ordered", "from", "base", "image", "to", "application", "image", "and", "squashes", "them", "into", "one", "ACI" ]
248258bd708afc51c1aa0f9e8b826c50d1ce66a8
https://github.com/appc/docker2aci/blob/248258bd708afc51c1aa0f9e8b826c50d1ce66a8/lib/docker2aci.go#L209-L254
15,097
blevesearch/segment
segment.go
NewSegmenter
func NewSegmenter(r io.Reader) *Segmenter { return &Segmenter{ r: r, segment: SegmentWords, maxTokenSize: MaxScanTokenSize, buf: make([]byte, 4096), // Plausible starting size; needn't be large. } }
go
func NewSegmenter(r io.Reader) *Segmenter { return &Segmenter{ r: r, segment: SegmentWords, maxTokenSize: MaxScanTokenSize, buf: make([]byte, 4096), // Plausible starting size; needn't be large. } }
[ "func", "NewSegmenter", "(", "r", "io", ".", "Reader", ")", "*", "Segmenter", "{", "return", "&", "Segmenter", "{", "r", ":", "r", ",", "segment", ":", "SegmentWords", ",", "maxTokenSize", ":", "MaxScanTokenSize", ",", "buf", ":", "make", "(", "[", "]", "byte", ",", "4096", ")", ",", "// Plausible starting size; needn't be large.", "}", "\n", "}" ]
// NewSegmenter returns a new Segmenter to read from r. // Defaults to segment using SegmentWords
[ "NewSegmenter", "returns", "a", "new", "Segmenter", "to", "read", "from", "r", ".", "Defaults", "to", "segment", "using", "SegmentWords" ]
762005e7a34fd909a84586299f1dd457371d36ee
https://github.com/blevesearch/segment/blob/762005e7a34fd909a84586299f1dd457371d36ee/segment.go#L73-L80
15,098
blevesearch/segment
segment.go
NewSegmenterDirect
func NewSegmenterDirect(buf []byte) *Segmenter { return &Segmenter{ segment: SegmentWords, maxTokenSize: MaxScanTokenSize, buf: buf, start: 0, end: len(buf), err: io.EOF, } }
go
func NewSegmenterDirect(buf []byte) *Segmenter { return &Segmenter{ segment: SegmentWords, maxTokenSize: MaxScanTokenSize, buf: buf, start: 0, end: len(buf), err: io.EOF, } }
[ "func", "NewSegmenterDirect", "(", "buf", "[", "]", "byte", ")", "*", "Segmenter", "{", "return", "&", "Segmenter", "{", "segment", ":", "SegmentWords", ",", "maxTokenSize", ":", "MaxScanTokenSize", ",", "buf", ":", "buf", ",", "start", ":", "0", ",", "end", ":", "len", "(", "buf", ")", ",", "err", ":", "io", ".", "EOF", ",", "}", "\n", "}" ]
// NewSegmenterDirect returns a new Segmenter to work directly with buf. // Defaults to segment using SegmentWords
[ "NewSegmenterDirect", "returns", "a", "new", "Segmenter", "to", "work", "directly", "with", "buf", ".", "Defaults", "to", "segment", "using", "SegmentWords" ]
762005e7a34fd909a84586299f1dd457371d36ee
https://github.com/blevesearch/segment/blob/762005e7a34fd909a84586299f1dd457371d36ee/segment.go#L84-L93
15,099
blevesearch/segment
segment.go
Err
func (s *Segmenter) Err() error { if s.err == io.EOF { return nil } return s.err }
go
func (s *Segmenter) Err() error { if s.err == io.EOF { return nil } return s.err }
[ "func", "(", "s", "*", "Segmenter", ")", "Err", "(", ")", "error", "{", "if", "s", ".", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "err", "\n", "}" ]
// Err returns the first non-EOF error that was encountered by the Segmenter.
[ "Err", "returns", "the", "first", "non", "-", "EOF", "error", "that", "was", "encountered", "by", "the", "Segmenter", "." ]
762005e7a34fd909a84586299f1dd457371d36ee
https://github.com/blevesearch/segment/blob/762005e7a34fd909a84586299f1dd457371d36ee/segment.go#L155-L160