yat  0.15.2pre
Fasta.h
1 #ifndef _theplu_yat_omic_fasta
2 #define _theplu_yat_omic_fasta
3 
4 // $Id: Fasta.h 3702 2017-10-04 06:41:25Z peter $
5 //
6 // Copyright (C) 2016, 2017 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 this program. 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 <map>
29 #include <string>
30 #include <vector>
31 
32 namespace theplu {
33 namespace yat {
34 namespace omic {
35 
44  class Fasta
45  {
46  public:
56  Fasta(const std::string& fn);
57 
61  bool present(const std::string& name) const;
62 
66  std::string name(size_t i) const;
67 
71  int nseq(void) const;
72 
78  int sequence_length(const std::string& name) const;
79 
89  class Sequence
90  {
91  public:
93  typedef const char* const_iterator;
94 
98  const_iterator begin(void) const;
99 
103  const_iterator end(void) const;
104 
108  int size(void) const;
109 
113  char operator[](size_t i) const;
114  private:
115  friend class Fasta;
116  friend Sequence reverse_complement(const Fasta::Sequence&);
117  boost::shared_array<const char> seq_;
118  int size_;
119  };
120 
124  Sequence sequence(const std::string& chr) const;
125 
134  Sequence sequence(const std::string& chr, int beg, int end) const;
135 
136  private:
137  boost::shared_ptr<faidx_t> faidx_;
138  // using compiler generated copy
139  //FastaIndex(const FastaIndex& other);
140  //FastaIndex& operator=(const FastaIndex& rhs);
141  void fetch(Sequence& seq, const std::string& chr, int begin, int end) const;
142  // throw exception; called when incorrect chr is passed
143  void throw_unknown_chr(const std::string&) const;
144 #ifndef YAT_HAVE_HTSLIB
145  std::vector<std::string> name_;
146  std::map<std::string, int> size_;
147 #endif
148  };
149 
150 
158  Fasta::Sequence reverse_complement(const Fasta::Sequence& sequence);
159 }}}
160 #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:93
Sequence sequence(const std::string &chr) const
wrapper class around struct faidx_t in libhts
Definition: Fasta.h:44
int sequence_length(const std::string &name) const
std::string name(size_t i) const
bool present(const std::string &name) const

Generated on Fri Jul 13 2018 02:33:27 for yat by  doxygen 1.8.11