libStatGen Software  1
SamFlag.h
00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __SAM_FLAG_H__
00019 #define __SAM_FLAG_H__
00020 
00021 #include <stdint.h>
00022 
00023 #ifdef DUPLICATE
00024 #undef DUPLICATE
00025 #endif
00026 
00027 /// Class for extracting information from a SAM Flag.
00028 class SamFlag
00029 {
00030 public:
00031     ///////////////////////
00032     /// @name  Constants for parsing a flag.
00033     //@{
00034     static const int16_t PAIRED              = 0x0001;
00035     static const int16_t PROPER_PAIR         = 0x0002;
00036     static const int16_t UNMAPPED            = 0x0004;
00037     static const int16_t MATE_UNMAPPED       = 0x0008;
00038     static const int16_t REVERSE             = 0x0010;
00039     static const int16_t MATE_REVERSED       = 0x0020;
00040     static const int16_t FIRST_READ          = 0x0040;
00041     static const int16_t SECOND_READ         = 0x0080;
00042     static const int16_t SECONDARY_ALIGNMENT = 0x0100;
00043     static const int16_t FAILED_QUALITY      = 0x0200;
00044     static const int16_t DUPLICATE           = 0x0400;
00045     static const int16_t SUPPLEMENTARY_ALIGNMENT = 0x0800;
00046     static const int16_t FRAGMENT_INFO       = 0x00C0;
00047     static const int16_t FRAGMENT_SHIFT      = 6;
00048     //@}
00049 
00050     ///////////////////////
00051     /// @name  Static methods for determining the contents of a flag.
00052     //@{
00053     static inline bool isMapped(uint16_t flag) {return(!(flag & UNMAPPED));}
00054     static inline bool isMateMapped(uint16_t flag) {return(!(flag & MATE_UNMAPPED));}
00055 
00056     static inline bool isPaired(uint16_t flag) {return(flag & PAIRED);}
00057     static inline bool isReverse(uint16_t flag) {return(flag & REVERSE);}
00058     static inline bool isMateReverse(uint16_t flag) {return(flag & MATE_REVERSED);}
00059     static inline bool isProperPair(uint16_t flag) 
00060     {
00061         // Proper pair is only applicable if also paired.
00062         return(isPaired(flag) && (flag & PROPER_PAIR));
00063     }
00064     static inline bool isDuplicate(uint16_t flag) {return(flag & DUPLICATE);}
00065     static inline bool isQCFailure(uint16_t flag) {return(flag & FAILED_QUALITY);}
00066 
00067     static inline bool isSecondary(uint16_t flag) {return(flag & SECONDARY_ALIGNMENT);}
00068 
00069     /// Return if it is the first fragment or not
00070     /// (if FIRST_READ is set and SECOND_READ is not).
00071     static inline bool isFirstFragment(uint16_t flag) 
00072     {
00073         // first fragment if FIRST_READ is set and SECOND_READ is not.
00074         return((flag & FIRST_READ) && !(flag & SECOND_READ));
00075     }
00076     /// Return if it is the last fragment or not
00077     /// (if FIRST_READ is not set and SECOND_READ is).
00078     static inline bool isLastFragment(uint16_t flag) 
00079     {
00080         // last fragment if FIRST_READ is not set and SECOND_READ is set.
00081         return(!(flag & FIRST_READ) && (flag & SECOND_READ));
00082     }
00083     /// Return if it is a middle fragment or not
00084     /// (if FIRST_READ is set and SECOND_READ is also set).
00085     static inline bool isMidFragment(uint16_t flag) 
00086     {
00087         // mid fragment if both FIRST_READ and SECOND_READ are set.
00088         return((flag & FIRST_READ) && (flag & SECOND_READ));
00089     }
00090     /// Return if it is an unknown fragment fragment or not
00091     /// (if FIRST_READ is not set and SECOND_READ is also not set).
00092     static inline bool isUnknownFragment(uint16_t flag) 
00093     {
00094         // unknown fragment index if neither FIRST_READ nor SECOND_READ are not.
00095         return(!(flag & FIRST_READ) && !(flag & SECOND_READ));
00096     }
00097 
00098     static inline uint8_t getFragmentType(uint16_t flag)
00099     {
00100         return((flag & FRAGMENT_INFO) >> FRAGMENT_SHIFT);
00101     }
00102 
00103     /// Mark the passed in flag as unmapped.
00104     static inline void setUnmapped(uint16_t& flag) { flag |= UNMAPPED;}
00105     /// Mark the passed in flag as not duplicate.
00106     static inline void setNotDuplicate(uint16_t& flag) { flag ^= DUPLICATE;}
00107     /// Mark the passed in flag as not duplicate.
00108     static inline void setDuplicate(uint16_t& flag) { flag |= DUPLICATE;}
00109     //@}
00110 
00111 private:
00112     SamFlag();
00113 };
00114 
00115 
00116 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends