-
Notifications
You must be signed in to change notification settings - Fork 16
/
fieldtype.go
69 lines (61 loc) · 1.44 KB
/
fieldtype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 GRAIL, Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package bam
import (
"fmt"
)
// FieldType defines a sam.Record field. Each field is stored in a separate
// file.
type FieldType uint8
const (
// FieldCoord combines <sam.Reference.ID(), sam.Record.Pos>. They need to be
// read together when seeking to a specific coordinate.
FieldCoord FieldType = iota
// Rest of Field* stands for the sam.Record field with the same name.
FieldFlags
FieldMapq
FieldCigar
FieldMateRefID
FieldMatePos
FieldTempLen
FieldName
FieldSeq
FieldQual
FieldAux
// FieldInvalid is a sentinel
FieldInvalid
NumFields = int(FieldInvalid)
)
// FieldNames lists all the bam Field names.
var FieldNames = []string{
"coord",
"flags",
"mapq",
"cigar",
"materefid",
"matepos",
"templen",
"name",
"seq",
"qual",
"aux",
}
// String returns the name of the type. The name is used as part of the PAM
// filenames, so it shall not be changed.
func (f FieldType) String() string {
if int(f) < len(FieldNames) {
return FieldNames[f]
}
return fmt.Sprintf("Field%d", f)
}
// ParseFieldType converts a string to FieldType. For example, "cigar" will
// return FieldCigar.
func ParseFieldType(v string) (FieldType, error) {
for f, name := range FieldNames {
if name == v {
return FieldType(f), nil
}
}
return FieldAux, fmt.Errorf("%v: invalid PAM field type", v)
}