From 0ac6f36f10e83f0dc41ba8c1ff9f540ed1edeedb Mon Sep 17 00:00:00 2001 From: Snehal Patil Date: Wed, 18 Feb 2026 12:22:13 -0500 Subject: [PATCH 1/5] added reheader option --- .gitignore | 1 + .../local/compression/compression_encryption_vcf.nf | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index af6f5f1..cb5208e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ cloudgene.report.json *.jar .idea scratch +imputationserver2.iml diff --git a/modules/local/compression/compression_encryption_vcf.nf b/modules/local/compression/compression_encryption_vcf.nf index f8413d1..d14d873 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -30,7 +30,7 @@ process COMPRESSION_ENCRYPTION_VCF { bcftools concat --threads ${threads} -n ${info_joined} -o ${info_name} -Oz # concat dosage files and update header - bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz + #bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz # annotate files if [[ "${params.encryption.annotate}" = true ]] @@ -39,9 +39,13 @@ process COMPRESSION_ENCRYPTION_VCF { echo "##mis_phasing=${params.phasing.engine}" >> add_header.txt echo "##mis_panel=${panel_version}" >> add_header.txt - bcftools annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz + #bcftools annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz + + bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} + else + bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz + mv intermediate_${imputed_name} ${imputed_name} - rm intermediate_${imputed_name} else mv intermediate_${imputed_name} ${imputed_name} fi From 0bde7e7c1e4dde5ce31acfc3c204498f85da73a6 Mon Sep 17 00:00:00 2001 From: Snehal Patil Date: Mon, 2 Mar 2026 14:25:30 -0500 Subject: [PATCH 2/5] Reheader format fixed --- .../compression/compression_encryption_vcf.nf | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/local/compression/compression_encryption_vcf.nf b/modules/local/compression/compression_encryption_vcf.nf index d14d873..bb8e6fa 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -25,6 +25,9 @@ process COMPRESSION_ENCRYPTION_VCF { def scale = params.encryption.thread_scale ?: 1 def threads = Math.max(1, Math.floor(task.cpus * scale) as int) + def first_vcf = imputed_joined[0] + println "First VCF is: ${first_vcf}" + """ # concat info files bcftools concat --threads ${threads} -n ${info_joined} -o ${info_name} -Oz @@ -35,13 +38,24 @@ process COMPRESSION_ENCRYPTION_VCF { # annotate files if [[ "${params.encryption.annotate}" = true ]] then - echo "##mis_pipeline=${workflow.manifest.version}" > add_header.txt - echo "##mis_phasing=${params.phasing.engine}" >> add_header.txt - echo "##mis_panel=${panel_version}" >> add_header.txt + bcftools view -h "${first_vcf}" > header_from_chunk.txt + + # build final header: keep ## lines, add custom lines, then #CHROM last + { + grep '^##' header_from_chunk.txt + echo "##mis_pipeline=${workflow.manifest.version}" + echo "##mis_phasing=${params.phasing.engine}" + echo "##mis_panel=${panel_version}" + grep '^#CHROM' header_from_chunk.txt + } > final_header.txt #bcftools annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz - bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} + bcftools concat --threads ${threads} --naive ${imputed_joined} -Ou \ + | bcftools reheader -h final_header.txt -o - - \ + | bcftools view -Oz -o ${imputed_name} + + #bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} else bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz mv intermediate_${imputed_name} ${imputed_name} From 7a4b7f48e249a0615d78ec119991b4e06c7e07b2 Mon Sep 17 00:00:00 2001 From: Snehal Patil Date: Tue, 3 Mar 2026 09:22:02 -0500 Subject: [PATCH 3/5] Reheader pipe with annotate and header --- modules/local/compression/compression_encryption_vcf.nf | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/local/compression/compression_encryption_vcf.nf b/modules/local/compression/compression_encryption_vcf.nf index bb8e6fa..d4db2da 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -38,6 +38,7 @@ process COMPRESSION_ENCRYPTION_VCF { # annotate files if [[ "${params.encryption.annotate}" = true ]] then + #Extracting the original header then paste the new one bcftools view -h "${first_vcf}" > header_from_chunk.txt # build final header: keep ## lines, add custom lines, then #CHROM last @@ -50,12 +51,8 @@ process COMPRESSION_ENCRYPTION_VCF { } > final_header.txt #bcftools annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz + bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} - bcftools concat --threads ${threads} --naive ${imputed_joined} -Ou \ - | bcftools reheader -h final_header.txt -o - - \ - | bcftools view -Oz -o ${imputed_name} - - #bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} else bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz mv intermediate_${imputed_name} ${imputed_name} From 9e316c41dc3034ceee40852a8ea1e8cf94fbfd3c Mon Sep 17 00:00:00 2001 From: Snehal Patil Date: Fri, 6 Mar 2026 12:20:20 -0500 Subject: [PATCH 4/5] Reheader with awk command --- .../compression/compression_encryption_vcf.nf | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/local/compression/compression_encryption_vcf.nf b/modules/local/compression/compression_encryption_vcf.nf index d4db2da..02b8b21 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -42,15 +42,25 @@ process COMPRESSION_ENCRYPTION_VCF { bcftools view -h "${first_vcf}" > header_from_chunk.txt # build final header: keep ## lines, add custom lines, then #CHROM last - { + /* { grep '^##' header_from_chunk.txt echo "##mis_pipeline=${workflow.manifest.version}" echo "##mis_phasing=${params.phasing.engine}" echo "##mis_panel=${panel_version}" grep '^#CHROM' header_from_chunk.txt - } > final_header.txt + } > final_header.txt */ + + awk -v pipeline="${workflow.manifest.version}" \ + -v phasing="${params.phasing.engine}" \ + -v panel="${panel_version}" ' + /^#CHROM/ { + print "##mis_pipeline=" pipeline + print "##mis_phasing=" phasing + print "##mis_panel=" panel + } + { print } + ' header_from_chunk.txt > final_header.txt - #bcftools annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} else From 538e8942e397d18733c43c4974e0f10bfed92bfc Mon Sep 17 00:00:00 2001 From: Snehal Patil Date: Thu, 12 Mar 2026 11:53:45 -0400 Subject: [PATCH 5/5] addded the function for the first file --- .../compression/compression_encryption_vcf.nf | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/modules/local/compression/compression_encryption_vcf.nf b/modules/local/compression/compression_encryption_vcf.nf index 02b8b21..c186b51 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -24,33 +24,21 @@ process COMPRESSION_ENCRYPTION_VCF { def panel_version = params.refpanel.id def scale = params.encryption.thread_scale ?: 1 def threads = Math.max(1, Math.floor(task.cpus * scale) as int) + def first_vcf = getFirstFile(imputed_vcf_data) - def first_vcf = imputed_joined[0] - println "First VCF is: ${first_vcf}" """ # concat info files bcftools concat --threads ${threads} -n ${info_joined} -o ${info_name} -Oz - # concat dosage files and update header - #bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz - # annotate files if [[ "${params.encryption.annotate}" = true ]] then - #Extracting the original header then paste the new one + #Extracting the original header to append the new one bcftools view -h "${first_vcf}" > header_from_chunk.txt # build final header: keep ## lines, add custom lines, then #CHROM last - /* { - grep '^##' header_from_chunk.txt - echo "##mis_pipeline=${workflow.manifest.version}" - echo "##mis_phasing=${params.phasing.engine}" - echo "##mis_panel=${panel_version}" - grep '^#CHROM' header_from_chunk.txt - } > final_header.txt */ - - awk -v pipeline="${workflow.manifest.version}" \ + awk -v pipeline="${workflow.manifest.version}" \ -v phasing="${params.phasing.engine}" \ -v panel="${panel_version}" ' /^#CHROM/ { @@ -61,15 +49,13 @@ process COMPRESSION_ENCRYPTION_VCF { { print } ' header_from_chunk.txt > final_header.txt + # concat dosage files and update header bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} else bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz mv intermediate_${imputed_name} ${imputed_name} - - else - mv intermediate_${imputed_name} ${imputed_name} - fi + fi # write meta files if [[ "${params.imputation.meta}" = true ]] @@ -115,3 +101,8 @@ def compareFilenames(a, b) { def processFileList(fileList) { return fileList.sort { a, b -> compareFilenames(a, b) }.join(" ") } + +def getFirstFile(fileList) { + def sorted = fileList.sort { a, b -> compareFilenames(a, b) } + return sorted[0] +} \ No newline at end of file