Skip to content

Commit 7dfbb47

Browse files
Merge pull request #145 from nasa/GL-DPPD-7113-patch-1
Fixed treatment vector to always assign "treatment" state to 1st group in contrasts vector and "control" state to 2nd group.
2 parents d81c2c0 + e6fb470 commit 7dfbb47

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

Methyl-Seq/Pipeline_GL-DPPD-7113_Versions/GL-DPPD-7113.md

+40-3
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ compute_contrast_bases <- function(i) {
13541354
# Make binary vector for treatment argument to methRead()
13551355
curr_treatment_vec <- c()
13561356
for (value in curr_sample_info_df$condition) {
1357-
if (value == curr_sample_info_df$condition[1]) {
1357+
if (value == curr_contrasts_vec[1]) {
13581358
curr_treatment_vec <- c(curr_treatment_vec, 1)
13591359
} else {
13601360
curr_treatment_vec <- c(curr_treatment_vec, 0)
@@ -1368,7 +1368,7 @@ compute_contrast_bases <- function(i) {
13681368
methylKit::unite(reorganize(
13691369
meth_obj,
13701370
sample.ids = as.list(curr_samples_vec),
1371-
treatment = as.integer(factor(curr_sample_info_df$condition)) - 1
1371+
treatment = curr_treatment_vec
13721372
),
13731373
min.per.group = 1L), # Keep only bases with coverage in at least one sample per group
13741374
mc.cores = myargs$mc_cores)
@@ -1490,7 +1490,44 @@ rm(df_list)
14901490
### 11f. Tile analysis
14911491

14921492
```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+
}
14941531

14951532
# Group bases into tiles
14961533
meth_tiles_obj <- tileMethylCounts(norm_meth_obj,

0 commit comments

Comments
 (0)