SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
maplist.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_IO_MAPLIST_HPP__
27 #define SHORE_IO_MAPLIST_HPP__
28 
29 #include <iomanip>
30 #include <iostream>
31 #include <map>
32 #include <set>
33 #include <sstream>
34 #include <stdexcept>
35 #include <string>
36 #include <utility>
37 #include <vector>
38 
39 #include <boost/function.hpp>
40 
44 #include "shore/datatype/coor.hpp"
46 #include "shore/stream/streams.hpp"
47 #include "shore/fmtio/text.hpp"
48 
49 namespace shore {
50 
52 std::ostream& operator<<(std::ostream& os,const shore::alignment& en);
53 
56 {
57  private:
58 
59  typedef boost::function<void ()> tagfun_t;
61  tagfun_t *m_tagfuns;
62 
63  std::string::const_iterator m_tagbeg;
64  std::string::const_iterator m_tagend;
65 
66  template<typename Iterator>
67  static size_t th(Iterator s)
68  {
69  return (uint32_t(s[0])&127u)|((uint32_t(s[1])&127u)<<7);//|((uint32_t(s[2])&127u)<<14);
70  }
71 
72  protected:
73 
74  static const size_t MAXTAGS=128*128;
75 
76  shore::alignment::accessory *m_alignment_tags;
77 
80 
81  void parse_tags(std::string::const_iterator b,std::string::const_iterator e);
82 
83  void tagfun_invalid();
84  void tagfun_RGR();
85  void tagfun_MPQ();
86  void tagfun_ORI();
87  void tagfun_NUM();
88  void tagfun_NXP();
89  void tagfun_OCL();
90 };
91 
94 :public maplist_tags_parser
95 {
96  private:
97 
98  shore::alignment::InsertState m_insstate_conv[256];
99 
100  shore::basic_line_reader m_linereader;
101  std::string m_linebuf;
102 
104  std::string m_indexfile;
105 
106  std::string m_readgroup_default;
107  shore::alignment::InsertState m_pestate_default;
108 
109  void init();
110 
111  void parse(shore::alignment &f);
112 
114  void pe_legacy_compat(shore::alignment &f);
115 
116  void set_default_tags(shore::alignment &a);
117  void guess_default_tags(const std::string &fn);
118 
119  public:
120 
122 
123  basic_maplist_reader(const std::string &fn);
124  basic_maplist_reader(std::istream *const is);
125 
126  bool next(shore::alignment &a);
127 
128  const std::string& get_name() const;
129 
130  const std::string& current_line() const;
131 };
132 
135 :public maplist_tags_parser
136 {
137  private:
138 
139  shore::alignment::InsertState m_insstate_conv[256];
140 
141  shore::line_reader m_linereader;
142 
143  // alternating input buffers for sort verification
144  shore::alignment m_ft1;
145  shore::alignment m_ft2;
146 
147  bool m_hasdata;
148  bool m_useft1;
149 
150  // comparator for sort verification
152 
153  std::string m_indexfile;
154 
155  std::string m_readgroup_default;
156  shore::alignment::InsertState m_pestate_default;
157 
158 
159  void parse(shore::alignment &f);
160 
162  void pe_legacy_compat(shore::alignment &f);
163 
164  void set_default_tags(shore::alignment &a);
165  void guess_default_tags(const std::string &fn);
166 
167  public:
168 
170 
172 
173  const shore::alignment& current() const;
174 
175  bool has_data() const;
176 
177  void next();
178 
179  const std::string& filename() const;
180 
181  const std::string& current_line() const;
182 
183  void set_range(
184  const shore::refseq_coor& s,const shore::refseq_coor& e,const long maxrl=0l);
185 };
186 
189 
192 {
193  private:
194 
195  shore::ostreams m_out;
196 
197  maplist_writer();
198 
199  public:
200 
202 
203  maplist_writer(const std::string& fn=std::string("stdout"));
204  maplist_writer(std::ostream *const out);
205  void append(const shore::alignment& f);
206  void append(const shore::segment &f);
207  void flush();
208 };
209 
212 
213 } // namespace
214 
215 #endif // SHORE_IO_MAPLIST_HPP__
216