From 80ac911a48ef2d9f0dc4153127bfc3fcdd29e8db Mon Sep 17 00:00:00 2001 From: Joon-Klaps Date: Mon, 21 Aug 2023 11:10:46 +0000 Subject: [PATCH] Starting on bcftools caller --- subworkflows/local/bam_call_variants.nf | 16 +++---- subworkflows/local/bam_variants_bcftools.nf | 53 +++++++++++++++++---- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/subworkflows/local/bam_call_variants.nf b/subworkflows/local/bam_call_variants.nf index 4e21fa49..7680e4c9 100644 --- a/subworkflows/local/bam_call_variants.nf +++ b/subworkflows/local/bam_call_variants.nf @@ -1,17 +1,13 @@ -// TODO nf-core: If in doubt look at other nf-core/subworkflows to see how we are doing things! :) -// https://github.com/nf-core/modules/tree/master/subworkflows -// You can also ask for help via your pull request or on the #subworkflows channel on the nf-core Slack workspace: -// https://nf-co.re/join -// TODO nf-core: A subworkflow SHOULD import at least two modules - -include { SAMTOOLS_SORT } from '../../../modules/nf-core/samtools/sort/main' -include { SAMTOOLS_INDEX } from '../../../modules/nf-core/samtools/index/main' +include { TABIX_TABIX } from '../../modules/nf-core/tabix/tabix/main' +include { BCFTOOLS_STATS } from '../../modules/nf-core/bcftools/stats/main' workflow { take: - // TODO nf-core: edit input (take) channels - ch_bam // channel: [ val(meta), [ bam ] ] + bam // channel: [ val(meta), [ bam ] ] + fasta // channel: [val (meta), [ fasta] ] + variant_caller // value: [ bcftools | ivar ] + main: diff --git a/subworkflows/local/bam_variants_bcftools.nf b/subworkflows/local/bam_variants_bcftools.nf index 4e21fa49..b95ddd75 100644 --- a/subworkflows/local/bam_variants_bcftools.nf +++ b/subworkflows/local/bam_variants_bcftools.nf @@ -1,11 +1,5 @@ -// TODO nf-core: If in doubt look at other nf-core/subworkflows to see how we are doing things! :) -// https://github.com/nf-core/modules/tree/master/subworkflows -// You can also ask for help via your pull request or on the #subworkflows channel on the nf-core Slack workspace: -// https://nf-co.re/join -// TODO nf-core: A subworkflow SHOULD import at least two modules - -include { SAMTOOLS_SORT } from '../../../modules/nf-core/samtools/sort/main' -include { SAMTOOLS_INDEX } from '../../../modules/nf-core/samtools/index/main' +include { BCFTOOLS_MPILEUP } from '../../modules/nf-core/bcftools/mpileup/main' +include { BCFTOOLS_NORM } from '../../modules/nf-core/bcftools/norm/main' workflow { @@ -14,9 +8,50 @@ workflow { ch_bam // channel: [ val(meta), [ bam ] ] main: - + ch_versions = Channel.empty() + // + // Call variants + // + BCFTOOLS_MPILEUP ( + bam.map{ meta, bam_file -> [ meta, bam_file, [] ] }, + fasta, + params.save_mpileup + ) + ch_versions = ch_versions.mix(BCFTOOLS_MPILEUP.out.versions.first()) + + // Filter out samples with 0 variants + BCFTOOLS_MPILEUP + .out + .vcf + .join(BCFTOOLS_MPILEUP.out.tbi) + .join(BCFTOOLS_MPILEUP.out.stats) + .filter { meta, vcf, tbi, stats -> WorkflowCommons.getNumVariantsFromBCFToolsStats(stats) > 0 } + .set { ch_vcf_tbi_stats } + + ch_vcf_tbi_stats + .map { meta, vcf, tbi, stats -> [ meta, vcf ] } + .set { ch_vcf } + + ch_vcf_tbi_stats + .map { meta, vcf, tbi, stats -> [ meta, tbi ] } + .set { ch_tbi } + + ch_vcf_tbi_stats + .map { meta, vcf, tbi, stats -> [ meta, stats ] } + .set { ch_stats } + + // + // Split multi-allelic positions + // + BCFTOOLS_NORM ( + ch_vcf.join(ch_tbi, by: [0]), + fasta + ) + ch_versions = ch_versions.mix(BCFTOOLS_NORM.out.versions.first()) + + // TODO nf-core: substitute modules here for the modules of your subworkflow SAMTOOLS_SORT ( ch_bam )