|
| 1 | +===================================== |
| 2 | +Toxo |
| 3 | +===================================== |
| 4 | + |
| 5 | +Toxo is an object-oriented MATLAB library for calculating penetrance tables of any interaction order model. It is centered on bivariate epistasis models, that is, models where the penetrance is an expression of two intervening variables. The user specifies the model, its desired heritability (or prevalence) and Minor Allele Frequency (MAF) and the library maximizes the resulting table's prevalence (or heritability). |
| 6 | + |
| 7 | +Toxo includes, as an example, the `models <https://github.com/chponte/toxo/blob/master/models/>`__ proposed by Marchini *et al*. [1]_ together with a `script <https://github.com/chponte/toxo/blob/master/generate_models.m>`__ to generate penetrance tables derived from those models. |
| 8 | + |
| 9 | +Requirements |
| 10 | +------------------------------------- |
| 11 | + |
| 12 | +* MATLAB (checked against version R2018a, it is likely to work on many others). |
| 13 | + |
| 14 | + |
| 15 | +Installation |
| 16 | +------------------------------------- |
| 17 | + |
| 18 | +1) Download the latest Toxo release from `here <https://github.com/chponte/toxo/releases/latest>`__. |
| 19 | +2) Unzip the contents of the file. |
| 20 | +3) Add the ``src/`` folder into your MATLAB environment or script: |
| 21 | + |
| 22 | + .. code:: matlab |
| 23 | +
|
| 24 | + addpath('path/to/src/folder'); |
| 25 | +
|
| 26 | +
|
| 27 | +Usage |
| 28 | +------------------------------------- |
| 29 | + |
| 30 | +Using Toxo starts with defining a model in CSV-like format. Not all models are supported by Toxo, make sure the desired model complies with the two requirements expressed below. Model variable values are then calculated, and the resulting penetrance table is written into a text file. A complete working example can be found `here <https://github.com/chponte/toxo/blob/master/generate_models.m>`__. |
| 31 | + |
| 32 | +Model requirements |
| 33 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 34 | +In order for Toxo to calculate the values of the two variables for which the prevalence (or heritability) is maximum, two requirements must be met: |
| 35 | + |
| 36 | +1) Penetrance expressions are non-decreasing monotonic polynomials in the real positive number space. Polynomials that meet this criteria have positive partial derivatives for all real positive values of both variables. For example, the polynomial |e1| is monotonically non-decreasing because |e2| and |e3| are positive for x > 0 and y > 0. |
| 37 | +2) Polynomials can be sorted unequivocally in the real positive number space. This can be demonstrated analytically for all models by comparing the polynomials in pairs. As an example, the demonstration that |e4| is greater than |e5| for real positive numbers would be: |
| 38 | + |
| 39 | +.. |e1| image:: https://latex.codecogs.com/gif.latex?x%281+y%29%5E2 |
| 40 | + :align: bottom |
| 41 | + |
| 42 | +.. |e2| image:: https://latex.codecogs.com/gif.latex?%5Ctfrac%7B%5Cpartial%7D%7B%5Cpartial%20x%7D%5Cbig%28x%281+y%29%5E2%5Cbig%29%20%3D%20%281+y%29%5E2 |
| 43 | + :align: bottom |
| 44 | + |
| 45 | +.. |e3| image:: https://latex.codecogs.com/gif.latex?%5Ctfrac%7B%5Cpartial%7D%7B%5Cpartial%20y%7D%5Cbig%28x%281+y%29%5E2%5Cbig%29%20%3D%20x%282y%20+%202%29 |
| 46 | + :align: bottom |
| 47 | + |
| 48 | +.. |e4| image:: https://latex.codecogs.com/gif.latex?x%281+y%29%5E4 |
| 49 | + :align: bottom |
| 50 | + |
| 51 | +.. |e5| image:: https://latex.codecogs.com/gif.latex?x%281+y%29%5E3 |
| 52 | + :align: bottom |
| 53 | + |
| 54 | +.. figure:: https://latex.codecogs.com/gif.latex?x%281+y%29%5E4%20%26%5Cge%20x%281+y%29%5E3 |
| 55 | + :align: center |
| 56 | + |
| 57 | +.. figure:: https://latex.codecogs.com/gif.latex?%281+y%29%5E4%20%26%5Cge%20%281+y%29%5E3 |
| 58 | + :align: center |
| 59 | + |
| 60 | +.. figure:: https://latex.codecogs.com/gif.latex?1+y%20%26%5Cge%201 |
| 61 | + :align: center |
| 62 | + |
| 63 | +.. figure:: https://latex.codecogs.com/gif.latex?y%20%26%5Cge%200 |
| 64 | + :align: center |
| 65 | + |
| 66 | +Model description |
| 67 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 68 | +Models read by Toxo are formatted in CSV-like style, where each row represents a genotype combination and its associated penetrance (separated by a comma). The order in which the rows appear does not matter. Empty lines or lines starting with '#' (comments) are ignored. |
| 69 | + |
| 70 | +Genotypes are represented as two characters, each one corresponding to each of the alleles from genotype. Alleles of the same genotype use the same alphabetic letter, and the difference in capitalization encodes the minor (lowercase) and major (uppercase) allele. There is no limit on the genotype combination size. |
| 71 | + |
| 72 | +Penetrance expressions are functions of two variables. Variables can take any alphabetic name, but for simplicity we will name them x and y. |
| 73 | + |
| 74 | +An example of model would be: |
| 75 | + |
| 76 | +.. code:: text |
| 77 | + |
| 78 | + # Model name |
| 79 | + |
| 80 | + AABB, x |
| 81 | + AABb, x |
| 82 | + AAbb, x |
| 83 | + AaBB, x |
| 84 | + AaBb, x*(1+y) |
| 85 | + Aabb, x*(1+y) |
| 86 | + aaBB, x |
| 87 | + aaBb, x*(1+y) |
| 88 | + aabb, x*(1+y) |
| 89 | +
|
| 90 | +Penetrance table calculation |
| 91 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 92 | +Once the model is defined, obtaining the penetrance table is very straightforward. First the model is imported into MATLAB using the Model class. Then, the penetrance class is obtained. The last step is to save the calculated table into a file. The following code snippet exemplifies the process: |
| 93 | + |
| 94 | + |
| 95 | +.. code:: matlab |
| 96 | + |
| 97 | + model = 'sample_model.csv'; |
| 98 | + output = 'penetrance_table.csv'; |
| 99 | + maf = 0.25; |
| 100 | + prevalence = 0.1; |
| 101 | + m = toxo.Model(model); |
| 102 | + p = m.find_max_heritability(maf, prevalence); |
| 103 | + p.write(output, toxo.PTable.format_csv); |
| 104 | +
|
| 105 | +
|
| 106 | +Classes in Toxo |
| 107 | +------------------------------------- |
| 108 | +Toxo implements two main classes, Model_ and PTable_, which encapsulate all the functionality: |
| 109 | + |
| 110 | +Model |
| 111 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 112 | +Model is a symbolic representation of an epistasis model. It is responsible for reading the model, parsing the text file and converting the penetrance strings to symbolic expressions. It offers two methods to calculate penetrance tables which maximize the associated penetrance or heritability under certain constraints. |
| 113 | + |
| 114 | +Attributes |
| 115 | +""""""""""""""""""""""""""""""""""""" |
| 116 | +name : ``String`` |
| 117 | + Name of the model. |
| 118 | +order : ``Integer`` |
| 119 | + Number of loci involved in the epistatic model. |
| 120 | +penetrances : ``Array of symbolic`` |
| 121 | + Array of symbolic expressions, representing the epistatic model. |
| 122 | +variables : ``Array of symbolic`` |
| 123 | + List of all variables contained in all symbolic expressions |
| 124 | + |
| 125 | +Methods |
| 126 | +""""""""""""""""""""""""""""""""""""" |
| 127 | +Model(path) |
| 128 | + Construct an instance of this class from the given model. |
| 129 | + |
| 130 | + - ``path`` : ``String`` - Path to the model CSV file. |
| 131 | +find_max_prevalence(maf, h) |
| 132 | + Calculate the penetrance table(s) of the model with the maximum admissible prevalence given its MAF and heritability. |
| 133 | + |
| 134 | + - ``maf`` : ``Double`` - MAF of the resulting penetrance table. |
| 135 | + - ``h`` : ``Double`` - Heritability of the resulting penetrance table. |
| 136 | + - ``output`` : ``toxo.PTable`` - Resulting penetrance table. |
| 137 | +find_max_heritability(maf, p) |
| 138 | + Calculate the penetrance table(s) of the model with the maximum admissible heritability given its MAF and prevalence. |
| 139 | + |
| 140 | + - ``maf`` : ``Double`` - MAF of the resulting penetrance table. |
| 141 | + - ``p`` : ``Double`` - Prevalence of the resulting penetrance table. |
| 142 | + - ``output`` : ``toxo.PTable`` - Resulting penetrance table. |
| 143 | + |
| 144 | +PTable |
| 145 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 146 | +Numeric representation of a penetrance table. This class provides methods to calculate several metrics, as well as a method to write the table to a file in several formats. |
| 147 | + |
| 148 | +Static constants |
| 149 | +""""""""""""""""""""""""""""""""""""" |
| 150 | +format_csv : ``Integer`` |
| 151 | + Represents the CSV output format, taken as a parameter in the write method. |
| 152 | +format_gametes: ``Integer`` |
| 153 | + Represents the GAMETES output format, taken as a parameter in the write method. |
| 154 | + |
| 155 | +Attributes |
| 156 | +""""""""""""""""""""""""""""""""""""" |
| 157 | +order : ``Integer`` |
| 158 | + Number of loci involved in the penetrance table. |
| 159 | +maf : ``Double`` |
| 160 | + Common MAF of all locis involved in the interaction. |
| 161 | +vars : ``Map`` |
| 162 | + Values of the variables present in the original model. |
| 163 | +gp : ``Array of symbolic`` |
| 164 | + Genotype probabilities table array. |
| 165 | +pt : ``Array of symbolic`` |
| 166 | + Penetrances table array. |
| 167 | + |
| 168 | +Methods |
| 169 | +""""""""""""""""""""""""""""""""""""" |
| 170 | +PTable(model, maf, values) |
| 171 | + Create a penetrance table from a given Model, using the MAF and variable values desired. |
| 172 | + |
| 173 | + - ``model`` : ``toxo.Model`` - Model from which the table is constructed. |
| 174 | + - ``maf`` : ``Double`` - MAF of the penetrance table. |
| 175 | + - ``values`` : ``Array of double`` - Values of the variables in Model. |
| 176 | +prevalence( ) |
| 177 | + Calculate the prevalence of the penetrance table. |
| 178 | + |
| 179 | + - ``output`` : ``Double`` - Prevalence of the table. |
| 180 | +heritability( ) |
| 181 | + Calculate the heritability of the penetrance table. |
| 182 | + |
| 183 | + - ``output`` : ``Double`` - Heritability of the table. |
| 184 | +write(path, format) |
| 185 | + Write the penetrance table into a text file using a specific output format. |
| 186 | + |
| 187 | + - ``path`` : ``String`` - File path in which the table should be written into. |
| 188 | + - ``format`` : ``Integer`` - Format to use for the output. |
| 189 | + |
| 190 | +Troubleshooting |
| 191 | +------------------------------------- |
| 192 | + |
| 193 | +If you are having trouble using Toxo, encounter any error or would like to see some additional functionality implemented, feel free to open an `Issue <https://github.com/chponte/toxo/issues>`_. |
| 194 | + |
| 195 | +References |
| 196 | +------------------------------------- |
| 197 | + |
| 198 | +.. [1] Marchini, Jonathan, Peter Donnelly, and Lon R. Cardon. 2005. "Genome-Wide Strategies for Detecting Multiple Loci That Influence Complex Diseases". Nature Genetics 37 (4): 413. https://doi.org/10.1038/ng1537. |
0 commit comments