Skip to content

Commit

Permalink
Improve groupTuple docs with scatter/gather example (#5520) [ci skip]
Browse files Browse the repository at this point in the history

Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman authored Nov 22, 2024
1 parent df69b8f commit b5c63a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
19 changes: 10 additions & 9 deletions docs/snippets/grouptuple-groupkey.nf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
chr_frequency = ["chr1": 2, "chr2": 3]

Channel.of(
['region1', 'chr1', '/path/to/region1_chr1.vcf'],
['region2', 'chr1', '/path/to/region2_chr1.vcf'],
['region1', 'chr2', '/path/to/region1_chr2.vcf'],
['region2', 'chr2', '/path/to/region2_chr2.vcf'],
['region3', 'chr2', '/path/to/region3_chr2.vcf']
['chr1', ['/path/to/region1_chr1.vcf', '/path/to/region2_chr1.vcf']],
['chr2', ['/path/to/region1_chr2.vcf', '/path/to/region2_chr2.vcf', '/path/to/region3_chr2.vcf']],
)
.map { region, chr, vcf -> tuple( groupKey(chr, chr_frequency[chr]), vcf ) }
.flatMap { chr, vcfs ->
vcfs.collect { vcf ->
tuple(groupKey(chr, vcfs.size()), vcf) // preserve group size with key
}
}
.view { v -> "scattered: ${v}" }
.groupTuple()
.view()
.map { key, vcfs -> tuple(key.getGroupTarget(), vcfs) } // unwrap group key
.view { v -> "gathered: ${v}" }
9 changes: 7 additions & 2 deletions docs/snippets/grouptuple-groupkey.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[chr1, [/path/to/region1_chr1.vcf, /path/to/region2_chr1.vcf]]
[chr2, [/path/to/region1_chr2.vcf, /path/to/region2_chr2.vcf, /path/to/region3_chr2.vcf]]
scattered: [chr1, /path/to/region1_chr1.vcf]
scattered: [chr1, /path/to/region2_chr1.vcf]
scattered: [chr2, /path/to/region1_chr2.vcf]
scattered: [chr2, /path/to/region2_chr2.vcf]
scattered: [chr2, /path/to/region3_chr2.vcf]
gathered: [chr1, [/path/to/region1_chr1.vcf, /path/to/region2_chr1.vcf]]
gathered: [chr2, [/path/to/region1_chr2.vcf, /path/to/region2_chr2.vcf, /path/to/region3_chr2.vcf]]

0 comments on commit b5c63a9

Please sign in to comment.