Skip to content

Commit 4b6689b

Browse files
authored
Apply suggestions from code review
We don't need to `import nextflow.Nextflow` inside Nextflow scripts because the methods are already in scope
1 parent 7c76ff3 commit 4b6689b

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

workflows/sarek.nf

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
*/
66

7-
import nextflow.Nextflow
87
def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params)
98

109
// Validate input parameters
@@ -61,9 +60,9 @@ input_sample = params.build_only_index ? Channel.empty() : extract_csv(file(para
6160

6261
// Fails when wrongfull extension for intervals file
6362
if (params.wes && !params.step == 'annotate') {
64-
if (params.intervals && !params.intervals.endsWith("bed")) Nextflow.error("Target file specified with `--intervals` must be in BED format for targeted data")
63+
if (params.intervals && !params.intervals.endsWith("bed")) error("Target file specified with `--intervals` must be in BED format for targeted data")
6564
else log.warn("Intervals file was provided without parameter `--wes`: Pipeline will assume this is Whole-Genome-Sequencing data.")
66-
} else if (params.intervals && !params.intervals.endsWith("bed") && !params.intervals.endsWith("list")) Nextflow.error("Intervals file must end with .bed, .list, or .interval_list")
65+
} else if (params.intervals && !params.intervals.endsWith("bed") && !params.intervals.endsWith("list")) error("Intervals file must end with .bed, .list, or .interval_list")
6766

6867
if (params.step == 'mapping' && params.aligner.contains("dragmap") && !(params.skip_tools && params.skip_tools.split(',').contains("baserecalibrator"))) {
6968
log.warn("DragMap was specified as aligner. Base recalibration is not contained in --skip_tools. It is recommended to skip baserecalibration when using DragMap\nhttps://gatk.broadinstitute.org/hc/en-us/articles/4407897446939--How-to-Run-germline-single-sample-short-variant-discovery-in-DRAGEN-mode")
@@ -72,10 +71,10 @@ if (params.step == 'mapping' && params.aligner.contains("dragmap") && !(params.s
7271
// Fails or warns when missing files or params for ascat
7372
if (params.tools && params.tools.split(',').contains('ascat')) {
7473
if (!params.ascat_alleles) {
75-
Nextflow.error("No allele files were provided for running ASCAT. Please provide a zip folder with allele files.")
74+
error("No allele files were provided for running ASCAT. Please provide a zip folder with allele files.")
7675
}
7776
if (!params.ascat_loci) {
78-
Nextflow.error("No loci files were provided for running ASCAT. Please provide a zip folder with loci files.")
77+
error("No loci files were provided for running ASCAT. Please provide a zip folder with loci files.")
7978
}
8079
if (!params.ascat_loci_gc && !params.ascat_loci_rt) {
8180
log.warn("No LogRCorrection performed in ASCAT. For LogRCorrection to run, please provide either loci gc files or both loci gc files and loci rt files.")
@@ -102,29 +101,29 @@ if (params.tools && params.tools.split(',').contains('mutect2')) {
102101
// Warns when missing resources for haplotypecaller
103102
if (!params.dbsnp && !params.known_indels) {
104103
if (params.step in ['mapping', 'markduplicates', 'prepare_recalibration', 'recalibrate'] && (!params.skip_tools || (params.skip_tools && !params.skip_tools.split(',').contains('baserecalibrator')))) {
105-
Nextflow.error("Base quality score recalibration requires at least one resource file. Please provide at least one of `--dbsnp` or `--known_indels`\nYou can skip this step in the workflow by adding `--skip_tools baserecalibrator` to the command.")
104+
error("Base quality score recalibration requires at least one resource file. Please provide at least one of `--dbsnp` or `--known_indels`\nYou can skip this step in the workflow by adding `--skip_tools baserecalibrator` to the command.")
106105
}
107106
if (params.tools && params.tools.split(',').contains('haplotypecaller')) {
108107
log.warn "If Haplotypecaller is specified, without `--dbsnp` or `--known_indels no filtering will be done. For filtering, please provide at least one of `--dbsnp` or `--known_indels`.\nFor more information see FilterVariantTranches (single-sample, default): https://gatk.broadinstitute.org/hc/en-us/articles/5358928898971-FilterVariantTranches\nFor more information see VariantRecalibration (--joint_germline): https://gatk.broadinstitute.org/hc/en-us/articles/5358906115227-VariantRecalibrator\nFor more information on GATK Best practice germline variant calling: https://gatk.broadinstitute.org/hc/en-us/articles/360035535932-Germline-short-variant-discovery-SNPs-Indels-"
109108
}
110109
}
111110
if (params.joint_germline && (!params.tools || !params.tools.split(',').contains('haplotypecaller'))) {
112-
Nextflow.error("The Haplotypecaller should be specified as one of the tools when doing joint germline variant calling. (The Haplotypecaller could be specified by adding `--tools haplotypecaller` to the nextflow command.) ")
111+
error("The Haplotypecaller should be specified as one of the tools when doing joint germline variant calling. (The Haplotypecaller could be specified by adding `--tools haplotypecaller` to the nextflow command.) ")
113112
}
114113
if (params.joint_germline && (!params.dbsnp || !params.known_indels || !params.known_snps || params.no_intervals)) {
115114
log.warn "If Haplotypecaller is specified, without `--dbsnp`, `--known_snps`, `--known_indels` or the associated resource labels (ie `known_snps_vqsr`), no variant recalibration will be done. For recalibration you must provide all of these resources.\nFor more information see VariantRecalibration: https://gatk.broadinstitute.org/hc/en-us/articles/5358906115227-VariantRecalibrator \nJoint germline variant calling also requires intervals in order to genotype the samples. As a result, if `--no_intervals` is set to `true` the joint germline variant calling will not be performed."
116115
}
117116

118117
// Fails when missing tools for variant_calling or annotate
119118
if ((params.step == 'variant_calling' || params.step == 'annotate') && !params.tools) {
120-
Nextflow.error("Please specify at least one tool when using `--step ${params.step}`.\nhttps://nf-co.re/sarek/parameters#tools")
119+
error("Please specify at least one tool when using `--step ${params.step}`.\nhttps://nf-co.re/sarek/parameters#tools")
121120
}
122121

123122
// Fails when missing sex information for CNV tools
124123
if (params.tools && (params.tools.split(',').contains('ascat') || params.tools.split(',').contains('controlfreec'))) {
125124
input_sample.map{
126125
if (it[0].sex == 'NA' ) {
127-
Nextflow.error("Please specify sex information for each sample in your samplesheet when using '--tools' with 'ascat' or 'controlfreec'.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
126+
error("Please specify sex information for each sample in your samplesheet when using '--tools' with 'ascat' or 'controlfreec'.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
128127
}
129128
}
130129
}
@@ -1098,7 +1097,7 @@ def extract_csv(csv_file) {
10981097
def line, samplesheet_line_count = 0;
10991098
while ((line = reader.readLine()) != null) {samplesheet_line_count++}
11001099
if (samplesheet_line_count < 2) {
1101-
Nextflow.error("Samplesheet had less than two lines. The sample sheet must be a csv file with a header, so at least two lines.")
1100+
error("Samplesheet had less than two lines. The sample sheet must be a csv file with a header, so at least two lines.")
11021101
}
11031102
}
11041103

@@ -1112,19 +1111,19 @@ def extract_csv(csv_file) {
11121111
.map{ row ->
11131112
if (params.step == "mapping") {
11141113
if ( !row.lane ) { // This also handles the case where the lane is left as an empty string
1115-
Nextflow.error('The sample sheet should specify a lane for patient "' + row.patient.toString() + '" and sample "' + row.sample.toString() + '".')
1114+
error('The sample sheet should specify a lane for patient "' + row.patient.toString() + '" and sample "' + row.sample.toString() + '".')
11161115
}
11171116
def patient_sample_lane = [row.patient.toString(), row.sample.toString(), row.lane.toString()]
11181117
if (patient_sample_lane in patient_sample_lane_combinations) {
1119-
Nextflow.error('The patient-sample-lane combination "' + row.patient.toString() + '", "' + row.sample.toString() + '", and "' + row.lane.toString() + '" is present multiple times in the sample sheet.')
1118+
error('The patient-sample-lane combination "' + row.patient.toString() + '", "' + row.sample.toString() + '", and "' + row.lane.toString() + '" is present multiple times in the sample sheet.')
11201119
} else {
11211120
patient_sample_lane_combinations.add(patient_sample_lane)
11221121
}
11231122
}
11241123
if (!sample2patient.containsKey(row.sample.toString())) {
11251124
sample2patient[row.sample.toString()] = row.patient.toString()
11261125
} else if (sample2patient[row.sample.toString()] != row.patient.toString()) {
1127-
Nextflow.error('The sample "' + row.sample.toString() + '" is registered for both patient "' + row.patient.toString() + '" and "' + sample2patient[row.sample.toString()] + '" in the sample sheet.')
1126+
error('The sample "' + row.sample.toString() + '" is registered for both patient "' + row.patient.toString() + '" and "' + sample2patient[row.sample.toString()] + '" in the sample sheet.')
11281127
}
11291128
}
11301129

@@ -1137,10 +1136,10 @@ def extract_csv(csv_file) {
11371136
.map{ row ->
11381137
sample_count_all++
11391138
if (!(row.patient && row.sample)) {
1140-
Nextflow.error("Missing field in csv file header. The csv file must have fields named 'patient' and 'sample'.")
1139+
error("Missing field in csv file header. The csv file must have fields named 'patient' and 'sample'.")
11411140
}
11421141
else if (row.patient.contains(" ") || row.sample.contains(" ")) {
1143-
Nextflow.error("Invalid value in csv file. Values for 'patient' and 'sample' can not contain space.")
1142+
error("Invalid value in csv file. Values for 'patient' and 'sample' can not contain space.")
11441143
}
11451144
[ [ row.patient.toString(), row.sample.toString() ], row ]
11461145
}.groupTuple()
@@ -1181,7 +1180,7 @@ def extract_csv(csv_file) {
11811180
if (params.tools.split(',').contains(tool)) tools_tumor_asked.add(tool)
11821181
}
11831182
if (!tools_tumor_asked.isEmpty()) {
1184-
Nextflow.error('The sample-sheet only contains normal-samples, but the following tools, which were requested with "--tools", expect at least one tumor-sample : ' + tools_tumor_asked.join(", "))
1183+
error('The sample-sheet only contains normal-samples, but the following tools, which were requested with "--tools", expect at least one tumor-sample : ' + tools_tumor_asked.join(", "))
11851184
}
11861185
} else if ((sample_count_tumor == sample_count_all) && params.tools) { // In this case, the sample-sheet contains no normal/germline-samples
11871186
def tools_requiring_normal_samples = ['ascat', 'deepvariant', 'haplotypecaller', 'msisensorpro']
@@ -1190,7 +1189,7 @@ def extract_csv(csv_file) {
11901189
if (params.tools.split(',').contains(tool_requiring_normal_samples)) requested_tools_requiring_normal_samples.add(tool_requiring_normal_samples)
11911190
}
11921191
if (!requested_tools_requiring_normal_samples.isEmpty()) {
1193-
Nextflow.error('The sample-sheet only contains tumor-samples, but the following tools, which were requested by the option "tools", expect at least one normal-sample : ' + requested_tools_requiring_normal_samples.join(", "))
1192+
error('The sample-sheet only contains tumor-samples, but the following tools, which were requested by the option "tools", expect at least one normal-sample : ' + requested_tools_requiring_normal_samples.join(", "))
11941193
}
11951194
}
11961195

@@ -1213,13 +1212,13 @@ def extract_csv(csv_file) {
12131212

12141213
if (params.step == 'mapping') return [ meta, [ fastq_1, fastq_2 ] ]
12151214
else {
1216-
Nextflow.error("Samplesheet contains fastq files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1215+
error("Samplesheet contains fastq files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12171216
}
12181217

12191218
// start from BAM
12201219
} else if (row.lane && row.bam) {
12211220
if (!row.bai) {
1222-
Nextflow.error("BAM index (bai) should be provided.")
1221+
error("BAM index (bai) should be provided.")
12231222
}
12241223
meta.id = "${row.sample}-${row.lane}".toString()
12251224
def bam = file(row.bam, checkIfExists: true)
@@ -1235,7 +1234,7 @@ def extract_csv(csv_file) {
12351234

12361235
if (params.step != 'annotate') return [ meta, bam, bai ]
12371236
else {
1238-
Nextflow.error("Samplesheet contains bam files but step is `annotate`. The pipeline is expecting vcf files for the annotation. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1237+
error("Samplesheet contains bam files but step is `annotate`. The pipeline is expecting vcf files for the annotation. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12391238
}
12401239

12411240
// recalibration
@@ -1249,7 +1248,7 @@ def extract_csv(csv_file) {
12491248

12501249
if (!(params.step == 'mapping' || params.step == 'annotate')) return [ meta, cram, crai, table ]
12511250
else {
1252-
Nextflow.error("Samplesheet contains cram files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1251+
error("Samplesheet contains cram files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12531252
}
12541253

12551254
// recalibration when skipping MarkDuplicates
@@ -1263,7 +1262,7 @@ def extract_csv(csv_file) {
12631262

12641263
if (!(params.step == 'mapping' || params.step == 'annotate')) return [ meta, bam, bai, table ]
12651264
else {
1266-
Nextflow.error("Samplesheet contains bam files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1265+
error("Samplesheet contains bam files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12671266
}
12681267

12691268
// prepare_recalibration or variant_calling
@@ -1276,7 +1275,7 @@ def extract_csv(csv_file) {
12761275

12771276
if (!(params.step == 'mapping' || params.step == 'annotate')) return [ meta, cram, crai ]
12781277
else {
1279-
Nextflow.error("Samplesheet contains cram files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1278+
error("Samplesheet contains cram files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12801279
}
12811280

12821281
// prepare_recalibration when skipping MarkDuplicates or `--step markduplicates`
@@ -1289,7 +1288,7 @@ def extract_csv(csv_file) {
12891288

12901289
if (!(params.step == 'mapping' || params.step == 'annotate')) return [ meta, bam, bai ]
12911290
else {
1292-
Nextflow.error("Samplesheet contains bam files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1291+
error("Samplesheet contains bam files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
12931292
}
12941293

12951294
// annotation
@@ -1302,10 +1301,10 @@ def extract_csv(csv_file) {
13021301

13031302
if (params.step == 'annotate') return [ meta, vcf ]
13041303
else {
1305-
Nextflow.error("Samplesheet contains vcf files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
1304+
error("Samplesheet contains vcf files but step is `$params.step`. Please check your samplesheet or adjust the step parameter.\nhttps://nf-co.re/sarek/usage#input-samplesheet-configurations")
13061305
}
13071306
} else {
1308-
Nextflow.error("Missing or unknown field in csv file header. Please check your samplesheet")
1307+
error("Missing or unknown field in csv file header. Please check your samplesheet")
13091308
}
13101309
}
13111310
}

0 commit comments

Comments
 (0)