SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
segment.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_SEGMENT_HPP__
27 #define SHORE_IO_SEGMENT_HPP__
28 
29 #include <iostream>
30 #include <string>
31 
34 #include "shore/stream/streams.hpp"
35 #include "shore/fmtio/text.hpp"
36 
37 namespace shore {
38 
41 {
42  private:
43 
44  bool m_is_gff;
45 
46  shore::row_reader m_reader;
47  shore::segment m_current;
48 
49  void parse();
50 
51  public:
52 
53  typedef shore::segment current_type;
54 
55  segment_reader(const std::string &fn);
56 
57  segment_reader(const std::string &fn,
58  const std::string &id,const std::string &chr,
59  const std::string &pos,
60  const std::string &strand,const std::string &size,
61  const std::string &end=std::string());
62 
63  segment_reader(std::istream *const in,const bool is_gff=false);
64 
65  segment_reader(std::istream *const in,
66  const std::string &id,const std::string &chr,
67  const std::string &pos,
68  const std::string &strand,const std::string &size,
69  const std::string &end=std::string());
70 
71  const shore::segment &current() const;
72  bool has_data();
73  void next();
74 
75  const std::string &current_line() const;
76  const std::string& get_header() const;
77 
78  bool is_gff() const;
79  bool with_id();
80  bool with_strand();
81 };
82 
85 
88 {
89  public:
90 
91  struct config
92  {
93  std::string filename;
94  std::ostream *streamptr;
95  bool wstrand;
96  bool wsize;
97  bool wcovminmax;
98  bool wp;
99 
100  config(const std::string &fn=std::string(),
101  std::ostream *ostr=0,
102  bool strand=true,bool size=true,
103  bool covminmax=false,bool p=false)
104  :filename(fn),streamptr(ostr),
105  wstrand(strand),wsize(size),wcovminmax(covminmax),wp(p)
106  {}
107  };
108 
109  private:
110 
111  shore::ostreams m_os;
112 
113  config m_conf;
114 
115  bool m_initialized;
116  size_t m_numwritten;
117 
118  public:
119 
120  typedef shore::segment append_type;
121 
122  segment_writer(const config &conf);
123  segment_writer(const std::string &fn,const bool strand=true,const bool size=true);
124  segment_writer(std::ostream *const os,const bool strand=true,const bool size=true);
125  ~segment_writer();
126 
127  void init(const bool covminmax,const bool p);
128 
129  void append(const shore::segment &seg);
130  void flush();
131 };
132 
135 
136 } // namespace
137 
138 #endif // SHORE_IO_SEGMENT_HPP__
139