1 /*
2  *  Copyright (C) 2013  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 __VCF_RECORD_DISCARD_RULES_H__
19 #define __VCF_RECORD_DISCARD_RULES_H__
20 
21 #include <vector>
22 
23 #ifdef __GXX_EXPERIMENTAL_CXX0X__
24 #include <unordered_set>
25 #else
26 #include <set>
27 #endif
28 
29 #include <string>
30 #include "VcfHeader.h"
31 
32 typedef std::string vcfIDtype;
33 
34 
35 class VcfRecordDiscardRules
36 {
37 public:
VcfRecordDiscardRules()38     VcfRecordDiscardRules()
39         : myExcludeIDs(),
40           myIncludeIDs(),
41           myNumDiscarded(0)
42     {}
43 
~VcfRecordDiscardRules()44     ~VcfRecordDiscardRules()
45     {
46     }
47 
48     void reset();
49 
getNumDiscarded()50     int getNumDiscarded() { return(myNumDiscarded); }
clearNumDiscarded()51     void clearNumDiscarded() { myNumDiscarded = 0; }
52 
53     ///////////////////////
54     /// @name  Set the discard rules.
55     //@{
56     /// When reading records, skip all variants with the ids specified
57     /// in the passed in filename.
58     /// Returns false, if the file could not be read.
59     bool setExcludeIDs(const char* filename);
60 
61     /// When reading records, keep only variants with the ids specified
62     /// in the passed in filename.
63     /// Returns false, if the file could not be read.
64     bool setIncludeIDs(const char* filename);
65     //@}
66 
67 
68     ///////////////////////
69     /// @name  Check if a record should be kept.
70     //@{
71     /// Return whether or not to discard the record based on the id.
72     /// Returns true if it should be disarded, false if not.
73     bool discardForID(std::string& myID);
74     //@}
75 
76 private:
77 #ifdef __GXX_EXPERIMENTAL_CXX0X__
78     typedef std::unordered_set<vcfIDtype> IDList;
79 #else
80     typedef std::set<vcfIDtype> IDList;
81 #endif
82 
83     VcfRecordDiscardRules(const VcfRecordDiscardRules& vcfRecordDiscardRules);
84     VcfRecordDiscardRules& operator=(const VcfRecordDiscardRules& vcfRecordDiscardRules);
85 
86     bool setIDs(IDList& idlist, const char* filename);
87 
88     IDList myExcludeIDs;
89     IDList myIncludeIDs;
90     int myNumDiscarded;
91 };
92 
93 #endif
94