Debian Codegraph @

sam/flag.go

raw symbols SCIP
1 // Copyright ©2012 The bíogo Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package sam
6
7 // A Flags represents a BAM record's alignment FLAG field.
8 type Flags uint16
9
10 const (
11 Paired Flags = 1 << iota // The read is paired in sequencing, no matter whether it is mapped in a pair.
12 ProperPair // The read is mapped in a proper pair.
13 Unmapped // The read itself is unmapped; conflictive with ProperPair.
14 MateUnmapped // The mate is unmapped.
15 Reverse // The read is mapped to the reverse strand.
16 MateReverse // The mate is mapped to the reverse strand.
17 Read1 // This is read1.
18 Read2 // This is read2.
19 Secondary // Not primary alignment.
20 QCFail // QC failure.
21 Duplicate // Optical or PCR duplicate.
22 Supplementary // Supplementary alignment, indicates alignment is part of a chimeric alignment.
23 )
24
25 // String representation of BAM alignment flags:
26 //
27 // 0x001 - p - Paired
28 // 0x002 - P - ProperPair
29 // 0x004 - u - Unmapped
30 // 0x008 - U - MateUnmapped
31 // 0x010 - r - Reverse
32 // 0x020 - R - MateReverse
33 // 0x040 - 1 - Read1
34 // 0x080 - 2 - Read2
35 // 0x100 - s - Secondary
36 // 0x200 - f - QCFail
37 // 0x400 - d - Duplicate
38 // 0x800 - S - Supplementary
39 //
40 // Note that flag bits are represented high order to the right.
41 func (f Flags) String() string {
42 // If 0x01 is unset, no assumptions can be made about 0x02, 0x08, 0x20, 0x40 and 0x80
43 const pairedMask = ProperPair | MateUnmapped | MateReverse | MateReverse | Read1 | Read2
44 if f&1 == 0 {
45 f &^= pairedMask
46 }
47
48 const flags = "pPuUrR12sfdS"
49
50 b := make([]byte, len(flags))
51 for i, c := range flags {
52 if f&(1<<uint(i)) != 0 {
53 b[i] = byte(c)
54 } else {
55 b[i] = '-'
56 }
57 }
58
59 return string(b)
60 }