1 /*
2    This file is part of the BOLT-LMM linear mixed model software package
3    developed by Po-Ru Loh.  Copyright (C) 2014-2019 Harvard University.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <vector>
20 #include <string>
21 #include <cstdio>
22 
23 #include "RestrictSnpSet.hpp"
24 #include "SnpData.hpp"
25 
26 namespace LMM {
27 
28   using std::vector;
29   using std::string;
30 
RestrictSnpSet(const string & restrictPartnerFile,bool _matchID,int Nautosomes)31   RestrictSnpSet::RestrictSnpSet(const string &restrictPartnerFile, bool _matchID, int Nautosomes) {
32       matchID = _matchID;
33       vector <SnpInfo> restrictSnps;
34       if (!restrictPartnerFile.empty()) {
35 	restrictSnps = SnpData::readBimFile(restrictPartnerFile, Nautosomes);
36 	for (uint64 m = 0; m < restrictSnps.size(); m++)
37 	  keys.insert(makeKey(restrictSnps[m]));
38       }
39     }
40 
makeKey(const SnpInfo & snp) const41   string RestrictSnpSet::makeKey(const SnpInfo &snp) const {
42     if (matchID) return snp.ID;
43     else {
44       char buf[20];
45       sprintf(buf, "%d,%d", snp.chrom, snp.physpos);
46       return string(buf);
47     }
48   }
49 
isAllowed(const SnpInfo & snp) const50   bool RestrictSnpSet::isAllowed(const SnpInfo &snp) const {
51     return keys.empty() || keys.find(makeKey(snp)) != keys.end();
52   }
53 
54 }
55