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
101
102
103
104
105
106
use Add;
/// A `Fraction` represents the *n* of *m* frequency of a feature in one or more annotated items.
///
/// For instance, we can represent the number of times *n* a feature
/// such as [Polydactyly](https://hpo.jax.org/browse/term/HP:0010442) was present
/// in a cohort of *m* individuals.
///
/// The counts are accessible via the `numerator` and `denominator` methods.
///
/// The `numerator` must be less than or equal to `denominator`.
/// However, it is possible for both to equal to `0`.
///
/// `Fraction` is generic over the data type that represents the count.
/// To simplify the API, we use `u32` as default.
/// Convert a tuple with numerator and denominator into the `Fraction`.
///
/// ## Examples
///
/// Parsing of `1/10` should succeed:
///
/// ```
/// use phenotypes::Fraction;
///
/// let f = Fraction::try_from((1, 10)).expect("Should never fail for this input");
///
/// assert_eq!(f.n(), 1);
/// assert_eq!(f.m(), 10);
/// ```
///
/// but we get an error if the numerator is greater than the denominator:
///
/// ```
/// use phenotypes::Fraction;
///
/// let err = Fraction::try_from((5, 3)).unwrap_err();
/// assert_eq!(err, "Numerator must be less than or equal to denominator!");
/// ```
/// Make a new `Fraction` by summing up *n* and *m* values.
///
/// ```
/// use phenotypes::Fraction;
///
/// let a = Fraction::try_from((1, 2)).unwrap();
/// let b = Fraction::try_from((3, 3)).unwrap();
///
/// let c = a + b;
///
/// assert_eq!(c.n(), 4);
/// assert_eq!(c.m(), 5);
/// ```