3762 |
19 Oct 18 |
peter |
1 |
#ifndef theplu_yat_omic_vcf_file |
3762 |
19 Oct 18 |
peter |
2 |
#define theplu_yat_omic_vcf_file |
3762 |
19 Oct 18 |
peter |
3 |
|
3762 |
19 Oct 18 |
peter |
// $Id$ |
3762 |
19 Oct 18 |
peter |
5 |
|
3762 |
19 Oct 18 |
peter |
6 |
/* |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2018, 2019, 2020, 2021 Peter Johansson |
3762 |
19 Oct 18 |
peter |
8 |
|
3762 |
19 Oct 18 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3762 |
19 Oct 18 |
peter |
10 |
|
3762 |
19 Oct 18 |
peter |
The yat library is free software; you can redistribute it and/or |
3762 |
19 Oct 18 |
peter |
modify it under the terms of the GNU General Public License as |
3762 |
19 Oct 18 |
peter |
published by the Free Software Foundation; either version 3 of the |
3762 |
19 Oct 18 |
peter |
License, or (at your option) any later version. |
3762 |
19 Oct 18 |
peter |
15 |
|
3762 |
19 Oct 18 |
peter |
The yat library is distributed in the hope that it will be useful, |
3762 |
19 Oct 18 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3762 |
19 Oct 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3762 |
19 Oct 18 |
peter |
General Public License for more details. |
3762 |
19 Oct 18 |
peter |
20 |
|
3762 |
19 Oct 18 |
peter |
You should have received a copy of the GNU General Public License |
3762 |
19 Oct 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3762 |
19 Oct 18 |
peter |
23 |
*/ |
3762 |
19 Oct 18 |
peter |
24 |
|
3823 |
16 Jul 19 |
peter |
25 |
#include "VcfHeader.h" |
3823 |
16 Jul 19 |
peter |
26 |
|
3764 |
22 Oct 18 |
peter |
27 |
#include <boost/noncopyable.hpp> |
3762 |
19 Oct 18 |
peter |
28 |
#include <boost/iostreams/filtering_stream.hpp> |
3762 |
19 Oct 18 |
peter |
29 |
|
3765 |
22 Oct 18 |
peter |
30 |
#include <fstream> |
3996 |
07 Oct 20 |
peter |
31 |
#include <memory> |
3762 |
19 Oct 18 |
peter |
32 |
#include <string> |
3762 |
19 Oct 18 |
peter |
33 |
|
3762 |
19 Oct 18 |
peter |
34 |
namespace theplu { |
3762 |
19 Oct 18 |
peter |
35 |
namespace yat { |
3762 |
19 Oct 18 |
peter |
36 |
namespace omic { |
3762 |
19 Oct 18 |
peter |
37 |
|
3789 |
04 Apr 19 |
peter |
38 |
class VCF; |
3789 |
04 Apr 19 |
peter |
39 |
|
3762 |
19 Oct 18 |
peter |
40 |
/** |
3762 |
19 Oct 18 |
peter |
\since New in yat 0.16 |
3762 |
19 Oct 18 |
peter |
42 |
*/ |
3764 |
22 Oct 18 |
peter |
43 |
class VcfFile : private boost::noncopyable |
3762 |
19 Oct 18 |
peter |
44 |
{ |
3762 |
19 Oct 18 |
peter |
45 |
public: |
3762 |
19 Oct 18 |
peter |
46 |
/** |
3762 |
19 Oct 18 |
peter |
\brief default constructor |
3762 |
19 Oct 18 |
peter |
48 |
*/ |
3762 |
19 Oct 18 |
peter |
49 |
VcfFile(void); |
3762 |
19 Oct 18 |
peter |
50 |
|
3762 |
19 Oct 18 |
peter |
51 |
/** |
3762 |
19 Oct 18 |
peter |
Opens file named \a fn. |
3762 |
19 Oct 18 |
peter |
53 |
|
3762 |
19 Oct 18 |
peter |
\see open |
3762 |
19 Oct 18 |
peter |
55 |
*/ |
3762 |
19 Oct 18 |
peter |
56 |
explicit VcfFile(const std::string& fn); |
3762 |
19 Oct 18 |
peter |
57 |
|
3762 |
19 Oct 18 |
peter |
58 |
/** |
3762 |
19 Oct 18 |
peter |
\brief close file |
3762 |
19 Oct 18 |
peter |
60 |
*/ |
3762 |
19 Oct 18 |
peter |
61 |
void close(void); |
3762 |
19 Oct 18 |
peter |
62 |
|
3762 |
19 Oct 18 |
peter |
63 |
/** |
3773 |
26 Oct 18 |
peter |
A file is good when it's open and until reading an entry |
3773 |
26 Oct 18 |
peter |
failed. |
3773 |
26 Oct 18 |
peter |
66 |
|
3773 |
26 Oct 18 |
peter |
\return true if file is still good |
3773 |
26 Oct 18 |
peter |
68 |
*/ |
3773 |
26 Oct 18 |
peter |
69 |
bool good(void) const; |
3773 |
26 Oct 18 |
peter |
70 |
|
3773 |
26 Oct 18 |
peter |
71 |
/** |
3762 |
19 Oct 18 |
peter |
\return true if file is open |
3762 |
19 Oct 18 |
peter |
73 |
*/ |
3762 |
19 Oct 18 |
peter |
74 |
bool is_open(void) const; |
3762 |
19 Oct 18 |
peter |
75 |
|
3762 |
19 Oct 18 |
peter |
76 |
/** |
3762 |
19 Oct 18 |
peter |
\brief open file named \a fn |
3771 |
25 Oct 18 |
peter |
78 |
|
3771 |
25 Oct 18 |
peter |
Open file \a fn, unless \a fn is "-", in which case \c stdin |
3771 |
25 Oct 18 |
peter |
is used. The function tries to detect whether file is |
3771 |
25 Oct 18 |
peter |
compressed (gzipped) or not by looking at the first byte which |
3771 |
25 Oct 18 |
peter |
is \a 0x1f for gzipped files. |
3771 |
25 Oct 18 |
peter |
83 |
|
3771 |
25 Oct 18 |
peter |
Function opens a VcfHeader and if the first bit does not |
4113 |
29 Sep 21 |
peter |
conform with the format of a VCF header, an exception is |
3771 |
25 Oct 18 |
peter |
thrown. |
3771 |
25 Oct 18 |
peter |
87 |
|
3771 |
25 Oct 18 |
peter |
\note If file already is open behaviour is undefined. |
3762 |
19 Oct 18 |
peter |
89 |
*/ |
3762 |
19 Oct 18 |
peter |
90 |
void open(const std::string& fn); |
3762 |
19 Oct 18 |
peter |
91 |
|
3762 |
19 Oct 18 |
peter |
92 |
/** |
3773 |
26 Oct 18 |
peter |
Read one VCF entry from file and assign to \a vcf. If there is |
3773 |
26 Oct 18 |
peter |
no more entry to read, the state of the file is switched to bad |
3773 |
26 Oct 18 |
peter |
and \c false is returned. |
3773 |
26 Oct 18 |
peter |
96 |
|
3773 |
26 Oct 18 |
peter |
\return true if successful |
3773 |
26 Oct 18 |
peter |
98 |
*/ |
3773 |
26 Oct 18 |
peter |
99 |
bool read(VCF& vcf); |
3773 |
26 Oct 18 |
peter |
100 |
|
3773 |
26 Oct 18 |
peter |
101 |
/** |
3762 |
19 Oct 18 |
peter |
\return reference to header |
3762 |
19 Oct 18 |
peter |
103 |
|
3762 |
19 Oct 18 |
peter |
Note that modifying the referenced object does not modify the |
3762 |
19 Oct 18 |
peter |
underlying file. |
3762 |
19 Oct 18 |
peter |
106 |
|
3771 |
25 Oct 18 |
peter |
\note If file is not open, behaviour is undefined. |
3762 |
19 Oct 18 |
peter |
108 |
*/ |
3762 |
19 Oct 18 |
peter |
109 |
VcfHeader& header(void); |
3762 |
19 Oct 18 |
peter |
110 |
|
3762 |
19 Oct 18 |
peter |
111 |
/** |
3762 |
19 Oct 18 |
peter |
\return reference to header |
3762 |
19 Oct 18 |
peter |
113 |
|
3762 |
19 Oct 18 |
peter |
\note If file is not open, behaviour is undefined. |
3762 |
19 Oct 18 |
peter |
115 |
*/ |
3762 |
19 Oct 18 |
peter |
116 |
const VcfHeader& header(void) const; |
3762 |
19 Oct 18 |
peter |
117 |
private: |
3996 |
07 Oct 20 |
peter |
118 |
std::unique_ptr<VcfHeader> header_; |
3762 |
19 Oct 18 |
peter |
119 |
boost::iostreams::filtering_istream fis_; |
3762 |
19 Oct 18 |
peter |
// store here for easy garbage collection |
3996 |
07 Oct 20 |
peter |
121 |
std::unique_ptr<std::ifstream> file_stream_; |
3762 |
19 Oct 18 |
peter |
122 |
std::string name_; |
3774 |
26 Oct 18 |
peter |
123 |
friend class VcfIterator; |
3762 |
19 Oct 18 |
peter |
124 |
}; |
3762 |
19 Oct 18 |
peter |
125 |
|
3762 |
19 Oct 18 |
peter |
126 |
}}} |
3762 |
19 Oct 18 |
peter |
127 |
|
3762 |
19 Oct 18 |
peter |
128 |
#endif |