3750 |
17 Oct 18 |
peter |
1 |
#ifndef theplu_yat_omic_vcf_header |
3750 |
17 Oct 18 |
peter |
2 |
#define theplu_yat_omic_vcf_header |
3750 |
17 Oct 18 |
peter |
3 |
|
3750 |
17 Oct 18 |
peter |
// $Id$ |
3750 |
17 Oct 18 |
peter |
5 |
|
3750 |
17 Oct 18 |
peter |
6 |
/* |
3999 |
08 Oct 20 |
peter |
Copyright (C) 2018, 2019, 2020 Peter Johansson |
3750 |
17 Oct 18 |
peter |
8 |
|
3750 |
17 Oct 18 |
peter |
The yat library is free software; you can redistribute it and/or |
3750 |
17 Oct 18 |
peter |
modify it under the terms of the GNU General Public License as |
3750 |
17 Oct 18 |
peter |
published by the Free Software Foundation; either version 3 of the |
3750 |
17 Oct 18 |
peter |
License, or (at your option) any later version. |
3750 |
17 Oct 18 |
peter |
13 |
|
3750 |
17 Oct 18 |
peter |
The yat library is distributed in the hope that it will be useful, |
3750 |
17 Oct 18 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3750 |
17 Oct 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3750 |
17 Oct 18 |
peter |
General Public License for more details. |
3750 |
17 Oct 18 |
peter |
18 |
|
3750 |
17 Oct 18 |
peter |
You should have received a copy of the GNU General Public License |
3754 |
17 Oct 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3750 |
17 Oct 18 |
peter |
21 |
*/ |
3750 |
17 Oct 18 |
peter |
22 |
|
3750 |
17 Oct 18 |
peter |
23 |
#include <iosfwd> |
3750 |
17 Oct 18 |
peter |
24 |
#include <string> |
3750 |
17 Oct 18 |
peter |
25 |
#include <vector> |
3750 |
17 Oct 18 |
peter |
26 |
|
3750 |
17 Oct 18 |
peter |
27 |
namespace theplu { |
3750 |
17 Oct 18 |
peter |
28 |
namespace yat { |
3750 |
17 Oct 18 |
peter |
29 |
namespace omic { |
3750 |
17 Oct 18 |
peter |
30 |
|
3750 |
17 Oct 18 |
peter |
31 |
/** |
3750 |
17 Oct 18 |
peter |
\since New in yat 0.16 |
3750 |
17 Oct 18 |
peter |
33 |
*/ |
3750 |
17 Oct 18 |
peter |
34 |
class VcfHeader |
3750 |
17 Oct 18 |
peter |
35 |
{ |
3750 |
17 Oct 18 |
peter |
36 |
public: |
3750 |
17 Oct 18 |
peter |
37 |
/** |
3750 |
17 Oct 18 |
peter |
\brief Constructor |
3750 |
17 Oct 18 |
peter |
39 |
|
3750 |
17 Oct 18 |
peter |
Creates an empty header |
3750 |
17 Oct 18 |
peter |
41 |
*/ |
3750 |
17 Oct 18 |
peter |
42 |
VcfHeader(const std::string& version); |
3750 |
17 Oct 18 |
peter |
43 |
|
3750 |
17 Oct 18 |
peter |
44 |
/** |
3750 |
17 Oct 18 |
peter |
Consumes lines until a line does not start with '#' and |
3750 |
17 Oct 18 |
peter |
constructs a VcfHeader. |
3750 |
17 Oct 18 |
peter |
47 |
*/ |
3750 |
17 Oct 18 |
peter |
48 |
VcfHeader(std::istream& is); |
3750 |
17 Oct 18 |
peter |
49 |
|
3750 |
17 Oct 18 |
peter |
50 |
/** |
3750 |
17 Oct 18 |
peter |
Adds a line ##\a key = \a value |
3750 |
17 Oct 18 |
peter |
52 |
*/ |
3750 |
17 Oct 18 |
peter |
53 |
void add(const std::string& key, const std::string& value); |
3750 |
17 Oct 18 |
peter |
54 |
|
3750 |
17 Oct 18 |
peter |
55 |
/** |
3750 |
17 Oct 18 |
peter |
Add a line |
3750 |
17 Oct 18 |
peter |
##key=<ID,Number=number,Type=type,Description=description> |
3750 |
17 Oct 18 |
peter |
58 |
|
3750 |
17 Oct 18 |
peter |
If number is 0, it's replaced with ".". |
3750 |
17 Oct 18 |
peter |
60 |
*/ |
3750 |
17 Oct 18 |
peter |
61 |
void add(const std::string& key, const std::string& ID, int number, |
3750 |
17 Oct 18 |
peter |
62 |
const std::string& type, const std::string& description); |
3750 |
17 Oct 18 |
peter |
63 |
|
3750 |
17 Oct 18 |
peter |
64 |
/** |
3750 |
17 Oct 18 |
peter |
Same as add("INFO", ID, number, type, description) |
3750 |
17 Oct 18 |
peter |
66 |
|
3809 |
05 Jul 19 |
peter |
\a number should be integer or special character as |
3750 |
17 Oct 18 |
peter |
A: one per alt allele |
3750 |
17 Oct 18 |
peter |
R: one per allele |
3750 |
17 Oct 18 |
peter |
G: one per genotype |
3750 |
17 Oct 18 |
peter |
.: unknown |
3750 |
17 Oct 18 |
peter |
72 |
*/ |
3750 |
17 Oct 18 |
peter |
73 |
void add_info(const std::string& ID, const std::string& number, |
3750 |
17 Oct 18 |
peter |
74 |
const std::string& type, const std::string& description); |
3750 |
17 Oct 18 |
peter |
75 |
|
3750 |
17 Oct 18 |
peter |
76 |
/** |
3750 |
17 Oct 18 |
peter |
Same as add("FORMAT", ID, number, type, description) |
3809 |
05 Jul 19 |
peter |
78 |
|
3809 |
05 Jul 19 |
peter |
\a number should be integer or special character as |
3809 |
05 Jul 19 |
peter |
A: one per alt allele |
3809 |
05 Jul 19 |
peter |
R: one per allele |
3809 |
05 Jul 19 |
peter |
G: one per genotype |
3809 |
05 Jul 19 |
peter |
.: unknown |
3750 |
17 Oct 18 |
peter |
84 |
*/ |
3750 |
17 Oct 18 |
peter |
85 |
void add_format(const std::string& ID, const std::string& number, |
3750 |
17 Oct 18 |
peter |
86 |
const std::string& type, const std::string& description); |
3750 |
17 Oct 18 |
peter |
87 |
|
3750 |
17 Oct 18 |
peter |
88 |
/** |
3750 |
17 Oct 18 |
peter |
add a line with something like: |
3750 |
17 Oct 18 |
peter |
##bcftools_viewCommand=view -l 9 -O z -; Date=Wed Apr 19 10:49:09 2017 |
3750 |
17 Oct 18 |
peter |
91 |
*/ |
3750 |
17 Oct 18 |
peter |
92 |
void add_program_command(int argc, char* argv[]); |
3750 |
17 Oct 18 |
peter |
93 |
|
3750 |
17 Oct 18 |
peter |
94 |
/** |
3750 |
17 Oct 18 |
peter |
add a line with something like |
3750 |
17 Oct 18 |
peter |
##bcftools_normVersion=1.4+htslib-1.4 |
3750 |
17 Oct 18 |
peter |
97 |
*/ |
3750 |
17 Oct 18 |
peter |
98 |
void add_program_version(const std::string& prog, |
3750 |
17 Oct 18 |
peter |
99 |
const std::string& version); |
3750 |
17 Oct 18 |
peter |
100 |
|
3750 |
17 Oct 18 |
peter |
101 |
/** |
3891 |
26 Mar 20 |
peter |
\brief erase line \a line |
3891 |
26 Mar 20 |
peter |
103 |
|
3891 |
26 Mar 20 |
peter |
The last line, starting with '\#CHROM', cannot be erased. Use |
3891 |
26 Mar 20 |
peter |
function samples(const std::vector<std::string>&) to alter that |
3891 |
26 Mar 20 |
peter |
line. |
3905 |
08 May 20 |
peter |
107 |
|
3905 |
08 May 20 |
peter |
\since New in yat 0.18 |
3891 |
26 Mar 20 |
peter |
109 |
*/ |
3891 |
26 Mar 20 |
peter |
110 |
void erase(size_t line); |
3891 |
26 Mar 20 |
peter |
111 |
|
3891 |
26 Mar 20 |
peter |
112 |
/** |
3750 |
17 Oct 18 |
peter |
\return the last line of the header |
3750 |
17 Oct 18 |
peter |
114 |
*/ |
3750 |
17 Oct 18 |
peter |
115 |
const std::string& header(void) const; |
3750 |
17 Oct 18 |
peter |
116 |
|
3750 |
17 Oct 18 |
peter |
117 |
/** |
3750 |
17 Oct 18 |
peter |
Set the last line of the header |
3750 |
17 Oct 18 |
peter |
119 |
*/ |
3750 |
17 Oct 18 |
peter |
120 |
void header(const std::string& header); |
3750 |
17 Oct 18 |
peter |
121 |
|
3750 |
17 Oct 18 |
peter |
122 |
/** |
3750 |
17 Oct 18 |
peter |
\return line \a i |
3750 |
17 Oct 18 |
peter |
124 |
*/ |
3750 |
17 Oct 18 |
peter |
125 |
const std::string& line(size_t i) const; |
3750 |
17 Oct 18 |
peter |
126 |
|
3750 |
17 Oct 18 |
peter |
127 |
/** |
3750 |
17 Oct 18 |
peter |
\return everything between prefix '##' and first '=' of line \a line |
3750 |
17 Oct 18 |
peter |
129 |
*/ |
3750 |
17 Oct 18 |
peter |
130 |
std::string key(size_t line) const; |
3750 |
17 Oct 18 |
peter |
131 |
|
3750 |
17 Oct 18 |
peter |
132 |
/** |
3750 |
17 Oct 18 |
peter |
Sort lines |
3891 |
26 Mar 20 |
peter |
134 |
|
3891 |
26 Mar 20 |
peter |
Lines are sorted with respect to their categories |
3891 |
26 Mar 20 |
peter |
a) \c '\#\#fileformat=' |
3891 |
26 Mar 20 |
peter |
b) \c '\#\#reference=' and \c '\#\#contig=' |
3891 |
26 Mar 20 |
peter |
c) \c '\#\#INFO=' |
3891 |
26 Mar 20 |
peter |
d) \c '\#\#FILTER=' |
3891 |
26 Mar 20 |
peter |
e) \c '\#\#FORMAT=' |
3891 |
26 Mar 20 |
peter |
f) other |
3891 |
26 Mar 20 |
peter |
g) \c '\#CHROM' |
3750 |
17 Oct 18 |
peter |
143 |
*/ |
3750 |
17 Oct 18 |
peter |
144 |
void nicify(void); |
3750 |
17 Oct 18 |
peter |
145 |
|
3750 |
17 Oct 18 |
peter |
146 |
/** |
3750 |
17 Oct 18 |
peter |
everything right of first '=' on line \a line |
3750 |
17 Oct 18 |
peter |
148 |
*/ |
3750 |
17 Oct 18 |
peter |
149 |
std::string value(size_t line) const; |
3750 |
17 Oct 18 |
peter |
150 |
|
3750 |
17 Oct 18 |
peter |
151 |
/** |
3750 |
17 Oct 18 |
peter |
returns "" if \a key is missing is false otherwise |
3750 |
17 Oct 18 |
peter |
corresponding value e.g. value(i, "Description") returns value |
3750 |
17 Oct 18 |
peter |
for key Description of line \a line |
3750 |
17 Oct 18 |
peter |
155 |
*/ |
3750 |
17 Oct 18 |
peter |
156 |
std::string value(size_t line, const std::string& key) const; |
3750 |
17 Oct 18 |
peter |
157 |
|
3750 |
17 Oct 18 |
peter |
158 |
/** |
3750 |
17 Oct 18 |
peter |
\return number of lines |
3750 |
17 Oct 18 |
peter |
160 |
*/ |
3750 |
17 Oct 18 |
peter |
161 |
size_t size(void) const; |
3750 |
17 Oct 18 |
peter |
162 |
|
3750 |
17 Oct 18 |
peter |
163 |
/** |
3750 |
17 Oct 18 |
peter |
Sample names occur tab-delimited in the last line starting from |
3750 |
17 Oct 18 |
peter |
10th column. |
3750 |
17 Oct 18 |
peter |
166 |
|
3750 |
17 Oct 18 |
peter |
\return samples name |
3750 |
17 Oct 18 |
peter |
168 |
*/ |
3750 |
17 Oct 18 |
peter |
169 |
const std::vector<std::string>& samples(void) const; |
3750 |
17 Oct 18 |
peter |
170 |
|
3750 |
17 Oct 18 |
peter |
171 |
/** |
3750 |
17 Oct 18 |
peter |
Set sample names |
3750 |
17 Oct 18 |
peter |
173 |
*/ |
3750 |
17 Oct 18 |
peter |
174 |
void samples(const std::vector<std::string>& s); |
3750 |
17 Oct 18 |
peter |
175 |
|
3750 |
17 Oct 18 |
peter |
176 |
private: |
3750 |
17 Oct 18 |
peter |
177 |
friend std::ostream& operator<<(std::ostream& os, const VcfHeader& b); |
3750 |
17 Oct 18 |
peter |
178 |
std::vector<std::string> lines_; |
3750 |
17 Oct 18 |
peter |
179 |
mutable std::vector<std::string> samples_; |
3750 |
17 Oct 18 |
peter |
180 |
|
3750 |
17 Oct 18 |
peter |
181 |
void add(const std::string& key, |
3750 |
17 Oct 18 |
peter |
182 |
const std::string& ID, const std::string& number, |
3750 |
17 Oct 18 |
peter |
183 |
const std::string& type, const std::string& description); |
3750 |
17 Oct 18 |
peter |
184 |
void key_value(size_t line, std::string& key, std::string& value) const; |
3750 |
17 Oct 18 |
peter |
// remove line with ##KEY=<ID=id* |
3750 |
17 Oct 18 |
peter |
186 |
void remove(const std::string& key, const std::string& id); |
3760 |
18 Oct 18 |
peter |
187 |
|
3760 |
18 Oct 18 |
peter |
// functor used in nicify |
3760 |
18 Oct 18 |
peter |
189 |
struct Compare |
3760 |
18 Oct 18 |
peter |
190 |
{ |
3760 |
18 Oct 18 |
peter |
191 |
bool operator()(const std::string& lhs, const std::string& rhs) const; |
3760 |
18 Oct 18 |
peter |
192 |
private: |
3760 |
18 Oct 18 |
peter |
193 |
int index(const std::string& s) const; |
3760 |
18 Oct 18 |
peter |
194 |
bool match(const std::string& s, const std::string& prefix) const; |
3760 |
18 Oct 18 |
peter |
195 |
}; |
3750 |
17 Oct 18 |
peter |
196 |
}; |
3750 |
17 Oct 18 |
peter |
197 |
|
3750 |
17 Oct 18 |
peter |
198 |
/** |
3750 |
17 Oct 18 |
peter |
\since new in yat 0.16 |
3750 |
17 Oct 18 |
peter |
200 |
|
3750 |
17 Oct 18 |
peter |
\relates VcfHeader |
3750 |
17 Oct 18 |
peter |
202 |
*/ |
3750 |
17 Oct 18 |
peter |
203 |
std::ostream& operator<<(std::ostream&, const VcfHeader& header); |
3750 |
17 Oct 18 |
peter |
204 |
|
3750 |
17 Oct 18 |
peter |
205 |
}}} |
3750 |
17 Oct 18 |
peter |
206 |
|
3750 |
17 Oct 18 |
peter |
207 |
#endif |