libStatGen Software 1
SamFlag.h
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __SAM_FLAG_H__
19#define __SAM_FLAG_H__
20
21#include <stdint.h>
22
23#ifdef DUPLICATE
24#undef DUPLICATE
25#endif
26
27/// Class for extracting information from a SAM Flag.
29{
30public:
31 ///////////////////////
32 /// @name Constants for parsing a flag.
33 //@{
34 static const int16_t PAIRED = 0x0001;
35 static const int16_t PROPER_PAIR = 0x0002;
36 static const int16_t UNMAPPED = 0x0004;
37 static const int16_t MATE_UNMAPPED = 0x0008;
38 static const int16_t REVERSE = 0x0010;
39 static const int16_t MATE_REVERSED = 0x0020;
40 static const int16_t FIRST_READ = 0x0040;
41 static const int16_t SECOND_READ = 0x0080;
42 static const int16_t SECONDARY_ALIGNMENT = 0x0100;
43 static const int16_t FAILED_QUALITY = 0x0200;
44 static const int16_t DUPLICATE = 0x0400;
45 static const int16_t SUPPLEMENTARY_ALIGNMENT = 0x0800;
46 static const int16_t FRAGMENT_INFO = 0x00C0;
47 static const int16_t FRAGMENT_SHIFT = 6;
48 //@}
49
50 ///////////////////////
51 /// @name Static methods for determining the contents of a flag.
52 //@{
53 static inline bool isMapped(uint16_t flag) {return(!(flag & UNMAPPED));}
54 static inline bool isMateMapped(uint16_t flag) {return(!(flag & MATE_UNMAPPED));}
55
56 static inline bool isPaired(uint16_t flag) {return(flag & PAIRED);}
57 static inline bool isReverse(uint16_t flag) {return(flag & REVERSE);}
58 static inline bool isMateReverse(uint16_t flag) {return(flag & MATE_REVERSED);}
59 static inline bool isProperPair(uint16_t flag)
60 {
61 // Proper pair is only applicable if also paired.
62 return(isPaired(flag) && (flag & PROPER_PAIR));
63 }
64 static inline bool isDuplicate(uint16_t flag) {return(flag & DUPLICATE);}
65 static inline bool isQCFailure(uint16_t flag) {return(flag & FAILED_QUALITY);}
66
67 static inline bool isSecondary(uint16_t flag) {return(flag & SECONDARY_ALIGNMENT);}
68
69 /// Return if it is the first fragment or not
70 /// (if FIRST_READ is set and SECOND_READ is not).
71 static inline bool isFirstFragment(uint16_t flag)
72 {
73 // first fragment if FIRST_READ is set and SECOND_READ is not.
74 return((flag & FIRST_READ) && !(flag & SECOND_READ));
75 }
76 /// Return if it is the last fragment or not
77 /// (if FIRST_READ is not set and SECOND_READ is).
78 static inline bool isLastFragment(uint16_t flag)
79 {
80 // last fragment if FIRST_READ is not set and SECOND_READ is set.
81 return(!(flag & FIRST_READ) && (flag & SECOND_READ));
82 }
83 /// Return if it is a middle fragment or not
84 /// (if FIRST_READ is set and SECOND_READ is also set).
85 static inline bool isMidFragment(uint16_t flag)
86 {
87 // mid fragment if both FIRST_READ and SECOND_READ are set.
88 return((flag & FIRST_READ) && (flag & SECOND_READ));
89 }
90 /// Return if it is an unknown fragment fragment or not
91 /// (if FIRST_READ is not set and SECOND_READ is also not set).
92 static inline bool isUnknownFragment(uint16_t flag)
93 {
94 // unknown fragment index if neither FIRST_READ nor SECOND_READ are not.
95 return(!(flag & FIRST_READ) && !(flag & SECOND_READ));
96 }
97
98 static inline uint8_t getFragmentType(uint16_t flag)
99 {
100 return((flag & FRAGMENT_INFO) >> FRAGMENT_SHIFT);
101 }
102
103 /// Mark the passed in flag as unmapped.
104 static inline void setUnmapped(uint16_t& flag) { flag |= UNMAPPED;}
105 /// Mark the passed in flag as not duplicate.
106 static inline void setNotDuplicate(uint16_t& flag) { flag ^= DUPLICATE;}
107 /// Mark the passed in flag as not duplicate.
108 static inline void setDuplicate(uint16_t& flag) { flag |= DUPLICATE;}
109 //@}
110
111private:
112 SamFlag();
113};
114
115
116#endif
Class for extracting information from a SAM Flag.
Definition: SamFlag.h:29
static void setNotDuplicate(uint16_t &flag)
Mark the passed in flag as not duplicate.
Definition: SamFlag.h:106
static bool isUnknownFragment(uint16_t flag)
Return if it is an unknown fragment fragment or not (if FIRST_READ is not set and SECOND_READ is also...
Definition: SamFlag.h:92
static bool isLastFragment(uint16_t flag)
Return if it is the last fragment or not (if FIRST_READ is not set and SECOND_READ is).
Definition: SamFlag.h:78
static void setDuplicate(uint16_t &flag)
Mark the passed in flag as not duplicate.
Definition: SamFlag.h:108
static bool isFirstFragment(uint16_t flag)
Return if it is the first fragment or not (if FIRST_READ is set and SECOND_READ is not).
Definition: SamFlag.h:71
static bool isMidFragment(uint16_t flag)
Return if it is a middle fragment or not (if FIRST_READ is set and SECOND_READ is also set).
Definition: SamFlag.h:85
static void setUnmapped(uint16_t &flag)
Mark the passed in flag as unmapped.
Definition: SamFlag.h:104