Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix join mismatch error for joint tumor only Mutect2 #1181

Merged
merged 12 commits into from
Aug 31, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,22 @@ workflow BAM_VARIANT_CALLING_TUMOR_ONLY_MUTECT2 {
MERGEMUTECTSTATS(stats_to_merge)

// Mix intervals and no_intervals channels together
vcf = Channel.empty().mix(MERGE_MUTECT2.out.vcf, vcf_branch.no_intervals)
tbi = Channel.empty().mix(MERGE_MUTECT2.out.tbi, tbi_branch.no_intervals)
stats = Channel.empty().mix(MERGEMUTECTSTATS.out.stats, stats_branch.no_intervals)
f1r2 = Channel.empty().mix(f1r2_to_merge, f1r2_branch.no_intervals)
// Remove unnecessary metadata
if (joint_mutect2) {
// Remove sample and status metadata as they become irrelevant for joint calling
vcf = Channel.empty().mix(MERGE_MUTECT2.out.vcf, vcf_branch.no_intervals).map{ meta, vcf -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type'), vcf ] }
tbi = Channel.empty().mix(MERGE_MUTECT2.out.tbi, tbi_branch.no_intervals).map{ meta, tbi -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type'), tbi ] }
stats = Channel.empty().mix(MERGEMUTECTSTATS.out.stats, stats_branch.no_intervals).map{ meta, stats -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type'), stats ] }
f1r2 = Channel.empty().mix(f1r2_to_merge, f1r2_branch.no_intervals).map{ meta, f1r2 -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type'), f1r2 ] }
}
else {
// Keep sample and status metadata
vcf = Channel.empty().mix(MERGE_MUTECT2.out.vcf, vcf_branch.no_intervals).map{ meta, vcf -> [ meta - meta.subMap('num_intervals', 'data_type'), vcf ] }
tbi = Channel.empty().mix(MERGE_MUTECT2.out.tbi, tbi_branch.no_intervals).map{ meta, tbi -> [ meta - meta.subMap('num_intervals', 'data_type'), tbi ] }
stats = Channel.empty().mix(MERGEMUTECTSTATS.out.stats, stats_branch.no_intervals).map{ meta, stats -> [ meta - meta.subMap('num_intervals', 'data_type'), stats ] }
f1r2 = Channel.empty().mix(f1r2_to_merge, f1r2_branch.no_intervals).map{ meta, f1r2 -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type'), f1r2 ] }

}
// Generate artifactpriors using learnreadorientationmodel on the f1r2 output of mutect2
LEARNREADORIENTATIONMODEL(f1r2)

Expand Down Expand Up @@ -125,13 +136,13 @@ workflow BAM_VARIANT_CALLING_TUMOR_ONLY_MUTECT2 {

if (joint_mutect2) {
// Remove sample names and retain patient name as the main identifier
calculatecontamination_out_seg = CALCULATECONTAMINATION.out.segmentation.map{ meta, seg -> [ meta - meta.subMap('sample') + [id:meta.patient], seg ] }.groupTuple()
calculatecontamination_out_cont = CALCULATECONTAMINATION.out.contamination.map{ meta, cont -> [ meta - meta.subMap('sample') + [id:meta.patient], cont ] }.groupTuple()
calculatecontamination_out_seg = CALCULATECONTAMINATION.out.segmentation.map{ meta, seg -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type') + [id:meta.patient], seg ] }.groupTuple()
calculatecontamination_out_cont = CALCULATECONTAMINATION.out.contamination.map{ meta, cont -> [ meta - meta.subMap('sample', 'status', 'num_intervals', 'data_type') + [id:meta.patient], cont ] }.groupTuple()
}
else {
// Regular single sample mode
calculatecontamination_out_seg = CALCULATECONTAMINATION.out.segmentation
calculatecontamination_out_cont = CALCULATECONTAMINATION.out.contamination
calculatecontamination_out_seg = CALCULATECONTAMINATION.out.segmentation.map{ meta, seg -> [ meta - meta.subMap('num_intervals', 'data_type'), seg ] }
calculatecontamination_out_cont = CALCULATECONTAMINATION.out.contamination.map{ meta, cont -> [ meta - meta.subMap('num_intervals', 'data_type'), cont ] }
}

// Mutect2 calls filtered by filtermutectcalls using the contamination and segmentation tables
Expand All @@ -146,7 +157,7 @@ workflow BAM_VARIANT_CALLING_TUMOR_ONLY_MUTECT2 {

vcf_filtered = FILTERMUTECTCALLS.out.vcf
// add variantcaller to meta map and remove no longer necessary field: num_intervals
.map{ meta, vcf -> [ meta - meta.subMap('num_intervals') + [ variantcaller:'mutect2' ], vcf ] }
.map{ meta, vcf -> [ meta + [ variantcaller:'mutect2' ], vcf ] }

versions = versions.mix(MERGE_MUTECT2.out.versions)
versions = versions.mix(CALCULATECONTAMINATION.out.versions)
Expand Down