yat  0.16.4pre
Fasta.h
1 #ifndef _theplu_yat_omic_fasta
2 #define _theplu_yat_omic_fasta
3 
4 // $Id: Fasta.h 3792 2019-04-12 07:15:09Z peter $
5 //
6 // Copyright (C) 2016, 2017, 2018 Peter Johansson
7 //
8 // This program 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 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with yat. If not, see <http://www.gnu.org/licenses/>.
20 
21 #include "config_bam.h"
22 
23 #include YAT_FAIDX_HEADER
24 
25 #include <boost/shared_array.hpp>
26 #include <boost/shared_ptr.hpp>
27 
28 #include <iosfwd>
29 #include <map>
30 #include <string>
31 #include <vector>
32 
33 namespace theplu {
34 namespace yat {
35 namespace omic {
36 
45  class Fasta
46  {
47  public:
57  Fasta(const std::string& fn);
58 
62  bool present(const std::string& name) const;
63 
67  std::string name(size_t i) const;
68 
72  int nseq(void) const;
73 
79  int sequence_length(const std::string& name) const;
80 
90  class Sequence
91  {
92  public:
94  typedef const char* const_iterator;
95 
99  const_iterator begin(void) const;
100 
104  const_iterator end(void) const;
105 
109  int size(void) const;
110 
114  char operator[](size_t i) const;
115  private:
116  friend class Fasta;
117  friend Sequence reverse_complement(const Fasta::Sequence&);
118  boost::shared_array<const char> seq_;
119  int size_;
120  };
121 
125  Sequence sequence(const std::string& chr) const;
126 
135  Sequence sequence(const std::string& chr, int beg, int end) const;
136 
137  private:
138  boost::shared_ptr<faidx_t> faidx_;
139  // using compiler generated copy
140  //FastaIndex(const FastaIndex& other);
141  //FastaIndex& operator=(const FastaIndex& rhs);
142  void fetch(Sequence& seq, const std::string& chr, int begin, int end) const;
143  // throw exception; called when incorrect chr is passed
144  void throw_unknown_chr(const std::string&) const;
145 #ifndef YAT_HAVE_HTSLIB
146  std::vector<std::string> name_;
147  std::map<std::string, int> size_;
148 #endif
149  };
150 
151 
159  Fasta::Sequence reverse_complement(const Fasta::Sequence& sequence);
160 
168  std::ostream& operator<<(std::ostream& os, const Fasta::Sequence&);
169 
170 }}}
171 #endif
Fasta(const std::string &fn)
The Department of Theoretical Physics namespace as we define it.
char operator[](size_t i) const
const_iterator end(void) const
int nseq(void) const
const_iterator begin(void) const
const char * const_iterator
const iterator is a const char*
Definition: Fasta.h:94
Sequence sequence(const std::string &chr) const
wrapper class around struct faidx_t in libhts
Definition: Fasta.h:45
std::ostream & operator<<(std::ostream &os, const Fasta::Sequence &)
outpout operator for Fasta:Sequence
int sequence_length(const std::string &name) const
std::string name(size_t i) const
bool present(const std::string &name) const

Generated on Thu Dec 12 2019 03:12:08 for yat by  doxygen 1.8.11