Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions assets/differentialabundance_report.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,51 @@ differential_file_suffix <- params$meta$params$differential_file_suffix
if (is.null(differential_file_suffix)) {
differential_file_suffix <- paste0(".", params$meta$params$differential_method, ".results.tsv")
}
differential_files <- lapply(contrasts$id, function(d) {
file.path(params$input_dir, paste0(gsub(" |;", "_", d), differential_file_suffix))
})
resolve_differential_file <- function(contrast_id, contrast_index) {
candidate_id <- as.character(contrast_id)

if (!is.na(candidate_id) && nzchar(candidate_id)) {
candidate_file <- file.path(params$input_dir, paste0(gsub(" |;", "_", candidate_id), differential_file_suffix))
if (file.exists(candidate_file)) {
return(candidate_file)
}
}

available_files <- list.files(
params$input_dir,
pattern = paste0(gsub("\\.", "\\\\.", differential_file_suffix), "$"),
full.names = TRUE
)

if (length(available_files) == nrow(contrasts)) {
return(sort(available_files)[contrast_index])
}

stop(
"Could not resolve differential file for contrast row ",
contrast_index,
" with id '",
candidate_id,
"'. Available differential files: ",
paste(basename(available_files), collapse = ", ")
)
}

differential_files <- mapply(
resolve_differential_file,
contrasts$id,
seq_len(nrow(contrasts)),
SIMPLIFY = FALSE
)
differential_names <- paste0(contrasts$id)
missing_differential_names <- is.na(differential_names) | !nzchar(differential_names)
if (any(missing_differential_names)) {
differential_names[missing_differential_names] <- sub(
paste0(gsub("\\.", "\\\\.", differential_file_suffix), "$"),
"",
basename(unlist(differential_files)[missing_differential_names])
)
}

# Initialize vector to store warning messages before merging tables
warnings_list <- c()
Expand Down
27 changes: 27 additions & 0 deletions assets/schema_contrasts.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@
"additionalProperties": false
},
"minItems": 1
},
"variables": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["string", "integer", "number", "numeric"]
},
"description": {
"type": "string"
},
"enum": {
"type": "array",
"items": {
"type": ["string", "number", "integer"]
},
"minItems": 1,
"uniqueItems": true
},
"minimum": {
"type": "number"
}
},
"additionalProperties": false
}
}
},
"required": ["contrasts"],
Expand Down
16 changes: 16 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ The necessary fields in order are:
- `formula` - A string representation of the model formula. It is used to build the design matrix.
- `make_contrasts_str` - An explicit literal contrast string (e.g., "treatmenthND6 - treatmentmCherry") that is passed directly to [`limma::makeContrasts()`](https://rdrr.io/bioc/limma/man/makeContrasts.html) in `VARIANCEPARTITION_DREAM`, `LIMMA_DIFFERENTIAL` and `DESEQ2_DIFFERENTIAL`. The parameter names must be syntactically valid variable names in R (see [`make.names`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/make.names.html)). This field provides full control for complex designs. Requires `formula`.

YAML contrast files can also include optional variable definitions. In the prototype implementation, `enum` values are used to set factor levels in the listed order before model matrices and contrast strings are evaluated:

```yaml
variables:
condition:
type: string
description: treatment group
enum: ["treated", "control"]
contrasts:
- id: condition_treated_control
formula: "~ condition"
make_contrasts_str: "conditioncontrol"
```

Supported prototype fields are `type`, `description`, `enum`, and `minimum`. `enum` is the important field for categorical variables because its first value becomes the model baseline for intercept-style formulas.

> [!IMPORTANT]
>
> - YAML contrast definitions using `comparison` **and** those using `formula` are both supported by all differential methods.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 79 additions & 1 deletion modules/nf-core/limma/differential/templates/limma_de.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading