yat
0.11.3pre
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
yat
omic
BamFile.h
1
#ifndef theplu_yat_omic_bam_file
2
#define theplu_yat_omic_bam_file
3
4
// $Id: BamFile.h 3078 2013-09-11 01:48:10Z peter $
5
6
/*
7
Copyright (C) 2012, 2013 Peter Johansson
8
9
This file is part of the yat library, http://dev.thep.lu.se/yat
10
11
The yat library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU General Public License as
13
published by the Free Software Foundation; either version 3 of the
14
License, or (at your option) any later version.
15
16
The yat library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
General Public License for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*/
24
25
#include "BamHeader.h"
26
#include "BamRead.h"
27
#include "config_bam.h"
28
29
#include "yat/utility/Exception.h"
30
#include "yat/utility/yat_assert.h"
31
32
#include YAT_SAM_HEADER
33
34
#include <boost/utility.hpp>
35
36
#include <cstdio>
37
#include <sstream>
38
#include <stdexcept>
39
#include <string>
40
41
namespace
theplu {
42
namespace
yat {
43
namespace
omic {
44
50
template
<
typename
Derived>
51
class
BamFile
: boost::noncopyable
52
{
53
typedef
Derived derived_type;
54
public
:
58
BamFile
(
void
);
59
65
virtual
~BamFile
(
void
);
66
70
void
close
(
void
);
71
75
bool
is_open
(
void
)
const
;
76
protected
:
82
void
open_base
(
const
std::string& fn,
const
std::string& mode,
83
const
void
* aux);
87
samfile_t*
sf_
;
88
94
const
std::string&
filename
(
void
)
const
{
return
filename_; }
95
private
:
96
std::string filename_;
97
};
98
99
105
class
InBamFile
:
public
BamFile
<InBamFile>
106
{
107
typedef
BamFile<InBamFile>
super_t
;
108
public
:
112
InBamFile
(
void
);
113
121
explicit
InBamFile
(
const
std::string& fn);
122
126
virtual
~InBamFile
(
void
);
127
131
const
BamHeader
&
header
(
void
)
const
;
132
141
const
bam_index_t*
index
(
void
)
const
;
142
150
void
open
(
const
std::string& fn);
151
157
bool
read
(
BamRead
&
read
);
158
164
bool
read
(
BamRead
& read, bam_iter_t iter);
165
private
:
166
BamHeader
header_;
167
mutable
bam_index_t* index_;
168
};
169
170
176
class
OutBamFile
:
public
BamFile
<OutBamFile>
177
{
178
typedef
BamFile<OutBamFile>
super_t
;
179
public
:
183
OutBamFile
(
void
);
184
192
OutBamFile
(
const
std::string&,
const
BamHeader
& header);
193
203
void
open
(
const
std::string& fn,
const
BamHeader
& hdr);
204
210
void
write
(
const
BamRead
& read);
211
private
:
212
};
213
214
215
// template implementations
216
template
<
class
Derived>
217
BamFile<Derived>::BamFile
(
void
)
218
: sf_(NULL) {}
219
220
221
template
<
class
Derived>
222
BamFile<Derived>::~BamFile
(
void
)
223
{
224
close();
225
}
226
227
228
template
<
class
Derived>
229
void
BamFile<Derived>::close
(
void
)
230
{
231
samclose(sf_);
232
sf_ = NULL;
233
}
234
235
236
template
<
class
Derived>
237
bool
BamFile<Derived>::is_open
(
void
)
const
238
{
239
return
sf_;
240
}
241
242
243
template
<
class
Derived>
244
void
BamFile<Derived>::open_base
(
const
std::string& fn,
245
const
std::string& mode,
246
const
void
* aux)
247
{
248
filename_ = fn;
249
YAT_ASSERT(!sf_);
250
sf_ = samopen(fn.c_str(), mode.c_str(), aux);
251
if
(!sf_) {
252
std::ostringstream ss;
253
ss <<
"failed open '"
<< fn <<
"'"
;
254
throw
utility::runtime_error
(ss.str());
255
}
256
}
257
258
}}}
259
#endif
Generated on Sat May 24 2014 03:33:05 for yat by
1.8.2