1 #ifndef theplu_yat_omic_bam_file 2 #define theplu_yat_omic_bam_file 25 #include "BamHeader.h" 27 #include "config_bam.h" 29 #include "yat/utility/Exception.h" 30 #include "yat/utility/FileUtil.h" 31 #include "yat/utility/yat_assert.h" 33 #include YAT_SAM_HEADER 35 #include <boost/utility.hpp> 51 template<
typename Derived>
54 typedef Derived derived_type;
97 void open_base(
const std::string& fn,
const std::string& mode,
100 #ifndef YAT_HAVE_HTSLIB 107 typedef samfile_t samFile;
120 const std::string&
filename(
void)
const {
return filename_; }
123 std::string filename_;
149 typedef bam_index_t index_type;
164 explicit InBamFile(
const std::string& fn);
174 void build_index(
void)
const;
189 const index_type* index(
void)
const;
194 uint64_t n_mapped(
int tid)
const;
201 uint64_t n_unmapped(
int tid)
const;
206 uint64_t n_no_coordinate(
void)
const;
215 void open(
const std::string& fn);
234 bool read(
BamRead& read, hts_itr_t* iter);
236 bool read(
BamRead& read, bam_iter_t iter);
239 uint64_t get_idx_stat(
int tid,
bool return_mapped)
const;
243 mutable index_type* index_;
280 unsigned int compression);
287 void build_index(
void)
const;
298 void open(
const std::string& fn,
const BamHeader& hdr);
314 void open(
const std::string& fn,
const BamHeader& hdr,
315 unsigned int compression);
324 void write(
const BamRead& read);
336 virtual ~
error(
void)
throw();
340 const BamRead& read(
void)
const;
346 void open(
const std::string& fn,
const std::string& mode,
353 template<
class Derived>
358 template<
class Derived>
365 template<
class Derived>
368 #ifdef YAT_HAVE_HTSLIB 369 int res = bam_index_build(filename_.c_str(), 0);
371 int res = bam_index_build(filename_.c_str());
374 std::ostringstream msg;
375 msg <<
"failed building index file '" << filename_ <<
".bai': ";
377 msg <<
"failed to build index";
379 msg <<
"failed to open file '" << filename_ <<
"'";
381 msg <<
"failed to save file";
387 template<
class Derived>
402 template<
class Derived>
409 template<
class Derived>
416 template<
class Derived>
418 const std::string& mode,
424 YAT_ASSERT(aux==NULL);
425 sf_ = sam_open(fn.c_str(), mode.c_str());
427 sf_ = samopen(fn.c_str(), mode.c_str(), aux);
430 std::ostringstream ss;
431 ss <<
"failed open '" << fn <<
"'";
bool exists(void) const
Check whether file exists.
The Department of Theoretical Physics namespace as we define it.
void open_base(const std::string &fn, const std::string &mode, const void *aux)
Definition: BamFile.h:417
const std::string & filename(void) const
filename of bam file
Definition: BamFile.h:120
Error thrown from OutBamFile::write(const BamRead&) at failure.
Definition: BamFile.h:329
BamFile(void)
Definition: BamFile.h:354
Class holding a bam query.
Definition: BamRead.h:53
bool is_open(void) const
Definition: BamFile.h:403
Class used for all runtime error detected within yat library.
Definition: Exception.h:38
samFile * sf_
Definition: BamFile.h:113
void build_index_base(void) const
Definition: BamFile.h:366
Class to report errors associated with IO operations.
Definition: Exception.h:109
bool have_index(void) const
Definition: BamFile.h:410
void close(void)
close file
Definition: BamFile.h:388
virtual ~BamFile(void)
Destructor.
Definition: BamFile.h:359
Definition: BamFile.h:252
Definition: BamFile.h:132
hts_idx_t index_type
Definition: BamFile.h:147
Checking file/directory existence and access permissions.
Definition: FileUtil.h:43