Skip to content

Instantly share code, notes, and snippets.

@tobsecret
Created February 11, 2019 17:14
Show Gist options
  • Save tobsecret/8f9c072a1943ea9dde287695877060b5 to your computer and use it in GitHub Desktop.
Save tobsecret/8f9c072a1943ea9dde287695877060b5 to your computer and use it in GitHub Desktop.
Splitting and samples by chromosome and combining them again in Nextflow
chroms = ['chr1', 'chr2', 'chr3'] //let's say we want to try out the first three chromosomes
samples = Channel
.from (['n1', chroms],
['n2', chroms])
//.subscribe {println it}
/*
[n1, [chr1, chr2, chr3]]
[n2, [chr1, chr2, chr3]]
*/
//Let's split by sample and chromosome
chromosomewise = samples
.map {it -> [it[0], it[1].collate(1)]}
//.subscribe {println it}
/*
[n1, [[chr1], [chr2], [chr3]]]
[n2, [[chr1], [chr2], [chr3]]]
*/
.transpose()
//.subscribe {println it}
/*
[n1, [chr1]]
[n1, [chr2]]
[n1, [chr3]]
[n2, [chr1]]
[n2, [chr2]]
[n2, [chr3]]
*/
//let's combine again by sample
samplewise = chromosomewise
.groupTuple()
//.subscribe {println it}
/*
[n1, [[chr1], [chr2], [chr3]]]
[n2, [[chr1], [chr2], [chr3]]]
*/
.map{it -> [it[0], it[1].flatten()]}
//.subscribe{println it}
/*
[n1, [chr1, chr2, chr3]]
[n2, [chr1, chr2, chr3]]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment