Skip to content

Commit 2802d3e

Browse files
author
Christian Ponte
committed
Rewrite main methods, update documentation accordingly
Squashed commit of the following: commit 9c82ac7 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu Jun 6 13:11:42 2019 +0200 Update code documentation commit ebad71a Author: Christian Ponte <christian.ponte@udc.es> Date: Wed Jun 5 13:15:46 2019 +0200 Fix class tables commit 159f9f8 Author: Christian Ponte <christian.ponte@udc.es> Date: Wed Jun 5 13:01:18 2019 +0200 Fix links, add acknowledgements commit ad1263b Author: Christian Ponte <christian.ponte@udc.es> Date: Wed Jun 5 12:39:48 2019 +0200 Update README with latest changes commit 7fd0245 Author: Christian Ponte <christian.ponte@udc.es> Date: Tue Jun 4 12:47:00 2019 +0200 Move examples to a separate folder commit 98bb274 Author: Christian Ponte <christian.ponte@udc.es> Date: Tue Jun 4 10:39:35 2019 +0200 Fix error when solution could not be found, reduce code repetitiveness commit 6b0f29c Author: Christian Ponte <christian.ponte@udc.es> Date: Mon Jun 3 11:06:37 2019 +0200 Test html table commit ee9cc01 Author: Christian Ponte <christian.ponte@udc.es> Date: Fri May 31 15:41:55 2019 +0200 Fix error in symbolic expressions inside the model definition files commit 12c8dfa Author: Christian Ponte <christian.ponte@udc.es> Date: Thu May 30 12:59:04 2019 +0200 Add complete usage example MATLAB script commit 2350749 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu May 30 11:05:48 2019 +0200 Update table generation script with the latest changes in the library commit 5d051e0 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu May 30 10:22:39 2019 +0200 Fix file permissions commit 02f64d1 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu May 30 10:22:06 2019 +0200 Add additive, multiplicative and threshold models of up to 8th order commit 3b128b1 Author: Christian Ponte <christian.ponte@udc.es> Date: Wed May 22 13:05:11 2019 +0200 Fix marginal_penetrances method commit 63d64d7 Author: Christian Ponte <christian.ponte@udc.es> Date: Wed May 22 09:14:19 2019 +0200 Add marginal_penetrances method commit 49608ad Author: Christian Ponte <christian.ponte@udc.es> Date: Tue May 21 14:04:18 2019 +0200 Simplify PTable class representation, update Model with changes commit 655a317 Author: Christian Ponte <christian.ponte@udc.es> Date: Tue May 21 12:40:56 2019 +0200 Change how maximum polynomial is found, add variable prequisites to solve call commit cd188ea Author: Christian Ponte <christian.ponte@udc.es> Date: Tue May 21 08:37:49 2019 +0200 Change MException identifiers, change throw instructions to throwAsCaller, add check for number of variables commit 6ab4496 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu Mar 28 14:56:54 2019 +0100 Add support for different MAF per loci commit 91c4d97 Author: Christian Ponte <christian.ponte@udc.es> Date: Thu Mar 28 12:23:36 2019 +0100 Change number of decimals in all output format, now depends on the number of digits used in the symbolic operations commit ef7873d Author: Christian Ponte <christian.ponte@udc.es> Date: Thu Mar 28 10:44:17 2019 +0100 Fix warning on generate_models.m, removed trailing '\' on output path commit 6f5e58a Author: Christian Ponte <christian.ponte@udc.es> Date: Wed Mar 27 20:54:22 2019 +0100 Fix avoidable sym to double cast in PTable contructor
1 parent 0e2650b commit 2802d3e

30 files changed

+29658
-373
lines changed

README.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Toxo
2+
3+
Toxo is an object-oriented MATLAB library for calculating penetrance tables of any bivariate epistasis model. It is solely dedicated to bivariate 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).
4+
5+
Toxo does not generate population samples, and is intended to be used together with other already existing simulation software such as [GAMETES](https://sourceforge.net/projects/gametes/). In order to acomplish that, Toxo includes multiple output formats to provide compatibility with external simulators, and can be easily extended to support additional programs.
6+
7+
Toxo includes, as examples, two MATLAB scripts:
8+
9+
1. [calculate_tables.m](examples/calculate_tables.m): calculates the penetrance tables of the additive, multiplicative and threshold third and fourth order models, for a number of MAF and heritability combinations.
10+
11+
2. [usage_example.m](examples/usage_example.m): calculates a penetrance table of the 2-way additive model using MAF = 0.25 and h² = 0.2, saves the table using GAMETES format, and calls GAMETES with the previous table to generate population samples.
12+
13+
---
14+
15+
## Table of contents
16+
17+
1. [Requirements.](#1-requirements)
18+
19+
2. [Contents of this repository.](#2-contents-of-this-repository)
20+
21+
3. [Usage.](#3-usage)
22+
23+
4. [Class documentation.](#4-classes-documentation)
24+
25+
5. [Troubleshooting.](#5-troubleshooting)
26+
27+
6. [Acknowledgements.](#6-acknowledgements)
28+
29+
---
30+
31+
## 1. Requirements
32+
33+
- MATLAB (tested against version R2018a, it is likely to work on many others).
34+
35+
## 2. Contents of this repository
36+
37+
- `models/` [Marchini's models](https://doi.org/10.1038/ng1537) (generalized to 3rd-8th order) that can be used together with Toxo.
38+
39+
- `src/` Source code of the library, to be included in MATLAB' s path.
40+
41+
- `examples/` Example scripts showcasing the usage of Toxo.
42+
43+
- `LICENSE` MIT license.
44+
45+
- `README.md` This file.
46+
47+
## 3. Usage
48+
49+
### Installation
50+
51+
1. Download the latest Toxo release from [here](https://github.com/chponte/toxo/releases/latest).
52+
53+
2. Unzip the contents of the file.
54+
55+
3. Add the `src/` folder into your MATLAB environment:
56+
57+
```matlab
58+
addpath('path/to/src/folder');
59+
```
60+
61+
### Using Toxo
62+
63+
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. Variable values are then calculated so that the resulting table fits some desired parameter, and the table is written into a file.
64+
65+
#### Model requirements
66+
67+
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:
68+
69+
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 ![x(1+y)^2](https://latex.codecogs.com/gif.latex?x%281+y%29%5E2) is monotonically non-decreasing because ![d/dx(x(1+y)^2) = (1+y)^2](https://latex.codecogs.com/gif.latex?%5Ctfrac%7B%5Cpartial%7D%7B%5Cpartial%20x%7D%5Cbig%28x%281&plus;y%29%5E2%5Cbig%29%20%3D%20%281&plus;y%29%5E2) and ![d/dy(x(1+y)^2) = x(2y+2)](https://latex.codecogs.com/gif.latex?%5Ctfrac%7B%5Cpartial%7D%7B%5Cpartial%20y%7D%5Cbig%28x%281&plus;y%29%5E2%5Cbig%29%20%3D%20x%282y%20&plus;%202%29) are positive for x > 0 and y > 0.
70+
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. Example:
71+
72+
![x(1+y)^4 >= x(1+y)^3](https://latex.codecogs.com/gif.latex?x%281&plus;y%29%5E4%20%26%5Cge%20x%281&plus;y%29%5E3)
73+
74+
![1+y >= 1](https://latex.codecogs.com/gif.latex?1&plus;y%20%26%5Cge%201)
75+
76+
![y >= 0](https://latex.codecogs.com/gif.latex?y%20%26%5Cge%200)
77+
78+
#### Model description
79+
80+
Models read by Toxo are formatted in a 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.
81+
82+
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.
83+
84+
Penetrance expressions are functions of two variables. Variables can take any alphabetic name, but for simplicity we will name them x and y.
85+
86+
An example of a model would be:
87+
88+
```matlab
89+
# 2-way additive model
90+
AABB, x
91+
AABb, x*(1+y)
92+
AAbb, x*(1+y)^2
93+
AaBB, x*(1+y)
94+
AaBb, x*(1+y)^2
95+
Aabb, x*(1+y)^3
96+
aaBB, x*(1+y)^2
97+
aaBb, x*(1+y)^3
98+
aabb, x*(1+y)^4
99+
```
100+
101+
#### Penetrance table calculation
102+
103+
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:
104+
105+
```matlab
106+
model = 'sample_model.csv';
107+
output = 'penetrance_table.csv';
108+
mafs = [0.25, 0.25];
109+
heritability = 0.1;
110+
m = toxo.Model(model);
111+
pt = m.find_max_prevalence(mafs, heritability);
112+
pt.write(output, toxo.PTable.format_csv);
113+
```
114+
115+
## 4. Classes documentation
116+
117+
Toxo implements two main classes, **Model** and **PTable**, which encapsulate all the functionality of the library:
118+
119+
| Model |
120+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
121+
| **+name**: *char*<br/>The name of the model as appears in its file name.<br/>**+order**: *double*<br/> The number of locus invoved in the epistasis relationship.<br/>**+penetrances**: *sym*<br/> Sorted array of symbolic penetrance expressions.<br/>**+variables**: *sym*<br/> Array containing the symbolic variables used throughout the table. |
122+
| **«constructor»+Model**(path: *char*)<br/> Class constructor, responsible for reading the epistasis model from the given path.<br/>**-max_penetrance**(): *sym*<br/> Returns the largest polynomial from all penetrance expressions, for any real and possitive value of the two variables.<br/>**-solve**(varargin: *sym*): *sym*<br/> Solve the equation system made of the provided equations.<br/>**+find_max_prevalence**(mafs: *double*, h: *double*): *PTable*<br/> Finds the table whose prevalence is maximum for the given MAFs and heritability, and returns it as a PTable object.<br/>**+find_max_heritability**(mafs: *double*, p: *double*): *PTable*<br/> Finds the table whose heritability is maximum for the given MAFs and prevalence, and returns it as a PTable object. |
123+
124+
| PTable |
125+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
126+
| <u>**+format_csv**: *double* = 0</u><br/> Static constant, storing the CSV format code for the write method.<br/><u>**+format_gametes**: *double* = 0</u><br/> Static constant, storing the GAMETES format code for the write method.<br/>**+order**: *double*<br/> The number of locus invoved in the epistasis relationship.<br/>**+vars**: *sym*<br/> Struct containing the original variable names and its value.<br/>**+pt**: *sym*<br/> Array of symbolic values representing the prenetrance table. |
127+
| **«constructor»+PTable**(model: *Model*, values: *double*)<br/> Class constructor, creates a penetrance table from a Model and its variables values.<br/>**-to_gametes**(fmask: *char*, mafs: *double*): *char*<br/> Returns a char array containing the table description, using the GAMETES format.<br/>**+prevalence**(mafs: *double*): *double*<br/> Returns the prevalence of the table.<br/>**+heritability**(mafs: *double*): *double*<br/> Returns the heritability of the table.<br/>**+marginal_penetrances**(mafs: *double*): *double*<br/> Returns the marginal penetrance of each allele from every locus.<br/>**+write**(path: *char*, format: *double*, varargin)<br/> Writes the table to the specified file using a specific format. Depending on the format, additional arguments may be provided. |
128+
129+
## 5. Troubleshooting
130+
131+
> Why do I get "*There is no solution to the problem defined*" when finding a penetrance table?
132+
133+
The MAF and prevalence (or heritability) combination that you have specified leads to an incompatible system. Make sure that that prevalence or heritability level can be achieved for the specified MAF. Plotting your model's prevalence or heritability surface can help to understand it.
134+
135+
> Why do I get "*Could not find a solution to the problem defined*" when finding a penetrance table?
136+
137+
The model that you are specifying may be too complex for the MATLAB's solver to process. This may be the case if, for example, your model contains big exponents (>32).
138+
139+
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).
140+
141+
## 6. Acknowledgements
142+
143+
Thanks to María J. Martín and Jorge González-Domínguez for their supervision of the project and writting of the article.

0 commit comments

Comments
 (0)