i have a random nextflow question. Am trying to co...
# random
f
i have a random nextflow question. Am trying to combine vcf files from 3 different callers but first i need to organise them as {meta, vcfs, tbis}. Here is an idea I have but I need some pointers on how to do it right.
Copy code
// Combine all VCF and TBI channels and sort by sample/meta
combined_vcfs = Channel.empty()

combined_vcfs = combined_vcfs.mix(
    // VCF FILES
    CLAIR3.out.vcf.collect{it[0,1]}.ifEmpty([]),
    CUTESV.out.vcf.collect{it[0,1]}.ifEmpty([]),
    NANOCALLER.out.vcf.collect{it[0,1]}.ifEmpty([]),
    // TBI FILES
    CLAIR3.out.tbi.collect{it[0,1]}.ifEmpty([]),
    CUTESV.out.tbi.collect{it[0,1]}.ifEmpty([]),
    NANOCALLER.out.tbi.collect{it[0,1]}.ifEmpty([])
)
.collect()
.toList()

// View combined channel files
combined_vcfs.flatten().view()

// The CHANELS collected
// [id:DGS-23-19753_barcode07, single_end:true]
// /mount/X__gene_characterization/work/24/1b6c48c9e49d45cd31775cab9386e4/DGS-23-19753_barcode07.vcf.gz
// [id:IMM-24-65382_barcode03, single_end:true]
// /mount/X__gene_characterization/work/cd/dae2e51325b91886a5d56e13d958ce/IMM-24-65382_barcode03.vcf.gz
// [id:DGS-23-19753_barcode35, single_end:true]
// /mount/X__gene_characterization/work/dc/2a19c797cd65e3bf9c441f1b0dc55d/DGS-23-19753_barcode35.vcf.gz
// [id:DGS-23-19753_barcode07, single_end:true]
// /mount/X__gene_characterization/work/24/1b6c48c9e49d45cd31775cab9386e4/DGS-23-19753_barcode07.vcf.gz.tbi
// [id:IMM-24-65382_barcode03, single_end:true]
// /mount/X_gene_characterization/work/cd/dae2e51325b91886a5d56e13d958ce/IMM-24-65382_barcode03.vcf.gz.tbi
// [id:DGS-23-19753_barcode35, single_end:true]
// /mount/X__gene_characterization/work/dc/2a19c797cd65e3bf9c441f1b0dc55d/DGS-23-19753_barcode35.vcf.gz.tbi

// Process the combined VCFs and TBIs
combined_vcfs = combined_vcfs
    .groupTuple(by: 0) // Group by meta (sample identifier)
    .flatMap { meta, path_list ->
        // Split the path_list into VCF and TBI files
        def vcfs = path_list.findAll { it.name.endsWith('.vcf.gz') }
        def tbis = path_list.findAll { it.name.endsWith('.vcf.gz.tbi') }
        
        // Ensure that VCFs match with corresponding TBIs
        def combinations = vcfs.collectMany { vcf ->
            tbis.collect { tbi ->
                // Return meta, VCF, and matching TBI
                return [meta, vcf, tbi]
            }
        }
        return combinations
    }
// Optionally, view the final combinations
// .view()