source: trunk/yat/omic/BamReadFilter.h @ 3081

Last change on this file since 3081 was 3081, checked in by Peter, 8 years ago

make BamReadFilter? an adaptable functor by inheriting from std::unary_function; also add missing doxygen since tag

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef theplu_yat_omic_bam_read_filter
2#define theplu_yat_omic_bam_read_filter
3
4// $Id: BamReadFilter.h 3081 2013-09-18 07:48:08Z peter $
5
6/*
7  Copyright (C) 2013 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "config_bam.h"
26#include YAT_BAM_HEADER
27
28#include <functional>
29
30namespace theplu {
31namespace yat {
32namespace omic {
33
34  class BamRead;
35
36  /**
37     \brief Filter bam reads
38
39     Class is specifically designed to be used with
40     boost::filter_iterator. The code below for example
41     \code
42     InBamFile in("example.bam");
43     BamReadIterator begin(in);
44     BamReadIterator end;
45     BamReadFilter filter(20, 0);
46     some_algo(make_filter_iterator(filter, begin, end),
47               make_filter_iterator(filter, end));
48     \endcode
49     iterates over all read with mapping quality 20 or greater.
50
51     \since new in yat 0.11
52   */
53  class BamReadFilter : public std::unary_function<const BamRead&, bool>
54  {
55  public:
56    /**
57       Create a functor which accepts reads with mapping quality \a
58       mapQ (or greater), flag must be unset in bits described by a \a
59       filter_flags, and flag must be set in bits described by \a
60       required_flags.
61     */
62    BamReadFilter(unsigned char mapQ, unsigned int filtered_flags=BAM_DEF_MASK,
63                  unsigned int required_flags=0);
64
65    /**
66       return true if 1) bam mapping quality is at least mapQ AND 2)
67       bam flags & filter_flags == 0 (no filter bit set) AND 3) bam
68       flags & required_flags == required_flags (all req bits set)
69    */
70    bool operator()(const yat::omic::BamRead& bam) const;
71  private:
72    unsigned char mapQ_;
73    unsigned int filtered_;
74    unsigned int required_;
75  };
76
77}}}
78#endif
Note: See TracBrowser for help on using the repository browser.