bpp-seq-omics  2.4.1
PlinkOutputMafIterator.h
Go to the documentation of this file.
1 //
2 // File: PlinkOutputMafIterator.h
3 // Authors: Julien Dutheil
4 // Created: Tue Dec 10 2015
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (2015)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _PLINKOUTPUTMAFITERATOR_H_
41 #define _PLINKOUTPUTMAFITERATOR_H_
42 
43 #include "MafIterator.h"
44 
45 //From the STL:
46 #include <iostream>
47 #include <string>
48 #include <deque>
49 
50 namespace bpp {
51 
57 {
58  private:
59  std::ostream* outputPed_;
60  std::ostream* outputMap_;
61  std::vector<std::string> species_;
62  std::string refSpecies_;
63  bool map3_;
64  std::vector<std::string> ped_;
65  std::string currentChr_;
66  size_t lastPosition_;
67  bool recodeChr_;
68  std::map<std::string, unsigned int> chrCodes_;
69  unsigned int currentCode_;
70 
71  public:
91  std::ostream* outPed,
92  std::ostream* outMap,
93  const std::vector<std::string>& species,
94  const std::string& reference,
95  bool map3 = false,
96  bool recodeChr = false) :
97  AbstractFilterMafIterator(iterator),
98  outputPed_(outPed), outputMap_(outMap), species_(species), refSpecies_(reference), map3_(map3),
99  ped_(species.size()), currentChr_(""), lastPosition_(0), recodeChr_(recodeChr), chrCodes_(), currentCode_(1)
100  {
101  init_();
102  }
103 
104  private:
107  outputPed_(iterator.outputPed_),
108  outputMap_(iterator.outputMap_),
109  species_(iterator.species_),
110  refSpecies_(iterator.refSpecies_),
111  map3_(iterator.map3_),
112  ped_(iterator.ped_),
113  currentChr_(iterator.currentChr_),
114  lastPosition_(iterator.lastPosition_),
115  recodeChr_(iterator.recodeChr_),
116  chrCodes_(iterator.chrCodes_),
117  currentCode_(iterator.currentCode_)
118  {}
119 
121  {
122  outputPed_ = iterator.outputPed_;
123  outputMap_ = iterator.outputMap_;
124  species_ = iterator.species_;
125  refSpecies_ = iterator.refSpecies_;
126  map3_ = iterator.map3_;
127  ped_ = iterator.ped_;
128  currentChr_ = iterator.currentChr_;
129  lastPosition_ = iterator.lastPosition_;
130  recodeChr_ = iterator.recodeChr_;
131  chrCodes_ = iterator.chrCodes_;
132  currentCode_ = iterator.currentCode_;
133  return *this;
134  }
135 
136 
137  public:
140  if (outputMap_ && currentBlock_)
143  writePedToFile_(*outputPed_); //Note we currently can output Map and no Ped, but not Ped without Map.
144  return currentBlock_;
145  }
146 
147  private:
148  void init_();
149  void parseBlock_(std::ostream& out, const MafBlock& block);
150  void writePedToFile_(std::ostream& out);
151 };
152 
153 } // end of namespace bpp.
154 
155 #endif //_PLINKOUTPUTMAFITERATOR_H_
Helper class for developping filter for maf blocks.
Definition: MafIterator.h:151
A synteny block data structure, the basic unit of a MAF alignement file.
Definition: MafBlock.h:57
Interface to loop over maf alignment blocks.
Definition: MafIterator.h:59
virtual MafBlock * nextBlock()=0
Get the next available alignment block.
This iterator outputs all biallelic SNPs in the PLINK format (ped and map files).
std::map< std::string, unsigned int > chrCodes_
std::vector< std::string > ped_
std::vector< std::string > species_
void parseBlock_(std::ostream &out, const MafBlock &block)
PlinkOutputMafIterator(MafIterator *iterator, std::ostream *outPed, std::ostream *outMap, const std::vector< std::string > &species, const std::string &reference, bool map3=false, bool recodeChr=false)
Build a new PlinkOutputMafIterator object.
PlinkOutputMafIterator(const PlinkOutputMafIterator &iterator)
void writePedToFile_(std::ostream &out)
PlinkOutputMafIterator & operator=(const PlinkOutputMafIterator &iterator)