yat  0.14.5pre
Fasta.h
1 #ifndef _theplu_yat_omic_fasta
2 #define _theplu_yat_omic_fasta
3 
4 // $Id: Fasta.h 3475 2016-03-08 08:05:33Z peter $
5 //
6 // Copyright (C) 2016 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 
133  Sequence sequence(const std::string& chr, int beg, int end) const;
134 
135  private:
136  boost::shared_ptr<faidx_t> faidx_;
137  // using compiler generated copy
138  //FastaIndex(const FastaIndex& other);
139  //FastaIndex& operator=(const FastaIndex& rhs);
140  void fetch(Sequence& seq, const std::string& chr, int begin, int end) const;
141  // throw exception; called when incorrect chr is passed
142  void throw_unknown_chr(const std::string&) const;
143 #ifndef YAT_HAVE_HTSLIB
144  std::vector<std::string> name_;
145  std::map<std::string, int> size_;
146 #endif
147  };
148 
149 
157  Fasta::Sequence reverse_complement(const Fasta::Sequence& sequence);
158 }}}
159 #endif
Fasta(const std::string &fn)
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 Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5