|
| 1 | +#!/usr/bin/env nextflow |
| 2 | + |
| 3 | +// Nextflow Pipeline Version |
| 4 | +params.release = "v0.2.4" |
| 5 | +params.releasedate = "11-25-2024" |
| 6 | +params.githublink = "https://github.com/ohsu-cedar-comp-hub/WGS-nextflow-workflow/releases/tag/v0.2.4" |
| 7 | + |
| 8 | +// Import tools |
| 9 | +include { TUMORONLYGETPILEUPSUMMARIES } from '../../tools/gatk/get_pileup_summaries.nf' |
| 10 | +include { TUMORONLYCALCULATECONTAMINATION } from '../../tools/gatk/calculate_contamination.nf' |
| 11 | +// include { GETINTERVALS } from '../../tools/samtools/get_intervals.nf' |
| 12 | +include { TUMORONLYMUTECT2 } from '../../tools/gatk/mutect2.nf' |
| 13 | +include { BGZIP; PREPAREVCF } from '../../tools/bcftools/prepareVCFs.nf' |
| 14 | +include { MERGESTATS } from '../../tools/bcftools/combineMutectStats.nf' |
| 15 | +include { LEARNORIENTATION } from '../../tools/bcftools/combineF1R2files.nf' |
| 16 | +include { FILTERMUTECT } from '../../tools/gatk/filter_mutect.nf' |
| 17 | +include { REHEADER } from '../../tools/bcftools/reheader.nf' |
| 18 | +include { FUNCOTATOR } from '../../tools/gatk/funcotator.nf' |
| 19 | +include { SNPEFF } from '../../tools/snpeff/annotate_variants.nf' |
| 20 | +include { PASS } from '../../tools/snpeff/sift_variants.nf' |
| 21 | +include { ADDFILTER } from '../../tools/bcftools/filterVCF.nf' |
| 22 | + |
| 23 | +tumor_ch = Channel.fromPath("${params.bam_files}/*.bam") |
| 24 | +tumor_ch_bai = Channel.fromPath("${params.bam_files}/*.bai") |
| 25 | + |
| 26 | +chromosomes = (1..22).collect { it.toString() } + ['X'] |
| 27 | +chrom_strings = Channel.from(chromosomes) |
| 28 | +chrom_ch = chrom_strings.map { it -> "chr" + it } |
| 29 | + |
| 30 | +// Begin main workflow |
| 31 | +workflow { |
| 32 | + TUMORONLYMUTECT2(tumor_ch, tumor_ch_bai, chrom_ch, params.sample_id, params.mutect_idx, params.mutect_idx_fai, params.mutect_idx_dict, params.pon_vcf, params.pon_tbi, params.pon_idx, params.pon_tar) |
| 33 | + |
| 34 | + // gatk getpileupsummaries |
| 35 | + TUMORONLYGETPILEUPSUMMARIES(tumor_ch, tumor_ch_bai, params.exac) |
| 36 | + tumor_table = GETPILEUPSUMMARIES.out |
| 37 | + |
| 38 | + // gatk calculate contamination from pileup summaries |
| 39 | + TUMORONLYCALCULATECONTAMINATION(tumor_table) |
| 40 | + contam_table = CALCULATECONTAMINATION.out.contamination.collect() |
| 41 | + segment_table = CALCULATECONTAMINATION.out.segment.collect() |
| 42 | + |
| 43 | + // Merge and prepare VCF |
| 44 | + BGZIP(MUTECT2.out.vcf) // concatenation requires bgzip'd files |
| 45 | + vcfs_ch = BGZIP.out.vcf.collect() // collect all bgzip vcf outputs into a channel |
| 46 | + split_vcf_index = BGZIP.out.index.collect() // collect all bgzip index outputs into a channel |
| 47 | + // concatenate, normalize, and sort the VCF |
| 48 | + PREPAREVCF(vcfs_ch, split_vcf_index, params.sample_id, params.mutect_idx, params.mutect_idx_fai, params.mutect_idx_dict) |
| 49 | + unfiltered_vcf = PREPAREVCF.out.vcf |
| 50 | + unfiltered_vcf_index = PREPAREVCF.out.index |
| 51 | + |
| 52 | + // Merge stats file |
| 53 | + stats = MUTECT2.out.stats |
| 54 | + stats_ch = stats.collect() |
| 55 | + MERGESTATS(stats_ch, params.sample_id) |
| 56 | + filter_stats = MERGESTATS.out |
| 57 | + |
| 58 | + // Merge f1r2 read orientation files |
| 59 | + f1r2files = MUTECT2.out.f1r2 |
| 60 | + f1r2_ch = f1r2files.collect() |
| 61 | + LEARNORIENTATION(f1r2_ch, params.sample_id) |
| 62 | + orientationmodel = LEARNORIENTATION.out |
| 63 | + |
| 64 | + // Filter mutect2 calls |
| 65 | + FILTERMUTECT(unfiltered_vcf, unfiltered_vcf_index, params.mutect_idx, params.mutect_idx_fai, params.mutect_idx_dict, filter_stats, orientationmodel, segment_table, contam_table, params.sample_id) |
| 66 | + |
| 67 | + // Add nextflow workflow versioning to VCF header |
| 68 | + REHEADER(FILTERMUTECT.out) |
| 69 | + |
| 70 | + // filter for passing variants |
| 71 | + PASS(REHEADER.out, params.sample_id) |
| 72 | + |
| 73 | + // filter for variants above certain allelic depth, VAF, etc using bcftools |
| 74 | + ADDFILTER(PASS.out, params.sample_id) |
| 75 | + vcf = ADDFILTER.out |
| 76 | + |
| 77 | + // Annotate with funcotator |
| 78 | + FUNCOTATOR(vcf, |
| 79 | + params.mutect_idx, params.mutect_idx_fai, params.mutect_idx_dict, |
| 80 | + params.funcotator_data, |
| 81 | + params.sample_id) |
| 82 | + |
| 83 | + // Annotate with snpEff |
| 84 | + SNPEFF(vcf, params.sample_id) |
| 85 | +} |
0 commit comments