yat  0.21pre
Fasta.h
1 #ifndef _theplu_yat_omic_fasta
2 #define _theplu_yat_omic_fasta
3 
4 // $Id: Fasta.h 4019 2020-11-06 01:55:37Z peter $
5 //
6 // Copyright (C) 2016, 2017, 2018, 2020 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 <htslib/faidx.h>
22 
23 #include <iosfwd>
24 #include <map>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 namespace theplu {
30 namespace yat {
31 namespace omic {
32 
41  class Fasta
42  {
43  public:
53  Fasta(const std::string& fn);
54 
58  bool present(const std::string& name) const;
59 
63  std::string name(size_t i) const;
64 
68  int nseq(void) const;
69 
75  int sequence_length(const std::string& name) const;
76 
86  class Sequence
87  {
88  public:
90  typedef const char* const_iterator;
91 
95  const_iterator begin(void) const;
96 
100  const_iterator end(void) const;
101 
105  int size(void) const;
106 
110  char operator[](size_t i) const;
111  private:
112  friend class Fasta;
113  friend Sequence reverse_complement(const Fasta::Sequence&);
114  std::shared_ptr<char> seq_;
115  int size_;
116  };
117 
121  Sequence sequence(const std::string& chr) const;
122 
131  Sequence sequence(const std::string& chr, int beg, int end) const;
132 
133  private:
134  std::shared_ptr<faidx_t> faidx_;
135  // using compiler generated copy
136  //FastaIndex(const FastaIndex& other);
137  //FastaIndex& operator=(const FastaIndex& rhs);
138  void fetch(Sequence& seq, const std::string& chr, int begin, int end) const;
139  // throw exception; called when incorrect chr is passed
140  void throw_unknown_chr(const std::string&) const;
141  };
142 
143 
151  Fasta::Sequence reverse_complement(const Fasta::Sequence& sequence);
152 
160  std::ostream& operator<<(std::ostream& os, const Fasta::Sequence&);
161 
162 }}}
163 #endif
Fasta(const std::string &fn)
The Department of Theoretical Physics namespace as we define it.
int sequence_length(const std::string &name) const
bool present(const std::string &name) const
const char * const_iterator
const iterator is a const char*
Definition: Fasta.h:90
const_iterator end(void) const
std::string name(size_t i) const
char operator[](size_t i) const
wrapper class around struct faidx_t in libhts
Definition: Fasta.h:41
Sequence sequence(const std::string &chr) const
const_iterator begin(void) const
int nseq(void) const

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14