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
|
---|---|---|---|---|---|---|---|---|---|---|---|
14,900 | goware/emailx | emailx.go | Validate | func Validate(email string) error {
if len(email) < 6 || len(email) > 254 {
return ErrInvalidFormat
}
at := strings.LastIndex(email, "@")
if at <= 0 || at > len(email)-3 {
return ErrInvalidFormat
}
user := email[:at]
host := email[at+1:]
if len(user) > 64 {
return ErrInvalidFormat
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return ErrInvalidFormat
}
switch host {
case "localhost", "example.com":
return nil
}
if _, err := net.LookupMX(host); err != nil {
if _, err := net.LookupIP(host); err != nil {
// Only fail if both MX and A records are missing - any of the
// two is enough for an email to be deliverable
return ErrUnresolvableHost
}
}
return nil
} | go | func Validate(email string) error {
if len(email) < 6 || len(email) > 254 {
return ErrInvalidFormat
}
at := strings.LastIndex(email, "@")
if at <= 0 || at > len(email)-3 {
return ErrInvalidFormat
}
user := email[:at]
host := email[at+1:]
if len(user) > 64 {
return ErrInvalidFormat
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return ErrInvalidFormat
}
switch host {
case "localhost", "example.com":
return nil
}
if _, err := net.LookupMX(host); err != nil {
if _, err := net.LookupIP(host); err != nil {
// Only fail if both MX and A records are missing - any of the
// two is enough for an email to be deliverable
return ErrUnresolvableHost
}
}
return nil
} | [
"func",
"Validate",
"(",
"email",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"email",
")",
"<",
"6",
"||",
"len",
"(",
"email",
")",
">",
"254",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"at",
":=",
"strings",
".",
"LastIndex",
"(",
"email",
",",
"\"",
"\"",
")",
"\n",
"if",
"at",
"<=",
"0",
"||",
"at",
">",
"len",
"(",
"email",
")",
"-",
"3",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"user",
":=",
"email",
"[",
":",
"at",
"]",
"\n",
"host",
":=",
"email",
"[",
"at",
"+",
"1",
":",
"]",
"\n\n",
"if",
"len",
"(",
"user",
")",
">",
"64",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n",
"if",
"userDotRegexp",
".",
"MatchString",
"(",
"user",
")",
"||",
"!",
"userRegexp",
".",
"MatchString",
"(",
"user",
")",
"||",
"!",
"hostRegexp",
".",
"MatchString",
"(",
"host",
")",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"switch",
"host",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"net",
".",
"LookupMX",
"(",
"host",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"err",
":=",
"net",
".",
"LookupIP",
"(",
"host",
")",
";",
"err",
"!=",
"nil",
"{",
"// Only fail if both MX and A records are missing - any of the",
"// two is enough for an email to be deliverable",
"return",
"ErrUnresolvableHost",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks format of a given email and resolves its host name. | [
"Validate",
"checks",
"format",
"of",
"a",
"given",
"email",
"and",
"resolves",
"its",
"host",
"name",
"."
] | 80a00e4677ff2f102e17b78107f255253e2032e5 | https://github.com/goware/emailx/blob/80a00e4677ff2f102e17b78107f255253e2032e5/emailx.go#L24-L58 |
14,901 | goware/emailx | emailx.go | ValidateFast | func ValidateFast(email string) error {
if len(email) < 6 || len(email) > 254 {
return ErrInvalidFormat
}
at := strings.LastIndex(email, "@")
if at <= 0 || at > len(email)-3 {
return ErrInvalidFormat
}
user := email[:at]
host := email[at+1:]
if len(user) > 64 {
return ErrInvalidFormat
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return ErrInvalidFormat
}
return nil
} | go | func ValidateFast(email string) error {
if len(email) < 6 || len(email) > 254 {
return ErrInvalidFormat
}
at := strings.LastIndex(email, "@")
if at <= 0 || at > len(email)-3 {
return ErrInvalidFormat
}
user := email[:at]
host := email[at+1:]
if len(user) > 64 {
return ErrInvalidFormat
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return ErrInvalidFormat
}
return nil
} | [
"func",
"ValidateFast",
"(",
"email",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"email",
")",
"<",
"6",
"||",
"len",
"(",
"email",
")",
">",
"254",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"at",
":=",
"strings",
".",
"LastIndex",
"(",
"email",
",",
"\"",
"\"",
")",
"\n",
"if",
"at",
"<=",
"0",
"||",
"at",
">",
"len",
"(",
"email",
")",
"-",
"3",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"user",
":=",
"email",
"[",
":",
"at",
"]",
"\n",
"host",
":=",
"email",
"[",
"at",
"+",
"1",
":",
"]",
"\n\n",
"if",
"len",
"(",
"user",
")",
">",
"64",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n",
"if",
"userDotRegexp",
".",
"MatchString",
"(",
"user",
")",
"||",
"!",
"userRegexp",
".",
"MatchString",
"(",
"user",
")",
"||",
"!",
"hostRegexp",
".",
"MatchString",
"(",
"host",
")",
"{",
"return",
"ErrInvalidFormat",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // ValidateFast checks format of a given email. | [
"ValidateFast",
"checks",
"format",
"of",
"a",
"given",
"email",
"."
] | 80a00e4677ff2f102e17b78107f255253e2032e5 | https://github.com/goware/emailx/blob/80a00e4677ff2f102e17b78107f255253e2032e5/emailx.go#L61-L82 |
14,902 | goware/emailx | emailx.go | Normalize | func Normalize(email string) string {
// Trim whitespaces.
email = strings.TrimSpace(email)
// Trim extra dot in hostname.
email = strings.TrimRight(email, ".")
// Lowercase.
email = strings.ToLower(email)
return email
} | go | func Normalize(email string) string {
// Trim whitespaces.
email = strings.TrimSpace(email)
// Trim extra dot in hostname.
email = strings.TrimRight(email, ".")
// Lowercase.
email = strings.ToLower(email)
return email
} | [
"func",
"Normalize",
"(",
"email",
"string",
")",
"string",
"{",
"// Trim whitespaces.",
"email",
"=",
"strings",
".",
"TrimSpace",
"(",
"email",
")",
"\n\n",
"// Trim extra dot in hostname.",
"email",
"=",
"strings",
".",
"TrimRight",
"(",
"email",
",",
"\"",
"\"",
")",
"\n\n",
"// Lowercase.",
"email",
"=",
"strings",
".",
"ToLower",
"(",
"email",
")",
"\n\n",
"return",
"email",
"\n",
"}"
] | // Normalize normalizes email address. | [
"Normalize",
"normalizes",
"email",
"address",
"."
] | 80a00e4677ff2f102e17b78107f255253e2032e5 | https://github.com/goware/emailx/blob/80a00e4677ff2f102e17b78107f255253e2032e5/emailx.go#L85-L96 |
14,903 | wader/gormstore | gormstore.go | New | func New(db *gorm.DB, keyPairs ...[]byte) *Store {
return NewOptions(db, Options{}, keyPairs...)
} | go | func New(db *gorm.DB, keyPairs ...[]byte) *Store {
return NewOptions(db, Options{}, keyPairs...)
} | [
"func",
"New",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"keyPairs",
"...",
"[",
"]",
"byte",
")",
"*",
"Store",
"{",
"return",
"NewOptions",
"(",
"db",
",",
"Options",
"{",
"}",
",",
"keyPairs",
"...",
")",
"\n",
"}"
] | // New creates a new gormstore session | [
"New",
"creates",
"a",
"new",
"gormstore",
"session"
] | acb787ba37557045dc3da46414b50233d49df8bf | https://github.com/wader/gormstore/blob/acb787ba37557045dc3da46414b50233d49df8bf/gormstore.go#L84-L86 |
14,904 | wader/gormstore | gormstore.go | NewOptions | func NewOptions(db *gorm.DB, opts Options, keyPairs ...[]byte) *Store {
st := &Store{
db: db,
opts: opts,
Codecs: securecookie.CodecsFromPairs(keyPairs...),
SessionOpts: &sessions.Options{
Path: defaultPath,
MaxAge: defaultMaxAge,
},
}
if st.opts.TableName == "" {
st.opts.TableName = defaultTableName
}
if !st.opts.SkipCreateTable {
st.db.AutoMigrate(&gormSession{tableName: st.opts.TableName})
}
return st
} | go | func NewOptions(db *gorm.DB, opts Options, keyPairs ...[]byte) *Store {
st := &Store{
db: db,
opts: opts,
Codecs: securecookie.CodecsFromPairs(keyPairs...),
SessionOpts: &sessions.Options{
Path: defaultPath,
MaxAge: defaultMaxAge,
},
}
if st.opts.TableName == "" {
st.opts.TableName = defaultTableName
}
if !st.opts.SkipCreateTable {
st.db.AutoMigrate(&gormSession{tableName: st.opts.TableName})
}
return st
} | [
"func",
"NewOptions",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"opts",
"Options",
",",
"keyPairs",
"...",
"[",
"]",
"byte",
")",
"*",
"Store",
"{",
"st",
":=",
"&",
"Store",
"{",
"db",
":",
"db",
",",
"opts",
":",
"opts",
",",
"Codecs",
":",
"securecookie",
".",
"CodecsFromPairs",
"(",
"keyPairs",
"...",
")",
",",
"SessionOpts",
":",
"&",
"sessions",
".",
"Options",
"{",
"Path",
":",
"defaultPath",
",",
"MaxAge",
":",
"defaultMaxAge",
",",
"}",
",",
"}",
"\n",
"if",
"st",
".",
"opts",
".",
"TableName",
"==",
"\"",
"\"",
"{",
"st",
".",
"opts",
".",
"TableName",
"=",
"defaultTableName",
"\n",
"}",
"\n\n",
"if",
"!",
"st",
".",
"opts",
".",
"SkipCreateTable",
"{",
"st",
".",
"db",
".",
"AutoMigrate",
"(",
"&",
"gormSession",
"{",
"tableName",
":",
"st",
".",
"opts",
".",
"TableName",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"st",
"\n",
"}"
] | // NewOptions creates a new gormstore session with options | [
"NewOptions",
"creates",
"a",
"new",
"gormstore",
"session",
"with",
"options"
] | acb787ba37557045dc3da46414b50233d49df8bf | https://github.com/wader/gormstore/blob/acb787ba37557045dc3da46414b50233d49df8bf/gormstore.go#L89-L108 |
14,905 | wader/gormstore | gormstore.go | Get | func (st *Store) Get(r *http.Request, name string) (*sessions.Session, error) {
return sessions.GetRegistry(r).Get(st, name)
} | go | func (st *Store) Get(r *http.Request, name string) (*sessions.Session, error) {
return sessions.GetRegistry(r).Get(st, name)
} | [
"func",
"(",
"st",
"*",
"Store",
")",
"Get",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"name",
"string",
")",
"(",
"*",
"sessions",
".",
"Session",
",",
"error",
")",
"{",
"return",
"sessions",
".",
"GetRegistry",
"(",
"r",
")",
".",
"Get",
"(",
"st",
",",
"name",
")",
"\n",
"}"
] | // Get returns a session for the given name after adding it to the registry. | [
"Get",
"returns",
"a",
"session",
"for",
"the",
"given",
"name",
"after",
"adding",
"it",
"to",
"the",
"registry",
"."
] | acb787ba37557045dc3da46414b50233d49df8bf | https://github.com/wader/gormstore/blob/acb787ba37557045dc3da46414b50233d49df8bf/gormstore.go#L111-L113 |
14,906 | wader/gormstore | gormstore.go | PeriodicCleanup | func (st *Store) PeriodicCleanup(interval time.Duration, quit <-chan struct{}) {
t := time.NewTicker(interval)
defer t.Stop()
for {
select {
case <-t.C:
st.Cleanup()
case <-quit:
return
}
}
} | go | func (st *Store) PeriodicCleanup(interval time.Duration, quit <-chan struct{}) {
t := time.NewTicker(interval)
defer t.Stop()
for {
select {
case <-t.C:
st.Cleanup()
case <-quit:
return
}
}
} | [
"func",
"(",
"st",
"*",
"Store",
")",
"PeriodicCleanup",
"(",
"interval",
"time",
".",
"Duration",
",",
"quit",
"<-",
"chan",
"struct",
"{",
"}",
")",
"{",
"t",
":=",
"time",
".",
"NewTicker",
"(",
"interval",
")",
"\n",
"defer",
"t",
".",
"Stop",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"t",
".",
"C",
":",
"st",
".",
"Cleanup",
"(",
")",
"\n",
"case",
"<-",
"quit",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // PeriodicCleanup runs Cleanup every interval. Close quit channel to stop. | [
"PeriodicCleanup",
"runs",
"Cleanup",
"every",
"interval",
".",
"Close",
"quit",
"channel",
"to",
"stop",
"."
] | acb787ba37557045dc3da46414b50233d49df8bf | https://github.com/wader/gormstore/blob/acb787ba37557045dc3da46414b50233d49df8bf/gormstore.go#L229-L240 |
14,907 | azer/crud | fields.go | SetDefaultPK | func SetDefaultPK(fields []*Field) {
if HasPK(fields) {
return
}
for i, f := range fields {
if !f.SQL.IsPrimaryKey && f.SQL.Name == "id" && f.SQL.Type == "int" {
fields[i].SQL.IsAutoIncrementing = true
fields[i].SQL.AutoIncrement = 1
fields[i].SQL.IsRequired = true
fields[i].SQL.IsPrimaryKey = true
return
}
}
} | go | func SetDefaultPK(fields []*Field) {
if HasPK(fields) {
return
}
for i, f := range fields {
if !f.SQL.IsPrimaryKey && f.SQL.Name == "id" && f.SQL.Type == "int" {
fields[i].SQL.IsAutoIncrementing = true
fields[i].SQL.AutoIncrement = 1
fields[i].SQL.IsRequired = true
fields[i].SQL.IsPrimaryKey = true
return
}
}
} | [
"func",
"SetDefaultPK",
"(",
"fields",
"[",
"]",
"*",
"Field",
")",
"{",
"if",
"HasPK",
"(",
"fields",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"!",
"f",
".",
"SQL",
".",
"IsPrimaryKey",
"&&",
"f",
".",
"SQL",
".",
"Name",
"==",
"\"",
"\"",
"&&",
"f",
".",
"SQL",
".",
"Type",
"==",
"\"",
"\"",
"{",
"fields",
"[",
"i",
"]",
".",
"SQL",
".",
"IsAutoIncrementing",
"=",
"true",
"\n",
"fields",
"[",
"i",
"]",
".",
"SQL",
".",
"AutoIncrement",
"=",
"1",
"\n",
"fields",
"[",
"i",
"]",
".",
"SQL",
".",
"IsRequired",
"=",
"true",
"\n",
"fields",
"[",
"i",
"]",
".",
"SQL",
".",
"IsPrimaryKey",
"=",
"true",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // If no PK is specified, then set `id` to be PK. | [
"If",
"no",
"PK",
"is",
"specified",
"then",
"set",
"id",
"to",
"be",
"PK",
"."
] | 41b8d890fefaaf6fa14bda0548ee6096a0a164f3 | https://github.com/azer/crud/blob/41b8d890fefaaf6fa14bda0548ee6096a0a164f3/fields.go#L55-L69 |
14,908 | ansel1/merry | print.go | Location | func Location(e error) (file string, line int) {
s := Stack(e)
if len(s) > 0 {
fnc, _ := runtime.CallersFrames(s[:1]).Next()
return fnc.File, fnc.Line
}
return "", 0
} | go | func Location(e error) (file string, line int) {
s := Stack(e)
if len(s) > 0 {
fnc, _ := runtime.CallersFrames(s[:1]).Next()
return fnc.File, fnc.Line
}
return "", 0
} | [
"func",
"Location",
"(",
"e",
"error",
")",
"(",
"file",
"string",
",",
"line",
"int",
")",
"{",
"s",
":=",
"Stack",
"(",
"e",
")",
"\n",
"if",
"len",
"(",
"s",
")",
">",
"0",
"{",
"fnc",
",",
"_",
":=",
"runtime",
".",
"CallersFrames",
"(",
"s",
"[",
":",
"1",
"]",
")",
".",
"Next",
"(",
")",
"\n",
"return",
"fnc",
".",
"File",
",",
"fnc",
".",
"Line",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"0",
"\n",
"}"
] | // Location returns zero values if e has no stacktrace | [
"Location",
"returns",
"zero",
"values",
"if",
"e",
"has",
"no",
"stacktrace"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/print.go#L61-L68 |
14,909 | ansel1/merry | print.go | SourceLine | func SourceLine(e error) string {
file, line := Location(e)
if line != 0 {
return fmt.Sprintf("%s:%d", file, line)
}
return ""
} | go | func SourceLine(e error) string {
file, line := Location(e)
if line != 0 {
return fmt.Sprintf("%s:%d", file, line)
}
return ""
} | [
"func",
"SourceLine",
"(",
"e",
"error",
")",
"string",
"{",
"file",
",",
"line",
":=",
"Location",
"(",
"e",
")",
"\n",
"if",
"line",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"file",
",",
"line",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // SourceLine returns the string representation of
// Location's result or an empty string if there's
// no stracktrace. | [
"SourceLine",
"returns",
"the",
"string",
"representation",
"of",
"Location",
"s",
"result",
"or",
"an",
"empty",
"string",
"if",
"there",
"s",
"no",
"stracktrace",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/print.go#L73-L79 |
14,910 | ansel1/merry | print.go | Stacktrace | func Stacktrace(e error) string {
s := Stack(e)
if len(s) > 0 {
buf := bytes.Buffer{}
frames := runtime.CallersFrames(s)
for {
frame, more := frames.Next()
buf.WriteString(frame.Function)
buf.WriteString(fmt.Sprintf("\n\t%s:%d\n", frame.File, frame.Line))
if !more {
break
}
}
return buf.String()
}
return ""
} | go | func Stacktrace(e error) string {
s := Stack(e)
if len(s) > 0 {
buf := bytes.Buffer{}
frames := runtime.CallersFrames(s)
for {
frame, more := frames.Next()
buf.WriteString(frame.Function)
buf.WriteString(fmt.Sprintf("\n\t%s:%d\n", frame.File, frame.Line))
if !more {
break
}
}
return buf.String()
}
return ""
} | [
"func",
"Stacktrace",
"(",
"e",
"error",
")",
"string",
"{",
"s",
":=",
"Stack",
"(",
"e",
")",
"\n",
"if",
"len",
"(",
"s",
")",
">",
"0",
"{",
"buf",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"frames",
":=",
"runtime",
".",
"CallersFrames",
"(",
"s",
")",
"\n",
"for",
"{",
"frame",
",",
"more",
":=",
"frames",
".",
"Next",
"(",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"frame",
".",
"Function",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\t",
"\\n",
"\"",
",",
"frame",
".",
"File",
",",
"frame",
".",
"Line",
")",
")",
"\n",
"if",
"!",
"more",
"{",
"break",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Stacktrace returns the error's stacktrace as a string formatted
// the same way as golangs runtime package.
// If e has no stacktrace, returns an empty string. | [
"Stacktrace",
"returns",
"the",
"error",
"s",
"stacktrace",
"as",
"a",
"string",
"formatted",
"the",
"same",
"way",
"as",
"golangs",
"runtime",
"package",
".",
"If",
"e",
"has",
"no",
"stacktrace",
"returns",
"an",
"empty",
"string",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/print.go#L84-L101 |
14,911 | ansel1/merry | errors.go | WithValue | func WithValue(e error, key, value interface{}) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithValue(key, value)
} | go | func WithValue(e error, key, value interface{}) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithValue(key, value)
} | [
"func",
"WithValue",
"(",
"e",
"error",
",",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"WrapSkipping",
"(",
"e",
",",
"1",
")",
".",
"WithValue",
"(",
"key",
",",
"value",
")",
"\n",
"}"
] | // WithValue adds a context an error. If the key was already set on e,
// the new value will take precedence.
// If e is nil, returns nil. | [
"WithValue",
"adds",
"a",
"context",
"an",
"error",
".",
"If",
"the",
"key",
"was",
"already",
"set",
"on",
"e",
"the",
"new",
"value",
"will",
"take",
"precedence",
".",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L144-L149 |
14,912 | ansel1/merry | errors.go | Value | func Value(e error, key interface{}) interface{} {
for {
switch m := e.(type) {
case nil:
return nil
case *merryErr:
if m.key == key {
return m.value
}
e = m.err
default:
return nil
}
}
} | go | func Value(e error, key interface{}) interface{} {
for {
switch m := e.(type) {
case nil:
return nil
case *merryErr:
if m.key == key {
return m.value
}
e = m.err
default:
return nil
}
}
} | [
"func",
"Value",
"(",
"e",
"error",
",",
"key",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"for",
"{",
"switch",
"m",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"nil",
"\n",
"case",
"*",
"merryErr",
":",
"if",
"m",
".",
"key",
"==",
"key",
"{",
"return",
"m",
".",
"value",
"\n",
"}",
"\n",
"e",
"=",
"m",
".",
"err",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Value returns the value for key, or nil if not set.
// If e is nil, returns nil. | [
"Value",
"returns",
"the",
"value",
"for",
"key",
"or",
"nil",
"if",
"not",
"set",
".",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L153-L167 |
14,913 | ansel1/merry | errors.go | Values | func Values(e error) map[interface{}]interface{} {
if e == nil {
return nil
}
var values map[interface{}]interface{}
for {
w, ok := e.(*merryErr)
if !ok {
return values
}
if values == nil {
values = make(map[interface{}]interface{}, 1)
}
if _, ok := values[w.key]; !ok {
values[w.key] = w.value
}
e = w.err
}
} | go | func Values(e error) map[interface{}]interface{} {
if e == nil {
return nil
}
var values map[interface{}]interface{}
for {
w, ok := e.(*merryErr)
if !ok {
return values
}
if values == nil {
values = make(map[interface{}]interface{}, 1)
}
if _, ok := values[w.key]; !ok {
values[w.key] = w.value
}
e = w.err
}
} | [
"func",
"Values",
"(",
"e",
"error",
")",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"values",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
"\n",
"for",
"{",
"w",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"merryErr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"values",
"\n",
"}",
"\n",
"if",
"values",
"==",
"nil",
"{",
"values",
"=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
",",
"1",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"values",
"[",
"w",
".",
"key",
"]",
";",
"!",
"ok",
"{",
"values",
"[",
"w",
".",
"key",
"]",
"=",
"w",
".",
"value",
"\n",
"}",
"\n",
"e",
"=",
"w",
".",
"err",
"\n",
"}",
"\n",
"}"
] | // Values returns a map of all values attached to the error
// If a key has been attached multiple times, the map will
// contain the last value mapped
// If e is nil, returns nil. | [
"Values",
"returns",
"a",
"map",
"of",
"all",
"values",
"attached",
"to",
"the",
"error",
"If",
"a",
"key",
"has",
"been",
"attached",
"multiple",
"times",
"the",
"map",
"will",
"contain",
"the",
"last",
"value",
"mapped",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L173-L191 |
14,914 | ansel1/merry | errors.go | Stack | func Stack(e error) []uintptr {
stack, _ := Value(e, stack).([]uintptr)
return stack
} | go | func Stack(e error) []uintptr {
stack, _ := Value(e, stack).([]uintptr)
return stack
} | [
"func",
"Stack",
"(",
"e",
"error",
")",
"[",
"]",
"uintptr",
"{",
"stack",
",",
"_",
":=",
"Value",
"(",
"e",
",",
"stack",
")",
".",
"(",
"[",
"]",
"uintptr",
")",
"\n",
"return",
"stack",
"\n",
"}"
] | // Stack returns the stack attached to an error, or nil if one is not attached
// If e is nil, returns nil. | [
"Stack",
"returns",
"the",
"stack",
"attached",
"to",
"an",
"error",
"or",
"nil",
"if",
"one",
"is",
"not",
"attached",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L216-L219 |
14,915 | ansel1/merry | errors.go | WithHTTPCode | func WithHTTPCode(e error, code int) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithHTTPCode(code)
} | go | func WithHTTPCode(e error, code int) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithHTTPCode(code)
} | [
"func",
"WithHTTPCode",
"(",
"e",
"error",
",",
"code",
"int",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"WrapSkipping",
"(",
"e",
",",
"1",
")",
".",
"WithHTTPCode",
"(",
"code",
")",
"\n",
"}"
] | // WithHTTPCode returns an error with an http code attached.
// If e is nil, returns nil. | [
"WithHTTPCode",
"returns",
"an",
"error",
"with",
"an",
"http",
"code",
"attached",
".",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L223-L228 |
14,916 | ansel1/merry | errors.go | HTTPCode | func HTTPCode(e error) int {
if e == nil {
return 200
}
code, _ := Value(e, httpCode).(int)
if code == 0 {
return 500
}
return code
} | go | func HTTPCode(e error) int {
if e == nil {
return 200
}
code, _ := Value(e, httpCode).(int)
if code == 0 {
return 500
}
return code
} | [
"func",
"HTTPCode",
"(",
"e",
"error",
")",
"int",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"200",
"\n",
"}",
"\n",
"code",
",",
"_",
":=",
"Value",
"(",
"e",
",",
"httpCode",
")",
".",
"(",
"int",
")",
"\n",
"if",
"code",
"==",
"0",
"{",
"return",
"500",
"\n",
"}",
"\n",
"return",
"code",
"\n",
"}"
] | // HTTPCode converts an error to an http status code. All errors
// map to 500, unless the error has an http code attached.
// If e is nil, returns 200. | [
"HTTPCode",
"converts",
"an",
"error",
"to",
"an",
"http",
"status",
"code",
".",
"All",
"errors",
"map",
"to",
"500",
"unless",
"the",
"error",
"has",
"an",
"http",
"code",
"attached",
".",
"If",
"e",
"is",
"nil",
"returns",
"200",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L233-L242 |
14,917 | ansel1/merry | errors.go | UserMessage | func UserMessage(e error) string {
if e == nil {
return ""
}
msg, _ := Value(e, userMessage).(string)
return msg
} | go | func UserMessage(e error) string {
if e == nil {
return ""
}
msg, _ := Value(e, userMessage).(string)
return msg
} | [
"func",
"UserMessage",
"(",
"e",
"error",
")",
"string",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"msg",
",",
"_",
":=",
"Value",
"(",
"e",
",",
"userMessage",
")",
".",
"(",
"string",
")",
"\n",
"return",
"msg",
"\n",
"}"
] | // UserMessage returns the end-user safe message. Returns empty if not set.
// If e is nil, returns "". | [
"UserMessage",
"returns",
"the",
"end",
"-",
"user",
"safe",
"message",
".",
"Returns",
"empty",
"if",
"not",
"set",
".",
"If",
"e",
"is",
"nil",
"returns",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L246-L252 |
14,918 | ansel1/merry | errors.go | Cause | func Cause(e error) error {
if e == nil {
return nil
}
c, _ := Value(e, cause).(error)
return c
} | go | func Cause(e error) error {
if e == nil {
return nil
}
c, _ := Value(e, cause).(error)
return c
} | [
"func",
"Cause",
"(",
"e",
"error",
")",
"error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"c",
",",
"_",
":=",
"Value",
"(",
"e",
",",
"cause",
")",
".",
"(",
"error",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Cause returns the cause of the argument. If e is nil, or has no cause,
// nil is returned. | [
"Cause",
"returns",
"the",
"cause",
"of",
"the",
"argument",
".",
"If",
"e",
"is",
"nil",
"or",
"has",
"no",
"cause",
"nil",
"is",
"returned",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L277-L283 |
14,919 | ansel1/merry | errors.go | WithCause | func WithCause(e error, cause error) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithCause(cause)
} | go | func WithCause(e error, cause error) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithCause(cause)
} | [
"func",
"WithCause",
"(",
"e",
"error",
",",
"cause",
"error",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"WrapSkipping",
"(",
"e",
",",
"1",
")",
".",
"WithCause",
"(",
"cause",
")",
"\n",
"}"
] | // WithCause returns an error based on the first argument, with the cause
// set to the second argument. If e is nil, returns nil. | [
"WithCause",
"returns",
"an",
"error",
"based",
"on",
"the",
"first",
"argument",
"with",
"the",
"cause",
"set",
"to",
"the",
"second",
"argument",
".",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L304-L309 |
14,920 | ansel1/merry | errors.go | WithUserMessage | func WithUserMessage(e error, msg string) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithUserMessage(msg)
} | go | func WithUserMessage(e error, msg string) Error {
if e == nil {
return nil
}
return WrapSkipping(e, 1).WithUserMessage(msg)
} | [
"func",
"WithUserMessage",
"(",
"e",
"error",
",",
"msg",
"string",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"WrapSkipping",
"(",
"e",
",",
"1",
")",
".",
"WithUserMessage",
"(",
"msg",
")",
"\n",
"}"
] | // WithUserMessage adds a message which is suitable for end users to see.
// If e is nil, returns nil. | [
"WithUserMessage",
"adds",
"a",
"message",
"which",
"is",
"suitable",
"for",
"end",
"users",
"to",
"see",
".",
"If",
"e",
"is",
"nil",
"returns",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L332-L337 |
14,921 | ansel1/merry | errors.go | Unwrap | func Unwrap(e error) error {
if e == nil {
return nil
}
for {
w, ok := e.(*merryErr)
if !ok {
return e
}
e = w.err
}
} | go | func Unwrap(e error) error {
if e == nil {
return nil
}
for {
w, ok := e.(*merryErr)
if !ok {
return e
}
e = w.err
}
} | [
"func",
"Unwrap",
"(",
"e",
"error",
")",
"error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"{",
"w",
",",
"ok",
":=",
"e",
".",
"(",
"*",
"merryErr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"e",
"\n",
"}",
"\n",
"e",
"=",
"w",
".",
"err",
"\n",
"}",
"\n",
"}"
] | // Unwrap returns the innermost underlying error.
// Only useful in advanced cases, like if you need to
// cast the underlying error to some type to get
// additional information from it.
// If e == nil, return nil. | [
"Unwrap",
"returns",
"the",
"innermost",
"underlying",
"error",
".",
"Only",
"useful",
"in",
"advanced",
"cases",
"like",
"if",
"you",
"need",
"to",
"cast",
"the",
"underlying",
"error",
"to",
"some",
"type",
"to",
"get",
"additional",
"information",
"from",
"it",
".",
"If",
"e",
"==",
"nil",
"return",
"nil",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L446-L457 |
14,922 | ansel1/merry | errors.go | Error | func (e *merryErr) Error() string {
if verbose {
return Details(e)
}
m := Message(e)
if m == "" {
m = UserMessage(e)
}
// add cause
if c := Cause(e); c != nil {
if ce := c.Error(); ce != "" {
m += ": " + ce
}
}
return m
} | go | func (e *merryErr) Error() string {
if verbose {
return Details(e)
}
m := Message(e)
if m == "" {
m = UserMessage(e)
}
// add cause
if c := Cause(e); c != nil {
if ce := c.Error(); ce != "" {
m += ": " + ce
}
}
return m
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"verbose",
"{",
"return",
"Details",
"(",
"e",
")",
"\n",
"}",
"\n",
"m",
":=",
"Message",
"(",
"e",
")",
"\n",
"if",
"m",
"==",
"\"",
"\"",
"{",
"m",
"=",
"UserMessage",
"(",
"e",
")",
"\n",
"}",
"\n",
"// add cause",
"if",
"c",
":=",
"Cause",
"(",
"e",
")",
";",
"c",
"!=",
"nil",
"{",
"if",
"ce",
":=",
"c",
".",
"Error",
"(",
")",
";",
"ce",
"!=",
"\"",
"\"",
"{",
"m",
"+=",
"\"",
"\"",
"+",
"ce",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] | // Error implements golang's error interface
// returns the message value if set, otherwise
// delegates to inner error | [
"Error",
"implements",
"golang",
"s",
"error",
"interface",
"returns",
"the",
"message",
"value",
"if",
"set",
"otherwise",
"delegates",
"to",
"inner",
"error"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L505-L520 |
14,923 | ansel1/merry | errors.go | WithValue | func (e *merryErr) WithValue(key, value interface{}) Error {
if e == nil {
return nil
}
return &merryErr{
err: e,
key: key,
value: value,
}
} | go | func (e *merryErr) WithValue(key, value interface{}) Error {
if e == nil {
return nil
}
return &merryErr{
err: e,
key: key,
value: value,
}
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithValue",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"merryErr",
"{",
"err",
":",
"e",
",",
"key",
":",
"key",
",",
"value",
":",
"value",
",",
"}",
"\n",
"}"
] | // return a new error with additional context | [
"return",
"a",
"new",
"error",
"with",
"additional",
"context"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L523-L532 |
14,924 | ansel1/merry | errors.go | WithStackSkipping | func (e *merryErr) WithStackSkipping(skip int) Error {
if e == nil {
return nil
}
return &merryErr{
err: e,
key: stack,
value: captureStack(skip + 1),
}
} | go | func (e *merryErr) WithStackSkipping(skip int) Error {
if e == nil {
return nil
}
return &merryErr{
err: e,
key: stack,
value: captureStack(skip + 1),
}
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithStackSkipping",
"(",
"skip",
"int",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"merryErr",
"{",
"err",
":",
"e",
",",
"key",
":",
"stack",
",",
"value",
":",
"captureStack",
"(",
"skip",
"+",
"1",
")",
",",
"}",
"\n",
"}"
] | // return a new error with a new stack capture | [
"return",
"a",
"new",
"error",
"with",
"a",
"new",
"stack",
"capture"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L543-L552 |
14,925 | ansel1/merry | errors.go | WithHTTPCode | func (e *merryErr) WithHTTPCode(code int) Error {
if e == nil {
return nil
}
return e.WithValue(httpCode, code)
} | go | func (e *merryErr) WithHTTPCode(code int) Error {
if e == nil {
return nil
}
return e.WithValue(httpCode, code)
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithHTTPCode",
"(",
"code",
"int",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"WithValue",
"(",
"httpCode",
",",
"code",
")",
"\n",
"}"
] | // return a new error with an http status code attached | [
"return",
"a",
"new",
"error",
"with",
"an",
"http",
"status",
"code",
"attached"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L555-L560 |
14,926 | ansel1/merry | errors.go | WithMessage | func (e *merryErr) WithMessage(msg string) Error {
if e == nil {
return nil
}
return e.WithValue(message, msg)
} | go | func (e *merryErr) WithMessage(msg string) Error {
if e == nil {
return nil
}
return e.WithValue(message, msg)
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithMessage",
"(",
"msg",
"string",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"WithValue",
"(",
"message",
",",
"msg",
")",
"\n",
"}"
] | // return a new error with a new message | [
"return",
"a",
"new",
"error",
"with",
"a",
"new",
"message"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L563-L568 |
14,927 | ansel1/merry | errors.go | WithMessagef | func (e *merryErr) WithMessagef(format string, a ...interface{}) Error {
if e == nil {
return nil
}
return e.WithMessage(fmt.Sprintf(format, a...))
} | go | func (e *merryErr) WithMessagef(format string, a ...interface{}) Error {
if e == nil {
return nil
}
return e.WithMessage(fmt.Sprintf(format, a...))
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithMessagef",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"WithMessage",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"a",
"...",
")",
")",
"\n",
"}"
] | // return a new error with a new formatted message | [
"return",
"a",
"new",
"error",
"with",
"a",
"new",
"formatted",
"message"
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L571-L576 |
14,928 | ansel1/merry | errors.go | WithCause | func (e *merryErr) WithCause(err error) Error {
if e == nil || err == nil {
return e
}
return e.WithValue(cause, err)
} | go | func (e *merryErr) WithCause(err error) Error {
if e == nil || err == nil {
return e
}
return e.WithValue(cause, err)
} | [
"func",
"(",
"e",
"*",
"merryErr",
")",
"WithCause",
"(",
"err",
"error",
")",
"Error",
"{",
"if",
"e",
"==",
"nil",
"||",
"err",
"==",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n",
"return",
"e",
".",
"WithValue",
"(",
"cause",
",",
"err",
")",
"\n",
"}"
] | // WithCause returns an error based on the receiver, with the cause
// set to the argument. | [
"WithCause",
"returns",
"an",
"error",
"based",
"on",
"the",
"receiver",
"with",
"the",
"cause",
"set",
"to",
"the",
"argument",
"."
] | 4db5a8dcd6e777f88c88819528382e5b1490a1ba | https://github.com/ansel1/merry/blob/4db5a8dcd6e777f88c88819528382e5b1490a1ba/errors.go#L628-L633 |
14,929 | containerd/fifo | raw.go | SyscallConn | func (f *fifo) SyscallConn() (syscall.RawConn, error) {
// deterministic check for closed
select {
case <-f.closed:
return nil, errors.New("fifo closed")
default:
}
select {
case <-f.closed:
return nil, errors.New("fifo closed")
case <-f.opened:
return f.file.SyscallConn()
default:
}
// Not opened and not closed, this means open is non-blocking AND it's not open yet
// Use rawConn to deal with non-blocking open.
rc := &rawConn{f: f, ready: make(chan struct{})}
go func() {
select {
case <-f.closed:
return
case <-f.opened:
rc.raw, rc.err = f.file.SyscallConn()
close(rc.ready)
}
}()
return rc, nil
} | go | func (f *fifo) SyscallConn() (syscall.RawConn, error) {
// deterministic check for closed
select {
case <-f.closed:
return nil, errors.New("fifo closed")
default:
}
select {
case <-f.closed:
return nil, errors.New("fifo closed")
case <-f.opened:
return f.file.SyscallConn()
default:
}
// Not opened and not closed, this means open is non-blocking AND it's not open yet
// Use rawConn to deal with non-blocking open.
rc := &rawConn{f: f, ready: make(chan struct{})}
go func() {
select {
case <-f.closed:
return
case <-f.opened:
rc.raw, rc.err = f.file.SyscallConn()
close(rc.ready)
}
}()
return rc, nil
} | [
"func",
"(",
"f",
"*",
"fifo",
")",
"SyscallConn",
"(",
")",
"(",
"syscall",
".",
"RawConn",
",",
"error",
")",
"{",
"// deterministic check for closed",
"select",
"{",
"case",
"<-",
"f",
".",
"closed",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"}",
"\n\n",
"select",
"{",
"case",
"<-",
"f",
".",
"closed",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"<-",
"f",
".",
"opened",
":",
"return",
"f",
".",
"file",
".",
"SyscallConn",
"(",
")",
"\n",
"default",
":",
"}",
"\n\n",
"// Not opened and not closed, this means open is non-blocking AND it's not open yet",
"// Use rawConn to deal with non-blocking open.",
"rc",
":=",
"&",
"rawConn",
"{",
"f",
":",
"f",
",",
"ready",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"f",
".",
"closed",
":",
"return",
"\n",
"case",
"<-",
"f",
".",
"opened",
":",
"rc",
".",
"raw",
",",
"rc",
".",
"err",
"=",
"f",
".",
"file",
".",
"SyscallConn",
"(",
")",
"\n",
"close",
"(",
"rc",
".",
"ready",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"rc",
",",
"nil",
"\n",
"}"
] | // SyscallConn provides raw access to the fifo's underlying filedescrptor.
// See syscall.Conn for guarentees provided by this interface. | [
"SyscallConn",
"provides",
"raw",
"access",
"to",
"the",
"fifo",
"s",
"underlying",
"filedescrptor",
".",
"See",
"syscall",
".",
"Conn",
"for",
"guarentees",
"provided",
"by",
"this",
"interface",
"."
] | a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c | https://github.com/containerd/fifo/blob/a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c/raw.go#L29-L59 |
14,930 | biogo/hts | sam/program.go | NewProgram | func NewProgram(uid, name, command, prev, v string) *Program {
return &Program{
id: -1,
uid: uid,
previous: prev,
name: name,
command: command,
version: v,
}
} | go | func NewProgram(uid, name, command, prev, v string) *Program {
return &Program{
id: -1,
uid: uid,
previous: prev,
name: name,
command: command,
version: v,
}
} | [
"func",
"NewProgram",
"(",
"uid",
",",
"name",
",",
"command",
",",
"prev",
",",
"v",
"string",
")",
"*",
"Program",
"{",
"return",
"&",
"Program",
"{",
"id",
":",
"-",
"1",
",",
"uid",
":",
"uid",
",",
"previous",
":",
"prev",
",",
"name",
":",
"name",
",",
"command",
":",
"command",
",",
"version",
":",
"v",
",",
"}",
"\n",
"}"
] | // NewProgram returns a Program with the given unique ID, name, command,
// previous program ID in the pipeline and version. | [
"NewProgram",
"returns",
"a",
"Program",
"with",
"the",
"given",
"unique",
"ID",
"name",
"command",
"previous",
"program",
"ID",
"in",
"the",
"pipeline",
"and",
"version",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L27-L36 |
14,931 | biogo/hts | sam/program.go | SetUID | func (r *Program) SetUID(uid string) error {
if r.owner != nil {
id, exists := r.owner.seenProgs[uid]
if exists {
if id != r.id {
return errors.New("sam: uid exists")
}
return nil
}
delete(r.owner.seenProgs, r.uid)
r.owner.seenProgs[uid] = r.id
}
r.uid = uid
return nil
} | go | func (r *Program) SetUID(uid string) error {
if r.owner != nil {
id, exists := r.owner.seenProgs[uid]
if exists {
if id != r.id {
return errors.New("sam: uid exists")
}
return nil
}
delete(r.owner.seenProgs, r.uid)
r.owner.seenProgs[uid] = r.id
}
r.uid = uid
return nil
} | [
"func",
"(",
"r",
"*",
"Program",
")",
"SetUID",
"(",
"uid",
"string",
")",
"error",
"{",
"if",
"r",
".",
"owner",
"!=",
"nil",
"{",
"id",
",",
"exists",
":=",
"r",
".",
"owner",
".",
"seenProgs",
"[",
"uid",
"]",
"\n",
"if",
"exists",
"{",
"if",
"id",
"!=",
"r",
".",
"id",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"delete",
"(",
"r",
".",
"owner",
".",
"seenProgs",
",",
"r",
".",
"uid",
")",
"\n",
"r",
".",
"owner",
".",
"seenProgs",
"[",
"uid",
"]",
"=",
"r",
".",
"id",
"\n",
"}",
"\n",
"r",
".",
"uid",
"=",
"uid",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetUID sets the unique program ID to uid. | [
"SetUID",
"sets",
"the",
"unique",
"program",
"ID",
"to",
"uid",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L55-L69 |
14,932 | biogo/hts | sam/program.go | Clone | func (p *Program) Clone() *Program {
if p == nil {
return nil
}
cp := *p
if len(cp.otherTags) != 0 {
cp.otherTags = make([]tagPair, len(cp.otherTags))
}
copy(cp.otherTags, p.otherTags)
cp.id = -1
cp.owner = nil
return &cp
} | go | func (p *Program) Clone() *Program {
if p == nil {
return nil
}
cp := *p
if len(cp.otherTags) != 0 {
cp.otherTags = make([]tagPair, len(cp.otherTags))
}
copy(cp.otherTags, p.otherTags)
cp.id = -1
cp.owner = nil
return &cp
} | [
"func",
"(",
"p",
"*",
"Program",
")",
"Clone",
"(",
")",
"*",
"Program",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cp",
":=",
"*",
"p",
"\n",
"if",
"len",
"(",
"cp",
".",
"otherTags",
")",
"!=",
"0",
"{",
"cp",
".",
"otherTags",
"=",
"make",
"(",
"[",
"]",
"tagPair",
",",
"len",
"(",
"cp",
".",
"otherTags",
")",
")",
"\n",
"}",
"\n",
"copy",
"(",
"cp",
".",
"otherTags",
",",
"p",
".",
"otherTags",
")",
"\n",
"cp",
".",
"id",
"=",
"-",
"1",
"\n",
"cp",
".",
"owner",
"=",
"nil",
"\n",
"return",
"&",
"cp",
"\n",
"}"
] | // Clone returns a deep copy of the Program. | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"Program",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L104-L116 |
14,933 | biogo/hts | sam/program.go | Tags | func (p *Program) Tags(fn func(t Tag, value string)) {
if fn == nil {
return
}
fn(idTag, p.UID())
if p.name != "" {
fn(programNameTag, p.name)
}
if p.command != "" {
fn(commandLineTag, p.command)
}
if p.previous != "" {
fn(previousProgTag, p.previous)
}
if p.version != "" {
fn(versionTag, p.version)
}
for _, tp := range p.otherTags {
fn(tp.tag, tp.value)
}
} | go | func (p *Program) Tags(fn func(t Tag, value string)) {
if fn == nil {
return
}
fn(idTag, p.UID())
if p.name != "" {
fn(programNameTag, p.name)
}
if p.command != "" {
fn(commandLineTag, p.command)
}
if p.previous != "" {
fn(previousProgTag, p.previous)
}
if p.version != "" {
fn(versionTag, p.version)
}
for _, tp := range p.otherTags {
fn(tp.tag, tp.value)
}
} | [
"func",
"(",
"p",
"*",
"Program",
")",
"Tags",
"(",
"fn",
"func",
"(",
"t",
"Tag",
",",
"value",
"string",
")",
")",
"{",
"if",
"fn",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"fn",
"(",
"idTag",
",",
"p",
".",
"UID",
"(",
")",
")",
"\n",
"if",
"p",
".",
"name",
"!=",
"\"",
"\"",
"{",
"fn",
"(",
"programNameTag",
",",
"p",
".",
"name",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"command",
"!=",
"\"",
"\"",
"{",
"fn",
"(",
"commandLineTag",
",",
"p",
".",
"command",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"previous",
"!=",
"\"",
"\"",
"{",
"fn",
"(",
"previousProgTag",
",",
"p",
".",
"previous",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"version",
"!=",
"\"",
"\"",
"{",
"fn",
"(",
"versionTag",
",",
"p",
".",
"version",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"tp",
":=",
"range",
"p",
".",
"otherTags",
"{",
"fn",
"(",
"tp",
".",
"tag",
",",
"tp",
".",
"value",
")",
"\n",
"}",
"\n",
"}"
] | // Tags applies the function fn to each of the tag-value pairs of the Program.
// The function fn must not add or delete tags held by the receiver during
// iteration. | [
"Tags",
"applies",
"the",
"function",
"fn",
"to",
"each",
"of",
"the",
"tag",
"-",
"value",
"pairs",
"of",
"the",
"Program",
".",
"The",
"function",
"fn",
"must",
"not",
"add",
"or",
"delete",
"tags",
"held",
"by",
"the",
"receiver",
"during",
"iteration",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L121-L141 |
14,934 | biogo/hts | sam/program.go | Get | func (p *Program) Get(t Tag) string {
switch t {
case idTag:
return p.UID()
case programNameTag:
return p.Name()
case commandLineTag:
return p.Command()
case previousProgTag:
return p.Previous()
case versionTag:
return p.Version()
}
for _, tp := range p.otherTags {
if t == tp.tag {
return tp.value
}
}
return ""
} | go | func (p *Program) Get(t Tag) string {
switch t {
case idTag:
return p.UID()
case programNameTag:
return p.Name()
case commandLineTag:
return p.Command()
case previousProgTag:
return p.Previous()
case versionTag:
return p.Version()
}
for _, tp := range p.otherTags {
if t == tp.tag {
return tp.value
}
}
return ""
} | [
"func",
"(",
"p",
"*",
"Program",
")",
"Get",
"(",
"t",
"Tag",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"idTag",
":",
"return",
"p",
".",
"UID",
"(",
")",
"\n",
"case",
"programNameTag",
":",
"return",
"p",
".",
"Name",
"(",
")",
"\n",
"case",
"commandLineTag",
":",
"return",
"p",
".",
"Command",
"(",
")",
"\n",
"case",
"previousProgTag",
":",
"return",
"p",
".",
"Previous",
"(",
")",
"\n",
"case",
"versionTag",
":",
"return",
"p",
".",
"Version",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"tp",
":=",
"range",
"p",
".",
"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 program 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",
"program",
"line",
"tag",
".",
"If",
"the",
"tag",
"is",
"not",
"present",
"the",
"empty",
"string",
"is",
"returned",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L145-L164 |
14,935 | biogo/hts | sam/program.go | Set | func (p *Program) Set(t Tag, value string) error {
switch t {
case idTag:
if value == "" {
return errDupProgram
}
case programNameTag:
p.name = value
case commandLineTag:
p.command = value
case previousProgTag:
p.previous = value
case versionTag:
p.version = value
default:
if value == "" {
for i, tp := range p.otherTags {
if t == tp.tag {
copy(p.otherTags[i:], p.otherTags[i+1:])
p.otherTags = p.otherTags[:len(p.otherTags)-1]
return nil
}
}
} else {
for i, tp := range p.otherTags {
if t == tp.tag {
p.otherTags[i].value = value
return nil
}
}
p.otherTags = append(p.otherTags, tagPair{tag: t, value: value})
}
}
return nil
} | go | func (p *Program) Set(t Tag, value string) error {
switch t {
case idTag:
if value == "" {
return errDupProgram
}
case programNameTag:
p.name = value
case commandLineTag:
p.command = value
case previousProgTag:
p.previous = value
case versionTag:
p.version = value
default:
if value == "" {
for i, tp := range p.otherTags {
if t == tp.tag {
copy(p.otherTags[i:], p.otherTags[i+1:])
p.otherTags = p.otherTags[:len(p.otherTags)-1]
return nil
}
}
} else {
for i, tp := range p.otherTags {
if t == tp.tag {
p.otherTags[i].value = value
return nil
}
}
p.otherTags = append(p.otherTags, tagPair{tag: t, value: value})
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Program",
")",
"Set",
"(",
"t",
"Tag",
",",
"value",
"string",
")",
"error",
"{",
"switch",
"t",
"{",
"case",
"idTag",
":",
"if",
"value",
"==",
"\"",
"\"",
"{",
"return",
"errDupProgram",
"\n",
"}",
"\n",
"case",
"programNameTag",
":",
"p",
".",
"name",
"=",
"value",
"\n",
"case",
"commandLineTag",
":",
"p",
".",
"command",
"=",
"value",
"\n",
"case",
"previousProgTag",
":",
"p",
".",
"previous",
"=",
"value",
"\n",
"case",
"versionTag",
":",
"p",
".",
"version",
"=",
"value",
"\n",
"default",
":",
"if",
"value",
"==",
"\"",
"\"",
"{",
"for",
"i",
",",
"tp",
":=",
"range",
"p",
".",
"otherTags",
"{",
"if",
"t",
"==",
"tp",
".",
"tag",
"{",
"copy",
"(",
"p",
".",
"otherTags",
"[",
"i",
":",
"]",
",",
"p",
".",
"otherTags",
"[",
"i",
"+",
"1",
":",
"]",
")",
"\n",
"p",
".",
"otherTags",
"=",
"p",
".",
"otherTags",
"[",
":",
"len",
"(",
"p",
".",
"otherTags",
")",
"-",
"1",
"]",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"i",
",",
"tp",
":=",
"range",
"p",
".",
"otherTags",
"{",
"if",
"t",
"==",
"tp",
".",
"tag",
"{",
"p",
".",
"otherTags",
"[",
"i",
"]",
".",
"value",
"=",
"value",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"p",
".",
"otherTags",
"=",
"append",
"(",
"p",
".",
"otherTags",
",",
"tagPair",
"{",
"tag",
":",
"t",
",",
"value",
":",
"value",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set sets the value associated with the given program line tag to the specified
// value. If value is the empty string and the tag may be absent, it is deleted. | [
"Set",
"sets",
"the",
"value",
"associated",
"with",
"the",
"given",
"program",
"line",
"tag",
"to",
"the",
"specified",
"value",
".",
"If",
"value",
"is",
"the",
"empty",
"string",
"and",
"the",
"tag",
"may",
"be",
"absent",
"it",
"is",
"deleted",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L168-L202 |
14,936 | biogo/hts | sam/program.go | String | func (p *Program) String() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "@PG\tID:%s", p.uid)
if p.name != "" {
fmt.Fprintf(&buf, "\tPN:%s", p.name)
}
if p.command != "" {
fmt.Fprintf(&buf, "\tCL:%s", p.command)
}
if p.previous != "" {
fmt.Fprintf(&buf, "\tPP:%s", p.previous)
}
if p.version != "" {
fmt.Fprintf(&buf, "\tVN:%s", p.version)
}
for _, tp := range p.otherTags {
fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value)
}
return buf.String()
} | go | func (p *Program) String() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "@PG\tID:%s", p.uid)
if p.name != "" {
fmt.Fprintf(&buf, "\tPN:%s", p.name)
}
if p.command != "" {
fmt.Fprintf(&buf, "\tCL:%s", p.command)
}
if p.previous != "" {
fmt.Fprintf(&buf, "\tPP:%s", p.previous)
}
if p.version != "" {
fmt.Fprintf(&buf, "\tVN:%s", p.version)
}
for _, tp := range p.otherTags {
fmt.Fprintf(&buf, "\t%s:%s", tp.tag, tp.value)
}
return buf.String()
} | [
"func",
"(",
"p",
"*",
"Program",
")",
"String",
"(",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"p",
".",
"uid",
")",
"\n",
"if",
"p",
".",
"name",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"p",
".",
"name",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"command",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"p",
".",
"command",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"previous",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"p",
".",
"previous",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"version",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"p",
".",
"version",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"tp",
":=",
"range",
"p",
".",
"otherTags",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"buf",
",",
"\"",
"\\t",
"\"",
",",
"tp",
".",
"tag",
",",
"tp",
".",
"value",
")",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // String returns a string representation of the program according to the
// SAM specification section 1.3, | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"program",
"according",
"to",
"the",
"SAM",
"specification",
"section",
"1",
".",
"3"
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/program.go#L206-L225 |
14,937 | biogo/hts | sam/cigar.go | IsValid | func (c Cigar) IsValid(length int) bool {
var pos int
for i, co := range c {
ct := co.Type()
if ct == CigarHardClipped && i != 0 && i != len(c)-1 {
return false
}
if ct == CigarSoftClipped && i != 0 && i != len(c)-1 {
if c[i-1].Type() != CigarHardClipped && c[i+1].Type() != CigarHardClipped {
return false
}
}
con := ct.Consumes()
if pos < 0 && con.Query != 0 {
return false
}
length -= co.Len() * con.Query
pos += co.Len() * con.Reference
}
return length == 0
} | go | func (c Cigar) IsValid(length int) bool {
var pos int
for i, co := range c {
ct := co.Type()
if ct == CigarHardClipped && i != 0 && i != len(c)-1 {
return false
}
if ct == CigarSoftClipped && i != 0 && i != len(c)-1 {
if c[i-1].Type() != CigarHardClipped && c[i+1].Type() != CigarHardClipped {
return false
}
}
con := ct.Consumes()
if pos < 0 && con.Query != 0 {
return false
}
length -= co.Len() * con.Query
pos += co.Len() * con.Reference
}
return length == 0
} | [
"func",
"(",
"c",
"Cigar",
")",
"IsValid",
"(",
"length",
"int",
")",
"bool",
"{",
"var",
"pos",
"int",
"\n",
"for",
"i",
",",
"co",
":=",
"range",
"c",
"{",
"ct",
":=",
"co",
".",
"Type",
"(",
")",
"\n",
"if",
"ct",
"==",
"CigarHardClipped",
"&&",
"i",
"!=",
"0",
"&&",
"i",
"!=",
"len",
"(",
"c",
")",
"-",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"ct",
"==",
"CigarSoftClipped",
"&&",
"i",
"!=",
"0",
"&&",
"i",
"!=",
"len",
"(",
"c",
")",
"-",
"1",
"{",
"if",
"c",
"[",
"i",
"-",
"1",
"]",
".",
"Type",
"(",
")",
"!=",
"CigarHardClipped",
"&&",
"c",
"[",
"i",
"+",
"1",
"]",
".",
"Type",
"(",
")",
"!=",
"CigarHardClipped",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"con",
":=",
"ct",
".",
"Consumes",
"(",
")",
"\n",
"if",
"pos",
"<",
"0",
"&&",
"con",
".",
"Query",
"!=",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"length",
"-=",
"co",
".",
"Len",
"(",
")",
"*",
"con",
".",
"Query",
"\n",
"pos",
"+=",
"co",
".",
"Len",
"(",
")",
"*",
"con",
".",
"Reference",
"\n",
"}",
"\n",
"return",
"length",
"==",
"0",
"\n",
"}"
] | // IsValid returns whether the CIGAR string is valid for a record of the given
// sequence length. Validity is defined by the sum of query consuming operations
// matching the given length, clipping operations only being present at the ends
// of alignments, and that CigarBack operations only result in query-consuming
// positions at or right of the start of the alignment. | [
"IsValid",
"returns",
"whether",
"the",
"CIGAR",
"string",
"is",
"valid",
"for",
"a",
"record",
"of",
"the",
"given",
"sequence",
"length",
".",
"Validity",
"is",
"defined",
"by",
"the",
"sum",
"of",
"query",
"consuming",
"operations",
"matching",
"the",
"given",
"length",
"clipping",
"operations",
"only",
"being",
"present",
"at",
"the",
"ends",
"of",
"alignments",
"and",
"that",
"CigarBack",
"operations",
"only",
"result",
"in",
"query",
"-",
"consuming",
"positions",
"at",
"or",
"right",
"of",
"the",
"start",
"of",
"the",
"alignment",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L20-L40 |
14,938 | biogo/hts | sam/cigar.go | String | func (c Cigar) String() string {
if len(c) == 0 {
return "*"
}
var b bytes.Buffer
for _, co := range c {
fmt.Fprint(&b, co)
}
return b.String()
} | go | func (c Cigar) String() string {
if len(c) == 0 {
return "*"
}
var b bytes.Buffer
for _, co := range c {
fmt.Fprint(&b, co)
}
return b.String()
} | [
"func",
"(",
"c",
"Cigar",
")",
"String",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"c",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"for",
"_",
",",
"co",
":=",
"range",
"c",
"{",
"fmt",
".",
"Fprint",
"(",
"&",
"b",
",",
"co",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // String returns the CIGAR string for c. | [
"String",
"returns",
"the",
"CIGAR",
"string",
"for",
"c",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L43-L52 |
14,939 | biogo/hts | sam/cigar.go | Lengths | func (c Cigar) Lengths() (ref, read int) {
var con Consume
for _, co := range c {
con = co.Type().Consumes()
if co.Type() != CigarBack {
ref += co.Len() * con.Reference
}
read += co.Len() * con.Query
}
return ref, read
} | go | func (c Cigar) Lengths() (ref, read int) {
var con Consume
for _, co := range c {
con = co.Type().Consumes()
if co.Type() != CigarBack {
ref += co.Len() * con.Reference
}
read += co.Len() * con.Query
}
return ref, read
} | [
"func",
"(",
"c",
"Cigar",
")",
"Lengths",
"(",
")",
"(",
"ref",
",",
"read",
"int",
")",
"{",
"var",
"con",
"Consume",
"\n",
"for",
"_",
",",
"co",
":=",
"range",
"c",
"{",
"con",
"=",
"co",
".",
"Type",
"(",
")",
".",
"Consumes",
"(",
")",
"\n",
"if",
"co",
".",
"Type",
"(",
")",
"!=",
"CigarBack",
"{",
"ref",
"+=",
"co",
".",
"Len",
"(",
")",
"*",
"con",
".",
"Reference",
"\n",
"}",
"\n",
"read",
"+=",
"co",
".",
"Len",
"(",
")",
"*",
"con",
".",
"Query",
"\n",
"}",
"\n",
"return",
"ref",
",",
"read",
"\n",
"}"
] | // Lengths returns the number of reference and read bases described by the Cigar. | [
"Lengths",
"returns",
"the",
"number",
"of",
"reference",
"and",
"read",
"bases",
"described",
"by",
"the",
"Cigar",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L55-L65 |
14,940 | biogo/hts | sam/cigar.go | NewCigarOp | func NewCigarOp(t CigarOpType, n int) CigarOp {
if uint64(n) > 1<<28-1 {
panic("sam: illegal CIGAR op length")
}
return CigarOp(t) | (CigarOp(n) << 4)
} | go | func NewCigarOp(t CigarOpType, n int) CigarOp {
if uint64(n) > 1<<28-1 {
panic("sam: illegal CIGAR op length")
}
return CigarOp(t) | (CigarOp(n) << 4)
} | [
"func",
"NewCigarOp",
"(",
"t",
"CigarOpType",
",",
"n",
"int",
")",
"CigarOp",
"{",
"if",
"uint64",
"(",
"n",
")",
">",
"1",
"<<",
"28",
"-",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"CigarOp",
"(",
"t",
")",
"|",
"(",
"CigarOp",
"(",
"n",
")",
"<<",
"4",
")",
"\n",
"}"
] | // NewCigarOp returns a CIGAR operation of the specified type with length n.
// Due to a limitation of the BAM format, CIGAR operation lengths are limited
// to 2^28-1, and NewCigarOp will panic if n is above this or negative. | [
"NewCigarOp",
"returns",
"a",
"CIGAR",
"operation",
"of",
"the",
"specified",
"type",
"with",
"length",
"n",
".",
"Due",
"to",
"a",
"limitation",
"of",
"the",
"BAM",
"format",
"CIGAR",
"operation",
"lengths",
"are",
"limited",
"to",
"2^28",
"-",
"1",
"and",
"NewCigarOp",
"will",
"panic",
"if",
"n",
"is",
"above",
"this",
"or",
"negative",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L74-L79 |
14,941 | biogo/hts | sam/cigar.go | String | func (ct CigarOpType) String() string {
if ct < 0 || ct > lastCigar {
ct = lastCigar
}
return cigarOps[ct]
} | go | func (ct CigarOpType) String() string {
if ct < 0 || ct > lastCigar {
ct = lastCigar
}
return cigarOps[ct]
} | [
"func",
"(",
"ct",
"CigarOpType",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ct",
"<",
"0",
"||",
"ct",
">",
"lastCigar",
"{",
"ct",
"=",
"lastCigar",
"\n",
"}",
"\n",
"return",
"cigarOps",
"[",
"ct",
"]",
"\n",
"}"
] | // String returns the string representation of a CigarOpType. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"a",
"CigarOpType",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L128-L133 |
14,942 | biogo/hts | sam/cigar.go | atoi | func atoi(b []byte) (int, error) {
if len(b) > len(powers) {
return 0, fmt.Errorf("sam: integer overflow: %q", b)
}
var n int64
k := len(b) - 1
for i, v := range b {
n += int64(v-'0') * powers[k-i]
if int64(int(n)) != n {
return 0, fmt.Errorf("sam: integer overflow: %q at %d", b, i)
}
}
return int(n), nil
} | go | func atoi(b []byte) (int, error) {
if len(b) > len(powers) {
return 0, fmt.Errorf("sam: integer overflow: %q", b)
}
var n int64
k := len(b) - 1
for i, v := range b {
n += int64(v-'0') * powers[k-i]
if int64(int(n)) != n {
return 0, fmt.Errorf("sam: integer overflow: %q at %d", b, i)
}
}
return int(n), nil
} | [
"func",
"atoi",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"b",
")",
">",
"len",
"(",
"powers",
")",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
")",
"\n",
"}",
"\n",
"var",
"n",
"int64",
"\n",
"k",
":=",
"len",
"(",
"b",
")",
"-",
"1",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"b",
"{",
"n",
"+=",
"int64",
"(",
"v",
"-",
"'0'",
")",
"*",
"powers",
"[",
"k",
"-",
"i",
"]",
"\n",
"if",
"int64",
"(",
"int",
"(",
"n",
")",
")",
"!=",
"n",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"int",
"(",
"n",
")",
",",
"nil",
"\n",
"}"
] | // atoi returns the integer interpretation of b which must be an ASCII decimal number representation. | [
"atoi",
"returns",
"the",
"integer",
"interpretation",
"of",
"b",
"which",
"must",
"be",
"an",
"ASCII",
"decimal",
"number",
"representation",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L207-L220 |
14,943 | biogo/hts | sam/cigar.go | ParseCigar | func ParseCigar(b []byte) (Cigar, error) {
if len(b) == 1 && b[0] == '*' {
return nil, nil
}
var (
c Cigar
op CigarOpType
n int
err error
)
for i := 0; i < len(b); i++ {
for j := i; j < len(b); j++ {
if b[j] < '0' || '9' < b[j] {
n, err = atoi(b[i:j])
if err != nil {
return nil, err
}
op = cigarOpTypeLookup[b[j]]
i = j
break
}
}
if op == lastCigar {
return nil, fmt.Errorf("sam: failed to parse cigar string %q: unknown operation %q", b, op)
}
for {
c = append(c, NewCigarOp(op, minInt(n, 1<<28-1)))
n -= 1<<28 - 1
if n <= 0 {
break
}
}
}
return c, nil
} | go | func ParseCigar(b []byte) (Cigar, error) {
if len(b) == 1 && b[0] == '*' {
return nil, nil
}
var (
c Cigar
op CigarOpType
n int
err error
)
for i := 0; i < len(b); i++ {
for j := i; j < len(b); j++ {
if b[j] < '0' || '9' < b[j] {
n, err = atoi(b[i:j])
if err != nil {
return nil, err
}
op = cigarOpTypeLookup[b[j]]
i = j
break
}
}
if op == lastCigar {
return nil, fmt.Errorf("sam: failed to parse cigar string %q: unknown operation %q", b, op)
}
for {
c = append(c, NewCigarOp(op, minInt(n, 1<<28-1)))
n -= 1<<28 - 1
if n <= 0 {
break
}
}
}
return c, nil
} | [
"func",
"ParseCigar",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"Cigar",
",",
"error",
")",
"{",
"if",
"len",
"(",
"b",
")",
"==",
"1",
"&&",
"b",
"[",
"0",
"]",
"==",
"'*'",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"var",
"(",
"c",
"Cigar",
"\n",
"op",
"CigarOpType",
"\n",
"n",
"int",
"\n",
"err",
"error",
"\n",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"b",
")",
";",
"i",
"++",
"{",
"for",
"j",
":=",
"i",
";",
"j",
"<",
"len",
"(",
"b",
")",
";",
"j",
"++",
"{",
"if",
"b",
"[",
"j",
"]",
"<",
"'0'",
"||",
"'9'",
"<",
"b",
"[",
"j",
"]",
"{",
"n",
",",
"err",
"=",
"atoi",
"(",
"b",
"[",
"i",
":",
"j",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"op",
"=",
"cigarOpTypeLookup",
"[",
"b",
"[",
"j",
"]",
"]",
"\n",
"i",
"=",
"j",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"op",
"==",
"lastCigar",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
",",
"op",
")",
"\n",
"}",
"\n\n",
"for",
"{",
"c",
"=",
"append",
"(",
"c",
",",
"NewCigarOp",
"(",
"op",
",",
"minInt",
"(",
"n",
",",
"1",
"<<",
"28",
"-",
"1",
")",
")",
")",
"\n",
"n",
"-=",
"1",
"<<",
"28",
"-",
"1",
"\n",
"if",
"n",
"<=",
"0",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // ParseCigar returns a Cigar parsed from the provided byte slice.
// ParseCigar will break CIGAR operations longer than 2^28-1 into
// multiple operations summing to the same length. | [
"ParseCigar",
"returns",
"a",
"Cigar",
"parsed",
"from",
"the",
"provided",
"byte",
"slice",
".",
"ParseCigar",
"will",
"break",
"CIGAR",
"operations",
"longer",
"than",
"2^28",
"-",
"1",
"into",
"multiple",
"operations",
"summing",
"to",
"the",
"same",
"length",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/cigar.go#L225-L260 |
14,944 | biogo/hts | bam/index.go | ReadIndex | func ReadIndex(r io.Reader) (*Index, error) {
var (
idx Index
magic [4]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != baiMagic {
return nil, errors.New("bam: magic number mismatch")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}
idx.idx, err = internal.ReadIndex(r, n, "bam")
if err != nil {
return nil, err
}
return &idx, nil
} | go | func ReadIndex(r io.Reader) (*Index, error) {
var (
idx Index
magic [4]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != baiMagic {
return nil, errors.New("bam: magic number mismatch")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}
idx.idx, err = internal.ReadIndex(r, n, "bam")
if err != nil {
return nil, err
}
return &idx, nil
} | [
"func",
"ReadIndex",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"(",
"idx",
"Index",
"\n",
"magic",
"[",
"4",
"]",
"byte",
"\n",
"err",
"error",
"\n",
")",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"magic",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"magic",
"!=",
"baiMagic",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"n",
"int32",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"idx",
".",
"idx",
",",
"err",
"=",
"internal",
".",
"ReadIndex",
"(",
"r",
",",
"n",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"idx",
",",
"nil",
"\n",
"}"
] | // ReadIndex reads the BAI Index from the given io.Reader. | [
"ReadIndex",
"reads",
"the",
"BAI",
"Index",
"from",
"the",
"given",
"io",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/index.go#L86-L113 |
14,945 | biogo/hts | bam/reader.go | NewReader | func NewReader(r io.Reader, rd int) (*Reader, error) {
bg, err := bgzf.NewReader(r, rd)
if err != nil {
return nil, err
}
h, _ := sam.NewHeader(nil, nil)
br := &Reader{
r: bg,
h: h,
references: int32(len(h.Refs())),
}
err = br.h.DecodeBinary(br.r)
if err != nil {
return nil, err
}
br.lastChunk.End = br.r.LastChunk().End
return br, nil
} | go | func NewReader(r io.Reader, rd int) (*Reader, error) {
bg, err := bgzf.NewReader(r, rd)
if err != nil {
return nil, err
}
h, _ := sam.NewHeader(nil, nil)
br := &Reader{
r: bg,
h: h,
references: int32(len(h.Refs())),
}
err = br.h.DecodeBinary(br.r)
if err != nil {
return nil, err
}
br.lastChunk.End = br.r.LastChunk().End
return br, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
",",
"rd",
"int",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"bg",
",",
"err",
":=",
"bgzf",
".",
"NewReader",
"(",
"r",
",",
"rd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"h",
",",
"_",
":=",
"sam",
".",
"NewHeader",
"(",
"nil",
",",
"nil",
")",
"\n",
"br",
":=",
"&",
"Reader",
"{",
"r",
":",
"bg",
",",
"h",
":",
"h",
",",
"references",
":",
"int32",
"(",
"len",
"(",
"h",
".",
"Refs",
"(",
")",
")",
")",
",",
"}",
"\n",
"err",
"=",
"br",
".",
"h",
".",
"DecodeBinary",
"(",
"br",
".",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"br",
".",
"lastChunk",
".",
"End",
"=",
"br",
".",
"r",
".",
"LastChunk",
"(",
")",
".",
"End",
"\n",
"return",
"br",
",",
"nil",
"\n",
"}"
] | // NewReader returns a new Reader using the given io.Reader
// and setting the read concurrency to rd. If rd is zero
// concurrency is set to GOMAXPROCS. The returned Reader
// should be closed after use to avoid leaking resources. | [
"NewReader",
"returns",
"a",
"new",
"Reader",
"using",
"the",
"given",
"io",
".",
"Reader",
"and",
"setting",
"the",
"read",
"concurrency",
"to",
"rd",
".",
"If",
"rd",
"is",
"zero",
"concurrency",
"is",
"set",
"to",
"GOMAXPROCS",
".",
"The",
"returned",
"Reader",
"should",
"be",
"closed",
"after",
"use",
"to",
"avoid",
"leaking",
"resources",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L44-L62 |
14,946 | biogo/hts | bam/reader.go | Seek | func (br *Reader) Seek(off bgzf.Offset) error {
return br.r.Seek(off)
} | go | func (br *Reader) Seek(off bgzf.Offset) error {
return br.r.Seek(off)
} | [
"func",
"(",
"br",
"*",
"Reader",
")",
"Seek",
"(",
"off",
"bgzf",
".",
"Offset",
")",
"error",
"{",
"return",
"br",
".",
"r",
".",
"Seek",
"(",
"off",
")",
"\n",
"}"
] | // Seek performs a seek to the specified bgzf.Offset. | [
"Seek",
"performs",
"a",
"seek",
"to",
"the",
"specified",
"bgzf",
".",
"Offset",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L199-L201 |
14,947 | biogo/hts | bam/reader.go | SetChunk | func (br *Reader) SetChunk(c *bgzf.Chunk) error {
if c != nil {
err := br.r.Seek(c.Begin)
if err != nil {
return err
}
}
br.c = c
return nil
} | go | func (br *Reader) SetChunk(c *bgzf.Chunk) error {
if c != nil {
err := br.r.Seek(c.Begin)
if err != nil {
return err
}
}
br.c = c
return nil
} | [
"func",
"(",
"br",
"*",
"Reader",
")",
"SetChunk",
"(",
"c",
"*",
"bgzf",
".",
"Chunk",
")",
"error",
"{",
"if",
"c",
"!=",
"nil",
"{",
"err",
":=",
"br",
".",
"r",
".",
"Seek",
"(",
"c",
".",
"Begin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"br",
".",
"c",
"=",
"c",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetChunk sets a limited range of the underlying BGZF file to read, after
// seeking to the start of the given chunk. It may be used to iterate over
// a defined genomic interval. | [
"SetChunk",
"sets",
"a",
"limited",
"range",
"of",
"the",
"underlying",
"BGZF",
"file",
"to",
"read",
"after",
"seeking",
"to",
"the",
"start",
"of",
"the",
"given",
"chunk",
".",
"It",
"may",
"be",
"used",
"to",
"iterate",
"over",
"a",
"defined",
"genomic",
"interval",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L206-L215 |
14,948 | biogo/hts | bam/reader.go | Error | func (i *Iterator) Error() error {
if i.err == io.EOF {
return nil
}
return i.err
} | go | func (i *Iterator) Error() error {
if i.err == io.EOF {
return nil
}
return i.err
} | [
"func",
"(",
"i",
"*",
"Iterator",
")",
"Error",
"(",
")",
"error",
"{",
"if",
"i",
".",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"i",
".",
"err",
"\n",
"}"
] | // Error returns the first non-EOF error that was encountered by the Iterator. | [
"Error",
"returns",
"the",
"first",
"non",
"-",
"EOF",
"error",
"that",
"was",
"encountered",
"by",
"the",
"Iterator",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L287-L292 |
14,949 | biogo/hts | bam/reader.go | Close | func (i *Iterator) Close() error {
i.r.SetChunk(nil)
return i.Error()
} | go | func (i *Iterator) Close() error {
i.r.SetChunk(nil)
return i.Error()
} | [
"func",
"(",
"i",
"*",
"Iterator",
")",
"Close",
"(",
")",
"error",
"{",
"i",
".",
"r",
".",
"SetChunk",
"(",
"nil",
")",
"\n",
"return",
"i",
".",
"Error",
"(",
")",
"\n",
"}"
] | // Close releases the underlying Reader. | [
"Close",
"releases",
"the",
"underlying",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L298-L301 |
14,950 | biogo/hts | bam/reader.go | parseAux | func parseAux(aux []byte) ([]sam.Aux, error) {
if len(aux) == 0 {
return nil, nil
}
aa := make([]sam.Aux, 0, 4)
for i := 0; i+2 < len(aux); {
t := aux[i+2]
switch j := jumps[t]; {
case j > 0:
j += 3
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j
case j < 0:
switch t {
case 'Z', 'H':
j := bytes.IndexByte(aux[i:], 0)
if j == -1 {
return nil, errors.New("bam: invalid zero terminated data: no zero")
}
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j + 1
case 'B':
length := binary.LittleEndian.Uint32(aux[i+4 : i+8])
j = int(length)*jumps[aux[i+3]] + int(unsafe.Sizeof(length)) + 4
if j < 0 || i+j < 0 || i+j > len(aux) {
return nil, fmt.Errorf("bam: invalid array length for aux data: %d", length)
}
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j
}
default:
return nil, fmt.Errorf("bam: unrecognised optional field type: %q", t)
}
}
return aa, nil
} | go | func parseAux(aux []byte) ([]sam.Aux, error) {
if len(aux) == 0 {
return nil, nil
}
aa := make([]sam.Aux, 0, 4)
for i := 0; i+2 < len(aux); {
t := aux[i+2]
switch j := jumps[t]; {
case j > 0:
j += 3
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j
case j < 0:
switch t {
case 'Z', 'H':
j := bytes.IndexByte(aux[i:], 0)
if j == -1 {
return nil, errors.New("bam: invalid zero terminated data: no zero")
}
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j + 1
case 'B':
length := binary.LittleEndian.Uint32(aux[i+4 : i+8])
j = int(length)*jumps[aux[i+3]] + int(unsafe.Sizeof(length)) + 4
if j < 0 || i+j < 0 || i+j > len(aux) {
return nil, fmt.Errorf("bam: invalid array length for aux data: %d", length)
}
aa = append(aa, sam.Aux(aux[i:i+j:i+j]))
i += j
}
default:
return nil, fmt.Errorf("bam: unrecognised optional field type: %q", t)
}
}
return aa, nil
} | [
"func",
"parseAux",
"(",
"aux",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"sam",
".",
"Aux",
",",
"error",
")",
"{",
"if",
"len",
"(",
"aux",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"aa",
":=",
"make",
"(",
"[",
"]",
"sam",
".",
"Aux",
",",
"0",
",",
"4",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"+",
"2",
"<",
"len",
"(",
"aux",
")",
";",
"{",
"t",
":=",
"aux",
"[",
"i",
"+",
"2",
"]",
"\n",
"switch",
"j",
":=",
"jumps",
"[",
"t",
"]",
";",
"{",
"case",
"j",
">",
"0",
":",
"j",
"+=",
"3",
"\n",
"aa",
"=",
"append",
"(",
"aa",
",",
"sam",
".",
"Aux",
"(",
"aux",
"[",
"i",
":",
"i",
"+",
"j",
":",
"i",
"+",
"j",
"]",
")",
")",
"\n",
"i",
"+=",
"j",
"\n",
"case",
"j",
"<",
"0",
":",
"switch",
"t",
"{",
"case",
"'Z'",
",",
"'H'",
":",
"j",
":=",
"bytes",
".",
"IndexByte",
"(",
"aux",
"[",
"i",
":",
"]",
",",
"0",
")",
"\n",
"if",
"j",
"==",
"-",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"aa",
"=",
"append",
"(",
"aa",
",",
"sam",
".",
"Aux",
"(",
"aux",
"[",
"i",
":",
"i",
"+",
"j",
":",
"i",
"+",
"j",
"]",
")",
")",
"\n",
"i",
"+=",
"j",
"+",
"1",
"\n",
"case",
"'B'",
":",
"length",
":=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"aux",
"[",
"i",
"+",
"4",
":",
"i",
"+",
"8",
"]",
")",
"\n",
"j",
"=",
"int",
"(",
"length",
")",
"*",
"jumps",
"[",
"aux",
"[",
"i",
"+",
"3",
"]",
"]",
"+",
"int",
"(",
"unsafe",
".",
"Sizeof",
"(",
"length",
")",
")",
"+",
"4",
"\n",
"if",
"j",
"<",
"0",
"||",
"i",
"+",
"j",
"<",
"0",
"||",
"i",
"+",
"j",
">",
"len",
"(",
"aux",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"length",
")",
"\n",
"}",
"\n",
"aa",
"=",
"append",
"(",
"aa",
",",
"sam",
".",
"Aux",
"(",
"aux",
"[",
"i",
":",
"i",
"+",
"j",
":",
"i",
"+",
"j",
"]",
")",
")",
"\n",
"i",
"+=",
"j",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"aa",
",",
"nil",
"\n",
"}"
] | // parseAux examines the data of a SAM record's OPT fields,
// returning a slice of sam.Aux that are backed by the original data. | [
"parseAux",
"examines",
"the",
"data",
"of",
"a",
"SAM",
"record",
"s",
"OPT",
"fields",
"returning",
"a",
"slice",
"of",
"sam",
".",
"Aux",
"that",
"are",
"backed",
"by",
"the",
"original",
"data",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L325-L360 |
14,951 | biogo/hts | bam/reader.go | newBuffer | func newBuffer(br *Reader) (*buffer, error) {
n, err := io.ReadFull(br.r, br.buf[:4])
// br.r.Chunk() is only valid after the call the Read(), so this
// must come after the first read in the record.
tx := br.r.Begin()
defer func() {
br.lastChunk = tx.End()
}()
if err != nil {
return nil, err
}
if n != 4 {
return nil, errors.New("bam: invalid record: short block size")
}
b := &buffer{data: br.buf[:4]}
size := int(b.readInt32())
if size == 0 {
return nil, io.EOF
}
if size < 0 {
return nil, errors.New("bam: invalid record: invalid block size")
}
b.off, b.data = 0, make([]byte, size)
n, err = io.ReadFull(br.r, b.data)
if err != nil {
return nil, err
}
if n != size {
return nil, errors.New("bam: truncated record")
}
return b, nil
} | go | func newBuffer(br *Reader) (*buffer, error) {
n, err := io.ReadFull(br.r, br.buf[:4])
// br.r.Chunk() is only valid after the call the Read(), so this
// must come after the first read in the record.
tx := br.r.Begin()
defer func() {
br.lastChunk = tx.End()
}()
if err != nil {
return nil, err
}
if n != 4 {
return nil, errors.New("bam: invalid record: short block size")
}
b := &buffer{data: br.buf[:4]}
size := int(b.readInt32())
if size == 0 {
return nil, io.EOF
}
if size < 0 {
return nil, errors.New("bam: invalid record: invalid block size")
}
b.off, b.data = 0, make([]byte, size)
n, err = io.ReadFull(br.r, b.data)
if err != nil {
return nil, err
}
if n != size {
return nil, errors.New("bam: truncated record")
}
return b, nil
} | [
"func",
"newBuffer",
"(",
"br",
"*",
"Reader",
")",
"(",
"*",
"buffer",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"br",
".",
"r",
",",
"br",
".",
"buf",
"[",
":",
"4",
"]",
")",
"\n",
"// br.r.Chunk() is only valid after the call the Read(), so this",
"// must come after the first read in the record.",
"tx",
":=",
"br",
".",
"r",
".",
"Begin",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"br",
".",
"lastChunk",
"=",
"tx",
".",
"End",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"4",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
":=",
"&",
"buffer",
"{",
"data",
":",
"br",
".",
"buf",
"[",
":",
"4",
"]",
"}",
"\n",
"size",
":=",
"int",
"(",
"b",
".",
"readInt32",
"(",
")",
")",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"nil",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"if",
"size",
"<",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"off",
",",
"b",
".",
"data",
"=",
"0",
",",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"n",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"br",
".",
"r",
",",
"b",
".",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"size",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // newBuffer returns a new buffer reading from the Reader's underlying bgzf.Reader and
// updates the Reader's lastChunk field. | [
"newBuffer",
"returns",
"a",
"new",
"buffer",
"reading",
"from",
"the",
"Reader",
"s",
"underlying",
"bgzf",
".",
"Reader",
"and",
"updates",
"the",
"Reader",
"s",
"lastChunk",
"field",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L444-L475 |
14,952 | biogo/hts | bam/reader.go | buildAux | func buildAux(aa []sam.Aux) (aux []byte) {
for _, a := range aa {
// TODO: validate each 'a'
aux = append(aux, []byte(a)...)
switch a.Type() {
case 'Z', 'H':
aux = append(aux, 0)
}
}
return
} | go | func buildAux(aa []sam.Aux) (aux []byte) {
for _, a := range aa {
// TODO: validate each 'a'
aux = append(aux, []byte(a)...)
switch a.Type() {
case 'Z', 'H':
aux = append(aux, 0)
}
}
return
} | [
"func",
"buildAux",
"(",
"aa",
"[",
"]",
"sam",
".",
"Aux",
")",
"(",
"aux",
"[",
"]",
"byte",
")",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"aa",
"{",
"// TODO: validate each 'a'",
"aux",
"=",
"append",
"(",
"aux",
",",
"[",
"]",
"byte",
"(",
"a",
")",
"...",
")",
"\n",
"switch",
"a",
".",
"Type",
"(",
")",
"{",
"case",
"'Z'",
",",
"'H'",
":",
"aux",
"=",
"append",
"(",
"aux",
",",
"0",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // buildAux constructs a single byte slice that represents a slice of sam.Aux. | [
"buildAux",
"constructs",
"a",
"single",
"byte",
"slice",
"that",
"represents",
"a",
"slice",
"of",
"sam",
".",
"Aux",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/reader.go#L478-L488 |
14,953 | biogo/hts | cram/cram.go | HasEOF | func HasEOF(r io.ReaderAt) (bool, error) {
type sizer interface {
Size() int64
}
type stater interface {
Stat() (os.FileInfo, error)
}
type lenSeeker interface {
io.Seeker
Len() int
}
var size int64
switch r := r.(type) {
case sizer:
size = r.Size()
case stater:
fi, err := r.Stat()
if err != nil {
return false, err
}
size = fi.Size()
case lenSeeker:
var err error
size, err = r.Seek(0, 1)
if err != nil {
return false, err
}
size += int64(r.Len())
default:
return false, ErrNoEnd
}
b := make([]byte, len(cramEOFmarker))
_, err := r.ReadAt(b, size-int64(len(cramEOFmarker)))
if err != nil {
return false, err
}
return bytes.Equal(b, cramEOFmarker), nil
} | go | func HasEOF(r io.ReaderAt) (bool, error) {
type sizer interface {
Size() int64
}
type stater interface {
Stat() (os.FileInfo, error)
}
type lenSeeker interface {
io.Seeker
Len() int
}
var size int64
switch r := r.(type) {
case sizer:
size = r.Size()
case stater:
fi, err := r.Stat()
if err != nil {
return false, err
}
size = fi.Size()
case lenSeeker:
var err error
size, err = r.Seek(0, 1)
if err != nil {
return false, err
}
size += int64(r.Len())
default:
return false, ErrNoEnd
}
b := make([]byte, len(cramEOFmarker))
_, err := r.ReadAt(b, size-int64(len(cramEOFmarker)))
if err != nil {
return false, err
}
return bytes.Equal(b, cramEOFmarker), nil
} | [
"func",
"HasEOF",
"(",
"r",
"io",
".",
"ReaderAt",
")",
"(",
"bool",
",",
"error",
")",
"{",
"type",
"sizer",
"interface",
"{",
"Size",
"(",
")",
"int64",
"\n",
"}",
"\n",
"type",
"stater",
"interface",
"{",
"Stat",
"(",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"\n",
"}",
"\n",
"type",
"lenSeeker",
"interface",
"{",
"io",
".",
"Seeker",
"\n",
"Len",
"(",
")",
"int",
"\n",
"}",
"\n",
"var",
"size",
"int64",
"\n",
"switch",
"r",
":=",
"r",
".",
"(",
"type",
")",
"{",
"case",
"sizer",
":",
"size",
"=",
"r",
".",
"Size",
"(",
")",
"\n",
"case",
"stater",
":",
"fi",
",",
"err",
":=",
"r",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"size",
"=",
"fi",
".",
"Size",
"(",
")",
"\n",
"case",
"lenSeeker",
":",
"var",
"err",
"error",
"\n",
"size",
",",
"err",
"=",
"r",
".",
"Seek",
"(",
"0",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"size",
"+=",
"int64",
"(",
"r",
".",
"Len",
"(",
")",
")",
"\n",
"default",
":",
"return",
"false",
",",
"ErrNoEnd",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"cramEOFmarker",
")",
")",
"\n",
"_",
",",
"err",
":=",
"r",
".",
"ReadAt",
"(",
"b",
",",
"size",
"-",
"int64",
"(",
"len",
"(",
"cramEOFmarker",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"bytes",
".",
"Equal",
"(",
"b",
",",
"cramEOFmarker",
")",
",",
"nil",
"\n",
"}"
] | // HasEOF checks for the presence of a CRAM magic EOF block.
// The magic block is defined in the CRAM specification. A magic block
// is written by a Writer on calling Close. The ReaderAt must provide
// some method for determining valid ReadAt offsets. | [
"HasEOF",
"checks",
"for",
"the",
"presence",
"of",
"a",
"CRAM",
"magic",
"EOF",
"block",
".",
"The",
"magic",
"block",
"is",
"defined",
"in",
"the",
"CRAM",
"specification",
".",
"A",
"magic",
"block",
"is",
"written",
"by",
"a",
"Writer",
"on",
"calling",
"Close",
".",
"The",
"ReaderAt",
"must",
"provide",
"some",
"method",
"for",
"determining",
"valid",
"ReadAt",
"offsets",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L52-L90 |
14,954 | biogo/hts | cram/cram.go | Next | func (r *Reader) Next() bool {
if r.err != nil {
return false
}
if r.c != nil {
io.Copy(ioutil.Discard, r.c.blockData)
}
var c Container
r.err = c.readFrom(r.r)
r.c = &c
return r.err == nil
} | go | func (r *Reader) Next() bool {
if r.err != nil {
return false
}
if r.c != nil {
io.Copy(ioutil.Discard, r.c.blockData)
}
var c Container
r.err = c.readFrom(r.r)
r.c = &c
return r.err == nil
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"r",
".",
"c",
"!=",
"nil",
"{",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"r",
".",
"c",
".",
"blockData",
")",
"\n",
"}",
"\n",
"var",
"c",
"Container",
"\n",
"r",
".",
"err",
"=",
"c",
".",
"readFrom",
"(",
"r",
".",
"r",
")",
"\n",
"r",
".",
"c",
"=",
"&",
"c",
"\n",
"return",
"r",
".",
"err",
"==",
"nil",
"\n",
"}"
] | // Next advances the Reader to the next CRAM container. It returns false
// when the stream ends, either by reaching the end of the stream or
// encountering an error. | [
"Next",
"advances",
"the",
"Reader",
"to",
"the",
"next",
"CRAM",
"container",
".",
"It",
"returns",
"false",
"when",
"the",
"stream",
"ends",
"either",
"by",
"reaching",
"the",
"end",
"of",
"the",
"stream",
"or",
"encountering",
"an",
"error",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L115-L126 |
14,955 | biogo/hts | cram/cram.go | readFrom | func (d *definition) readFrom(r io.Reader) error {
err := binary.Read(r, binary.LittleEndian, d)
if err != nil {
return err
}
magic := reflect.TypeOf(*d).Field(0).Tag.Get("is")
if !bytes.Equal(d.Magic[:], []byte(magic)) {
return fmt.Errorf("cram: not a cram file: magic bytes %q", d.Magic)
}
return nil
} | go | func (d *definition) readFrom(r io.Reader) error {
err := binary.Read(r, binary.LittleEndian, d)
if err != nil {
return err
}
magic := reflect.TypeOf(*d).Field(0).Tag.Get("is")
if !bytes.Equal(d.Magic[:], []byte(magic)) {
return fmt.Errorf("cram: not a cram file: magic bytes %q", d.Magic)
}
return nil
} | [
"func",
"(",
"d",
"*",
"definition",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"err",
":=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"d",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"magic",
":=",
"reflect",
".",
"TypeOf",
"(",
"*",
"d",
")",
".",
"Field",
"(",
"0",
")",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"d",
".",
"Magic",
"[",
":",
"]",
",",
"[",
"]",
"byte",
"(",
"magic",
")",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"d",
".",
"Magic",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // readFrom populates a definition from the given io.Reader. If the magic
// number of the file is not "CRAM" readFrom returns an error. | [
"readFrom",
"populates",
"a",
"definition",
"from",
"the",
"given",
"io",
".",
"Reader",
".",
"If",
"the",
"magic",
"number",
"of",
"the",
"file",
"is",
"not",
"CRAM",
"readFrom",
"returns",
"an",
"error",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L153-L163 |
14,956 | biogo/hts | cram/cram.go | readFrom | func (c *Container) readFrom(r io.Reader) error {
crc := crc32.NewIEEE()
er := errorReader{r: io.TeeReader(r, crc)}
var buf [4]byte
io.ReadFull(&er, buf[:])
c.blockLen = int32(binary.LittleEndian.Uint32(buf[:]))
c.refID = er.itf8()
c.start = er.itf8()
c.span = er.itf8()
c.nRec = er.itf8()
c.recCount = er.ltf8()
c.bases = er.ltf8()
c.blocks = er.itf8()
c.landmarks = er.itf8slice()
sum := crc.Sum32()
_, err := io.ReadFull(&er, buf[:])
if err != nil {
return err
}
c.crc32 = binary.LittleEndian.Uint32(buf[:])
if c.crc32 != sum {
return fmt.Errorf("cram: container crc32 mismatch got:0x%08x want:0x%08x", sum, c.crc32)
}
if er.err != nil {
return er.err
}
// The spec says T[] is {itf8, element...}.
// This is not true for byte[] according to
// the EOF block.
c.blockData = &io.LimitedReader{R: r, N: int64(c.blockLen)}
return nil
} | go | func (c *Container) readFrom(r io.Reader) error {
crc := crc32.NewIEEE()
er := errorReader{r: io.TeeReader(r, crc)}
var buf [4]byte
io.ReadFull(&er, buf[:])
c.blockLen = int32(binary.LittleEndian.Uint32(buf[:]))
c.refID = er.itf8()
c.start = er.itf8()
c.span = er.itf8()
c.nRec = er.itf8()
c.recCount = er.ltf8()
c.bases = er.ltf8()
c.blocks = er.itf8()
c.landmarks = er.itf8slice()
sum := crc.Sum32()
_, err := io.ReadFull(&er, buf[:])
if err != nil {
return err
}
c.crc32 = binary.LittleEndian.Uint32(buf[:])
if c.crc32 != sum {
return fmt.Errorf("cram: container crc32 mismatch got:0x%08x want:0x%08x", sum, c.crc32)
}
if er.err != nil {
return er.err
}
// The spec says T[] is {itf8, element...}.
// This is not true for byte[] according to
// the EOF block.
c.blockData = &io.LimitedReader{R: r, N: int64(c.blockLen)}
return nil
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"crc",
":=",
"crc32",
".",
"NewIEEE",
"(",
")",
"\n",
"er",
":=",
"errorReader",
"{",
"r",
":",
"io",
".",
"TeeReader",
"(",
"r",
",",
"crc",
")",
"}",
"\n",
"var",
"buf",
"[",
"4",
"]",
"byte",
"\n",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"buf",
"[",
":",
"]",
")",
"\n",
"c",
".",
"blockLen",
"=",
"int32",
"(",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"buf",
"[",
":",
"]",
")",
")",
"\n",
"c",
".",
"refID",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"c",
".",
"start",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"c",
".",
"span",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"c",
".",
"nRec",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"c",
".",
"recCount",
"=",
"er",
".",
"ltf8",
"(",
")",
"\n",
"c",
".",
"bases",
"=",
"er",
".",
"ltf8",
"(",
")",
"\n",
"c",
".",
"blocks",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"c",
".",
"landmarks",
"=",
"er",
".",
"itf8slice",
"(",
")",
"\n",
"sum",
":=",
"crc",
".",
"Sum32",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"crc32",
"=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"c",
".",
"crc32",
"!=",
"sum",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sum",
",",
"c",
".",
"crc32",
")",
"\n",
"}",
"\n",
"if",
"er",
".",
"err",
"!=",
"nil",
"{",
"return",
"er",
".",
"err",
"\n",
"}",
"\n",
"// The spec says T[] is {itf8, element...}.",
"// This is not true for byte[] according to",
"// the EOF block.",
"c",
".",
"blockData",
"=",
"&",
"io",
".",
"LimitedReader",
"{",
"R",
":",
"r",
",",
"N",
":",
"int64",
"(",
"c",
".",
"blockLen",
")",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // readFrom populates a Container from the given io.Reader checking that the
// CRC32 for the container header is correct. | [
"readFrom",
"populates",
"a",
"Container",
"from",
"the",
"given",
"io",
".",
"Reader",
"checking",
"that",
"the",
"CRC32",
"for",
"the",
"container",
"header",
"is",
"correct",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L187-L218 |
14,957 | biogo/hts | cram/cram.go | Next | func (c *Container) Next() bool {
if c.err != nil {
return false
}
var b Block
c.err = b.readFrom(c.blockData)
if c.err == nil {
c.block = &b
return true
}
return false
} | go | func (c *Container) Next() bool {
if c.err != nil {
return false
}
var b Block
c.err = b.readFrom(c.blockData)
if c.err == nil {
c.block = &b
return true
}
return false
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"c",
".",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"var",
"b",
"Block",
"\n",
"c",
".",
"err",
"=",
"b",
".",
"readFrom",
"(",
"c",
".",
"blockData",
")",
"\n",
"if",
"c",
".",
"err",
"==",
"nil",
"{",
"c",
".",
"block",
"=",
"&",
"b",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Next advances the Container to the next CRAM block. It returns false
// when the data ends, either by reaching the end of the container or
// encountering an error. | [
"Next",
"advances",
"the",
"Container",
"to",
"the",
"next",
"CRAM",
"block",
".",
"It",
"returns",
"false",
"when",
"the",
"data",
"ends",
"either",
"by",
"reaching",
"the",
"end",
"of",
"the",
"container",
"or",
"encountering",
"an",
"error",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L223-L234 |
14,958 | biogo/hts | cram/cram.go | readFrom | func (b *Block) readFrom(r io.Reader) error {
crc := crc32.NewIEEE()
er := errorReader{r: io.TeeReader(r, crc)}
var buf [4]byte
io.ReadFull(&er, buf[:2])
b.method = buf[0]
b.typ = buf[1]
b.contentID = er.itf8()
b.compressedSize = er.itf8()
b.rawSize = er.itf8()
if b.method == rawMethod && b.compressedSize != b.rawSize {
return fmt.Errorf("cram: compressed (%d) != raw (%d) size for raw method", b.compressedSize, b.rawSize)
}
// The spec says T[] is {itf8, element...}.
// This is not true for byte[] according to
// the EOF block.
b.blockData = make([]byte, b.compressedSize)
_, err := io.ReadFull(&er, b.blockData)
if err != nil {
return err
}
sum := crc.Sum32()
_, err = io.ReadFull(&er, buf[:])
if err != nil {
return err
}
b.crc32 = binary.LittleEndian.Uint32(buf[:])
if b.crc32 != sum {
return fmt.Errorf("cram: block crc32 mismatch got:0x%08x want:0x%08x", sum, b.crc32)
}
return nil
} | go | func (b *Block) readFrom(r io.Reader) error {
crc := crc32.NewIEEE()
er := errorReader{r: io.TeeReader(r, crc)}
var buf [4]byte
io.ReadFull(&er, buf[:2])
b.method = buf[0]
b.typ = buf[1]
b.contentID = er.itf8()
b.compressedSize = er.itf8()
b.rawSize = er.itf8()
if b.method == rawMethod && b.compressedSize != b.rawSize {
return fmt.Errorf("cram: compressed (%d) != raw (%d) size for raw method", b.compressedSize, b.rawSize)
}
// The spec says T[] is {itf8, element...}.
// This is not true for byte[] according to
// the EOF block.
b.blockData = make([]byte, b.compressedSize)
_, err := io.ReadFull(&er, b.blockData)
if err != nil {
return err
}
sum := crc.Sum32()
_, err = io.ReadFull(&er, buf[:])
if err != nil {
return err
}
b.crc32 = binary.LittleEndian.Uint32(buf[:])
if b.crc32 != sum {
return fmt.Errorf("cram: block crc32 mismatch got:0x%08x want:0x%08x", sum, b.crc32)
}
return nil
} | [
"func",
"(",
"b",
"*",
"Block",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"crc",
":=",
"crc32",
".",
"NewIEEE",
"(",
")",
"\n",
"er",
":=",
"errorReader",
"{",
"r",
":",
"io",
".",
"TeeReader",
"(",
"r",
",",
"crc",
")",
"}",
"\n",
"var",
"buf",
"[",
"4",
"]",
"byte",
"\n",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"buf",
"[",
":",
"2",
"]",
")",
"\n",
"b",
".",
"method",
"=",
"buf",
"[",
"0",
"]",
"\n",
"b",
".",
"typ",
"=",
"buf",
"[",
"1",
"]",
"\n",
"b",
".",
"contentID",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"b",
".",
"compressedSize",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"b",
".",
"rawSize",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"if",
"b",
".",
"method",
"==",
"rawMethod",
"&&",
"b",
".",
"compressedSize",
"!=",
"b",
".",
"rawSize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"b",
".",
"compressedSize",
",",
"b",
".",
"rawSize",
")",
"\n",
"}",
"\n",
"// The spec says T[] is {itf8, element...}.",
"// This is not true for byte[] according to",
"// the EOF block.",
"b",
".",
"blockData",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"b",
".",
"compressedSize",
")",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"b",
".",
"blockData",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sum",
":=",
"crc",
".",
"Sum32",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"b",
".",
"crc32",
"=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"buf",
"[",
":",
"]",
")",
"\n",
"if",
"b",
".",
"crc32",
"!=",
"sum",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sum",
",",
"b",
".",
"crc32",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // readFrom fills a Block from the given io.Reader checking that the
// CRC32 for the block is correct. | [
"readFrom",
"fills",
"a",
"Block",
"from",
"the",
"given",
"io",
".",
"Reader",
"checking",
"that",
"the",
"CRC32",
"for",
"the",
"block",
"is",
"correct",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L282-L313 |
14,959 | biogo/hts | cram/cram.go | Value | func (b *Block) Value() (interface{}, error) {
switch b.typ {
case fileHeader:
var h sam.Header
blockData, err := b.expandBlockdata()
if err != nil {
return nil, err
}
end := binary.LittleEndian.Uint32(blockData[:4])
err = h.UnmarshalText(blockData[4 : 4+end])
if err != nil {
return nil, err
}
return &h, nil
case mappedSliceHeader:
var s Slice
s.readFrom(bytes.NewReader(b.blockData))
return &s, nil
default:
// Experimental.
switch b.method {
case gzipMethod, bzip2Method, lzmaMethod:
var err error
b.blockData, err = b.expandBlockdata()
if err != nil {
return nil, err
}
b.method |= 0x80
default:
// Do nothing.
}
return b, nil
}
} | go | func (b *Block) Value() (interface{}, error) {
switch b.typ {
case fileHeader:
var h sam.Header
blockData, err := b.expandBlockdata()
if err != nil {
return nil, err
}
end := binary.LittleEndian.Uint32(blockData[:4])
err = h.UnmarshalText(blockData[4 : 4+end])
if err != nil {
return nil, err
}
return &h, nil
case mappedSliceHeader:
var s Slice
s.readFrom(bytes.NewReader(b.blockData))
return &s, nil
default:
// Experimental.
switch b.method {
case gzipMethod, bzip2Method, lzmaMethod:
var err error
b.blockData, err = b.expandBlockdata()
if err != nil {
return nil, err
}
b.method |= 0x80
default:
// Do nothing.
}
return b, nil
}
} | [
"func",
"(",
"b",
"*",
"Block",
")",
"Value",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"b",
".",
"typ",
"{",
"case",
"fileHeader",
":",
"var",
"h",
"sam",
".",
"Header",
"\n",
"blockData",
",",
"err",
":=",
"b",
".",
"expandBlockdata",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"end",
":=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"blockData",
"[",
":",
"4",
"]",
")",
"\n",
"err",
"=",
"h",
".",
"UnmarshalText",
"(",
"blockData",
"[",
"4",
":",
"4",
"+",
"end",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"h",
",",
"nil",
"\n",
"case",
"mappedSliceHeader",
":",
"var",
"s",
"Slice",
"\n",
"s",
".",
"readFrom",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
".",
"blockData",
")",
")",
"\n",
"return",
"&",
"s",
",",
"nil",
"\n",
"default",
":",
"// Experimental.",
"switch",
"b",
".",
"method",
"{",
"case",
"gzipMethod",
",",
"bzip2Method",
",",
"lzmaMethod",
":",
"var",
"err",
"error",
"\n",
"b",
".",
"blockData",
",",
"err",
"=",
"b",
".",
"expandBlockdata",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"b",
".",
"method",
"|=",
"0x80",
"\n",
"default",
":",
"// Do nothing.",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // Value returns the value of the Block.
//
// Note that rANS decompression is not implemented. | [
"Value",
"returns",
"the",
"value",
"of",
"the",
"Block",
".",
"Note",
"that",
"rANS",
"decompression",
"is",
"not",
"implemented",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L318-L351 |
14,960 | biogo/hts | cram/cram.go | expandBlockdata | func (b *Block) expandBlockdata() ([]byte, error) {
switch b.method {
default:
panic(fmt.Sprintf("cram: unknown method: %v", b.method))
case rawMethod:
return b.blockData, nil
case gzipMethod:
gz, err := gzip.NewReader(bytes.NewReader(b.blockData))
if err != nil {
return nil, err
}
return ioutil.ReadAll(gz)
case bzip2Method:
return ioutil.ReadAll(bzip2.NewReader(bytes.NewReader(b.blockData)))
case lzmaMethod:
lz, err := lzma.NewReader(bytes.NewReader(b.blockData))
if err != nil {
return nil, err
}
return ioutil.ReadAll(lz)
case ransMethod:
// Unimplemented.
// BUG(kortschak): The rANS method is not implemented.
// Data blocks compressed with rANS will be returned
// compressed and an "unimplemented" error will be
// returned.
return b.blockData, errors.New("unimplemented")
}
} | go | func (b *Block) expandBlockdata() ([]byte, error) {
switch b.method {
default:
panic(fmt.Sprintf("cram: unknown method: %v", b.method))
case rawMethod:
return b.blockData, nil
case gzipMethod:
gz, err := gzip.NewReader(bytes.NewReader(b.blockData))
if err != nil {
return nil, err
}
return ioutil.ReadAll(gz)
case bzip2Method:
return ioutil.ReadAll(bzip2.NewReader(bytes.NewReader(b.blockData)))
case lzmaMethod:
lz, err := lzma.NewReader(bytes.NewReader(b.blockData))
if err != nil {
return nil, err
}
return ioutil.ReadAll(lz)
case ransMethod:
// Unimplemented.
// BUG(kortschak): The rANS method is not implemented.
// Data blocks compressed with rANS will be returned
// compressed and an "unimplemented" error will be
// returned.
return b.blockData, errors.New("unimplemented")
}
} | [
"func",
"(",
"b",
"*",
"Block",
")",
"expandBlockdata",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"b",
".",
"method",
"{",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"method",
")",
")",
"\n",
"case",
"rawMethod",
":",
"return",
"b",
".",
"blockData",
",",
"nil",
"\n",
"case",
"gzipMethod",
":",
"gz",
",",
"err",
":=",
"gzip",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
".",
"blockData",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"ReadAll",
"(",
"gz",
")",
"\n",
"case",
"bzip2Method",
":",
"return",
"ioutil",
".",
"ReadAll",
"(",
"bzip2",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
".",
"blockData",
")",
")",
")",
"\n",
"case",
"lzmaMethod",
":",
"lz",
",",
"err",
":=",
"lzma",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
".",
"blockData",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"ReadAll",
"(",
"lz",
")",
"\n",
"case",
"ransMethod",
":",
"// Unimplemented.",
"// BUG(kortschak): The rANS method is not implemented.",
"// Data blocks compressed with rANS will be returned",
"// compressed and an \"unimplemented\" error will be",
"// returned.",
"return",
"b",
".",
"blockData",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // expandBlockdata decompresses the block's compressed data. | [
"expandBlockdata",
"decompresses",
"the",
"block",
"s",
"compressed",
"data",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L354-L382 |
14,961 | biogo/hts | cram/cram.go | readFrom | func (s *Slice) readFrom(r io.Reader) error {
er := errorReader{r: r}
s.refID = er.itf8()
s.start = er.itf8()
s.span = er.itf8()
s.nRec = er.itf8()
s.recCount = er.ltf8()
s.blocks = er.itf8()
s.blockIDs = er.itf8slice()
s.embeddedRefID = er.itf8()
_, err := io.ReadFull(&er, s.md5sum[:])
if err != nil {
return err
}
s.tags, err = ioutil.ReadAll(&er)
return err
} | go | func (s *Slice) readFrom(r io.Reader) error {
er := errorReader{r: r}
s.refID = er.itf8()
s.start = er.itf8()
s.span = er.itf8()
s.nRec = er.itf8()
s.recCount = er.ltf8()
s.blocks = er.itf8()
s.blockIDs = er.itf8slice()
s.embeddedRefID = er.itf8()
_, err := io.ReadFull(&er, s.md5sum[:])
if err != nil {
return err
}
s.tags, err = ioutil.ReadAll(&er)
return err
} | [
"func",
"(",
"s",
"*",
"Slice",
")",
"readFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"er",
":=",
"errorReader",
"{",
"r",
":",
"r",
"}",
"\n",
"s",
".",
"refID",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"s",
".",
"start",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"s",
".",
"span",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"s",
".",
"nRec",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"s",
".",
"recCount",
"=",
"er",
".",
"ltf8",
"(",
")",
"\n",
"s",
".",
"blocks",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"s",
".",
"blockIDs",
"=",
"er",
".",
"itf8slice",
"(",
")",
"\n",
"s",
".",
"embeddedRefID",
"=",
"er",
".",
"itf8",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"&",
"er",
",",
"s",
".",
"md5sum",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
".",
"tags",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"&",
"er",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // readFrom populates a Slice from the given io.Reader. | [
"readFrom",
"populates",
"a",
"Slice",
"from",
"the",
"given",
"io",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L401-L417 |
14,962 | biogo/hts | cram/cram.go | itf8 | func (r *errorReader) itf8() int32 {
var buf [5]byte
_, r.err = io.ReadFull(r, buf[:1])
if r.err != nil {
return 0
}
i, n, ok := itf8.Decode(buf[:1])
if ok {
return i
}
_, r.err = io.ReadFull(r, buf[1:n])
if r.err != nil {
return 0
}
i, _, ok = itf8.Decode(buf[:n])
if !ok {
r.err = fmt.Errorf("cram: failed to decode itf-8 stream %#v", buf[:n])
}
return i
} | go | func (r *errorReader) itf8() int32 {
var buf [5]byte
_, r.err = io.ReadFull(r, buf[:1])
if r.err != nil {
return 0
}
i, n, ok := itf8.Decode(buf[:1])
if ok {
return i
}
_, r.err = io.ReadFull(r, buf[1:n])
if r.err != nil {
return 0
}
i, _, ok = itf8.Decode(buf[:n])
if !ok {
r.err = fmt.Errorf("cram: failed to decode itf-8 stream %#v", buf[:n])
}
return i
} | [
"func",
"(",
"r",
"*",
"errorReader",
")",
"itf8",
"(",
")",
"int32",
"{",
"var",
"buf",
"[",
"5",
"]",
"byte",
"\n",
"_",
",",
"r",
".",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"buf",
"[",
":",
"1",
"]",
")",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"i",
",",
"n",
",",
"ok",
":=",
"itf8",
".",
"Decode",
"(",
"buf",
"[",
":",
"1",
"]",
")",
"\n",
"if",
"ok",
"{",
"return",
"i",
"\n",
"}",
"\n",
"_",
",",
"r",
".",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"buf",
"[",
"1",
":",
"n",
"]",
")",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"i",
",",
"_",
",",
"ok",
"=",
"itf8",
".",
"Decode",
"(",
"buf",
"[",
":",
"n",
"]",
")",
"\n",
"if",
"!",
"ok",
"{",
"r",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"buf",
"[",
":",
"n",
"]",
")",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}"
] | // itf8 returns the ITF-8 encoded number at the current reader position. | [
"itf8",
"returns",
"the",
"ITF",
"-",
"8",
"encoded",
"number",
"at",
"the",
"current",
"reader",
"position",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L436-L455 |
14,963 | biogo/hts | cram/cram.go | ltf8 | func (r *errorReader) ltf8() int64 {
var buf [9]byte
_, r.err = io.ReadFull(r, buf[:1])
if r.err != nil {
return 0
}
i, n, ok := ltf8.Decode(buf[:1])
if ok {
return i
}
_, r.err = io.ReadFull(r, buf[1:n])
if r.err != nil {
return 0
}
i, _, ok = ltf8.Decode(buf[:n])
if !ok {
r.err = fmt.Errorf("cram: failed to decode ltf-8 stream %#v", buf[:n])
}
return i
} | go | func (r *errorReader) ltf8() int64 {
var buf [9]byte
_, r.err = io.ReadFull(r, buf[:1])
if r.err != nil {
return 0
}
i, n, ok := ltf8.Decode(buf[:1])
if ok {
return i
}
_, r.err = io.ReadFull(r, buf[1:n])
if r.err != nil {
return 0
}
i, _, ok = ltf8.Decode(buf[:n])
if !ok {
r.err = fmt.Errorf("cram: failed to decode ltf-8 stream %#v", buf[:n])
}
return i
} | [
"func",
"(",
"r",
"*",
"errorReader",
")",
"ltf8",
"(",
")",
"int64",
"{",
"var",
"buf",
"[",
"9",
"]",
"byte",
"\n",
"_",
",",
"r",
".",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"buf",
"[",
":",
"1",
"]",
")",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"i",
",",
"n",
",",
"ok",
":=",
"ltf8",
".",
"Decode",
"(",
"buf",
"[",
":",
"1",
"]",
")",
"\n",
"if",
"ok",
"{",
"return",
"i",
"\n",
"}",
"\n",
"_",
",",
"r",
".",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"buf",
"[",
"1",
":",
"n",
"]",
")",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"i",
",",
"_",
",",
"ok",
"=",
"ltf8",
".",
"Decode",
"(",
"buf",
"[",
":",
"n",
"]",
")",
"\n",
"if",
"!",
"ok",
"{",
"r",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"buf",
"[",
":",
"n",
"]",
")",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}"
] | // itf8 returns the LTF-8 encoded number at the current reader position. | [
"itf8",
"returns",
"the",
"LTF",
"-",
"8",
"encoded",
"number",
"at",
"the",
"current",
"reader",
"position",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/cram/cram.go#L478-L497 |
14,964 | biogo/hts | tabix/tabix.go | ReadFrom | func ReadFrom(r io.Reader) (*Index, error) {
var (
idx Index
magic [4]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != tbiMagic {
return nil, errors.New("tabix: magic number mismatch")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}
err = readTabixHeader(r, &idx)
if err != nil {
return nil, err
}
if len(idx.refNames) != int(n) {
return nil, fmt.Errorf("tabix: name count mismatch: %d != %d", len(idx.refNames), n)
}
idx.nameMap = make(map[string]int)
for i, n := range idx.refNames {
idx.nameMap[n] = i
}
idx.idx, err = internal.ReadIndex(r, n, "tabix")
if err != nil {
return nil, err
}
return &idx, nil
} | go | func ReadFrom(r io.Reader) (*Index, error) {
var (
idx Index
magic [4]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != tbiMagic {
return nil, errors.New("tabix: magic number mismatch")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}
err = readTabixHeader(r, &idx)
if err != nil {
return nil, err
}
if len(idx.refNames) != int(n) {
return nil, fmt.Errorf("tabix: name count mismatch: %d != %d", len(idx.refNames), n)
}
idx.nameMap = make(map[string]int)
for i, n := range idx.refNames {
idx.nameMap[n] = i
}
idx.idx, err = internal.ReadIndex(r, n, "tabix")
if err != nil {
return nil, err
}
return &idx, nil
} | [
"func",
"ReadFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"(",
"idx",
"Index",
"\n",
"magic",
"[",
"4",
"]",
"byte",
"\n",
"err",
"error",
"\n",
")",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"magic",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"magic",
"!=",
"tbiMagic",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"n",
"int32",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"err",
"=",
"readTabixHeader",
"(",
"r",
",",
"&",
"idx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"idx",
".",
"refNames",
")",
"!=",
"int",
"(",
"n",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"idx",
".",
"refNames",
")",
",",
"n",
")",
"\n",
"}",
"\n",
"idx",
".",
"nameMap",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"i",
",",
"n",
":=",
"range",
"idx",
".",
"refNames",
"{",
"idx",
".",
"nameMap",
"[",
"n",
"]",
"=",
"i",
"\n",
"}",
"\n\n",
"idx",
".",
"idx",
",",
"err",
"=",
"internal",
".",
"ReadIndex",
"(",
"r",
",",
"n",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"idx",
",",
"nil",
"\n",
"}"
] | // ReadFrom reads the tabix index from the given io.Reader. Note that
// the tabix specification states that the index is stored as BGZF, but
// ReadFrom does not perform decompression. | [
"ReadFrom",
"reads",
"the",
"tabix",
"index",
"from",
"the",
"given",
"io",
".",
"Reader",
".",
"Note",
"that",
"the",
"tabix",
"specification",
"states",
"that",
"the",
"index",
"is",
"stored",
"as",
"BGZF",
"but",
"ReadFrom",
"does",
"not",
"perform",
"decompression",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/tabix/tabix.go#L130-L170 |
14,965 | biogo/hts | tabix/tabix.go | WriteTo | func WriteTo(w io.Writer, idx *Index) error {
err := binary.Write(w, binary.LittleEndian, tbiMagic)
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(len(idx.idx.Refs)))
if err != nil {
return err
}
err = writeTabixHeader(w, idx)
if err != nil {
return err
}
return internal.WriteIndex(w, &idx.idx, "tabix")
} | go | func WriteTo(w io.Writer, idx *Index) error {
err := binary.Write(w, binary.LittleEndian, tbiMagic)
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(len(idx.idx.Refs)))
if err != nil {
return err
}
err = writeTabixHeader(w, idx)
if err != nil {
return err
}
return internal.WriteIndex(w, &idx.idx, "tabix")
} | [
"func",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
",",
"idx",
"*",
"Index",
")",
"error",
"{",
"err",
":=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"tbiMagic",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"int32",
"(",
"len",
"(",
"idx",
".",
"idx",
".",
"Refs",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"writeTabixHeader",
"(",
"w",
",",
"idx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"internal",
".",
"WriteIndex",
"(",
"w",
",",
"&",
"idx",
".",
"idx",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // WriteTo writes the index to the given io.Writer. Note that
// the tabix specification states that the index is stored as BGZF, but
// WriteTo does not perform compression. | [
"WriteTo",
"writes",
"the",
"index",
"to",
"the",
"given",
"io",
".",
"Writer",
".",
"Note",
"that",
"the",
"tabix",
"specification",
"states",
"that",
"the",
"index",
"is",
"stored",
"as",
"BGZF",
"but",
"WriteTo",
"does",
"not",
"perform",
"compression",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/tabix/tabix.go#L226-L242 |
14,966 | biogo/hts | csi/csi_write.go | WriteTo | func WriteTo(w io.Writer, idx *Index) error {
idx.sort()
err := binary.Write(w, binary.LittleEndian, csiMagic)
if err != nil {
return err
}
_, err = w.Write([]byte{idx.Version})
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(idx.minShift))
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(idx.depth))
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(len(idx.Auxilliary)))
if err != nil {
return err
}
_, err = w.Write(idx.Auxilliary)
if err != nil {
return err
}
binLimit := uint32(((1 << ((idx.depth + 1) * nextBinShift)) - 1) / 7)
err = writeIndices(w, idx.Version, idx.refs, binLimit)
if err != nil {
return err
}
if idx.unmapped != nil {
err = binary.Write(w, binary.LittleEndian, idx.unmapped)
}
return err
} | go | func WriteTo(w io.Writer, idx *Index) error {
idx.sort()
err := binary.Write(w, binary.LittleEndian, csiMagic)
if err != nil {
return err
}
_, err = w.Write([]byte{idx.Version})
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(idx.minShift))
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(idx.depth))
if err != nil {
return err
}
err = binary.Write(w, binary.LittleEndian, int32(len(idx.Auxilliary)))
if err != nil {
return err
}
_, err = w.Write(idx.Auxilliary)
if err != nil {
return err
}
binLimit := uint32(((1 << ((idx.depth + 1) * nextBinShift)) - 1) / 7)
err = writeIndices(w, idx.Version, idx.refs, binLimit)
if err != nil {
return err
}
if idx.unmapped != nil {
err = binary.Write(w, binary.LittleEndian, idx.unmapped)
}
return err
} | [
"func",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
",",
"idx",
"*",
"Index",
")",
"error",
"{",
"idx",
".",
"sort",
"(",
")",
"\n",
"err",
":=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"csiMagic",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"idx",
".",
"Version",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"int32",
"(",
"idx",
".",
"minShift",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"int32",
"(",
"idx",
".",
"depth",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"binary",
".",
"Write",
"(",
"w",
",",
"binary",
".",
"LittleEndian",
",",
"int32",
"(",
"len",
"(",
"idx",
".",
"Auxilliary",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"idx",
".",
"Auxilliary",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"binLimit",
":=",
"uint32",
"(",
"(",
"(",
"1",
"<<",
"(",
"(",
"idx",
".",
"depth",
"+",
"1",
")",
"*",
"nextBinShift",
")",
")",
"-",
"1",
")",
"/",
"7",
")",
"\n",
"err",
"=",
"writeIndices",
"(",
"w",
",",
"idx",
".",
"Version",
",",
"idx",
".",
"refs",
",",
"binLimit",
")",
"\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",
"}"
] | // WriteTo writes the CSI index to the given io.Writer. Note that
// the csi specification states that the index is stored as BGZF, but
// WriteTo does not perform compression. | [
"WriteTo",
"writes",
"the",
"CSI",
"index",
"to",
"the",
"given",
"io",
".",
"Writer",
".",
"Note",
"that",
"the",
"csi",
"specification",
"states",
"that",
"the",
"index",
"is",
"stored",
"as",
"BGZF",
"but",
"WriteTo",
"does",
"not",
"perform",
"compression",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/csi/csi_write.go#L19-L54 |
14,967 | biogo/hts | bgzf/index/strategy.go | CompressorStrategy | func CompressorStrategy(near int64) MergeStrategy {
return func(chunks []bgzf.Chunk) []bgzf.Chunk {
if len(chunks) == 0 {
return nil
}
for c := 1; c < len(chunks); c++ {
leftChunk := chunks[c-1]
rightChunk := &chunks[c]
if leftChunk.End.File+near >= rightChunk.Begin.File {
rightChunk.Begin = leftChunk.Begin
if vOffset(leftChunk.End) > vOffset(rightChunk.End) {
rightChunk.End = leftChunk.End
}
chunks = append(chunks[:c-1], chunks[c:]...)
c--
}
}
return chunks
}
} | go | func CompressorStrategy(near int64) MergeStrategy {
return func(chunks []bgzf.Chunk) []bgzf.Chunk {
if len(chunks) == 0 {
return nil
}
for c := 1; c < len(chunks); c++ {
leftChunk := chunks[c-1]
rightChunk := &chunks[c]
if leftChunk.End.File+near >= rightChunk.Begin.File {
rightChunk.Begin = leftChunk.Begin
if vOffset(leftChunk.End) > vOffset(rightChunk.End) {
rightChunk.End = leftChunk.End
}
chunks = append(chunks[:c-1], chunks[c:]...)
c--
}
}
return chunks
}
} | [
"func",
"CompressorStrategy",
"(",
"near",
"int64",
")",
"MergeStrategy",
"{",
"return",
"func",
"(",
"chunks",
"[",
"]",
"bgzf",
".",
"Chunk",
")",
"[",
"]",
"bgzf",
".",
"Chunk",
"{",
"if",
"len",
"(",
"chunks",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"c",
":=",
"1",
";",
"c",
"<",
"len",
"(",
"chunks",
")",
";",
"c",
"++",
"{",
"leftChunk",
":=",
"chunks",
"[",
"c",
"-",
"1",
"]",
"\n",
"rightChunk",
":=",
"&",
"chunks",
"[",
"c",
"]",
"\n",
"if",
"leftChunk",
".",
"End",
".",
"File",
"+",
"near",
">=",
"rightChunk",
".",
"Begin",
".",
"File",
"{",
"rightChunk",
".",
"Begin",
"=",
"leftChunk",
".",
"Begin",
"\n",
"if",
"vOffset",
"(",
"leftChunk",
".",
"End",
")",
">",
"vOffset",
"(",
"rightChunk",
".",
"End",
")",
"{",
"rightChunk",
".",
"End",
"=",
"leftChunk",
".",
"End",
"\n",
"}",
"\n",
"chunks",
"=",
"append",
"(",
"chunks",
"[",
":",
"c",
"-",
"1",
"]",
",",
"chunks",
"[",
"c",
":",
"]",
"...",
")",
"\n",
"c",
"--",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"chunks",
"\n",
"}",
"\n",
"}"
] | // CompressorStrategy returns a MergeStrategy that will merge bgzf.Chunks
// that have a distance between BGZF block starts less than or equal
// to near. | [
"CompressorStrategy",
"returns",
"a",
"MergeStrategy",
"that",
"will",
"merge",
"bgzf",
".",
"Chunks",
"that",
"have",
"a",
"distance",
"between",
"BGZF",
"block",
"starts",
"less",
"than",
"or",
"equal",
"to",
"near",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/index/strategy.go#L28-L47 |
14,968 | biogo/hts | bam/writer.go | NewWriter | func NewWriter(w io.Writer, h *sam.Header, wc int) (*Writer, error) {
return NewWriterLevel(w, h, gzip.DefaultCompression, wc)
} | go | func NewWriter(w io.Writer, h *sam.Header, wc int) (*Writer, error) {
return NewWriterLevel(w, h, gzip.DefaultCompression, wc)
} | [
"func",
"NewWriter",
"(",
"w",
"io",
".",
"Writer",
",",
"h",
"*",
"sam",
".",
"Header",
",",
"wc",
"int",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"return",
"NewWriterLevel",
"(",
"w",
",",
"h",
",",
"gzip",
".",
"DefaultCompression",
",",
"wc",
")",
"\n",
"}"
] | // NewWriter returns a new Writer using the given SAM header. Write
// concurrency is set to wc. | [
"NewWriter",
"returns",
"a",
"new",
"Writer",
"using",
"the",
"given",
"SAM",
"header",
".",
"Write",
"concurrency",
"is",
"set",
"to",
"wc",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/writer.go#L28-L30 |
14,969 | biogo/hts | bam/writer.go | Write | func (bw *Writer) Write(r *sam.Record) error {
if len(r.Name) == 0 || len(r.Name) > 254 {
return errors.New("bam: name absent or too long")
}
if r.Qual != nil && len(r.Qual) != r.Seq.Length {
return errors.New("bam: sequence/quality length mismatch")
}
tags := buildAux(r.AuxFields)
recLen := bamFixedRemainder +
len(r.Name) + 1 + // Null terminated.
len(r.Cigar)<<2 + // CigarOps are 4 bytes.
len(r.Seq.Seq) +
len(r.Qual) +
len(tags)
bw.buf.Reset()
bin := binaryWriter{w: &bw.buf}
// Write record header data.
bin.writeInt32(int32(recLen))
bin.writeInt32(int32(r.Ref.ID()))
bin.writeInt32(int32(r.Pos))
bin.writeUint8(byte(len(r.Name) + 1))
bin.writeUint8(r.MapQ)
bin.writeUint16(uint16(r.Bin())) //r.bin
bin.writeUint16(uint16(len(r.Cigar)))
bin.writeUint16(uint16(r.Flags))
bin.writeInt32(int32(r.Seq.Length))
bin.writeInt32(int32(r.MateRef.ID()))
bin.writeInt32(int32(r.MatePos))
bin.writeInt32(int32(r.TempLen))
// Write variable length data.
bw.buf.WriteString(r.Name)
bw.buf.WriteByte(0)
writeCigarOps(&bin, r.Cigar)
bw.buf.Write(doublets(r.Seq.Seq).Bytes())
if r.Qual != nil {
bw.buf.Write(r.Qual)
} else {
for i := 0; i < r.Seq.Length; i++ {
bw.buf.WriteByte(0xff)
}
}
bw.buf.Write(tags)
_, err := bw.bg.Write(bw.buf.Bytes())
return err
} | go | func (bw *Writer) Write(r *sam.Record) error {
if len(r.Name) == 0 || len(r.Name) > 254 {
return errors.New("bam: name absent or too long")
}
if r.Qual != nil && len(r.Qual) != r.Seq.Length {
return errors.New("bam: sequence/quality length mismatch")
}
tags := buildAux(r.AuxFields)
recLen := bamFixedRemainder +
len(r.Name) + 1 + // Null terminated.
len(r.Cigar)<<2 + // CigarOps are 4 bytes.
len(r.Seq.Seq) +
len(r.Qual) +
len(tags)
bw.buf.Reset()
bin := binaryWriter{w: &bw.buf}
// Write record header data.
bin.writeInt32(int32(recLen))
bin.writeInt32(int32(r.Ref.ID()))
bin.writeInt32(int32(r.Pos))
bin.writeUint8(byte(len(r.Name) + 1))
bin.writeUint8(r.MapQ)
bin.writeUint16(uint16(r.Bin())) //r.bin
bin.writeUint16(uint16(len(r.Cigar)))
bin.writeUint16(uint16(r.Flags))
bin.writeInt32(int32(r.Seq.Length))
bin.writeInt32(int32(r.MateRef.ID()))
bin.writeInt32(int32(r.MatePos))
bin.writeInt32(int32(r.TempLen))
// Write variable length data.
bw.buf.WriteString(r.Name)
bw.buf.WriteByte(0)
writeCigarOps(&bin, r.Cigar)
bw.buf.Write(doublets(r.Seq.Seq).Bytes())
if r.Qual != nil {
bw.buf.Write(r.Qual)
} else {
for i := 0; i < r.Seq.Length; i++ {
bw.buf.WriteByte(0xff)
}
}
bw.buf.Write(tags)
_, err := bw.bg.Write(bw.buf.Bytes())
return err
} | [
"func",
"(",
"bw",
"*",
"Writer",
")",
"Write",
"(",
"r",
"*",
"sam",
".",
"Record",
")",
"error",
"{",
"if",
"len",
"(",
"r",
".",
"Name",
")",
"==",
"0",
"||",
"len",
"(",
"r",
".",
"Name",
")",
">",
"254",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Qual",
"!=",
"nil",
"&&",
"len",
"(",
"r",
".",
"Qual",
")",
"!=",
"r",
".",
"Seq",
".",
"Length",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"tags",
":=",
"buildAux",
"(",
"r",
".",
"AuxFields",
")",
"\n",
"recLen",
":=",
"bamFixedRemainder",
"+",
"len",
"(",
"r",
".",
"Name",
")",
"+",
"1",
"+",
"// Null terminated.",
"len",
"(",
"r",
".",
"Cigar",
")",
"<<",
"2",
"+",
"// CigarOps are 4 bytes.",
"len",
"(",
"r",
".",
"Seq",
".",
"Seq",
")",
"+",
"len",
"(",
"r",
".",
"Qual",
")",
"+",
"len",
"(",
"tags",
")",
"\n\n",
"bw",
".",
"buf",
".",
"Reset",
"(",
")",
"\n",
"bin",
":=",
"binaryWriter",
"{",
"w",
":",
"&",
"bw",
".",
"buf",
"}",
"\n\n",
"// Write record header data.",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"recLen",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"Ref",
".",
"ID",
"(",
")",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"Pos",
")",
")",
"\n",
"bin",
".",
"writeUint8",
"(",
"byte",
"(",
"len",
"(",
"r",
".",
"Name",
")",
"+",
"1",
")",
")",
"\n",
"bin",
".",
"writeUint8",
"(",
"r",
".",
"MapQ",
")",
"\n",
"bin",
".",
"writeUint16",
"(",
"uint16",
"(",
"r",
".",
"Bin",
"(",
")",
")",
")",
"//r.bin",
"\n",
"bin",
".",
"writeUint16",
"(",
"uint16",
"(",
"len",
"(",
"r",
".",
"Cigar",
")",
")",
")",
"\n",
"bin",
".",
"writeUint16",
"(",
"uint16",
"(",
"r",
".",
"Flags",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"Seq",
".",
"Length",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"MateRef",
".",
"ID",
"(",
")",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"MatePos",
")",
")",
"\n",
"bin",
".",
"writeInt32",
"(",
"int32",
"(",
"r",
".",
"TempLen",
")",
")",
"\n\n",
"// Write variable length data.",
"bw",
".",
"buf",
".",
"WriteString",
"(",
"r",
".",
"Name",
")",
"\n",
"bw",
".",
"buf",
".",
"WriteByte",
"(",
"0",
")",
"\n",
"writeCigarOps",
"(",
"&",
"bin",
",",
"r",
".",
"Cigar",
")",
"\n",
"bw",
".",
"buf",
".",
"Write",
"(",
"doublets",
"(",
"r",
".",
"Seq",
".",
"Seq",
")",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"r",
".",
"Qual",
"!=",
"nil",
"{",
"bw",
".",
"buf",
".",
"Write",
"(",
"r",
".",
"Qual",
")",
"\n",
"}",
"else",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"r",
".",
"Seq",
".",
"Length",
";",
"i",
"++",
"{",
"bw",
".",
"buf",
".",
"WriteByte",
"(",
"0xff",
")",
"\n",
"}",
"\n",
"}",
"\n",
"bw",
".",
"buf",
".",
"Write",
"(",
"tags",
")",
"\n",
"_",
",",
"err",
":=",
"bw",
".",
"bg",
".",
"Write",
"(",
"bw",
".",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Write writes r to the BAM stream. | [
"Write",
"writes",
"r",
"to",
"the",
"BAM",
"stream",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/writer.go#L76-L123 |
14,970 | biogo/hts | csi/csi.go | MinimumShiftFor | func MinimumShiftFor(max int64, depth uint32) (uint32, bool) {
for shift := uint32(0); shift < 32; shift++ {
if validIndexPos(int(max), shift, depth) {
return shift, true
}
}
return 0, false
} | go | func MinimumShiftFor(max int64, depth uint32) (uint32, bool) {
for shift := uint32(0); shift < 32; shift++ {
if validIndexPos(int(max), shift, depth) {
return shift, true
}
}
return 0, false
} | [
"func",
"MinimumShiftFor",
"(",
"max",
"int64",
",",
"depth",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"for",
"shift",
":=",
"uint32",
"(",
"0",
")",
";",
"shift",
"<",
"32",
";",
"shift",
"++",
"{",
"if",
"validIndexPos",
"(",
"int",
"(",
"max",
")",
",",
"shift",
",",
"depth",
")",
"{",
"return",
"shift",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"false",
"\n",
"}"
] | // MinimumShiftFor returns the lowest minimum shift value that can be used to index
// the given maximum position with the given index depth. | [
"MinimumShiftFor",
"returns",
"the",
"lowest",
"minimum",
"shift",
"value",
"that",
"can",
"be",
"used",
"to",
"index",
"the",
"given",
"maximum",
"position",
"with",
"the",
"given",
"index",
"depth",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/csi/csi.go#L30-L37 |
14,971 | biogo/hts | csi/csi.go | MinimumDepthFor | func MinimumDepthFor(max int64, shift uint32) (uint32, bool) {
for depth := uint32(0); depth < 32; depth++ {
if validIndexPos(int(max), shift, depth) {
return depth, true
}
}
return 0, false
} | go | func MinimumDepthFor(max int64, shift uint32) (uint32, bool) {
for depth := uint32(0); depth < 32; depth++ {
if validIndexPos(int(max), shift, depth) {
return depth, true
}
}
return 0, false
} | [
"func",
"MinimumDepthFor",
"(",
"max",
"int64",
",",
"shift",
"uint32",
")",
"(",
"uint32",
",",
"bool",
")",
"{",
"for",
"depth",
":=",
"uint32",
"(",
"0",
")",
";",
"depth",
"<",
"32",
";",
"depth",
"++",
"{",
"if",
"validIndexPos",
"(",
"int",
"(",
"max",
")",
",",
"shift",
",",
"depth",
")",
"{",
"return",
"depth",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"false",
"\n",
"}"
] | // MinimumDepthFor returns the lowest depth value that can be used to index
// the given maximum position with the given index minimum shift. | [
"MinimumDepthFor",
"returns",
"the",
"lowest",
"depth",
"value",
"that",
"can",
"be",
"used",
"to",
"index",
"the",
"given",
"maximum",
"position",
"with",
"the",
"given",
"index",
"minimum",
"shift",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/csi/csi.go#L41-L48 |
14,972 | biogo/hts | csi/csi.go | New | func New(minShift, depth int) *Index {
if minShift == 0 {
minShift = DefaultShift
}
if depth == 0 {
depth = DefaultDepth
}
return &Index{Version: 0x2, minShift: uint32(minShift), depth: uint32(depth)}
} | go | func New(minShift, depth int) *Index {
if minShift == 0 {
minShift = DefaultShift
}
if depth == 0 {
depth = DefaultDepth
}
return &Index{Version: 0x2, minShift: uint32(minShift), depth: uint32(depth)}
} | [
"func",
"New",
"(",
"minShift",
",",
"depth",
"int",
")",
"*",
"Index",
"{",
"if",
"minShift",
"==",
"0",
"{",
"minShift",
"=",
"DefaultShift",
"\n",
"}",
"\n",
"if",
"depth",
"==",
"0",
"{",
"depth",
"=",
"DefaultDepth",
"\n",
"}",
"\n",
"return",
"&",
"Index",
"{",
"Version",
":",
"0x2",
",",
"minShift",
":",
"uint32",
"(",
"minShift",
")",
",",
"depth",
":",
"uint32",
"(",
"depth",
")",
"}",
"\n",
"}"
] | // New returns a CSI index with the given minimum shift and depth.
// The returned index defaults to CSI version 2. | [
"New",
"returns",
"a",
"CSI",
"index",
"with",
"the",
"given",
"minimum",
"shift",
"and",
"depth",
".",
"The",
"returned",
"index",
"defaults",
"to",
"CSI",
"version",
"2",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/csi/csi.go#L56-L64 |
14,973 | biogo/hts | csi/csi_read.go | ReadFrom | func ReadFrom(r io.Reader) (*Index, error) {
var (
idx Index
magic [3]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != csiMagic {
return nil, errors.New("csi: magic number mismatch")
}
version := []byte{0}
_, err = io.ReadFull(r, version)
if err != nil {
return nil, err
}
idx.Version = version[0]
if idx.Version != 0x1 && idx.Version != 0x2 {
return nil, fmt.Errorf("csi: unknown version: %d", version[0])
}
err = binary.Read(r, binary.LittleEndian, &idx.minShift)
if err != nil {
return nil, err
}
if int32(idx.minShift) < 0 {
return nil, errors.New("csi: invalid minimum shift value")
}
err = binary.Read(r, binary.LittleEndian, &idx.depth)
if err != nil {
return nil, err
}
if int32(idx.depth) < 0 {
return nil, errors.New("csi: invalid index depth value")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n > 0 {
idx.Auxilliary = make([]byte, n)
_, err = io.ReadFull(r, idx.Auxilliary)
if err != nil {
return nil, err
}
}
binLimit := uint32(((1 << ((idx.depth + 1) * nextBinShift)) - 1) / 7)
idx.refs, err = readIndices(r, idx.Version, binLimit)
if err != nil {
return nil, err
}
var nUnmapped uint64
err = binary.Read(r, binary.LittleEndian, &nUnmapped)
if err == nil {
idx.unmapped = &nUnmapped
} else if err != io.EOF {
return nil, err
}
idx.isSorted = true
return &idx, nil
} | go | func ReadFrom(r io.Reader) (*Index, error) {
var (
idx Index
magic [3]byte
err error
)
err = binary.Read(r, binary.LittleEndian, &magic)
if err != nil {
return nil, err
}
if magic != csiMagic {
return nil, errors.New("csi: magic number mismatch")
}
version := []byte{0}
_, err = io.ReadFull(r, version)
if err != nil {
return nil, err
}
idx.Version = version[0]
if idx.Version != 0x1 && idx.Version != 0x2 {
return nil, fmt.Errorf("csi: unknown version: %d", version[0])
}
err = binary.Read(r, binary.LittleEndian, &idx.minShift)
if err != nil {
return nil, err
}
if int32(idx.minShift) < 0 {
return nil, errors.New("csi: invalid minimum shift value")
}
err = binary.Read(r, binary.LittleEndian, &idx.depth)
if err != nil {
return nil, err
}
if int32(idx.depth) < 0 {
return nil, errors.New("csi: invalid index depth value")
}
var n int32
err = binary.Read(r, binary.LittleEndian, &n)
if err != nil {
return nil, err
}
if n > 0 {
idx.Auxilliary = make([]byte, n)
_, err = io.ReadFull(r, idx.Auxilliary)
if err != nil {
return nil, err
}
}
binLimit := uint32(((1 << ((idx.depth + 1) * nextBinShift)) - 1) / 7)
idx.refs, err = readIndices(r, idx.Version, binLimit)
if err != nil {
return nil, err
}
var nUnmapped uint64
err = binary.Read(r, binary.LittleEndian, &nUnmapped)
if err == nil {
idx.unmapped = &nUnmapped
} else if err != io.EOF {
return nil, err
}
idx.isSorted = true
return &idx, nil
} | [
"func",
"ReadFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"(",
"idx",
"Index",
"\n",
"magic",
"[",
"3",
"]",
"byte",
"\n",
"err",
"error",
"\n",
")",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"magic",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"magic",
"!=",
"csiMagic",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"version",
":=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"idx",
".",
"Version",
"=",
"version",
"[",
"0",
"]",
"\n",
"if",
"idx",
".",
"Version",
"!=",
"0x1",
"&&",
"idx",
".",
"Version",
"!=",
"0x2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"version",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"idx",
".",
"minShift",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"int32",
"(",
"idx",
".",
"minShift",
")",
"<",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"idx",
".",
"depth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"int32",
"(",
"idx",
".",
"depth",
")",
"<",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"n",
"int32",
"\n",
"err",
"=",
"binary",
".",
"Read",
"(",
"r",
",",
"binary",
".",
"LittleEndian",
",",
"&",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"n",
">",
"0",
"{",
"idx",
".",
"Auxilliary",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"idx",
".",
"Auxilliary",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"binLimit",
":=",
"uint32",
"(",
"(",
"(",
"1",
"<<",
"(",
"(",
"idx",
".",
"depth",
"+",
"1",
")",
"*",
"nextBinShift",
")",
")",
"-",
"1",
")",
"/",
"7",
")",
"\n",
"idx",
".",
"refs",
",",
"err",
"=",
"readIndices",
"(",
"r",
",",
"idx",
".",
"Version",
",",
"binLimit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"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",
"nil",
",",
"err",
"\n",
"}",
"\n",
"idx",
".",
"isSorted",
"=",
"true",
"\n",
"return",
"&",
"idx",
",",
"nil",
"\n",
"}"
] | // ReadFrom reads the CSI index from the given io.Reader. Note that
// the csi specification states that the index is stored as BGZF, but
// ReadFrom does not perform decompression. | [
"ReadFrom",
"reads",
"the",
"CSI",
"index",
"from",
"the",
"given",
"io",
".",
"Reader",
".",
"Note",
"that",
"the",
"csi",
"specification",
"states",
"that",
"the",
"index",
"is",
"stored",
"as",
"BGZF",
"but",
"ReadFrom",
"does",
"not",
"perform",
"decompression",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/csi/csi_read.go#L21-L83 |
14,974 | biogo/hts | sam/sam.go | NewReader | func NewReader(r io.Reader) (*Reader, error) {
h, _ := NewHeader(nil, nil)
sr := &Reader{
r: bufio.NewReader(r),
h: h,
}
var b []byte
p, err := sr.r.Peek(1)
if err != nil {
return nil, err
}
if p[0] != '@' {
sr.seenRefs = make(map[string]*Reference)
return sr, nil
}
for {
l, err := sr.r.ReadBytes('\n')
if err != nil {
return nil, io.ErrUnexpectedEOF
}
b = append(b, l...)
p, err := sr.r.Peek(1)
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
if p[0] != '@' {
break
}
}
err = sr.h.UnmarshalText(b)
if err != nil {
return nil, err
}
return sr, nil
} | go | func NewReader(r io.Reader) (*Reader, error) {
h, _ := NewHeader(nil, nil)
sr := &Reader{
r: bufio.NewReader(r),
h: h,
}
var b []byte
p, err := sr.r.Peek(1)
if err != nil {
return nil, err
}
if p[0] != '@' {
sr.seenRefs = make(map[string]*Reference)
return sr, nil
}
for {
l, err := sr.r.ReadBytes('\n')
if err != nil {
return nil, io.ErrUnexpectedEOF
}
b = append(b, l...)
p, err := sr.r.Peek(1)
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
if p[0] != '@' {
break
}
}
err = sr.h.UnmarshalText(b)
if err != nil {
return nil, err
}
return sr, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"h",
",",
"_",
":=",
"NewHeader",
"(",
"nil",
",",
"nil",
")",
"\n",
"sr",
":=",
"&",
"Reader",
"{",
"r",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
",",
"h",
":",
"h",
",",
"}",
"\n\n",
"var",
"b",
"[",
"]",
"byte",
"\n",
"p",
",",
"err",
":=",
"sr",
".",
"r",
".",
"Peek",
"(",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"p",
"[",
"0",
"]",
"!=",
"'@'",
"{",
"sr",
".",
"seenRefs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Reference",
")",
"\n",
"return",
"sr",
",",
"nil",
"\n",
"}",
"\n\n",
"for",
"{",
"l",
",",
"err",
":=",
"sr",
".",
"r",
".",
"ReadBytes",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"io",
".",
"ErrUnexpectedEOF",
"\n",
"}",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"l",
"...",
")",
"\n",
"p",
",",
"err",
":=",
"sr",
".",
"r",
".",
"Peek",
"(",
"1",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"p",
"[",
"0",
"]",
"!=",
"'@'",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
"=",
"sr",
".",
"h",
".",
"UnmarshalText",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"sr",
",",
"nil",
"\n",
"}"
] | // NewReader returns a new Reader, reading from the given io.Reader. | [
"NewReader",
"returns",
"a",
"new",
"Reader",
"reading",
"from",
"the",
"given",
"io",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/sam.go#L26-L67 |
14,975 | biogo/hts | sam/sam.go | Read | func (r *Reader) Read() (*Record, error) {
b, err := r.r.ReadBytes('\n')
if err != nil {
return nil, err
}
b = b[:len(b)-1]
if b[len(b)-1] == '\r' {
b = b[:len(b)-1]
}
var rec Record
// Handle cases where a header was present.
if r.seenRefs == nil {
err = rec.UnmarshalSAM(r.h, b)
if err != nil {
return nil, err
}
return &rec, nil
}
// Handle cases where no SAM header is present.
err = rec.UnmarshalSAM(nil, b)
if err != nil {
return nil, err
}
if ref, ok := r.seenRefs[rec.Ref.Name()]; ok {
rec.Ref = ref
} else if rec.Ref != nil {
err = r.h.AddReference(rec.Ref)
if err != nil {
return nil, err
}
r.seenRefs[rec.Ref.Name()] = rec.Ref
} else {
r.seenRefs["*"] = nil
}
if ref, ok := r.seenRefs[rec.MateRef.Name()]; ok {
rec.MateRef = ref
} else if rec.MateRef != nil {
err = r.h.AddReference(rec.MateRef)
if err != nil {
return nil, err
}
r.seenRefs[rec.MateRef.Name()] = rec.MateRef
} else {
r.seenRefs["*"] = nil
}
return &rec, nil
} | go | func (r *Reader) Read() (*Record, error) {
b, err := r.r.ReadBytes('\n')
if err != nil {
return nil, err
}
b = b[:len(b)-1]
if b[len(b)-1] == '\r' {
b = b[:len(b)-1]
}
var rec Record
// Handle cases where a header was present.
if r.seenRefs == nil {
err = rec.UnmarshalSAM(r.h, b)
if err != nil {
return nil, err
}
return &rec, nil
}
// Handle cases where no SAM header is present.
err = rec.UnmarshalSAM(nil, b)
if err != nil {
return nil, err
}
if ref, ok := r.seenRefs[rec.Ref.Name()]; ok {
rec.Ref = ref
} else if rec.Ref != nil {
err = r.h.AddReference(rec.Ref)
if err != nil {
return nil, err
}
r.seenRefs[rec.Ref.Name()] = rec.Ref
} else {
r.seenRefs["*"] = nil
}
if ref, ok := r.seenRefs[rec.MateRef.Name()]; ok {
rec.MateRef = ref
} else if rec.MateRef != nil {
err = r.h.AddReference(rec.MateRef)
if err != nil {
return nil, err
}
r.seenRefs[rec.MateRef.Name()] = rec.MateRef
} else {
r.seenRefs["*"] = nil
}
return &rec, nil
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Read",
"(",
")",
"(",
"*",
"Record",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"r",
".",
"r",
".",
"ReadBytes",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"b",
"=",
"b",
"[",
":",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"\n",
"if",
"b",
"[",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"==",
"'\\r'",
"{",
"b",
"=",
"b",
"[",
":",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"var",
"rec",
"Record",
"\n\n",
"// Handle cases where a header was present.",
"if",
"r",
".",
"seenRefs",
"==",
"nil",
"{",
"err",
"=",
"rec",
".",
"UnmarshalSAM",
"(",
"r",
".",
"h",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"rec",
",",
"nil",
"\n",
"}",
"\n\n",
"// Handle cases where no SAM header is present.",
"err",
"=",
"rec",
".",
"UnmarshalSAM",
"(",
"nil",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"ref",
",",
"ok",
":=",
"r",
".",
"seenRefs",
"[",
"rec",
".",
"Ref",
".",
"Name",
"(",
")",
"]",
";",
"ok",
"{",
"rec",
".",
"Ref",
"=",
"ref",
"\n",
"}",
"else",
"if",
"rec",
".",
"Ref",
"!=",
"nil",
"{",
"err",
"=",
"r",
".",
"h",
".",
"AddReference",
"(",
"rec",
".",
"Ref",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"seenRefs",
"[",
"rec",
".",
"Ref",
".",
"Name",
"(",
")",
"]",
"=",
"rec",
".",
"Ref",
"\n",
"}",
"else",
"{",
"r",
".",
"seenRefs",
"[",
"\"",
"\"",
"]",
"=",
"nil",
"\n",
"}",
"\n",
"if",
"ref",
",",
"ok",
":=",
"r",
".",
"seenRefs",
"[",
"rec",
".",
"MateRef",
".",
"Name",
"(",
")",
"]",
";",
"ok",
"{",
"rec",
".",
"MateRef",
"=",
"ref",
"\n",
"}",
"else",
"if",
"rec",
".",
"MateRef",
"!=",
"nil",
"{",
"err",
"=",
"r",
".",
"h",
".",
"AddReference",
"(",
"rec",
".",
"MateRef",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"seenRefs",
"[",
"rec",
".",
"MateRef",
".",
"Name",
"(",
")",
"]",
"=",
"rec",
".",
"MateRef",
"\n",
"}",
"else",
"{",
"r",
".",
"seenRefs",
"[",
"\"",
"\"",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"rec",
",",
"nil",
"\n",
"}"
] | // Read returns the next sam.Record in the SAM stream. | [
"Read",
"returns",
"the",
"next",
"sam",
".",
"Record",
"in",
"the",
"SAM",
"stream",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/sam.go#L75-L125 |
14,976 | biogo/hts | sam/sam.go | NewWriter | func NewWriter(w io.Writer, h *Header, flags int) (*Writer, error) {
if flags < FlagDecimal || flags > FlagString {
return nil, errors.New("bam: flag format option out of range")
}
sw := &Writer{w: w, flags: flags}
text, _ := h.MarshalText()
_, err := w.Write(text)
if err != nil {
return nil, err
}
return sw, nil
} | go | func NewWriter(w io.Writer, h *Header, flags int) (*Writer, error) {
if flags < FlagDecimal || flags > FlagString {
return nil, errors.New("bam: flag format option out of range")
}
sw := &Writer{w: w, flags: flags}
text, _ := h.MarshalText()
_, err := w.Write(text)
if err != nil {
return nil, err
}
return sw, nil
} | [
"func",
"NewWriter",
"(",
"w",
"io",
".",
"Writer",
",",
"h",
"*",
"Header",
",",
"flags",
"int",
")",
"(",
"*",
"Writer",
",",
"error",
")",
"{",
"if",
"flags",
"<",
"FlagDecimal",
"||",
"flags",
">",
"FlagString",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sw",
":=",
"&",
"Writer",
"{",
"w",
":",
"w",
",",
"flags",
":",
"flags",
"}",
"\n",
"text",
",",
"_",
":=",
"h",
".",
"MarshalText",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"sw",
",",
"nil",
"\n",
"}"
] | // NewWriter returns a Writer to the given io.Writer using h for the SAM
// header. The format of flags for SAM lines can be FlagDecimal, FlagHex
// or FlagString. | [
"NewWriter",
"returns",
"a",
"Writer",
"to",
"the",
"given",
"io",
".",
"Writer",
"using",
"h",
"for",
"the",
"SAM",
"header",
".",
"The",
"format",
"of",
"flags",
"for",
"SAM",
"lines",
"can",
"be",
"FlagDecimal",
"FlagHex",
"or",
"FlagString",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/sam.go#L186-L197 |
14,977 | biogo/hts | sam/sam.go | Write | func (w *Writer) Write(r *Record) error {
b, err := r.MarshalSAM(w.flags)
if err != nil {
return err
}
b = append(b, '\n')
_, err = w.w.Write(b)
return err
} | go | func (w *Writer) Write(r *Record) error {
b, err := r.MarshalSAM(w.flags)
if err != nil {
return err
}
b = append(b, '\n')
_, err = w.w.Write(b)
return err
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Write",
"(",
"r",
"*",
"Record",
")",
"error",
"{",
"b",
",",
"err",
":=",
"r",
".",
"MarshalSAM",
"(",
"w",
".",
"flags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"b",
"=",
"append",
"(",
"b",
",",
"'\\n'",
")",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"w",
".",
"Write",
"(",
"b",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Write writes r to the SAM stream. | [
"Write",
"writes",
"r",
"to",
"the",
"SAM",
"stream",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/sam/sam.go#L200-L208 |
14,978 | biogo/hts | bam/merger.go | Read | func (m *Merger) Read() (rec *sam.Record, err error) {
if len(m.readers) == 0 {
return nil, io.EOF
}
if m.less == nil {
return m.cat()
}
return m.nextBySortOrder()
} | go | func (m *Merger) Read() (rec *sam.Record, err error) {
if len(m.readers) == 0 {
return nil, io.EOF
}
if m.less == nil {
return m.cat()
}
return m.nextBySortOrder()
} | [
"func",
"(",
"m",
"*",
"Merger",
")",
"Read",
"(",
")",
"(",
"rec",
"*",
"sam",
".",
"Record",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"m",
".",
"readers",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"if",
"m",
".",
"less",
"==",
"nil",
"{",
"return",
"m",
".",
"cat",
"(",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"nextBySortOrder",
"(",
")",
"\n",
"}"
] | // Read returns the next sam.Record in the BAM stream.
//
// The Read behaviour will depend on the underlying Readers. | [
"Read",
"returns",
"the",
"next",
"sam",
".",
"Record",
"in",
"the",
"BAM",
"stream",
".",
"The",
"Read",
"behaviour",
"will",
"depend",
"on",
"the",
"underlying",
"Readers",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bam/merger.go#L115-L123 |
14,979 | biogo/hts | bgzf/reader.go | newCountReader | func newCountReader(r io.Reader) *countReader {
switch r := r.(type) {
case *countReader:
panic("bgzf: illegal use of internal type")
case flate.Reader:
return &countReader{fr: r}
default:
return &countReader{fr: bufio.NewReader(r)}
}
} | go | func newCountReader(r io.Reader) *countReader {
switch r := r.(type) {
case *countReader:
panic("bgzf: illegal use of internal type")
case flate.Reader:
return &countReader{fr: r}
default:
return &countReader{fr: bufio.NewReader(r)}
}
} | [
"func",
"newCountReader",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"countReader",
"{",
"switch",
"r",
":=",
"r",
".",
"(",
"type",
")",
"{",
"case",
"*",
"countReader",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"case",
"flate",
".",
"Reader",
":",
"return",
"&",
"countReader",
"{",
"fr",
":",
"r",
"}",
"\n",
"default",
":",
"return",
"&",
"countReader",
"{",
"fr",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
"}",
"\n",
"}",
"\n",
"}"
] | // newCountReader returns a new countReader. | [
"newCountReader",
"returns",
"a",
"new",
"countReader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L27-L36 |
14,980 | biogo/hts | bgzf/reader.go | Read | func (r *countReader) Read(p []byte) (int, error) {
n, err := r.fr.Read(p)
r.off += int64(n)
return n, err
} | go | func (r *countReader) Read(p []byte) (int, error) {
n, err := r.fr.Read(p)
r.off += int64(n)
return n, err
} | [
"func",
"(",
"r",
"*",
"countReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"r",
".",
"fr",
".",
"Read",
"(",
"p",
")",
"\n",
"r",
".",
"off",
"+=",
"int64",
"(",
"n",
")",
"\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // Read is required to satisfy flate.Reader. | [
"Read",
"is",
"required",
"to",
"satisfy",
"flate",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L39-L43 |
14,981 | biogo/hts | bgzf/reader.go | ReadByte | func (r *countReader) ReadByte() (byte, error) {
b, err := r.fr.ReadByte()
if err == nil {
r.off++
}
return b, err
} | go | func (r *countReader) ReadByte() (byte, error) {
b, err := r.fr.ReadByte()
if err == nil {
r.off++
}
return b, err
} | [
"func",
"(",
"r",
"*",
"countReader",
")",
"ReadByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"r",
".",
"fr",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"r",
".",
"off",
"++",
"\n",
"}",
"\n",
"return",
"b",
",",
"err",
"\n",
"}"
] | // ReadByte is required to satisfy flate.Reader. | [
"ReadByte",
"is",
"required",
"to",
"satisfy",
"flate",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L46-L52 |
14,982 | biogo/hts | bgzf/reader.go | seek | func (r *countReader) seek(rs io.ReadSeeker, off int64) error {
_, err := rs.Seek(off, 0)
if err != nil {
return err
}
type reseter interface {
Reset(io.Reader)
}
switch cr := r.fr.(type) {
case reseter:
cr.Reset(rs)
default:
r.fr = newCountReader(rs)
}
r.off = off
return nil
} | go | func (r *countReader) seek(rs io.ReadSeeker, off int64) error {
_, err := rs.Seek(off, 0)
if err != nil {
return err
}
type reseter interface {
Reset(io.Reader)
}
switch cr := r.fr.(type) {
case reseter:
cr.Reset(rs)
default:
r.fr = newCountReader(rs)
}
r.off = off
return nil
} | [
"func",
"(",
"r",
"*",
"countReader",
")",
"seek",
"(",
"rs",
"io",
".",
"ReadSeeker",
",",
"off",
"int64",
")",
"error",
"{",
"_",
",",
"err",
":=",
"rs",
".",
"Seek",
"(",
"off",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"type",
"reseter",
"interface",
"{",
"Reset",
"(",
"io",
".",
"Reader",
")",
"\n",
"}",
"\n",
"switch",
"cr",
":=",
"r",
".",
"fr",
".",
"(",
"type",
")",
"{",
"case",
"reseter",
":",
"cr",
".",
"Reset",
"(",
"rs",
")",
"\n",
"default",
":",
"r",
".",
"fr",
"=",
"newCountReader",
"(",
"rs",
")",
"\n",
"}",
"\n",
"r",
".",
"off",
"=",
"off",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // seek moves the countReader to the specified offset using rs as the
// underlying reader. | [
"seek",
"moves",
"the",
"countReader",
"to",
"the",
"specified",
"offset",
"using",
"rs",
"as",
"the",
"underlying",
"reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L59-L77 |
14,983 | biogo/hts | bgzf/reader.go | Read | func (r *buffer) Read(b []byte) (int, error) {
if r.off >= r.size {
return 0, io.EOF
}
if n := r.size - r.off; len(b) > n {
b = b[:n]
}
n := copy(b, r.data[r.off:])
r.off += n
return n, nil
} | go | func (r *buffer) Read(b []byte) (int, error) {
if r.off >= r.size {
return 0, io.EOF
}
if n := r.size - r.off; len(b) > n {
b = b[:n]
}
n := copy(b, r.data[r.off:])
r.off += n
return n, nil
} | [
"func",
"(",
"r",
"*",
"buffer",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"r",
".",
"off",
">=",
"r",
".",
"size",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"if",
"n",
":=",
"r",
".",
"size",
"-",
"r",
".",
"off",
";",
"len",
"(",
"b",
")",
">",
"n",
"{",
"b",
"=",
"b",
"[",
":",
"n",
"]",
"\n",
"}",
"\n",
"n",
":=",
"copy",
"(",
"b",
",",
"r",
".",
"data",
"[",
"r",
".",
"off",
":",
"]",
")",
"\n",
"r",
".",
"off",
"+=",
"n",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // Read provides the flate.Decompressor Read method. | [
"Read",
"provides",
"the",
"flate",
".",
"Decompressor",
"Read",
"method",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L88-L98 |
14,984 | biogo/hts | bgzf/reader.go | ReadByte | func (r *buffer) ReadByte() (byte, error) {
if r.off == r.size {
return 0, io.EOF
}
b := r.data[r.off]
r.off++
return b, nil
} | go | func (r *buffer) ReadByte() (byte, error) {
if r.off == r.size {
return 0, io.EOF
}
b := r.data[r.off]
r.off++
return b, nil
} | [
"func",
"(",
"r",
"*",
"buffer",
")",
"ReadByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"if",
"r",
".",
"off",
"==",
"r",
".",
"size",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"b",
":=",
"r",
".",
"data",
"[",
"r",
".",
"off",
"]",
"\n",
"r",
".",
"off",
"++",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] | // ReadByte provides the flate.Decompressor ReadByte method. | [
"ReadByte",
"provides",
"the",
"flate",
".",
"Decompressor",
"ReadByte",
"method",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L101-L108 |
14,985 | biogo/hts | bgzf/reader.go | readLimited | func (r *buffer) readLimited(n int, src *countReader) error {
if r.hasData() {
panic("bgzf: read into non-empty buffer")
}
r.off = 0
var err error
r.size, err = io.ReadFull(src, r.data[:n])
return err
} | go | func (r *buffer) readLimited(n int, src *countReader) error {
if r.hasData() {
panic("bgzf: read into non-empty buffer")
}
r.off = 0
var err error
r.size, err = io.ReadFull(src, r.data[:n])
return err
} | [
"func",
"(",
"r",
"*",
"buffer",
")",
"readLimited",
"(",
"n",
"int",
",",
"src",
"*",
"countReader",
")",
"error",
"{",
"if",
"r",
".",
"hasData",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"r",
".",
"off",
"=",
"0",
"\n",
"var",
"err",
"error",
"\n",
"r",
".",
"size",
",",
"err",
"=",
"io",
".",
"ReadFull",
"(",
"src",
",",
"r",
".",
"data",
"[",
":",
"n",
"]",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // readLimited reads n bytes into the buffer from the given source. | [
"readLimited",
"reads",
"n",
"bytes",
"into",
"the",
"buffer",
"from",
"the",
"given",
"source",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L117-L125 |
14,986 | biogo/hts | bgzf/reader.go | Read | func (d *decompressor) Read(b []byte) (int, error) {
if d.buf.hasData() {
return d.buf.Read(b)
}
return d.cr.Read(b)
} | go | func (d *decompressor) Read(b []byte) (int, error) {
if d.buf.hasData() {
return d.buf.Read(b)
}
return d.cr.Read(b)
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"d",
".",
"buf",
".",
"hasData",
"(",
")",
"{",
"return",
"d",
".",
"buf",
".",
"Read",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"d",
".",
"cr",
".",
"Read",
"(",
"b",
")",
"\n",
"}"
] | // Read provides the Read method for the decompressor's gzip.Reader. | [
"Read",
"provides",
"the",
"Read",
"method",
"for",
"the",
"decompressor",
"s",
"gzip",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L153-L158 |
14,987 | biogo/hts | bgzf/reader.go | ReadByte | func (d *decompressor) ReadByte() (byte, error) {
if d.buf.hasData() {
return d.buf.ReadByte()
}
return d.cr.ReadByte()
} | go | func (d *decompressor) ReadByte() (byte, error) {
if d.buf.hasData() {
return d.buf.ReadByte()
}
return d.cr.ReadByte()
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"ReadByte",
"(",
")",
"(",
"byte",
",",
"error",
")",
"{",
"if",
"d",
".",
"buf",
".",
"hasData",
"(",
")",
"{",
"return",
"d",
".",
"buf",
".",
"ReadByte",
"(",
")",
"\n",
"}",
"\n",
"return",
"d",
".",
"cr",
".",
"ReadByte",
"(",
")",
"\n",
"}"
] | // ReadByte provides the ReadByte method for the decompressor's gzip.Reader. | [
"ReadByte",
"provides",
"the",
"ReadByte",
"method",
"for",
"the",
"decompressor",
"s",
"gzip",
".",
"Reader",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L161-L166 |
14,988 | biogo/hts | bgzf/reader.go | lazyBlock | func (d *decompressor) lazyBlock() {
if d.blk == nil {
if w, ok := d.owner.cache.(Wrapper); ok {
d.blk = w.Wrap(&block{owner: d.owner})
} else {
d.blk = &block{owner: d.owner}
}
return
}
if !d.blk.ownedBy(d.owner) {
d.blk.setOwner(d.owner)
}
} | go | func (d *decompressor) lazyBlock() {
if d.blk == nil {
if w, ok := d.owner.cache.(Wrapper); ok {
d.blk = w.Wrap(&block{owner: d.owner})
} else {
d.blk = &block{owner: d.owner}
}
return
}
if !d.blk.ownedBy(d.owner) {
d.blk.setOwner(d.owner)
}
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"lazyBlock",
"(",
")",
"{",
"if",
"d",
".",
"blk",
"==",
"nil",
"{",
"if",
"w",
",",
"ok",
":=",
"d",
".",
"owner",
".",
"cache",
".",
"(",
"Wrapper",
")",
";",
"ok",
"{",
"d",
".",
"blk",
"=",
"w",
".",
"Wrap",
"(",
"&",
"block",
"{",
"owner",
":",
"d",
".",
"owner",
"}",
")",
"\n",
"}",
"else",
"{",
"d",
".",
"blk",
"=",
"&",
"block",
"{",
"owner",
":",
"d",
".",
"owner",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"!",
"d",
".",
"blk",
".",
"ownedBy",
"(",
"d",
".",
"owner",
")",
"{",
"d",
".",
"blk",
".",
"setOwner",
"(",
"d",
".",
"owner",
")",
"\n",
"}",
"\n",
"}"
] | // lazyBlock conditionally creates a ready to use Block. | [
"lazyBlock",
"conditionally",
"creates",
"a",
"ready",
"to",
"use",
"Block",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L169-L181 |
14,989 | biogo/hts | bgzf/reader.go | acquireHead | func (d *decompressor) acquireHead() {
d.wg.Add(1)
d.cr = <-d.owner.head
} | go | func (d *decompressor) acquireHead() {
d.wg.Add(1)
d.cr = <-d.owner.head
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"acquireHead",
"(",
")",
"{",
"d",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"d",
".",
"cr",
"=",
"<-",
"d",
".",
"owner",
".",
"head",
"\n",
"}"
] | // acquireHead gains the read head from the decompressor's owner. | [
"acquireHead",
"gains",
"the",
"read",
"head",
"from",
"the",
"decompressor",
"s",
"owner",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L184-L187 |
14,990 | biogo/hts | bgzf/reader.go | releaseHead | func (d *decompressor) releaseHead() {
d.owner.head <- d.cr
d.cr = nil // Defensively zero the reader.
} | go | func (d *decompressor) releaseHead() {
d.owner.head <- d.cr
d.cr = nil // Defensively zero the reader.
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"releaseHead",
"(",
")",
"{",
"d",
".",
"owner",
".",
"head",
"<-",
"d",
".",
"cr",
"\n",
"d",
".",
"cr",
"=",
"nil",
"// Defensively zero the reader.",
"\n",
"}"
] | // releaseHead releases the read head back to the decompressor's owner. | [
"releaseHead",
"releases",
"the",
"read",
"head",
"back",
"to",
"the",
"decompressor",
"s",
"owner",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L190-L193 |
14,991 | biogo/hts | bgzf/reader.go | wait | func (d *decompressor) wait() (Block, error) {
d.wg.Wait()
blk := d.blk
d.blk = nil
return blk, d.err
} | go | func (d *decompressor) wait() (Block, error) {
d.wg.Wait()
blk := d.blk
d.blk = nil
return blk, d.err
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"wait",
"(",
")",
"(",
"Block",
",",
"error",
")",
"{",
"d",
".",
"wg",
".",
"Wait",
"(",
")",
"\n",
"blk",
":=",
"d",
".",
"blk",
"\n",
"d",
".",
"blk",
"=",
"nil",
"\n",
"return",
"blk",
",",
"d",
".",
"err",
"\n",
"}"
] | // wait waits for the current member to be decompressed or fail, and returns
// the resulting error state. | [
"wait",
"waits",
"for",
"the",
"current",
"member",
"to",
"be",
"decompressed",
"or",
"fail",
"and",
"returns",
"the",
"resulting",
"error",
"state",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L197-L202 |
14,992 | biogo/hts | bgzf/reader.go | nextBlockAt | func (d *decompressor) nextBlockAt(off int64, rs io.ReadSeeker) *decompressor {
d.err = nil
for {
exists, next := d.owner.cacheHasBlockFor(off)
if !exists {
break
}
off = next
}
d.lazyBlock()
d.acquireHead()
defer d.releaseHead()
if d.cr.offset() != off {
if rs == nil {
// It should not be possible for the expected next block base
// to be out of register with the count reader unless Seek
// has been called, so we know the base reader must be an
// io.ReadSeeker.
var ok bool
rs, ok = d.owner.r.(io.ReadSeeker)
if !ok {
panic("bgzf: unexpected offset without seek")
}
}
d.err = d.cr.seek(rs, off)
if d.err != nil {
d.wg.Done()
return d
}
}
d.blk.setBase(d.cr.offset())
d.err = d.readMember()
if d.err != nil {
d.wg.Done()
return d
}
d.blk.setHeader(d.gz.Header)
d.gz.Header = gzip.Header{} // Prevent retention of header field in next use.
// Decompress data into the decompressor's Block.
go func() {
d.err = d.blk.readFrom(&d.gz)
d.wg.Done()
}()
return d
} | go | func (d *decompressor) nextBlockAt(off int64, rs io.ReadSeeker) *decompressor {
d.err = nil
for {
exists, next := d.owner.cacheHasBlockFor(off)
if !exists {
break
}
off = next
}
d.lazyBlock()
d.acquireHead()
defer d.releaseHead()
if d.cr.offset() != off {
if rs == nil {
// It should not be possible for the expected next block base
// to be out of register with the count reader unless Seek
// has been called, so we know the base reader must be an
// io.ReadSeeker.
var ok bool
rs, ok = d.owner.r.(io.ReadSeeker)
if !ok {
panic("bgzf: unexpected offset without seek")
}
}
d.err = d.cr.seek(rs, off)
if d.err != nil {
d.wg.Done()
return d
}
}
d.blk.setBase(d.cr.offset())
d.err = d.readMember()
if d.err != nil {
d.wg.Done()
return d
}
d.blk.setHeader(d.gz.Header)
d.gz.Header = gzip.Header{} // Prevent retention of header field in next use.
// Decompress data into the decompressor's Block.
go func() {
d.err = d.blk.readFrom(&d.gz)
d.wg.Done()
}()
return d
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"nextBlockAt",
"(",
"off",
"int64",
",",
"rs",
"io",
".",
"ReadSeeker",
")",
"*",
"decompressor",
"{",
"d",
".",
"err",
"=",
"nil",
"\n",
"for",
"{",
"exists",
",",
"next",
":=",
"d",
".",
"owner",
".",
"cacheHasBlockFor",
"(",
"off",
")",
"\n",
"if",
"!",
"exists",
"{",
"break",
"\n",
"}",
"\n",
"off",
"=",
"next",
"\n",
"}",
"\n\n",
"d",
".",
"lazyBlock",
"(",
")",
"\n\n",
"d",
".",
"acquireHead",
"(",
")",
"\n",
"defer",
"d",
".",
"releaseHead",
"(",
")",
"\n\n",
"if",
"d",
".",
"cr",
".",
"offset",
"(",
")",
"!=",
"off",
"{",
"if",
"rs",
"==",
"nil",
"{",
"// It should not be possible for the expected next block base",
"// to be out of register with the count reader unless Seek",
"// has been called, so we know the base reader must be an",
"// io.ReadSeeker.",
"var",
"ok",
"bool",
"\n",
"rs",
",",
"ok",
"=",
"d",
".",
"owner",
".",
"r",
".",
"(",
"io",
".",
"ReadSeeker",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"d",
".",
"err",
"=",
"d",
".",
"cr",
".",
"seek",
"(",
"rs",
",",
"off",
")",
"\n",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"d",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"return",
"d",
"\n",
"}",
"\n",
"}",
"\n\n",
"d",
".",
"blk",
".",
"setBase",
"(",
"d",
".",
"cr",
".",
"offset",
"(",
")",
")",
"\n",
"d",
".",
"err",
"=",
"d",
".",
"readMember",
"(",
")",
"\n",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"d",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"return",
"d",
"\n",
"}",
"\n",
"d",
".",
"blk",
".",
"setHeader",
"(",
"d",
".",
"gz",
".",
"Header",
")",
"\n",
"d",
".",
"gz",
".",
"Header",
"=",
"gzip",
".",
"Header",
"{",
"}",
"// Prevent retention of header field in next use.",
"\n\n",
"// Decompress data into the decompressor's Block.",
"go",
"func",
"(",
")",
"{",
"d",
".",
"err",
"=",
"d",
".",
"blk",
".",
"readFrom",
"(",
"&",
"d",
".",
"gz",
")",
"\n",
"d",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"d",
"\n",
"}"
] | // nextBlockAt makes the decompressor ready for reading decompressed data
// from its Block. It checks if there is a cached Block for the nextBase,
// otherwise it seeks to the correct location if decompressor is not
// correctly positioned, and then reads the compressed data and fills
// the decompressed Block.
// After nextBlockAt returns without error, the decompressor's Block
// holds a valid gzip.Header and base offset. | [
"nextBlockAt",
"makes",
"the",
"decompressor",
"ready",
"for",
"reading",
"decompressed",
"data",
"from",
"its",
"Block",
".",
"It",
"checks",
"if",
"there",
"is",
"a",
"cached",
"Block",
"for",
"the",
"nextBase",
"otherwise",
"it",
"seeks",
"to",
"the",
"correct",
"location",
"if",
"decompressor",
"is",
"not",
"correctly",
"positioned",
"and",
"then",
"reads",
"the",
"compressed",
"data",
"and",
"fills",
"the",
"decompressed",
"Block",
".",
"After",
"nextBlockAt",
"returns",
"without",
"error",
"the",
"decompressor",
"s",
"Block",
"holds",
"a",
"valid",
"gzip",
".",
"Header",
"and",
"base",
"offset",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L214-L264 |
14,993 | biogo/hts | bgzf/reader.go | expectedMemberSize | func expectedMemberSize(h gzip.Header) int {
i := bytes.Index(h.Extra, bgzfExtraPrefix)
if i < 0 || i+5 >= len(h.Extra) {
return -1
}
return (int(h.Extra[i+4]) | int(h.Extra[i+5])<<8) + 1
} | go | func expectedMemberSize(h gzip.Header) int {
i := bytes.Index(h.Extra, bgzfExtraPrefix)
if i < 0 || i+5 >= len(h.Extra) {
return -1
}
return (int(h.Extra[i+4]) | int(h.Extra[i+5])<<8) + 1
} | [
"func",
"expectedMemberSize",
"(",
"h",
"gzip",
".",
"Header",
")",
"int",
"{",
"i",
":=",
"bytes",
".",
"Index",
"(",
"h",
".",
"Extra",
",",
"bgzfExtraPrefix",
")",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
"+",
"5",
">=",
"len",
"(",
"h",
".",
"Extra",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"(",
"int",
"(",
"h",
".",
"Extra",
"[",
"i",
"+",
"4",
"]",
")",
"|",
"int",
"(",
"h",
".",
"Extra",
"[",
"i",
"+",
"5",
"]",
")",
"<<",
"8",
")",
"+",
"1",
"\n",
"}"
] | // expectedMemberSize returns the size of the BGZF conformant gzip member.
// It returns -1 if no BGZF block size field is found. | [
"expectedMemberSize",
"returns",
"the",
"size",
"of",
"the",
"BGZF",
"conformant",
"gzip",
"member",
".",
"It",
"returns",
"-",
"1",
"if",
"no",
"BGZF",
"block",
"size",
"field",
"is",
"found",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L268-L274 |
14,994 | biogo/hts | bgzf/reader.go | readMember | func (d *decompressor) readMember() error {
// Set the decompressor to Read from the underlying flate.Reader
// and mark the starting offset from which the underlying reader
// was used.
d.buf.reset()
mark := d.cr.offset()
err := d.gz.Reset(d)
if err != nil {
d.blockSize = -1
return err
}
d.blockSize = expectedMemberSize(d.gz.Header)
if d.blockSize < 0 {
return ErrNoBlockSize
}
skipped := int(d.cr.offset() - mark)
need := d.blockSize - skipped
if need == 0 {
return io.EOF
} else if need < 0 {
return ErrCorrupt
}
// Read compressed data into the decompressor buffer until the
// underlying flate.Reader is positioned at the end of the gzip
// member in which the readMember call was made.
return d.buf.readLimited(need, d.cr)
} | go | func (d *decompressor) readMember() error {
// Set the decompressor to Read from the underlying flate.Reader
// and mark the starting offset from which the underlying reader
// was used.
d.buf.reset()
mark := d.cr.offset()
err := d.gz.Reset(d)
if err != nil {
d.blockSize = -1
return err
}
d.blockSize = expectedMemberSize(d.gz.Header)
if d.blockSize < 0 {
return ErrNoBlockSize
}
skipped := int(d.cr.offset() - mark)
need := d.blockSize - skipped
if need == 0 {
return io.EOF
} else if need < 0 {
return ErrCorrupt
}
// Read compressed data into the decompressor buffer until the
// underlying flate.Reader is positioned at the end of the gzip
// member in which the readMember call was made.
return d.buf.readLimited(need, d.cr)
} | [
"func",
"(",
"d",
"*",
"decompressor",
")",
"readMember",
"(",
")",
"error",
"{",
"// Set the decompressor to Read from the underlying flate.Reader",
"// and mark the starting offset from which the underlying reader",
"// was used.",
"d",
".",
"buf",
".",
"reset",
"(",
")",
"\n",
"mark",
":=",
"d",
".",
"cr",
".",
"offset",
"(",
")",
"\n\n",
"err",
":=",
"d",
".",
"gz",
".",
"Reset",
"(",
"d",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"d",
".",
"blockSize",
"=",
"-",
"1",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"d",
".",
"blockSize",
"=",
"expectedMemberSize",
"(",
"d",
".",
"gz",
".",
"Header",
")",
"\n",
"if",
"d",
".",
"blockSize",
"<",
"0",
"{",
"return",
"ErrNoBlockSize",
"\n",
"}",
"\n",
"skipped",
":=",
"int",
"(",
"d",
".",
"cr",
".",
"offset",
"(",
")",
"-",
"mark",
")",
"\n",
"need",
":=",
"d",
".",
"blockSize",
"-",
"skipped",
"\n",
"if",
"need",
"==",
"0",
"{",
"return",
"io",
".",
"EOF",
"\n",
"}",
"else",
"if",
"need",
"<",
"0",
"{",
"return",
"ErrCorrupt",
"\n",
"}",
"\n\n",
"// Read compressed data into the decompressor buffer until the",
"// underlying flate.Reader is positioned at the end of the gzip",
"// member in which the readMember call was made.",
"return",
"d",
".",
"buf",
".",
"readLimited",
"(",
"need",
",",
"d",
".",
"cr",
")",
"\n",
"}"
] | // readMember buffers the gzip member starting the current decompressor offset. | [
"readMember",
"buffers",
"the",
"gzip",
"member",
"starting",
"the",
"current",
"decompressor",
"offset",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L277-L306 |
14,995 | biogo/hts | bgzf/reader.go | NewReader | func NewReader(r io.Reader, rd int) (*Reader, error) {
if rd == 0 {
rd = runtime.GOMAXPROCS(0)
}
bg := &Reader{
r: r,
head: make(chan *countReader, 1),
}
bg.head <- newCountReader(r)
// Make work loop control structures.
if rd > 1 {
bg.waiting = make(chan *decompressor, rd)
bg.working = make(chan *decompressor, rd)
bg.control = make(chan int64, 1)
bg.done = make(chan struct{})
for ; rd > 1; rd-- {
bg.waiting <- &decompressor{owner: bg}
}
}
// Read the first block now so we can fail before
// the first Read call if there is a problem.
bg.dec = &decompressor{owner: bg}
blk, err := bg.dec.nextBlockAt(0, nil).wait()
if err != nil {
return nil, err
}
bg.current = blk
bg.Header = bg.current.header()
// Set up work loop if rd was > 1.
if bg.control != nil {
bg.waiting <- bg.dec
bg.dec = nil
next := blk.NextBase()
go func() {
defer func() {
bg.mu.Lock()
bg.cache = nil
bg.mu.Unlock()
close(bg.done)
}()
for dec := range bg.waiting {
var open bool
if next < 0 {
next, open = <-bg.control
if !open {
return
}
} else {
select {
case next, open = <-bg.control:
if !open {
return
}
default:
}
}
dec.nextBlockAt(next, nil)
next = dec.blk.NextBase()
bg.working <- dec
}
}()
}
return bg, nil
} | go | func NewReader(r io.Reader, rd int) (*Reader, error) {
if rd == 0 {
rd = runtime.GOMAXPROCS(0)
}
bg := &Reader{
r: r,
head: make(chan *countReader, 1),
}
bg.head <- newCountReader(r)
// Make work loop control structures.
if rd > 1 {
bg.waiting = make(chan *decompressor, rd)
bg.working = make(chan *decompressor, rd)
bg.control = make(chan int64, 1)
bg.done = make(chan struct{})
for ; rd > 1; rd-- {
bg.waiting <- &decompressor{owner: bg}
}
}
// Read the first block now so we can fail before
// the first Read call if there is a problem.
bg.dec = &decompressor{owner: bg}
blk, err := bg.dec.nextBlockAt(0, nil).wait()
if err != nil {
return nil, err
}
bg.current = blk
bg.Header = bg.current.header()
// Set up work loop if rd was > 1.
if bg.control != nil {
bg.waiting <- bg.dec
bg.dec = nil
next := blk.NextBase()
go func() {
defer func() {
bg.mu.Lock()
bg.cache = nil
bg.mu.Unlock()
close(bg.done)
}()
for dec := range bg.waiting {
var open bool
if next < 0 {
next, open = <-bg.control
if !open {
return
}
} else {
select {
case next, open = <-bg.control:
if !open {
return
}
default:
}
}
dec.nextBlockAt(next, nil)
next = dec.blk.NextBase()
bg.working <- dec
}
}()
}
return bg, nil
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
",",
"rd",
"int",
")",
"(",
"*",
"Reader",
",",
"error",
")",
"{",
"if",
"rd",
"==",
"0",
"{",
"rd",
"=",
"runtime",
".",
"GOMAXPROCS",
"(",
"0",
")",
"\n",
"}",
"\n",
"bg",
":=",
"&",
"Reader",
"{",
"r",
":",
"r",
",",
"head",
":",
"make",
"(",
"chan",
"*",
"countReader",
",",
"1",
")",
",",
"}",
"\n",
"bg",
".",
"head",
"<-",
"newCountReader",
"(",
"r",
")",
"\n\n",
"// Make work loop control structures.",
"if",
"rd",
">",
"1",
"{",
"bg",
".",
"waiting",
"=",
"make",
"(",
"chan",
"*",
"decompressor",
",",
"rd",
")",
"\n",
"bg",
".",
"working",
"=",
"make",
"(",
"chan",
"*",
"decompressor",
",",
"rd",
")",
"\n",
"bg",
".",
"control",
"=",
"make",
"(",
"chan",
"int64",
",",
"1",
")",
"\n",
"bg",
".",
"done",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"for",
";",
"rd",
">",
"1",
";",
"rd",
"--",
"{",
"bg",
".",
"waiting",
"<-",
"&",
"decompressor",
"{",
"owner",
":",
"bg",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Read the first block now so we can fail before",
"// the first Read call if there is a problem.",
"bg",
".",
"dec",
"=",
"&",
"decompressor",
"{",
"owner",
":",
"bg",
"}",
"\n",
"blk",
",",
"err",
":=",
"bg",
".",
"dec",
".",
"nextBlockAt",
"(",
"0",
",",
"nil",
")",
".",
"wait",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"bg",
".",
"current",
"=",
"blk",
"\n",
"bg",
".",
"Header",
"=",
"bg",
".",
"current",
".",
"header",
"(",
")",
"\n\n",
"// Set up work loop if rd was > 1.",
"if",
"bg",
".",
"control",
"!=",
"nil",
"{",
"bg",
".",
"waiting",
"<-",
"bg",
".",
"dec",
"\n",
"bg",
".",
"dec",
"=",
"nil",
"\n",
"next",
":=",
"blk",
".",
"NextBase",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"bg",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"bg",
".",
"cache",
"=",
"nil",
"\n",
"bg",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"close",
"(",
"bg",
".",
"done",
")",
"\n",
"}",
"(",
")",
"\n",
"for",
"dec",
":=",
"range",
"bg",
".",
"waiting",
"{",
"var",
"open",
"bool",
"\n",
"if",
"next",
"<",
"0",
"{",
"next",
",",
"open",
"=",
"<-",
"bg",
".",
"control",
"\n",
"if",
"!",
"open",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"{",
"select",
"{",
"case",
"next",
",",
"open",
"=",
"<-",
"bg",
".",
"control",
":",
"if",
"!",
"open",
"{",
"return",
"\n",
"}",
"\n",
"default",
":",
"}",
"\n",
"}",
"\n",
"dec",
".",
"nextBlockAt",
"(",
"next",
",",
"nil",
")",
"\n",
"next",
"=",
"dec",
".",
"blk",
".",
"NextBase",
"(",
")",
"\n",
"bg",
".",
"working",
"<-",
"dec",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"bg",
",",
"nil",
"\n",
"}"
] | // NewReader returns a new BGZF reader.
//
// The number of concurrent read decompressors is specified by rd.
// If rd is 0, GOMAXPROCS concurrent will be created. The returned
// Reader should be closed after use to avoid leaking resources. | [
"NewReader",
"returns",
"a",
"new",
"BGZF",
"reader",
".",
"The",
"number",
"of",
"concurrent",
"read",
"decompressors",
"is",
"specified",
"by",
"rd",
".",
"If",
"rd",
"is",
"0",
"GOMAXPROCS",
"concurrent",
"will",
"be",
"created",
".",
"The",
"returned",
"Reader",
"should",
"be",
"closed",
"after",
"use",
"to",
"avoid",
"leaking",
"resources",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L368-L436 |
14,996 | biogo/hts | bgzf/reader.go | Seek | func (bg *Reader) Seek(off Offset) error {
rs, ok := bg.r.(io.ReadSeeker)
if !ok {
return ErrNotASeeker
}
if off.File != bg.current.Base() || !bg.current.hasData() {
ok := bg.cacheSwap(off.File)
if !ok {
var dec *decompressor
if bg.dec != nil {
dec = bg.dec
} else {
select {
case dec = <-bg.waiting:
case dec = <-bg.working:
blk, err := dec.wait()
if err == nil {
bg.keep(blk)
}
}
}
bg.current, bg.err = dec.
using(bg.current).
nextBlockAt(off.File, rs).
wait()
if bg.dec == nil {
select {
case <-bg.control:
default:
}
bg.control <- bg.current.NextBase()
bg.waiting <- dec
}
bg.Header = bg.current.header()
if bg.err != nil {
return bg.err
}
}
}
bg.err = bg.current.seek(int64(off.Block))
if bg.err == nil {
bg.lastChunk = Chunk{Begin: off, End: off}
}
return bg.err
} | go | func (bg *Reader) Seek(off Offset) error {
rs, ok := bg.r.(io.ReadSeeker)
if !ok {
return ErrNotASeeker
}
if off.File != bg.current.Base() || !bg.current.hasData() {
ok := bg.cacheSwap(off.File)
if !ok {
var dec *decompressor
if bg.dec != nil {
dec = bg.dec
} else {
select {
case dec = <-bg.waiting:
case dec = <-bg.working:
blk, err := dec.wait()
if err == nil {
bg.keep(blk)
}
}
}
bg.current, bg.err = dec.
using(bg.current).
nextBlockAt(off.File, rs).
wait()
if bg.dec == nil {
select {
case <-bg.control:
default:
}
bg.control <- bg.current.NextBase()
bg.waiting <- dec
}
bg.Header = bg.current.header()
if bg.err != nil {
return bg.err
}
}
}
bg.err = bg.current.seek(int64(off.Block))
if bg.err == nil {
bg.lastChunk = Chunk{Begin: off, End: off}
}
return bg.err
} | [
"func",
"(",
"bg",
"*",
"Reader",
")",
"Seek",
"(",
"off",
"Offset",
")",
"error",
"{",
"rs",
",",
"ok",
":=",
"bg",
".",
"r",
".",
"(",
"io",
".",
"ReadSeeker",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ErrNotASeeker",
"\n",
"}",
"\n\n",
"if",
"off",
".",
"File",
"!=",
"bg",
".",
"current",
".",
"Base",
"(",
")",
"||",
"!",
"bg",
".",
"current",
".",
"hasData",
"(",
")",
"{",
"ok",
":=",
"bg",
".",
"cacheSwap",
"(",
"off",
".",
"File",
")",
"\n",
"if",
"!",
"ok",
"{",
"var",
"dec",
"*",
"decompressor",
"\n",
"if",
"bg",
".",
"dec",
"!=",
"nil",
"{",
"dec",
"=",
"bg",
".",
"dec",
"\n",
"}",
"else",
"{",
"select",
"{",
"case",
"dec",
"=",
"<-",
"bg",
".",
"waiting",
":",
"case",
"dec",
"=",
"<-",
"bg",
".",
"working",
":",
"blk",
",",
"err",
":=",
"dec",
".",
"wait",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"bg",
".",
"keep",
"(",
"blk",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"bg",
".",
"current",
",",
"bg",
".",
"err",
"=",
"dec",
".",
"using",
"(",
"bg",
".",
"current",
")",
".",
"nextBlockAt",
"(",
"off",
".",
"File",
",",
"rs",
")",
".",
"wait",
"(",
")",
"\n",
"if",
"bg",
".",
"dec",
"==",
"nil",
"{",
"select",
"{",
"case",
"<-",
"bg",
".",
"control",
":",
"default",
":",
"}",
"\n",
"bg",
".",
"control",
"<-",
"bg",
".",
"current",
".",
"NextBase",
"(",
")",
"\n",
"bg",
".",
"waiting",
"<-",
"dec",
"\n",
"}",
"\n",
"bg",
".",
"Header",
"=",
"bg",
".",
"current",
".",
"header",
"(",
")",
"\n",
"if",
"bg",
".",
"err",
"!=",
"nil",
"{",
"return",
"bg",
".",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"bg",
".",
"err",
"=",
"bg",
".",
"current",
".",
"seek",
"(",
"int64",
"(",
"off",
".",
"Block",
")",
")",
"\n",
"if",
"bg",
".",
"err",
"==",
"nil",
"{",
"bg",
".",
"lastChunk",
"=",
"Chunk",
"{",
"Begin",
":",
"off",
",",
"End",
":",
"off",
"}",
"\n",
"}",
"\n\n",
"return",
"bg",
".",
"err",
"\n",
"}"
] | // Seek performs a seek operation to the given virtual offset. | [
"Seek",
"performs",
"a",
"seek",
"operation",
"to",
"the",
"given",
"virtual",
"offset",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L446-L493 |
14,997 | biogo/hts | bgzf/reader.go | Close | func (bg *Reader) Close() error {
if bg.control != nil {
close(bg.control)
close(bg.waiting)
<-bg.done
}
if bg.err == io.EOF {
return nil
}
return bg.err
} | go | func (bg *Reader) Close() error {
if bg.control != nil {
close(bg.control)
close(bg.waiting)
<-bg.done
}
if bg.err == io.EOF {
return nil
}
return bg.err
} | [
"func",
"(",
"bg",
"*",
"Reader",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"bg",
".",
"control",
"!=",
"nil",
"{",
"close",
"(",
"bg",
".",
"control",
")",
"\n",
"close",
"(",
"bg",
".",
"waiting",
")",
"\n",
"<-",
"bg",
".",
"done",
"\n",
"}",
"\n",
"if",
"bg",
".",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"bg",
".",
"err",
"\n",
"}"
] | // Close closes the reader and releases resources. | [
"Close",
"closes",
"the",
"reader",
"and",
"releases",
"resources",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L505-L515 |
14,998 | biogo/hts | bgzf/reader.go | nextBlock | func (bg *Reader) nextBlock() error {
base := bg.current.NextBase()
ok := bg.cacheSwap(base)
if ok {
bg.Header = bg.current.header()
return nil
}
var err error
if bg.dec != nil {
bg.dec.using(bg.current).nextBlockAt(base, nil)
bg.current, err = bg.dec.wait()
} else {
var ok bool
for i := 0; i < cap(bg.working); i++ {
dec := <-bg.working
bg.current, err = dec.wait()
bg.waiting <- dec
if bg.current.Base() == base {
ok = true
break
}
if err == nil {
bg.keep(bg.current)
bg.current = nil
}
}
if !ok {
panic("bgzf: unexpected block")
}
}
if err != nil {
return err
}
// Only set header if there was no error.
h := bg.current.header()
if bg.current.isMagicBlock() {
// TODO(kortschak): Do this more carefully. It may be that
// someone actually has extra data in this field that we are
// clobbering.
bg.Header.Extra = h.Extra
} else {
bg.Header = h
}
return nil
} | go | func (bg *Reader) nextBlock() error {
base := bg.current.NextBase()
ok := bg.cacheSwap(base)
if ok {
bg.Header = bg.current.header()
return nil
}
var err error
if bg.dec != nil {
bg.dec.using(bg.current).nextBlockAt(base, nil)
bg.current, err = bg.dec.wait()
} else {
var ok bool
for i := 0; i < cap(bg.working); i++ {
dec := <-bg.working
bg.current, err = dec.wait()
bg.waiting <- dec
if bg.current.Base() == base {
ok = true
break
}
if err == nil {
bg.keep(bg.current)
bg.current = nil
}
}
if !ok {
panic("bgzf: unexpected block")
}
}
if err != nil {
return err
}
// Only set header if there was no error.
h := bg.current.header()
if bg.current.isMagicBlock() {
// TODO(kortschak): Do this more carefully. It may be that
// someone actually has extra data in this field that we are
// clobbering.
bg.Header.Extra = h.Extra
} else {
bg.Header = h
}
return nil
} | [
"func",
"(",
"bg",
"*",
"Reader",
")",
"nextBlock",
"(",
")",
"error",
"{",
"base",
":=",
"bg",
".",
"current",
".",
"NextBase",
"(",
")",
"\n",
"ok",
":=",
"bg",
".",
"cacheSwap",
"(",
"base",
")",
"\n",
"if",
"ok",
"{",
"bg",
".",
"Header",
"=",
"bg",
".",
"current",
".",
"header",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"bg",
".",
"dec",
"!=",
"nil",
"{",
"bg",
".",
"dec",
".",
"using",
"(",
"bg",
".",
"current",
")",
".",
"nextBlockAt",
"(",
"base",
",",
"nil",
")",
"\n",
"bg",
".",
"current",
",",
"err",
"=",
"bg",
".",
"dec",
".",
"wait",
"(",
")",
"\n",
"}",
"else",
"{",
"var",
"ok",
"bool",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"cap",
"(",
"bg",
".",
"working",
")",
";",
"i",
"++",
"{",
"dec",
":=",
"<-",
"bg",
".",
"working",
"\n",
"bg",
".",
"current",
",",
"err",
"=",
"dec",
".",
"wait",
"(",
")",
"\n",
"bg",
".",
"waiting",
"<-",
"dec",
"\n",
"if",
"bg",
".",
"current",
".",
"Base",
"(",
")",
"==",
"base",
"{",
"ok",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"bg",
".",
"keep",
"(",
"bg",
".",
"current",
")",
"\n",
"bg",
".",
"current",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Only set header if there was no error.",
"h",
":=",
"bg",
".",
"current",
".",
"header",
"(",
")",
"\n",
"if",
"bg",
".",
"current",
".",
"isMagicBlock",
"(",
")",
"{",
"// TODO(kortschak): Do this more carefully. It may be that",
"// someone actually has extra data in this field that we are",
"// clobbering.",
"bg",
".",
"Header",
".",
"Extra",
"=",
"h",
".",
"Extra",
"\n",
"}",
"else",
"{",
"bg",
".",
"Header",
"=",
"h",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // nextBlock swaps the current decompressed block for the next
// in the stream. If the block is available from the cache
// no additional work is done, otherwise a decompressor is
// used or waited on. | [
"nextBlock",
"swaps",
"the",
"current",
"decompressed",
"block",
"for",
"the",
"next",
"in",
"the",
"stream",
".",
"If",
"the",
"block",
"is",
"available",
"from",
"the",
"cache",
"no",
"additional",
"work",
"is",
"done",
"otherwise",
"a",
"decompressor",
"is",
"used",
"or",
"waited",
"on",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L567-L614 |
14,999 | biogo/hts | bgzf/reader.go | cacheSwap | func (bg *Reader) cacheSwap(base int64) bool {
bg.mu.RLock()
defer bg.mu.RUnlock()
if bg.cache == nil {
return false
}
blk, err := bg.cachedBlockFor(base)
if err != nil {
return false
}
if blk != nil {
// TODO(kortschak): Under some conditions, e.g. FIFO
// cache we will be discarding a non-nil evicted Block.
// Consider retaining these in a sync.Pool.
bg.cachePut(bg.current)
bg.current = blk
return true
}
var retained bool
bg.current, retained = bg.cachePut(bg.current)
if retained {
bg.current = nil
}
return false
} | go | func (bg *Reader) cacheSwap(base int64) bool {
bg.mu.RLock()
defer bg.mu.RUnlock()
if bg.cache == nil {
return false
}
blk, err := bg.cachedBlockFor(base)
if err != nil {
return false
}
if blk != nil {
// TODO(kortschak): Under some conditions, e.g. FIFO
// cache we will be discarding a non-nil evicted Block.
// Consider retaining these in a sync.Pool.
bg.cachePut(bg.current)
bg.current = blk
return true
}
var retained bool
bg.current, retained = bg.cachePut(bg.current)
if retained {
bg.current = nil
}
return false
} | [
"func",
"(",
"bg",
"*",
"Reader",
")",
"cacheSwap",
"(",
"base",
"int64",
")",
"bool",
"{",
"bg",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"bg",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"bg",
".",
"cache",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"blk",
",",
"err",
":=",
"bg",
".",
"cachedBlockFor",
"(",
"base",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"blk",
"!=",
"nil",
"{",
"// TODO(kortschak): Under some conditions, e.g. FIFO",
"// cache we will be discarding a non-nil evicted Block.",
"// Consider retaining these in a sync.Pool.",
"bg",
".",
"cachePut",
"(",
"bg",
".",
"current",
")",
"\n",
"bg",
".",
"current",
"=",
"blk",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"var",
"retained",
"bool",
"\n",
"bg",
".",
"current",
",",
"retained",
"=",
"bg",
".",
"cachePut",
"(",
"bg",
".",
"current",
")",
"\n",
"if",
"retained",
"{",
"bg",
".",
"current",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // cacheSwap attempts to swap the current Block for a cached Block
// for the given base offset. It returns true if successful. | [
"cacheSwap",
"attempts",
"to",
"swap",
"the",
"current",
"Block",
"for",
"a",
"cached",
"Block",
"for",
"the",
"given",
"base",
"offset",
".",
"It",
"returns",
"true",
"if",
"successful",
"."
] | aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64 | https://github.com/biogo/hts/blob/aafaa03b4ed961cf75d5f7ace0d70cf9fa921f64/bgzf/reader.go#L618-L643 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.