Skip to content

Commit

Permalink
Publish files for failed QC jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Sep 26, 2024
1 parent 2029f96 commit 32532df
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
7 changes: 6 additions & 1 deletion main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ workflow {
site_files_ch.collect()
)

// check if QC chunks exist in case QC failed
QUALITY_CONTROL.out.qc_metafiles.ifEmpty{
error ""
}

if (params.mode == 'imputation') {

phased_ch = QUALITY_CONTROL.out.qc_metafiles
Expand Down Expand Up @@ -153,7 +158,7 @@ workflow.onComplete {
body "Dear ${params.user.name}, \n Your job has been ${statusMessage}.\n\n More details can be found at the following link: ${params.service.url}/index.html#!jobs/${params.project}"
}
}
println "::error:: Imputation failed."
println "::error:: Imputation Server 2 workflow failed."
return
}

Expand Down
14 changes: 11 additions & 3 deletions modules/local/quality_control/quality_control_vcf.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ process QUALITY_CONTROL_VCF {
val(panel_version)

output:
path("${metaFilesDir}/*"), emit: chunks_csv
path("${metaFilesDir}/*"), emit: chunks_csv, optional: true
path("${chunksDir}/*"), emit: chunks_vcf
path("${statisticsDir}/*"), optional: true
path("maf.txt"), emit: maf_file, optional: true
Expand Down Expand Up @@ -56,10 +56,18 @@ process QUALITY_CONTROL_VCF {
--report qc_report.txt \
$chain \
$vcf_files
exit_code_a=\$?
cat qc_report.txt
exit \$exit_code_a
# Check if QC step failed
if [[ \$exit_code_a -ne 0 ]]; then
rm -rf ${metaFilesDir}
fi
cat qc_report.txt
# Always exit 0 that QC files get published
exit 0
"""

}
25 changes: 25 additions & 0 deletions tests/data/refpanels/hapmap2/cloudgene_with_qcfilters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: HapMap 2
description: HapMap2 Reference Panel for Michigan Imputation Server
version: 2.0.0
website: http://imputationserver.sph.umich.edu
category: RefPanel
id: hapmap2-chr20

properties:
id: hapmap2-chr20
build: hg19
genotypes: ${CLOUDGENE_APP_LOCATION}/msavs/hapmap_r22.chr$chr.CEU.hg19.msav
sites: ${CLOUDGENE_APP_LOCATION}/sites/hapmap_r22.chr$chr.CEU.hg19_impute.sites.gz
mapEagle: ${CLOUDGENE_APP_LOCATION}/map/genetic_map_hg19_withX.txt.gz
refEagle: ${CLOUDGENE_APP_LOCATION}/bcfs/hapmap_r22.chr$chr.CEU.hg19.recode.bcf
refBeagle: ${CLOUDGENE_APP_LOCATION}/bcfs/hapmap_r22.chr$chr.CEU.hg19.recode.bref3
mapBeagle: ${CLOUDGENE_APP_LOCATION}/map/plink.chr$chr.GRCh37.map
populations:
- id: eur
name: EUR
samples: 60
- id: "off"
name: Off
samples: -1
qcFilter:
minSnps: 10000
29 changes: 29 additions & 0 deletions tests/main.qc.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ nextflow_pipeline {

}

test("Should fail QC-only but publish files") {

when {
params {
project = "test-job"
build = "hg19"
files = "$projectDir/tests/data/input/chr20-phased/*.vcf.gz"
allele_frequency_population = "eur"
mode = "qc-only"
refpanel_yaml = "$projectDir/tests/data/refpanels/hapmap2/cloudgene_with_qcfilters.yaml"
output = "${outputDir}"
}
}

then {
assert workflow.failed

assert file("${outputDir}/statistics/snps-typed-only.txt").exists()

def log = file("${outputDir}/qc_report.txt")

assert snapshot(
log.text
).match()

}

}

test("Should run QC-only without population") {

when {
Expand Down
10 changes: 10 additions & 0 deletions tests/main.qc.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"Should fail QC-only but publish files": {
"content": [
"::log:: Reference Panel Ranges: genome-wide\n::message:: Calculating QC Statistics\n::group type=message::\n<b>Statistics:</b>\nAlternative allele frequency > 0.5 sites: 2,296\nReference Overlap: 99.00 %\nMatch: 7,735\nAllele switch: 0\nStrand flip: 0\nStrand flip and allele switch: 0\nA/T, C/G genotypes: 0\n<b>Filtered sites:</b>\nFilter flag set: 0\nInvalid alleles: 0\nMultiallelic sites: 0\nDuplicated sites: 0\nNonSNP sites: 0\nMonomorphic sites: 11\nAllele mismatch: 0\nSNPs call rate < 90%: 0\n::endgroup::\n::group type=error::\nExcluded sites in total: 11\nRemaining sites in total: 7,735\nSee snps-excluded.txt for details\nTyped only sites: 78\nSee typed-only.txt for details\n\n<b>Warning:</b> 4 Chunk(s) excluded: < 10000 SNPs (see chunks-excluded.txt for details).\n\nRemaining chunk(s): 0\n\n<b>Error:</b> No chunks passed the QC step. Imputation cannot be started!\n::endgroup::\n"
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.2"
},
"timestamp": "2024-09-26T16:41:25.904156"
},
"Should write typed only sites": {
"content": [
"::log:: Reference Panel Ranges: genome-wide\n::message:: Calculating QC Statistics\n::group type=message::\n<b>Statistics:</b>\nAlternative allele frequency > 0.5 sites: 2,296\nReference Overlap: 99.00 %\nMatch: 7,735\nAllele switch: 0\nStrand flip: 0\nStrand flip and allele switch: 0\nA/T, C/G genotypes: 0\n<b>Filtered sites:</b>\nFilter flag set: 0\nInvalid alleles: 0\nMultiallelic sites: 0\nDuplicated sites: 0\nNonSNP sites: 0\nMonomorphic sites: 11\nAllele mismatch: 0\nSNPs call rate < 90%: 0\n::endgroup::\n::group type=warning::\nExcluded sites in total: 11\nRemaining sites in total: 7,735\nSee snps-excluded.txt for details\nTyped only sites: 78\nSee typed-only.txt for details\n\n::endgroup::\n",
Expand Down

0 comments on commit 32532df

Please sign in to comment.