Skip to content

Commit b5c63a9

Browse files
authored
Improve groupTuple docs with scatter/gather example (#5520) [ci skip]
Signed-off-by: Ben Sherman <[email protected]>
1 parent df69b8f commit b5c63a9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
chr_frequency = ["chr1": 2, "chr2": 3]
2-
31
Channel.of(
4-
['region1', 'chr1', '/path/to/region1_chr1.vcf'],
5-
['region2', 'chr1', '/path/to/region2_chr1.vcf'],
6-
['region1', 'chr2', '/path/to/region1_chr2.vcf'],
7-
['region2', 'chr2', '/path/to/region2_chr2.vcf'],
8-
['region3', 'chr2', '/path/to/region3_chr2.vcf']
2+
['chr1', ['/path/to/region1_chr1.vcf', '/path/to/region2_chr1.vcf']],
3+
['chr2', ['/path/to/region1_chr2.vcf', '/path/to/region2_chr2.vcf', '/path/to/region3_chr2.vcf']],
94
)
10-
.map { region, chr, vcf -> tuple( groupKey(chr, chr_frequency[chr]), vcf ) }
5+
.flatMap { chr, vcfs ->
6+
vcfs.collect { vcf ->
7+
tuple(groupKey(chr, vcfs.size()), vcf) // preserve group size with key
8+
}
9+
}
10+
.view { v -> "scattered: ${v}" }
1111
.groupTuple()
12-
.view()
12+
.map { key, vcfs -> tuple(key.getGroupTarget(), vcfs) } // unwrap group key
13+
.view { v -> "gathered: ${v}" }
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
[chr1, [/path/to/region1_chr1.vcf, /path/to/region2_chr1.vcf]]
2-
[chr2, [/path/to/region1_chr2.vcf, /path/to/region2_chr2.vcf, /path/to/region3_chr2.vcf]]
1+
scattered: [chr1, /path/to/region1_chr1.vcf]
2+
scattered: [chr1, /path/to/region2_chr1.vcf]
3+
scattered: [chr2, /path/to/region1_chr2.vcf]
4+
scattered: [chr2, /path/to/region2_chr2.vcf]
5+
scattered: [chr2, /path/to/region3_chr2.vcf]
6+
gathered: [chr1, [/path/to/region1_chr1.vcf, /path/to/region2_chr1.vcf]]
7+
gathered: [chr2, [/path/to/region1_chr2.vcf, /path/to/region2_chr2.vcf, /path/to/region3_chr2.vcf]]

0 commit comments

Comments
 (0)