File: header.h

package info (click to toggle)
vcftools 0.1.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,680 kB
  • ctags: 1,215
  • sloc: cpp: 12,118; perl: 10,973; ansic: 1,467; pascal: 1,064; makefile: 67; php: 57; sh: 12
file content (86 lines) | stat: -rw-r--r-- 2,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * header.h
 *
 *  Created on: Apr 29, 2013
 *      Author: amarcketta
 */

#ifndef HEADER_H_
#define HEADER_H_

#include <cstring>
#include <string>
#include <map>
#include <vector>
#include "output_log.h"

using namespace std;
extern output_log LOG;

enum Type_enum {Integer=0, Float=1, Character=2, String=3, Flag=4};

class Field_description
{
public:
	string Field;
	string ID;
	int idx;
	int N_entries;
	string N_entries_str;
	string Type_str;
	Type_enum Type;
	string Description;
	string Length;
	string Assembly;
	string Source;
	string Version;
	string Other;

	Field_description() : Field(""), ID(""), idx(-1), N_entries(0), N_entries_str(""), Type_str(""), Type(Integer), Description(""), Length(""), Assembly(""), Source(""), Version(""), Other("") {};
	~Field_description() {};
};

class header
{
public:
	unsigned int contig_index;
	bool has_contigs;
	bool has_genotypes;
	bool has_header;
	bool has_file_format;
	bool has_idx;
	vector<string> indv;
	vector<string> lines;
	vector<Field_description> parsed_lines;
	unsigned int N_indv;

	map<int, Field_description> INFO_map;
	map<int, Field_description> FILTER_map;
	map<int, Field_description> FORMAT_map;
	map<int, Field_description> CONTIG_map;
	map<string, int> CONTIG_reverse_map;
	map<string, int> FILTER_reverse_map;
	map<string, int> INFO_reverse_map;
	map<string, int> FORMAT_reverse_map;

	header();
	~header() {};

	void reprint();
	void reparse();
	void parse_meta(const string &line, unsigned int &line_index);
	void parse_header(const string &line);

	int add_INFO_descriptor(const string &in, int index);
	int add_FILTER_descriptor(const string &in, int index);
	int add_FORMAT_descriptor(const string &in, int index);
	void add_CONTIG_descriptor(const string &in, int index);

	static void tokenize(const string &in, char token, vector<string> &out);
	static int str2int(const string &in, const int missing_value=-1);
	static string int2str(const int in, const int missing_value=-1);
	static double str2double(const string &in, const double missing_value=-1.0);
	static string double2str(const double in, const double missing_value=-1.0);
};

#endif /* HEADER_H_ */