Skip to content

Commit

Permalink
Fix mismatch problem when passing user-defined contrast matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene233 committed Jan 9, 2024
1 parent 5f85fe7 commit e66c48c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
# mastR 1.3.1

* Remove Matrix version bound.

# mastR 1.3.2

* Update function `voom_fit_treat()` to allow pass user-defined contrast matrix.
24 changes: 6 additions & 18 deletions R/DE_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,11 @@ voom_fit_treat <- function(dge,
make.names(target_group),
"Others"
)
## set target_group to be the first level
dge$samples$group <- factor(dge$samples$group,
levels = c(make.names(target_group), "Others")
)
} else {
dge$samples$group <- ifelse(grepl(target_group, dge$samples[[group_col]]),
make.names(target_group),
make.names(dge$samples[[group_col]])
)
## set target_group to be the first level
dge$samples$group <- factor(
dge$samples$group,
levels = c(
make.names(target_group),
unique(dge$samples$group[dge$samples$group != make.names(target_group)])
)
)
}

## make design
Expand All @@ -92,14 +80,14 @@ voom_fit_treat <- function(dge,
contrast.mat <- list(...)[["contrast_mat"]]
## check contrast.mat validity
stopifnot("contrast.mat must be a matrix!" = is.matrix(contrast.mat),
"contrast.mat levels/rownames are not consistent with design matrix!" =
identical(sort(rownames(contrast.mat)), sort(colnames(design))))
"contrast.mat levels/rownames don't match design matrix!" =
identical(rownames(contrast.mat), colnames(design)))
}else {
contrast.mat <- limma::makeContrasts(
contrasts = c(paste(levels(dge$samples$group)[1],
levels(dge$samples$group)[-1],
sep = "-"
)),
contrasts = c(sprintf("%s-%s",
make.names(target_group),
make.names(setdiff(dge$samples$group, make.names(target_group)))
)),
## target_group vs all the rest respectively
## if group = TRUE, it's target_group vs Others
levels = design
Expand Down

0 comments on commit e66c48c

Please sign in to comment.