Skip to content

Commit

Permalink
Add condition to execute the module and update snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmmobbs93 committed Dec 20, 2024
1 parent 3834865 commit 6dafd95
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
8 changes: 7 additions & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ process {
}

withName: VALIDATE_MODEL {
ext.args = { params.observations_id_col ? "--sample_id_col ${params.observations_id_col}" : '' }
ext.args = {
params.observations_name_col ?
"--sample_id_col ${params.observations_name_col}" :
params.observations_id_col ?
"--sample_id_col ${params.observations_id_col}" :
''
}
publishDir = [
path: { "${params.outdir}/validate" },
mode: params.publish_dir_mode,
Expand Down
4 changes: 2 additions & 2 deletions modules/local/validatemodel/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ process VALIDATE_MODEL {
'community.wave.seqera.io/library/r-jsonlite_r-optparse_r-tidyverse_r-yaml:18dc3fc2d990206d' }"

input:
path samplesheet
tuple val(meta), path(models_yml)
tuple val(meta) , path(samplesheet)
tuple val(meta2), path(models_yml)

output:
tuple val(meta), path("pheno_table.csv"), emit: pheno_table
Expand Down
22 changes: 19 additions & 3 deletions modules/local/validatemodel/resources/usr/bin/validate_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,31 @@ sample_column <- opt$sample_id_col # "sample" #
# LOAD FILES --------------------------------------------------------
## Load models.yml file
tryCatch({
models <- read_yaml(path_yml)
if (!file.exists(path_yml)) {
stop(sprintf("File '%s' does not exist.", path_yml), call. = FALSE)
}
if (!grepl("\\.(yaml|yml)$", path_yml, ignore.case = TRUE)) {
stop(sprintf("File '%s' is not a YAML file (expected .yaml or .yml extension).", path_yml), call. = FALSE)
}
models <- yaml::read_yaml(path_yml)
cat("Loaded YML file successfully.\n")
}, error = function(e) {
stop("Error loading YML file: ", e$message)
stop(sprintf("Error loading YML file '%s': %s", path_yml, e$message), call. = FALSE)
})

## Load samplesheet CSV file
tryCatch({
samplesheet <- readr::read_csv(path_samplesheet, show_col_types = FALSE)
# Set the separator based on the file extension
sep <- if (str_detect(path_samplesheet, "\\.(csv|CSV)$")) {
","
} else if (str_detect(path_samplesheet, "\\.(tsv|TSV)$")) {
"\t"
} else {
stop("Unsupported file extension. Please provide a .csv or .tsv file.")
}

# Read the file using the determined separator
samplesheet <- read_delim(path_samplesheet, delim = sep, show_col_types = FALSE)
if ( !sample_column %in% colnames(samplesheet) ) {
stop(paste0("The sample identificator column '", sample_column, "' is not present in the samplesheet file") )
}
Expand Down
3 changes: 3 additions & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ set -C # No clobber - prevent output redirection from overwriting files.
// Disable process selector warnings by default. Use debug profile to enable warnings.
nextflow.enable.configProcessNamesValidation = false

// Enable loading modules bin files
nextflow.enable.moduleBinaries = true

def trace_timestamp = new java.util.Date().format( 'yyyy-MM-dd_HH-mm-ss')
timeline {
enabled = true
Expand Down
17 changes: 12 additions & 5 deletions tests/test.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
},
"Test profile with yaml contrasts": {
"content": [
21,
22,
{
"DESEQ2_DIFFERENTIAL": {
"r-base": "4.1.3",
Expand Down Expand Up @@ -321,7 +321,11 @@
"tables/differential/treatment_mCherry_hND6_sample_number.deseq2.results_filtered.tsv",
"tables/processed_abundance",
"tables/processed_abundance/all.normalised_counts.tsv",
"tables/processed_abundance/all.vst.tsv"
"tables/processed_abundance/all.vst.tsv",
"validate",
"validate/designs.json",
"validate/pheno_table.csv",
"validate/versions.yml"
],
[
"treatment_mCherry_hND6_.dds.rld.rds:md5,dfe51910e230ae9cc2bc9fa5651666ba",
Expand Down Expand Up @@ -368,13 +372,16 @@
"treatment_mCherry_hND6_sample_number.deseq2.results.tsv:md5,b41cbaacd04a25b45295f3f987ff7500",
"treatment_mCherry_hND6_sample_number.deseq2.results_filtered.tsv:md5,98fa3ec0992859d2a524ecce1259f0ed",
"all.normalised_counts.tsv:md5,1d7ad0c02b483f2eff1a5b357a74d011",
"all.vst.tsv:md5,a08d06d3c3218619b7bd85beead467bd"
"all.vst.tsv:md5,a08d06d3c3218619b7bd85beead467bd",
"designs.json:md5,088d536fdff430dc12f4f8b0395a9636",
"pheno_table.csv:md5,4969fce19ad1ea5b3cf124f4dcc6a403",
"versions.yml:md5,592a22e359ab942c2d315ef0c6ed3fb1"
]
],
"meta": {
"nf-test": "0.9.0",
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2024-12-20T13:41:10.4647836"
"timestamp": "2024-12-20T19:25:36.541448998"
}
}
17 changes: 12 additions & 5 deletions tests/test_maxquant.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
},
"Test maxquant profile with yaml contrasts": {
"content": [
20,
21,
{
"LIMMA_DIFFERENTIAL": {
"r-base": "4.3.3",
Expand Down Expand Up @@ -289,7 +289,11 @@
"tables/proteus/Celltype/raw_proteingroups_tab.tsv",
"tables/proteus/fakeBatch",
"tables/proteus/fakeBatch/normalizeMedian.normalized_proteingroups_tab.tsv",
"tables/proteus/fakeBatch/raw_proteingroups_tab.tsv"
"tables/proteus/fakeBatch/raw_proteingroups_tab.tsv",
"validate",
"validate/designs.json",
"validate/pheno_table.csv",
"validate/versions.yml"
],
[
"fakebatch_fakeBatch_b1_b2.MArrayLM.limma.rds:md5,f321bf1e4fd44827810df9a9c38776d6",
Expand Down Expand Up @@ -342,13 +346,16 @@
"normalizeMedian.normalized_proteingroups_tab.tsv:md5,154fcd8d23409981b897d153e7b7e34e",
"raw_proteingroups_tab.tsv:md5,33a8791f84c676ea1aea4842231acb6a",
"normalizeMedian.normalized_proteingroups_tab.tsv:md5,154fcd8d23409981b897d153e7b7e34e",
"raw_proteingroups_tab.tsv:md5,33a8791f84c676ea1aea4842231acb6a"
"raw_proteingroups_tab.tsv:md5,33a8791f84c676ea1aea4842231acb6a",
"designs.json:md5,4ef011dc27b01e863483eb06f0bc4006",
"pheno_table.csv:md5,e42e42e88a3f71959fd0750dfe93417a",
"versions.yml:md5,592a22e359ab942c2d315ef0c6ed3fb1"
]
],
"meta": {
"nf-test": "0.9.0",
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2024-12-20T13:45:34.62418232"
"timestamp": "2024-12-20T20:09:08.805617631"
}
}
14 changes: 9 additions & 5 deletions workflows/differentialabundance.nf
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ workflow DIFFERENTIALABUNDANCE {
ch_contrasts_file = Channel.from([[exp_meta, file(params.contrasts)]])


// Run module to validate models
VALIDATE_MODEL(
ch_input,
ch_contrasts_file
)
// Run module to validate models from yml file
if ( params.contrasts.endsWith(".yaml") || params.contrasts.endsWith(".yml") ) {

VALIDATE_MODEL (
ch_input,
ch_contrasts_file
)

}

// If we have affy array data in the form of CEL files we'll be deriving
// matrix and annotation from them
Expand Down

0 comments on commit 6dafd95

Please sign in to comment.