-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlleleSpecific.hpp
88 lines (67 loc) · 2.48 KB
/
AlleleSpecific.hpp
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
#ifndef genomic_AlleleSpecific_h
#define genomic_AlleleSpecific_h
#include <cmath>
#include <limits>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include "typedefs.h"
#include "global.hpp"
#define ENABLE_IF_ALLELE_SPECIFIC typename boost::enable_if<boost::is_base_and_derived<allele_specific_base, allele_specific_type>, allele_specific_type>
struct allele_specific_base {};
template <typename a_type, typename b_type>
struct allele_specific : allele_specific_base
{
a_type a;
b_type b;
allele_specific() {}
allele_specific(a_type A, b_type B) : a(A), b(B) {}
};
template <typename allele_specific_type> inline
ENABLE_IF_ALLELE_SPECIFIC::type operator+(const allele_specific_type& x, const allele_specific_type& y) {
return allele_specific_type(x.a + y.a, x.b + y.b);
}
template <typename allele_specific_type> inline
ENABLE_IF_ALLELE_SPECIFIC::type absdiff(const allele_specific_type& x, const allele_specific_type& y) {
return allele_specific_type( absdiff(x.a, y.a), absdiff(x.b, y.b) );
}
template <typename allele_specific_type> inline
ENABLE_IF_ALLELE_SPECIFIC::type operator*(const allele_specific_type& x, float z) {
return allele_specific_type(x.a * z, x.b * z);
}
template <typename allele_specific_type> inline
bool operator<=(const allele_specific_type& x, float z) {
return x.a <= z;
}
template <typename allele_specific_type> inline
bool operator>=(const allele_specific_type& x, float z) {
return x.a >= z;
}
inline
bool operator<=(const alleles_rcn& x, float z) {
return (x.a + x.b) <= z;
}
inline
bool operator>=(const alleles_rcn& x, float z) {
return (x.a + x.b) >= z;
}
template <typename allele_specific_type> inline
bool operator!=(const allele_specific_type& x, const ENABLE_IF_ALLELE_SPECIFIC::type& y) {
return !( eq(x.a, y.a) && eq(y.b, y.b) );
}
template <typename allele_specific_type> inline
bool operator==(const allele_specific_type& x, const ENABLE_IF_ALLELE_SPECIFIC::type& y) {
return eq(x.a, y.a) && eq(x.b, y.b);
}
template <typename allele_specific_type> inline
std::istream& operator>>(std::istream& is, ENABLE_IF_ALLELE_SPECIFIC::type& x) {
return is >> x.a >> ' ' >> x.b;
}
template <typename allele_specific_type>
inline bool eq(const allele_specific_type& x, const ENABLE_IF_ALLELE_SPECIFIC::type& y) {
return eq(x.a, y.a) && eq(x.b, y.b);
}
template <typename allele_specific_type>
inline bool neq(const allele_specific_type& x, const ENABLE_IF_ALLELE_SPECIFIC::type& y) {
return neq(x.a, y.a) || neq(x.b, y.b);
}
#endif