|
| 1 | +nextflow_pipeline { |
| 2 | + |
| 3 | + name "Test Workflow annotate.nf" |
| 4 | + script "workflows/annotate.nf" |
| 5 | + tag "workflow" |
| 6 | + |
| 7 | + test("-profile test") { |
| 8 | + |
| 9 | + when { |
| 10 | + params { |
| 11 | + project_name = "nf_test_annotate" |
| 12 | + results_dir = "$outputDir" |
| 13 | + if (System.getenv('CONTAINER_TAG_NAME')) { |
| 14 | + container_tag_name = System.getenv('CONTAINER_TAG_NAME') |
| 15 | + } else if (System.getenv('CONTAINER_TAG_BASE')) { |
| 16 | + container_tag_name = "${System.getenv('CONTAINER_TAG_BASE')}${params.container_arch == 'arm64' ? '-arm64-latest' : '-latest'}" |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + then { |
| 22 | + assert workflow.success |
| 23 | + |
| 24 | + // Rounds floats to `decimals` places. Little groovy magic to avoid floating-point differences in test comparisons |
| 25 | + // e.g. with decimals=3, "1.2345" -> "1.235" (HALF_UP rounds the .5 tie up) |
| 26 | + // Only whole fields matching the float pattern are rounded (via ==~, a full-string match) - |
| 27 | + // multi-dot values like a cath_label "3.40.50.720" are left untouched instead of being |
| 28 | + // mangled by matching "3.40" as a substring. |
| 29 | + def roundFloats = { String path, String delimiter = '\t', int decimals = 3 -> |
| 30 | + file(path).readLines().collect { line -> |
| 31 | + line.split(delimiter, -1).collect { field -> |
| 32 | + field ==~ /-?\d+\.\d+/ ? new BigDecimal(field).setScale(decimals, java.math.RoundingMode.HALF_UP).toString() : field |
| 33 | + }.join(delimiter) |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // stable_path: all files/folders under the results dir with a stable path (incl. file name) |
| 38 | + def stable_path = getAllFilesFromDir(params.results_dir, relative: true, includeDir: true, ignore: ['*.html', 'WORKFLOW_COMPLETED']) |
| 39 | + // stable_content: all files under the results dir with stable content (volatile files excluded via .nftignore) |
| 40 | + def stable_content = getAllFilesFromDir(params.results_dir, ignoreFile: 'tests/.nftignore') |
| 41 | + |
| 42 | + // Files with known floating-point jitter: compare rounded content instead of raw bytes |
| 43 | + def rounded_final_results = roundFloats("${params.results_dir}/final_results.tsv") |
| 44 | + def rounded_merizo = roundFloats("${params.results_dir}/domain_assignments.merizo.tsv") |
| 45 | + def rounded_domain_quality = roundFloats("${params.results_dir}/all_domain_quality.csv", ',') |
| 46 | + |
| 47 | + assertAll( |
| 48 | + { assert snapshot( |
| 49 | + stable_path, stable_content, |
| 50 | + rounded_final_results, rounded_merizo, rounded_domain_quality |
| 51 | + ).match() } |
| 52 | + ) |
| 53 | + } |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments