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..c186b51 100644 --- a/modules/local/compression/compression_encryption_vcf.nf +++ b/modules/local/compression/compression_encryption_vcf.nf @@ -24,27 +24,38 @@ 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) + """ # 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 - 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 annotate --threads ${threads} -h add_header.txt intermediate_${imputed_name} -o ${imputed_name} -Oz + #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 + 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 + + # concat dosage files and update header + bcftools concat --threads ${threads} -n ${imputed_joined} -Oz | bcftools reheader -h final_header.txt -o ${imputed_name} - rm intermediate_${imputed_name} else + bcftools concat --threads ${threads} -n ${imputed_joined} -o intermediate_${imputed_name} -Oz mv intermediate_${imputed_name} ${imputed_name} - fi + fi # write meta files if [[ "${params.imputation.meta}" = true ]] @@ -90,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