Skip to content

Commit

Permalink
Add gas parameter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kylacochrane committed Jun 17, 2024
1 parent 327e46b commit 95c0f5c
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
135 changes: 135 additions & 0 deletions tests/pipelines/main_gm_threshold.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
nextflow_pipeline {

name "Integration Tests of adjusting gm_thresholds parameters"
script "main.nf"

test("Test fail pipeline if null threshold set") {
tag "pipeline_failure_null_threshold"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = null
}
}

then {
assert workflow.failed
assert workflow.stdout.contains("ERROR ~ --gm_thresholds null: Cannot pass null or empty string")
}
}

test("Test fail pipeline if empty threshold set") {
tag "pipeline_failure_no_threshold"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = ""
}
}

then {
assert workflow.failed
assert workflow.stdout.contains("ERROR ~ --gm_thresholds : Cannot pass null or empty string")
}
}

test("Test fail pipeline if negative threshold set") {
tag "pipeline_failure_negative_threshold"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = "-1"
}
}

then {
assert workflow.failed
assert workflow.stderr.contains('* --gm_thresholds: string [-1] does not match pattern ^(\\d+(\\.\\d+)?,)*\\d+(\\.\\d+)?$ (-1)')
}
}

test("Test fail pipeline if mismatch between thresholds and scaled distm") {
tag "pipeline_failure_threshold_scaled"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = "1,0.5,2"
pd_distm = "scaled"
}
}

then {
assert workflow.failed
assert workflow.stdout.contains("ERROR ~ '--pd_distm scaled' is set, but '--gm_thresholds 1,0.5,2' contains thresholds outside of range [0,1]."
+ " Please either set '--pd_distm hamming' or adjust the threshold values.")
}
}

test("Test fail pipeline if mismatch between thresholds and hamming distm") {
tag "pipeline_failure_threshold_hamming"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = "2,1,0.5"
pd_distm = "hamming"
}
}

then {
assert workflow.failed
assert workflow.stdout.contains("ERROR ~ '--pd_distm hamming' is set, but '--gm_thresholds 2,1,0.5' contains fractions."
+ " Please either set '--pd_distm scaled' or remove fractions from distance thresholds.")
}
}

test("Test pipeline with single threshold set to 1") {
tag "pipeline_thresh_1"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = "1"
}
}

then {
assert workflow.failed
assert (workflow.stdout =~ /Error \[1.0\] supplied thresholds do not equal the number of threshold columns in reference_clusters.txt/).find()
}
}

test("Test pipeline with threshold set to 1,0") {
tag "pipeline_thresh_1.0"

when {
params {
input = "$baseDir/tests/data/samplesheets/samplesheet1.csv"
outdir = "results"

gm_thresholds = "1,0"
}
}

then {
assert workflow.failed
assert (workflow.stdout =~ /Error \[1.0, 0.0\] supplied thresholds do not equal the number of threshold columns in reference_clusters.txt/).find()
}
}
}
22 changes: 21 additions & 1 deletion workflows/gas_nomenclature.nf
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,27 @@ workflow GAS_NOMENCLATURE {

expected_clusters = CLUSTER_FILE(clusters)

// GAS CALL
// GAS CALL processes

if(params.gm_thresholds == null || params.gm_thresholds == ""){
exit 1, "--gm_thresholds ${params.gm_thresholds}: Cannot pass null or empty string"
}

gm_thresholds_list = params.gm_thresholds.split(',')
if (params.pd_distm == 'hamming') {
if (gm_thresholds_list.any { it != null && it.contains('.') }) {
exit 1, ("'--pd_distm ${params.pd_distm}' is set, but '--gm_thresholds ${params.gm_thresholds}' contains fractions."
+ " Please either set '--pd_distm scaled' or remove fractions from distance thresholds.")
}
} else if (params.pd_distm == 'scaled') {
if (gm_thresholds_list.any { it != null && (it as Float < 0 || it as Float > 1) }) {
exit 1, ("'--pd_distm ${params.pd_distm}' is set, but '--gm_thresholds ${params.gm_thresholds}' contains thresholds outside of range [0,1]."
+ " Please either set '--pd_distm hamming' or adjust the threshold values.")
}
} else {
exit 1, "'--pd_distm ${params.pd_distm}' is an invalid value. Please set to either 'hamming' or 'scaled'."
}

called_data = GAS_CALL(expected_clusters.text, distances.results)
ch_versions = ch_versions.mix(called_data.versions)

Expand Down

0 comments on commit 95c0f5c

Please sign in to comment.