This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
/
genotype.h
100 lines (81 loc) · 2.58 KB
/
genotype.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef __gamgee__genotype__
#define __gamgee__genotype__
#include "utils/hts_memory.h"
#include "genotype_encoding_value.h"
#include "genotype_encoding.h"
#include "utils/utils.h"
#include "utils/format_field_type.h"
#include "htslib/vcf.h"
#include <memory>
namespace gamgee {
/**
* @brief Encodes a genotype.
*/
class Genotype {
public:
/**
* @brief Creates a genotype.
* @param body The shared memory variant "line" from a vcf, or bcf.
* @param format_ptr The GT field from the line.
* @param data_ptr The GT for this sample.
*/
Genotype(const std::shared_ptr<bcf1_t>& body, const bcf_fmt_t* const format_ptr, const uint8_t* data_ptr);
/**
* @brief Moves a genotype.
* @param other The other genotype object to move.
*/
Genotype(Genotype&& other) noexcept;
// only for diploids
/**
* @brief Checks if this genotype is any type of heterozygous call.
* @return True if this GT is a het.
* @note only for diploids.
*/
bool is_het() const;
/**
* @brief Checks if this genotype is a homozygous call that is non-reference.
* @return True if this GT is a hom var.
* @note only for diploids.
*/
bool is_hom_var() const;
/**
* @brief Checks if this genotype is a homozygous call that is reference.
* @return True if this GT is a hom ref.
* @note only for diploids.
*/
bool is_hom_ref() const;
/**
* @brief Returns a bit encoding of the first two alleles.
* @return A bit encoding of the first two alleles.
* @note only for diploids.
*/
GenotypeEncoding value() const; // returns the number of the genotype. => 0/1 = 1 | 0/0 = 0 | 1/1 = 2 ... | 0/2
/**
* @brief Returns a string decoding of each allele.
* @param index From [0,size())
* @return A string decoding of the allele at index.
*/
GenotypeEncodingValue operator[](const uint32_t index) const; // getter
/**
* @brief Number of alleles in this genotype.
* @return Number of alleles in this genotype.
*/
uint32_t size() const;
/**
* @brief The alleles in this genotype.
* @return The alleles in this genotype as strings.
*/
vector<string> alleles() const; // returns the actual alleles (e.g. A/T or TG/C or T/T/C or T/T/T/T/T ... )
private:
const std::shared_ptr<bcf1_t> m_body;
const bcf_fmt_t* const m_format_ptr;
const uint8_t* m_data_ptr;
int32_t allele(const uint32_t allele_index) const;
template<class TYPE>
int32_t allele(const uint32_t allele_index) const;
template<class TYPE>
vector<string> alleles(TYPE missing, TYPE vector_end) const;
string allele_string(int32_t allele_int) const;
};
}
#endif