Skip to content

Commit 452bbc2

Browse files
authored
New tests for samplesheet (#1856)
<!-- # nf-core/sarek pull request Many thanks for contributing to nf-core/sarek! Please fill in the appropriate checklist below (delete whatever is not relevant). These are the most common things requested on pull requests (PRs). Remember that PRs should be made against the dev branch, unless you're preparing a pipeline release. Learn more about contributing: [CONTRIBUTING.md](https://github.com/nf-core/sarek/tree/master/.github/CONTRIBUTING.md) --> ## PR checklist - [ ] This comment contains a description of changes (with reason). - [ ] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added a new tool - have you followed the pipeline conventions in the [contribution docs](https://github.com/nf-core/sarek/tree/master/.github/CONTRIBUTING.md) - [ ] If necessary, also make a PR on the nf-core/sarek _branch_ on the [nf-core/test-datasets](https://github.com/nf-core/test-datasets) repository. - [ ] Make sure your code lints (`nf-core pipelines lint`). - [ ] Ensure the test suite passes (`nextflow run . -profile test,docker --outdir <OUTDIR>`). - [ ] Check for unexpected warnings in debug mode (`nextflow run . -profile debug,test,docker --outdir <OUTDIR>`). - [ ] Usage Documentation in `docs/usage.md` is updated. - [ ] Output Documentation in `docs/output.md` is updated. - [ ] `CHANGELOG.md` is updated. - [ ] `README.md` is updated (including new tool citations and authors/contributors).
1 parent 74624a3 commit 452bbc2

File tree

7 files changed

+133
-50
lines changed

7 files changed

+133
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- [1817](https://github.com/nf-core/sarek/pull/1817) - Added new contributor
1414
- [1841](https://github.com/nf-core/sarek/pull/1841) - Add pcr-indel-model parameter for GATK HaplotypeCaller
1515
- [1848](https://github.com/nf-core/sarek/pull/1848) - Add parameter for setting pixel distance for GATK MarkDuplicates
16+
- [1856](https://github.com/nf-core/sarek/pull/1856) - Added early failure when more than 1 normal sample per patient is provided for somatic variant calling
1617

1718
### Changed
1819

subworkflows/local/samplesheet_to_channel/main.nf

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,60 @@
11
workflow SAMPLESHEET_TO_CHANNEL{
22

33
take:
4-
ch_from_samplesheet //
5-
aligner //
6-
ascat_alleles //
7-
ascat_loci //
8-
ascat_loci_gc //
9-
ascat_loci_rt //
10-
bcftools_annotations //
11-
bcftools_annotations_tbi //
12-
bcftools_header_lines //
13-
build_only_index //
14-
dbsnp //
15-
fasta //
16-
germline_resource //
17-
intervals //
18-
joint_germline //
19-
joint_mutect2 //
20-
known_indels //
21-
known_snps //
22-
no_intervals //
23-
pon //
24-
sentieon_dnascope_emit_mode //
25-
sentieon_haplotyper_emit_mode //
26-
seq_center //
27-
seq_platform //
28-
skip_tools //
29-
snpeff_cache //
30-
snpeff_db //
31-
step //
32-
tools //
33-
umi_read_structure //
34-
wes //
4+
ch_from_samplesheet // samplesheet
5+
aligner // String: aligner
6+
ascat_alleles // Path: ascat alleles
7+
ascat_loci // Path: ascat loci
8+
ascat_loci_gc // Path: ascat loci gc
9+
ascat_loci_rt // Path: ascat loci rt
10+
bcftools_annotations // Path: bcftools annotations
11+
bcftools_annotations_tbi // Path: bcftools annotations tbi
12+
bcftools_header_lines // Path: bcftools header lines
13+
build_only_index // Boolean: build only index
14+
dbsnp // Path: dbsnp
15+
fasta // Path: fasta
16+
germline_resource // Path: germline resource
17+
intervals // Path: intervals
18+
joint_germline // Boolean: joint_germline
19+
joint_mutect2 // Boolean: joint_mutect2
20+
known_indels // Path: known indels
21+
known_snps // Path: known snps
22+
no_intervals // Boolean: no intervals
23+
pon // Path: pon
24+
sentieon_dnascope_emit_mode // String: sentieon dnascope emit mode
25+
sentieon_haplotyper_emit_mode // String: sentieon haplotyper emit mode
26+
seq_center // String: seq center
27+
seq_platform // String: seq platform
28+
skip_tools // Array: skip tools
29+
snpeff_cache // Path: snpeff cache
30+
snpeff_db // String: snpeff db
31+
step // String: step
32+
tools // Array: tools
33+
umi_read_structure // String: umi read structure
34+
wes // wes
3535

3636
main:
3737
ch_from_samplesheet.dump(tag:"ch_from_samplesheet")
38+
39+
ch_from_samplesheet
40+
.map { meta, _fastq_1, _fastq_2, _spring_1, _spring_2, _table, _cram, _crai, _bam, _bai, _vcf, _variantcaller ->
41+
// Get only the patient, sample and status fields from the meta map
42+
[meta.patient, meta.subMap('sample', 'status')]
43+
}
44+
.unique()
45+
.groupTuple()
46+
.map { patient, samples ->
47+
// Count samples with status 0 and status 1
48+
def status0_count = samples.count { it.status == 0 }
49+
def status1_count = samples.count { it.status == 1 }
50+
51+
// Check the condition and exit with an error if met
52+
if (status1_count == 1 && status0_count > 1) {
53+
System.err.println("Patient [${patient}] has more than one sample [${status0_count}] with normal status [0] and one sample with tumor status [1].")
54+
error("Execution halted due to sample status inconsistency.")
55+
}
56+
}
57+
3858
input_sample = ch_from_samplesheet.map{ meta, fastq_1, fastq_2, spring_1, spring_2, table, cram, crai, bam, bai, vcf, variantcaller ->
3959
// generate patient_sample key to group lanes together
4060
[ meta.patient + meta.sample, [meta, fastq_1, fastq_2, spring_1, spring_2, table, cram, crai, bam, bai, vcf, variantcaller] ]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
patient,sex,status,sample,cram,crai
2+
test,XX,0,sample1,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test.paired_end.recalibrated.sorted.cram,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test.paired_end.recalibrated.sorted.cram.crai
3+
test,XX,0,sample1B,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test.paired_end.recalibrated.sorted.cram,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test.paired_end.recalibrated.sorted.cram.crai
4+
test,XX,1,sample2,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test2.paired_end.recalibrated.sorted.cram,https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/illumina/cram/test2.paired_end.recalibrated.sorted.cram.crai

tests/default.nf.test

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,4 @@ nextflow_pipeline {
4949
)
5050
}
5151
}
52-
53-
test("-profile test --input tests/csv/3.0/sample_with_space.csv") {
54-
55-
when {
56-
params {
57-
input = "${projectDir}/tests/csv/3.0/sample_with_space.csv"
58-
outdir = "$outputDir"
59-
}
60-
}
61-
62-
then {
63-
assertAll(
64-
{ assert workflow.failed},
65-
{ assert workflow.stderr.toString().contains("Sample ID must be provided, cannot contain spaces and must be a string value") }
66-
)
67-
}
68-
}
6952
}

tests/default.nf.test.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@
324324
],
325325
"meta": {
326326
"nf-test": "0.9.2",
327-
"nextflow": "24.10.4"
327+
"nextflow": "25.02.1"
328328
},
329-
"timestamp": "2025-03-10T11:13:17.000556982"
329+
"timestamp": "2025-04-02T15:44:44.567674265"
330330
}
331331
}

tests/samplesheets.nf.test

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
nextflow_pipeline {
2+
3+
name "Test pipeline"
4+
script "../main.nf"
5+
tag "pipeline"
6+
tag "pipeline_sarek"
7+
tag "cpu"
8+
9+
test("-profile test --input tests/csv/3.0/sample_with_space.csv") {
10+
when {
11+
params {
12+
input = "${projectDir}/tests/csv/3.0/sample_with_space.csv"
13+
outdir = "$outputDir"
14+
}
15+
}
16+
17+
then {
18+
assertAll(
19+
{ assert workflow.failed},
20+
{ assert snapshot(
21+
workflow.stderr.toString().split(",")[0..1,3..5]
22+
).match() }
23+
)
24+
}
25+
}
26+
27+
test("-profile test --step variant_calling --input tests/csv/3.0/recalibrated_somatic_two_normal_one_sample.csv") {
28+
29+
when {
30+
params {
31+
modules_testdata_base_path = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/'
32+
input = "${projectDir}/tests/csv/3.0/recalibrated_somatic_two_normal_one_sample.csv"
33+
outdir = "$outputDir"
34+
step = "variant_calling"
35+
}
36+
}
37+
38+
then {
39+
assertAll(
40+
{ assert workflow.failed},
41+
{ assert snapshot(
42+
workflow.stderr.toString().split(",")[0]
43+
).match() }
44+
)
45+
}
46+
}
47+
}

tests/samplesheets.nf.test.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"-profile test --step variant_calling --input tests/csv/3.0/recalibrated_somatic_two_normal_one_sample.csv": {
3+
"content": [
4+
"[Patient [test] has more than one sample [2] with normal status [0] and one sample with tumor status [1].]"
5+
],
6+
"meta": {
7+
"nf-test": "0.9.2",
8+
"nextflow": "24.10.5"
9+
},
10+
"timestamp": "2025-04-03T17:48:43.052129562"
11+
},
12+
"-profile test --input tests/csv/3.0/sample_with_space.csv": {
13+
"content": [
14+
[
15+
"[\u001b[0;31mThe following invalid input values have been detected:",
16+
" ",
17+
" \t-> Entry 2: Error for field 'sample' (test 2): \"test 2\" does not match regular expression [^\\S+$] (Sample ID must be provided",
18+
" cannot contain spaces and must be a string value)",
19+
" \u001b[0m"
20+
]
21+
],
22+
"meta": {
23+
"nf-test": "0.9.2",
24+
"nextflow": "24.10.5"
25+
},
26+
"timestamp": "2025-04-03T12:12:16.909966356"
27+
}
28+
}

0 commit comments

Comments
 (0)