33## Synopsis
44
55``` console
6- dnmtools radmeth -factor case -o output.txt design_matrix.txt proportion_table .txt
6+ dnmtools radmeth -factor case -o output.txt design_matrix.txt data_matrix .txt
77```
88
99## Description
1010
1111The differential-methylation detection method described in this section is
1212based on the beta-binomial regression. We recommend using this method when
13- more than three replicates are available in each group. For rapid differential
14- methylation analysis the regression-based method should be run on a large
15- machine with many cores. Note that the actual processing time depends on the
16- coverage of each methylome, the number of sites analyzed, and the number of
17- methylomes in the dataset.
18-
19- ### Generating proportion tables
20-
21- The first step in the differential methylation analysis is to assemble a
22- proportion table containing read proportions for all target
23- methylomes. Dnmtools includes a program [ merge] ( ../merge ) to generate a
24- proportion table from the given collection of methylomes. Suppose that we want
25- to compare methylomes named ` control-a.meth ` , ` control-b.meth ` ,
26- ` control-c.meth ` to the methylomes ` case-a.meth ` , ` case-b.meth ` ,
27- ` case-c.meth ` . The proportion table can be created with the following
28- command:
13+ more than three replicates are available in each group, or for a more
14+ complicated experimental design, there are enough samples to fit the
15+ parameters. The radmeth command can take advantage of multiple cores for
16+ improved speed. The processing time depends on the number of sites analyzed
17+ and the number of methylomes in the dataset.
18+
19+ ### Generating input tables
20+
21+ The first step in the differential methylation analysis is to assemble a table
22+ with the counts of total reads and methylated reads for each site (rows) and
23+ each methylome (columns). Dnmtools includes a command [ merge] ( ../merge ) to
24+ generate this kind of table from the given collection of methylomes in
25+ [ counts] ( ../counts ) format.
26+
27+ Features: although the explanation here focuses on individual CpG sites, the
28+ identical method can be applied to genomic intervals as features (rows). The
29+ common requirement is that in each row, each "column" has a count for total
30+ reads and a count for reads indicating methylation. One prominent example is
31+ to run the ` roi ` command on a set of genomic intervals, and use the output as
32+ the basis for differential methylation analysis.
33+
34+ Suppose that we want to compare methylomes named ` control_a.sym ` ,
35+ ` control_b.sym ` , ` control_c.sym ` to the methylomes ` case_a.sym ` , ` case_b.sym ` ,
36+ ` case_c.sym ` . Each of these filenames suggests that the methylation is for
37+ symmetric CpG sites as would be obtained using the [ sym] ( ../sym ) command.
38+
39+ The data matrix can be created with the following command:
2940
3041``` console
3142$ dnmtools merge -t -radmeth \
32- control-a .meth control-b .meth control-c .meth \
33- case-a .meth case-b .meth case-c .meth > proportion-table .txt
43+ control_a .meth control_b .meth control_c .meth \
44+ case_a .meth case_b .meth case_c .meth > data_table .txt
3445```
3546
36- This is what ` proportion-table .txt` looks like:
47+ This is what ` data_table .txt` looks like:
3748
3849``` txt
3950control_a control_b control_c case_a case_b case_c
@@ -43,17 +54,21 @@ chr1:160:+:CpG 12 8 10 5 17 4 15 14 1
4354chr1:309:+:CpG 1 1 1 0 17 12 12 8 2 1 19 8
4455```
4556
46- As indicated in the header, this proportion table contains information about 6
57+ As indicated in the header, this table contains information about 6
4758methylomes: 3 controls and 3 cases. Each row of the table contains
48- information about a CpG site and a proportion of reads mapping over this site
49- in each methylome. For example, the first row describes a cytosine within a
50- CpG site located on chromosome 1 at position 108. This site is present in 9
51- reads in the methylome control a and is methylated in 6 of them. Note that the
52- dnmtools ` merge ` command adds methylomes into the proportion table in the
53- order in which they are listed on the command line.
54-
55- Note: the header conforms to a traditional "data frame" from R, which does not
56- include a column name for the row names, which are the first column.
59+ information about an individual CpG site, and two values for each column
60+ heading: one value being the count of total reads and the second the count of
61+ methylated reads. Note that the second value does not need to be integers,
62+ which can happen when reads contribute fractionally, as in counts from
63+ nanopore. For example, the first row describes a cytosine within a CpG site
64+ located on chromosome 1 at position 108. This site is covered by 9 reads in
65+ the methylome "control a" and 6 of those reads indicate methylation. Note that
66+ the dnmtools ` merge ` command adds methylomes into the data matrix in the order
67+ in which they are listed on the command line.
68+
69+ Note: the header does not include a column name for the first column, and for
70+ each methylome, currently there is only one column name for each pair of
71+ columns in this format.
5772
5873### Design matrix
5974
@@ -71,25 +86,25 @@ case_c 1 1
7186```
7287
7388The design matrix shows that samples in this dataset are associated with two
74- factors: base and case. The first column corresponds to the base factor and
75- will always be present in the design matrix. Think of it as stating that all
89+ factors: base and case. The first column corresponds to the intercept and will
90+ always be present in the design matrix. Think of it as stating that all
7691samples have the same baseline mean methylation level. To distinguish cases
7792from controls we add another factor case (second column). The ` 1 ` s in this
78- column correspond to the samples which belong to the cases group. You can use
79- this design matrix as a template to create design matrices for two-group
93+ second column indicate the methylomes that belong to the cases group. You can
94+ use this design matrix as a template to create design matrices for two-group
8095comparisons involving arbitrary many methylomes.
8196
82- After creating the proportion table and the design matrix, we are now ready to
83- start the differential methylation analysis. It consists of (1) regression,
97+ After creating the data matrix and the design matrix, we are now ready to
98+ start the differential methylation analysis. It consists of (1) regression,
8499(2) combining significance, and (3) multiple testing adjustment steps.
85100
86101### Regression
87102
88- Suppose that the ` proportion-table .txt` and ` design-matrix .txt` are as
103+ Suppose that the ` data_table .txt` and ` design_matrix .txt` are as
89104described above. The regression step is run with the command
90105
91106``` console
92- $ dnmtools radmeth -factor case -o output.txt design-matrix .txt proportion-table .txt
107+ $ dnmtools radmeth -factor case -o output.txt design_matrix .txt data_table .txt
93108```
94109
95110The ` -factor ` parameter specifies the factor with respect to which we want to
@@ -101,18 +116,36 @@ respectively. The p-value (5-th column) is given by the log-likelihood ratio
101116test.
102117
103118Depending on the distribution of methylated and unmethylated CpGs, some
104- p-values may not be calculated. If there are no reads that cover a given CpG,
105- the value ` NA_LOW_COV ` will be printed instead of a p-value. If all CpGs are
106- fully methylated and fully methylated in both case and control, we say the CpG
107- has an "extreme distribution". In these cases, we cannot reject the null and
108- output ` NA_EXTREME_CNT ` . Finally, if there are numerical errors in the
109- log-likelihood ratio test, we simply print ` NA ` . You can opt out of these
110- additional NA informations by not using the ` -n ` flag.
111-
112- We do not recommend relying too much on the individual p-values of CpGs from
113- radmeth, as they often do not contain sufficient coverage for significant
114- biological interpretations. Instead, we recommend merging p-values of
115- neighboring CpGs using [ radadjust] ( ../radadjust ) .
119+ p-values may not be calculated, and a value of NA will be output. If the
120+ argument ` -na-info ` is used, the following detail will be given. If there are
121+ no reads that cover a given CpG, the value ` NA_LOW_COV ` will be printed
122+ instead of a p-value. If all CpGs are fully methylated and fully methylated in
123+ both case and control, we say the CpG has a "extreme" counts. In these cases,
124+ we cannot reject the null and output ` NA_EXTREME_CNT ` . Finally, if there are
125+ numerical errors in the log-likelihood ratio test, we simply print ` NA ` .
126+
127+ ## Output format
128+
129+ The output for ` radmeth ` is one line for each row of the input data matrix.
130+ If the input data matrix has rownames with "tokens" separated by colons, for
131+ example "chr3:67363494:+: CpG ", then this will appear in the output but with
132+ the colons replaced by tabs. If the rownames in the input file do not have
133+ colons, they will be output as is, in the first column of the output file.
134+
135+ - The second column, or the first column after the (possibly transformed)
136+ rowname, is the p-value for that column, or an NA value (see above).
137+ - After the p-value, the mean methylation per "group" is given in each
138+ subsequent column. Here, a "group" is a combination of factor levels,
139+ assuming binary factors. The order of groups corresponds to the order of
140+ their binary representation in the design matrix. The order for the groups
141+ in the example design matrix below would be (MB=100, MA=101, FB=110,
142+ FA=111).
143+ - The final column in the output is the "overdispersion factor" for the
144+ beta-binomial. Assume ` phi ` is the dispersion. The binomial variance is
145+ ` np(1-p) ` and the beta-binomial variance is ` np(1-p)((n+phi)/(phi+1)) ` . So
146+ ` (n - 1)/(phi + 1) ` is the factor by which the variance for the
147+ beta-binomial exceeds that of the binomial. An overdispersion factor of 0
148+ means the beta-binomial is behaving just like a binomial.
116149
117150## Tutorial
118151
@@ -281,17 +314,17 @@ differential methylation between levels for our factor of interest (named
281314"factor" in the design matrix). Here is a look at part of the output:
282315
283316``` console
284- $ head sim/ samples.radmeth
285- chr1 163 + CG 0.0877822 35 22 45 36
286- chr1 206 + CG 0.442745 37 30 43 38
287- chr1 232 + CG 0.756925 28 20 35 26
288- chr1 278 + CG 0.794626 43 35 37 31
289- chr1 296 + CG 0.635986 33 29 38 32
290- chr1 310 + CG 0.641986 37 28 31 22
291- chr1 322 + CG 0.0973903 38 33 47 35
292- chr1 324 + CG 0.260703 40 29 31 26
293- chr1 350 + CG 0.888242 36 30 35 29
294- chr1 356 + CG 0.0535286 37 35 42 33
317+ $ head samples.radmeth | column -t
318+ chr1 163 + CG 0.0863989 0.818157 0.653660 0.775035 0.591029 0.000052
319+ chr1 206 + CG 0.443989 0.841557 0.764998 0.908700 0.859154 0.000091
320+ chr1 232 + CG 0.756234 0.776885 0.744420 0.725115 0.688140 0.000242
321+ chr1 278 + CG 0.77863 0.831485 0.807046 0.842138 0.818908 0.000808
322+ chr1 296 + CG 0.648263 0.848138 0.884828 0.836674 0.875727 0.000341
323+ chr1 310 + CG 0.640836 0.729179 0.780351 0.689915 0.745921 0.139695
324+ chr1 322 + CG 0.0972604 0.679385 0.849711 0.789027 0.908915 0.000235
325+ chr1 324 + CG 0.25803 0.861294 0.753022 0.822346 0.694456 0.008238
326+ chr1 350 + CG 0.890771 0.844111 0.855183 0.807851 0.820951 0.000267
327+ chr1 356 + CG 0.0527503 0.750013 0.933344 0.818157 0.954543 0.000315
295328```
296329
297330Focusing on the 5th column, we see values between 0 and 1, but none of them
@@ -306,16 +339,19 @@ for i in M F A B; do
306339done
307340```
308341
342+ (The argument ` -relaxed ` to the [ selectsites] ( ../selectsites ) command is to
343+ allow for flexibility in the column format after the first 6.)
344+
309345The result allows us to verify that ` radmeth ` with the design matrix given
310346above identifies sites as significant when they differ between levels A and B
311347of the factor of interest:
312348
313349``` console
314350$ for i in sim/features_[ABFM].txt; do echo $i ` awk ' BEGIN{k=0;c=0}{k+=$5;c+=1}END{print k,c,k/c}' $i ` ; done | column -t
315- sim/features_A.txt 0.256072 430 0.000595517
316- sim/features_B.txt 0.114786 372 0.000308564
317- sim/features_F.txt 197.332 400 0.493329
318- sim/features_M.txt 297.728 588 0.50634
351+ sim/features_A.txt 0.255514 430 0.000594218
352+ sim/features_B.txt 0.11431 372 0.000307286
353+ sim/features_F.txt 196.602 400 0.491505
354+ sim/features_M.txt 296.222 588 0.50378
319355```
320356
321357The p-values in features associated with either M or F are averaging around
@@ -354,10 +390,10 @@ analogous but with this modified design matrix:
354390$ dnmtools radmeth -o sim/samples_noint.radmeth -f factor design_noint.txt sim/table.txt
355391$ for i in M F A B; do dnmtools selectsites -relaxed -o sim/features_noint_${i} .txt sim/features_${i} .bed sim/samples_noint.radmeth; done
356392$ for i in sim/* _noint_* .txt; do echo $i ` awk ' BEGIN{k=0;c=0}{k+=$5;c+=1}END{print k,c,k/c}' $i ` ; done | column -t
357- sim/features_noint_A.txt 8.27931 430 0.0192542
358- sim/features_noint_B.txt 15.2397 372 0.040967
359- sim/features_noint_F.txt 77.2656 400 0.193164
360- sim/features_noint_M.txt 93.7312 588 0.159407
393+ sim/features_noint_A.txt 8.27797 430 0.0192511
394+ sim/features_noint_B.txt 15.2391 372 0.0409654
395+ sim/features_noint_F.txt 77.2454 400 0.193114
396+ sim/features_noint_M.txt 93.7184 588 0.159385
361397```
362398
363399Although the sites within features corresponding to A and B are much lower on
0 commit comments