@@ -1354,7 +1354,7 @@ compute_contrast_bases <- function(i) {
1354
1354
# Make binary vector for treatment argument to methRead()
1355
1355
curr_treatment_vec <- c()
1356
1356
for (value in curr_sample_info_df $ condition ) {
1357
- if (value == curr_sample_info_df $ condition [1 ]) {
1357
+ if (value == curr_contrasts_vec [1 ]) {
1358
1358
curr_treatment_vec <- c(curr_treatment_vec , 1 )
1359
1359
} else {
1360
1360
curr_treatment_vec <- c(curr_treatment_vec , 0 )
@@ -1368,7 +1368,7 @@ compute_contrast_bases <- function(i) {
1368
1368
methylKit :: unite(reorganize(
1369
1369
meth_obj ,
1370
1370
sample.ids = as.list(curr_samples_vec ),
1371
- treatment = as.integer( factor ( curr_sample_info_df $ condition )) - 1
1371
+ treatment = curr_treatment_vec
1372
1372
),
1373
1373
min.per.group = 1L ), # Keep only bases with coverage in at least one sample per group
1374
1374
mc.cores = myargs $ mc_cores )
@@ -1490,7 +1490,44 @@ rm(df_list)
1490
1490
### 11f. Tile analysis
1491
1491
1492
1492
``` R
1493
- # ## Tile analysis ###
1493
+ # ## Function for computing differential methylation per tile for each contrasts ###
1494
+ compute_contrast_tiles <- function (i ) {
1495
+ # Get current contrast
1496
+ curr_contrasts_vec <- contrasts [, i ]
1497
+
1498
+ # Get subset sample info table relevant to current contrast
1499
+ curr_sample_info_df <- sample_meth_info_df %> % filter(condition %in% curr_contrasts_vec )
1500
+
1501
+ # Get which samples are relevant to current contrast
1502
+ curr_samples_vec <- curr_sample_info_df %> % pull(sample_id )
1503
+
1504
+ # Make binary vector for treatment argument to methRead()
1505
+ curr_treatment_vec <- c()
1506
+ for (value in curr_sample_info_df $ condition ) {
1507
+ if (value == curr_contrasts_vec [1 ]) {
1508
+ curr_treatment_vec <- c(curr_treatment_vec , 1 )
1509
+ } else {
1510
+ curr_treatment_vec <- c(curr_treatment_vec , 0 )
1511
+ }
1512
+ }
1513
+
1514
+ # return methylation statistics for tiles
1515
+ return (
1516
+ as.data.frame(getData(
1517
+ calculateDiffMeth(
1518
+ methylKit :: unite(reorganize(
1519
+ meth_tiles_obj ,
1520
+ sample.ids = as.list(curr_samples_vec ),
1521
+ treatment = curr_treatment_vec
1522
+ ),
1523
+ min.per.group = 1L ), # Keep only tiles with coverage in at least one sample per group
1524
+ mc.cores = myargs $ mc_cores )
1525
+ )
1526
+ ) %> %
1527
+ relocate(" meth.diff" , .before = " pvalue" ) %> % # move methyl diff value before stats values
1528
+ rename_with(~ paste0(.x , " _" , colnames(contrasts )[i ]), any_of(c(" pvalue" , " qvalue" , " meth.diff" )))
1529
+ )
1530
+ }
1494
1531
1495
1532
# Group bases into tiles
1496
1533
meth_tiles_obj <- tileMethylCounts(norm_meth_obj ,
0 commit comments